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

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

Issue 671793004: Clean up the media stream audio track code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 1 month 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 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/media_stream_audio_processor.h" 5 #include "content/renderer/media/media_stream_audio_processor.h"
6 6
7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
9 #if defined(OS_MACOSX) 8 #if defined(OS_MACOSX)
10 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
11 #endif 10 #endif
12 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/renderer/media/media_stream_audio_processor_options.h" 12 #include "content/renderer/media/media_stream_audio_processor_options.h"
15 #include "content/renderer/media/rtc_media_constraints.h" 13 #include "content/renderer/media/rtc_media_constraints.h"
16 #include "content/renderer/media/webrtc_audio_device_impl.h" 14 #include "content/renderer/media/webrtc_audio_device_impl.h"
17 #include "media/audio/audio_parameters.h" 15 #include "media/audio/audio_parameters.h"
18 #include "media/base/audio_converter.h" 16 #include "media/base/audio_converter.h"
19 #include "media/base/audio_fifo.h" 17 #include "media/base/audio_fifo.h"
20 #include "media/base/channel_layout.h" 18 #include "media/base/channel_layout.h"
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
22 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" 20 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
23 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" 21 #include "third_party/webrtc/modules/audio_processing/typing_detection.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 base::ThreadChecker thread_checker_; 196 base::ThreadChecker thread_checker_;
199 const int source_channels_; // For a DCHECK. 197 const int source_channels_; // For a DCHECK.
200 const int source_frames_; // For a DCHECK. 198 const int source_frames_; // For a DCHECK.
201 scoped_ptr<media::AudioBus> audio_source_intermediate_; 199 scoped_ptr<media::AudioBus> audio_source_intermediate_;
202 scoped_ptr<MediaStreamAudioBus> destination_; 200 scoped_ptr<MediaStreamAudioBus> destination_;
203 scoped_ptr<media::AudioFifo> fifo_; 201 scoped_ptr<media::AudioFifo> fifo_;
204 // Only used when the FIFO is disabled; 202 // Only used when the FIFO is disabled;
205 bool data_available_; 203 bool data_available_;
206 }; 204 };
207 205
208 bool MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() {
209 return !CommandLine::ForCurrentProcess()->HasSwitch(
210 switches::kDisableAudioTrackProcessing);
211 }
212
213 MediaStreamAudioProcessor::MediaStreamAudioProcessor( 206 MediaStreamAudioProcessor::MediaStreamAudioProcessor(
214 const blink::WebMediaConstraints& constraints, 207 const blink::WebMediaConstraints& constraints,
215 int effects, 208 int effects,
216 WebRtcPlayoutDataSource* playout_data_source) 209 WebRtcPlayoutDataSource* playout_data_source)
217 : render_delay_ms_(0), 210 : render_delay_ms_(0),
218 playout_data_source_(playout_data_source), 211 playout_data_source_(playout_data_source),
219 audio_mirroring_(false), 212 audio_mirroring_(false),
220 typing_detected_(false), 213 typing_detected_(false),
221 stopped_(false) { 214 stopped_(false) {
222 capture_thread_checker_.DetachFromThread(); 215 capture_thread_checker_.DetachFromThread();
223 render_thread_checker_.DetachFromThread(); 216 render_thread_checker_.DetachFromThread();
224 InitializeAudioProcessingModule(constraints, effects); 217 InitializeAudioProcessingModule(constraints, effects);
225 if (IsAudioTrackProcessingEnabled()) { 218
226 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); 219 aec_dump_message_filter_ = AecDumpMessageFilter::Get();
227 // In unit tests not creating a message filter, |aec_dump_message_filter_| 220 // In unit tests not creating a message filter, |aec_dump_message_filter_|
228 // will be NULL. We can just ignore that. Other unit tests and browser tests 221 // will be NULL. We can just ignore that. Other unit tests and browser tests
229 // ensure that we do get the filter when we should. 222 // ensure that we do get the filter when we should.
230 if (aec_dump_message_filter_.get()) 223 if (aec_dump_message_filter_.get())
231 aec_dump_message_filter_->AddDelegate(this); 224 aec_dump_message_filter_->AddDelegate(this);
232 }
233 } 225 }
234 226
235 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { 227 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() {
236 DCHECK(main_thread_checker_.CalledOnValidThread()); 228 DCHECK(main_thread_checker_.CalledOnValidThread());
237 Stop(); 229 Stop();
238 } 230 }
239 231
240 void MediaStreamAudioProcessor::OnCaptureFormatChanged( 232 void MediaStreamAudioProcessor::OnCaptureFormatChanged(
241 const media::AudioParameters& input_format) { 233 const media::AudioParameters& input_format) {
242 DCHECK(main_thread_checker_.CalledOnValidThread()); 234 DCHECK(main_thread_checker_.CalledOnValidThread());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 DCHECK(main_thread_checker_.CalledOnValidThread()); 386 DCHECK(main_thread_checker_.CalledOnValidThread());
395 DCHECK(!audio_processing_); 387 DCHECK(!audio_processing_);
396 388
397 MediaAudioConstraints audio_constraints(constraints, effects); 389 MediaAudioConstraints audio_constraints(constraints, effects);
398 390
399 // Audio mirroring can be enabled even though audio processing is otherwise 391 // Audio mirroring can be enabled even though audio processing is otherwise
400 // disabled. 392 // disabled.
401 audio_mirroring_ = audio_constraints.GetProperty( 393 audio_mirroring_ = audio_constraints.GetProperty(
402 MediaAudioConstraints::kGoogAudioMirroring); 394 MediaAudioConstraints::kGoogAudioMirroring);
403 395
404 if (!IsAudioTrackProcessingEnabled()) {
405 RecordProcessingState(AUDIO_PROCESSING_IN_WEBRTC);
406 return;
407 }
408
409 #if defined(OS_IOS) 396 #if defined(OS_IOS)
410 // On iOS, VPIO provides built-in AGC and AEC. 397 // On iOS, VPIO provides built-in AGC and AEC.
411 const bool echo_cancellation = false; 398 const bool echo_cancellation = false;
412 const bool goog_agc = false; 399 const bool goog_agc = false;
413 #else 400 #else
414 const bool echo_cancellation = 401 const bool echo_cancellation =
415 audio_constraints.GetEchoCancellationProperty(); 402 audio_constraints.GetEchoCancellationProperty();
416 const bool goog_agc = audio_constraints.GetProperty( 403 const bool goog_agc = audio_constraints.GetProperty(
417 MediaAudioConstraints::kGoogAutoGainControl); 404 MediaAudioConstraints::kGoogAutoGainControl);
418 #endif 405 #endif
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 vad->stream_has_voice()); 617 vad->stream_has_voice());
631 base::subtle::Release_Store(&typing_detected_, detected); 618 base::subtle::Release_Store(&typing_detected_, detected);
632 } 619 }
633 620
634 // Return 0 if the volume hasn't been changed, and otherwise the new volume. 621 // Return 0 if the volume hasn't been changed, and otherwise the new volume.
635 return (agc->stream_analog_level() == volume) ? 622 return (agc->stream_analog_level() == volume) ?
636 0 : agc->stream_analog_level(); 623 0 : agc->stream_analog_level();
637 } 624 }
638 625
639 } // namespace content 626 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.h ('k') | content/renderer/media/media_stream_audio_processor_options.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698