| 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 <stdio.h> | 11 #include <stdio.h> |
| 12 | 12 |
| 13 #include <iostream> | 13 #include <iostream> |
| 14 | 14 |
| 15 #include "gflags/gflags.h" | |
| 16 #include "webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.h" | 15 #include "webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.h" |
| 16 #include "webrtc/rtc_base/flags.h" |
| 17 #include "webrtc/test/testsupport/fileutils.h" | 17 #include "webrtc/test/testsupport/fileutils.h" |
| 18 #include "webrtc/typedefs.h" | 18 #include "webrtc/typedefs.h" |
| 19 | 19 |
| 20 // Flag validators. | |
| 21 static bool ValidateRuntime(const char* flagname, int value) { | |
| 22 if (value > 0) // Value is ok. | |
| 23 return true; | |
| 24 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value)); | |
| 25 return false; | |
| 26 } | |
| 27 static bool ValidateLossrate(const char* flagname, int value) { | |
| 28 if (value >= 0) // Value is ok. | |
| 29 return true; | |
| 30 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value)); | |
| 31 return false; | |
| 32 } | |
| 33 static bool ValidateDriftfactor(const char* flagname, double value) { | |
| 34 if (value >= 0.0 && value < 1.0) // Value is ok. | |
| 35 return true; | |
| 36 printf("Invalid value for --%s: %f\n", flagname, value); | |
| 37 return false; | |
| 38 } | |
| 39 | |
| 40 // Define command line flags. | 20 // Define command line flags. |
| 41 DEFINE_int32(runtime_ms, 10000, "Simulated runtime in ms."); | 21 DEFINE_int(runtime_ms, 10000, "Simulated runtime in ms."); |
| 42 static const bool runtime_ms_dummy = | 22 DEFINE_int(lossrate, 10, |
| 43 google::RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime); | 23 "Packet lossrate; drop every N packets."); |
| 44 DEFINE_int32(lossrate, 10, | 24 DEFINE_float(drift, 0.1f, |
| 45 "Packet lossrate; drop every N packets."); | |
| 46 static const bool lossrate_dummy = | |
| 47 google::RegisterFlagValidator(&FLAGS_lossrate, &ValidateLossrate); | |
| 48 DEFINE_double(drift, 0.1, | |
| 49 "Clockdrift factor."); | 25 "Clockdrift factor."); |
| 50 static const bool drift_dummy = | 26 DEFINE_bool(help, false, "Print this message."); |
| 51 google::RegisterFlagValidator(&FLAGS_drift, &ValidateDriftfactor); | |
| 52 | 27 |
| 53 int main(int argc, char* argv[]) { | 28 int main(int argc, char* argv[]) { |
| 54 std::string program_name = argv[0]; | 29 std::string program_name = argv[0]; |
| 55 std::string usage = "Tool for measuring the speed of NetEq.\n" | 30 std::string usage = "Tool for measuring the speed of NetEq.\n" |
| 56 "Usage: " + program_name + " [options]\n\n" | 31 "Usage: " + program_name + " [options]\n\n" |
| 57 " --runtime_ms=N runtime in ms; default is 10000 ms\n" | 32 " --runtime_ms=N runtime in ms; default is 10000 ms\n" |
| 58 " --lossrate=N drop every N packets; default is 10\n" | 33 " --lossrate=N drop every N packets; default is 10\n" |
| 59 " --drift=F clockdrift factor between 0.0 and 1.0; " | 34 " --drift=F clockdrift factor between 0.0 and 1.0; " |
| 60 "default is 0.1\n"; | 35 "default is 0.1\n"; |
| 61 google::SetUsageMessage(usage); | |
| 62 google::ParseCommandLineFlags(&argc, &argv, true); | |
| 63 webrtc::test::SetExecutablePath(argv[0]); | 36 webrtc::test::SetExecutablePath(argv[0]); |
| 64 | 37 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || |
| 65 if (argc != 1) { | 38 FLAG_help || argc != 1) { |
| 66 // Print usage information. | 39 printf("%s", usage.c_str()); |
| 67 std::cout << google::ProgramUsage(); | 40 if (FLAG_help) { |
| 68 return 0; | 41 rtc::FlagList::Print(nullptr, false); |
| 42 return 0; |
| 43 } |
| 44 return 1; |
| 69 } | 45 } |
| 46 RTC_CHECK_GT(FLAG_runtime_ms, 0); |
| 47 RTC_CHECK_GE(FLAG_lossrate, 0); |
| 48 RTC_CHECK(FLAG_drift >= 0.0 && FLAG_drift < 1.0); |
| 70 | 49 |
| 71 int64_t result = | 50 int64_t result = |
| 72 webrtc::test::NetEqPerformanceTest::Run(FLAGS_runtime_ms, FLAGS_lossrate, | 51 webrtc::test::NetEqPerformanceTest::Run(FLAG_runtime_ms, FLAG_lossrate, |
| 73 FLAGS_drift); | 52 FLAG_drift); |
| 74 if (result <= 0) { | 53 if (result <= 0) { |
| 75 std::cout << "There was an error" << std::endl; | 54 std::cout << "There was an error" << std::endl; |
| 76 return -1; | 55 return -1; |
| 77 } | 56 } |
| 78 | 57 |
| 79 std::cout << "Simulation done" << std::endl; | 58 std::cout << "Simulation done" << std::endl; |
| 80 std::cout << "Runtime = " << result << " ms" << std::endl; | 59 std::cout << "Runtime = " << result << " ms" << std::endl; |
| 81 return 0; | 60 return 0; |
| 82 } | 61 } |
| OLD | NEW |