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

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

Issue 1942803002: Caching AudioOutputDevice instances in mixer manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, fix for sleep() compile error on win and a bit of cleanup around timeouts. Created 4 years, 7 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 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 enum { kPauseDelaySeconds = 10 }; 16 enum { kPauseDelaySeconds = 10 };
17 17
18 AudioRendererMixer::AudioRendererMixer( 18 AudioRendererMixer::AudioRendererMixer(
19 const AudioParameters& output_params, 19 const AudioParameters& output_params,
20 const scoped_refptr<AudioRendererSink>& sink) 20 AudioRendererSink* sink,
21 const ReleaseSinkCallback& release_sink_cb)
21 : audio_sink_(sink), 22 : audio_sink_(sink),
23 release_sink_cb_(release_sink_cb),
22 output_params_(output_params), 24 output_params_(output_params),
23 master_converter_(output_params, output_params, true), 25 master_converter_(output_params, output_params, true),
24 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)), 26 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)),
25 last_play_time_(base::TimeTicks::Now()), 27 last_play_time_(base::TimeTicks::Now()),
26 // Initialize |playing_| to true since Start() results in an auto-play. 28 // Initialize |playing_| to true since Start() results in an auto-play.
27 playing_(true) { 29 playing_(true) {
30 DCHECK(audio_sink_);
28 audio_sink_->Initialize(output_params, this); 31 audio_sink_->Initialize(output_params, this);
29 audio_sink_->Start(); 32 audio_sink_->Start();
30 } 33 }
31 34
32 AudioRendererMixer::~AudioRendererMixer() { 35 AudioRendererMixer::~AudioRendererMixer() {
33 // AudioRendererSinks must be stopped before being destructed. 36 // AudioRendererSink must be stopped before mixer is destructed.
34 audio_sink_->Stop(); 37 audio_sink_->Stop();
38 // Releasing the sink.
39 release_sink_cb_.Run(audio_sink_);
35 40
36 // Ensure that all mixer inputs have removed themselves prior to destruction. 41 // Ensure that all mixer inputs have removed themselves prior to destruction.
37 DCHECK(master_converter_.empty()); 42 DCHECK(master_converter_.empty());
38 DCHECK(converters_.empty()); 43 DCHECK(converters_.empty());
39 DCHECK_EQ(error_callbacks_.size(), 0U); 44 DCHECK_EQ(error_callbacks_.size(), 0U);
40 } 45 }
41 46
42 void AudioRendererMixer::AddMixerInput(const AudioParameters& input_params, 47 void AudioRendererMixer::AddMixerInput(const AudioParameters& input_params,
43 AudioConverter::InputCallback* input) { 48 AudioConverter::InputCallback* input) {
44 base::AutoLock auto_lock(lock_); 49 base::AutoLock auto_lock(lock_);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 151 }
147 152
148 void AudioRendererMixer::OnRenderError() { 153 void AudioRendererMixer::OnRenderError() {
149 // Call each mixer input and signal an error. 154 // Call each mixer input and signal an error.
150 base::AutoLock auto_lock(lock_); 155 base::AutoLock auto_lock(lock_);
151 for (const auto& cb : error_callbacks_) 156 for (const auto& cb : error_callbacks_)
152 cb.Run(); 157 cb.Run();
153 } 158 }
154 159
155 } // namespace media 160 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698