| 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 "content/renderer/media/webrtc_audio_renderer.h" | 5 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "content/renderer/media/audio_device_factory.h" | |
| 11 #include "content/renderer/media/audio_hardware.h" | 10 #include "content/renderer/media/audio_hardware.h" |
| 11 #include "content/renderer/media/audio_message_filter.h" |
| 12 #include "content/renderer/media/webrtc_audio_device_impl.h" | 12 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 13 #include "content/renderer/render_thread_impl.h" |
| 14 #include "media/audio/audio_output_device.h" |
| 13 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
| 14 #include "media/audio/sample_rates.h" | 16 #include "media/audio/sample_rates.h" |
| 15 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 16 #include "media/audio/win/core_audio_util_win.h" | 18 #include "media/audio/win/core_audio_util_win.h" |
| 17 #endif | 19 #endif |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer", | 75 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer", |
| 74 afpb, kUnexpectedAudioBufferSize); | 76 afpb, kUnexpectedAudioBufferSize); |
| 75 } else { | 77 } else { |
| 76 // Report unexpected sample rates using a unique histogram name. | 78 // Report unexpected sample rates using a unique histogram name. |
| 77 UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputFramesPerBufferUnexpected", param); | 79 UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputFramesPerBufferUnexpected", param); |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 | 82 |
| 81 } // namespace | 83 } // namespace |
| 82 | 84 |
| 83 WebRtcAudioRenderer::WebRtcAudioRenderer() | 85 WebRtcAudioRenderer::WebRtcAudioRenderer(int source_render_view_id) |
| 84 : state_(UNINITIALIZED), | 86 : state_(UNINITIALIZED), |
| 87 source_render_view_id_(source_render_view_id), |
| 85 source_(NULL) { | 88 source_(NULL) { |
| 86 } | 89 } |
| 87 | 90 |
| 88 WebRtcAudioRenderer::~WebRtcAudioRenderer() { | 91 WebRtcAudioRenderer::~WebRtcAudioRenderer() { |
| 89 DCHECK_EQ(state_, UNINITIALIZED); | 92 DCHECK_EQ(state_, UNINITIALIZED); |
| 90 buffer_.reset(); | 93 buffer_.reset(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool WebRtcAudioRenderer::Initialize(WebRtcAudioRendererSource* source) { | 96 bool WebRtcAudioRenderer::Initialize(WebRtcAudioRendererSource* source) { |
| 94 base::AutoLock auto_lock(lock_); | 97 base::AutoLock auto_lock(lock_); |
| 95 DCHECK_EQ(state_, UNINITIALIZED); | 98 DCHECK_EQ(state_, UNINITIALIZED); |
| 96 DCHECK(source); | 99 DCHECK(source); |
| 97 DCHECK(!sink_); | 100 DCHECK(!sink_); |
| 98 DCHECK(!source_); | 101 DCHECK(!source_); |
| 99 | 102 |
| 100 sink_ = AudioDeviceFactory::NewOutputDevice(); | |
| 101 DCHECK(sink_); | |
| 102 | |
| 103 // Ask the browser for the default audio output hardware sample-rate. | 103 // Ask the browser for the default audio output hardware sample-rate. |
| 104 // This request is based on a synchronous IPC message. | 104 // This request is based on a synchronous IPC message. |
| 105 int sample_rate = GetAudioOutputSampleRate(); | 105 int sample_rate = GetAudioOutputSampleRate(); |
| 106 DVLOG(1) << "Audio output hardware sample rate: " << sample_rate; | 106 DVLOG(1) << "Audio output hardware sample rate: " << sample_rate; |
| 107 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputSampleRate", | 107 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputSampleRate", |
| 108 sample_rate, media::kUnexpectedAudioSampleRate); | 108 sample_rate, media::kUnexpectedAudioSampleRate); |
| 109 | 109 |
| 110 // Verify that the reported output hardware sample rate is supported | 110 // Verify that the reported output hardware sample rate is supported |
| 111 // on the current platform. | 111 // on the current platform. |
| 112 if (std::find(&kValidOutputRates[0], | 112 if (std::find(&kValidOutputRates[0], |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // Allocate local audio buffers based on the parameters above. | 183 // Allocate local audio buffers based on the parameters above. |
| 184 // It is assumed that each audio sample contains 16 bits and each | 184 // It is assumed that each audio sample contains 16 bits and each |
| 185 // audio frame contains one or two audio samples depending on the | 185 // audio frame contains one or two audio samples depending on the |
| 186 // number of channels. | 186 // number of channels. |
| 187 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]); | 187 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]); |
| 188 | 188 |
| 189 source_ = source; | 189 source_ = source; |
| 190 source->SetRenderFormat(params_); | 190 source->SetRenderFormat(params_); |
| 191 | 191 |
| 192 // Configure the audio rendering client and start the rendering. | 192 // Configure the audio rendering client and start the rendering. |
| 193 scoped_refptr<content::AudioMessageFilter> audio_message_filter = |
| 194 RenderThreadImpl::current()->audio_message_filter(); |
| 195 sink_ = new media::AudioOutputDevice( |
| 196 audio_message_filter, |
| 197 RenderThreadImpl::current()->GetIOMessageLoopProxy()); |
| 193 sink_->Initialize(params_, this); | 198 sink_->Initialize(params_, this); |
| 194 | 199 audio_message_filter->AssociateStreamWithProducer(sink_->stream_id(), |
| 200 source_render_view_id_); |
| 195 sink_->Start(); | 201 sink_->Start(); |
| 196 | 202 |
| 197 state_ = PAUSED; | 203 state_ = PAUSED; |
| 198 | 204 |
| 199 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputChannelLayout", | 205 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputChannelLayout", |
| 200 channel_layout, media::CHANNEL_LAYOUT_MAX); | 206 channel_layout, media::CHANNEL_LAYOUT_MAX); |
| 201 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer", | 207 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer", |
| 202 buffer_size, kUnexpectedAudioBufferSize); | 208 buffer_size, kUnexpectedAudioBufferSize); |
| 203 AddHistogramFramesPerBuffer(buffer_size); | 209 AddHistogramFramesPerBuffer(buffer_size); |
| 204 | 210 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 params_.bits_per_sample() / 8); | 269 params_.bits_per_sample() / 8); |
| 264 return audio_bus->frames(); | 270 return audio_bus->frames(); |
| 265 } | 271 } |
| 266 | 272 |
| 267 void WebRtcAudioRenderer::OnRenderError() { | 273 void WebRtcAudioRenderer::OnRenderError() { |
| 268 NOTIMPLEMENTED(); | 274 NOTIMPLEMENTED(); |
| 269 LOG(ERROR) << "OnRenderError()"; | 275 LOG(ERROR) << "OnRenderError()"; |
| 270 } | 276 } |
| 271 | 277 |
| 272 } // namespace content | 278 } // namespace content |
| OLD | NEW |