| 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_impl.h" | 5 #include "media/audio/audio_output_dispatcher_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_output_proxy.h" | 14 #include "media/audio/audio_output_proxy.h" |
| 15 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 AudioOutputDispatcherImpl::AudioOutputDispatcherImpl( | 19 AudioOutputDispatcherImpl::AudioOutputDispatcherImpl( |
| 20 AudioManager* audio_manager, | 20 AudioManager* audio_manager, |
| 21 const AudioParameters& params, | 21 const AudioParameters& params, |
| 22 const std::string& input_device_id, |
| 22 const base::TimeDelta& close_delay) | 23 const base::TimeDelta& close_delay) |
| 23 : AudioOutputDispatcher(audio_manager, params), | 24 : AudioOutputDispatcher(audio_manager, params, input_device_id), |
| 24 pause_delay_(base::TimeDelta::FromMicroseconds( | 25 pause_delay_(base::TimeDelta::FromMicroseconds( |
| 25 2 * params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / | 26 2 * params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / |
| 26 static_cast<float>(params.sample_rate()))), | 27 static_cast<float>(params.sample_rate()))), |
| 27 paused_proxies_(0), | 28 paused_proxies_(0), |
| 28 weak_this_(this), | 29 weak_this_(this), |
| 29 close_timer_(FROM_HERE, | 30 close_timer_(FROM_HERE, |
| 30 close_delay, | 31 close_delay, |
| 31 weak_this_.GetWeakPtr(), | 32 weak_this_.GetWeakPtr(), |
| 32 &AudioOutputDispatcherImpl::ClosePendingStreams) { | 33 &AudioOutputDispatcherImpl::ClosePendingStreams) { |
| 33 } | 34 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 idle_streams_.clear(); | 160 idle_streams_.clear(); |
| 160 | 161 |
| 161 it = pausing_streams_.begin(); | 162 it = pausing_streams_.begin(); |
| 162 for (; it != pausing_streams_.end(); ++it) | 163 for (; it != pausing_streams_.end(); ++it) |
| 163 (*it)->Close(); | 164 (*it)->Close(); |
| 164 pausing_streams_.clear(); | 165 pausing_streams_.clear(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool AudioOutputDispatcherImpl::CreateAndOpenStream() { | 168 bool AudioOutputDispatcherImpl::CreateAndOpenStream() { |
| 168 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 169 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 169 AudioOutputStream* stream = audio_manager_->MakeAudioOutputStream(params_); | 170 AudioOutputStream* stream = audio_manager_->MakeAudioOutputStream( |
| 171 params_, input_device_id_); |
| 170 if (!stream) | 172 if (!stream) |
| 171 return false; | 173 return false; |
| 172 | 174 |
| 173 if (!stream->Open()) { | 175 if (!stream->Open()) { |
| 174 stream->Close(); | 176 stream->Close(); |
| 175 return false; | 177 return false; |
| 176 } | 178 } |
| 177 idle_streams_.push_back(stream); | 179 idle_streams_.push_back(stream); |
| 178 return true; | 180 return true; |
| 179 } | 181 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 193 // This method is called by |close_timer_|. | 195 // This method is called by |close_timer_|. |
| 194 void AudioOutputDispatcherImpl::ClosePendingStreams() { | 196 void AudioOutputDispatcherImpl::ClosePendingStreams() { |
| 195 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 197 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 196 while (!idle_streams_.empty()) { | 198 while (!idle_streams_.empty()) { |
| 197 idle_streams_.back()->Close(); | 199 idle_streams_.back()->Close(); |
| 198 idle_streams_.pop_back(); | 200 idle_streams_.pop_back(); |
| 199 } | 201 } |
| 200 } | 202 } |
| 201 | 203 |
| 202 } // namespace media | 204 } // namespace media |
| OLD | NEW |