Chromium Code Reviews| 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.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 13 #include "media/audio/audio_output_dispatcher_impl.h" | 14 #include "media/audio/audio_output_dispatcher_impl.h" |
| 14 #include "media/audio/audio_output_proxy.h" | 15 #include "media/audio/audio_output_proxy.h" |
| 15 #include "media/audio/audio_util.h" | 16 #include "media/audio/audio_util.h" |
| 17 #include "media/audio/sample_rates.h" | |
| 16 #include "media/base/audio_pull_fifo.h" | 18 #include "media/base/audio_pull_fifo.h" |
| 19 #include "media/base/limits.h" | |
| 17 #include "media/base/multi_channel_resampler.h" | 20 #include "media/base/multi_channel_resampler.h" |
| 18 | 21 |
| 22 #if defined(OS_WIN) | |
| 23 #include "media/audio/win/audio_low_latency_output_win.h" | |
| 24 #endif | |
| 25 | |
| 19 namespace media { | 26 namespace media { |
| 20 | 27 |
| 28 static void RecordStats(const AudioParameters& output_params) { | |
| 29 UMA_HISTOGRAM_ENUMERATION( | |
| 30 "Media.HardwareAudioBitsPerChannel", output_params.bits_per_sample(), | |
|
scherkus (not reviewing)
2012/09/12 13:34:50
don't you have a WASAPI version of this?
DaleCurtis
2012/09/12 14:03:52
Not sure I'm landing that. I don't think it will w
| |
| 31 limits::kMaxBitsPerSample); | |
| 32 #if defined(OS_WIN) | |
| 33 // TODO(dalecurtis): Since channel mixing is handle by the output device right | |
|
scherkus (not reviewing)
2012/09/12 13:35:13
s/handle/handled/
DaleCurtis
2012/09/12 14:03:52
Done.
| |
| 34 // now and not by AudioOutputResampler, we need to query for hardware channel | |
| 35 // information. Remove once AOR handles this, http://crbug.com/138762 | |
| 36 UMA_HISTOGRAM_ENUMERATION( | |
| 37 "Media.HardwareAudioChannelLayout", | |
| 38 WASAPIAudioOutputStream::HardwareChannelLayout(), CHANNEL_LAYOUT_MAX); | |
| 39 UMA_HISTOGRAM_ENUMERATION( | |
| 40 "Media.HardwareAudioChannelCount", | |
| 41 WASAPIAudioOutputStream::HardwareChannelCount(), limits::kMaxChannels); | |
| 42 #else | |
| 43 UMA_HISTOGRAM_ENUMERATION( | |
| 44 "Media.HardwareAudioChannelLayout", output_params.channel_layout(), | |
| 45 CHANNEL_LAYOUT_MAX); | |
| 46 UMA_HISTOGRAM_ENUMERATION( | |
| 47 "Media.HardwareAudioChannelCount", output_params.channels(), | |
| 48 limits::kMaxChannels); | |
| 49 #endif | |
| 50 AudioSampleRate asr = media::AsAudioSampleRate(output_params.sample_rate()); | |
| 51 if (asr != kUnexpectedAudioSampleRate) { | |
| 52 UMA_HISTOGRAM_ENUMERATION( | |
| 53 "Media.HardwareAudioSamplesPerSecond", asr, kUnexpectedAudioSampleRate); | |
| 54 } else { | |
| 55 UMA_HISTOGRAM_COUNTS( | |
| 56 "Media.HardwareAudioSamplesPerSecondUnexpected", | |
| 57 output_params.sample_rate()); | |
| 58 } | |
| 59 } | |
| 60 | |
| 21 AudioOutputResampler::AudioOutputResampler(AudioManager* audio_manager, | 61 AudioOutputResampler::AudioOutputResampler(AudioManager* audio_manager, |
| 22 const AudioParameters& input_params, | 62 const AudioParameters& input_params, |
| 23 const AudioParameters& output_params, | 63 const AudioParameters& output_params, |
| 24 const base::TimeDelta& close_delay) | 64 const base::TimeDelta& close_delay) |
| 25 : AudioOutputDispatcher(audio_manager, input_params), | 65 : AudioOutputDispatcher(audio_manager, input_params), |
| 26 source_callback_(NULL), | 66 source_callback_(NULL), |
| 27 io_ratio_(1), | 67 io_ratio_(1), |
| 28 input_bytes_per_frame_(input_params.GetBytesPerFrame()), | 68 input_bytes_per_frame_(input_params.GetBytesPerFrame()), |
| 29 output_bytes_per_frame_(output_params.GetBytesPerFrame()), | 69 output_bytes_per_frame_(output_params.GetBytesPerFrame()), |
| 30 outstanding_audio_bytes_(0) { | 70 outstanding_audio_bytes_(0) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 base::Unretained(this)))); | 110 base::Unretained(this)))); |
| 71 } | 111 } |
| 72 | 112 |
| 73 DVLOG(1) << "I/O ratio is " << io_ratio_; | 113 DVLOG(1) << "I/O ratio is " << io_ratio_; |
| 74 } | 114 } |
| 75 | 115 |
| 76 // TODO(dalecurtis): All this code should be merged into AudioOutputMixer once | 116 // TODO(dalecurtis): All this code should be merged into AudioOutputMixer once |
| 77 // we've stabilized the issues there. | 117 // we've stabilized the issues there. |
| 78 dispatcher_ = new AudioOutputDispatcherImpl( | 118 dispatcher_ = new AudioOutputDispatcherImpl( |
| 79 audio_manager, output_params, close_delay); | 119 audio_manager, output_params, close_delay); |
| 120 | |
| 121 // Record UMA statistics for the hardware configuration. | |
| 122 RecordStats(output_params); | |
| 80 } | 123 } |
| 81 | 124 |
| 82 AudioOutputResampler::~AudioOutputResampler() {} | 125 AudioOutputResampler::~AudioOutputResampler() {} |
| 83 | 126 |
| 84 bool AudioOutputResampler::OpenStream() { | 127 bool AudioOutputResampler::OpenStream() { |
| 85 // TODO(dalecurtis): Automatically revert to high latency path if OpenStream() | 128 // TODO(dalecurtis): Automatically revert to high latency path if OpenStream() |
| 86 // fails; use default high latency output values + rebuffering / resampling. | 129 // fails; use default high latency output values + rebuffering / resampling. |
| 87 return dispatcher_->OpenStream(); | 130 return dispatcher_->OpenStream(); |
| 88 } | 131 } |
| 89 | 132 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 source_callback_->OnError(stream, code); | 239 source_callback_->OnError(stream, code); |
| 197 } | 240 } |
| 198 | 241 |
| 199 void AudioOutputResampler::WaitTillDataReady() { | 242 void AudioOutputResampler::WaitTillDataReady() { |
| 200 base::AutoLock auto_lock(source_lock_); | 243 base::AutoLock auto_lock(source_lock_); |
| 201 if (source_callback_ && !outstanding_audio_bytes_) | 244 if (source_callback_ && !outstanding_audio_bytes_) |
| 202 source_callback_->WaitTillDataReady(); | 245 source_callback_->WaitTillDataReady(); |
| 203 } | 246 } |
| 204 | 247 |
| 205 } // namespace media | 248 } // namespace media |
| OLD | NEW |