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 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 enum { kPauseDelaySeconds = 10 }; | 18 enum { kPauseDelaySeconds = 10 }; |
18 | 19 |
19 // 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 |
20 // 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 |
21 // lock. | 22 // lock. |
22 class AudioRendererMixer::UMAMaxValueTracker { | 23 class AudioRendererMixer::UMAMaxValueTracker { |
23 public: | 24 public: |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return audio_sink_->GetOutputDeviceInfo(); | 158 return audio_sink_->GetOutputDeviceInfo(); |
158 } | 159 } |
159 | 160 |
160 bool AudioRendererMixer::CurrentThreadIsRenderingThread() { | 161 bool AudioRendererMixer::CurrentThreadIsRenderingThread() { |
161 return audio_sink_->CurrentThreadIsRenderingThread(); | 162 return audio_sink_->CurrentThreadIsRenderingThread(); |
162 } | 163 } |
163 | 164 |
164 int AudioRendererMixer::Render(AudioBus* audio_bus, | 165 int AudioRendererMixer::Render(AudioBus* audio_bus, |
165 uint32_t frames_delayed, | 166 uint32_t frames_delayed, |
166 uint32_t frames_skipped) { | 167 uint32_t frames_skipped) { |
| 168 TRACE_EVENT0("audio", "AudioRendererMixer::Render"); |
167 base::AutoLock auto_lock(lock_); | 169 base::AutoLock auto_lock(lock_); |
168 | 170 |
169 // 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 |
170 // 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 |
171 // in the pause state. | 173 // in the pause state. |
172 const base::TimeTicks now = base::TimeTicks::Now(); | 174 const base::TimeTicks now = base::TimeTicks::Now(); |
173 if (!master_converter_.empty()) { | 175 if (!master_converter_.empty()) { |
174 last_play_time_ = now; | 176 last_play_time_ = now; |
175 } else if (now - last_play_time_ >= pause_delay_ && playing_) { | 177 } else if (now - last_play_time_ >= pause_delay_ && playing_) { |
176 audio_sink_->Pause(); | 178 audio_sink_->Pause(); |
177 playing_ = false; | 179 playing_ = false; |
178 } | 180 } |
179 | 181 |
180 master_converter_.ConvertWithDelay(frames_delayed, audio_bus); | 182 master_converter_.ConvertWithDelay(frames_delayed, audio_bus); |
181 return audio_bus->frames(); | 183 return audio_bus->frames(); |
182 } | 184 } |
183 | 185 |
184 void AudioRendererMixer::OnRenderError() { | 186 void AudioRendererMixer::OnRenderError() { |
185 // Call each mixer input and signal an error. | 187 // Call each mixer input and signal an error. |
186 base::AutoLock auto_lock(lock_); | 188 base::AutoLock auto_lock(lock_); |
187 for (const auto& cb : error_callbacks_) | 189 for (const auto& cb : error_callbacks_) |
188 cb.Run(); | 190 cb.Run(); |
189 } | 191 } |
190 | 192 |
191 } // namespace media | 193 } // namespace media |
OLD | NEW |