| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // mode. |kMinLowLatencyFrameSize| is arbitrarily based on Pepper Flash's | 128 // mode. |kMinLowLatencyFrameSize| is arbitrarily based on Pepper Flash's |
| 129 // MAXIMUM frame size for low latency. | 129 // MAXIMUM frame size for low latency. |
| 130 static const int kMinLowLatencyFrameSize = 2048; | 130 static const int kMinLowLatencyFrameSize = 2048; |
| 131 const int frames_per_buffer = | 131 const int frames_per_buffer = |
| 132 std::max(params_.frames_per_buffer(), kMinLowLatencyFrameSize); | 132 std::max(params_.frames_per_buffer(), kMinLowLatencyFrameSize); |
| 133 | 133 |
| 134 output_params_ = AudioParameters( | 134 output_params_ = AudioParameters( |
| 135 AudioParameters::AUDIO_PCM_LINEAR, params_.channel_layout(), | 135 AudioParameters::AUDIO_PCM_LINEAR, params_.channel_layout(), |
| 136 params_.sample_rate(), params_.bits_per_sample(), | 136 params_.sample_rate(), params_.bits_per_sample(), |
| 137 frames_per_buffer); | 137 frames_per_buffer); |
| 138 output_device_id_ = ""; | 138 device_id_ = ""; |
| 139 Initialize(); | 139 Initialize(); |
| 140 #endif | 140 #endif |
| 141 } | 141 } |
| 142 | 142 |
| 143 AudioOutputResampler::AudioOutputResampler(AudioManager* audio_manager, | 143 AudioOutputResampler::AudioOutputResampler(AudioManager* audio_manager, |
| 144 const AudioParameters& input_params, | 144 const AudioParameters& input_params, |
| 145 const AudioParameters& output_params, | 145 const AudioParameters& output_params, |
| 146 const std::string& output_device_id, | 146 const std::string& output_device_id, |
| 147 const std::string& input_device_id, | |
| 148 const base::TimeDelta& close_delay) | 147 const base::TimeDelta& close_delay) |
| 149 : AudioOutputDispatcher(audio_manager, input_params, output_device_id, | 148 : AudioOutputDispatcher(audio_manager, input_params, output_device_id), |
| 150 input_device_id), | |
| 151 close_delay_(close_delay), | 149 close_delay_(close_delay), |
| 152 output_params_(output_params), | 150 output_params_(output_params), |
| 153 streams_opened_(false) { | 151 streams_opened_(false) { |
| 154 DCHECK(input_params.IsValid()); | 152 DCHECK(input_params.IsValid()); |
| 155 DCHECK(output_params.IsValid()); | 153 DCHECK(output_params.IsValid()); |
| 156 DCHECK_EQ(output_params_.format(), AudioParameters::AUDIO_PCM_LOW_LATENCY); | 154 DCHECK_EQ(output_params_.format(), AudioParameters::AUDIO_PCM_LOW_LATENCY); |
| 157 | 155 |
| 158 // Record UMA statistics for the hardware configuration. | 156 // Record UMA statistics for the hardware configuration. |
| 159 RecordStats(output_params); | 157 RecordStats(output_params); |
| 160 | 158 |
| 161 Initialize(); | 159 Initialize(); |
| 162 } | 160 } |
| 163 | 161 |
| 164 AudioOutputResampler::~AudioOutputResampler() { | 162 AudioOutputResampler::~AudioOutputResampler() { |
| 165 DCHECK(callbacks_.empty()); | 163 DCHECK(callbacks_.empty()); |
| 166 } | 164 } |
| 167 | 165 |
| 168 void AudioOutputResampler::Initialize() { | 166 void AudioOutputResampler::Initialize() { |
| 169 DCHECK(!streams_opened_); | 167 DCHECK(!streams_opened_); |
| 170 DCHECK(callbacks_.empty()); | 168 DCHECK(callbacks_.empty()); |
| 171 dispatcher_ = new AudioOutputDispatcherImpl( | 169 dispatcher_ = new AudioOutputDispatcherImpl( |
| 172 audio_manager_, output_params_, output_device_id_, input_device_id_, | 170 audio_manager_, output_params_, device_id_, close_delay_); |
| 173 close_delay_); | |
| 174 } | 171 } |
| 175 | 172 |
| 176 bool AudioOutputResampler::OpenStream() { | 173 bool AudioOutputResampler::OpenStream() { |
| 177 DCHECK(task_runner_->BelongsToCurrentThread()); | 174 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 178 | 175 |
| 179 if (dispatcher_->OpenStream()) { | 176 if (dispatcher_->OpenStream()) { |
| 180 // Only record the UMA statistic if we didn't fallback during construction | 177 // Only record the UMA statistic if we didn't fallback during construction |
| 181 // and only for the first stream we open. | 178 // and only for the first stream we open. |
| 182 if (!streams_opened_ && | 179 if (!streams_opened_ && |
| 183 output_params_.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 180 output_params_.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 if (frames > 0 && frames < dest->frames()) | 391 if (frames > 0 && frames < dest->frames()) |
| 395 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 392 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
| 396 return frames > 0 ? 1 : 0; | 393 return frames > 0 ? 1 : 0; |
| 397 } | 394 } |
| 398 | 395 |
| 399 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 396 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
| 400 source_callback_->OnError(stream); | 397 source_callback_->OnError(stream); |
| 401 } | 398 } |
| 402 | 399 |
| 403 } // namespace media | 400 } // namespace media |
| OLD | NEW |