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/neteq4/tools/packet.h"
17 #include "webrtc/modules/audio_coding/neteq4/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 FILE* in_file = fopen(argv[1], "rb");
64 printf("Cannot open input file %s\n", argv[1]);
67 printf("Input file: %s\n", argv[1]);
68 webrtc::scoped_ptr<webrtc::test::RtpFileSource> file_source(
69 webrtc::test::RtpFileSource::Create(argv[1]));
70 assert(file_source.get());
71 // Set RTP extension ID.
72 bool print_audio_level = false;
73 if (!google::GetCommandLineFlagInfoOrDie("audio_level").is_default) {
74 print_audio_level = true;
75 file_source->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel,
81 out_file = fopen(argv[2], "wt");
83 printf("Cannot open output file %s\n", argv[2]);
86 printf("Output file: %s\n\n", argv[2]);
92 fprintf(out_file, "SeqNo TimeStamp SendTime Size PT M SSRC");
93 if (print_audio_level) {
94 fprintf(out_file, " AuLvl (V)");
96 fprintf(out_file, "\n");
98 webrtc::scoped_ptr<webrtc::test::Packet> packet;
99 while (!file_source->EndOfFile()) {
100 packet.reset(file_source->NextPacket());
102 // This is probably an RTCP packet. Move on to the next one.
105 assert(packet.get());
106 // Write packet data to file.
108 "%5u %10u %10u %5i %5i %2i %#08X",
109 packet->header().sequenceNumber,
110 packet->header().timestamp,
111 static_cast<unsigned int>(packet->time_ms()),
112 static_cast<int>(packet->packet_length_bytes()),
113 packet->header().payloadType,
114 packet->header().markerBit,
115 packet->header().ssrc);
116 if (print_audio_level && packet->header().extension.hasAudioLevel) {
117 // |audioLevel| consists of one bit for "V" and then 7 bits level.
120 packet->header().extension.audioLevel & 0x7F,
121 (packet->header().extension.audioLevel & 0x80) == 0 ? 0 : 1);
123 fprintf(out_file, "\n");
125 if (packet->header().payloadType == FLAGS_red) {
126 std::list<webrtc::RTPHeader*> red_headers;
127 packet->ExtractRedHeaders(&red_headers);
128 while (!red_headers.empty()) {
129 webrtc::RTPHeader* red = red_headers.front();
132 "* %5u %10u %10u %5i\n",
135 static_cast<unsigned int>(packet->time_ms()),
137 red_headers.pop_front();