Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: media/mojo/services/mojo_audio_output.cc

Issue 2697793002: Add mojo interface+impl for audio stream control. (Closed)
Patch Set: Introduce provider Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/mojo/services/mojo_audio_output.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/callback_helpers.h"
11 #include "base/memory/shared_memory.h"
12 #include "base/sync_socket.h"
13 #include "mojo/public/cpp/system/platform_handle.h"
14
15 namespace media {
16
17 MojoAudioOutput::MojoAudioOutput(
18 mojom::AudioOutputRequest request,
19 CreateDelegateCallback create_delegate_callback,
20 StreamCreatedCallback stream_created_callback,
21 base::OnceClosure deleter_callback)
22 : stream_created_callback_(std::move(stream_created_callback)),
23 deleter_callback_(std::move(deleter_callback)),
24 binding_(this, std::move(request)),
25 delegate_(std::move(create_delegate_callback).Run(this)) {
26 DCHECK(thread_checker_.CalledOnValidThread());
27 DCHECK(deleter_callback_);
28 // |this| owns |binding_|, so unretained is safe.
29 binding_.set_connection_error_handler(
30 base::Bind(&MojoAudioOutput::OnError, base::Unretained(this)));
31 }
32
33 MojoAudioOutput::~MojoAudioOutput() {
34 DCHECK(thread_checker_.CalledOnValidThread());
35 }
36
37 void MojoAudioOutput::Play() {
38 DCHECK(thread_checker_.CalledOnValidThread());
39 delegate_->OnPlayStream();
40 }
41
42 void MojoAudioOutput::Pause() {
43 DCHECK(thread_checker_.CalledOnValidThread());
44 delegate_->OnPauseStream();
45 }
46
47 void MojoAudioOutput::SetVolume(double volume) {
48 DCHECK(thread_checker_.CalledOnValidThread());
49 if (volume < 0 || volume > 1) {
DaleCurtis 2017/03/06 17:56:12 Hmm, should this be a BadMessage instead which kil
Max Morin 2017/03/07 11:23:16 I don't know if we get any bad volumes, I recall b
50 LOG(ERROR) << "MojoAudioOutput::SetVolume(" << volume << ") out of range.";
51 OnError();
52 return;
53 }
54 delegate_->OnSetVolume(volume);
55 }
56
57 void MojoAudioOutput::OnStreamCreated(
58 int stream_id,
DaleCurtis 2017/03/06 17:56:12 Unused? Still necessary?
Max Morin 2017/03/07 11:23:16 It is part of the AudioOutputDelegate::EventHandle
59 base::SharedMemory* shared_memory,
60 base::CancelableSyncSocket* foreign_socket) {
61 DCHECK(thread_checker_.CalledOnValidThread());
62 DCHECK(stream_created_callback_);
63 DCHECK(shared_memory);
64 DCHECK(foreign_socket);
65
66 base::SharedMemoryHandle foreign_memory_handle =
67 base::SharedMemory::DuplicateHandle(shared_memory->handle());
68 DCHECK(base::SharedMemory::IsHandleValid(foreign_memory_handle));
69
70 mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle(
71 foreign_memory_handle, shared_memory->requested_size(), false);
72 mojo::ScopedHandle socket_handle =
73 mojo::WrapPlatformFile(foreign_socket->handle());
74
75 DCHECK(buffer_handle.is_valid());
76 DCHECK(socket_handle.is_valid());
77
78 base::ResetAndReturn(&stream_created_callback_)
79 .Run(std::move(buffer_handle), std::move(socket_handle));
80 }
81
82 void MojoAudioOutput::OnStreamError(int stream_id) {
83 DCHECK(thread_checker_.CalledOnValidThread());
84 OnError();
85 }
86
87 void MojoAudioOutput::OnError() {
88 DCHECK(thread_checker_.CalledOnValidThread());
89 DCHECK(deleter_callback_);
90 // Destroys |this|.
91 std::move(deleter_callback_).Run();
92 }
93
94 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698