xref: /aosp_15_r20/external/webrtc/modules/remote_bitrate_estimator/tools/rtp_to_text.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
13 #include <memory>
14 
15 #include "modules/remote_bitrate_estimator/tools/bwe_rtp.h"
16 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
17 #include "modules/rtp_rtcp/source/rtp_header_extensions.h"
18 #include "modules/rtp_rtcp/source/rtp_packet.h"
19 #include "rtc_base/strings/string_builder.h"
20 #include "test/rtp_file_reader.h"
21 
main(int argc,char * argv[])22 int main(int argc, char* argv[]) {
23   std::unique_ptr<webrtc::test::RtpFileReader> reader;
24   webrtc::RtpHeaderExtensionMap rtp_header_extensions;
25   if (!ParseArgsAndSetupRtpReader(argc, argv, reader, rtp_header_extensions)) {
26     return -1;
27   }
28 
29   bool arrival_time_only = (argc >= 5 && strncmp(argv[4], "-t", 2) == 0);
30 
31   fprintf(stdout,
32           "seqnum timestamp ts_offset abs_sendtime recvtime "
33           "markerbit ssrc size original_size\n");
34   int packet_counter = 0;
35   int non_zero_abs_send_time = 0;
36   int non_zero_ts_offsets = 0;
37   webrtc::test::RtpPacket packet;
38   while (reader->NextPacket(&packet)) {
39     webrtc::RtpPacket header(&rtp_header_extensions);
40     header.Parse(packet.data, packet.length);
41     uint32_t abs_send_time = 0;
42     if (header.GetExtension<webrtc::AbsoluteSendTime>(&abs_send_time) &&
43         abs_send_time != 0)
44       ++non_zero_abs_send_time;
45     int32_t toffset = 0;
46     if (header.GetExtension<webrtc::TransmissionOffset>(&toffset) &&
47         toffset != 0)
48       ++non_zero_ts_offsets;
49     if (arrival_time_only) {
50       rtc::StringBuilder ss;
51       ss << static_cast<int64_t>(packet.time_ms) * 1000000;
52       fprintf(stdout, "%s\n", ss.str().c_str());
53     } else {
54       fprintf(stdout, "%u %u %d %u %u %d %u %zu %zu\n", header.SequenceNumber(),
55               header.Timestamp(), toffset, abs_send_time, packet.time_ms,
56               header.Marker(), header.Ssrc(), packet.length,
57               packet.original_length);
58     }
59     ++packet_counter;
60   }
61   fprintf(stderr, "Parsed %d packets\n", packet_counter);
62   fprintf(stderr, "Packets with non-zero absolute send time: %d\n",
63           non_zero_abs_send_time);
64   fprintf(stderr, "Packets with non-zero timestamp offset: %d\n",
65           non_zero_ts_offsets);
66   return 0;
67 }
68