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