| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 AudioOutputResampler::AudioOutputResampler(AudioManager* audio_manager, | 73 AudioOutputResampler::AudioOutputResampler(AudioManager* audio_manager, |
| 74 const AudioParameters& input_params, | 74 const AudioParameters& input_params, |
| 75 const AudioParameters& output_params, | 75 const AudioParameters& output_params, |
| 76 const base::TimeDelta& close_delay) | 76 const base::TimeDelta& close_delay) |
| 77 : AudioOutputDispatcher(audio_manager, input_params), | 77 : AudioOutputDispatcher(audio_manager, input_params), |
| 78 source_callback_(NULL), | 78 source_callback_(NULL), |
| 79 io_ratio_(1), | 79 io_ratio_(1), |
| 80 close_delay_(close_delay), | 80 close_delay_(close_delay), |
| 81 outstanding_audio_bytes_(0), | 81 outstanding_audio_bytes_(0), |
| 82 output_params_(output_params) { | 82 output_params_(output_params) { |
| 83 DCHECK_EQ(output_params_.format(), AudioParameters::AUDIO_PCM_LOW_LATENCY); |
| 83 Initialize(); | 84 Initialize(); |
| 84 // Record UMA statistics for the hardware configuration. | 85 // Record UMA statistics for the hardware configuration. |
| 85 RecordStats(output_params_); | 86 RecordStats(output_params_); |
| 86 } | 87 } |
| 87 | 88 |
| 88 AudioOutputResampler::~AudioOutputResampler() {} | 89 AudioOutputResampler::~AudioOutputResampler() {} |
| 89 | 90 |
| 90 void AudioOutputResampler::Initialize() { | 91 void AudioOutputResampler::Initialize() { |
| 91 io_ratio_ = 1; | 92 io_ratio_ = 1; |
| 92 | 93 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 params_.frames_per_buffer() != output_params_.frames_per_buffer()) { | 127 params_.frames_per_buffer() != output_params_.frames_per_buffer()) { |
| 127 DVLOG(1) << "Rebuffering from " << params_.frames_per_buffer() | 128 DVLOG(1) << "Rebuffering from " << params_.frames_per_buffer() |
| 128 << " to " << output_params_.frames_per_buffer(); | 129 << " to " << output_params_.frames_per_buffer(); |
| 129 audio_fifo_.reset(new AudioPullFifo( | 130 audio_fifo_.reset(new AudioPullFifo( |
| 130 params_.channels(), params_.frames_per_buffer(), base::Bind( | 131 params_.channels(), params_.frames_per_buffer(), base::Bind( |
| 131 &AudioOutputResampler::SourceCallback_Locked, | 132 &AudioOutputResampler::SourceCallback_Locked, |
| 132 base::Unretained(this)))); | 133 base::Unretained(this)))); |
| 133 } | 134 } |
| 134 | 135 |
| 135 DVLOG(1) << "I/O ratio is " << io_ratio_; | 136 DVLOG(1) << "I/O ratio is " << io_ratio_; |
| 137 } else { |
| 138 DVLOG(1) << "Input and output params are the same; in pass-through mode."; |
| 136 } | 139 } |
| 137 | 140 |
| 138 // TODO(dalecurtis): All this code should be merged into AudioOutputMixer once | 141 // TODO(dalecurtis): All this code should be merged into AudioOutputMixer once |
| 139 // we've stabilized the issues there. | 142 // we've stabilized the issues there. |
| 140 dispatcher_ = new AudioOutputDispatcherImpl( | 143 dispatcher_ = new AudioOutputDispatcherImpl( |
| 141 audio_manager_, output_params_, close_delay_); | 144 audio_manager_, output_params_, close_delay_); |
| 142 } | 145 } |
| 143 | 146 |
| 144 bool AudioOutputResampler::OpenStream() { | 147 bool AudioOutputResampler::OpenStream() { |
| 145 if (dispatcher_->OpenStream()) { | 148 if (dispatcher_->OpenStream()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 164 | 167 |
| 165 // Record UMA statistics about the hardware which triggered the failure so we | 168 // Record UMA statistics about the hardware which triggered the failure so we |
| 166 // can debug and triage later. | 169 // can debug and triage later. |
| 167 UMA_HISTOGRAM_BOOLEAN("Media.FallbackToHighLatencyAudioPath", true); | 170 UMA_HISTOGRAM_BOOLEAN("Media.FallbackToHighLatencyAudioPath", true); |
| 168 RecordFallbackStats(output_params_); | 171 RecordFallbackStats(output_params_); |
| 169 | 172 |
| 170 // Open failed! Attempt to open the output device in high latency mode using | 173 // Open failed! Attempt to open the output device in high latency mode using |
| 171 // a new high latency appropriate buffer size. |kMinLowLatencyFrameSize| is | 174 // a new high latency appropriate buffer size. |kMinLowLatencyFrameSize| is |
| 172 // arbitrarily based on Pepper Flash's MAXIMUM frame size for low latency. | 175 // arbitrarily based on Pepper Flash's MAXIMUM frame size for low latency. |
| 173 static const int kMinLowLatencyFrameSize = 2048; | 176 static const int kMinLowLatencyFrameSize = 2048; |
| 174 int frames_per_buffer = std::max( | 177 int frames_per_buffer = std::min( |
| 175 std::min(params_.frames_per_buffer(), kMinLowLatencyFrameSize), | 178 std::max(params_.frames_per_buffer(), kMinLowLatencyFrameSize), |
| 176 static_cast<int>(GetHighLatencyOutputBufferSize(params_.sample_rate()))); | 179 static_cast<int>(GetHighLatencyOutputBufferSize(params_.sample_rate()))); |
| 177 | 180 |
| 178 output_params_ = AudioParameters( | 181 output_params_ = AudioParameters( |
| 179 AudioParameters::AUDIO_PCM_LINEAR, params_.channel_layout(), | 182 AudioParameters::AUDIO_PCM_LINEAR, params_.channel_layout(), |
| 180 params_.sample_rate(), params_.bits_per_sample(), frames_per_buffer); | 183 params_.sample_rate(), params_.bits_per_sample(), frames_per_buffer); |
| 181 Initialize(); | 184 Initialize(); |
| 182 | 185 |
| 183 // Retry, if this fails, there's nothing left to do but report the error back. | 186 // Retry, if this fails, there's nothing left to do but report the error back. |
| 184 return dispatcher_->OpenStream(); | 187 return dispatcher_->OpenStream(); |
| 185 } | 188 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 source_callback_->OnError(stream, code); | 304 source_callback_->OnError(stream, code); |
| 302 } | 305 } |
| 303 | 306 |
| 304 void AudioOutputResampler::WaitTillDataReady() { | 307 void AudioOutputResampler::WaitTillDataReady() { |
| 305 base::AutoLock auto_lock(source_lock_); | 308 base::AutoLock auto_lock(source_lock_); |
| 306 if (source_callback_ && !outstanding_audio_bytes_) | 309 if (source_callback_ && !outstanding_audio_bytes_) |
| 307 source_callback_->WaitTillDataReady(); | 310 source_callback_->WaitTillDataReady(); |
| 308 } | 311 } |
| 309 | 312 |
| 310 } // namespace media | 313 } // namespace media |
| OLD | NEW |