Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: content/renderer/media/webrtc_audio_renderer.cc

Issue 12383016: Merge AssociateStreamWithProducer message into CreateStream message for both audio output and input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 10 #include "content/renderer/media/audio_device_factory.h"
11 #include "content/renderer/media/renderer_audio_output_device.h"
12 #include "content/renderer/media/webrtc_audio_device_impl.h" 11 #include "content/renderer/media/webrtc_audio_device_impl.h"
13 #include "content/renderer/render_thread_impl.h" 12 #include "content/renderer/render_thread_impl.h"
13 #include "media/audio/audio_output_device.h"
14 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
15 #include "media/audio/sample_rates.h" 15 #include "media/audio/sample_rates.h"
16 #include "media/base/audio_hardware_config.h" 16 #include "media/base/audio_hardware_config.h"
17 17
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "media/audio/win/core_audio_util_win.h" 20 #include "media/audio/win/core_audio_util_win.h"
21 #endif 21 #endif
22 22
23 namespace content { 23 namespace content {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 bool WebRtcAudioRenderer::Initialize(WebRtcAudioRendererSource* source) { 105 bool WebRtcAudioRenderer::Initialize(WebRtcAudioRendererSource* source) {
106 DVLOG(1) << "WebRtcAudioRenderer::Initialize()"; 106 DVLOG(1) << "WebRtcAudioRenderer::Initialize()";
107 DCHECK(thread_checker_.CalledOnValidThread()); 107 DCHECK(thread_checker_.CalledOnValidThread());
108 base::AutoLock auto_lock(lock_); 108 base::AutoLock auto_lock(lock_);
109 DCHECK_EQ(state_, UNINITIALIZED); 109 DCHECK_EQ(state_, UNINITIALIZED);
110 DCHECK(source); 110 DCHECK(source);
111 DCHECK(!sink_); 111 DCHECK(!sink_);
112 DCHECK(!source_); 112 DCHECK(!source_);
113 113
114 sink_ = AudioDeviceFactory::NewOutputDevice();
115 DCHECK(sink_);
116
117 // Use mono on all platforms but Windows for now. 114 // Use mono on all platforms but Windows for now.
118 // TODO(henrika): Tracking at http://crbug.com/166771. 115 // TODO(henrika): Tracking at http://crbug.com/166771.
119 media::ChannelLayout channel_layout = media::CHANNEL_LAYOUT_MONO; 116 media::ChannelLayout channel_layout = media::CHANNEL_LAYOUT_MONO;
120 #if defined(OS_WIN) 117 #if defined(OS_WIN)
121 channel_layout = media::CHANNEL_LAYOUT_STEREO; 118 channel_layout = media::CHANNEL_LAYOUT_STEREO;
122 #endif 119 #endif
123 120
124 // Ask the renderer for the default audio output hardware sample-rate. 121 // Ask the renderer for the default audio output hardware sample-rate.
125 media::AudioHardwareConfig* hardware_config = 122 media::AudioHardwareConfig* hardware_config =
126 RenderThreadImpl::current()->GetAudioHardwareConfig(); 123 RenderThreadImpl::current()->GetAudioHardwareConfig();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // It is assumed that each audio sample contains 16 bits and each 196 // It is assumed that each audio sample contains 16 bits and each
200 // audio frame contains one or two audio samples depending on the 197 // audio frame contains one or two audio samples depending on the
201 // number of channels. 198 // number of channels.
202 buffer_.reset( 199 buffer_.reset(
203 new int16[source_params.frames_per_buffer() * source_params.channels()]); 200 new int16[source_params.frames_per_buffer() * source_params.channels()]);
204 201
205 source_ = source; 202 source_ = source;
206 source->SetRenderFormat(source_params); 203 source->SetRenderFormat(source_params);
207 204
208 // Configure the audio rendering client and start rendering. 205 // Configure the audio rendering client and start rendering.
206 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_);
209 sink_->Initialize(sink_params, this); 207 sink_->Initialize(sink_params, this);
210 sink_->SetSourceRenderView(source_render_view_id_);
211 sink_->Start(); 208 sink_->Start();
212 209
213 // User must call Play() before any audio can be heard. 210 // User must call Play() before any audio can be heard.
214 state_ = PAUSED; 211 state_ = PAUSED;
215 212
216 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputChannelLayout", 213 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputChannelLayout",
217 source_params.channel_layout(), 214 source_params.channel_layout(),
218 media::CHANNEL_LAYOUT_MAX); 215 media::CHANNEL_LAYOUT_MAX);
219 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer", 216 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer",
220 source_params.frames_per_buffer(), 217 source_params.frames_per_buffer(),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 341 }
345 342
346 // De-interleave each channel and convert to 32-bit floating-point 343 // De-interleave each channel and convert to 32-bit floating-point
347 // with nominal range -1.0 -> +1.0 to match the callback format. 344 // with nominal range -1.0 -> +1.0 to match the callback format.
348 audio_bus->FromInterleaved(buffer_.get(), 345 audio_bus->FromInterleaved(buffer_.get(),
349 audio_bus->frames(), 346 audio_bus->frames(),
350 sizeof(buffer_[0])); 347 sizeof(buffer_[0]));
351 } 348 }
352 349
353 } // namespace content 350 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698