diff options
author | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-24 16:43:27 +0000 |
---|---|---|
committer | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-24 16:43:27 +0000 |
commit | 69ef8505dcc588b7a9d5b6e31ef94192351b1e44 (patch) | |
tree | 8a1a64604288709695461d2c77dd27792362ac5f /content/renderer | |
parent | d6d72a4addd24f17e08eaeb0e43e95b8a014dd50 (diff) | |
download | chromium_src-69ef8505dcc588b7a9d5b6e31ef94192351b1e44.zip chromium_src-69ef8505dcc588b7a9d5b6e31ef94192351b1e44.tar.gz chromium_src-69ef8505dcc588b7a9d5b6e31ef94192351b1e44.tar.bz2 |
Revert 246894 "Wire up AGC to the MediaStreamAudioProcessor."
It seems to have broken this test:
[----------] 1 test from AudioStreamHandlerTest
[ RUN ] AudioStreamHandlerTest.ConsecutivePlayRequests
../../media/base/android/media_source_player_unittest.cc:1665: Failure
Expected: (first_job) != (second_job), actual: 0x766d4210 vs 0x766d4210
[ FAILED ] MediaSourcePlayerTest.VideoConfigChangeContinuesAcrossSeek (125 ms)
[ RUN ] MediaSourcePlayerTest.SeekToThenReleaseThenStart
[ OK ] MediaSourcePlayerTest.SeekToThenReleaseThenStart (82 ms)
[----------] 8 tests from MediaSourcePlayerTest (590 ms total)
> Wire up AGC to the MediaStreamAudioProcessor.
>
> This CL enables the AGC in the processor based on the constraints, and also trigger SetVolume() in the capturer if the AGC tries to adjust the volume.
>
> There are also some small changes in the MediaStreamAudioProcessor and its unittest.
>
> BUG=264611
> TEST= content_unittest --gtest_filter="*MediaStreamAudioProcessor*"
>
> Review URL: https://codereview.chromium.org/141513006
TBR=xians@chromium.org
Review URL: https://codereview.chromium.org/146923002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
6 files changed, 40 insertions, 127 deletions
diff --git a/content/renderer/media/media_stream_audio_processor.cc b/content/renderer/media/media_stream_audio_processor.cc index 4422b50..35b8d9f 100644 --- a/content/renderer/media/media_stream_audio_processor.cc +++ b/content/renderer/media/media_stream_audio_processor.cc @@ -23,7 +23,7 @@ namespace { using webrtc::AudioProcessing; using webrtc::MediaConstraintsInterface; -#if defined(OS_ANDROID) +#if defined(ANDROID) const int kAudioProcessingSampleRate = 16000; #else const int kAudioProcessingSampleRate = 32000; @@ -142,8 +142,7 @@ MediaStreamAudioProcessor::MediaStreamAudioProcessor( const media::AudioParameters& source_params, const blink::WebMediaConstraints& constraints, int effects) - : render_delay_ms_(0), - audio_mirroring_(false) { + : render_delay_ms_(0) { capture_thread_checker_.DetachFromThread(); render_thread_checker_.DetachFromThread(); InitializeAudioProcessingModule(constraints, effects); @@ -192,7 +191,7 @@ void MediaStreamAudioProcessor::PushRenderData( bool MediaStreamAudioProcessor::ProcessAndConsumeData( base::TimeDelta capture_delay, int volume, bool key_pressed, - int* new_volume, int16** out) { + int16** out) { DCHECK(capture_thread_checker_.CalledOnValidThread()); TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData"); @@ -200,8 +199,7 @@ bool MediaStreamAudioProcessor::ProcessAndConsumeData( if (!capture_converter_->Convert(&capture_frame_)) return false; - *new_volume = ProcessData(&capture_frame_, capture_delay, volume, - key_pressed); + ProcessData(&capture_frame_, capture_delay, volume, key_pressed); *out = capture_frame_.data_; return true; @@ -226,24 +224,19 @@ void MediaStreamAudioProcessor::InitializeAudioProcessingModule( RTCMediaConstraints native_constraints(constraints); ApplyFixedAudioConstraints(&native_constraints); if (effects & media::AudioParameters::ECHO_CANCELLER) { - // If platform echo canceller is enabled, disable the software AEC. + // If platform echo cancellator is enabled, disable the software AEC. native_constraints.AddMandatory( MediaConstraintsInterface::kEchoCancellation, MediaConstraintsInterface::kValueFalse, true); } -#if defined(OS_IOS) - // On iOS, VPIO provides built-in AEC and AGC. - const bool enable_aec = false; - const bool enable_agc = false; -#else const bool enable_aec = GetPropertyFromConstraints( &native_constraints, MediaConstraintsInterface::kEchoCancellation); - const bool enable_agc = GetPropertyFromConstraints( - &native_constraints, webrtc::MediaConstraintsInterface::kAutoGainControl); -#endif - -#if defined(OS_IOS) || defined(OS_ANDROID) + const bool enable_ns = GetPropertyFromConstraints( + &native_constraints, MediaConstraintsInterface::kNoiseSuppression); + const bool enable_high_pass_filter = GetPropertyFromConstraints( + &native_constraints, MediaConstraintsInterface::kHighpassFilter); +#if defined(IOS) || defined(ANDROID) const bool enable_experimental_aec = false; const bool enable_typing_detection = false; #else @@ -254,17 +247,9 @@ void MediaStreamAudioProcessor::InitializeAudioProcessingModule( &native_constraints, MediaConstraintsInterface::kTypingNoiseDetection); #endif - const bool enable_ns = GetPropertyFromConstraints( - &native_constraints, MediaConstraintsInterface::kNoiseSuppression); - const bool enable_high_pass_filter = GetPropertyFromConstraints( - &native_constraints, MediaConstraintsInterface::kHighpassFilter); - - audio_mirroring_ = GetPropertyFromConstraints( - &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); - // Return immediately if no audio processing component is enabled. if (!enable_aec && !enable_experimental_aec && !enable_ns && - !enable_high_pass_filter && !enable_typing_detection && !enable_agc) { + !enable_high_pass_filter && !enable_typing_detection) { return; } @@ -287,8 +272,6 @@ void MediaStreamAudioProcessor::InitializeAudioProcessingModule( if (enable_typing_detection) EnableTypingDetection(audio_processing_.get()); - if (enable_agc) - EnableAutomaticGainControl(audio_processing_.get()); // Configure the audio format the audio processing is running on. This // has to be done after all the needed components are enabled. @@ -358,15 +341,15 @@ void MediaStreamAudioProcessor::InitializeRenderConverterIfNeeded( frames_per_buffer); } -int MediaStreamAudioProcessor::ProcessData(webrtc::AudioFrame* audio_frame, - base::TimeDelta capture_delay, - int volume, - bool key_pressed) { +void MediaStreamAudioProcessor::ProcessData(webrtc::AudioFrame* audio_frame, + base::TimeDelta capture_delay, + int volume, + bool key_pressed) { DCHECK(capture_thread_checker_.CalledOnValidThread()); if (!audio_processing_) - return 0; + return; - TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessData"); + TRACE_EVENT0("audio", "MediaStreamAudioProcessor::Process10MsData"); DCHECK_EQ(audio_processing_->sample_rate_hz(), capture_converter_->sink_parameters().sample_rate()); DCHECK_EQ(audio_processing_->num_input_channels(), @@ -380,7 +363,7 @@ int MediaStreamAudioProcessor::ProcessData(webrtc::AudioFrame* audio_frame, DCHECK_LT(capture_delay_ms, std::numeric_limits<base::subtle::Atomic32>::max()); int total_delay_ms = capture_delay_ms + render_delay_ms; - if (total_delay_ms > 300) { + if (total_delay_ms > 1000) { LOG(WARNING) << "Large audio delay, capture delay: " << capture_delay_ms << "ms; render delay: " << render_delay_ms << "ms"; } @@ -392,16 +375,8 @@ int MediaStreamAudioProcessor::ProcessData(webrtc::AudioFrame* audio_frame, err = audio_processing_->ProcessStream(audio_frame); DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; - // TODO(xians): Add support for typing detection, audio level calculation. - - if (audio_mirroring_ && audio_frame->num_channels_ == 2) { - // TODO(xians): Swap the stereo channels after switching to media::AudioBus. - } - - // Return 0 if the volume has not been changed, otherwise return the new - // volume. - return (agc->stream_analog_level() == volume) ? - 0 : agc->stream_analog_level(); + // TODO(xians): Add support for AGC, typing detection, audio level + // calculation, stereo swapping. } void MediaStreamAudioProcessor::StopAudioProcessing() { diff --git a/content/renderer/media/media_stream_audio_processor.h b/content/renderer/media/media_stream_audio_processor.h index 12c0fc5..be5b8b0 100644 --- a/content/renderer/media/media_stream_audio_processor.h +++ b/content/renderer/media/media_stream_audio_processor.h @@ -63,9 +63,6 @@ class CONTENT_EXPORT MediaStreamAudioProcessor : // the post-processed data if the method is returning a true. The lifetime // of the data represeted by |out| is guaranteed to outlive the method call. // That also says *|out| won't change until this method is called again. - // |new_volume| receives the new microphone volume from the AGC. - // The new microphoen volume range is [0, 255], and the value will be 0 if - // the microphone volume should not be adjusted. // Returns true if the internal FIFO has at least 10 ms data for processing, // otherwise false. // |capture_delay|, |volume| and |key_pressed| will be passed to @@ -74,7 +71,6 @@ class CONTENT_EXPORT MediaStreamAudioProcessor : bool ProcessAndConsumeData(base::TimeDelta capture_delay, int volume, bool key_pressed, - int* new_volume, int16** out); @@ -92,8 +88,6 @@ class CONTENT_EXPORT MediaStreamAudioProcessor : virtual ~MediaStreamAudioProcessor(); private: - friend class MediaStreamAudioProcessorTest; - class MediaStreamAudioConverter; // Helper to initialize the WebRtc AudioProcessing. @@ -109,12 +103,10 @@ class CONTENT_EXPORT MediaStreamAudioProcessor : int frames_per_buffer); // Called by ProcessAndConsumeData(). - // Returns the new microphone volume in the range of |0, 255]. - // When the volume does not need to be updated, it returns 0. - int ProcessData(webrtc::AudioFrame* audio_frame, - base::TimeDelta capture_delay, - int volume, - bool key_pressed); + void ProcessData(webrtc::AudioFrame* audio_frame, + base::TimeDelta capture_delay, + int volume, + bool key_pressed); // Called when the processor is going away. void StopAudioProcessing(); @@ -151,9 +143,6 @@ class CONTENT_EXPORT MediaStreamAudioProcessor : // Used to DCHECK that PushRenderData() is called on the render audio thread. base::ThreadChecker render_thread_checker_; - - // Flag to enable the stereo channels mirroring. - bool audio_mirroring_; }; } // namespace content diff --git a/content/renderer/media/media_stream_audio_processor_options.cc b/content/renderer/media/media_stream_audio_processor_options.cc index 882d57c..cffc5a1 100644 --- a/content/renderer/media/media_stream_audio_processor_options.cc +++ b/content/renderer/media/media_stream_audio_processor_options.cc @@ -39,8 +39,10 @@ struct { webrtc::MediaConstraintsInterface::kValueTrue }, { webrtc::MediaConstraintsInterface::kHighpassFilter, webrtc::MediaConstraintsInterface::kValueTrue }, + // TODO(xians): Verify if it is OK to set typing detection to kValueFalse as + // default. { webrtc::MediaConstraintsInterface::kTypingNoiseDetection, - webrtc::MediaConstraintsInterface::kValueTrue }, + webrtc::MediaConstraintsInterface::kValueFalse }, }; } // namespace @@ -88,20 +90,23 @@ bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, } void EnableEchoCancellation(AudioProcessing* audio_processing) { -#if defined(OS_ANDROID) +#if defined(OS_IOS) + // On iOS, VPIO provides built-in EC and AGC. + return; +#elif defined(OS_ANDROID) // Mobile devices are using AECM. - int err = audio_processing->echo_control_mobile()->set_routing_mode( + int err = audio_processing->echo_control_mobile()->Enable(true); + err |= audio_processing->echo_control_mobile()->set_routing_mode( webrtc::EchoControlMobile::kSpeakerphone); - err |= audio_processing->echo_control_mobile()->Enable(true); CHECK_EQ(err, 0); #else - int err = audio_processing->echo_cancellation()->set_suppression_level( + int err = audio_processing->echo_cancellation()->Enable(true); + err |= audio_processing->echo_cancellation()->set_suppression_level( webrtc::EchoCancellation::kHighSuppression); // Enable the metrics for AEC. err |= audio_processing->echo_cancellation()->enable_metrics(true); err |= audio_processing->echo_cancellation()->enable_delay_logging(true); - err |= audio_processing->echo_cancellation()->Enable(true); CHECK_EQ(err, 0); #endif } @@ -117,6 +122,7 @@ void EnableHighPassFilter(AudioProcessing* audio_processing) { CHECK_EQ(audio_processing->high_pass_filter()->Enable(true), 0); } +// TODO(xians): stereo swapping void EnableTypingDetection(AudioProcessing* audio_processing) { int err = audio_processing->voice_detection()->Enable(true); err |= audio_processing->voice_detection()->set_likelihood( @@ -157,15 +163,4 @@ void StopAecDump(AudioProcessing* audio_processing) { DLOG(ERROR) << "Fail to stop AEC debug recording"; } -void EnableAutomaticGainControl(AudioProcessing* audio_processing) { -#if defined(OS_ANDROID) || defined(OS_IOS) - const webrtc::GainControl::Mode mode = webrtc::GainControl::kFixedDigital; -#else - const webrtc::GainControl::Mode mode = webrtc::GainControl::kAdaptiveAnalog; -#endif - int err = audio_processing->gain_control()->set_mode(mode); - err |= audio_processing->gain_control()->Enable(true); - CHECK_EQ(err, 0); -} - } // namespace content diff --git a/content/renderer/media/media_stream_audio_processor_options.h b/content/renderer/media/media_stream_audio_processor_options.h index 6057ae1..c8b6982 100644 --- a/content/renderer/media/media_stream_audio_processor_options.h +++ b/content/renderer/media/media_stream_audio_processor_options.h @@ -68,8 +68,6 @@ void StartAecDump(AudioProcessing* audio_processing); // Stops the echo cancellation dump in |audio_processing|. void StopAecDump(AudioProcessing* audio_processing); -void EnableAutomaticGainControl(AudioProcessing* audio_processing); - } // namespace content #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_ diff --git a/content/renderer/media/media_stream_audio_processor_unittest.cc b/content/renderer/media/media_stream_audio_processor_unittest.cc index f562055..a890d1d4 100644 --- a/content/renderer/media/media_stream_audio_processor_unittest.cc +++ b/content/renderer/media/media_stream_audio_processor_unittest.cc @@ -86,10 +86,8 @@ class MediaStreamAudioProcessorTest : public ::testing::Test { params_.frames_per_buffer(), base::TimeDelta::FromMilliseconds(10)); int16* output = NULL; - int new_volume = 0; while(audio_processor->ProcessAndConsumeData( - base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, - &output)) { + base::TimeDelta::FromMilliseconds(10), 255, false, &output)) { EXPECT_TRUE(output != NULL); EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), expected_output_sample_rate); @@ -103,41 +101,6 @@ class MediaStreamAudioProcessorTest : public ::testing::Test { } } - void VerifyDefaultComponents(MediaStreamAudioProcessor* audio_processor) { - webrtc::AudioProcessing* audio_processing = - audio_processor->audio_processing_.get(); -#if defined(OS_ANDROID) - EXPECT_TRUE(audio_processing->echo_control_mobile()->is_enabled()); - EXPECT_TRUE(audio_processing->echo_control_mobile()->routing_mode() == - webrtc::EchoControlMobile::kSpeakerphone); - EXPECT_FALSE(audio_processing->echo_cancellation()->is_enabled()); -#elif !defined(OS_IOS) - EXPECT_TRUE(audio_processing->echo_cancellation()->is_enabled()); - EXPECT_TRUE(audio_processing->echo_cancellation()->suppression_level() == - webrtc::EchoCancellation::kHighSuppression); - EXPECT_TRUE(audio_processing->echo_cancellation()->are_metrics_enabled()); - EXPECT_TRUE( - audio_processing->echo_cancellation()->is_delay_logging_enabled()); -#endif - - EXPECT_TRUE(audio_processing->noise_suppression()->is_enabled()); - EXPECT_TRUE(audio_processing->noise_suppression()->level() == - webrtc::NoiseSuppression::kHigh); - EXPECT_TRUE(audio_processing->high_pass_filter()->is_enabled()); - EXPECT_TRUE(audio_processing->gain_control()->is_enabled()); -#if defined(OS_ANDROID) || defined(OS_IOS) - EXPECT_TRUE(audio_processing->gain_control()->mode() == - webrtc::GainControl::kFixedDigital); - EXPECT_FALSE(audio_processing->voice_detection()->is_enabled()); -#else - EXPECT_TRUE(audio_processing->gain_control()->mode() == - webrtc::GainControl::kAdaptiveAnalog); - EXPECT_TRUE(audio_processing->voice_detection()->is_enabled()); - EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == - webrtc::VoiceDetection::kVeryLowLikelihood); -#endif - } - media::AudioParameters params_; }; @@ -162,7 +125,6 @@ TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { scoped_refptr<MediaStreamAudioProcessor> audio_processor( new MediaStreamAudioProcessor(params_, constraints, 0)); EXPECT_TRUE(audio_processor->has_audio_processing()); - VerifyDefaultComponents(audio_processor); ProcessDataAndVerifyFormat(audio_processor, kAudioProcessingSampleRate, diff --git a/content/renderer/media/webrtc_audio_capturer.cc b/content/renderer/media/webrtc_audio_capturer.cc index 561965e..ff4ecc7 100644 --- a/content/renderer/media/webrtc_audio_capturer.cc +++ b/content/renderer/media/webrtc_audio_capturer.cc @@ -478,22 +478,16 @@ void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, // Process and consume the data in the processor until there is not enough // data in the processor. int16* output = NULL; - int new_volume = 0; while (audio_processor->ProcessAndConsumeData( - audio_delay, current_volume, key_pressed, &new_volume, &output)) { + audio_delay, current_volume, key_pressed, &output)) { // Feed the post-processed data to the tracks. for (TrackList::ItemList::const_iterator it = tracks.begin(); it != tracks.end(); ++it) { (*it)->Capture(output, audio_delay, current_volume, key_pressed, need_audio_processing); } - - if (new_volume) { - SetVolume(new_volume); - - // Update the |current_volume| to avoid passing the old volume to AGC. - current_volume = new_volume; - } + // TODO(xians): Apply the new volume after AGC is working with the + // MediaStreamAudioProcessor. } } |