1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <stdio.h>
12
13 #include <iostream>
14
15 #include "gflags/gflags.h"
16 #include "webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.h"
17 #include "webrtc/typedefs.h"
18
19 // Flag validators.
ValidateRuntime(const char * flagname,int value)20 static bool ValidateRuntime(const char* flagname, int value) {
21 if (value > 0) // Value is ok.
22 return true;
23 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value));
24 return false;
25 }
ValidateLossrate(const char * flagname,int value)26 static bool ValidateLossrate(const char* flagname, int value) {
27 if (value >= 0) // Value is ok.
28 return true;
29 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value));
30 return false;
31 }
ValidateDriftfactor(const char * flagname,double value)32 static bool ValidateDriftfactor(const char* flagname, double value) {
33 if (value >= 0.0 && value < 1.0) // Value is ok.
34 return true;
35 printf("Invalid value for --%s: %f\n", flagname, value);
36 return false;
37 }
38
39 // Define command line flags.
40 DEFINE_int32(runtime_ms, 10000, "Simulated runtime in ms.");
41 static const bool runtime_ms_dummy =
42 google::RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime);
43 DEFINE_int32(lossrate, 10,
44 "Packet lossrate; drop every N packets.");
45 static const bool lossrate_dummy =
46 google::RegisterFlagValidator(&FLAGS_lossrate, &ValidateLossrate);
47 DEFINE_double(drift, 0.1,
48 "Clockdrift factor.");
49 static const bool drift_dummy =
50 google::RegisterFlagValidator(&FLAGS_drift, &ValidateDriftfactor);
51
main(int argc,char * argv[])52 int main(int argc, char* argv[]) {
53 std::string program_name = argv[0];
54 std::string usage = "Tool for measuring the speed of NetEq.\n"
55 "Usage: " + program_name + " [options]\n\n"
56 " --runtime_ms=N runtime in ms; default is 10000 ms\n"
57 " --lossrate=N drop every N packets; default is 10\n"
58 " --drift=F clockdrift factor between 0.0 and 1.0; "
59 "default is 0.1\n";
60 google::SetUsageMessage(usage);
61 google::ParseCommandLineFlags(&argc, &argv, true);
62
63 if (argc != 1) {
64 // Print usage information.
65 std::cout << google::ProgramUsage();
66 return 0;
67 }
68
69 int64_t result =
70 webrtc::test::NetEqPerformanceTest::Run(FLAGS_runtime_ms, FLAGS_lossrate,
71 FLAGS_drift);
72 if (result <= 0) {
73 std::cout << "There was an error" << std::endl;
74 return -1;
75 }
76
77 std::cout << "Simulation done" << std::endl;
78 std::cout << "Runtime = " << result << " ms" << std::endl;
79 return 0;
80 }
81