Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / remote_bitrate_estimator / tools / rtp_to_text.cc
1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10
11 #include <stdio.h>
12 #include <sstream>
13
14 #include "webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.h"
15 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
16 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
17 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
18 #include "webrtc/test/rtp_file_reader.h"
19
20 int main(int argc, char** argv) {
21   if (argc < 4) {
22     fprintf(stderr, "Usage: rtp_to_text <extension type> <extension id>"
23            " <input_file.rtp> [-t]\n");
24     fprintf(stderr, "<extension type> can either be:\n"
25            "  abs for absolute send time or\n"
26            "  tsoffset for timestamp offset.\n"
27            "<extension id> is the id associated with the extension.\n"
28            "  -t is an optional flag, if set only packet arrival time will be"
29            " output.\n");
30     return -1;
31   }
32   webrtc::test::RtpFileReader* reader;
33   webrtc::RtpHeaderParser* parser;
34   if (!ParseArgsAndSetupEstimator(argc, argv, NULL, NULL, &reader, &parser,
35                                   NULL, NULL)) {
36     return -1;
37   }
38   bool arrival_time_only = (argc >= 5 && strncmp(argv[4], "-t", 2) == 0);
39   webrtc::scoped_ptr<webrtc::test::RtpFileReader> rtp_reader(reader);
40   webrtc::scoped_ptr<webrtc::RtpHeaderParser> rtp_parser(parser);
41   fprintf(stdout, "seqnum timestamp ts_offset abs_sendtime recvtime "
42           "markerbit ssrc size\n");
43   int packet_counter = 0;
44   int non_zero_abs_send_time = 0;
45   int non_zero_ts_offsets = 0;
46   webrtc::test::RtpFileReader::Packet packet;
47   while (rtp_reader->NextPacket(&packet)) {
48     webrtc::RTPHeader header;
49     parser->Parse(packet.data, packet.length, &header);
50     if (header.extension.absoluteSendTime != 0)
51       ++non_zero_abs_send_time;
52     if (header.extension.transmissionTimeOffset != 0)
53       ++non_zero_ts_offsets;
54     if (arrival_time_only) {
55       std::stringstream ss;
56       ss << static_cast<int64_t>(packet.time_ms) * 1000000;
57       fprintf(stdout, "%s\n", ss.str().c_str());
58     } else {
59       fprintf(stdout,
60               "%u %u %d %u %u %d %u %d\n",
61               header.sequenceNumber,
62               header.timestamp,
63               header.extension.transmissionTimeOffset,
64               header.extension.absoluteSendTime,
65               packet.time_ms,
66               header.markerBit,
67               header.ssrc,
68               static_cast<int>(packet.length));
69     }
70     ++packet_counter;
71   }
72   fprintf(stderr, "Parsed %d packets\n", packet_counter);
73   fprintf(stderr, "Packets with non-zero absolute send time: %d\n",
74          non_zero_abs_send_time);
75   fprintf(stderr, "Packets with non-zero timestamp offset: %d\n",
76          non_zero_ts_offsets);
77   return 0;
78 }