OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 using std::string; | 21 using std::string; |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 namespace test { | 24 namespace test { |
25 | 25 |
26 const uint8_t kPayloadType = 95; | 26 const uint8_t kPayloadType = 95; |
27 const int kOutputSizeMs = 10; | 27 const int kOutputSizeMs = 10; |
28 const int kInitSeed = 0x12345678; | 28 const int kInitSeed = 0x12345678; |
29 const int kPacketLossTimeUnitMs = 10; | 29 const int kPacketLossTimeUnitMs = 10; |
30 | 30 |
31 // Common validator for file names. | |
32 static bool ValidateFilename(const string& value, bool write) { | |
33 FILE* fid = write ? fopen(value.c_str(), "wb") : fopen(value.c_str(), "rb"); | |
34 if (fid == nullptr) | |
35 return false; | |
36 fclose(fid); | |
37 return true; | |
38 } | |
39 | |
40 // Define switch for input file name. | 31 // Define switch for input file name. |
41 static bool ValidateInFilename(const char* flagname, const string& value) { | 32 static bool ValidateInFilename(const char* flagname, const string& value) { |
42 if (!ValidateFilename(value, false)) { | 33 return false; |
43 printf("Invalid input filename."); | |
44 return false; | |
45 } | |
46 return true; | |
47 } | 34 } |
48 | 35 |
49 DEFINE_string( | 36 DEFINE_string( |
50 in_filename, | 37 in_filename, |
51 ResourcePath("audio_coding/speech_mono_16kHz", "pcm"), | 38 ResourcePath("audio_coding/speech_mono_16kHz", "pcm"), |
52 "Filename for input audio (specify sample rate with --input_sample_rate ," | 39 "Filename for input audio (specify sample rate with --input_sample_rate ," |
53 "and channels with --channels)."); | 40 "and channels with --channels)."); |
54 | 41 |
55 static const bool in_filename_dummy = | 42 static const bool in_filename_dummy = |
56 RegisterFlagValidator(&FLAGS_in_filename, &ValidateInFilename); | 43 RegisterFlagValidator(&FLAGS_in_filename, &ValidateInFilename); |
57 | 44 |
58 // Define switch for sample rate. | 45 // Define switch for sample rate. |
59 static bool ValidateSampleRate(const char* flagname, int32_t value) { | 46 static bool ValidateSampleRate(const char* flagname, int32_t value) { |
60 if (value == 8000 || value == 16000 || value == 32000 || value == 48000) | |
61 return true; | |
62 printf("Invalid sample rate should be 8000, 16000, 32000 or 48000 Hz."); | |
63 return false; | 47 return false; |
64 } | 48 } |
65 | 49 |
66 DEFINE_int32(input_sample_rate, 16000, "Sample rate of input file in Hz."); | 50 DEFINE_int32(input_sample_rate, 16000, "Sample rate of input file in Hz."); |
67 | 51 |
68 static const bool sample_rate_dummy = | 52 static const bool sample_rate_dummy = |
69 RegisterFlagValidator(&FLAGS_input_sample_rate, &ValidateSampleRate); | 53 RegisterFlagValidator(&FLAGS_input_sample_rate, &ValidateSampleRate); |
70 | 54 |
71 // Define switch for channels. | 55 // Define switch for channels. |
72 static bool ValidateChannels(const char* flagname, int32_t value) { | 56 static bool ValidateChannels(const char* flagname, int32_t value) { |
73 if (value == 1) | |
74 return true; | |
75 printf("Invalid number of channels, current support only 1."); | |
76 return false; | 57 return false; |
77 } | 58 } |
78 | 59 |
79 DEFINE_int32(channels, 1, "Number of channels in input audio."); | 60 DEFINE_int32(channels, 1, "Number of channels in input audio."); |
80 | 61 |
81 static const bool channels_dummy = | 62 static const bool channels_dummy = |
82 RegisterFlagValidator(&FLAGS_channels, &ValidateChannels); | 63 RegisterFlagValidator(&FLAGS_channels, &ValidateChannels); |
83 | 64 |
84 // Define switch for output file name. | 65 // Define switch for output file name. |
85 static bool ValidateOutFilename(const char* flagname, const string& value) { | 66 static bool ValidateOutFilename(const char* flagname, const string& value) { |
86 if (!ValidateFilename(value, true)) { | 67 return false; |
87 printf("Invalid output filename."); | |
88 return false; | |
89 } | |
90 return true; | |
91 } | 68 } |
92 | 69 |
93 DEFINE_string(out_filename, | 70 DEFINE_string(out_filename, |
94 OutputPath() + "neteq_quality_test_out.pcm", | 71 OutputPath() + "neteq_quality_test_out.pcm", |
95 "Name of output audio file."); | 72 "Name of output audio file."); |
96 | 73 |
97 static const bool out_filename_dummy = | 74 static const bool out_filename_dummy = |
98 RegisterFlagValidator(&FLAGS_out_filename, &ValidateOutFilename); | 75 RegisterFlagValidator(&FLAGS_out_filename, &ValidateOutFilename); |
99 | 76 |
100 // Define switch for packet loss rate. | 77 // Define switch for packet loss rate. |
101 static bool ValidatePacketLossRate(const char* /* flag_name */, int32_t value) { | 78 static bool ValidatePacketLossRate(const char* /* flag_name */, int32_t value) { |
102 if (value >= 0 && value <= 100) | |
103 return true; | |
104 printf("Invalid packet loss percentile, should be between 0 and 100."); | |
105 return false; | 79 return false; |
106 } | 80 } |
107 | 81 |
108 // Define switch for runtime. | 82 // Define switch for runtime. |
109 static bool ValidateRuntime(const char* flagname, int32_t value) { | 83 static bool ValidateRuntime(const char* flagname, int32_t value) { |
110 if (value > 0) | |
111 return true; | |
112 printf("Invalid runtime, should be greater than 0."); | |
113 return false; | 84 return false; |
114 } | 85 } |
115 | 86 |
116 DEFINE_int32(runtime_ms, 10000, "Simulated runtime (milliseconds)."); | 87 DEFINE_int32(runtime_ms, 10000, "Simulated runtime (milliseconds)."); |
117 | 88 |
118 static const bool runtime_dummy = | 89 static const bool runtime_dummy = |
119 RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime); | 90 RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime); |
120 | 91 |
121 DEFINE_int32(packet_loss_rate, 10, "Percentile of packet loss."); | 92 DEFINE_int32(packet_loss_rate, 10, "Percentile of packet loss."); |
122 | 93 |
123 static const bool packet_loss_rate_dummy = | 94 static const bool packet_loss_rate_dummy = |
124 RegisterFlagValidator(&FLAGS_packet_loss_rate, &ValidatePacketLossRate); | 95 RegisterFlagValidator(&FLAGS_packet_loss_rate, &ValidatePacketLossRate); |
125 | 96 |
126 // Define switch for random loss mode. | 97 // Define switch for random loss mode. |
127 static bool ValidateRandomLossMode(const char* /* flag_name */, int32_t value) { | 98 static bool ValidateRandomLossMode(const char* /* flag_name */, int32_t value) { |
128 if (value >= 0 && value <= 2) | |
129 return true; | |
130 printf("Invalid random packet loss mode, should be between 0 and 2."); | |
131 return false; | 99 return false; |
132 } | 100 } |
133 | 101 |
134 DEFINE_int32(random_loss_mode, 1, | 102 DEFINE_int32(random_loss_mode, 1, |
135 "Random loss mode: 0--no loss, 1--uniform loss, 2--Gilbert Elliot loss."); | 103 "Random loss mode: 0--no loss, 1--uniform loss, 2--Gilbert Elliot loss."); |
136 static const bool random_loss_mode_dummy = | 104 static const bool random_loss_mode_dummy = |
137 RegisterFlagValidator(&FLAGS_random_loss_mode, &ValidateRandomLossMode); | 105 RegisterFlagValidator(&FLAGS_random_loss_mode, &ValidateRandomLossMode); |
138 | 106 |
139 // Define switch for burst length. | 107 // Define switch for burst length. |
140 static bool ValidateBurstLength(const char* /* flag_name */, int32_t value) { | 108 static bool ValidateBurstLength(const char* /* flag_name */, int32_t value) { |
141 if (value >= kPacketLossTimeUnitMs) | |
142 return true; | |
143 printf("Invalid burst length, should be greater than %d ms.", | |
144 kPacketLossTimeUnitMs); | |
145 return false; | 109 return false; |
146 } | 110 } |
147 | 111 |
148 DEFINE_int32(burst_length, 30, | 112 DEFINE_int32(burst_length, 30, |
149 "Burst length in milliseconds, only valid for Gilbert Elliot loss."); | 113 "Burst length in milliseconds, only valid for Gilbert Elliot loss."); |
150 | 114 |
151 static const bool burst_length_dummy = | 115 static const bool burst_length_dummy = |
152 RegisterFlagValidator(&FLAGS_burst_length, &ValidateBurstLength); | 116 RegisterFlagValidator(&FLAGS_burst_length, &ValidateBurstLength); |
153 | 117 |
154 // Define switch for drift factor. | 118 // Define switch for drift factor. |
155 static bool ValidateDriftFactor(const char* /* flag_name */, double value) { | 119 static bool ValidateDriftFactor(const char* /* flag_name */, double value) { |
156 if (value > -0.1) | |
157 return true; | |
158 printf("Invalid drift factor, should be greater than -0.1."); | |
159 return false; | 120 return false; |
160 } | 121 } |
161 | 122 |
162 DEFINE_double(drift_factor, 0.0, "Time drift factor."); | 123 DEFINE_double(drift_factor, 0.0, "Time drift factor."); |
163 | 124 |
164 static const bool drift_factor_dummy = | 125 static const bool drift_factor_dummy = |
165 RegisterFlagValidator(&FLAGS_drift_factor, &ValidateDriftFactor); | 126 RegisterFlagValidator(&FLAGS_drift_factor, &ValidateDriftFactor); |
166 | 127 |
167 // ProbTrans00Solver() is to calculate the transition probability from no-loss | 128 // ProbTrans00Solver() is to calculate the transition probability from no-loss |
168 // state to itself in a modified Gilbert Elliot packet loss model. The result is | 129 // state to itself in a modified Gilbert Elliot packet loss model. The result is |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 393 } |
433 } | 394 } |
434 Log() << "Average bit rate was " | 395 Log() << "Average bit rate was " |
435 << 8.0f * total_payload_size_bytes_ / FLAGS_runtime_ms | 396 << 8.0f * total_payload_size_bytes_ / FLAGS_runtime_ms |
436 << " kbps" | 397 << " kbps" |
437 << std::endl; | 398 << std::endl; |
438 } | 399 } |
439 | 400 |
440 } // namespace test | 401 } // namespace test |
441 } // namespace webrtc | 402 } // namespace webrtc |
OLD | NEW |