| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if (it->Equals(error_cb)) { | 64 if (it->Equals(error_cb)) { |
| 65 error_callbacks_.erase(it); | 65 error_callbacks_.erase(it); |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 // An error callback should always exist when called. | 70 // An error callback should always exist when called. |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void AudioRendererMixer::SwitchOutputDevice( |
| 75 const std::string& device_id, |
| 76 const GURL& security_origin, |
| 77 const base::Callback<void(int)>& callback) { |
| 78 DVLOG(1) << __FUNCTION__ << "(" << device_id << ", " |
| 79 << security_origin << ")"; |
| 80 base::AutoLock auto_lock(lock_); |
| 81 audio_sink_->SwitchOutputDevice(device_id, security_origin, callback); |
| 82 } |
| 83 |
| 84 |
| 74 int AudioRendererMixer::Render(AudioBus* audio_bus, | 85 int AudioRendererMixer::Render(AudioBus* audio_bus, |
| 75 int audio_delay_milliseconds) { | 86 int audio_delay_milliseconds) { |
| 76 base::AutoLock auto_lock(lock_); | 87 base::AutoLock auto_lock(lock_); |
| 77 | 88 |
| 78 // If there are no mixer inputs and we haven't seen one for a while, pause the | 89 // If there are no mixer inputs and we haven't seen one for a while, pause the |
| 79 // sink to avoid wasting resources when media elements are present but remain | 90 // sink to avoid wasting resources when media elements are present but remain |
| 80 // in the pause state. | 91 // in the pause state. |
| 81 const base::TimeTicks now = base::TimeTicks::Now(); | 92 const base::TimeTicks now = base::TimeTicks::Now(); |
| 82 if (!audio_converter_.empty()) { | 93 if (!audio_converter_.empty()) { |
| 83 last_play_time_ = now; | 94 last_play_time_ = now; |
| 84 } else if (now - last_play_time_ >= pause_delay_ && playing_) { | 95 } else if (now - last_play_time_ >= pause_delay_ && playing_) { |
| 85 audio_sink_->Pause(); | 96 audio_sink_->Pause(); |
| 86 playing_ = false; | 97 playing_ = false; |
| 87 } | 98 } |
| 88 | 99 |
| 89 audio_converter_.ConvertWithDelay( | 100 audio_converter_.ConvertWithDelay( |
| 90 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds), audio_bus); | 101 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds), audio_bus); |
| 91 return audio_bus->frames(); | 102 return audio_bus->frames(); |
| 92 } | 103 } |
| 93 | 104 |
| 94 void AudioRendererMixer::OnRenderError() { | 105 void AudioRendererMixer::OnRenderError() { |
| 95 // Call each mixer input and signal an error. | 106 // Call each mixer input and signal an error. |
| 96 base::AutoLock auto_lock(lock_); | 107 base::AutoLock auto_lock(lock_); |
| 97 for (const auto& cb : error_callbacks_) | 108 for (const auto& cb : error_callbacks_) |
| 98 cb.Run(); | 109 cb.Run(); |
| 99 } | 110 } |
| 100 | 111 |
| 101 } // namespace media | 112 } // namespace media |
| OLD | NEW |