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

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

Issue 2466463005: Support (E)AC3 passthrough
Patch Set: Improve CastMediaClient::IsSupportedPassthroughAudio() Created 4 years, 1 month 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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 int count_; 47 int count_;
48 int max_count_; 48 int max_count_;
49 DISALLOW_COPY_AND_ASSIGN(UMAMaxValueTracker); 49 DISALLOW_COPY_AND_ASSIGN(UMAMaxValueTracker);
50 }; 50 };
51 51
52 AudioRendererMixer::AudioRendererMixer(const AudioParameters& output_params, 52 AudioRendererMixer::AudioRendererMixer(const AudioParameters& output_params,
53 scoped_refptr<AudioRendererSink> sink, 53 scoped_refptr<AudioRendererSink> sink,
54 const UmaLogCallback& log_callback) 54 const UmaLogCallback& log_callback)
55 : output_params_(output_params), 55 : output_params_(output_params),
56 audio_sink_(std::move(sink)), 56 audio_sink_(std::move(sink)),
57 raw_input_(nullptr),
DaleCurtis 2016/11/01 23:05:13 Why is this necessary? Instead the AudioConverter
AndyWu 2016/11/04 18:04:24 Just took a shortcut, since none of these function
AndyWu 2016/11/04 19:43:48 You are right, the change is not necessary.
57 master_converter_(output_params, output_params, true), 58 master_converter_(output_params, output_params, true),
58 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)), 59 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)),
59 last_play_time_(base::TimeTicks::Now()), 60 last_play_time_(base::TimeTicks::Now()),
60 // Initialize |playing_| to true since Start() results in an auto-play. 61 // Initialize |playing_| to true since Start() results in an auto-play.
61 playing_(true), 62 playing_(true),
62 input_count_tracker_(new UMAMaxValueTracker(log_callback)) { 63 input_count_tracker_(new UMAMaxValueTracker(log_callback)) {
63 DCHECK(audio_sink_); 64 DCHECK(audio_sink_);
64 audio_sink_->Initialize(output_params, this); 65 audio_sink_->Initialize(output_params, this);
65 audio_sink_->Start(); 66 audio_sink_->Start();
66 } 67 }
(...skipping 10 matching lines...) Expand all
77 78
78 void AudioRendererMixer::AddMixerInput(const AudioParameters& input_params, 79 void AudioRendererMixer::AddMixerInput(const AudioParameters& input_params,
79 AudioConverter::InputCallback* input) { 80 AudioConverter::InputCallback* input) {
80 base::AutoLock auto_lock(lock_); 81 base::AutoLock auto_lock(lock_);
81 if (!playing_) { 82 if (!playing_) {
82 playing_ = true; 83 playing_ = true;
83 last_play_time_ = base::TimeTicks::Now(); 84 last_play_time_ = base::TimeTicks::Now();
84 audio_sink_->Play(); 85 audio_sink_->Play();
85 } 86 }
86 87
88 if (input_params.IsRawFormat()) {
89 DCHECK(input);
90 DCHECK(!raw_input_);
91
92 raw_input_ = input;
93 return;
94 }
95
87 int input_sample_rate = input_params.sample_rate(); 96 int input_sample_rate = input_params.sample_rate();
88 if (is_master_sample_rate(input_sample_rate)) { 97 if (is_master_sample_rate(input_sample_rate)) {
89 master_converter_.AddInput(input); 98 master_converter_.AddInput(input);
90 } else { 99 } else {
91 AudioConvertersMap::iterator converter = 100 AudioConvertersMap::iterator converter =
92 converters_.find(input_sample_rate); 101 converters_.find(input_sample_rate);
93 if (converter == converters_.end()) { 102 if (converter == converters_.end()) {
94 std::pair<AudioConvertersMap::iterator, bool> result = 103 std::pair<AudioConvertersMap::iterator, bool> result =
95 converters_.insert(std::make_pair( 104 converters_.insert(std::make_pair(
96 input_sample_rate, base::WrapUnique( 105 input_sample_rate, base::WrapUnique(
(...skipping 11 matching lines...) Expand all
108 } 117 }
109 118
110 input_count_tracker_->Increment(); 119 input_count_tracker_->Increment();
111 } 120 }
112 121
113 void AudioRendererMixer::RemoveMixerInput( 122 void AudioRendererMixer::RemoveMixerInput(
114 const AudioParameters& input_params, 123 const AudioParameters& input_params,
115 AudioConverter::InputCallback* input) { 124 AudioConverter::InputCallback* input) {
116 base::AutoLock auto_lock(lock_); 125 base::AutoLock auto_lock(lock_);
117 126
127 if (raw_input_ == input) {
128 raw_input_ = nullptr;
129 return;
130 }
131
118 int input_sample_rate = input_params.sample_rate(); 132 int input_sample_rate = input_params.sample_rate();
119 if (is_master_sample_rate(input_sample_rate)) { 133 if (is_master_sample_rate(input_sample_rate)) {
120 master_converter_.RemoveInput(input); 134 master_converter_.RemoveInput(input);
121 } else { 135 } else {
122 AudioConvertersMap::iterator converter = 136 AudioConvertersMap::iterator converter =
123 converters_.find(input_sample_rate); 137 converters_.find(input_sample_rate);
124 DCHECK(converter != converters_.end()); 138 DCHECK(converter != converters_.end());
125 converter->second->RemoveInput(input); 139 converter->second->RemoveInput(input);
126 if (converter->second->empty()) { 140 if (converter->second->empty()) {
127 // Remove converter when it's empty. 141 // Remove converter when it's empty.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 bool AudioRendererMixer::CurrentThreadIsRenderingThread() { 175 bool AudioRendererMixer::CurrentThreadIsRenderingThread() {
162 return audio_sink_->CurrentThreadIsRenderingThread(); 176 return audio_sink_->CurrentThreadIsRenderingThread();
163 } 177 }
164 178
165 int AudioRendererMixer::Render(AudioBus* audio_bus, 179 int AudioRendererMixer::Render(AudioBus* audio_bus,
166 uint32_t frames_delayed, 180 uint32_t frames_delayed,
167 uint32_t frames_skipped) { 181 uint32_t frames_skipped) {
168 TRACE_EVENT0("audio", "AudioRendererMixer::Render"); 182 TRACE_EVENT0("audio", "AudioRendererMixer::Render");
169 base::AutoLock auto_lock(lock_); 183 base::AutoLock auto_lock(lock_);
170 184
185 if (raw_input_) {
186 return raw_input_->ProvideInput(audio_bus, frames_delayed);
187 }
188
171 // If there are no mixer inputs and we haven't seen one for a while, pause the 189 // If there are no mixer inputs and we haven't seen one for a while, pause the
172 // sink to avoid wasting resources when media elements are present but remain 190 // sink to avoid wasting resources when media elements are present but remain
173 // in the pause state. 191 // in the pause state.
174 const base::TimeTicks now = base::TimeTicks::Now(); 192 const base::TimeTicks now = base::TimeTicks::Now();
175 if (!master_converter_.empty()) { 193 if (!master_converter_.empty()) {
176 last_play_time_ = now; 194 last_play_time_ = now;
177 } else if (now - last_play_time_ >= pause_delay_ && playing_) { 195 } else if (now - last_play_time_ >= pause_delay_ && playing_) {
178 audio_sink_->Pause(); 196 audio_sink_->Pause();
179 playing_ = false; 197 playing_ = false;
180 } 198 }
181 199
182 master_converter_.ConvertWithDelay(frames_delayed, audio_bus); 200 master_converter_.ConvertWithDelay(frames_delayed, audio_bus);
183 return audio_bus->frames(); 201 return audio_bus->frames();
184 } 202 }
185 203
186 void AudioRendererMixer::OnRenderError() { 204 void AudioRendererMixer::OnRenderError() {
187 // Call each mixer input and signal an error. 205 // Call each mixer input and signal an error.
188 base::AutoLock auto_lock(lock_); 206 base::AutoLock auto_lock(lock_);
189 for (const auto& cb : error_callbacks_) 207 for (const auto& cb : error_callbacks_)
190 cb.Run(); 208 cb.Run();
191 } 209 }
192 210
193 } // namespace media 211 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698