| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 #include <string.h> |
| 13 | 14 |
| 14 #include <iostream> | 15 #include <iostream> |
| 15 #include <memory> | 16 #include <memory> |
| 16 | 17 |
| 17 #include "gflags/gflags.h" | |
| 18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
| 19 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" | 19 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" |
| 20 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" | 20 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
| 21 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" | 21 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 22 #include "webrtc/modules/audio_coding/test/Channel.h" | 22 #include "webrtc/modules/audio_coding/test/Channel.h" |
| 23 #include "webrtc/modules/audio_coding/test/PCMFile.h" | 23 #include "webrtc/modules/audio_coding/test/PCMFile.h" |
| 24 #include "webrtc/modules/audio_coding/test/utility.h" | 24 #include "webrtc/modules/audio_coding/test/utility.h" |
| 25 #include "webrtc/rtc_base/flags.h" |
| 25 #include "webrtc/system_wrappers/include/event_wrapper.h" | 26 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 26 #include "webrtc/test/gtest.h" | 27 #include "webrtc/test/gtest.h" |
| 27 #include "webrtc/test/testsupport/fileutils.h" | 28 #include "webrtc/test/testsupport/fileutils.h" |
| 28 #include "webrtc/typedefs.h" | 29 #include "webrtc/typedefs.h" |
| 29 | 30 |
| 30 DEFINE_string(codec, "isac", "Codec Name"); | 31 DEFINE_string(codec, "isac", "Codec Name"); |
| 31 DEFINE_int32(sample_rate_hz, 16000, "Sampling rate in Hertz."); | 32 DEFINE_int(sample_rate_hz, 16000, "Sampling rate in Hertz."); |
| 32 DEFINE_int32(num_channels, 1, "Number of Channels."); | 33 DEFINE_int(num_channels, 1, "Number of Channels."); |
| 33 DEFINE_string(input_file, "", "Input file, PCM16 32 kHz, optional."); | 34 DEFINE_string(input_file, "", "Input file, PCM16 32 kHz, optional."); |
| 34 DEFINE_int32(delay, 0, "Delay in millisecond."); | 35 DEFINE_int(delay, 0, "Delay in millisecond."); |
| 35 DEFINE_bool(dtx, false, "Enable DTX at the sender side."); | 36 DEFINE_bool(dtx, false, "Enable DTX at the sender side."); |
| 36 DEFINE_bool(packet_loss, false, "Apply packet loss, c.f. Channel{.cc, .h}."); | 37 DEFINE_bool(packet_loss, false, "Apply packet loss, c.f. Channel{.cc, .h}."); |
| 37 DEFINE_bool(fec, false, "Use Forward Error Correction (FEC)."); | 38 DEFINE_bool(fec, false, "Use Forward Error Correction (FEC)."); |
| 39 DEFINE_bool(help, false, "Print this message."); |
| 38 | 40 |
| 39 namespace webrtc { | 41 namespace webrtc { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 struct CodecSettings { | 45 struct CodecSettings { |
| 44 char name[50]; | 46 char name[50]; |
| 45 int sample_rate_hz; | 47 int sample_rate_hz; |
| 46 int num_channels; | 48 int num_channels; |
| 47 }; | 49 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 delete channel_a2b_; | 75 delete channel_a2b_; |
| 74 channel_a2b_ = NULL; | 76 channel_a2b_ = NULL; |
| 75 } | 77 } |
| 76 in_file_a_.Close(); | 78 in_file_a_.Close(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void Initialize() { | 81 void Initialize() { |
| 80 test_cntr_ = 0; | 82 test_cntr_ = 0; |
| 81 std::string file_name = webrtc::test::ResourcePath( | 83 std::string file_name = webrtc::test::ResourcePath( |
| 82 "audio_coding/testfile32kHz", "pcm"); | 84 "audio_coding/testfile32kHz", "pcm"); |
| 83 if (FLAGS_input_file.size() > 0) | 85 if (strlen(FLAG_input_file) > 0) |
| 84 file_name = FLAGS_input_file; | 86 file_name = FLAG_input_file; |
| 85 in_file_a_.Open(file_name, 32000, "rb"); | 87 in_file_a_.Open(file_name, 32000, "rb"); |
| 86 ASSERT_EQ(0, acm_a_->InitializeReceiver()) << | 88 ASSERT_EQ(0, acm_a_->InitializeReceiver()) << |
| 87 "Couldn't initialize receiver.\n"; | 89 "Couldn't initialize receiver.\n"; |
| 88 ASSERT_EQ(0, acm_b_->InitializeReceiver()) << | 90 ASSERT_EQ(0, acm_b_->InitializeReceiver()) << |
| 89 "Couldn't initialize receiver.\n"; | 91 "Couldn't initialize receiver.\n"; |
| 90 | 92 |
| 91 if (FLAGS_delay > 0) { | 93 if (FLAG_delay > 0) { |
| 92 ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAGS_delay)) << | 94 ASSERT_EQ(0, acm_b_->SetMinimumPlayoutDelay(FLAG_delay)) << |
| 93 "Failed to set minimum delay.\n"; | 95 "Failed to set minimum delay.\n"; |
| 94 } | 96 } |
| 95 | 97 |
| 96 int num_encoders = acm_a_->NumberOfCodecs(); | 98 int num_encoders = acm_a_->NumberOfCodecs(); |
| 97 CodecInst my_codec_param; | 99 CodecInst my_codec_param; |
| 98 for (int n = 0; n < num_encoders; n++) { | 100 for (int n = 0; n < num_encoders; n++) { |
| 99 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)) << | 101 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)) << |
| 100 "Failed to get codec."; | 102 "Failed to get codec."; |
| 101 if (STR_CASE_CMP(my_codec_param.plname, "opus") == 0) | 103 if (STR_CASE_CMP(my_codec_param.plname, "opus") == 0) |
| 102 my_codec_param.channels = 1; | 104 my_codec_param.channels = 1; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 ASSERT_EQ(0, acm_a_->SetREDStatus(config.fec)) << | 161 ASSERT_EQ(0, acm_a_->SetREDStatus(config.fec)) << |
| 160 "Failed to set RED.\n"; | 162 "Failed to set RED.\n"; |
| 161 } | 163 } |
| 162 | 164 |
| 163 void ConfigChannel(bool packet_loss) { | 165 void ConfigChannel(bool packet_loss) { |
| 164 channel_a2b_->SetFECTestWithPacketLoss(packet_loss); | 166 channel_a2b_->SetFECTestWithPacketLoss(packet_loss); |
| 165 } | 167 } |
| 166 | 168 |
| 167 void OpenOutFile(const char* output_id) { | 169 void OpenOutFile(const char* output_id) { |
| 168 std::stringstream file_stream; | 170 std::stringstream file_stream; |
| 169 file_stream << "delay_test_" << FLAGS_codec << "_" << FLAGS_sample_rate_hz | 171 file_stream << "delay_test_" << FLAG_codec << "_" << FLAG_sample_rate_hz |
| 170 << "Hz" << "_" << FLAGS_delay << "ms.pcm"; | 172 << "Hz" << "_" << FLAG_delay << "ms.pcm"; |
| 171 std::cout << "Output file: " << file_stream.str() << std::endl << std::endl; | 173 std::cout << "Output file: " << file_stream.str() << std::endl << std::endl; |
| 172 std::string file_name = webrtc::test::OutputPath() + file_stream.str(); | 174 std::string file_name = webrtc::test::OutputPath() + file_stream.str(); |
| 173 out_file_b_.Open(file_name.c_str(), 32000, "wb"); | 175 out_file_b_.Open(file_name.c_str(), 32000, "wb"); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void Run(int duration_sec, const char* output_prefix) { | 178 void Run(int duration_sec, const char* output_prefix) { |
| 177 OpenOutFile(output_prefix); | 179 OpenOutFile(output_prefix); |
| 178 AudioFrame audio_frame; | 180 AudioFrame audio_frame; |
| 179 uint32_t out_freq_hz_b = out_file_b_.SamplingFrequency(); | 181 uint32_t out_freq_hz_b = out_file_b_.SamplingFrequency(); |
| 180 | 182 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 235 |
| 234 PCMFile in_file_a_; | 236 PCMFile in_file_a_; |
| 235 PCMFile out_file_b_; | 237 PCMFile out_file_b_; |
| 236 int test_cntr_; | 238 int test_cntr_; |
| 237 int encoding_sample_rate_hz_; | 239 int encoding_sample_rate_hz_; |
| 238 }; | 240 }; |
| 239 | 241 |
| 240 } // namespace webrtc | 242 } // namespace webrtc |
| 241 | 243 |
| 242 int main(int argc, char* argv[]) { | 244 int main(int argc, char* argv[]) { |
| 243 google::ParseCommandLineFlags(&argc, &argv, true); | 245 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { |
| 246 return 1; |
| 247 } |
| 248 if (FLAG_help) { |
| 249 rtc::FlagList::Print(nullptr, false); |
| 250 return 0; |
| 251 } |
| 252 |
| 244 webrtc::TestSettings test_setting; | 253 webrtc::TestSettings test_setting; |
| 245 strcpy(test_setting.codec.name, FLAGS_codec.c_str()); | 254 strcpy(test_setting.codec.name, FLAG_codec); |
| 246 | 255 |
| 247 if (FLAGS_sample_rate_hz != 8000 && | 256 if (FLAG_sample_rate_hz != 8000 && |
| 248 FLAGS_sample_rate_hz != 16000 && | 257 FLAG_sample_rate_hz != 16000 && |
| 249 FLAGS_sample_rate_hz != 32000 && | 258 FLAG_sample_rate_hz != 32000 && |
| 250 FLAGS_sample_rate_hz != 48000) { | 259 FLAG_sample_rate_hz != 48000) { |
| 251 std::cout << "Invalid sampling rate.\n"; | 260 std::cout << "Invalid sampling rate.\n"; |
| 252 return 1; | 261 return 1; |
| 253 } | 262 } |
| 254 test_setting.codec.sample_rate_hz = FLAGS_sample_rate_hz; | 263 test_setting.codec.sample_rate_hz = FLAG_sample_rate_hz; |
| 255 if (FLAGS_num_channels < 1 || FLAGS_num_channels > 2) { | 264 if (FLAG_num_channels < 1 || FLAG_num_channels > 2) { |
| 256 std::cout << "Only mono and stereo are supported.\n"; | 265 std::cout << "Only mono and stereo are supported.\n"; |
| 257 return 1; | 266 return 1; |
| 258 } | 267 } |
| 259 test_setting.codec.num_channels = FLAGS_num_channels; | 268 test_setting.codec.num_channels = FLAG_num_channels; |
| 260 test_setting.acm.dtx = FLAGS_dtx; | 269 test_setting.acm.dtx = FLAG_dtx; |
| 261 test_setting.acm.fec = FLAGS_fec; | 270 test_setting.acm.fec = FLAG_fec; |
| 262 test_setting.packet_loss = FLAGS_packet_loss; | 271 test_setting.packet_loss = FLAG_packet_loss; |
| 263 | 272 |
| 264 webrtc::DelayTest delay_test; | 273 webrtc::DelayTest delay_test; |
| 265 delay_test.Initialize(); | 274 delay_test.Initialize(); |
| 266 delay_test.Perform(&test_setting, 1, 240, "delay_test"); | 275 delay_test.Perform(&test_setting, 1, 240, "delay_test"); |
| 267 return 0; | 276 return 0; |
| 268 } | 277 } |
| OLD | NEW |