Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/file_util.h" | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "content/public/common/content_switches.h" | |
| 12 #include "content/renderer/media/rtc_media_constraints.h" | |
| 13 #include "content/renderer/media/webrtc_audio_processor.h" | |
| 14 #include "media/audio/audio_parameters.h" | |
| 15 #include "media/base/audio_bus.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | |
| 19 | |
| 20 using ::testing::_; | |
| 21 using ::testing::AnyNumber; | |
| 22 using ::testing::AtLeast; | |
| 23 using ::testing::Return; | |
| 24 | |
| 25 namespace content { | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 #if defined(ANDROID) | |
| 30 const int kAudioProcessingSampleRate = 16000; | |
| 31 #else | |
| 32 const int kAudioProcessingSampleRate = 32000; | |
| 33 #endif | |
| 34 const int kAudioProcessingNumberOfChannel = 1; | |
| 35 | |
| 36 // The number of packers used for testing. | |
| 37 const int kNumberOfPacketsForTest = 100; | |
| 38 | |
| 39 void ReadDataFromSpeechFile(char* data, int length) { | |
| 40 base::FilePath file; | |
| 41 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file)); | |
| 42 file = file.Append(FILE_PATH_LITERAL("media")) | |
| 43 .Append(FILE_PATH_LITERAL("test")) | |
| 44 .Append(FILE_PATH_LITERAL("data")) | |
| 45 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw")); | |
|
Henrik Grunell
2013/11/22 09:03:36
Is this a common way of specifying a file used in
no longer working on chromium
2013/11/22 13:27:53
yes.
| |
| 46 DCHECK(base::PathExists(file)); | |
| 47 int64 data_file_size64 = 0; | |
| 48 DCHECK(file_util::GetFileSize(file, &data_file_size64)); | |
| 49 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); | |
| 50 DCHECK(data_file_size64 > length); | |
|
Henrik Grunell
2013/11/22 09:03:36
Only do this check in debug builds? (If you change
no longer working on chromium
2013/11/22 13:27:53
that is unittest, DCHECK is enough.
| |
| 51 } | |
| 52 | |
| 53 // Constant constraint keys which enables default audio constraints on | |
| 54 // mediastreams with audio. | |
| 55 struct { | |
| 56 const char* key; | |
| 57 const char* value; | |
| 58 } const kDefaultAudioConstraints[] = { | |
|
tommi (sloooow) - chröme
2013/11/21 19:52:03
make this a static const inside ApplyFixedAudioCon
no longer working on chromium
2013/11/22 13:27:53
Done.
| |
| 59 { webrtc::MediaConstraintsInterface::kEchoCancellation, | |
| 60 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 61 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | |
|
Henrik Grunell
2013/11/22 09:03:36
Why do we need to set experimental AEC platform co
no longer working on chromium
2013/11/22 13:27:53
This is the same as the production code. Do you kn
Henrik Grunell
2013/11/25 10:52:02
The reason is to not make any assumptions about th
Henrik Grunell
2013/11/26 08:08:44
We decided to revisit further testing including th
| |
| 62 // Enable the extended filter mode AEC on platforms with known echo issues. | |
| 63 { webrtc::MediaConstraintsInterface::kExperimentalEchoCancellation, | |
| 64 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 65 #endif | |
| 66 { webrtc::MediaConstraintsInterface::kAutoGainControl, | |
| 67 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 68 { webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, | |
| 69 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 70 { webrtc::MediaConstraintsInterface::kNoiseSuppression, | |
| 71 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 72 { webrtc::MediaConstraintsInterface::kHighpassFilter, | |
| 73 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 74 }; | |
| 75 | |
| 76 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { | |
| 77 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | |
| 78 constraints->AddMandatory(kDefaultAudioConstraints[i].key, | |
| 79 kDefaultAudioConstraints[i].value, false); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 } // namespace | |
| 84 | |
| 85 class WebRtcAudioProcessorTest : public ::testing::Test { | |
| 86 public: | |
| 87 WebRtcAudioProcessorTest() | |
| 88 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
| 89 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) { | |
| 90 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 91 switches::kEnableAudioTrackProcessing); | |
|
tommi (sloooow) - chröme
2013/11/21 19:52:03
is this a common thing to do for tests? could we
no longer working on chromium
2013/11/22 13:27:53
That is what I found from the current unittests.
tommi (sloooow) - chröme
2013/11/22 14:32:42
what is this falg you speak of? :)
I understand t
no longer working on chromium
2013/11/25 16:36:26
flag means switches::kEnableAudioTrackProcessing.
| |
| 92 } | |
| 93 | |
| 94 protected: | |
| 95 // Helper method to save duplicated code. | |
| 96 void ProcessDataAndVerifyFormat(WebRtcAudioProcessor* audio_processor, | |
| 97 int expected_output_sample_rate, | |
| 98 int expected_output_channels, | |
| 99 int expected_output_buffer_size) { | |
| 100 // Read the audio data from a file. | |
| 101 const int packet_size = | |
| 102 params_.frames_per_buffer() * 2 * params_.channels(); | |
| 103 const size_t length = packet_size * kNumberOfPacketsForTest; | |
| 104 scoped_ptr<char[]> capture_data(new char[length]); | |
| 105 ReadDataFromSpeechFile(capture_data.get(), length); | |
| 106 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); | |
| 107 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( | |
| 108 params_.channels(), params_.frames_per_buffer()); | |
| 109 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { | |
| 110 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); | |
| 111 audio_processor->PushCaptureData(data_bus.get()); | |
| 112 | |
| 113 // Feed data as render data to the processor, this does not cost anything | |
|
Henrik Grunell
2013/11/22 09:03:36
"Feed data as render data to the processor" is red
no longer working on chromium
2013/11/22 13:27:53
Done.
| |
| 114 // when the audio processing is off in the processor. | |
| 115 audio_processor->PushRenderData( | |
| 116 data_ptr, | |
| 117 params_.sample_rate(), params_.channels(), | |
| 118 params_.frames_per_buffer(), base::TimeDelta::FromMilliseconds(10)); | |
| 119 | |
| 120 // Process and consume the data in the processor. | |
|
Henrik Grunell
2013/11/22 09:03:36
This comment is redundant. Remove.
no longer working on chromium
2013/11/22 13:27:53
Done.
| |
| 121 int16* output = NULL; | |
| 122 while(audio_processor->ProcessAndConsumeData( | |
| 123 base::TimeDelta::FromMilliseconds(10), 255, false, &output)) { | |
| 124 EXPECT_TRUE(output != NULL); | |
| 125 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), | |
| 126 expected_output_sample_rate); | |
| 127 EXPECT_EQ(audio_processor->OutputFormat().channels(), | |
| 128 expected_output_channels); | |
| 129 EXPECT_EQ(audio_processor->OutputFormat().frames_per_buffer(), | |
| 130 expected_output_buffer_size); | |
| 131 } | |
| 132 | |
| 133 data_ptr += params_.frames_per_buffer() * params_.channels(); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 media::AudioParameters params_; | |
| 138 }; | |
| 139 | |
| 140 TEST_F(WebRtcAudioProcessorTest, WithoutAudioProcessing) { | |
|
Henrik Grunell
2013/11/22 09:03:36
I suggest testing function by function in separate
no longer working on chromium
2013/11/22 13:27:53
Yes, PushCaptureData, PushRenderData and ProcessAn
Henrik Grunell
2013/11/25 10:52:02
OK, if it doesn't make sense to test individual fu
no longer working on chromium
2013/11/25 16:36:26
Done.
| |
| 141 // Setup the audio processor with empty constraint. | |
| 142 RTCMediaConstraints constraints; | |
| 143 WebRtcAudioProcessor audio_processor(&constraints); | |
| 144 audio_processor.SetCaptureFormat(params_); | |
| 145 EXPECT_FALSE(audio_processor.has_audio_processing()); | |
| 146 | |
| 147 ProcessDataAndVerifyFormat(&audio_processor, | |
| 148 params_.sample_rate(), | |
| 149 params_.channels(), | |
| 150 params_.sample_rate() / 100); | |
| 151 } | |
| 152 | |
| 153 TEST_F(WebRtcAudioProcessorTest, WithAudioProcessing) { | |
|
Henrik Grunell
2013/11/22 09:03:36
Is there any way we can test different sets of con
no longer working on chromium
2013/11/22 13:27:53
WebRtcAudioProcessor can take one constraint at it
Henrik Grunell
2013/11/25 10:52:02
Well, no, I mean testing this class. You set const
no longer working on chromium
2013/11/25 16:36:26
As discussed offline, I don't have time to add mor
| |
| 154 // Setup the audio processor with default constraint. | |
| 155 RTCMediaConstraints constraints; | |
| 156 ApplyFixedAudioConstraints(&constraints); | |
| 157 WebRtcAudioProcessor audio_processor(&constraints); | |
| 158 audio_processor.SetCaptureFormat(params_); | |
| 159 EXPECT_TRUE(audio_processor.has_audio_processing()); | |
| 160 | |
| 161 ProcessDataAndVerifyFormat(&audio_processor, | |
| 162 kAudioProcessingSampleRate, | |
| 163 kAudioProcessingNumberOfChannel, | |
| 164 kAudioProcessingSampleRate / 100); | |
| 165 } | |
| 166 | |
| 167 } // namespace content | |
| OLD | NEW |