OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 <assert.h> | 11 #include <assert.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "gflags/gflags.h" | |
18 #include "webrtc/modules/audio_coding/neteq/tools/packet.h" | 17 #include "webrtc/modules/audio_coding/neteq/tools/packet.h" |
19 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" | 18 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" |
20 | 19 #include "webrtc/rtc_base/flags.h" |
21 // Flag validator. | |
22 static bool ValidatePayloadType(const char* flagname, int32_t value) { | |
23 if (value >= 0 && value <= 127) // Value is ok. | |
24 return true; | |
25 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value)); | |
26 return false; | |
27 } | |
28 static bool ValidateExtensionId(const char* flagname, int32_t value) { | |
29 if (value > 0 && value <= 255) // Value is ok. | |
30 return true; | |
31 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value)); | |
32 return false; | |
33 } | |
34 | 20 |
35 // Define command line flags. | 21 // Define command line flags. |
36 DEFINE_int32(red, 117, "RTP payload type for RED"); | 22 DEFINE_int(red, 117, "RTP payload type for RED"); |
37 static const bool red_dummy = | 23 DEFINE_int(audio_level, -1, "Extension ID for audio level (RFC 6464); " |
38 google::RegisterFlagValidator(&FLAGS_red, &ValidatePayloadType); | 24 "-1 not to print audio level"); |
39 DEFINE_int32(audio_level, 1, "Extension ID for audio level (RFC 6464)"); | 25 DEFINE_int(abs_send_time, -1, "Extension ID for absolute sender time; " |
40 static const bool audio_level_dummy = | 26 "-1 not to print absolute send time"); |
41 google::RegisterFlagValidator(&FLAGS_audio_level, &ValidateExtensionId); | 27 DEFINE_bool(help, false, "Print this message"); |
42 DEFINE_int32(abs_send_time, 3, "Extension ID for absolute sender time"); | |
43 static const bool abs_send_time_dummy = | |
44 google::RegisterFlagValidator(&FLAGS_abs_send_time, &ValidateExtensionId); | |
45 | 28 |
46 int main(int argc, char* argv[]) { | 29 int main(int argc, char* argv[]) { |
47 std::string program_name = argv[0]; | 30 std::string program_name = argv[0]; |
48 std::string usage = | 31 std::string usage = |
49 "Tool for parsing an RTP dump file to text output.\n" | 32 "Tool for parsing an RTP dump file to text output.\n" |
50 "Run " + | 33 "Run " + |
51 program_name + | 34 program_name + |
52 " --helpshort for usage.\n" | 35 " --help for usage.\n" |
53 "Example usage:\n" + | 36 "Example usage:\n" + |
54 program_name + " input.rtp output.txt\n\n" + | 37 program_name + " input.rtp output.txt\n\n" + |
55 "Output is sent to stdout if no output file is given." + | 38 "Output is sent to stdout if no output file is given. " + |
56 "Note that this tool can read files with our without payloads."; | 39 "Note that this tool can read files with or without payloads.\n"; |
57 google::SetUsageMessage(usage); | 40 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || |
58 google::ParseCommandLineFlags(&argc, &argv, true); | 41 FLAG_help || (argc != 2 && argc != 3)) { |
| 42 printf("%s", usage.c_str()); |
| 43 if (FLAG_help) { |
| 44 rtc::FlagList::Print(nullptr, false); |
| 45 return 0; |
| 46 } |
| 47 return 1; |
| 48 } |
59 | 49 |
60 if (argc != 2 && argc != 3) { | 50 RTC_CHECK(FLAG_red >= 0 && FLAG_red <= 127); // Payload type |
61 // Print usage information. | 51 RTC_CHECK(FLAG_audio_level == -1 || // Default |
62 printf("%s", google::ProgramUsage()); | 52 (FLAG_audio_level > 0 && FLAG_audio_level <= 255)); // Extension ID |
63 return 0; | 53 RTC_CHECK(FLAG_abs_send_time == -1 || // Default |
64 } | 54 (FLAG_abs_send_time > 0 && FLAG_abs_send_time <= 255)); // Extension ID |
65 | 55 |
66 printf("Input file: %s\n", argv[1]); | 56 printf("Input file: %s\n", argv[1]); |
67 std::unique_ptr<webrtc::test::RtpFileSource> file_source( | 57 std::unique_ptr<webrtc::test::RtpFileSource> file_source( |
68 webrtc::test::RtpFileSource::Create(argv[1])); | 58 webrtc::test::RtpFileSource::Create(argv[1])); |
69 assert(file_source.get()); | 59 assert(file_source.get()); |
70 // Set RTP extension IDs. | 60 // Set RTP extension IDs. |
71 bool print_audio_level = false; | 61 bool print_audio_level = false; |
72 if (!google::GetCommandLineFlagInfoOrDie("audio_level").is_default) { | 62 if (FLAG_audio_level != -1) { |
73 print_audio_level = true; | 63 print_audio_level = true; |
74 file_source->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel, | 64 file_source->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel, |
75 FLAGS_audio_level); | 65 FLAG_audio_level); |
76 } | 66 } |
77 bool print_abs_send_time = false; | 67 bool print_abs_send_time = false; |
78 if (!google::GetCommandLineFlagInfoOrDie("abs_send_time").is_default) { | 68 if (FLAG_abs_send_time != -1) { |
79 print_abs_send_time = true; | 69 print_abs_send_time = true; |
80 file_source->RegisterRtpHeaderExtension( | 70 file_source->RegisterRtpHeaderExtension( |
81 webrtc::kRtpExtensionAbsoluteSendTime, FLAGS_abs_send_time); | 71 webrtc::kRtpExtensionAbsoluteSendTime, FLAG_abs_send_time); |
82 } | 72 } |
83 | 73 |
84 FILE* out_file; | 74 FILE* out_file; |
85 if (argc == 3) { | 75 if (argc == 3) { |
86 out_file = fopen(argv[2], "wt"); | 76 out_file = fopen(argv[2], "wt"); |
87 if (!out_file) { | 77 if (!out_file) { |
88 printf("Cannot open output file %s\n", argv[2]); | 78 printf("Cannot open output file %s\n", argv[2]); |
89 return -1; | 79 return -1; |
90 } | 80 } |
91 printf("Output file: %s\n\n", argv[2]); | 81 printf("Output file: %s\n\n", argv[2]); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Abs sender time is 24 bit 6.18 fixed point. Divide by 2^18 to convert | 143 // Abs sender time is 24 bit 6.18 fixed point. Divide by 2^18 to convert |
154 // to floating point representation. | 144 // to floating point representation. |
155 double send_time_seconds = | 145 double send_time_seconds = |
156 static_cast<double>(packet->header().extension.absoluteSendTime) / | 146 static_cast<double>(packet->header().extension.absoluteSendTime) / |
157 262144 + | 147 262144 + |
158 64.0 * cycles; | 148 64.0 * cycles; |
159 fprintf(out_file, " %11f", send_time_seconds); | 149 fprintf(out_file, " %11f", send_time_seconds); |
160 } | 150 } |
161 fprintf(out_file, "\n"); | 151 fprintf(out_file, "\n"); |
162 | 152 |
163 if (packet->header().payloadType == FLAGS_red) { | 153 if (packet->header().payloadType == FLAG_red) { |
164 std::list<webrtc::RTPHeader*> red_headers; | 154 std::list<webrtc::RTPHeader*> red_headers; |
165 packet->ExtractRedHeaders(&red_headers); | 155 packet->ExtractRedHeaders(&red_headers); |
166 while (!red_headers.empty()) { | 156 while (!red_headers.empty()) { |
167 webrtc::RTPHeader* red = red_headers.front(); | 157 webrtc::RTPHeader* red = red_headers.front(); |
168 assert(red); | 158 assert(red); |
169 fprintf(out_file, | 159 fprintf(out_file, |
170 "* %5u %10u %10u %5i\n", | 160 "* %5u %10u %10u %5i\n", |
171 red->sequenceNumber, | 161 red->sequenceNumber, |
172 red->timestamp, | 162 red->timestamp, |
173 static_cast<unsigned int>(packet->time_ms()), | 163 static_cast<unsigned int>(packet->time_ms()), |
174 red->payloadType); | 164 red->payloadType); |
175 red_headers.pop_front(); | 165 red_headers.pop_front(); |
176 delete red; | 166 delete red; |
177 } | 167 } |
178 } | 168 } |
179 } | 169 } |
180 | 170 |
181 fclose(out_file); | 171 fclose(out_file); |
182 | 172 |
183 return 0; | 173 return 0; |
184 } | 174 } |
OLD | NEW |