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

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

Issue 2131563002: Stop using GetAudioHardwareConfig to get audio parameters in WebRtcLocalAudioSourceProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor formatting change Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_local_audio_source_provider.h" 5 #include "content/renderer/media/webrtc_local_audio_source_provider.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/render_thread_impl.h" 8 #include "content/public/renderer/render_frame.h"
9 #include "content/renderer/media/audio_device_factory.h"
9 #include "media/base/audio_fifo.h" 10 #include "media/base/audio_fifo.h"
10 #include "media/base/audio_hardware_config.h"
11 #include "media/base/audio_parameters.h" 11 #include "media/base/audio_parameters.h"
12 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" 12 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h"
13 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
13 15
14 using blink::WebVector; 16 using blink::WebVector;
15 17
16 namespace content { 18 namespace content {
17 19
18 static const size_t kMaxNumberOfBuffers = 10; 20 static const size_t kMaxNumberOfBuffers = 10;
19 21
20 // Size of the buffer that WebAudio processes each time, it is the same value 22 // Size of the buffer that WebAudio processes each time, it is the same value
21 // as AudioNode::ProcessingSizeInFrames in WebKit. 23 // as AudioNode::ProcessingSizeInFrames in WebKit.
22 // static 24 // static
23 const size_t WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize = 128; 25 const size_t WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize = 128;
24 26
25 WebRtcLocalAudioSourceProvider::WebRtcLocalAudioSourceProvider( 27 WebRtcLocalAudioSourceProvider::WebRtcLocalAudioSourceProvider(
26 const blink::WebMediaStreamTrack& track) 28 const blink::WebMediaStreamTrack& track)
27 : is_enabled_(false), 29 : is_enabled_(false),
28 track_(track), 30 track_(track),
29 track_stopped_(false) { 31 track_stopped_(false) {
30 // Get the native audio output hardware sample-rate for the sink. 32 // Get the native audio output hardware sample-rate for the sink.
31 // We need to check if RenderThreadImpl is valid here since the unittests 33 // We need to check if there is a valid frame since the unittests
32 // do not have one and they will inject their own |sink_params_| for testing. 34 // do not have one and they will inject their own |sink_params_| for testing.
33 if (RenderThreadImpl::current()) { 35 blink::WebLocalFrame* const web_frame =
34 media::AudioHardwareConfig* hardware_config = 36 blink::WebLocalFrame::frameForCurrentContext();
35 RenderThreadImpl::current()->GetAudioHardwareConfig(); 37 RenderFrame* const render_frame = RenderFrame::FromWebFrame(web_frame);
36 int sample_rate = hardware_config->GetOutputSampleRate(); 38 if (render_frame) {
39 int sample_rate = AudioDeviceFactory::GetOutputDeviceInfo(
40 render_frame->GetRoutingID(), 0, std::string(),
41 web_frame->getSecurityOrigin())
42 .output_params()
43 .sample_rate();
37 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 44 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
38 media::CHANNEL_LAYOUT_STEREO, sample_rate, 16, 45 media::CHANNEL_LAYOUT_STEREO, sample_rate, 16,
39 kWebAudioRenderBufferSize); 46 kWebAudioRenderBufferSize);
40 } 47 }
41
42 // Connect the source provider to the track as a sink. 48 // Connect the source provider to the track as a sink.
43 MediaStreamAudioSink::AddToAudioTrack(this, track_); 49 MediaStreamAudioSink::AddToAudioTrack(this, track_);
44 } 50 }
45 51
46 WebRtcLocalAudioSourceProvider::~WebRtcLocalAudioSourceProvider() { 52 WebRtcLocalAudioSourceProvider::~WebRtcLocalAudioSourceProvider() {
47 if (audio_converter_.get()) 53 if (audio_converter_.get())
48 audio_converter_->RemoveInput(this); 54 audio_converter_->RemoveInput(this);
49 55
50 // If the track is still active, it is necessary to notify the track before 56 // If the track is still active, it is necessary to notify the track before
51 // the source provider goes away. 57 // the source provider goes away.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 149
144 return 1.0; 150 return 1.0;
145 } 151 }
146 152
147 void WebRtcLocalAudioSourceProvider::SetSinkParamsForTesting( 153 void WebRtcLocalAudioSourceProvider::SetSinkParamsForTesting(
148 const media::AudioParameters& sink_params) { 154 const media::AudioParameters& sink_params) {
149 sink_params_ = sink_params; 155 sink_params_ = sink_params;
150 } 156 }
151 157
152 } // namespace content 158 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698