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

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: Addressing miu@ and grunell@ review comments, changing AudioDeviceFactory to produce AudioCapturerS… Created 4 years, 8 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,
19 const std::string& device_id, 18 const std::string& device_id,
20 const url::Origin& security_origin) 19 const url::Origin& security_origin)
21 : started_(false), 20 : started_(false),
22 playing_(false), 21 playing_(false),
23 volume_(1.0f), 22 volume_(1.0f),
24 get_mixer_cb_(get_mixer_cb), 23 get_mixer_cb_(get_mixer_cb),
25 remove_mixer_cb_(remove_mixer_cb), 24 remove_mixer_cb_(remove_mixer_cb),
26 get_hardware_params_cb_(get_hardware_params_cb),
27 device_id_(device_id), 25 device_id_(device_id),
28 security_origin_(security_origin), 26 security_origin_(security_origin),
29 mixer_(nullptr), 27 mixer_(nullptr),
30 callback_(nullptr), 28 callback_(nullptr),
31 error_cb_(base::Bind(&AudioRendererMixerInput::OnRenderError, 29 error_cb_(base::Bind(&AudioRendererMixerInput::OnRenderError,
32 base::Unretained(this))) {} 30 base::Unretained(this))) {}
33 31
34 AudioRendererMixerInput::~AudioRendererMixerInput() { 32 AudioRendererMixerInput::~AudioRendererMixerInput() {
35 DCHECK(!mixer_); 33 DCHECK(!mixer_);
36 } 34 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 101
104 mixer_->RemoveMixerInput(params_, this); 102 mixer_->RemoveMixerInput(params_, this);
105 playing_ = false; 103 playing_ = false;
106 } 104 }
107 105
108 bool AudioRendererMixerInput::SetVolume(double volume) { 106 bool AudioRendererMixerInput::SetVolume(double volume) {
109 volume_ = volume; 107 volume_ = volume;
110 return true; 108 return true;
111 } 109 }
112 110
113 OutputDevice* AudioRendererMixerInput::GetOutputDevice() { 111 OutputDeviceInfo AudioRendererMixerInput::GetOutputDeviceInfo() {
114 return this; 112 return mixer_ ? mixer_->GetOutputDeviceInfo() : OutputDeviceInfo();
115 } 113 }
116 114
117 void AudioRendererMixerInput::SwitchOutputDevice( 115 void AudioRendererMixerInput::SwitchOutputDevice(
118 const std::string& device_id, 116 const std::string& device_id,
119 const url::Origin& security_origin, 117 const url::Origin& security_origin,
120 const SwitchOutputDeviceCB& callback) { 118 const OutputDeviceStatusCB& callback) {
121 if (!mixer_) { 119 if (!mixer_) {
122 if (pending_switch_callback_.is_null()) { 120 if (pending_switch_callback_.is_null()) {
123 pending_switch_callback_ = callback; 121 pending_switch_callback_ = callback;
124 pending_switch_device_id_ = device_id; 122 pending_switch_device_id_ = device_id;
125 pending_switch_security_origin_ = security_origin; 123 pending_switch_security_origin_ = security_origin;
126 } else { 124 } else {
127 callback.Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); 125 callback.Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL);
128 } 126 }
129 127
130 return; 128 return;
(...skipping 20 matching lines...) Expand all
151 mixer_ = new_mixer; 149 mixer_ = new_mixer;
152 mixer_->AddErrorCallback(error_cb_); 150 mixer_->AddErrorCallback(error_cb_);
153 started_ = true; 151 started_ = true;
154 152
155 if (was_playing) 153 if (was_playing)
156 Play(); 154 Play();
157 155
158 callback.Run(OUTPUT_DEVICE_STATUS_OK); 156 callback.Run(OUTPUT_DEVICE_STATUS_OK);
159 } 157 }
160 158
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, 159 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus,
178 base::TimeDelta buffer_delay) { 160 base::TimeDelta buffer_delay) {
179 // TODO(chcunningham): Delete this conversion and change ProvideInput to more 161 // TODO(chcunningham): Delete this conversion and change ProvideInput to more
180 // precisely describe delay as a count of frames delayed instead of TimeDelta. 162 // precisely describe delay as a count of frames delayed instead of TimeDelta.
181 // See http://crbug.com/587522. 163 // See http://crbug.com/587522.
182 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() / 164 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() /
183 params_.GetMicrosecondsPerFrame()); 165 params_.GetMicrosecondsPerFrame());
184 166
185 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); 167 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0);
186 168
187 // AudioConverter expects unfilled frames to be zeroed. 169 // AudioConverter expects unfilled frames to be zeroed.
188 if (frames_filled < audio_bus->frames()) { 170 if (frames_filled < audio_bus->frames()) {
189 audio_bus->ZeroFramesPartial( 171 audio_bus->ZeroFramesPartial(
190 frames_filled, audio_bus->frames() - frames_filled); 172 frames_filled, audio_bus->frames() - frames_filled);
191 } 173 }
192 174
193 return frames_filled > 0 ? volume_ : 0; 175 return frames_filled > 0 ? volume_ : 0;
194 } 176 }
195 177
196 void AudioRendererMixerInput::OnRenderError() { 178 void AudioRendererMixerInput::OnRenderError() {
197 callback_->OnRenderError(); 179 callback_->OnRenderError();
198 } 180 }
199 181
200 } // namespace media 182 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698