Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2017 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 <sstream> | |
| 13 #include <string> | |
| 14 | |
| 15 #include "gflags/gflags.h" | |
| 16 #include "webrtc/base/checks.h" | |
| 17 #include "webrtc/call/call.h" | |
| 18 #include "webrtc/common_types.h" | |
| 19 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" | |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | |
| 21 | |
|
danilchap
2017/02/07 09:59:49
#include "webrtc/modules/rtp_rtcp/source/rtcp_pack
| |
| 22 namespace { | |
| 23 | |
| 24 DEFINE_bool(noincoming, false, "Excludes incoming packets."); | |
| 25 DEFINE_bool(nooutgoing, false, "Excludes outgoing packets."); | |
| 26 // TODO(terelius): Note that the media type doesn't work with outgoing packets. | |
| 27 DEFINE_bool(noaudio, false, "Excludes audio packets."); | |
| 28 // TODO(terelius): Note that the media type doesn't work with outgoing packets. | |
| 29 DEFINE_bool(novideo, false, "Excludes video packets."); | |
| 30 // TODO(terelius): Note that the media type doesn't work with outgoing packets. | |
| 31 DEFINE_bool(nodata, false, "Excludes data packets."); | |
| 32 DEFINE_bool(nortp, false, "Excludes RTP packets."); | |
| 33 DEFINE_bool(nortcp, false, "Excludes RTCP packets."); | |
| 34 // TODO(terelius): Allow a list of SSRCs. | |
| 35 DEFINE_string(ssrc, | |
| 36 "", | |
| 37 "Print only packets with this SSRC (decimal or hex, the latter " | |
| 38 "starting with 0x)."); | |
| 39 | |
| 40 // Parses the input string for a valid SSRC. If a valid SSRC is found, it is | |
| 41 // written to the output variable |ssrc|, and true is returned. Otherwise, | |
| 42 // false is returned. | |
| 43 // The empty string must be validated as true, because it is the default value | |
| 44 // of the command-line flag. In this case, no value is written to the output | |
| 45 // variable. | |
| 46 bool ParseSsrc(std::string str, uint32_t* ssrc) { | |
| 47 // If the input string starts with 0x or 0X it indicates a hexadecimal number. | |
| 48 auto read_mode = std::dec; | |
| 49 if (str.size() > 2 && | |
| 50 (str.substr(0, 2) == "0x" || str.substr(0, 2) == "0X")) { | |
| 51 read_mode = std::hex; | |
| 52 str = str.substr(2); | |
| 53 } | |
| 54 std::stringstream ss(str); | |
| 55 ss >> read_mode >> *ssrc; | |
| 56 return str.empty() || (!ss.fail() && ss.eof()); | |
| 57 } | |
| 58 | |
| 59 bool ExcludePacket(webrtc::PacketDirection direction, | |
| 60 webrtc::MediaType media_type, | |
| 61 uint32_t packet_ssrc, | |
| 62 uint32_t filtered_ssrc) { | |
| 63 if (FLAGS_nooutgoing && direction == webrtc::kOutgoingPacket) | |
| 64 return true; | |
| 65 if (FLAGS_noincoming && direction == webrtc::kIncomingPacket) | |
| 66 return true; | |
| 67 if (FLAGS_noaudio && media_type == webrtc::MediaType::AUDIO) | |
| 68 return true; | |
| 69 if (FLAGS_novideo && media_type == webrtc::MediaType::VIDEO) | |
| 70 return true; | |
| 71 if (FLAGS_nodata && media_type == webrtc::MediaType::DATA) | |
| 72 return true; | |
| 73 if (!FLAGS_ssrc.empty() && packet_ssrc != filtered_ssrc) | |
| 74 return true; | |
| 75 return false; | |
| 76 } | |
| 77 | |
| 78 std::string StreamInfo(webrtc::PacketDirection direction, | |
| 79 webrtc::MediaType media_type) { | |
| 80 if (direction == webrtc::kOutgoingPacket) { | |
| 81 if (media_type == webrtc::MediaType::AUDIO) | |
| 82 return "(out,audio)"; | |
| 83 if (media_type == webrtc::MediaType::VIDEO) | |
| 84 return "(out,video)"; | |
| 85 if (media_type == webrtc::MediaType::DATA) | |
| 86 return "(out,data)"; | |
| 87 } | |
|
danilchap
2017/02/07 09:59:49
may be add return "(out)" to at least log directio
| |
| 88 if (direction == webrtc::kIncomingPacket) { | |
| 89 if (media_type == webrtc::MediaType::AUDIO) | |
| 90 return "(in,audio)"; | |
| 91 if (media_type == webrtc::MediaType::VIDEO) | |
| 92 return "(in,video)"; | |
| 93 if (media_type == webrtc::MediaType::DATA) | |
| 94 return "(in,data)"; | |
| 95 } | |
| 96 return "()"; | |
| 97 } | |
| 98 | |
| 99 } // namespace | |
| 100 | |
| 101 // This utility will print basic information about each packet to stdout. | |
| 102 // Note that parser will assert if the protobuf event is missing some required | |
| 103 // fields and we attempt to access them. We don't handle this at the moment. | |
| 104 int main(int argc, char* argv[]) { | |
| 105 std::string program_name = argv[0]; | |
| 106 std::string usage = | |
| 107 "Tool for printing packet information from an RtcEventLog as text.\n" | |
| 108 "Run " + | |
| 109 program_name + | |
| 110 " --helpshort for usage.\n" | |
| 111 "Example usage:\n" + | |
| 112 program_name + " input.rel\n"; | |
| 113 google::SetUsageMessage(usage); | |
| 114 google::ParseCommandLineFlags(&argc, &argv, true); | |
| 115 | |
| 116 if (argc != 2) { | |
| 117 std::cout << google::ProgramUsage(); | |
| 118 return 0; | |
| 119 } | |
| 120 std::string input_file = argv[1]; | |
| 121 | |
| 122 uint32_t filtered_ssrc = 0; | |
| 123 if (!FLAGS_ssrc.empty()) | |
| 124 RTC_CHECK(ParseSsrc(FLAGS_ssrc, &filtered_ssrc)) | |
| 125 << "Flag verification has failed."; | |
| 126 | |
| 127 webrtc::ParsedRtcEventLog parsed_stream; | |
| 128 if (!parsed_stream.ParseFile(input_file)) { | |
| 129 std::cerr << "Error while parsing input file: " << input_file << std::endl; | |
| 130 return -1; | |
| 131 } | |
| 132 | |
| 133 for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { | |
| 134 if (!FLAGS_nortp && | |
| 135 parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { | |
| 136 size_t header_length; | |
| 137 size_t total_length; | |
| 138 uint8_t header[IP_PACKET_SIZE]; | |
| 139 webrtc::PacketDirection direction; | |
| 140 webrtc::MediaType media_type; | |
| 141 parsed_stream.GetRtpHeader(i, &direction, &media_type, header, | |
| 142 &header_length, &total_length); | |
| 143 | |
| 144 // Parse header to get SSRC and RTP time. | |
| 145 webrtc::RtpUtility::RtpHeaderParser rtp_parser(header, header_length); | |
| 146 webrtc::RTPHeader parsed_header; | |
| 147 rtp_parser.Parse(&parsed_header); | |
| 148 | |
| 149 if (ExcludePacket(direction, media_type, parsed_header.ssrc, | |
| 150 filtered_ssrc)) | |
| 151 continue; | |
| 152 | |
| 153 std::cout << parsed_stream.GetTimestamp(i) << "\tRTP" | |
| 154 << StreamInfo(direction, media_type) | |
| 155 << "\tSSRC=" << parsed_header.ssrc | |
| 156 << "\ttimestamp=" << parsed_header.timestamp << std::endl; | |
| 157 } | |
| 158 if (!FLAGS_nortcp && | |
| 159 parsed_stream.GetEventType(i) == | |
| 160 webrtc::ParsedRtcEventLog::RTCP_EVENT) { | |
| 161 size_t length; | |
| 162 uint8_t packet[IP_PACKET_SIZE]; | |
| 163 webrtc::PacketDirection direction; | |
| 164 webrtc::MediaType media_type; | |
| 165 parsed_stream.GetRtcpPacket(i, &direction, &media_type, packet, &length); | |
| 166 | |
| 167 // Parse header to get SSRC and RTP time. | |
|
danilchap
2017/02/07 09:59:49
rtcp are not rtp packets. As a start might be enou
| |
| 168 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet, length); | |
| 169 webrtc::RTPHeader parsed_header; | |
| 170 rtp_parser.Parse(&parsed_header); | |
| 171 | |
| 172 if (ExcludePacket(direction, media_type, parsed_header.ssrc, | |
| 173 filtered_ssrc)) | |
| 174 continue; | |
| 175 | |
| 176 std::cout << parsed_stream.GetTimestamp(i) << "\tRTCP" | |
| 177 << StreamInfo(direction, media_type) | |
| 178 << "\tSSRC=" << parsed_header.ssrc | |
| 179 << "\ttimestamp=" << parsed_header.timestamp << std::endl; | |
| 180 } | |
| 181 } | |
| 182 return 0; | |
| 183 } | |
| OLD | NEW |