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

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

Issue 2389783002: Make AudioRendererMixerInput::SwitchOutputDevice to work correctly even if it has not been initiali… (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | media/base/audio_renderer_mixer_input_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 void AudioRendererMixerInput::SwitchOutputDevice( 121 void AudioRendererMixerInput::SwitchOutputDevice(
122 const std::string& device_id, 122 const std::string& device_id,
123 const url::Origin& security_origin, 123 const url::Origin& security_origin,
124 const OutputDeviceStatusCB& callback) { 124 const OutputDeviceStatusCB& callback) {
125 if (device_id == device_id_) { 125 if (device_id == device_id_) {
126 callback.Run(OUTPUT_DEVICE_STATUS_OK); 126 callback.Run(OUTPUT_DEVICE_STATUS_OK);
127 return; 127 return;
128 } 128 }
129 129
130 OutputDeviceStatus new_mixer_status = OUTPUT_DEVICE_STATUS_ERROR_INTERNAL; 130 if (mixer_) {
131 AudioRendererMixer* new_mixer = 131 OutputDeviceStatus new_mixer_status = OUTPUT_DEVICE_STATUS_ERROR_INTERNAL;
132 mixer_pool_->GetMixer(owner_id_, params_, latency_, device_id, 132 AudioRendererMixer* new_mixer =
133 security_origin, &new_mixer_status); 133 mixer_pool_->GetMixer(owner_id_, params_, latency_, device_id,
134 if (new_mixer_status != OUTPUT_DEVICE_STATUS_OK) { 134 security_origin, &new_mixer_status);
135 callback.Run(new_mixer_status); 135 if (new_mixer_status != OUTPUT_DEVICE_STATUS_OK) {
136 return; 136 callback.Run(new_mixer_status);
137 } 137 return;
138 }
138 139
139 device_id_ = device_id;
140 security_origin_ = security_origin;
141
142 if (mixer_) {
143 bool was_playing = playing_; 140 bool was_playing = playing_;
144 Stop(); 141 Stop();
142 device_id_ = device_id;
143 security_origin_ = security_origin;
145 mixer_ = new_mixer; 144 mixer_ = new_mixer;
146 mixer_->AddErrorCallback(error_cb_); 145 mixer_->AddErrorCallback(error_cb_);
147 started_ = true; 146 started_ = true;
147
148 if (was_playing) 148 if (was_playing)
149 Play(); 149 Play();
150
150 } else { 151 } else {
151 mixer_pool_->ReturnMixer(new_mixer); 152 OutputDeviceStatus new_mixer_status =
153 mixer_pool_
154 ->GetOutputDeviceInfo(owner_id_, 0 /* session_id */, device_id,
155 security_origin)
156 .device_status();
157 if (new_mixer_status != OUTPUT_DEVICE_STATUS_OK) {
158 callback.Run(new_mixer_status);
159 return;
160 }
161 device_id_ = device_id;
162 security_origin_ = security_origin;
152 } 163 }
153 164
154 callback.Run(OUTPUT_DEVICE_STATUS_OK); 165 callback.Run(OUTPUT_DEVICE_STATUS_OK);
155 } 166 }
156 167
157 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, 168 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus,
158 uint32_t frames_delayed) { 169 uint32_t frames_delayed) {
159 TRACE_EVENT0("audio", "AudioRendererMixerInput::ProvideInput"); 170 TRACE_EVENT0("audio", "AudioRendererMixerInput::ProvideInput");
160 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); 171 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0);
161 172
(...skipping 10 matching lines...) Expand all
172 base::AutoLock auto_lock(volume_lock_); 183 base::AutoLock auto_lock(volume_lock_);
173 return frames_filled > 0 ? volume_ : 0; 184 return frames_filled > 0 ? volume_ : 0;
174 } 185 }
175 } 186 }
176 187
177 void AudioRendererMixerInput::OnRenderError() { 188 void AudioRendererMixerInput::OnRenderError() {
178 callback_->OnRenderError(); 189 callback_->OnRenderError();
179 } 190 }
180 191
181 } // namespace media 192 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_renderer_mixer_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698