| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 DCHECK(task_runner_->BelongsToCurrentThread()); | 291 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 292 | 292 |
| 293 // No AudioOutputProxy objects should hold a reference to us when we get | 293 // No AudioOutputProxy objects should hold a reference to us when we get |
| 294 // to this stage. | 294 // to this stage. |
| 295 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference"; | 295 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference"; |
| 296 | 296 |
| 297 dispatcher_->Shutdown(); | 297 dispatcher_->Shutdown(); |
| 298 DCHECK(callbacks_.empty()); | 298 DCHECK(callbacks_.empty()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void AudioOutputResampler::CloseStreamsForWedgeFix() { | |
| 302 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 303 | |
| 304 // Stop and close all active streams. Once all streams across all dispatchers | |
| 305 // have been closed the AudioManager will call RestartStreamsForWedgeFix(). | |
| 306 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); | |
| 307 ++it) { | |
| 308 if (it->second->started()) | |
| 309 dispatcher_->StopStream(it->first); | |
| 310 dispatcher_->CloseStream(it->first); | |
| 311 } | |
| 312 | |
| 313 // Close all idle streams as well. | |
| 314 dispatcher_->CloseStreamsForWedgeFix(); | |
| 315 } | |
| 316 | |
| 317 void AudioOutputResampler::RestartStreamsForWedgeFix() { | |
| 318 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 319 // By opening all streams first and then starting them one by one we ensure | |
| 320 // the dispatcher only opens streams for those which will actually be used. | |
| 321 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); | |
| 322 ++it) { | |
| 323 dispatcher_->OpenStream(); | |
| 324 } | |
| 325 for (CallbackMap::iterator it = callbacks_.begin(); it != callbacks_.end(); | |
| 326 ++it) { | |
| 327 if (it->second->started()) | |
| 328 dispatcher_->StartStream(it->second, it->first); | |
| 329 } | |
| 330 } | |
| 331 | |
| 332 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, | 301 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, |
| 333 const AudioParameters& output_params) | 302 const AudioParameters& output_params) |
| 334 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / | 303 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / |
| 335 output_params.GetBytesPerSecond()), | 304 output_params.GetBytesPerSecond()), |
| 336 source_callback_(NULL), | 305 source_callback_(NULL), |
| 337 input_bytes_per_second_(input_params.GetBytesPerSecond()), | 306 input_bytes_per_second_(input_params.GetBytesPerSecond()), |
| 338 audio_converter_(input_params, output_params, false) {} | 307 audio_converter_(input_params, output_params, false) {} |
| 339 | 308 |
| 340 OnMoreDataConverter::~OnMoreDataConverter() { | 309 OnMoreDataConverter::~OnMoreDataConverter() { |
| 341 // Ensure Stop() has been called so we don't end up with an AudioOutputStream | 310 // 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... |
| 399 if (frames > 0 && frames < dest->frames()) | 368 if (frames > 0 && frames < dest->frames()) |
| 400 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 369 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
| 401 return frames > 0 ? 1 : 0; | 370 return frames > 0 ? 1 : 0; |
| 402 } | 371 } |
| 403 | 372 |
| 404 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 373 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
| 405 source_callback_->OnError(stream); | 374 source_callback_->OnError(stream); |
| 406 } | 375 } |
| 407 | 376 |
| 408 } // namespace media | 377 } // namespace media |
| OLD | NEW |