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

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: rebase 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(!started_); 33 DCHECK(!started_);
36 DCHECK(!mixer_); 34 DCHECK(!mixer_);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 mixer_->RemoveMixerInput(params_, this); 104 mixer_->RemoveMixerInput(params_, this);
107 playing_ = false; 105 playing_ = false;
108 } 106 }
109 107
110 bool AudioRendererMixerInput::SetVolume(double volume) { 108 bool AudioRendererMixerInput::SetVolume(double volume) {
111 base::AutoLock auto_lock(volume_lock_); 109 base::AutoLock auto_lock(volume_lock_);
112 volume_ = volume; 110 volume_ = volume;
113 return true; 111 return true;
114 } 112 }
115 113
116 OutputDevice* AudioRendererMixerInput::GetOutputDevice() { 114 OutputDeviceInfo AudioRendererMixerInput::GetOutputDeviceInfo() {
117 return this; 115 return mixer_ ? mixer_->GetOutputDeviceInfo() : OutputDeviceInfo();
118 } 116 }
119 117
120 void AudioRendererMixerInput::SwitchOutputDevice( 118 void AudioRendererMixerInput::SwitchOutputDevice(
121 const std::string& device_id, 119 const std::string& device_id,
122 const url::Origin& security_origin, 120 const url::Origin& security_origin,
123 const SwitchOutputDeviceCB& callback) { 121 const OutputDeviceStatusCB& callback) {
124 if (!mixer_) { 122 if (!mixer_) {
125 if (pending_switch_callback_.is_null()) { 123 if (pending_switch_callback_.is_null()) {
126 pending_switch_callback_ = callback; 124 pending_switch_callback_ = callback;
127 pending_switch_device_id_ = device_id; 125 pending_switch_device_id_ = device_id;
128 pending_switch_security_origin_ = security_origin; 126 pending_switch_security_origin_ = security_origin;
129 } else { 127 } else {
130 callback.Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); 128 callback.Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL);
131 } 129 }
132 130
133 return; 131 return;
(...skipping 20 matching lines...) Expand all
154 mixer_ = new_mixer; 152 mixer_ = new_mixer;
155 mixer_->AddErrorCallback(error_cb_); 153 mixer_->AddErrorCallback(error_cb_);
156 started_ = true; 154 started_ = true;
157 155
158 if (was_playing) 156 if (was_playing)
159 Play(); 157 Play();
160 158
161 callback.Run(OUTPUT_DEVICE_STATUS_OK); 159 callback.Run(OUTPUT_DEVICE_STATUS_OK);
162 } 160 }
163 161
164 AudioParameters AudioRendererMixerInput::GetOutputParameters() {
165 if (mixer_)
166 return mixer_->GetOutputDevice()->GetOutputParameters();
167 return get_hardware_params_cb_.Run(device_id_, security_origin_);
168 }
169
170 OutputDeviceStatus AudioRendererMixerInput::GetDeviceStatus() {
171 if (mixer_)
172 return mixer_->GetOutputDevice()->GetDeviceStatus();
173
174 if (started_)
175 return OUTPUT_DEVICE_STATUS_ERROR_INTERNAL;
176
177 return OUTPUT_DEVICE_STATUS_OK;
178 }
179
180 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, 162 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus,
181 base::TimeDelta buffer_delay) { 163 base::TimeDelta buffer_delay) {
182 // TODO(chcunningham): Delete this conversion and change ProvideInput to more 164 // TODO(chcunningham): Delete this conversion and change ProvideInput to more
183 // 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.
184 // See http://crbug.com/587522. 166 // See http://crbug.com/587522.
185 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() / 167 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() /
186 params_.GetMicrosecondsPerFrame()); 168 params_.GetMicrosecondsPerFrame());
187 169
188 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); 170 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0);
189 171
(...skipping 10 matching lines...) Expand all
200 base::AutoLock auto_lock(volume_lock_); 182 base::AutoLock auto_lock(volume_lock_);
201 return frames_filled > 0 ? volume_ : 0; 183 return frames_filled > 0 ? volume_ : 0;
202 } 184 }
203 } 185 }
204 186
205 void AudioRendererMixerInput::OnRenderError() { 187 void AudioRendererMixerInput::OnRenderError() {
206 callback_->OnRenderError(); 188 callback_->OnRenderError();
207 } 189 }
208 190
209 } // namespace media 191 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_renderer_mixer_input.h ('k') | media/base/audio_renderer_mixer_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698