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

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

Issue 883293005: Cast: Basic cast_receiver API for chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed extra BUILD.gn line Created 5 years, 10 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
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_capturer.h" 5 #include "content/renderer/media/webrtc_audio_capturer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 media::AudioSampleRate asr; 194 media::AudioSampleRate asr;
195 if (media::ToAudioSampleRate(device_info_.device.input.sample_rate, &asr)) { 195 if (media::ToAudioSampleRate(device_info_.device.input.sample_rate, &asr)) {
196 UMA_HISTOGRAM_ENUMERATION( 196 UMA_HISTOGRAM_ENUMERATION(
197 "WebRTC.AudioInputSampleRate", asr, media::kAudioSampleRateMax + 1); 197 "WebRTC.AudioInputSampleRate", asr, media::kAudioSampleRateMax + 1);
198 } else { 198 } else {
199 UMA_HISTOGRAM_COUNTS("WebRTC.AudioInputSampleRateUnexpected", 199 UMA_HISTOGRAM_COUNTS("WebRTC.AudioInputSampleRateUnexpected",
200 device_info_.device.input.sample_rate); 200 device_info_.device.input.sample_rate);
201 } 201 }
202 202
203 // Create and configure the default audio capturing source. 203 // Create and configure the default audio capturing source.
204 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id_), 204 SetCapturerSourceInternal(
205 channel_layout, 205 AudioDeviceFactory::NewInputDevice(render_view_id_),
206 static_cast<float>(device_info_.device.input.sample_rate)); 206 channel_layout,
207 static_cast<float>(device_info_.device.input.sample_rate));
207 208
208 // Add the capturer to the WebRtcAudioDeviceImpl since it needs some hardware 209 // Add the capturer to the WebRtcAudioDeviceImpl since it needs some hardware
209 // information from the capturer. 210 // information from the capturer.
210 if (audio_device_) 211 if (audio_device_)
211 audio_device_->AddAudioCapturer(this); 212 audio_device_->AddAudioCapturer(this);
212 213
213 return true; 214 return true;
214 } 215 }
215 216
216 WebRtcAudioCapturer::WebRtcAudioCapturer( 217 WebRtcAudioCapturer::WebRtcAudioCapturer(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (stop_source) { 279 if (stop_source) {
279 // Since WebRtcAudioCapturer does not inherit MediaStreamAudioSource, 280 // Since WebRtcAudioCapturer does not inherit MediaStreamAudioSource,
280 // and instead MediaStreamAudioSource is composed of a WebRtcAudioCapturer, 281 // and instead MediaStreamAudioSource is composed of a WebRtcAudioCapturer,
281 // we have to call StopSource on the MediaStreamSource. This will call 282 // we have to call StopSource on the MediaStreamSource. This will call
282 // MediaStreamAudioSource::DoStopSource which in turn call 283 // MediaStreamAudioSource::DoStopSource which in turn call
283 // WebRtcAudioCapturerer::Stop(); 284 // WebRtcAudioCapturerer::Stop();
284 audio_source_->StopSource(); 285 audio_source_->StopSource();
285 } 286 }
286 } 287 }
287 288
288 void WebRtcAudioCapturer::SetCapturerSource( 289 void WebRtcAudioCapturer::SetCapturerSourceInternal(
289 const scoped_refptr<media::AudioCapturerSource>& source, 290 const scoped_refptr<media::AudioCapturerSource>& source,
290 media::ChannelLayout channel_layout, 291 media::ChannelLayout channel_layout,
291 float sample_rate) { 292 float sample_rate) {
292 DCHECK(thread_checker_.CalledOnValidThread()); 293 DCHECK(thread_checker_.CalledOnValidThread());
293 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," 294 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << ","
294 << "sample_rate=" << sample_rate << ")"; 295 << "sample_rate=" << sample_rate << ")";
295 scoped_refptr<media::AudioCapturerSource> old_source; 296 scoped_refptr<media::AudioCapturerSource> old_source;
296 { 297 {
297 base::AutoLock auto_lock(lock_); 298 base::AutoLock auto_lock(lock_);
298 if (source_.get() == source.get()) 299 if (source_.get() == source.get())
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 358 }
358 359
359 // Do nothing if the current buffer size is the WebRtc native buffer size. 360 // Do nothing if the current buffer size is the WebRtc native buffer size.
360 if (GetBufferSize(input_params.sample_rate()) == 361 if (GetBufferSize(input_params.sample_rate()) ==
361 input_params.frames_per_buffer()) { 362 input_params.frames_per_buffer()) {
362 return; 363 return;
363 } 364 }
364 365
365 // Create a new audio stream as source which will open the hardware using 366 // Create a new audio stream as source which will open the hardware using
366 // WebRtc native buffer size. 367 // WebRtc native buffer size.
367 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), 368 SetCapturerSourceInternal(AudioDeviceFactory::NewInputDevice(render_view_id),
368 input_params.channel_layout(), 369 input_params.channel_layout(),
369 static_cast<float>(input_params.sample_rate())); 370 static_cast<float>(input_params.sample_rate()));
370 } 371 }
371 372
372 void WebRtcAudioCapturer::Start() { 373 void WebRtcAudioCapturer::Start() {
373 DCHECK(thread_checker_.CalledOnValidThread()); 374 DCHECK(thread_checker_.CalledOnValidThread());
374 DVLOG(1) << "WebRtcAudioCapturer::Start()"; 375 DVLOG(1) << "WebRtcAudioCapturer::Start()";
375 base::AutoLock auto_lock(lock_); 376 base::AutoLock auto_lock(lock_);
376 if (running_ || !source_.get()) 377 if (running_ || !source_.get())
377 return; 378 return;
378 379
379 // Start the data source, i.e., start capturing data from the current source. 380 // Start the data source, i.e., start capturing data from the current source.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 hardware_buffer_size <= peer_connection_buffer_size && 579 hardware_buffer_size <= peer_connection_buffer_size &&
579 !audio_processor_->has_audio_processing()) { 580 !audio_processor_->has_audio_processing()) {
580 DVLOG(1) << "WebRtcAudioCapturer is using hardware buffer size " 581 DVLOG(1) << "WebRtcAudioCapturer is using hardware buffer size "
581 << hardware_buffer_size; 582 << hardware_buffer_size;
582 return hardware_buffer_size; 583 return hardware_buffer_size;
583 } 584 }
584 585
585 return (sample_rate / 100); 586 return (sample_rate / 100);
586 } 587 }
587 588
588 void WebRtcAudioCapturer::SetCapturerSourceForTesting( 589 void WebRtcAudioCapturer::SetCapturerSource(
589 const scoped_refptr<media::AudioCapturerSource>& source, 590 const scoped_refptr<media::AudioCapturerSource>& source,
590 media::AudioParameters params) { 591 media::AudioParameters params) {
591 // Create a new audio stream as source which uses the new source. 592 // Create a new audio stream as source which uses the new source.
592 SetCapturerSource(source, params.channel_layout(), 593 SetCapturerSourceInternal(source, params.channel_layout(),
593 static_cast<float>(params.sample_rate())); 594 static_cast<float>(params.sample_rate()));
594 } 595 }
595 596
596 } // namespace content 597 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.h ('k') | content/renderer/media/webrtc_audio_capturer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698