OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include <iostream> | 13 #include <iostream> |
14 #include <memory> | 14 #include <memory> |
15 #include <sstream> | 15 #include <sstream> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 18 #include "webrtc/logging/rtc_event_log/rtc_event_log.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/byte_io.h" | 20 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
22 #include "webrtc/rtc_base/checks.h" | 22 #include "webrtc/rtc_base/checks.h" |
23 #include "webrtc/rtc_base/flags.h" | 23 #include "webrtc/rtc_base/flags.h" |
24 #include "webrtc/test/rtp_file_writer.h" | 24 #include "webrtc/test/rtp_file_writer.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 using MediaType = webrtc::ParsedRtcEventLog::MediaType; | 28 using MediaType = webrtc::ParsedRtcEventLog::MediaType; |
29 | 29 |
30 DEFINE_bool(noaudio, | 30 DEFINE_bool( |
31 false, | 31 audio, |
32 "Excludes audio packets from the converted RTPdump file."); | 32 true, |
33 DEFINE_bool(novideo, | 33 "Use --noaudio to exclude audio packets from the converted RTPdump file."); |
34 false, | 34 DEFINE_bool( |
35 "Excludes video packets from the converted RTPdump file."); | 35 video, |
36 DEFINE_bool(nodata, | 36 true, |
37 false, | 37 "Use --novideo to exclude video packets from the converted RTPdump file."); |
38 "Excludes data packets from the converted RTPdump file."); | 38 DEFINE_bool( |
39 DEFINE_bool(nortp, | 39 data, |
40 false, | 40 true, |
41 "Excludes RTP packets from the converted RTPdump file."); | 41 "Use --nodata to exclude data packets from the converted RTPdump file."); |
42 DEFINE_bool(nortcp, | 42 DEFINE_bool( |
43 false, | 43 rtp, |
44 "Excludes RTCP packets from the converted RTPdump file."); | 44 true, |
| 45 "Use --nortp to exclude RTP packets from the converted RTPdump file."); |
| 46 DEFINE_bool( |
| 47 rtcp, |
| 48 true, |
| 49 "Use --nortcp to exclude RTCP packets from the converted RTPdump file."); |
45 DEFINE_string(ssrc, | 50 DEFINE_string(ssrc, |
46 "", | 51 "", |
47 "Store only packets with this SSRC (decimal or hex, the latter " | 52 "Store only packets with this SSRC (decimal or hex, the latter " |
48 "starting with 0x)."); | 53 "starting with 0x)."); |
49 DEFINE_bool(help, false, "Prints this message."); | 54 DEFINE_bool(help, false, "Prints this message."); |
50 | 55 |
51 // Parses the input string for a valid SSRC. If a valid SSRC is found, it is | 56 // Parses the input string for a valid SSRC. If a valid SSRC is found, it is |
52 // written to the output variable |ssrc|, and true is returned. Otherwise, | 57 // written to the output variable |ssrc|, and true is returned. Otherwise, |
53 // false is returned. | 58 // false is returned. |
54 // The empty string must be validated as true, because it is the default value | 59 // The empty string must be validated as true, because it is the default value |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 120 |
116 std::cout << "Found " << parsed_stream.GetNumberOfEvents() | 121 std::cout << "Found " << parsed_stream.GetNumberOfEvents() |
117 << " events in the input file." << std::endl; | 122 << " events in the input file." << std::endl; |
118 int rtp_counter = 0, rtcp_counter = 0; | 123 int rtp_counter = 0, rtcp_counter = 0; |
119 bool header_only = false; | 124 bool header_only = false; |
120 for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { | 125 for (size_t i = 0; i < parsed_stream.GetNumberOfEvents(); i++) { |
121 // The parsed_stream will assert if the protobuf event is missing | 126 // The parsed_stream will assert if the protobuf event is missing |
122 // some required fields and we attempt to access them. We could consider | 127 // some required fields and we attempt to access them. We could consider |
123 // a softer failure option, but it does not seem useful to generate | 128 // a softer failure option, but it does not seem useful to generate |
124 // RTP dumps based on broken event logs. | 129 // RTP dumps based on broken event logs. |
125 if (!FLAG_nortp && | 130 if (FLAG_rtp && |
126 parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { | 131 parsed_stream.GetEventType(i) == webrtc::ParsedRtcEventLog::RTP_EVENT) { |
127 webrtc::test::RtpPacket packet; | 132 webrtc::test::RtpPacket packet; |
128 webrtc::PacketDirection direction; | 133 webrtc::PacketDirection direction; |
129 parsed_stream.GetRtpHeader(i, &direction, packet.data, &packet.length, | 134 parsed_stream.GetRtpHeader(i, &direction, packet.data, &packet.length, |
130 &packet.original_length); | 135 &packet.original_length); |
131 if (packet.original_length > packet.length) | 136 if (packet.original_length > packet.length) |
132 header_only = true; | 137 header_only = true; |
133 packet.time_ms = parsed_stream.GetTimestamp(i) / 1000; | 138 packet.time_ms = parsed_stream.GetTimestamp(i) / 1000; |
134 | 139 |
135 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet.data, | 140 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet.data, |
136 packet.length); | 141 packet.length); |
137 | 142 |
138 // TODO(terelius): Maybe add a flag to dump outgoing traffic instead? | 143 // TODO(terelius): Maybe add a flag to dump outgoing traffic instead? |
139 if (direction == webrtc::kOutgoingPacket) | 144 if (direction == webrtc::kOutgoingPacket) |
140 continue; | 145 continue; |
141 | 146 |
142 webrtc::RTPHeader parsed_header; | 147 webrtc::RTPHeader parsed_header; |
143 rtp_parser.Parse(&parsed_header); | 148 rtp_parser.Parse(&parsed_header); |
144 MediaType media_type = | 149 MediaType media_type = |
145 parsed_stream.GetMediaType(parsed_header.ssrc, direction); | 150 parsed_stream.GetMediaType(parsed_header.ssrc, direction); |
146 if (FLAG_noaudio && media_type == MediaType::AUDIO) | 151 if (!FLAG_audio && media_type == MediaType::AUDIO) |
147 continue; | 152 continue; |
148 if (FLAG_novideo && media_type == MediaType::VIDEO) | 153 if (!FLAG_video && media_type == MediaType::VIDEO) |
149 continue; | 154 continue; |
150 if (FLAG_nodata && media_type == MediaType::DATA) | 155 if (!FLAG_data && media_type == MediaType::DATA) |
151 continue; | 156 continue; |
152 if (strlen(FLAG_ssrc) > 0) { | 157 if (strlen(FLAG_ssrc) > 0) { |
153 const uint32_t packet_ssrc = | 158 const uint32_t packet_ssrc = |
154 webrtc::ByteReader<uint32_t>::ReadBigEndian( | 159 webrtc::ByteReader<uint32_t>::ReadBigEndian( |
155 reinterpret_cast<const uint8_t*>(packet.data + 8)); | 160 reinterpret_cast<const uint8_t*>(packet.data + 8)); |
156 if (packet_ssrc != ssrc_filter) | 161 if (packet_ssrc != ssrc_filter) |
157 continue; | 162 continue; |
158 } | 163 } |
159 | 164 |
160 rtp_writer->WritePacket(&packet); | 165 rtp_writer->WritePacket(&packet); |
161 rtp_counter++; | 166 rtp_counter++; |
162 } | 167 } |
163 if (!FLAG_nortcp && | 168 if (FLAG_rtcp && parsed_stream.GetEventType(i) == |
164 parsed_stream.GetEventType(i) == | 169 webrtc::ParsedRtcEventLog::RTCP_EVENT) { |
165 webrtc::ParsedRtcEventLog::RTCP_EVENT) { | |
166 webrtc::test::RtpPacket packet; | 170 webrtc::test::RtpPacket packet; |
167 webrtc::PacketDirection direction; | 171 webrtc::PacketDirection direction; |
168 parsed_stream.GetRtcpPacket(i, &direction, packet.data, &packet.length); | 172 parsed_stream.GetRtcpPacket(i, &direction, packet.data, &packet.length); |
169 // For RTCP packets the original_length should be set to 0 in the | 173 // For RTCP packets the original_length should be set to 0 in the |
170 // RTPdump format. | 174 // RTPdump format. |
171 packet.original_length = 0; | 175 packet.original_length = 0; |
172 packet.time_ms = parsed_stream.GetTimestamp(i) / 1000; | 176 packet.time_ms = parsed_stream.GetTimestamp(i) / 1000; |
173 | 177 |
174 // TODO(terelius): Maybe add a flag to dump outgoing traffic instead? | 178 // TODO(terelius): Maybe add a flag to dump outgoing traffic instead? |
175 if (direction == webrtc::kOutgoingPacket) | 179 if (direction == webrtc::kOutgoingPacket) |
176 continue; | 180 continue; |
177 | 181 |
178 // Note that |packet_ssrc| is the sender SSRC. An RTCP message may contain | 182 // Note that |packet_ssrc| is the sender SSRC. An RTCP message may contain |
179 // report blocks for many streams, thus several SSRCs and they doen't | 183 // report blocks for many streams, thus several SSRCs and they doen't |
180 // necessarily have to be of the same media type. | 184 // necessarily have to be of the same media type. |
181 const uint32_t packet_ssrc = webrtc::ByteReader<uint32_t>::ReadBigEndian( | 185 const uint32_t packet_ssrc = webrtc::ByteReader<uint32_t>::ReadBigEndian( |
182 reinterpret_cast<const uint8_t*>(packet.data + 4)); | 186 reinterpret_cast<const uint8_t*>(packet.data + 4)); |
183 MediaType media_type = parsed_stream.GetMediaType(packet_ssrc, direction); | 187 MediaType media_type = parsed_stream.GetMediaType(packet_ssrc, direction); |
184 if (FLAG_noaudio && media_type == MediaType::AUDIO) | 188 if (!FLAG_audio && media_type == MediaType::AUDIO) |
185 continue; | 189 continue; |
186 if (FLAG_novideo && media_type == MediaType::VIDEO) | 190 if (!FLAG_video && media_type == MediaType::VIDEO) |
187 continue; | 191 continue; |
188 if (FLAG_nodata && media_type == MediaType::DATA) | 192 if (!FLAG_data && media_type == MediaType::DATA) |
189 continue; | 193 continue; |
190 if (strlen(FLAG_ssrc) > 0) { | 194 if (strlen(FLAG_ssrc) > 0) { |
191 if (packet_ssrc != ssrc_filter) | 195 if (packet_ssrc != ssrc_filter) |
192 continue; | 196 continue; |
193 } | 197 } |
194 | 198 |
195 rtp_writer->WritePacket(&packet); | 199 rtp_writer->WritePacket(&packet); |
196 rtcp_counter++; | 200 rtcp_counter++; |
197 } | 201 } |
198 } | 202 } |
199 std::cout << "Wrote " << rtp_counter << (header_only ? " header-only" : "") | 203 std::cout << "Wrote " << rtp_counter << (header_only ? " header-only" : "") |
200 << " RTP packets and " << rtcp_counter << " RTCP packets to the " | 204 << " RTP packets and " << rtcp_counter << " RTCP packets to the " |
201 << "output file." << std::endl; | 205 << "output file." << std::endl; |
202 return 0; | 206 return 0; |
203 } | 207 } |
OLD | NEW |