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 "modules/audio_coding/neteq/tools/neteq_performance_test.h"
16 #include "rtc_base/flags.h"
17 #include "test/testsupport/fileutils.h"
18 #include "typedefs.h"  // NOLINT(build/include)
19 
20 // Define command line flags.
21 DEFINE_int(runtime_ms, 10000, "Simulated runtime in ms.");
22 DEFINE_int(lossrate, 10,
23            "Packet lossrate; drop every N packets.");
24 DEFINE_float(drift, 0.1f,
25              "Clockdrift factor.");
26 DEFINE_bool(help, false, "Print this message.");
27 
main(int argc,char * argv[])28 int main(int argc, char* argv[]) {
29   std::string program_name = argv[0];
30   std::string usage = "Tool for measuring the speed of NetEq.\n"
31       "Usage: " + program_name + " [options]\n\n"
32       "  --runtime_ms=N         runtime in ms; default is 10000 ms\n"
33       "  --lossrate=N           drop every N packets; default is 10\n"
34       "  --drift=F              clockdrift factor between 0.0 and 1.0; "
35       "default is 0.1\n";
36   webrtc::test::SetExecutablePath(argv[0]);
37   if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) ||
38       FLAG_help || argc != 1) {
39     printf("%s", usage.c_str());
40     if (FLAG_help) {
41       rtc::FlagList::Print(nullptr, false);
42       return 0;
43     }
44     return 1;
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);
49 
50   int64_t result =
51       webrtc::test::NetEqPerformanceTest::Run(FLAG_runtime_ms, FLAG_lossrate,
52                                               FLAG_drift);
53   if (result <= 0) {
54     std::cout << "There was an error" << std::endl;
55     return -1;
56   }
57 
58   std::cout << "Simulation done" << std::endl;
59   std::cout << "Runtime = " << result << " ms" << std::endl;
60   return 0;
61 }
62