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

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

Issue 139303016: Feed the render data to MediaStreamAudioProcessor and used AudioBus in render callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and added check the thread check on the destructor Created 6 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 | Annotate | Revision Log
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ReadDataFromSpeechFile(capture_data.get(), length); 73 ReadDataFromSpeechFile(capture_data.get(), length);
74 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); 74 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get());
75 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( 75 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create(
76 params_.channels(), params_.frames_per_buffer()); 76 params_.channels(), params_.frames_per_buffer());
77 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { 77 for (int i = 0; i < kNumberOfPacketsForTest; ++i) {
78 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); 78 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2);
79 audio_processor->PushCaptureData(data_bus.get()); 79 audio_processor->PushCaptureData(data_bus.get());
80 80
81 // |audio_processor| does nothing when the audio processing is off in 81 // |audio_processor| does nothing when the audio processing is off in
82 // the processor. 82 // the processor.
83 audio_processor->PushRenderData( 83 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get();
84 data_ptr, 84 #if defined(OS_ANDROID) || defined(OS_IOS)
85 params_.sample_rate(), params_.channels(), 85 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled();
tommi (sloooow) - chröme 2014/02/17 15:03:44 out of curiosity, what's the difference between ec
no longer working on chromium 2014/02/17 17:15:32 echo_control_mobile() is the AEC used by mobile, a
tommi (sloooow) - chröme 2014/02/18 12:54:12 What I'm trying to understand is the difference be
no longer working on chromium 2014/02/18 17:37:53 Comment has been addressed offline, the answer is
86 params_.frames_per_buffer(), base::TimeDelta::FromMilliseconds(10)); 86 #else
87 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled();
88 #endif
89 if (is_aec_enabled) {
90 audio_processor->OnPlayoutData(data_bus.get(), params_.sample_rate(),
91 10);
92 }
87 93
88 int16* output = NULL; 94 int16* output = NULL;
89 int new_volume = 0; 95 int new_volume = 0;
90 while(audio_processor->ProcessAndConsumeData( 96 while(audio_processor->ProcessAndConsumeData(
91 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, 97 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume,
92 &output)) { 98 &output)) {
93 EXPECT_TRUE(output != NULL); 99 EXPECT_TRUE(output != NULL);
94 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), 100 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(),
95 expected_output_sample_rate); 101 expected_output_sample_rate);
96 EXPECT_EQ(audio_processor->OutputFormat().channels(), 102 EXPECT_EQ(audio_processor->OutputFormat().channels(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 #endif 144 #endif
139 } 145 }
140 146
141 media::AudioParameters params_; 147 media::AudioParameters params_;
142 }; 148 };
143 149
144 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { 150 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) {
145 // Setup the audio processor without enabling the flag. 151 // Setup the audio processor without enabling the flag.
146 blink::WebMediaConstraints constraints; 152 blink::WebMediaConstraints constraints;
147 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 153 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
148 new MediaStreamAudioProcessor(params_, constraints, 0)); 154 new MediaStreamAudioProcessor(params_, constraints, 0, NULL));
149 EXPECT_FALSE(audio_processor->has_audio_processing()); 155 EXPECT_FALSE(audio_processor->has_audio_processing());
150 156
151 ProcessDataAndVerifyFormat(audio_processor, 157 ProcessDataAndVerifyFormat(audio_processor,
152 params_.sample_rate(), 158 params_.sample_rate(),
153 params_.channels(), 159 params_.channels(),
154 params_.sample_rate() / 100); 160 params_.sample_rate() / 100);
155 } 161 }
156 162
157 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { 163 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) {
158 // Setup the audio processor with enabling the flag. 164 // Setup the audio processor with enabling the flag.
159 CommandLine::ForCurrentProcess()->AppendSwitch( 165 CommandLine::ForCurrentProcess()->AppendSwitch(
160 switches::kEnableAudioTrackProcessing); 166 switches::kEnableAudioTrackProcessing);
161 blink::WebMediaConstraints constraints; 167 blink::WebMediaConstraints constraints;
162 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 168 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
163 new MediaStreamAudioProcessor(params_, constraints, 0)); 169 new MediaStreamAudioProcessor(params_, constraints, 0, NULL));
164 EXPECT_TRUE(audio_processor->has_audio_processing()); 170 EXPECT_TRUE(audio_processor->has_audio_processing());
165 VerifyDefaultComponents(audio_processor); 171 VerifyDefaultComponents(audio_processor);
166 172
167 ProcessDataAndVerifyFormat(audio_processor, 173 ProcessDataAndVerifyFormat(audio_processor,
168 kAudioProcessingSampleRate, 174 kAudioProcessingSampleRate,
169 kAudioProcessingNumberOfChannel, 175 kAudioProcessingNumberOfChannel,
170 kAudioProcessingSampleRate / 100); 176 kAudioProcessingSampleRate / 100);
171 } 177 }
172 178
173 } // namespace content 179 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698