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_resampler.h" | 5 #include "media/audio/audio_output_resampler.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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 DCHECK(message_loop_->BelongsToCurrentThread()); | 287 DCHECK(message_loop_->BelongsToCurrentThread()); |
288 | 288 |
289 // No AudioOutputProxy objects should hold a reference to us when we get | 289 // No AudioOutputProxy objects should hold a reference to us when we get |
290 // to this stage. | 290 // to this stage. |
291 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference"; | 291 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference"; |
292 | 292 |
293 dispatcher_->Shutdown(); | 293 dispatcher_->Shutdown(); |
294 DCHECK(callbacks_.empty()); | 294 DCHECK(callbacks_.empty()); |
295 } | 295 } |
296 | 296 |
| 297 void AudioOutputResampler::CloseStreamsForWedgeFix() { |
| 298 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 299 |
| 300 // Stop and close all active streams. Once all streams across all dispatchers |
| 301 // have been closed the AudioManager will call RestartStreamsForWedgeFix(). |
| 302 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); |
| 303 ++it) { |
| 304 dispatcher_->StopStream(it->first); |
| 305 dispatcher_->CloseStream(it->first); |
| 306 } |
| 307 |
| 308 // Close all idle streams as well. |
| 309 dispatcher_->CloseStreamsForWedgeFix(); |
| 310 } |
| 311 |
| 312 void AudioOutputResampler::RestartStreamsForWedgeFix() { |
| 313 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 314 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); |
| 315 ++it) { |
| 316 dispatcher_->OpenStream(); |
| 317 dispatcher_->StartStream(it->second, it->first); |
| 318 } |
| 319 } |
| 320 |
297 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, | 321 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, |
298 const AudioParameters& output_params) | 322 const AudioParameters& output_params) |
299 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / | 323 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / |
300 output_params.GetBytesPerSecond()), | 324 output_params.GetBytesPerSecond()), |
301 source_callback_(NULL), | 325 source_callback_(NULL), |
302 source_bus_(NULL), | 326 source_bus_(NULL), |
303 input_bytes_per_second_(input_params.GetBytesPerSecond()), | 327 input_bytes_per_second_(input_params.GetBytesPerSecond()), |
304 audio_converter_(input_params, output_params, false) {} | 328 audio_converter_(input_params, output_params, false) {} |
305 | 329 |
306 OnMoreDataConverter::~OnMoreDataConverter() { | 330 OnMoreDataConverter::~OnMoreDataConverter() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 if (frames > 0 && frames < dest->frames()) | 391 if (frames > 0 && frames < dest->frames()) |
368 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 392 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
369 return frames > 0 ? 1 : 0; | 393 return frames > 0 ? 1 : 0; |
370 } | 394 } |
371 | 395 |
372 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 396 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
373 source_callback_->OnError(stream); | 397 source_callback_->OnError(stream); |
374 } | 398 } |
375 | 399 |
376 } // namespace media | 400 } // namespace media |
OLD | NEW |