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

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

Issue 594233002: Strip away the keyboard mic channel if no audio processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@change_stream_layout_to_kmic
Patch Set: Rebase Created 6 years, 2 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
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/aligned_memory.h" 9 #include "base/memory/aligned_memory.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 22 matching lines...) Expand all
33 #if defined(ANDROID) 33 #if defined(ANDROID)
34 const int kAudioProcessingSampleRate = 16000; 34 const int kAudioProcessingSampleRate = 16000;
35 #else 35 #else
36 const int kAudioProcessingSampleRate = 32000; 36 const int kAudioProcessingSampleRate = 32000;
37 #endif 37 #endif
38 const int kAudioProcessingNumberOfChannel = 1; 38 const int kAudioProcessingNumberOfChannel = 1;
39 39
40 // The number of packers used for testing. 40 // The number of packers used for testing.
41 const int kNumberOfPacketsForTest = 100; 41 const int kNumberOfPacketsForTest = 100;
42 42
43 const int kMaxNumberOfPlayoutDataChannels = 2;
44
43 void ReadDataFromSpeechFile(char* data, int length) { 45 void ReadDataFromSpeechFile(char* data, int length) {
44 base::FilePath file; 46 base::FilePath file;
45 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file)); 47 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file));
46 file = file.Append(FILE_PATH_LITERAL("media")) 48 file = file.Append(FILE_PATH_LITERAL("media"))
47 .Append(FILE_PATH_LITERAL("test")) 49 .Append(FILE_PATH_LITERAL("test"))
48 .Append(FILE_PATH_LITERAL("data")) 50 .Append(FILE_PATH_LITERAL("data"))
49 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw")); 51 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw"));
50 DCHECK(base::PathExists(file)); 52 DCHECK(base::PathExists(file));
51 int64 data_file_size64 = 0; 53 int64 data_file_size64 = 0;
52 DCHECK(base::GetFileSize(file, &data_file_size64)); 54 DCHECK(base::GetFileSize(file, &data_file_size64));
(...skipping 19 matching lines...) Expand all
72 // Read the audio data from a file. 74 // Read the audio data from a file.
73 const media::AudioParameters& params = audio_processor->InputFormat(); 75 const media::AudioParameters& params = audio_processor->InputFormat();
74 const int packet_size = 76 const int packet_size =
75 params.frames_per_buffer() * 2 * params.channels(); 77 params.frames_per_buffer() * 2 * params.channels();
76 const size_t length = packet_size * kNumberOfPacketsForTest; 78 const size_t length = packet_size * kNumberOfPacketsForTest;
77 scoped_ptr<char[]> capture_data(new char[length]); 79 scoped_ptr<char[]> capture_data(new char[length]);
78 ReadDataFromSpeechFile(capture_data.get(), length); 80 ReadDataFromSpeechFile(capture_data.get(), length);
79 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); 81 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get());
80 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( 82 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create(
81 params.channels(), params.frames_per_buffer()); 83 params.channels(), params.frames_per_buffer());
84
85 // |data_bus_playout| is used if the number of capture channels is larger
86 // that max allowed playout channels. |data_bus_playout_to_use| points to
87 // the AudioBus to use, either |data_bus| or |data_bus_playout|.
88 scoped_ptr<media::AudioBus> data_bus_playout;
89 media::AudioBus* data_bus_playout_to_use = data_bus.get();
90 if (params.channels() > kMaxNumberOfPlayoutDataChannels) {
91 data_bus_playout =
92 media::AudioBus::CreateWrapper(kMaxNumberOfPlayoutDataChannels);
93 data_bus_playout->set_frames(params.frames_per_buffer());
94 data_bus_playout_to_use = data_bus_playout.get();
95 }
96
82 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { 97 for (int i = 0; i < kNumberOfPacketsForTest; ++i) {
83 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); 98 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2);
84 audio_processor->PushCaptureData(data_bus.get()); 99 audio_processor->PushCaptureData(data_bus.get());
85 100
86 // |audio_processor| does nothing when the audio processing is off in 101 // |audio_processor| does nothing when the audio processing is off in
87 // the processor. 102 // the processor.
88 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get(); 103 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get();
89 #if defined(OS_ANDROID) || defined(OS_IOS) 104 #if defined(OS_ANDROID) || defined(OS_IOS)
90 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled(); 105 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled();
91 // AEC should be turned off for mobiles. 106 // AEC should be turned off for mobiles.
92 DCHECK(!ap || !ap->echo_cancellation()->is_enabled()); 107 DCHECK(!ap || !ap->echo_cancellation()->is_enabled());
93 #else 108 #else
94 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled(); 109 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled();
95 #endif 110 #endif
96 if (is_aec_enabled) { 111 if (is_aec_enabled) {
97 audio_processor->OnPlayoutData(data_bus.get(), params.sample_rate(), 112 if (params.channels() > kMaxNumberOfPlayoutDataChannels) {
98 10); 113 for (int i = 0; i < kMaxNumberOfPlayoutDataChannels; ++i) {
114 data_bus_playout->SetChannelData(
115 i, const_cast<float*>(data_bus->channel(i)));
116 }
117 }
118 audio_processor->OnPlayoutData(data_bus_playout_to_use,
119 params.sample_rate(), 10);
99 } 120 }
100 121
101 int16* output = NULL; 122 int16* output = NULL;
102 int new_volume = 0; 123 int new_volume = 0;
103 while(audio_processor->ProcessAndConsumeData( 124 while(audio_processor->ProcessAndConsumeData(
104 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, 125 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume,
105 &output)) { 126 &output)) {
106 EXPECT_TRUE(output != NULL); 127 EXPECT_TRUE(output != NULL);
107 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), 128 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(),
108 expected_output_sample_rate); 129 expected_output_sample_rate);
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 EXPECT_TRUE(output != NULL); 483 EXPECT_TRUE(output != NULL);
463 EXPECT_EQ(output_bus->channel(0)[0], 0); 484 EXPECT_EQ(output_bus->channel(0)[0], 0);
464 EXPECT_NE(output_bus->channel(1)[0], 0); 485 EXPECT_NE(output_bus->channel(1)[0], 0);
465 } 486 }
466 487
467 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 488 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
468 // |audio_processor|. 489 // |audio_processor|.
469 audio_processor = NULL; 490 audio_processor = NULL;
470 } 491 }
471 492
493 TEST_F(MediaStreamAudioProcessorTest, TestWithKeyboardMicChannel) {
494 MockMediaConstraintFactory constraint_factory;
495 constraint_factory.AddMandatory(
496 MediaAudioConstraints::kGoogExperimentalNoiseSuppression, true);
497 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
498 new WebRtcAudioDeviceImpl());
499 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
500 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
501 constraint_factory.CreateWebMediaConstraints(), 0,
502 webrtc_audio_device.get()));
503 EXPECT_TRUE(audio_processor->has_audio_processing());
504
505 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
506 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
507 48000, 16, 512);
508 audio_processor->OnCaptureFormatChanged(params);
509
510 ProcessDataAndVerifyFormat(audio_processor.get(),
511 kAudioProcessingSampleRate,
512 kAudioProcessingNumberOfChannel,
513 kAudioProcessingSampleRate / 100);
514 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
515 // |audio_processor|.
516 audio_processor = NULL;
517 }
518
519 TEST_F(MediaStreamAudioProcessorTest,
520 TestWithKeyboardMicChannelWithoutProcessing) {
521 // Setup the audio processor with disabled flag on.
522 CommandLine::ForCurrentProcess()->AppendSwitch(
523 switches::kDisableAudioTrackProcessing);
524 MockMediaConstraintFactory constraint_factory;
525 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
526 new WebRtcAudioDeviceImpl());
527 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
528 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
529 constraint_factory.CreateWebMediaConstraints(), 0,
530 webrtc_audio_device.get()));
531 EXPECT_FALSE(audio_processor->has_audio_processing());
532
533 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
534 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
535 48000, 16, 512);
536 audio_processor->OnCaptureFormatChanged(params);
537
538 ProcessDataAndVerifyFormat(
539 audio_processor.get(),
540 params.sample_rate(),
541 media::ChannelLayoutToChannelCount(media::CHANNEL_LAYOUT_STEREO),
542 params.sample_rate() / 100);
543 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
544 // |audio_processor|.
545 audio_processor = NULL;
546 }
547
472 } // namespace content 548 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698