| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 DCHECK(message_loop_->BelongsToCurrentThread()); | 284 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 285 | 285 |
| 286 // No AudioOutputProxy objects should hold a reference to us when we get | 286 // No AudioOutputProxy objects should hold a reference to us when we get |
| 287 // to this stage. | 287 // to this stage. |
| 288 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference"; | 288 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference"; |
| 289 | 289 |
| 290 dispatcher_->Shutdown(); | 290 dispatcher_->Shutdown(); |
| 291 DCHECK(callbacks_.empty()); | 291 DCHECK(callbacks_.empty()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void AudioOutputResampler::CloseStreamsForWedgeFix() { | |
| 295 DCHECK(message_loop_->BelongsToCurrentThread()); | |
| 296 | |
| 297 // Stop and close all active streams. Once all streams across all dispatchers | |
| 298 // have been closed the AudioManager will call RestartStreamsForWedgeFix(). | |
| 299 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); | |
| 300 ++it) { | |
| 301 dispatcher_->StopStream(it->first); | |
| 302 dispatcher_->CloseStream(it->first); | |
| 303 } | |
| 304 | |
| 305 // Close all idle streams as well. | |
| 306 dispatcher_->CloseStreamsForWedgeFix(); | |
| 307 } | |
| 308 | |
| 309 void AudioOutputResampler::RestartStreamsForWedgeFix() { | |
| 310 DCHECK(message_loop_->BelongsToCurrentThread()); | |
| 311 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); | |
| 312 ++it) { | |
| 313 dispatcher_->OpenStream(); | |
| 314 dispatcher_->StartStream(it->second, it->first); | |
| 315 } | |
| 316 } | |
| 317 | |
| 318 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, | 294 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, |
| 319 const AudioParameters& output_params) | 295 const AudioParameters& output_params) |
| 320 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / | 296 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / |
| 321 output_params.GetBytesPerSecond()), | 297 output_params.GetBytesPerSecond()), |
| 322 source_callback_(NULL), | 298 source_callback_(NULL), |
| 323 input_bytes_per_second_(input_params.GetBytesPerSecond()), | 299 input_bytes_per_second_(input_params.GetBytesPerSecond()), |
| 324 audio_converter_(input_params, output_params, false) {} | 300 audio_converter_(input_params, output_params, false) {} |
| 325 | 301 |
| 326 OnMoreDataConverter::~OnMoreDataConverter() { | 302 OnMoreDataConverter::~OnMoreDataConverter() { |
| 327 // Ensure Stop() has been called so we don't end up with an AudioOutputStream | 303 // Ensure Stop() has been called so we don't end up with an AudioOutputStream |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 if (frames > 0 && frames < dest->frames()) | 361 if (frames > 0 && frames < dest->frames()) |
| 386 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 362 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
| 387 return frames > 0 ? 1 : 0; | 363 return frames > 0 ? 1 : 0; |
| 388 } | 364 } |
| 389 | 365 |
| 390 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 366 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
| 391 source_callback_->OnError(stream); | 367 source_callback_->OnError(stream); |
| 392 } | 368 } |
| 393 | 369 |
| 394 } // namespace media | 370 } // namespace media |
| OLD | NEW |