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

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

Issue 1703473002: Make AudioOutputDevice restartable and reinitializable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_mixing
Patch Set: Created 4 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
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.h" 5 #include "media/base/audio_renderer_mixer.h"
6 #include "media/base/audio_hardware_config.h" 6 #include "media/base/audio_hardware_config.h"
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 const GetNewSinkCB& get_new_sink_cb) 184 const GetNewSinkCB& get_new_sink_cb)
185 : get_new_sink_cb_(get_new_sink_cb), 185 : get_new_sink_cb_(get_new_sink_cb),
186 output_param_detector_(new OutputParamDetector(output_params)), 186 output_param_detector_(new OutputParamDetector(output_params)),
187 audio_sink_(sink), 187 audio_sink_(sink),
188 output_params_(output_params), 188 output_params_(output_params),
189 master_converter_(output_params, output_params, true), 189 master_converter_(output_params, output_params, true),
190 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)), 190 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)),
191 last_play_time_(base::TimeTicks::Now()), 191 last_play_time_(base::TimeTicks::Now()),
192 // Initialize |playing_| to true since Start() results in an auto-play. 192 // Initialize |playing_| to true since Start() results in an auto-play.
193 playing_(true) { 193 playing_(true) {
194 printf("################ Creating new mixer.\n");
194 DVLOG(1) << "AudioRendererMixer::AudioRendererMixer(),\n" 195 DVLOG(1) << "AudioRendererMixer::AudioRendererMixer(),\n"
195 << output_params_.AsHumanReadableString() << "mixer: " << this; 196 << output_params_.AsHumanReadableString() << "mixer: " << this;
196 // TODO(olka) we probably want to (a) start with a null sink and create a new 197 // TODO(olka) we probably want to (a) start with a null sink and create a new
197 // one when a new input is added, or (b) create a sink through a callback 198 // one when a new input is added, or (b) create a sink through a callback
198 audio_sink_->Initialize(output_params, this); 199 audio_sink_->Initialize(output_params, this);
199 audio_sink_->Start(); 200 audio_sink_->Start();
200 } 201 }
201 202
202 AudioRendererMixer::~AudioRendererMixer() { 203 AudioRendererMixer::~AudioRendererMixer() {
203 DVLOG(1) << "AudioRendererMixer::~AudioRendererMixer(), mixer: " << this; 204 DVLOG(1) << "AudioRendererMixer::~AudioRendererMixer(), mixer: " << this;
(...skipping 27 matching lines...) Expand all
231 232
232 // If |frames_per_buffer| does not change, do not bother to reconfigure the 233 // If |frames_per_buffer| does not change, do not bother to reconfigure the
233 // sink depending on just |format|. TODO(olka) we may reconcider this. 234 // sink depending on just |format|. TODO(olka) we may reconcider this.
234 { 235 {
235 base::AutoLock auto_lock(lock_); 236 base::AutoLock auto_lock(lock_);
236 if (new_output_params.frames_per_buffer() == 237 if (new_output_params.frames_per_buffer() ==
237 output_params_.frames_per_buffer()) 238 output_params_.frames_per_buffer())
238 return; 239 return;
239 } 240 }
240 241
242 #if 1
243 {
244 // base::AutoLock auto_lock(lock_);
245 if (audio_sink_) {
246 printf("################ Restarting sink for mixer.\n");
247 // Initialize |playing_| to true since Start() results in an auto-play.
248 last_play_time_ = base::TimeTicks::Now();
249 output_params_ = new_output_params;
250 audio_sink_->Stop();
251 audio_sink_->Initialize(output_params_, this);
252 audio_sink_->Start();
253 if (playing_)
254 audio_sink_->Play();
255 DVLOG(1) << "Sink reinitialized";
256 return;
257 }
258 }
259 #endif
260
261 NOTREACHED();
262
263 printf("################ Creating new sink for mixer.\n");
264
241 // To minimize possible glitches during the sink switch, first we initialize 265 // To minimize possible glitches during the sink switch, first we initialize
242 // the new sink, and after that we stop the current one. This may be a problem 266 // the new sink, and after that we stop the current one. This may be a problem
243 // on Mac since audio output won't switch to a larger buffer when there is IO 267 // on Mac since audio output won't switch to a larger buffer when there is IO
244 // with a smaller one. 268 // with a smaller one.
245 scoped_refptr<media::AudioRendererSink> new_audio_sink = 269 scoped_refptr<media::AudioRendererSink> new_audio_sink =
246 get_new_sink_cb_.Run(); 270 get_new_sink_cb_.Run();
247 if (!new_audio_sink) { 271 if (!new_audio_sink) {
248 LOG(ERROR) << "Sink creation failed."; 272 LOG(ERROR) << "Sink creation failed.";
249 return; // Fail back to an existing one. 273 return; // Fail back to an existing one.
250 } 274 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 419 }
396 420
397 void AudioRendererMixer::OnRenderError() { 421 void AudioRendererMixer::OnRenderError() {
398 // Call each mixer input and signal an error. 422 // Call each mixer input and signal an error.
399 base::AutoLock auto_lock(lock_); 423 base::AutoLock auto_lock(lock_);
400 for (const auto& cb : error_callbacks_) 424 for (const auto& cb : error_callbacks_)
401 cb.Run(); 425 cb.Run();
402 } 426 }
403 427
404 } // namespace media 428 } // namespace media
OLDNEW
« media/audio/audio_device_thread.cc ('K') | « media/audio/audio_output_device.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698