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

Side by Side Diff: media/base/audio_renderer_mixer_input.cc

Issue 1809093003: Moving SwitchOutputDevice out of OutputDevice interface, eliminating OutputDevice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace RestartableAudioRendererSink with SwitchableAudioRendererSink in webmediaplayer_impl unit t… Created 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/audio_renderer_mixer_input.h" 5 #include "media/base/audio_renderer_mixer_input.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "media/base/audio_renderer_mixer.h" 11 #include "media/base/audio_renderer_mixer.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 AudioRendererMixerInput::AudioRendererMixerInput( 15 AudioRendererMixerInput::AudioRendererMixerInput(
16 const GetMixerCB& get_mixer_cb, 16 const GetMixerCB& get_mixer_cb,
17 const RemoveMixerCB& remove_mixer_cb, 17 const RemoveMixerCB& remove_mixer_cb,
18 const GetHardwareParamsCB& get_hardware_params_cb, 18 const GetOutputDeviceCB& get_output_device_cb,
19 const std::string& device_id, 19 const std::string& device_id,
20 const url::Origin& security_origin) 20 const url::Origin& security_origin)
21 : started_(false), 21 : started_(false),
22 playing_(false), 22 playing_(false),
23 volume_(1.0f), 23 volume_(1.0f),
24 get_mixer_cb_(get_mixer_cb), 24 get_mixer_cb_(get_mixer_cb),
25 remove_mixer_cb_(remove_mixer_cb), 25 remove_mixer_cb_(remove_mixer_cb),
26 get_hardware_params_cb_(get_hardware_params_cb), 26 get_output_device_cb_(get_output_device_cb),
27 device_id_(device_id), 27 device_id_(device_id),
28 security_origin_(security_origin), 28 security_origin_(security_origin),
29 mixer_(nullptr), 29 mixer_(nullptr),
30 callback_(nullptr), 30 callback_(nullptr),
31 error_cb_(base::Bind(&AudioRendererMixerInput::OnRenderError, 31 error_cb_(base::Bind(&AudioRendererMixerInput::OnRenderError,
32 base::Unretained(this))) {} 32 base::Unretained(this))) {}
33 33
34 AudioRendererMixerInput::~AudioRendererMixerInput() { 34 AudioRendererMixerInput::~AudioRendererMixerInput() {
35 DCHECK(!mixer_); 35 DCHECK(!mixer_);
36 } 36 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 mixer_->RemoveMixerInput(params_, this); 104 mixer_->RemoveMixerInput(params_, this);
105 playing_ = false; 105 playing_ = false;
106 } 106 }
107 107
108 bool AudioRendererMixerInput::SetVolume(double volume) { 108 bool AudioRendererMixerInput::SetVolume(double volume) {
109 volume_ = volume; 109 volume_ = volume;
110 return true; 110 return true;
111 } 111 }
112 112
113 OutputDevice* AudioRendererMixerInput::GetOutputDevice() { 113 OutputDevice* AudioRendererMixerInput::GetOutputDevice() {
114 return this; 114 return mixer_ ? mixer_->GetOutputDevice()
115 : get_output_device_cb_.Run(device_id_, security_origin_);
Guido Urdaneta 2016/03/17 17:38:24 Shouldn't this one return nullptr when there is no
o1ka 2016/03/18 10:45:40 Of cause we need to make sure it does not leak ;)
115 } 116 }
116 117
117 void AudioRendererMixerInput::SwitchOutputDevice( 118 void AudioRendererMixerInput::SwitchOutputDevice(
118 const std::string& device_id, 119 const std::string& device_id,
119 const url::Origin& security_origin, 120 const url::Origin& security_origin,
120 const SwitchOutputDeviceCB& callback) { 121 const SwitchOutputDeviceCB& callback) {
121 if (!mixer_) { 122 if (!mixer_) {
122 if (pending_switch_callback_.is_null()) { 123 if (pending_switch_callback_.is_null()) {
123 pending_switch_callback_ = callback; 124 pending_switch_callback_ = callback;
124 pending_switch_device_id_ = device_id; 125 pending_switch_device_id_ = device_id;
(...skipping 26 matching lines...) Expand all
151 mixer_ = new_mixer; 152 mixer_ = new_mixer;
152 mixer_->AddErrorCallback(error_cb_); 153 mixer_->AddErrorCallback(error_cb_);
153 started_ = true; 154 started_ = true;
154 155
155 if (was_playing) 156 if (was_playing)
156 Play(); 157 Play();
157 158
158 callback.Run(OUTPUT_DEVICE_STATUS_OK); 159 callback.Run(OUTPUT_DEVICE_STATUS_OK);
159 } 160 }
160 161
161 AudioParameters AudioRendererMixerInput::GetOutputParameters() {
162 if (mixer_)
163 return mixer_->GetOutputDevice()->GetOutputParameters();
164 return get_hardware_params_cb_.Run(device_id_, security_origin_);
165 }
166
167 OutputDeviceStatus AudioRendererMixerInput::GetDeviceStatus() {
168 if (mixer_)
169 return mixer_->GetOutputDevice()->GetDeviceStatus();
170
171 if (started_)
172 return OUTPUT_DEVICE_STATUS_ERROR_INTERNAL;
173
174 return OUTPUT_DEVICE_STATUS_OK;
175 }
176
177 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, 162 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus,
178 base::TimeDelta buffer_delay) { 163 base::TimeDelta buffer_delay) {
179 // TODO(chcunningham): Delete this conversion and change ProvideInput to more 164 // TODO(chcunningham): Delete this conversion and change ProvideInput to more
180 // precisely describe delay as a count of frames delayed instead of TimeDelta. 165 // precisely describe delay as a count of frames delayed instead of TimeDelta.
181 // See http://crbug.com/587522. 166 // See http://crbug.com/587522.
182 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() / 167 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() /
183 params_.GetMicrosecondsPerFrame()); 168 params_.GetMicrosecondsPerFrame());
184 169
185 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); 170 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0);
186 171
187 // AudioConverter expects unfilled frames to be zeroed. 172 // AudioConverter expects unfilled frames to be zeroed.
188 if (frames_filled < audio_bus->frames()) { 173 if (frames_filled < audio_bus->frames()) {
189 audio_bus->ZeroFramesPartial( 174 audio_bus->ZeroFramesPartial(
190 frames_filled, audio_bus->frames() - frames_filled); 175 frames_filled, audio_bus->frames() - frames_filled);
191 } 176 }
192 177
193 return frames_filled > 0 ? volume_ : 0; 178 return frames_filled > 0 ? volume_ : 0;
194 } 179 }
195 180
196 void AudioRendererMixerInput::OnRenderError() { 181 void AudioRendererMixerInput::OnRenderError() {
197 callback_->OnRenderError(); 182 callback_->OnRenderError();
198 } 183 }
199 184
200 } // namespace media 185 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698