| 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/audio/audio_output_dispatcher.h" | 5 #include "media/audio/audio_output_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "media/audio/audio_io.h" | 11 #include "media/audio/audio_io.h" |
| 12 | 12 |
| 13 AudioOutputDispatcher::AudioOutputDispatcher( | 13 AudioOutputDispatcher::AudioOutputDispatcher( |
| 14 AudioManager* audio_manager, const AudioParameters& params, | 14 AudioManager* audio_manager, const AudioParameters& params, |
| 15 base::TimeDelta close_delay) | 15 base::TimeDelta close_delay) |
| 16 : audio_manager_(audio_manager), | 16 : audio_manager_(audio_manager), |
| 17 message_loop_(MessageLoop::current()), | 17 message_loop_(MessageLoop::current()), |
| 18 params_(params), | 18 params_(params), |
| 19 pause_delay_(base::TimeDelta::FromMilliseconds( | 19 pause_delay_(base::TimeDelta::FromMilliseconds( |
| 20 2 * params.samples_per_packet * | 20 2 * params.frames_per_buffer() * |
| 21 base::Time::kMillisecondsPerSecond / params.sample_rate)), | 21 base::Time::kMillisecondsPerSecond / params.sample_rate())), |
| 22 paused_proxies_(0), | 22 paused_proxies_(0), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), | 23 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), |
| 24 close_timer_(FROM_HERE, | 24 close_timer_(FROM_HERE, |
| 25 close_delay, | 25 close_delay, |
| 26 weak_this_.GetWeakPtr(), | 26 weak_this_.GetWeakPtr(), |
| 27 &AudioOutputDispatcher::ClosePendingStreams) { | 27 &AudioOutputDispatcher::ClosePendingStreams) { |
| 28 // We expect to be instantiated on the audio thread. Otherwise the | 28 // We expect to be instantiated on the audio thread. Otherwise the |
| 29 // message_loop_ member will point to the wrong message loop! | 29 // message_loop_ member will point to the wrong message loop! |
| 30 DCHECK(audio_manager->GetMessageLoop()->BelongsToCurrentThread()); | 30 DCHECK(audio_manager->GetMessageLoop()->BelongsToCurrentThread()); |
| 31 } | 31 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 // This method is called by |close_timer_|. | 162 // This method is called by |close_timer_|. |
| 163 void AudioOutputDispatcher::ClosePendingStreams() { | 163 void AudioOutputDispatcher::ClosePendingStreams() { |
| 164 DCHECK_EQ(MessageLoop::current(), message_loop_); | 164 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 165 | 165 |
| 166 while (!idle_streams_.empty()) { | 166 while (!idle_streams_.empty()) { |
| 167 idle_streams_.back()->Close(); | 167 idle_streams_.back()->Close(); |
| 168 idle_streams_.pop_back(); | 168 idle_streams_.pop_back(); |
| 169 } | 169 } |
| 170 } | 170 } |
| OLD | NEW |