Index: webrtc/logging/rtc_event_log/rtc_event_log2text.cc |
diff --git a/webrtc/logging/rtc_event_log/rtc_event_log2text.cc b/webrtc/logging/rtc_event_log/rtc_event_log2text.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b560b180c9c5cb48e9726ed8dd2e5e8cfddf2b31 |
--- /dev/null |
+++ b/webrtc/logging/rtc_event_log/rtc_event_log2text.cc |
@@ -0,0 +1,186 @@ |
+/* |
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include <iostream> |
+// #include <memory> |
ivoc
2017/02/06 16:38:11
Please remove if it's not needed.
terelius
2017/02/06 17:09:43
Done.
|
+#include <sstream> |
+#include <string> |
+ |
+#include "gflags/gflags.h" |
+#include "webrtc/base/checks.h" |
+#include "webrtc/call/call.h" |
+#include "webrtc/common_types.h" |
+#include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
+ |
+namespace { |
+ |
+DEFINE_bool(noincoming, false, "Excludes incoming packets."); |
+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.
|
+// 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.
|
+DEFINE_bool(noaudio, false, "Excludes audio packets."); |
+// TODO(terelius): Note that the media type don't work with outgoing packets. |
+DEFINE_bool(novideo, false, "Excludes video packets."); |
+// TODO(terelius): Note that the media type don't work with outgoing packets. |
+DEFINE_bool(nodata, false, "Excludes data packets."); |
+DEFINE_bool(nortp, false, "Excludes RTP packets."); |
+DEFINE_bool(nortcp, false, "Excludes RTCP packets."); |
+// TODO(terelius): Allow a list of SSRCs. |
+DEFINE_string(ssrc, |
+ "", |
+ "Print only packets with this SSRC (decimal or hex, the latter " |
+ "starting with 0x)."); |
+ |
+// Parses the input string for a valid SSRC. If a valid SSRC is found, it is |
+// written to the output variable |ssrc|, and true is returned. Otherwise, |
+// false is returned. |
+// The empty string must be validated as true, because it is the default value |
+// of the command-line flag. In this case, no value is written to the output |
+// variable. |
+bool ParseSsrc(std::string str, uint32_t* ssrc) { |
+ // If the input string starts with 0x or 0X it indicates a hexadecimal number. |
+ auto read_mode = std::dec; |
+ if (str.size() > 2 && |
+ (str.substr(0, 2) == "0x" || str.substr(0, 2) == "0X")) { |
+ read_mode = std::hex; |
+ str = str.substr(2); |
+ } |
+ std::stringstream ss(str); |
+ ss >> read_mode >> *ssrc; |
+ return str.empty() || (!ss.fail() && ss.eof()); |
+} |
+ |
+bool ExcludePacket(webrtc::PacketDirection direction, |
+ webrtc::MediaType media_type, |
+ uint32_t packet_ssrc, |
+ uint32_t filtered_ssrc) { |
+ if (FLAGS_nooutgoing && direction == webrtc::kOutgoingPacket) |
+ return true; |
+ if (FLAGS_noincoming && direction == webrtc::kIncomingPacket) |
+ return true; |
+ if (FLAGS_noaudio && media_type == webrtc::MediaType::AUDIO) |
+ return true; |
+ if (FLAGS_novideo && media_type == webrtc::MediaType::VIDEO) |
+ return true; |
+ if (FLAGS_nodata && media_type == webrtc::MediaType::DATA) |
+ return true; |
+ if (!FLAGS_ssrc.empty() && packet_ssrc != filtered_ssrc) |
+ return true; |
+ return false; |
+} |
+ |
+std::string StreamInfo(webrtc::PacketDirection direction, |
+ webrtc::MediaType media_type) { |
+ if (direction == webrtc::kOutgoingPacket) { |
+ if (media_type == webrtc::MediaType::AUDIO) |
+ return "(out,audio)"; |
+ if (media_type == webrtc::MediaType::VIDEO) |
+ return "(out,video)"; |
+ if (media_type == webrtc::MediaType::DATA) |
+ return "(out,data)"; |
+ } |
+ if (direction == webrtc::kIncomingPacket) { |
+ if (media_type == webrtc::MediaType::AUDIO) |
+ return "(in,audio)"; |
+ if (media_type == webrtc::MediaType::VIDEO) |
+ return "(in,video)"; |
+ if (media_type == webrtc::MediaType::DATA) |
+ return "(in,data)"; |
+ } |
+ 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.
|
+} |
+ |
+} // namespace |
+ |
+// 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.
|
+int main(int argc, char* argv[]) { |
+ std::string program_name = argv[0]; |
+ std::string usage = |
+ "Tool for printing packet information from an RtcEventLog as text.\n" |
+ "Run " + |
+ program_name + |
+ " --helpshort for usage.\n" |
+ "Example usage:\n" + |
+ program_name + " input.rel\n"; |
+ google::SetUsageMessage(usage); |
+ google::ParseCommandLineFlags(&argc, &argv, true); |
+ |
+ if (argc != 2) { |
+ std::cout << google::ProgramUsage(); |
+ return 0; |
+ } |
+ std::string input_file = argv[1]; |
+ |
+ uint32_t filtered_ssrc = 0; |
+ if (!FLAGS_ssrc.empty()) |
+ RTC_CHECK(ParseSsrc(FLAGS_ssrc, &filtered_ssrc)) |
+ << "Flag verification has failed."; |
+ |
+ webrtc::ParsedRtcEventLog parsed_stream; |
+ if (!parsed_stream.ParseFile(input_file)) { |
+ std::cerr << "Error while parsing input file: " << input_file << std::endl; |
+ return -1; |
+ } |
+ |
+ for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { |
+ // The parsed_stream will assert if the protobuf event is missing |
+ // some required fields and we attempt to access them. We could consider |
+ // a softer failure option, but it does not seem useful to generate |
+ // 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.
|
+ if (!FLAGS_nortp && |
+ parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { |
+ size_t header_length; |
+ size_t total_length; |
+ uint8_t header[IP_PACKET_SIZE]; |
+ webrtc::PacketDirection direction; |
+ webrtc::MediaType media_type; |
+ parsed_stream.GetRtpHeader(i, &direction, &media_type, header, |
+ &header_length, &total_length); |
+ |
+ // Parse header to get SSRC and RTP time. |
+ webrtc::RtpUtility::RtpHeaderParser rtp_parser(header, header_length); |
+ webrtc::RTPHeader parsed_header; |
+ rtp_parser.Parse(&parsed_header); |
+ |
+ if (ExcludePacket(direction, media_type, parsed_header.ssrc, |
+ filtered_ssrc)) |
+ continue; |
+ |
+ std::cout << parsed_stream.GetTimestamp(i) << "\tRTP" |
+ << StreamInfo(direction, media_type) |
+ << "\tSSRC=" << parsed_header.ssrc |
+ << "\ttimestamp =" << parsed_header.timestamp << std::endl; |
+ } |
+ if (!FLAGS_nortcp && |
+ parsed_stream.GetEventType(i) == |
+ webrtc::ParsedRtcEventLog::RTCP_EVENT) { |
+ size_t length; |
+ uint8_t packet[IP_PACKET_SIZE]; |
+ webrtc::PacketDirection direction; |
+ webrtc::MediaType media_type; |
+ parsed_stream.GetRtcpPacket(i, &direction, &media_type, packet, &length); |
+ |
+ // Parse header to get SSRC and RTP time. |
+ webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet, length); |
+ webrtc::RTPHeader parsed_header; |
+ rtp_parser.Parse(&parsed_header); |
+ |
+ if (ExcludePacket(direction, media_type, parsed_header.ssrc, |
+ filtered_ssrc)) |
+ continue; |
+ |
+ std::cout << parsed_stream.GetTimestamp(i) << "\tRTCP" |
+ << StreamInfo(direction, media_type) |
+ << "\tSSRC=" << parsed_header.ssrc |
+ << "\ttimestamp =" << parsed_header.timestamp << std::endl; |
+ } |
+ } |
+ return 0; |
+} |