OLD | NEW |
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 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "media/base/audio_timestamp_helper.h" | |
16 | 15 |
17 namespace media { | 16 namespace media { |
18 | 17 |
19 enum { kPauseDelaySeconds = 10 }; | 18 enum { kPauseDelaySeconds = 10 }; |
20 | 19 |
21 // Tracks the maximum value of a counter and logs it into a UMA histogram upon | 20 // Tracks the maximum value of a counter and logs it into a UMA histogram upon |
22 // each increase of the maximum. NOT thread-safe, make sure it is used under | 21 // each increase of the maximum. NOT thread-safe, make sure it is used under |
23 // lock. | 22 // lock. |
24 class AudioRendererMixer::UMAMaxValueTracker { | 23 class AudioRendererMixer::UMAMaxValueTracker { |
25 public: | 24 public: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 155 |
157 OutputDeviceInfo AudioRendererMixer::GetOutputDeviceInfo() { | 156 OutputDeviceInfo AudioRendererMixer::GetOutputDeviceInfo() { |
158 DVLOG(1) << __func__; | 157 DVLOG(1) << __func__; |
159 return audio_sink_->GetOutputDeviceInfo(); | 158 return audio_sink_->GetOutputDeviceInfo(); |
160 } | 159 } |
161 | 160 |
162 bool AudioRendererMixer::CurrentThreadIsRenderingThread() { | 161 bool AudioRendererMixer::CurrentThreadIsRenderingThread() { |
163 return audio_sink_->CurrentThreadIsRenderingThread(); | 162 return audio_sink_->CurrentThreadIsRenderingThread(); |
164 } | 163 } |
165 | 164 |
166 int AudioRendererMixer::Render(base::TimeDelta delay, | 165 int AudioRendererMixer::Render(AudioBus* audio_bus, |
167 base::TimeTicks delay_timestamp, | 166 uint32_t frames_delayed, |
168 int prior_frames_skipped, | 167 uint32_t frames_skipped) { |
169 AudioBus* audio_bus) { | |
170 TRACE_EVENT0("audio", "AudioRendererMixer::Render"); | 168 TRACE_EVENT0("audio", "AudioRendererMixer::Render"); |
171 base::AutoLock auto_lock(lock_); | 169 base::AutoLock auto_lock(lock_); |
172 | 170 |
173 // If there are no mixer inputs and we haven't seen one for a while, pause the | 171 // If there are no mixer inputs and we haven't seen one for a while, pause the |
174 // sink to avoid wasting resources when media elements are present but remain | 172 // sink to avoid wasting resources when media elements are present but remain |
175 // in the pause state. | 173 // in the pause state. |
176 const base::TimeTicks now = base::TimeTicks::Now(); | 174 const base::TimeTicks now = base::TimeTicks::Now(); |
177 if (!master_converter_.empty()) { | 175 if (!master_converter_.empty()) { |
178 last_play_time_ = now; | 176 last_play_time_ = now; |
179 } else if (now - last_play_time_ >= pause_delay_ && playing_) { | 177 } else if (now - last_play_time_ >= pause_delay_ && playing_) { |
180 audio_sink_->Pause(); | 178 audio_sink_->Pause(); |
181 playing_ = false; | 179 playing_ = false; |
182 } | 180 } |
183 | 181 |
184 uint32_t frames_delayed = | |
185 AudioTimestampHelper::TimeToFrames(delay, output_params_.sample_rate()); | |
186 master_converter_.ConvertWithDelay(frames_delayed, audio_bus); | 182 master_converter_.ConvertWithDelay(frames_delayed, audio_bus); |
187 return audio_bus->frames(); | 183 return audio_bus->frames(); |
188 } | 184 } |
189 | 185 |
190 void AudioRendererMixer::OnRenderError() { | 186 void AudioRendererMixer::OnRenderError() { |
191 // Call each mixer input and signal an error. | 187 // Call each mixer input and signal an error. |
192 base::AutoLock auto_lock(lock_); | 188 base::AutoLock auto_lock(lock_); |
193 for (const auto& cb : error_callbacks_) | 189 for (const auto& cb : error_callbacks_) |
194 cb.Run(); | 190 cb.Run(); |
195 } | 191 } |
196 | 192 |
197 } // namespace media | 193 } // namespace media |
OLD | NEW |