Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc

Issue 3005483002: Replace remaining gflags usages with rtc_base/flags (Closed)
Patch Set: Rebase Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <errno.h> 11 #include <errno.h>
12 #include <inttypes.h> 12 #include <inttypes.h>
13 #include <limits.h> // For ULONG_MAX returned by strtoul. 13 #include <limits.h> // For ULONG_MAX returned by strtoul.
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <stdlib.h> // For strtoul. 15 #include <stdlib.h> // For strtoul.
16 #include <string.h>
16 17
17 #include <algorithm> 18 #include <algorithm>
18 #include <ios> 19 #include <ios>
19 #include <iostream> 20 #include <iostream>
20 #include <memory> 21 #include <memory>
21 #include <numeric> 22 #include <numeric>
22 #include <string> 23 #include <string>
23 24
24 #include "gflags/gflags.h"
25 #include "webrtc/modules/audio_coding/neteq/include/neteq.h" 25 #include "webrtc/modules/audio_coding/neteq/include/neteq.h"
26 #include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h" 26 #include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h"
27 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" 27 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
28 #include "webrtc/modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" 28 #include "webrtc/modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
29 #include "webrtc/modules/audio_coding/neteq/tools/neteq_packet_source_input.h" 29 #include "webrtc/modules/audio_coding/neteq/tools/neteq_packet_source_input.h"
30 #include "webrtc/modules/audio_coding/neteq/tools/neteq_replacement_input.h" 30 #include "webrtc/modules/audio_coding/neteq/tools/neteq_replacement_input.h"
31 #include "webrtc/modules/audio_coding/neteq/tools/neteq_test.h" 31 #include "webrtc/modules/audio_coding/neteq/tools/neteq_test.h"
32 #include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h" 32 #include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h"
33 #include "webrtc/modules/audio_coding/neteq/tools/output_wav_file.h" 33 #include "webrtc/modules/audio_coding/neteq/tools/output_wav_file.h"
34 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" 34 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h"
35 #include "webrtc/modules/include/module_common_types.h" 35 #include "webrtc/modules/include/module_common_types.h"
36 #include "webrtc/rtc_base/checks.h" 36 #include "webrtc/rtc_base/checks.h"
37 #include "webrtc/rtc_base/flags.h"
37 #include "webrtc/test/testsupport/fileutils.h" 38 #include "webrtc/test/testsupport/fileutils.h"
38 #include "webrtc/typedefs.h" 39 #include "webrtc/typedefs.h"
39 40
40 namespace webrtc { 41 namespace webrtc {
41 namespace test { 42 namespace test {
42 namespace { 43 namespace {
43 44
44 // Parses the input string for a valid SSRC (at the start of the string). If a 45 // Parses the input string for a valid SSRC (at the start of the string). If a
45 // valid SSRC is found, it is written to the output variable |ssrc|, and true is 46 // valid SSRC is found, it is written to the output variable |ssrc|, and true is
46 // returned. Otherwise, false is returned. 47 // returned. Otherwise, false is returned.
(...skipping 11 matching lines...) Expand all
58 return false; // Value out of range for unsigned long. 59 return false; // Value out of range for unsigned long.
59 if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF) 60 if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF)
60 return false; // Value out of range for uint32_t. 61 return false; // Value out of range for uint32_t.
61 if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length())) 62 if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length()))
62 return false; // Part of the string was not parsed. 63 return false; // Part of the string was not parsed.
63 *ssrc = static_cast<uint32_t>(value); 64 *ssrc = static_cast<uint32_t>(value);
64 return true; 65 return true;
65 } 66 }
66 67
67 // Flag validators. 68 // Flag validators.
68 bool ValidatePayloadType(const char* flagname, int32_t value) { 69 bool ValidatePayloadType(int value) {
69 if (value >= 0 && value <= 127) // Value is ok. 70 if (value >= 0 && value <= 127) // Value is ok.
70 return true; 71 return true;
71 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value)); 72 printf("Payload type must be between 0 and 127, not %d\n",
73 static_cast<int>(value));
72 return false; 74 return false;
73 } 75 }
74 76
75 bool ValidateSsrcValue(const char* flagname, const std::string& str) { 77 bool ValidateSsrcValue(const std::string& str) {
76 uint32_t dummy_ssrc; 78 uint32_t dummy_ssrc;
77 return ParseSsrc(str, &dummy_ssrc); 79 if (ParseSsrc(str, &dummy_ssrc)) // Value is ok.
80 return true;
81 printf("Invalid SSRC: %s\n", str.c_str());
82 return false;
78 } 83 }
79 84
80 static bool ValidateExtensionId(const char* flagname, int32_t value) { 85 static bool ValidateExtensionId(int value) {
81 if (value > 0 && value <= 255) // Value is ok. 86 if (value > 0 && value <= 255) // Value is ok.
82 return true; 87 return true;
83 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value)); 88 printf("Extension ID must be between 1 and 255, not %d\n",
89 static_cast<int>(value));
84 return false; 90 return false;
85 } 91 }
86 92
87 // Define command line flags. 93 // Define command line flags.
88 DEFINE_int32(pcmu, 0, "RTP payload type for PCM-u"); 94 DEFINE_int(pcmu, 0, "RTP payload type for PCM-u");
89 const bool pcmu_dummy = 95 DEFINE_int(pcma, 8, "RTP payload type for PCM-a");
90 google::RegisterFlagValidator(&FLAGS_pcmu, &ValidatePayloadType); 96 DEFINE_int(ilbc, 102, "RTP payload type for iLBC");
91 DEFINE_int32(pcma, 8, "RTP payload type for PCM-a"); 97 DEFINE_int(isac, 103, "RTP payload type for iSAC");
92 const bool pcma_dummy = 98 DEFINE_int(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)");
93 google::RegisterFlagValidator(&FLAGS_pcma, &ValidatePayloadType); 99 DEFINE_int(opus, 111, "RTP payload type for Opus");
94 DEFINE_int32(ilbc, 102, "RTP payload type for iLBC"); 100 DEFINE_int(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)");
95 const bool ilbc_dummy = 101 DEFINE_int(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)");
96 google::RegisterFlagValidator(&FLAGS_ilbc, &ValidatePayloadType); 102 DEFINE_int(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)");
97 DEFINE_int32(isac, 103, "RTP payload type for iSAC"); 103 DEFINE_int(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)");
98 const bool isac_dummy = 104 DEFINE_int(g722, 9, "RTP payload type for G.722");
99 google::RegisterFlagValidator(&FLAGS_isac, &ValidatePayloadType); 105 DEFINE_int(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)");
100 DEFINE_int32(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)"); 106 DEFINE_int(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)");
101 const bool isac_swb_dummy = 107 DEFINE_int(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)");
102 google::RegisterFlagValidator(&FLAGS_isac_swb, &ValidatePayloadType); 108 DEFINE_int(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)");
103 DEFINE_int32(opus, 111, "RTP payload type for Opus"); 109 DEFINE_int(red, 117, "RTP payload type for redundant audio (RED)");
104 const bool opus_dummy = 110 DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)");
105 google::RegisterFlagValidator(&FLAGS_opus, &ValidatePayloadType); 111 DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)");
106 DEFINE_int32(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)"); 112 DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)");
107 const bool pcm16b_dummy = 113 DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)");
108 google::RegisterFlagValidator(&FLAGS_pcm16b, &ValidatePayloadType);
109 DEFINE_int32(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)");
110 const bool pcm16b_wb_dummy =
111 google::RegisterFlagValidator(&FLAGS_pcm16b_wb, &ValidatePayloadType);
112 DEFINE_int32(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)");
113 const bool pcm16b_swb32_dummy =
114 google::RegisterFlagValidator(&FLAGS_pcm16b_swb32, &ValidatePayloadType);
115 DEFINE_int32(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)");
116 const bool pcm16b_swb48_dummy =
117 google::RegisterFlagValidator(&FLAGS_pcm16b_swb48, &ValidatePayloadType);
118 DEFINE_int32(g722, 9, "RTP payload type for G.722");
119 const bool g722_dummy =
120 google::RegisterFlagValidator(&FLAGS_g722, &ValidatePayloadType);
121 DEFINE_int32(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)");
122 const bool avt_dummy =
123 google::RegisterFlagValidator(&FLAGS_avt, &ValidatePayloadType);
124 DEFINE_int32(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)");
125 const bool avt_16_dummy =
126 google::RegisterFlagValidator(&FLAGS_avt_16, &ValidatePayloadType);
127 DEFINE_int32(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)");
128 const bool avt_32_dummy =
129 google::RegisterFlagValidator(&FLAGS_avt_32, &ValidatePayloadType);
130 DEFINE_int32(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)");
131 const bool avt_48_dummy =
132 google::RegisterFlagValidator(&FLAGS_avt_48, &ValidatePayloadType);
133 DEFINE_int32(red, 117, "RTP payload type for redundant audio (RED)");
134 const bool red_dummy =
135 google::RegisterFlagValidator(&FLAGS_red, &ValidatePayloadType);
136 DEFINE_int32(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)");
137 const bool cn_nb_dummy =
138 google::RegisterFlagValidator(&FLAGS_cn_nb, &ValidatePayloadType);
139 DEFINE_int32(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)");
140 const bool cn_wb_dummy =
141 google::RegisterFlagValidator(&FLAGS_cn_wb, &ValidatePayloadType);
142 DEFINE_int32(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)");
143 const bool cn_swb32_dummy =
144 google::RegisterFlagValidator(&FLAGS_cn_swb32, &ValidatePayloadType);
145 DEFINE_int32(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)");
146 const bool cn_swb48_dummy =
147 google::RegisterFlagValidator(&FLAGS_cn_swb48, &ValidatePayloadType);
148 DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and " 114 DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and "
149 "codec"); 115 "codec");
150 DEFINE_string(replacement_audio_file, "", 116 DEFINE_string(replacement_audio_file, "",
151 "A PCM file that will be used to populate ""dummy"" RTP packets"); 117 "A PCM file that will be used to populate ""dummy"" RTP packets");
152 DEFINE_string(ssrc, 118 DEFINE_string(ssrc,
153 "", 119 "",
154 "Only use packets with this SSRC (decimal or hex, the latter " 120 "Only use packets with this SSRC (decimal or hex, the latter "
155 "starting with 0x)"); 121 "starting with 0x)");
156 const bool hex_ssrc_dummy = 122 DEFINE_int(audio_level, 1, "Extension ID for audio level (RFC 6464)");
157 google::RegisterFlagValidator(&FLAGS_ssrc, &ValidateSsrcValue); 123 DEFINE_int(abs_send_time, 3, "Extension ID for absolute sender time");
hlundin-webrtc 2017/08/30 21:07:54 I think you will find one more extension if you re
oprypin_webrtc 2017/08/31 00:23:25 Rebased.
158 DEFINE_int32(audio_level, 1, "Extension ID for audio level (RFC 6464)");
159 const bool audio_level_dummy =
160 google::RegisterFlagValidator(&FLAGS_audio_level, &ValidateExtensionId);
161 DEFINE_int32(abs_send_time, 3, "Extension ID for absolute sender time");
162 const bool abs_send_time_dummy =
163 google::RegisterFlagValidator(&FLAGS_abs_send_time, &ValidateExtensionId);
164 DEFINE_bool(matlabplot, 124 DEFINE_bool(matlabplot,
165 false, 125 false,
166 "Generates a matlab script for plotting the delay profile"); 126 "Generates a matlab script for plotting the delay profile");
127 DEFINE_bool(help, false, "Prints this message");
167 128
168 // Maps a codec type to a printable name string. 129 // Maps a codec type to a printable name string.
169 std::string CodecName(NetEqDecoder codec) { 130 std::string CodecName(NetEqDecoder codec) {
170 switch (codec) { 131 switch (codec) {
171 case NetEqDecoder::kDecoderPCMu: 132 case NetEqDecoder::kDecoderPCMu:
172 return "PCM-u"; 133 return "PCM-u";
173 case NetEqDecoder::kDecoderPCMa: 134 case NetEqDecoder::kDecoderPCMa:
174 return "PCM-a"; 135 return "PCM-a";
175 case NetEqDecoder::kDecoderILBC: 136 case NetEqDecoder::kDecoderILBC:
176 return "iLBC"; 137 return "iLBC";
(...skipping 30 matching lines...) Expand all
207 case NetEqDecoder::kDecoderCNGswb32kHz: 168 case NetEqDecoder::kDecoderCNGswb32kHz:
208 return "comfort noise (32 kHz)"; 169 return "comfort noise (32 kHz)";
209 case NetEqDecoder::kDecoderCNGswb48kHz: 170 case NetEqDecoder::kDecoderCNGswb48kHz:
210 return "comfort noise (48 kHz)"; 171 return "comfort noise (48 kHz)";
211 default: 172 default:
212 FATAL(); 173 FATAL();
213 return "undefined"; 174 return "undefined";
214 } 175 }
215 } 176 }
216 177
217 void PrintCodecMappingEntry(NetEqDecoder codec, google::int32 flag) { 178 void PrintCodecMappingEntry(NetEqDecoder codec, int flag) {
218 std::cout << CodecName(codec) << ": " << flag << std::endl; 179 std::cout << CodecName(codec) << ": " << flag << std::endl;
219 } 180 }
220 181
221 void PrintCodecMapping() { 182 void PrintCodecMapping() {
222 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAGS_pcmu); 183 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu);
223 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAGS_pcma); 184 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma);
224 PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAGS_ilbc); 185 PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc);
225 PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAGS_isac); 186 PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac);
226 PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAGS_isac_swb); 187 PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb);
227 PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAGS_opus); 188 PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus);
228 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAGS_pcm16b); 189 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b);
229 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAGS_pcm16b_wb); 190 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb);
230 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz, 191 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz,
231 FLAGS_pcm16b_swb32); 192 FLAG_pcm16b_swb32);
232 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz, 193 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz,
233 FLAGS_pcm16b_swb48); 194 FLAG_pcm16b_swb48);
234 PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAGS_g722); 195 PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722);
235 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAGS_avt); 196 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt);
236 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAGS_avt_16); 197 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16);
237 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAGS_avt_32); 198 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32);
238 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAGS_avt_48); 199 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48);
239 PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAGS_red); 200 PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red);
240 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAGS_cn_nb); 201 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb);
241 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAGS_cn_wb); 202 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb);
242 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAGS_cn_swb32); 203 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32);
243 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAGS_cn_swb48); 204 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48);
244 } 205 }
245 206
246 rtc::Optional<int> CodecSampleRate(uint8_t payload_type) { 207 rtc::Optional<int> CodecSampleRate(uint8_t payload_type) {
247 if (payload_type == FLAGS_pcmu || payload_type == FLAGS_pcma || 208 if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma ||
248 payload_type == FLAGS_ilbc || payload_type == FLAGS_pcm16b || 209 payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b ||
249 payload_type == FLAGS_cn_nb || payload_type == FLAGS_avt) 210 payload_type == FLAG_cn_nb || payload_type == FLAG_avt)
250 return rtc::Optional<int>(8000); 211 return rtc::Optional<int>(8000);
251 if (payload_type == FLAGS_isac || payload_type == FLAGS_pcm16b_wb || 212 if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb ||
252 payload_type == FLAGS_g722 || payload_type == FLAGS_cn_wb || 213 payload_type == FLAG_g722 || payload_type == FLAG_cn_wb ||
253 payload_type == FLAGS_avt_16) 214 payload_type == FLAG_avt_16)
254 return rtc::Optional<int>(16000); 215 return rtc::Optional<int>(16000);
255 if (payload_type == FLAGS_isac_swb || payload_type == FLAGS_pcm16b_swb32 || 216 if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 ||
256 payload_type == FLAGS_cn_swb32 || payload_type == FLAGS_avt_32) 217 payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32)
257 return rtc::Optional<int>(32000); 218 return rtc::Optional<int>(32000);
258 if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 || 219 if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 ||
259 payload_type == FLAGS_cn_swb48 || payload_type == FLAGS_avt_48) 220 payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48)
260 return rtc::Optional<int>(48000); 221 return rtc::Optional<int>(48000);
261 if (payload_type == FLAGS_red) 222 if (payload_type == FLAG_red)
262 return rtc::Optional<int>(0); 223 return rtc::Optional<int>(0);
263 return rtc::Optional<int>(); 224 return rtc::Optional<int>();
264 } 225 }
265 226
266 // Class to let through only the packets with a given SSRC. Should be used as an 227 // Class to let through only the packets with a given SSRC. Should be used as an
267 // outer layer on another NetEqInput object. 228 // outer layer on another NetEqInput object.
268 class FilterSsrcInput : public NetEqInput { 229 class FilterSsrcInput : public NetEqInput {
269 public: 230 public:
270 FilterSsrcInput(std::unique_ptr<NetEqInput> source, uint32_t ssrc) 231 FilterSsrcInput(std::unique_ptr<NetEqInput> source, uint32_t ssrc)
271 : source_(std::move(source)), ssrc_(ssrc) { 232 : source_(std::move(source)), ssrc_(ssrc) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 408
448 private: 409 private:
449 NetEqGetAudioCallback* other_callback_; 410 NetEqGetAudioCallback* other_callback_;
450 size_t counter_ = 0; 411 size_t counter_ = 0;
451 std::vector<NetEqNetworkStatistics> stats_; 412 std::vector<NetEqNetworkStatistics> stats_;
452 }; 413 };
453 414
454 int RunTest(int argc, char* argv[]) { 415 int RunTest(int argc, char* argv[]) {
455 std::string program_name = argv[0]; 416 std::string program_name = argv[0];
456 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" 417 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
457 "Run " + program_name + " --helpshort for usage.\n" 418 "Run " + program_name + " --help for usage.\n"
458 "Example usage:\n" + program_name + 419 "Example usage:\n" + program_name +
459 " input.rtp output.{pcm, wav}\n"; 420 " input.rtp output.{pcm, wav}\n";
460 google::SetUsageMessage(usage); 421 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
461 google::ParseCommandLineFlags(&argc, &argv, true); 422 return 1;
423 }
424 if (FLAG_help) {
425 std::cout << usage;
426 rtc::FlagList::Print(nullptr, false);
427 return 0;
428 }
462 429
463 if (FLAGS_codec_map) { 430 if (FLAG_codec_map) {
464 PrintCodecMapping(); 431 PrintCodecMapping();
465 } 432 }
466 433
467 if (argc != 3) { 434 if (argc != 3) {
468 if (FLAGS_codec_map) { 435 if (FLAG_codec_map) {
469 // We have already printed the codec map. Just end the program. 436 // We have already printed the codec map. Just end the program.
470 return 0; 437 return 0;
471 } 438 }
472 // Print usage information. 439 // Print usage information.
473 std::cout << google::ProgramUsage(); 440 std::cout << usage;
474 return 0; 441 return 0;
475 } 442 }
443 RTC_CHECK(ValidatePayloadType(FLAG_pcmu));
444 RTC_CHECK(ValidatePayloadType(FLAG_pcma));
445 RTC_CHECK(ValidatePayloadType(FLAG_ilbc));
446 RTC_CHECK(ValidatePayloadType(FLAG_isac));
447 RTC_CHECK(ValidatePayloadType(FLAG_isac_swb));
448 RTC_CHECK(ValidatePayloadType(FLAG_opus));
449 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b));
450 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb));
451 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32));
452 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48));
453 RTC_CHECK(ValidatePayloadType(FLAG_g722));
454 RTC_CHECK(ValidatePayloadType(FLAG_avt));
455 RTC_CHECK(ValidatePayloadType(FLAG_avt_16));
456 RTC_CHECK(ValidatePayloadType(FLAG_avt_32));
457 RTC_CHECK(ValidatePayloadType(FLAG_avt_48));
458 RTC_CHECK(ValidatePayloadType(FLAG_red));
459 RTC_CHECK(ValidatePayloadType(FLAG_cn_nb));
460 RTC_CHECK(ValidatePayloadType(FLAG_cn_wb));
461 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32));
462 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48));
463 RTC_CHECK(ValidateSsrcValue(FLAG_ssrc));
464 RTC_CHECK(ValidateExtensionId(FLAG_audio_level));
465 RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time));
476 466
477 // Gather RTP header extensions in a map. 467 // Gather RTP header extensions in a map.
478 NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { 468 NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = {
479 {FLAGS_audio_level, kRtpExtensionAudioLevel}, 469 {FLAG_audio_level, kRtpExtensionAudioLevel},
480 {FLAGS_abs_send_time, kRtpExtensionAbsoluteSendTime}}; 470 {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime}};
481 471
482 const std::string input_file_name = argv[1]; 472 const std::string input_file_name = argv[1];
483 std::unique_ptr<NetEqInput> input; 473 std::unique_ptr<NetEqInput> input;
484 if (RtpFileSource::ValidRtpDump(input_file_name) || 474 if (RtpFileSource::ValidRtpDump(input_file_name) ||
485 RtpFileSource::ValidPcap(input_file_name)) { 475 RtpFileSource::ValidPcap(input_file_name)) {
486 input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map)); 476 input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map));
487 } else { 477 } else {
488 input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map)); 478 input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map));
489 } 479 }
490 480
491 std::cout << "Input file: " << input_file_name << std::endl; 481 std::cout << "Input file: " << input_file_name << std::endl;
492 RTC_CHECK(input) << "Cannot open input file"; 482 RTC_CHECK(input) << "Cannot open input file";
493 RTC_CHECK(!input->ended()) << "Input file is empty"; 483 RTC_CHECK(!input->ended()) << "Input file is empty";
494 484
495 // Check if an SSRC value was provided. 485 // Check if an SSRC value was provided.
496 if (!FLAGS_ssrc.empty()) { 486 if (strlen(FLAG_ssrc) > 0) {
497 uint32_t ssrc; 487 uint32_t ssrc;
498 RTC_CHECK(ParseSsrc(FLAGS_ssrc, &ssrc)) << "Flag verification has failed."; 488 RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed.";
499 input.reset(new FilterSsrcInput(std::move(input), ssrc)); 489 input.reset(new FilterSsrcInput(std::move(input), ssrc));
500 } 490 }
501 491
502 // Check the sample rate. 492 // Check the sample rate.
503 rtc::Optional<int> sample_rate_hz; 493 rtc::Optional<int> sample_rate_hz;
504 std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc; 494 std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc;
505 while (input->NextHeader()) { 495 while (input->NextHeader()) {
506 rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader(); 496 rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader();
507 RTC_DCHECK(first_rtp_header); 497 RTC_DCHECK(first_rtp_header);
508 sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType); 498 sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // Open a wav file. 533 // Open a wav file.
544 output.reset(new OutputWavFile(output_file_name, *sample_rate_hz)); 534 output.reset(new OutputWavFile(output_file_name, *sample_rate_hz));
545 } else { 535 } else {
546 // Open a pcm file. 536 // Open a pcm file.
547 output.reset(new OutputAudioFile(output_file_name)); 537 output.reset(new OutputAudioFile(output_file_name));
548 } 538 }
549 539
550 std::cout << "Output file: " << output_file_name << std::endl; 540 std::cout << "Output file: " << output_file_name << std::endl;
551 541
552 NetEqTest::DecoderMap codecs = { 542 NetEqTest::DecoderMap codecs = {
553 {FLAGS_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, 543 {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")},
554 {FLAGS_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, 544 {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")},
555 {FLAGS_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, 545 {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")},
556 {FLAGS_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, 546 {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")},
557 {FLAGS_isac_swb, 547 {FLAG_isac_swb,
558 std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")}, 548 std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")},
559 {FLAGS_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, 549 {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")},
560 {FLAGS_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, 550 {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")},
561 {FLAGS_pcm16b_wb, 551 {FLAG_pcm16b_wb,
562 std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")}, 552 std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")},
563 {FLAGS_pcm16b_swb32, 553 {FLAG_pcm16b_swb32,
564 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")}, 554 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")},
565 {FLAGS_pcm16b_swb48, 555 {FLAG_pcm16b_swb48,
566 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")}, 556 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")},
567 {FLAGS_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, 557 {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")},
568 {FLAGS_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, 558 {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")},
569 {FLAGS_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, 559 {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")},
570 {FLAGS_avt_32, 560 {FLAG_avt_32,
571 std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")}, 561 std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")},
572 {FLAGS_avt_48, 562 {FLAG_avt_48,
573 std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")}, 563 std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")},
574 {FLAGS_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, 564 {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")},
575 {FLAGS_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, 565 {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")},
576 {FLAGS_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, 566 {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")},
577 {FLAGS_cn_swb32, 567 {FLAG_cn_swb32,
578 std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")}, 568 std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")},
579 {FLAGS_cn_swb48, 569 {FLAG_cn_swb48,
580 std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}}; 570 std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}};
581 571
582 // Check if a replacement audio file was provided. 572 // Check if a replacement audio file was provided.
583 std::unique_ptr<AudioDecoder> replacement_decoder; 573 std::unique_ptr<AudioDecoder> replacement_decoder;
584 NetEqTest::ExtDecoderMap ext_codecs; 574 NetEqTest::ExtDecoderMap ext_codecs;
585 if (!FLAGS_replacement_audio_file.empty()) { 575 if (strlen(FLAG_replacement_audio_file) > 0) {
586 // Find largest unused payload type. 576 // Find largest unused payload type.
587 int replacement_pt = 127; 577 int replacement_pt = 127;
588 while (!(codecs.find(replacement_pt) == codecs.end() && 578 while (!(codecs.find(replacement_pt) == codecs.end() &&
589 ext_codecs.find(replacement_pt) == ext_codecs.end())) { 579 ext_codecs.find(replacement_pt) == ext_codecs.end())) {
590 --replacement_pt; 580 --replacement_pt;
591 RTC_CHECK_GE(replacement_pt, 0); 581 RTC_CHECK_GE(replacement_pt, 0);
592 } 582 }
593 583
594 auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) { 584 auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) {
595 std::set<uint8_t> b; 585 std::set<uint8_t> b;
596 for (auto& x : a) { 586 for (auto& x : a) {
597 b.insert(static_cast<uint8_t>(x)); 587 b.insert(static_cast<uint8_t>(x));
598 } 588 }
599 return b; 589 return b;
600 }; 590 };
601 591
602 std::set<uint8_t> cn_types = std_set_int32_to_uint8( 592 std::set<uint8_t> cn_types = std_set_int32_to_uint8(
603 {FLAGS_cn_nb, FLAGS_cn_wb, FLAGS_cn_swb32, FLAGS_cn_swb48}); 593 {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48});
604 std::set<uint8_t> forbidden_types = 594 std::set<uint8_t> forbidden_types =
605 std_set_int32_to_uint8({FLAGS_g722, FLAGS_red, FLAGS_avt, 595 std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt,
606 FLAGS_avt_16, FLAGS_avt_32, FLAGS_avt_48}); 596 FLAG_avt_16, FLAG_avt_32, FLAG_avt_48});
607 input.reset(new NetEqReplacementInput(std::move(input), replacement_pt, 597 input.reset(new NetEqReplacementInput(std::move(input), replacement_pt,
608 cn_types, forbidden_types)); 598 cn_types, forbidden_types));
609 599
610 replacement_decoder.reset(new FakeDecodeFromFile( 600 replacement_decoder.reset(new FakeDecodeFromFile(
611 std::unique_ptr<InputAudioFile>( 601 std::unique_ptr<InputAudioFile>(
612 new InputAudioFile(FLAGS_replacement_audio_file)), 602 new InputAudioFile(FLAG_replacement_audio_file)),
613 48000, false)); 603 48000, false));
614 NetEqTest::ExternalDecoderInfo ext_dec_info = { 604 NetEqTest::ExternalDecoderInfo ext_dec_info = {
615 replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary, 605 replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary,
616 "replacement codec"}; 606 "replacement codec"};
617 ext_codecs[replacement_pt] = ext_dec_info; 607 ext_codecs[replacement_pt] = ext_dec_info;
618 } 608 }
619 609
620 NetEqTest::Callbacks callbacks; 610 NetEqTest::Callbacks callbacks;
621 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer; 611 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
622 if (FLAGS_matlabplot) { 612 if (FLAG_matlabplot) {
623 delay_analyzer.reset(new NetEqDelayAnalyzer); 613 delay_analyzer.reset(new NetEqDelayAnalyzer);
624 } 614 }
625 615
626 SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get()); 616 SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get());
627 callbacks.post_insert_packet = &ssrc_switch_detector; 617 callbacks.post_insert_packet = &ssrc_switch_detector;
628 StatsGetter stats_getter(delay_analyzer.get()); 618 StatsGetter stats_getter(delay_analyzer.get());
629 callbacks.get_audio_callback = &stats_getter; 619 callbacks.get_audio_callback = &stats_getter;
630 NetEq::Config config; 620 NetEq::Config config;
631 config.sample_rate_hz = *sample_rate_hz; 621 config.sample_rate_hz = *sample_rate_hz;
632 NetEqTest test(config, codecs, ext_codecs, std::move(input), 622 NetEqTest test(config, codecs, ext_codecs, std::move(input),
633 std::move(output), callbacks); 623 std::move(output), callbacks);
634 624
635 int64_t test_duration_ms = test.Run(); 625 int64_t test_duration_ms = test.Run();
636 626
637 if (FLAGS_matlabplot) { 627 if (FLAG_matlabplot) {
638 auto matlab_script_name = output_file_name; 628 auto matlab_script_name = output_file_name;
639 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', 629 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.',
640 '_'); 630 '_');
641 std::cout << "Creating Matlab plot script " << matlab_script_name + ".m" 631 std::cout << "Creating Matlab plot script " << matlab_script_name + ".m"
642 << std::endl; 632 << std::endl;
643 delay_analyzer->CreateMatlabScript(matlab_script_name + ".m"); 633 delay_analyzer->CreateMatlabScript(matlab_script_name + ".m");
644 } 634 }
645 635
646 printf("Simulation statistics:\n"); 636 printf("Simulation statistics:\n");
647 printf(" output duration: %" PRId64 " ms\n", test_duration_ms); 637 printf(" output duration: %" PRId64 " ms\n", test_duration_ms);
(...skipping 16 matching lines...) Expand all
664 return 0; 654 return 0;
665 } 655 }
666 656
667 } // namespace 657 } // namespace
668 } // namespace test 658 } // namespace test
669 } // namespace webrtc 659 } // namespace webrtc
670 660
671 int main(int argc, char* argv[]) { 661 int main(int argc, char* argv[]) {
672 webrtc::test::RunTest(argc, argv); 662 webrtc::test::RunTest(argc, argv);
673 } 663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698