Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webrtc/logging/rtc_event_log/rtc_event_log2text.cc

Issue 2673403002: New tool for printing basic packet information from an RTC event log to stdout. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/logging/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 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 <iostream>
12 // #include <memory>
ivoc 2017/02/06 16:38:11 Please remove if it's not needed.
terelius 2017/02/06 17:09:43 Done.
13 #include <sstream>
14 #include <string>
15
16 #include "gflags/gflags.h"
17 #include "webrtc/base/checks.h"
18 #include "webrtc/call/call.h"
19 #include "webrtc/common_types.h"
20 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h"
21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
22
23 namespace {
24
25 DEFINE_bool(noincoming, false, "Excludes incoming packets.");
26 DEFINE_bool(nooutgoing, false, "Excludes incoming packets.");
ivoc 2017/02/06 16:38:11 I assume this should be "Excludes outgoing packets
terelius 2017/02/06 17:09:43 Done.
27 // TODO(terelius): Note that the media type don't work with outgoing packets.
ivoc 2017/02/06 16:38:11 doesn't
terelius 2017/02/06 17:09:43 Done.
28 DEFINE_bool(noaudio, false, "Excludes audio packets.");
29 // TODO(terelius): Note that the media type don't work with outgoing packets.
30 DEFINE_bool(novideo, false, "Excludes video packets.");
31 // TODO(terelius): Note that the media type don't work with outgoing packets.
32 DEFINE_bool(nodata, false, "Excludes data packets.");
33 DEFINE_bool(nortp, false, "Excludes RTP packets.");
34 DEFINE_bool(nortcp, false, "Excludes RTCP packets.");
35 // TODO(terelius): Allow a list of SSRCs.
36 DEFINE_string(ssrc,
37 "",
38 "Print only packets with this SSRC (decimal or hex, the latter "
39 "starting with 0x).");
40
41 // Parses the input string for a valid SSRC. If a valid SSRC is found, it is
42 // written to the output variable |ssrc|, and true is returned. Otherwise,
43 // false is returned.
44 // The empty string must be validated as true, because it is the default value
45 // of the command-line flag. In this case, no value is written to the output
46 // variable.
47 bool ParseSsrc(std::string str, uint32_t* ssrc) {
48 // If the input string starts with 0x or 0X it indicates a hexadecimal number.
49 auto read_mode = std::dec;
50 if (str.size() > 2 &&
51 (str.substr(0, 2) == "0x" || str.substr(0, 2) == "0X")) {
52 read_mode = std::hex;
53 str = str.substr(2);
54 }
55 std::stringstream ss(str);
56 ss >> read_mode >> *ssrc;
57 return str.empty() || (!ss.fail() && ss.eof());
58 }
59
60 bool ExcludePacket(webrtc::PacketDirection direction,
61 webrtc::MediaType media_type,
62 uint32_t packet_ssrc,
63 uint32_t filtered_ssrc) {
64 if (FLAGS_nooutgoing && direction == webrtc::kOutgoingPacket)
65 return true;
66 if (FLAGS_noincoming && direction == webrtc::kIncomingPacket)
67 return true;
68 if (FLAGS_noaudio && media_type == webrtc::MediaType::AUDIO)
69 return true;
70 if (FLAGS_novideo && media_type == webrtc::MediaType::VIDEO)
71 return true;
72 if (FLAGS_nodata && media_type == webrtc::MediaType::DATA)
73 return true;
74 if (!FLAGS_ssrc.empty() && packet_ssrc != filtered_ssrc)
75 return true;
76 return false;
77 }
78
79 std::string StreamInfo(webrtc::PacketDirection direction,
80 webrtc::MediaType media_type) {
81 if (direction == webrtc::kOutgoingPacket) {
82 if (media_type == webrtc::MediaType::AUDIO)
83 return "(out,audio)";
84 if (media_type == webrtc::MediaType::VIDEO)
85 return "(out,video)";
86 if (media_type == webrtc::MediaType::DATA)
87 return "(out,data)";
88 }
89 if (direction == webrtc::kIncomingPacket) {
90 if (media_type == webrtc::MediaType::AUDIO)
91 return "(in,audio)";
92 if (media_type == webrtc::MediaType::VIDEO)
93 return "(in,video)";
94 if (media_type == webrtc::MediaType::DATA)
95 return "(in,data)";
96 }
97 return "()";
ivoc 2017/02/06 16:38:11 I think it would be good to add an RTC_NOTREACHED
terelius 2017/02/06 17:09:43 It isn't unreachable; both direction and media_typ
ivoc 2017/02/07 07:56:52 Acknowledged.
98 }
99
100 } // namespace
101
102 // This utility will convert a stored event log to the rtpdump format.
ivoc 2017/02/06 16:38:11 Please update comment :-)
terelius 2017/02/06 17:09:43 Done.
103 int main(int argc, char* argv[]) {
104 std::string program_name = argv[0];
105 std::string usage =
106 "Tool for printing packet information from an RtcEventLog as text.\n"
107 "Run " +
108 program_name +
109 " --helpshort for usage.\n"
110 "Example usage:\n" +
111 program_name + " input.rel\n";
112 google::SetUsageMessage(usage);
113 google::ParseCommandLineFlags(&argc, &argv, true);
114
115 if (argc != 2) {
116 std::cout << google::ProgramUsage();
117 return 0;
118 }
119 std::string input_file = argv[1];
120
121 uint32_t filtered_ssrc = 0;
122 if (!FLAGS_ssrc.empty())
123 RTC_CHECK(ParseSsrc(FLAGS_ssrc, &filtered_ssrc))
124 << "Flag verification has failed.";
125
126 webrtc::ParsedRtcEventLog parsed_stream;
127 if (!parsed_stream.ParseFile(input_file)) {
128 std::cerr << "Error while parsing input file: " << input_file << std::endl;
129 return -1;
130 }
131
132 for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) {
133 // The parsed_stream will assert if the protobuf event is missing
134 // some required fields and we attempt to access them. We could consider
135 // a softer failure option, but it does not seem useful to generate
136 // RTP dumps based on broken event logs.
ivoc 2017/02/06 16:38:11 Please update comment.
terelius 2017/02/06 17:09:43 Done.
137 if (!FLAGS_nortp &&
138 parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) {
139 size_t header_length;
140 size_t total_length;
141 uint8_t header[IP_PACKET_SIZE];
142 webrtc::PacketDirection direction;
143 webrtc::MediaType media_type;
144 parsed_stream.GetRtpHeader(i, &direction, &media_type, header,
145 &header_length, &total_length);
146
147 // Parse header to get SSRC and RTP time.
148 webrtc::RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
149 webrtc::RTPHeader parsed_header;
150 rtp_parser.Parse(&parsed_header);
151
152 if (ExcludePacket(direction, media_type, parsed_header.ssrc,
153 filtered_ssrc))
154 continue;
155
156 std::cout << parsed_stream.GetTimestamp(i) << "\tRTP"
157 << StreamInfo(direction, media_type)
158 << "\tSSRC=" << parsed_header.ssrc
159 << "\ttimestamp =" << parsed_header.timestamp << std::endl;
160 }
161 if (!FLAGS_nortcp &&
162 parsed_stream.GetEventType(i) ==
163 webrtc::ParsedRtcEventLog::RTCP_EVENT) {
164 size_t length;
165 uint8_t packet[IP_PACKET_SIZE];
166 webrtc::PacketDirection direction;
167 webrtc::MediaType media_type;
168 parsed_stream.GetRtcpPacket(i, &direction, &media_type, packet, &length);
169
170 // Parse header to get SSRC and RTP time.
171 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet, length);
172 webrtc::RTPHeader parsed_header;
173 rtp_parser.Parse(&parsed_header);
174
175 if (ExcludePacket(direction, media_type, parsed_header.ssrc,
176 filtered_ssrc))
177 continue;
178
179 std::cout << parsed_stream.GetTimestamp(i) << "\tRTCP"
180 << StreamInfo(direction, media_type)
181 << "\tSSRC=" << parsed_header.ssrc
182 << "\ttimestamp =" << parsed_header.timestamp << std::endl;
183 }
184 }
185 return 0;
186 }
OLDNEW
« no previous file with comments | « webrtc/logging/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698