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/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/time/time.h" | 12 #include "base/time/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 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 AudioOutputDispatcherImpl::AudioOutputDispatcherImpl( | 18 AudioOutputDispatcherImpl::AudioOutputDispatcherImpl( |
19 AudioManager* audio_manager, | 19 AudioManager* audio_manager, |
20 const AudioParameters& params, | 20 const AudioParameters& params, |
21 const std::string& output_device_id, | 21 const std::string& output_device_id, |
22 const std::string& input_device_id, | |
23 const base::TimeDelta& close_delay) | 22 const base::TimeDelta& close_delay) |
24 : AudioOutputDispatcher(audio_manager, | 23 : AudioOutputDispatcher(audio_manager, |
25 params, | 24 params, |
26 output_device_id, | 25 output_device_id), |
27 input_device_id), | |
28 idle_proxies_(0), | 26 idle_proxies_(0), |
29 close_timer_(FROM_HERE, | 27 close_timer_(FROM_HERE, |
30 close_delay, | 28 close_delay, |
31 this, | 29 this, |
32 &AudioOutputDispatcherImpl::CloseAllIdleStreams), | 30 &AudioOutputDispatcherImpl::CloseAllIdleStreams), |
33 audio_log_( | 31 audio_log_( |
34 audio_manager->CreateAudioLog(AudioLogFactory::AUDIO_OUTPUT_STREAM)), | 32 audio_manager->CreateAudioLog(AudioLogFactory::AUDIO_OUTPUT_STREAM)), |
35 audio_stream_id_(0) {} | 33 audio_stream_id_(0) {} |
36 | 34 |
37 AudioOutputDispatcherImpl::~AudioOutputDispatcherImpl() { | 35 AudioOutputDispatcherImpl::~AudioOutputDispatcherImpl() { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 DCHECK(task_runner_->BelongsToCurrentThread()); | 122 DCHECK(task_runner_->BelongsToCurrentThread()); |
125 | 123 |
126 // Close all idle streams immediately. The |close_timer_| will handle | 124 // Close all idle streams immediately. The |close_timer_| will handle |
127 // invalidating any outstanding tasks upon its destruction. | 125 // invalidating any outstanding tasks upon its destruction. |
128 CloseAllIdleStreams(); | 126 CloseAllIdleStreams(); |
129 } | 127 } |
130 | 128 |
131 bool AudioOutputDispatcherImpl::CreateAndOpenStream() { | 129 bool AudioOutputDispatcherImpl::CreateAndOpenStream() { |
132 DCHECK(task_runner_->BelongsToCurrentThread()); | 130 DCHECK(task_runner_->BelongsToCurrentThread()); |
133 AudioOutputStream* stream = audio_manager_->MakeAudioOutputStream( | 131 AudioOutputStream* stream = audio_manager_->MakeAudioOutputStream( |
134 params_, output_device_id_, input_device_id_); | 132 params_, device_id_); |
135 if (!stream) | 133 if (!stream) |
136 return false; | 134 return false; |
137 | 135 |
138 if (!stream->Open()) { | 136 if (!stream->Open()) { |
139 stream->Close(); | 137 stream->Close(); |
140 return false; | 138 return false; |
141 } | 139 } |
142 | 140 |
143 const int stream_id = audio_stream_id_++; | 141 const int stream_id = audio_stream_id_++; |
144 audio_stream_ids_[stream] = stream_id; | 142 audio_stream_ids_[stream] = stream_id; |
145 audio_log_->OnCreated( | 143 audio_log_->OnCreated( |
146 stream_id, params_, input_device_id_, output_device_id_); | 144 stream_id, params_, device_id_); |
147 | 145 |
148 idle_streams_.push_back(stream); | 146 idle_streams_.push_back(stream); |
149 return true; | 147 return true; |
150 } | 148 } |
151 | 149 |
152 void AudioOutputDispatcherImpl::CloseAllIdleStreams() { | 150 void AudioOutputDispatcherImpl::CloseAllIdleStreams() { |
153 DCHECK(task_runner_->BelongsToCurrentThread()); | 151 DCHECK(task_runner_->BelongsToCurrentThread()); |
154 CloseIdleStreams(0); | 152 CloseIdleStreams(0); |
155 } | 153 } |
156 | 154 |
(...skipping 20 matching lines...) Expand all Loading... |
177 | 175 |
178 void AudioOutputDispatcherImpl::RestartStreamsForWedgeFix() { | 176 void AudioOutputDispatcherImpl::RestartStreamsForWedgeFix() { |
179 DCHECK(task_runner_->BelongsToCurrentThread()); | 177 DCHECK(task_runner_->BelongsToCurrentThread()); |
180 | 178 |
181 // Should only be called when the dispatcher is used with fake streams which | 179 // Should only be called when the dispatcher is used with fake streams which |
182 // don't need to be shutdown or restarted. | 180 // don't need to be shutdown or restarted. |
183 CHECK_EQ(params_.format(), AudioParameters::AUDIO_FAKE); | 181 CHECK_EQ(params_.format(), AudioParameters::AUDIO_FAKE); |
184 } | 182 } |
185 | 183 |
186 } // namespace media | 184 } // namespace media |
OLD | NEW |