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

Side by Side Diff: media/mojo/clients/mojo_audio_renderer_sink_impl.cc

Issue 2640003002: Implement MojoAudioRendererSink and use it in UtilityMojoMediaClient (Closed)
Patch Set: Rebase Created 3 years, 10 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
« no previous file with comments | « media/mojo/clients/mojo_audio_renderer_sink_impl.h ('k') | media/mojo/clients/mojo_renderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/clients/mojo_audio_renderer_sink_impl.h"
6
7 #include "media/mojo/common/media_type_converters.h"
8
9 namespace media {
10
11 MojoAudioRendererSinkImpl::MojoAudioRendererSinkImpl(
12 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
13 media::AudioRendererSink* sink,
14 mojo::InterfaceRequest<mojom::AudioRendererSink> request)
15 : media_task_runner_(media_task_runner),
16 audio_device_task_runner_(nullptr),
17 binding_(this, std::move(request)),
18 sink_(sink),
19 started_(false) {
20 CHECK(media_task_runner_->BelongsToCurrentThread());
21 }
22
23 MojoAudioRendererSinkImpl::~MojoAudioRendererSinkImpl() {
24 CHECK(media_task_runner_->BelongsToCurrentThread());
25
26 if (started_) {
27 sink_->Stop();
28 started_ = false;
29 }
30 }
31
32 int MojoAudioRendererSinkImpl::Render(base::TimeDelta delay,
33 base::TimeTicks delay_timestamp,
34 int prior_frames_skipped,
35 AudioBus* dest) {
36 if (!callback_.is_bound()) {
37 callback_.Bind(std::move(callback_info_));
38
39 if (!audio_device_task_runner_) {
40 audio_device_task_runner_ = base::ThreadTaskRunnerHandle::Get();
41 CHECK(audio_device_task_runner_ != media_task_runner_);
42 }
43 }
44
45 CHECK(audio_device_task_runner_->BelongsToCurrentThread());
46
47 int nb_filled_frames = 0;
48 mojom::AudioBusPtr mojo_audio_bus;
49
50 // Alternative solution is to bind mojom::AudioRendererSinkRenderCallbackPtr
51 // to the audio device thread. Like
52 callback_->Render(delay, delay_timestamp, prior_frames_skipped,
53 &nb_filled_frames, &mojo_audio_bus);
54
55 callback_info_ = callback_.PassInterface();
56
57 if (!mojo_audio_bus)
58 return 0;
59
60 // TODO(j.isorce): consider using AudioSyncReader once it is mojified.
61 std::unique_ptr<media::AudioBus> audio_bus_wrapper =
62 media::AudioBus::WrapMemory(mojo_audio_bus->nb_channels,
63 mojo_audio_bus->nb_frames,
64 mojo_audio_bus->data.data());
65 audio_bus_wrapper->CopyTo(dest);
66
67 return nb_filled_frames;
68 }
69
70 void MojoAudioRendererSinkImpl::OnRenderError() {
71 CHECK(audio_device_task_runner_->BelongsToCurrentThread());
72
73 if (!callback_.is_bound())
74 callback_.Bind(std::move(callback_info_));
75
76 callback_->OnRenderError();
77
78 callback_info_ = callback_.PassInterface();
79 }
80
81 void MojoAudioRendererSinkImpl::Initialize(
82 const media::AudioParameters& params,
83 mojom::AudioRendererSinkRenderCallbackPtr callback) {
84 CHECK(media_task_runner_->BelongsToCurrentThread());
85 if (callback)
86 callback_info_ = callback.PassInterface();
87 sink_->Initialize(params, this);
88 }
89
90 void MojoAudioRendererSinkImpl::Start() {
91 CHECK(media_task_runner_->BelongsToCurrentThread());
92 CHECK(!started_);
93
94 started_ = true;
95 sink_->Start();
96 }
97
98 void MojoAudioRendererSinkImpl::Stop() {
99 CHECK(media_task_runner_->BelongsToCurrentThread());
100 CHECK(started_);
101
102 started_ = false;
103 sink_->Stop();
104 }
105
106 void MojoAudioRendererSinkImpl::Pause() {
107 CHECK(media_task_runner_->BelongsToCurrentThread());
108 sink_->Pause();
109 }
110
111 void MojoAudioRendererSinkImpl::Play() {
112 CHECK(media_task_runner_->BelongsToCurrentThread());
113 sink_->Play();
114 }
115
116 void MojoAudioRendererSinkImpl::SetVolume(double volume,
117 const SetVolumeCallback& callback) {
118 CHECK(media_task_runner_->BelongsToCurrentThread());
119 bool success = sink_->SetVolume(volume);
120 callback.Run(success);
121 }
122
123 void MojoAudioRendererSinkImpl::GetOutputDeviceInfo(
124 const GetOutputDeviceInfoCallback& callback) {
125 CHECK(media_task_runner_->BelongsToCurrentThread());
126 media::OutputDeviceInfo info = sink_->GetOutputDeviceInfo();
127 callback.Run(info);
128 }
129
130 void MojoAudioRendererSinkImpl::CurrentThreadIsRenderingThread(
131 const CurrentThreadIsRenderingThreadCallback& callback) {
132 CHECK(media_task_runner_->BelongsToCurrentThread());
133 bool is_rendering_thread = sink_->CurrentThreadIsRenderingThread();
134 callback.Run(is_rendering_thread);
135 }
136
137 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_audio_renderer_sink_impl.h ('k') | media/mojo/clients/mojo_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698