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

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");
158 DEFINE_int32(audio_level, 1, "Extension ID for audio level (RFC 6464)"); 124 DEFINE_int(transport_seq_no, 5, "Extension ID for transport sequence number");
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_int32(transport_seq_no, 5, "Extension ID for transport sequence number");
165 const bool transport_seq_no_dummy =
166 google::RegisterFlagValidator(&FLAGS_transport_seq_no,
167 &ValidateExtensionId);
168 DEFINE_bool(matlabplot, 125 DEFINE_bool(matlabplot,
169 false, 126 false,
170 "Generates a matlab script for plotting the delay profile"); 127 "Generates a matlab script for plotting the delay profile");
128 DEFINE_bool(help, false, "Prints this message");
171 129
172 // Maps a codec type to a printable name string. 130 // Maps a codec type to a printable name string.
173 std::string CodecName(NetEqDecoder codec) { 131 std::string CodecName(NetEqDecoder codec) {
174 switch (codec) { 132 switch (codec) {
175 case NetEqDecoder::kDecoderPCMu: 133 case NetEqDecoder::kDecoderPCMu:
176 return "PCM-u"; 134 return "PCM-u";
177 case NetEqDecoder::kDecoderPCMa: 135 case NetEqDecoder::kDecoderPCMa:
178 return "PCM-a"; 136 return "PCM-a";
179 case NetEqDecoder::kDecoderILBC: 137 case NetEqDecoder::kDecoderILBC:
180 return "iLBC"; 138 return "iLBC";
(...skipping 30 matching lines...) Expand all
211 case NetEqDecoder::kDecoderCNGswb32kHz: 169 case NetEqDecoder::kDecoderCNGswb32kHz:
212 return "comfort noise (32 kHz)"; 170 return "comfort noise (32 kHz)";
213 case NetEqDecoder::kDecoderCNGswb48kHz: 171 case NetEqDecoder::kDecoderCNGswb48kHz:
214 return "comfort noise (48 kHz)"; 172 return "comfort noise (48 kHz)";
215 default: 173 default:
216 FATAL(); 174 FATAL();
217 return "undefined"; 175 return "undefined";
218 } 176 }
219 } 177 }
220 178
221 void PrintCodecMappingEntry(NetEqDecoder codec, google::int32 flag) { 179 void PrintCodecMappingEntry(NetEqDecoder codec, int flag) {
222 std::cout << CodecName(codec) << ": " << flag << std::endl; 180 std::cout << CodecName(codec) << ": " << flag << std::endl;
223 } 181 }
224 182
225 void PrintCodecMapping() { 183 void PrintCodecMapping() {
226 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAGS_pcmu); 184 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu);
227 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAGS_pcma); 185 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma);
228 PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAGS_ilbc); 186 PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc);
229 PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAGS_isac); 187 PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac);
230 PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAGS_isac_swb); 188 PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb);
231 PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAGS_opus); 189 PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus);
232 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAGS_pcm16b); 190 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b);
233 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAGS_pcm16b_wb); 191 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb);
234 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz, 192 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz,
235 FLAGS_pcm16b_swb32); 193 FLAG_pcm16b_swb32);
236 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz, 194 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz,
237 FLAGS_pcm16b_swb48); 195 FLAG_pcm16b_swb48);
238 PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAGS_g722); 196 PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722);
239 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAGS_avt); 197 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt);
240 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAGS_avt_16); 198 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16);
241 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAGS_avt_32); 199 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32);
242 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAGS_avt_48); 200 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48);
243 PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAGS_red); 201 PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red);
244 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAGS_cn_nb); 202 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb);
245 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAGS_cn_wb); 203 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb);
246 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAGS_cn_swb32); 204 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32);
247 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAGS_cn_swb48); 205 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48);
248 } 206 }
249 207
250 rtc::Optional<int> CodecSampleRate(uint8_t payload_type) { 208 rtc::Optional<int> CodecSampleRate(uint8_t payload_type) {
251 if (payload_type == FLAGS_pcmu || payload_type == FLAGS_pcma || 209 if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma ||
252 payload_type == FLAGS_ilbc || payload_type == FLAGS_pcm16b || 210 payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b ||
253 payload_type == FLAGS_cn_nb || payload_type == FLAGS_avt) 211 payload_type == FLAG_cn_nb || payload_type == FLAG_avt)
254 return rtc::Optional<int>(8000); 212 return rtc::Optional<int>(8000);
255 if (payload_type == FLAGS_isac || payload_type == FLAGS_pcm16b_wb || 213 if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb ||
256 payload_type == FLAGS_g722 || payload_type == FLAGS_cn_wb || 214 payload_type == FLAG_g722 || payload_type == FLAG_cn_wb ||
257 payload_type == FLAGS_avt_16) 215 payload_type == FLAG_avt_16)
258 return rtc::Optional<int>(16000); 216 return rtc::Optional<int>(16000);
259 if (payload_type == FLAGS_isac_swb || payload_type == FLAGS_pcm16b_swb32 || 217 if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 ||
260 payload_type == FLAGS_cn_swb32 || payload_type == FLAGS_avt_32) 218 payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32)
261 return rtc::Optional<int>(32000); 219 return rtc::Optional<int>(32000);
262 if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 || 220 if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 ||
263 payload_type == FLAGS_cn_swb48 || payload_type == FLAGS_avt_48) 221 payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48)
264 return rtc::Optional<int>(48000); 222 return rtc::Optional<int>(48000);
265 if (payload_type == FLAGS_red) 223 if (payload_type == FLAG_red)
266 return rtc::Optional<int>(0); 224 return rtc::Optional<int>(0);
267 return rtc::Optional<int>(); 225 return rtc::Optional<int>();
268 } 226 }
269 227
270 // Class to let through only the packets with a given SSRC. Should be used as an 228 // Class to let through only the packets with a given SSRC. Should be used as an
271 // outer layer on another NetEqInput object. 229 // outer layer on another NetEqInput object.
272 class FilterSsrcInput : public NetEqInput { 230 class FilterSsrcInput : public NetEqInput {
273 public: 231 public:
274 FilterSsrcInput(std::unique_ptr<NetEqInput> source, uint32_t ssrc) 232 FilterSsrcInput(std::unique_ptr<NetEqInput> source, uint32_t ssrc)
275 : source_(std::move(source)), ssrc_(ssrc) { 233 : source_(std::move(source)), ssrc_(ssrc) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 411
454 private: 412 private:
455 NetEqGetAudioCallback* other_callback_; 413 NetEqGetAudioCallback* other_callback_;
456 size_t counter_ = 0; 414 size_t counter_ = 0;
457 std::vector<NetEqNetworkStatistics> stats_; 415 std::vector<NetEqNetworkStatistics> stats_;
458 }; 416 };
459 417
460 int RunTest(int argc, char* argv[]) { 418 int RunTest(int argc, char* argv[]) {
461 std::string program_name = argv[0]; 419 std::string program_name = argv[0];
462 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" 420 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
463 "Run " + program_name + " --helpshort for usage.\n" 421 "Run " + program_name + " --help for usage.\n"
464 "Example usage:\n" + program_name + 422 "Example usage:\n" + program_name +
465 " input.rtp output.{pcm, wav}\n"; 423 " input.rtp output.{pcm, wav}\n";
466 google::SetUsageMessage(usage); 424 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
467 google::ParseCommandLineFlags(&argc, &argv, true); 425 return 1;
426 }
427 if (FLAG_help) {
428 std::cout << usage;
429 rtc::FlagList::Print(nullptr, false);
430 return 0;
431 }
468 432
469 if (FLAGS_codec_map) { 433 if (FLAG_codec_map) {
470 PrintCodecMapping(); 434 PrintCodecMapping();
471 } 435 }
472 436
473 if (argc != 3) { 437 if (argc != 3) {
474 if (FLAGS_codec_map) { 438 if (FLAG_codec_map) {
475 // We have already printed the codec map. Just end the program. 439 // We have already printed the codec map. Just end the program.
476 return 0; 440 return 0;
477 } 441 }
478 // Print usage information. 442 // Print usage information.
479 std::cout << google::ProgramUsage(); 443 std::cout << usage;
480 return 0; 444 return 0;
481 } 445 }
446 RTC_CHECK(ValidatePayloadType(FLAG_pcmu));
447 RTC_CHECK(ValidatePayloadType(FLAG_pcma));
448 RTC_CHECK(ValidatePayloadType(FLAG_ilbc));
449 RTC_CHECK(ValidatePayloadType(FLAG_isac));
450 RTC_CHECK(ValidatePayloadType(FLAG_isac_swb));
451 RTC_CHECK(ValidatePayloadType(FLAG_opus));
452 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b));
453 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb));
454 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32));
455 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48));
456 RTC_CHECK(ValidatePayloadType(FLAG_g722));
457 RTC_CHECK(ValidatePayloadType(FLAG_avt));
458 RTC_CHECK(ValidatePayloadType(FLAG_avt_16));
459 RTC_CHECK(ValidatePayloadType(FLAG_avt_32));
460 RTC_CHECK(ValidatePayloadType(FLAG_avt_48));
461 RTC_CHECK(ValidatePayloadType(FLAG_red));
462 RTC_CHECK(ValidatePayloadType(FLAG_cn_nb));
463 RTC_CHECK(ValidatePayloadType(FLAG_cn_wb));
464 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32));
465 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48));
466 RTC_CHECK(ValidateSsrcValue(FLAG_ssrc));
467 RTC_CHECK(ValidateExtensionId(FLAG_audio_level));
468 RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time));
469 RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no));
482 470
483 // Gather RTP header extensions in a map. 471 // Gather RTP header extensions in a map.
484 NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { 472 NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = {
485 {FLAGS_audio_level, kRtpExtensionAudioLevel}, 473 {FLAG_audio_level, kRtpExtensionAudioLevel},
486 {FLAGS_abs_send_time, kRtpExtensionAbsoluteSendTime}, 474 {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime},
487 {FLAGS_transport_seq_no, kRtpExtensionTransportSequenceNumber}}; 475 {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}};
488 476
489 const std::string input_file_name = argv[1]; 477 const std::string input_file_name = argv[1];
490 std::unique_ptr<NetEqInput> input; 478 std::unique_ptr<NetEqInput> input;
491 if (RtpFileSource::ValidRtpDump(input_file_name) || 479 if (RtpFileSource::ValidRtpDump(input_file_name) ||
492 RtpFileSource::ValidPcap(input_file_name)) { 480 RtpFileSource::ValidPcap(input_file_name)) {
493 input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map)); 481 input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map));
494 } else { 482 } else {
495 input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map)); 483 input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map));
496 } 484 }
497 485
498 std::cout << "Input file: " << input_file_name << std::endl; 486 std::cout << "Input file: " << input_file_name << std::endl;
499 RTC_CHECK(input) << "Cannot open input file"; 487 RTC_CHECK(input) << "Cannot open input file";
500 RTC_CHECK(!input->ended()) << "Input file is empty"; 488 RTC_CHECK(!input->ended()) << "Input file is empty";
501 489
502 // Check if an SSRC value was provided. 490 // Check if an SSRC value was provided.
503 if (!FLAGS_ssrc.empty()) { 491 if (strlen(FLAG_ssrc) > 0) {
504 uint32_t ssrc; 492 uint32_t ssrc;
505 RTC_CHECK(ParseSsrc(FLAGS_ssrc, &ssrc)) << "Flag verification has failed."; 493 RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed.";
506 input.reset(new FilterSsrcInput(std::move(input), ssrc)); 494 input.reset(new FilterSsrcInput(std::move(input), ssrc));
507 } 495 }
508 496
509 // Check the sample rate. 497 // Check the sample rate.
510 rtc::Optional<int> sample_rate_hz; 498 rtc::Optional<int> sample_rate_hz;
511 std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc; 499 std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc;
512 while (input->NextHeader()) { 500 while (input->NextHeader()) {
513 rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader(); 501 rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader();
514 RTC_DCHECK(first_rtp_header); 502 RTC_DCHECK(first_rtp_header);
515 sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType); 503 sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 // Open a wav file. 538 // Open a wav file.
551 output.reset(new OutputWavFile(output_file_name, *sample_rate_hz)); 539 output.reset(new OutputWavFile(output_file_name, *sample_rate_hz));
552 } else { 540 } else {
553 // Open a pcm file. 541 // Open a pcm file.
554 output.reset(new OutputAudioFile(output_file_name)); 542 output.reset(new OutputAudioFile(output_file_name));
555 } 543 }
556 544
557 std::cout << "Output file: " << output_file_name << std::endl; 545 std::cout << "Output file: " << output_file_name << std::endl;
558 546
559 NetEqTest::DecoderMap codecs = { 547 NetEqTest::DecoderMap codecs = {
560 {FLAGS_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, 548 {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")},
561 {FLAGS_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, 549 {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")},
562 {FLAGS_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, 550 {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")},
563 {FLAGS_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, 551 {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")},
564 {FLAGS_isac_swb, 552 {FLAG_isac_swb,
565 std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")}, 553 std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")},
566 {FLAGS_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, 554 {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")},
567 {FLAGS_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, 555 {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")},
568 {FLAGS_pcm16b_wb, 556 {FLAG_pcm16b_wb,
569 std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")}, 557 std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")},
570 {FLAGS_pcm16b_swb32, 558 {FLAG_pcm16b_swb32,
571 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")}, 559 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")},
572 {FLAGS_pcm16b_swb48, 560 {FLAG_pcm16b_swb48,
573 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")}, 561 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")},
574 {FLAGS_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, 562 {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")},
575 {FLAGS_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, 563 {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")},
576 {FLAGS_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, 564 {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")},
577 {FLAGS_avt_32, 565 {FLAG_avt_32,
578 std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")}, 566 std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")},
579 {FLAGS_avt_48, 567 {FLAG_avt_48,
580 std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")}, 568 std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")},
581 {FLAGS_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, 569 {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")},
582 {FLAGS_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, 570 {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")},
583 {FLAGS_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, 571 {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")},
584 {FLAGS_cn_swb32, 572 {FLAG_cn_swb32,
585 std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")}, 573 std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")},
586 {FLAGS_cn_swb48, 574 {FLAG_cn_swb48,
587 std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}}; 575 std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}};
588 576
589 // Check if a replacement audio file was provided. 577 // Check if a replacement audio file was provided.
590 std::unique_ptr<AudioDecoder> replacement_decoder; 578 std::unique_ptr<AudioDecoder> replacement_decoder;
591 NetEqTest::ExtDecoderMap ext_codecs; 579 NetEqTest::ExtDecoderMap ext_codecs;
592 if (!FLAGS_replacement_audio_file.empty()) { 580 if (strlen(FLAG_replacement_audio_file) > 0) {
593 // Find largest unused payload type. 581 // Find largest unused payload type.
594 int replacement_pt = 127; 582 int replacement_pt = 127;
595 while (!(codecs.find(replacement_pt) == codecs.end() && 583 while (!(codecs.find(replacement_pt) == codecs.end() &&
596 ext_codecs.find(replacement_pt) == ext_codecs.end())) { 584 ext_codecs.find(replacement_pt) == ext_codecs.end())) {
597 --replacement_pt; 585 --replacement_pt;
598 RTC_CHECK_GE(replacement_pt, 0); 586 RTC_CHECK_GE(replacement_pt, 0);
599 } 587 }
600 588
601 auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) { 589 auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) {
602 std::set<uint8_t> b; 590 std::set<uint8_t> b;
603 for (auto& x : a) { 591 for (auto& x : a) {
604 b.insert(static_cast<uint8_t>(x)); 592 b.insert(static_cast<uint8_t>(x));
605 } 593 }
606 return b; 594 return b;
607 }; 595 };
608 596
609 std::set<uint8_t> cn_types = std_set_int32_to_uint8( 597 std::set<uint8_t> cn_types = std_set_int32_to_uint8(
610 {FLAGS_cn_nb, FLAGS_cn_wb, FLAGS_cn_swb32, FLAGS_cn_swb48}); 598 {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48});
611 std::set<uint8_t> forbidden_types = 599 std::set<uint8_t> forbidden_types =
612 std_set_int32_to_uint8({FLAGS_g722, FLAGS_red, FLAGS_avt, 600 std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt,
613 FLAGS_avt_16, FLAGS_avt_32, FLAGS_avt_48}); 601 FLAG_avt_16, FLAG_avt_32, FLAG_avt_48});
614 input.reset(new NetEqReplacementInput(std::move(input), replacement_pt, 602 input.reset(new NetEqReplacementInput(std::move(input), replacement_pt,
615 cn_types, forbidden_types)); 603 cn_types, forbidden_types));
616 604
617 replacement_decoder.reset(new FakeDecodeFromFile( 605 replacement_decoder.reset(new FakeDecodeFromFile(
618 std::unique_ptr<InputAudioFile>( 606 std::unique_ptr<InputAudioFile>(
619 new InputAudioFile(FLAGS_replacement_audio_file)), 607 new InputAudioFile(FLAG_replacement_audio_file)),
620 48000, false)); 608 48000, false));
621 NetEqTest::ExternalDecoderInfo ext_dec_info = { 609 NetEqTest::ExternalDecoderInfo ext_dec_info = {
622 replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary, 610 replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary,
623 "replacement codec"}; 611 "replacement codec"};
624 ext_codecs[replacement_pt] = ext_dec_info; 612 ext_codecs[replacement_pt] = ext_dec_info;
625 } 613 }
626 614
627 NetEqTest::Callbacks callbacks; 615 NetEqTest::Callbacks callbacks;
628 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer; 616 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
629 if (FLAGS_matlabplot) { 617 if (FLAG_matlabplot) {
630 delay_analyzer.reset(new NetEqDelayAnalyzer); 618 delay_analyzer.reset(new NetEqDelayAnalyzer);
631 } 619 }
632 620
633 SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get()); 621 SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get());
634 callbacks.post_insert_packet = &ssrc_switch_detector; 622 callbacks.post_insert_packet = &ssrc_switch_detector;
635 StatsGetter stats_getter(delay_analyzer.get()); 623 StatsGetter stats_getter(delay_analyzer.get());
636 callbacks.get_audio_callback = &stats_getter; 624 callbacks.get_audio_callback = &stats_getter;
637 NetEq::Config config; 625 NetEq::Config config;
638 config.sample_rate_hz = *sample_rate_hz; 626 config.sample_rate_hz = *sample_rate_hz;
639 NetEqTest test(config, codecs, ext_codecs, std::move(input), 627 NetEqTest test(config, codecs, ext_codecs, std::move(input),
640 std::move(output), callbacks); 628 std::move(output), callbacks);
641 629
642 int64_t test_duration_ms = test.Run(); 630 int64_t test_duration_ms = test.Run();
643 631
644 if (FLAGS_matlabplot) { 632 if (FLAG_matlabplot) {
645 auto matlab_script_name = output_file_name; 633 auto matlab_script_name = output_file_name;
646 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', 634 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.',
647 '_'); 635 '_');
648 std::cout << "Creating Matlab plot script " << matlab_script_name + ".m" 636 std::cout << "Creating Matlab plot script " << matlab_script_name + ".m"
649 << std::endl; 637 << std::endl;
650 delay_analyzer->CreateMatlabScript(matlab_script_name + ".m"); 638 delay_analyzer->CreateMatlabScript(matlab_script_name + ".m");
651 } 639 }
652 640
653 printf("Simulation statistics:\n"); 641 printf("Simulation statistics:\n");
654 printf(" output duration: %" PRId64 " ms\n", test_duration_ms); 642 printf(" output duration: %" PRId64 " ms\n", test_duration_ms);
(...skipping 16 matching lines...) Expand all
671 return 0; 659 return 0;
672 } 660 }
673 661
674 } // namespace 662 } // namespace
675 } // namespace test 663 } // namespace test
676 } // namespace webrtc 664 } // namespace webrtc
677 665
678 int main(int argc, char* argv[]) { 666 int main(int argc, char* argv[]) {
679 webrtc::test::RunTest(argc, argv); 667 webrtc::test::RunTest(argc, argv);
680 } 668 }
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/test/neteq_speed_test.cc ('k') | webrtc/modules/audio_coding/neteq/tools/rtp_analyze.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698