OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <iostream> | 11 #include <iostream> |
12 #include <sstream> | 12 #include <sstream> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "gflags/gflags.h" | |
16 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/flags.h" |
17 #include "webrtc/call/call.h" | 17 #include "webrtc/call/call.h" |
18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" | 19 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" | 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" |
(...skipping 17 matching lines...) Expand all Loading... |
44 DEFINE_bool(novideo, false, "Excludes video packets."); | 44 DEFINE_bool(novideo, false, "Excludes video packets."); |
45 // TODO(terelius): Note that the media type doesn't work with outgoing packets. | 45 // TODO(terelius): Note that the media type doesn't work with outgoing packets. |
46 DEFINE_bool(nodata, false, "Excludes data packets."); | 46 DEFINE_bool(nodata, false, "Excludes data packets."); |
47 DEFINE_bool(nortp, false, "Excludes RTP packets."); | 47 DEFINE_bool(nortp, false, "Excludes RTP packets."); |
48 DEFINE_bool(nortcp, false, "Excludes RTCP packets."); | 48 DEFINE_bool(nortcp, false, "Excludes RTCP packets."); |
49 // TODO(terelius): Allow a list of SSRCs. | 49 // TODO(terelius): Allow a list of SSRCs. |
50 DEFINE_string(ssrc, | 50 DEFINE_string(ssrc, |
51 "", | 51 "", |
52 "Print only packets with this SSRC (decimal or hex, the latter " | 52 "Print only packets with this SSRC (decimal or hex, the latter " |
53 "starting with 0x)."); | 53 "starting with 0x)."); |
| 54 DEFINE_bool(help, false, "prints this message"); |
54 | 55 |
55 static uint32_t filtered_ssrc = 0; | 56 static uint32_t filtered_ssrc = 0; |
56 | 57 |
57 // Parses the input string for a valid SSRC. If a valid SSRC is found, it is | 58 // Parses the input string for a valid SSRC. If a valid SSRC is found, it is |
58 // written to the static global variable |filtered_ssrc|, and true is returned. | 59 // written to the static global variable |filtered_ssrc|, and true is returned. |
59 // Otherwise, false is returned. | 60 // Otherwise, false is returned. |
60 // The empty string must be validated as true, because it is the default value | 61 // The empty string must be validated as true, because it is the default value |
61 // of the command-line flag. In this case, no value is written to the output | 62 // of the command-line flag. In this case, no value is written to the output |
62 // variable. | 63 // variable. |
63 bool ParseSsrc(std::string str) { | 64 bool ParseSsrc(std::string str) { |
64 // If the input string starts with 0x or 0X it indicates a hexadecimal number. | 65 // If the input string starts with 0x or 0X it indicates a hexadecimal number. |
65 auto read_mode = std::dec; | 66 auto read_mode = std::dec; |
66 if (str.size() > 2 && | 67 if (str.size() > 2 && |
67 (str.substr(0, 2) == "0x" || str.substr(0, 2) == "0X")) { | 68 (str.substr(0, 2) == "0x" || str.substr(0, 2) == "0X")) { |
68 read_mode = std::hex; | 69 read_mode = std::hex; |
69 str = str.substr(2); | 70 str = str.substr(2); |
70 } | 71 } |
71 std::stringstream ss(str); | 72 std::stringstream ss(str); |
72 ss >> read_mode >> filtered_ssrc; | 73 ss >> read_mode >> filtered_ssrc; |
73 return str.empty() || (!ss.fail() && ss.eof()); | 74 return str.empty() || (!ss.fail() && ss.eof()); |
74 } | 75 } |
75 | 76 |
76 bool ExcludePacket(webrtc::PacketDirection direction, | 77 bool ExcludePacket(webrtc::PacketDirection direction, |
77 webrtc::MediaType media_type, | 78 webrtc::MediaType media_type, |
78 uint32_t packet_ssrc) { | 79 uint32_t packet_ssrc) { |
79 if (FLAGS_nooutgoing && direction == webrtc::kOutgoingPacket) | 80 if (FLAG_nooutgoing && direction == webrtc::kOutgoingPacket) |
80 return true; | 81 return true; |
81 if (FLAGS_noincoming && direction == webrtc::kIncomingPacket) | 82 if (FLAG_noincoming && direction == webrtc::kIncomingPacket) |
82 return true; | 83 return true; |
83 if (FLAGS_noaudio && media_type == webrtc::MediaType::AUDIO) | 84 if (FLAG_noaudio && media_type == webrtc::MediaType::AUDIO) |
84 return true; | 85 return true; |
85 if (FLAGS_novideo && media_type == webrtc::MediaType::VIDEO) | 86 if (FLAG_novideo && media_type == webrtc::MediaType::VIDEO) |
86 return true; | 87 return true; |
87 if (FLAGS_nodata && media_type == webrtc::MediaType::DATA) | 88 if (FLAG_nodata && media_type == webrtc::MediaType::DATA) |
88 return true; | 89 return true; |
89 if (!FLAGS_ssrc.empty() && packet_ssrc != filtered_ssrc) | 90 if (FLAG_ssrc && packet_ssrc != filtered_ssrc) |
90 return true; | 91 return true; |
91 return false; | 92 return false; |
92 } | 93 } |
93 | 94 |
94 const char* StreamInfo(webrtc::PacketDirection direction, | 95 const char* StreamInfo(webrtc::PacketDirection direction, |
95 webrtc::MediaType media_type) { | 96 webrtc::MediaType media_type) { |
96 if (direction == webrtc::kOutgoingPacket) { | 97 if (direction == webrtc::kOutgoingPacket) { |
97 if (media_type == webrtc::MediaType::AUDIO) | 98 if (media_type == webrtc::MediaType::AUDIO) |
98 return "(out,audio)"; | 99 return "(out,audio)"; |
99 else if (media_type == webrtc::MediaType::VIDEO) | 100 else if (media_type == webrtc::MediaType::VIDEO) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 292 } |
292 } | 293 } |
293 | 294 |
294 } // namespace | 295 } // namespace |
295 | 296 |
296 // This utility will print basic information about each packet to stdout. | 297 // This utility will print basic information about each packet to stdout. |
297 // Note that parser will assert if the protobuf event is missing some required | 298 // Note that parser will assert if the protobuf event is missing some required |
298 // fields and we attempt to access them. We don't handle this at the moment. | 299 // fields and we attempt to access them. We don't handle this at the moment. |
299 int main(int argc, char* argv[]) { | 300 int main(int argc, char* argv[]) { |
300 std::string program_name = argv[0]; | 301 std::string program_name = argv[0]; |
301 std::string usage = | 302 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
| 303 if (FLAG_help) { |
| 304 rtc::FlagList::Print(nullptr, false); |
| 305 return 0; |
| 306 } |
| 307 |
| 308 if (argc != 2) { |
| 309 std::cout << |
302 "Tool for printing packet information from an RtcEventLog as text.\n" | 310 "Tool for printing packet information from an RtcEventLog as text.\n" |
303 "Run " + | 311 "Run " + |
304 program_name + | 312 program_name + |
305 " --helpshort for usage.\n" | 313 " --help for usage.\n" |
306 "Example usage:\n" + | 314 "Example usage:\n" + |
307 program_name + " input.rel\n"; | 315 program_name + " input.rel\n"; |
308 google::SetUsageMessage(usage); | |
309 google::ParseCommandLineFlags(&argc, &argv, true); | |
310 | |
311 if (argc != 2) { | |
312 std::cout << google::ProgramUsage(); | |
313 return 0; | 316 return 0; |
314 } | 317 } |
315 std::string input_file = argv[1]; | 318 std::string input_file = argv[1]; |
316 | 319 |
317 if (!FLAGS_ssrc.empty()) | 320 if (FLAG_ssrc) |
318 RTC_CHECK(ParseSsrc(FLAGS_ssrc)) << "Flag verification has failed."; | 321 RTC_CHECK(ParseSsrc(FLAG_ssrc)) << "Flag verification has failed."; |
319 | 322 |
320 webrtc::ParsedRtcEventLog parsed_stream; | 323 webrtc::ParsedRtcEventLog parsed_stream; |
321 if (!parsed_stream.ParseFile(input_file)) { | 324 if (!parsed_stream.ParseFile(input_file)) { |
322 std::cerr << "Error while parsing input file: " << input_file << std::endl; | 325 std::cerr << "Error while parsing input file: " << input_file << std::endl; |
323 return -1; | 326 return -1; |
324 } | 327 } |
325 | 328 |
326 for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { | 329 for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { |
327 if (!FLAGS_noconfig && !FLAGS_novideo && !FLAGS_noincoming && | 330 if (!FLAG_noconfig && !FLAG_novideo && !FLAG_noincoming && |
328 parsed_stream.GetEventType(i) == | 331 parsed_stream.GetEventType(i) == |
329 webrtc::ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT) { | 332 webrtc::ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT) { |
330 webrtc::VideoReceiveStream::Config config(nullptr); | 333 webrtc::VideoReceiveStream::Config config(nullptr); |
331 parsed_stream.GetVideoReceiveConfig(i, &config); | 334 parsed_stream.GetVideoReceiveConfig(i, &config); |
332 std::cout << parsed_stream.GetTimestamp(i) << "\tVIDEO_RECV_CONFIG" | 335 std::cout << parsed_stream.GetTimestamp(i) << "\tVIDEO_RECV_CONFIG" |
333 << "\tssrc=" << config.rtp.remote_ssrc | 336 << "\tssrc=" << config.rtp.remote_ssrc |
334 << "\tfeedback_ssrc=" << config.rtp.local_ssrc << std::endl; | 337 << "\tfeedback_ssrc=" << config.rtp.local_ssrc << std::endl; |
335 } | 338 } |
336 if (!FLAGS_noconfig && !FLAGS_novideo && !FLAGS_nooutgoing && | 339 if (!FLAG_noconfig && !FLAG_novideo && !FLAG_nooutgoing && |
337 parsed_stream.GetEventType(i) == | 340 parsed_stream.GetEventType(i) == |
338 webrtc::ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT) { | 341 webrtc::ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT) { |
339 webrtc::VideoSendStream::Config config(nullptr); | 342 webrtc::VideoSendStream::Config config(nullptr); |
340 parsed_stream.GetVideoSendConfig(i, &config); | 343 parsed_stream.GetVideoSendConfig(i, &config); |
341 std::cout << parsed_stream.GetTimestamp(i) << "\tVIDEO_SEND_CONFIG"; | 344 std::cout << parsed_stream.GetTimestamp(i) << "\tVIDEO_SEND_CONFIG"; |
342 std::cout << "\tssrcs="; | 345 std::cout << "\tssrcs="; |
343 for (const auto& ssrc : config.rtp.ssrcs) | 346 for (const auto& ssrc : config.rtp.ssrcs) |
344 std::cout << ssrc << ','; | 347 std::cout << ssrc << ','; |
345 std::cout << "\trtx_ssrcs="; | 348 std::cout << "\trtx_ssrcs="; |
346 for (const auto& ssrc : config.rtp.rtx.ssrcs) | 349 for (const auto& ssrc : config.rtp.rtx.ssrcs) |
347 std::cout << ssrc << ','; | 350 std::cout << ssrc << ','; |
348 std::cout << std::endl; | 351 std::cout << std::endl; |
349 } | 352 } |
350 if (!FLAGS_noconfig && !FLAGS_noaudio && !FLAGS_noincoming && | 353 if (!FLAG_noconfig && !FLAG_noaudio && !FLAG_noincoming && |
351 parsed_stream.GetEventType(i) == | 354 parsed_stream.GetEventType(i) == |
352 webrtc::ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT) { | 355 webrtc::ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT) { |
353 webrtc::AudioReceiveStream::Config config; | 356 webrtc::AudioReceiveStream::Config config; |
354 parsed_stream.GetAudioReceiveConfig(i, &config); | 357 parsed_stream.GetAudioReceiveConfig(i, &config); |
355 std::cout << parsed_stream.GetTimestamp(i) << "\tAUDIO_RECV_CONFIG" | 358 std::cout << parsed_stream.GetTimestamp(i) << "\tAUDIO_RECV_CONFIG" |
356 << "\tssrc=" << config.rtp.remote_ssrc | 359 << "\tssrc=" << config.rtp.remote_ssrc |
357 << "\tfeedback_ssrc=" << config.rtp.local_ssrc << std::endl; | 360 << "\tfeedback_ssrc=" << config.rtp.local_ssrc << std::endl; |
358 } | 361 } |
359 if (!FLAGS_noconfig && !FLAGS_noaudio && !FLAGS_nooutgoing && | 362 if (!FLAG_noconfig && !FLAG_noaudio && !FLAG_nooutgoing && |
360 parsed_stream.GetEventType(i) == | 363 parsed_stream.GetEventType(i) == |
361 webrtc::ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT) { | 364 webrtc::ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT) { |
362 webrtc::AudioSendStream::Config config(nullptr); | 365 webrtc::AudioSendStream::Config config(nullptr); |
363 parsed_stream.GetAudioSendConfig(i, &config); | 366 parsed_stream.GetAudioSendConfig(i, &config); |
364 std::cout << parsed_stream.GetTimestamp(i) << "\tAUDIO_SEND_CONFIG" | 367 std::cout << parsed_stream.GetTimestamp(i) << "\tAUDIO_SEND_CONFIG" |
365 << "\tssrc=" << config.rtp.ssrc << std::endl; | 368 << "\tssrc=" << config.rtp.ssrc << std::endl; |
366 } | 369 } |
367 if (!FLAGS_nortp && | 370 if (!FLAG_nortp && |
368 parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { | 371 parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { |
369 size_t header_length; | 372 size_t header_length; |
370 size_t total_length; | 373 size_t total_length; |
371 uint8_t header[IP_PACKET_SIZE]; | 374 uint8_t header[IP_PACKET_SIZE]; |
372 webrtc::PacketDirection direction; | 375 webrtc::PacketDirection direction; |
373 webrtc::MediaType media_type; | 376 webrtc::MediaType media_type; |
374 parsed_stream.GetRtpHeader(i, &direction, &media_type, header, | 377 parsed_stream.GetRtpHeader(i, &direction, &media_type, header, |
375 &header_length, &total_length); | 378 &header_length, &total_length); |
376 | 379 |
377 // Parse header to get SSRC and RTP time. | 380 // Parse header to get SSRC and RTP time. |
378 webrtc::RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | 381 webrtc::RtpUtility::RtpHeaderParser rtp_parser(header, header_length); |
379 webrtc::RTPHeader parsed_header; | 382 webrtc::RTPHeader parsed_header; |
380 rtp_parser.Parse(&parsed_header); | 383 rtp_parser.Parse(&parsed_header); |
381 | 384 |
382 if (ExcludePacket(direction, media_type, parsed_header.ssrc)) | 385 if (ExcludePacket(direction, media_type, parsed_header.ssrc)) |
383 continue; | 386 continue; |
384 | 387 |
385 std::cout << parsed_stream.GetTimestamp(i) << "\tRTP" | 388 std::cout << parsed_stream.GetTimestamp(i) << "\tRTP" |
386 << StreamInfo(direction, media_type) | 389 << StreamInfo(direction, media_type) |
387 << "\tssrc=" << parsed_header.ssrc | 390 << "\tssrc=" << parsed_header.ssrc |
388 << "\ttimestamp=" << parsed_header.timestamp << std::endl; | 391 << "\ttimestamp=" << parsed_header.timestamp << std::endl; |
389 } | 392 } |
390 if (!FLAGS_nortcp && | 393 if (!FLAG_nortcp && |
391 parsed_stream.GetEventType(i) == | 394 parsed_stream.GetEventType(i) == |
392 webrtc::ParsedRtcEventLog::RTCP_EVENT) { | 395 webrtc::ParsedRtcEventLog::RTCP_EVENT) { |
393 size_t length; | 396 size_t length; |
394 uint8_t packet[IP_PACKET_SIZE]; | 397 uint8_t packet[IP_PACKET_SIZE]; |
395 webrtc::PacketDirection direction; | 398 webrtc::PacketDirection direction; |
396 webrtc::MediaType media_type; | 399 webrtc::MediaType media_type; |
397 parsed_stream.GetRtcpPacket(i, &direction, &media_type, packet, &length); | 400 parsed_stream.GetRtcpPacket(i, &direction, &media_type, packet, &length); |
398 | 401 |
399 webrtc::rtcp::CommonHeader rtcp_block; | 402 webrtc::rtcp::CommonHeader rtcp_block; |
400 const uint8_t* packet_end = packet + length; | 403 const uint8_t* packet_end = packet + length; |
(...skipping 30 matching lines...) Expand all Loading... |
431 PrintPsFeedback(rtcp_block, log_timestamp, direction, media_type); | 434 PrintPsFeedback(rtcp_block, log_timestamp, direction, media_type); |
432 break; | 435 break; |
433 default: | 436 default: |
434 break; | 437 break; |
435 } | 438 } |
436 } | 439 } |
437 } | 440 } |
438 } | 441 } |
439 return 0; | 442 return 0; |
440 } | 443 } |
OLD | NEW |