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

Side by Side Diff: content/renderer/media/webrtc_audio_device_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: checked echo_control_mobile()->is_enabled()) for android and ios 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 (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 <vector> 5 #include <vector>
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 class MockWebRtcAudioRendererSource : public WebRtcAudioRendererSource { 244 class MockWebRtcAudioRendererSource : public WebRtcAudioRendererSource {
245 public: 245 public:
246 explicit MockWebRtcAudioRendererSource(base::WaitableEvent* event) 246 explicit MockWebRtcAudioRendererSource(base::WaitableEvent* event)
247 : event_(event) { 247 : event_(event) {
248 DCHECK(event_); 248 DCHECK(event_);
249 } 249 }
250 virtual ~MockWebRtcAudioRendererSource() {} 250 virtual ~MockWebRtcAudioRendererSource() {}
251 251
252 // WebRtcAudioRendererSource implementation. 252 // WebRtcAudioRendererSource implementation.
253 virtual void RenderData(uint8* audio_data, 253 virtual void RenderData(media::AudioBus* audio_bus,
254 int number_of_channels, 254 int sample_rate,
255 int number_of_frames,
256 int audio_delay_milliseconds) OVERRIDE { 255 int audio_delay_milliseconds) OVERRIDE {
257 // Signal that a callback has been received. 256 // Signal that a callback has been received.
258 // Initialize the memory to zero to avoid uninitialized warning from 257 // Initialize the memory to zero to avoid uninitialized warning from
259 // Valgrind. 258 // Valgrind.
260 memset(audio_data, 0, 259 audio_bus->Zero();
261 sizeof(int16) * number_of_channels * number_of_frames);
262 event_->Signal(); 260 event_->Signal();
263 } 261 }
264 262
265 virtual void SetRenderFormat(const media::AudioParameters& params) OVERRIDE {
266 }
267
268 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE {}; 263 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE {};
269 264
270 private: 265 private:
271 base::WaitableEvent* event_; 266 base::WaitableEvent* event_;
272 267
273 DISALLOW_COPY_AND_ASSIGN(MockWebRtcAudioRendererSource); 268 DISALLOW_COPY_AND_ASSIGN(MockWebRtcAudioRendererSource);
274 }; 269 };
275 270
276 // Prints numerical information to stdout in a controlled format so we can plot 271 // Prints numerical information to stdout in a controlled format so we can plot
277 // the result. 272 // the result.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 bool enable_apm) { 320 bool enable_apm) {
326 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 321 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
327 new WebRtcAudioDeviceImpl()); 322 new WebRtcAudioDeviceImpl());
328 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 323 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
329 EXPECT_TRUE(engine.valid()); 324 EXPECT_TRUE(engine.valid());
330 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 325 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
331 EXPECT_TRUE(base.valid()); 326 EXPECT_TRUE(base.valid());
332 int err = base->Init(webrtc_audio_device.get()); 327 int err = base->Init(webrtc_audio_device.get());
333 EXPECT_EQ(0, err); 328 EXPECT_EQ(0, err);
334 329
335 // We use OnSetFormat() and SetRenderFormat() to configure the audio 330 // We use OnSetFormat() to configure the audio parameters so that this
336 // parameters so that this test can run on machine without hardware device. 331 // test can run on machine without hardware device.
337 const media::AudioParameters params = media::AudioParameters( 332 const media::AudioParameters params = media::AudioParameters(
338 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 333 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
339 48000, 2, 480); 334 48000, 2, 480);
340 PeerConnectionAudioSink* capturer_sink = 335 PeerConnectionAudioSink* capturer_sink =
341 static_cast<PeerConnectionAudioSink*>(webrtc_audio_device.get()); 336 static_cast<PeerConnectionAudioSink*>(webrtc_audio_device.get());
342 WebRtcAudioRendererSource* renderer_source = 337 WebRtcAudioRendererSource* renderer_source =
343 static_cast<WebRtcAudioRendererSource*>(webrtc_audio_device.get()); 338 static_cast<WebRtcAudioRendererSource*>(webrtc_audio_device.get());
344 renderer_source->SetRenderFormat(params);
345 339
346 // Turn on/off all the signal processing components like AGC, AEC and NS. 340 // Turn on/off all the signal processing components like AGC, AEC and NS.
347 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get()); 341 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get());
348 EXPECT_TRUE(audio_processing.valid()); 342 EXPECT_TRUE(audio_processing.valid());
349 audio_processing->SetAgcStatus(enable_apm); 343 audio_processing->SetAgcStatus(enable_apm);
350 audio_processing->SetNsStatus(enable_apm); 344 audio_processing->SetNsStatus(enable_apm);
351 audio_processing->SetEcStatus(enable_apm); 345 audio_processing->SetEcStatus(enable_apm);
352 346
353 // Create a voice channel for the WebRtc. 347 // Create a voice channel for the WebRtc.
354 int channel = base->CreateChannel(); 348 int channel = base->CreateChannel();
355 EXPECT_NE(-1, channel); 349 EXPECT_NE(-1, channel);
356 SetChannelCodec(engine.get(), channel); 350 SetChannelCodec(engine.get(), channel);
357 351
358 // Use our fake network transmission and start playout and recording. 352 // Use our fake network transmission and start playout and recording.
359 ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get()); 353 ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get());
360 EXPECT_TRUE(network.valid()); 354 EXPECT_TRUE(network.valid());
361 scoped_ptr<WebRTCTransportImpl> transport( 355 scoped_ptr<WebRTCTransportImpl> transport(
362 new WebRTCTransportImpl(network.get())); 356 new WebRTCTransportImpl(network.get()));
363 EXPECT_EQ(0, network->RegisterExternalTransport(channel, *transport.get())); 357 EXPECT_EQ(0, network->RegisterExternalTransport(channel, *transport.get()));
364 EXPECT_EQ(0, base->StartPlayout(channel)); 358 EXPECT_EQ(0, base->StartPlayout(channel));
365 EXPECT_EQ(0, base->StartSend(channel)); 359 EXPECT_EQ(0, base->StartSend(channel));
366 360
367 // Read speech data from a speech test file. 361 // Read speech data from a speech test file.
368 const int input_packet_size = 362 const int input_packet_size =
369 params.frames_per_buffer() * 2 * params.channels(); 363 params.frames_per_buffer() * 2 * params.channels();
370 const int num_output_channels = webrtc_audio_device->output_channels();
371 const int output_packet_size = webrtc_audio_device->output_buffer_size() * 2 *
372 num_output_channels;
373 const size_t length = input_packet_size * kNumberOfPacketsForLoopbackTest; 364 const size_t length = input_packet_size * kNumberOfPacketsForLoopbackTest;
374 scoped_ptr<char[]> capture_data(new char[length]); 365 scoped_ptr<char[]> capture_data(new char[length]);
375 ReadDataFromSpeechFile(capture_data.get(), length); 366 ReadDataFromSpeechFile(capture_data.get(), length);
376 367
377 // Start the timer. 368 // Start the timer.
378 scoped_ptr<uint8[]> buffer(new uint8[output_packet_size]); 369 scoped_ptr<media::AudioBus> render_audio_bus(media::AudioBus::Create(params));
379 base::Time start_time = base::Time::Now(); 370 base::Time start_time = base::Time::Now();
380 int delay = 0; 371 int delay = 0;
381 std::vector<int> voe_channels; 372 std::vector<int> voe_channels;
382 voe_channels.push_back(channel); 373 voe_channels.push_back(channel);
383 for (int j = 0; j < kNumberOfPacketsForLoopbackTest; ++j) { 374 for (int j = 0; j < kNumberOfPacketsForLoopbackTest; ++j) {
384 // Sending fake capture data to WebRtc. 375 // Sending fake capture data to WebRtc.
385 capturer_sink->OnData( 376 capturer_sink->OnData(
386 reinterpret_cast<int16*>(capture_data.get() + input_packet_size * j), 377 reinterpret_cast<int16*>(capture_data.get() + input_packet_size * j),
387 params.sample_rate(), 378 params.sample_rate(),
388 params.channels(), 379 params.channels(),
389 params.frames_per_buffer(), 380 params.frames_per_buffer(),
390 voe_channels, 381 voe_channels,
391 kHardwareLatencyInMs, 382 kHardwareLatencyInMs,
392 1.0, 383 1.0,
393 enable_apm, 384 enable_apm,
394 false); 385 false);
395 386
396 // Receiving data from WebRtc. 387 // Receiving data from WebRtc.
397 renderer_source->RenderData( 388 renderer_source->RenderData(
398 reinterpret_cast<uint8*>(buffer.get()), 389 render_audio_bus.get(), params.sample_rate(),
399 num_output_channels, webrtc_audio_device->output_buffer_size(),
400 kHardwareLatencyInMs + delay); 390 kHardwareLatencyInMs + delay);
401 delay = (base::Time::Now() - start_time).InMilliseconds(); 391 delay = (base::Time::Now() - start_time).InMilliseconds();
402 } 392 }
403 393
404 int latency = (base::Time::Now() - start_time).InMilliseconds(); 394 int latency = (base::Time::Now() - start_time).InMilliseconds();
405 395
406 EXPECT_EQ(0, base->StopSend(channel)); 396 EXPECT_EQ(0, base->StopSend(channel));
407 EXPECT_EQ(0, base->StopPlayout(channel)); 397 EXPECT_EQ(0, base->StopPlayout(channel));
408 EXPECT_EQ(0, base->DeleteChannel(channel)); 398 EXPECT_EQ(0, base->DeleteChannel(channel));
409 EXPECT_EQ(0, base->Terminate()); 399 EXPECT_EQ(0, base->Terminate());
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 LOG(WARNING) << "Test disabled due to the test hangs on WinXP."; 978 LOG(WARNING) << "Test disabled due to the test hangs on WinXP.";
989 return; 979 return;
990 } 980 }
991 #endif 981 #endif
992 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true); 982 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true);
993 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)", 983 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)",
994 "t", latency); 984 "t", latency);
995 } 985 }
996 986
997 } // namespace content 987 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698