2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
15 #include "google/gflags.h"
16 #include "webrtc/modules/audio_coding/neteq/tools/packet.h"
17 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h"
18 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
21 static bool ValidatePayloadType(const char* flagname, int32_t value) {
22 if (value >= 0 && value <= 127) // Value is ok.
24 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value));
27 static bool ValidateExtensionId(const char* flagname, int32_t value) {
28 if (value > 0 && value <= 255) // Value is ok.
30 printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value));
34 // Define command line flags.
35 DEFINE_int32(red, 117, "RTP payload type for RED");
36 static const bool red_dummy =
37 google::RegisterFlagValidator(&FLAGS_red, &ValidatePayloadType);
38 DEFINE_int32(audio_level, 1, "Extension ID for audio level (RFC 6464)");
39 static const bool audio_level_dummy =
40 google::RegisterFlagValidator(&FLAGS_audio_level, &ValidateExtensionId);
42 int main(int argc, char* argv[]) {
43 std::string program_name = argv[0];
45 "Tool for parsing an RTP dump file to text output.\n"
48 " --helpshort for usage.\n"
50 program_name + " input.rtp output.txt\n\n" +
51 "Output is sent to stdout if no output file is given." +
52 "Note that this tool can read files with our without payloads.";
53 google::SetUsageMessage(usage);
54 google::ParseCommandLineFlags(&argc, &argv, true);
56 if (argc != 2 && argc != 3) {
57 // Print usage information.
58 printf("%s", google::ProgramUsage());
62 printf("Input file: %s\n", argv[1]);
63 webrtc::scoped_ptr<webrtc::test::RtpFileSource> file_source(
64 webrtc::test::RtpFileSource::Create(argv[1]));
65 assert(file_source.get());
66 // Set RTP extension ID.
67 bool print_audio_level = false;
68 if (!google::GetCommandLineFlagInfoOrDie("audio_level").is_default) {
69 print_audio_level = true;
70 file_source->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel,
76 out_file = fopen(argv[2], "wt");
78 printf("Cannot open output file %s\n", argv[2]);
81 printf("Output file: %s\n\n", argv[2]);
87 fprintf(out_file, "SeqNo TimeStamp SendTime Size PT M SSRC");
88 if (print_audio_level) {
89 fprintf(out_file, " AuLvl (V)");
91 fprintf(out_file, "\n");
93 webrtc::scoped_ptr<webrtc::test::Packet> packet;
95 packet.reset(file_source->NextPacket());
97 // End of file reached.
100 // Write packet data to file.
102 "%5u %10u %10u %5i %5i %2i %#08X",
103 packet->header().sequenceNumber,
104 packet->header().timestamp,
105 static_cast<unsigned int>(packet->time_ms()),
106 static_cast<int>(packet->packet_length_bytes()),
107 packet->header().payloadType,
108 packet->header().markerBit,
109 packet->header().ssrc);
110 if (print_audio_level && packet->header().extension.hasAudioLevel) {
111 // |audioLevel| consists of one bit for "V" and then 7 bits level.
114 packet->header().extension.audioLevel & 0x7F,
115 (packet->header().extension.audioLevel & 0x80) == 0 ? 0 : 1);
117 fprintf(out_file, "\n");
119 if (packet->header().payloadType == FLAGS_red) {
120 std::list<webrtc::RTPHeader*> red_headers;
121 packet->ExtractRedHeaders(&red_headers);
122 while (!red_headers.empty()) {
123 webrtc::RTPHeader* red = red_headers.front();
126 "* %5u %10u %10u %5i\n",
129 static_cast<unsigned int>(packet->time_ms()),
131 red_headers.pop_front();