OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chromecast/media/audio/cast_audio_mixer.h" | 5 #include "chromecast/media/audio/cast_audio_mixer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" |
10 #include "chromecast/media/audio/cast_audio_manager.h" | 11 #include "chromecast/media/audio/cast_audio_manager.h" |
11 #include "chromecast/media/audio/cast_audio_output_stream.h" | 12 #include "chromecast/media/audio/cast_audio_output_stream.h" |
12 #include "media/base/audio_timestamp_helper.h" | 13 #include "media/base/audio_timestamp_helper.h" |
13 #include "media/base/channel_layout.h" | 14 #include "media/base/channel_layout.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 const int kBitsPerSample = 16; | 17 const int kBitsPerSample = 16; |
17 const int kFramesPerBuffer = 1024; | 18 const int kFramesPerBuffer = 1024; |
18 const int kSampleRate = 48000; | 19 const int kSampleRate = 48000; |
19 } // namespace | 20 } // namespace |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 CastAudioMixer::~CastAudioMixer() {} | 195 CastAudioMixer::~CastAudioMixer() {} |
195 | 196 |
196 ::media::AudioOutputStream* CastAudioMixer::MakeStream( | 197 ::media::AudioOutputStream* CastAudioMixer::MakeStream( |
197 const ::media::AudioParameters& params) { | 198 const ::media::AudioParameters& params) { |
198 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); | 199 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); |
199 return new MixerProxyStream(params, output_params_, this); | 200 return new MixerProxyStream(params, output_params_, this); |
200 } | 201 } |
201 | 202 |
202 bool CastAudioMixer::Register(MixerProxyStream* proxy_stream) { | 203 bool CastAudioMixer::Register(MixerProxyStream* proxy_stream) { |
203 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); | 204 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); |
204 DCHECK(std::find(proxy_streams_.begin(), proxy_streams_.end(), | 205 DCHECK(!base::ContainsValue(proxy_streams_, proxy_stream)); |
205 proxy_stream) == proxy_streams_.end()); | |
206 | 206 |
207 // Do not allow opening new streams while in error state. | 207 // Do not allow opening new streams while in error state. |
208 if (error_) | 208 if (error_) |
209 return false; | 209 return false; |
210 | 210 |
211 // Initialize a backend instance if there are no output streams. | 211 // Initialize a backend instance if there are no output streams. |
212 // The stream will fail to register if the CastAudioOutputStream | 212 // The stream will fail to register if the CastAudioOutputStream |
213 // is not opened properly. | 213 // is not opened properly. |
214 if (proxy_streams_.empty()) { | 214 if (proxy_streams_.empty()) { |
215 DCHECK(!output_stream_); | 215 DCHECK(!output_stream_); |
216 output_stream_ = audio_manager_->MakeMixerOutputStream(output_params_); | 216 output_stream_ = audio_manager_->MakeMixerOutputStream(output_params_); |
217 if (!output_stream_->Open()) { | 217 if (!output_stream_->Open()) { |
218 output_stream_->Close(); | 218 output_stream_->Close(); |
219 output_stream_ = nullptr; | 219 output_stream_ = nullptr; |
220 return false; | 220 return false; |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 proxy_streams_.insert(proxy_stream); | 224 proxy_streams_.insert(proxy_stream); |
225 return true; | 225 return true; |
226 } | 226 } |
227 | 227 |
228 void CastAudioMixer::Unregister(MixerProxyStream* proxy_stream) { | 228 void CastAudioMixer::Unregister(MixerProxyStream* proxy_stream) { |
229 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); | 229 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); |
230 DCHECK(std::find(proxy_streams_.begin(), proxy_streams_.end(), | 230 DCHECK(base::ContainsValue(proxy_streams_, proxy_stream)); |
231 proxy_stream) != proxy_streams_.end()); | |
232 | 231 |
233 proxy_streams_.erase(proxy_stream); | 232 proxy_streams_.erase(proxy_stream); |
234 | 233 |
235 // Reset the state once all streams have been unregistered. | 234 // Reset the state once all streams have been unregistered. |
236 if (proxy_streams_.empty()) { | 235 if (proxy_streams_.empty()) { |
237 DCHECK(mixer_->empty()); | 236 DCHECK(mixer_->empty()); |
238 if (output_stream_) | 237 if (output_stream_) |
239 output_stream_->Close(); | 238 output_stream_->Close(); |
240 output_stream_ = nullptr; | 239 output_stream_ = nullptr; |
241 error_ = false; | 240 error_ = false; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void CastAudioMixer::HandleError() { | 290 void CastAudioMixer::HandleError() { |
292 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); | 291 DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_); |
293 | 292 |
294 error_ = true; | 293 error_ = true; |
295 for (auto it = proxy_streams_.begin(); it != proxy_streams_.end(); ++it) | 294 for (auto it = proxy_streams_.begin(); it != proxy_streams_.end(); ++it) |
296 (*it)->OnError(); | 295 (*it)->OnError(); |
297 } | 296 } |
298 | 297 |
299 } // namespace media | 298 } // namespace media |
300 } // namespace chromecast | 299 } // namespace chromecast |
OLD | NEW |