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 "webrtc/video/rtc_event_log.h" | 11 #include "webrtc/video/rtc_event_log.h" |
12 | 12 |
13 #include <deque> | 13 #include <deque> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/criticalsection.h" | 16 #include "webrtc/base/criticalsection.h" |
17 #include "webrtc/base/thread_annotations.h" | 17 #include "webrtc/base/thread_annotations.h" |
18 #include "webrtc/call.h" | 18 #include "webrtc/call.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
19 #include "webrtc/system_wrappers/interface/clock.h" | 20 #include "webrtc/system_wrappers/interface/clock.h" |
20 #include "webrtc/system_wrappers/interface/file_wrapper.h" | 21 #include "webrtc/system_wrappers/interface/file_wrapper.h" |
21 | 22 |
22 #ifdef ENABLE_RTC_EVENT_LOG | 23 #ifdef ENABLE_RTC_EVENT_LOG |
23 // Files generated at build-time by the protobuf compiler. | 24 // Files generated at build-time by the protobuf compiler. |
24 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 25 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
25 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" | 26 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" |
26 #else | 27 #else |
27 #include "webrtc/video/rtc_event_log.pb.h" | 28 #include "webrtc/video/rtc_event_log.pb.h" |
28 #endif | 29 #endif |
29 #endif | 30 #endif |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 | 33 |
33 #ifndef ENABLE_RTC_EVENT_LOG | 34 #ifndef ENABLE_RTC_EVENT_LOG |
34 | 35 |
35 // No-op implementation if flag is not set. | 36 // No-op implementation if flag is not set. |
36 class RtcEventLogImpl final : public RtcEventLog { | 37 class RtcEventLogImpl final : public RtcEventLog { |
37 public: | 38 public: |
38 void StartLogging(const std::string& file_name, int duration_ms) override {} | 39 void StartLogging(const std::string& file_name, int duration_ms) override {} |
39 void StopLogging(void) override {} | 40 void StopLogging(void) override {} |
40 void LogVideoReceiveStreamConfig( | 41 void LogVideoReceiveStreamConfig( |
41 const VideoReceiveStream::Config& config) override {} | 42 const VideoReceiveStream::Config& config) override {} |
42 void LogVideoSendStreamConfig( | 43 void LogVideoSendStreamConfig( |
43 const VideoSendStream::Config& config) override {} | 44 const VideoSendStream::Config& config) override {} |
44 void LogRtpHeader(bool incoming, | 45 void LogRtpHeader(bool incoming, |
45 MediaType media_type, | 46 MediaType media_type, |
46 const uint8_t* header, | 47 const uint8_t* header, |
47 size_t header_length, | 48 size_t packet_length) override {} |
48 size_t total_length) override {} | |
49 void LogRtcpPacket(bool incoming, | 49 void LogRtcpPacket(bool incoming, |
50 MediaType media_type, | 50 MediaType media_type, |
51 const uint8_t* packet, | 51 const uint8_t* packet, |
52 size_t length) override {} | 52 size_t length) override {} |
53 void LogDebugEvent(DebugEvent event_type) override {} | 53 void LogDebugEvent(DebugEvent event_type) override {} |
54 }; | 54 }; |
55 | 55 |
56 #else // ENABLE_RTC_EVENT_LOG is defined | 56 #else // ENABLE_RTC_EVENT_LOG is defined |
57 | 57 |
58 class RtcEventLogImpl final : public RtcEventLog { | 58 class RtcEventLogImpl final : public RtcEventLog { |
59 public: | 59 public: |
60 RtcEventLogImpl(); | 60 RtcEventLogImpl(); |
61 | 61 |
62 void StartLogging(const std::string& file_name, int duration_ms) override; | 62 void StartLogging(const std::string& file_name, int duration_ms) override; |
63 void StopLogging() override; | 63 void StopLogging() override; |
64 void LogVideoReceiveStreamConfig( | 64 void LogVideoReceiveStreamConfig( |
65 const VideoReceiveStream::Config& config) override; | 65 const VideoReceiveStream::Config& config) override; |
66 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; | 66 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; |
67 void LogRtpHeader(bool incoming, | 67 void LogRtpHeader(bool incoming, |
68 MediaType media_type, | 68 MediaType media_type, |
69 const uint8_t* header, | 69 const uint8_t* header, |
70 size_t header_length, | 70 size_t packet_length) override; |
71 size_t total_length) override; | |
72 void LogRtcpPacket(bool incoming, | 71 void LogRtcpPacket(bool incoming, |
73 MediaType media_type, | 72 MediaType media_type, |
74 const uint8_t* packet, | 73 const uint8_t* packet, |
75 size_t length) override; | 74 size_t length) override; |
76 void LogDebugEvent(DebugEvent event_type) override; | 75 void LogDebugEvent(DebugEvent event_type) override; |
77 | 76 |
78 private: | 77 private: |
79 // Stops logging and clears the stored data and buffers. | 78 // Stops logging and clears the stored data and buffers. |
80 void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 79 void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
81 // Adds a new event to the logfile if logging is active, or adds it to the | 80 // Adds a new event to the logfile if logging is active, or adds it to the |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 encoder->set_name(config.encoder_settings.payload_name); | 276 encoder->set_name(config.encoder_settings.payload_name); |
278 encoder->set_payload_type(config.encoder_settings.payload_type); | 277 encoder->set_payload_type(config.encoder_settings.payload_type); |
279 | 278 |
280 // TODO(terelius): We should use a separate event queue for config events. | 279 // TODO(terelius): We should use a separate event queue for config events. |
281 // The current approach of storing the configuration together with the | 280 // The current approach of storing the configuration together with the |
282 // RTP events causes the configuration information to be removed 10s | 281 // RTP events causes the configuration information to be removed 10s |
283 // after the ReceiveStream is created. | 282 // after the ReceiveStream is created. |
284 HandleEvent(&event); | 283 HandleEvent(&event); |
285 } | 284 } |
286 | 285 |
287 // TODO(terelius): It is more convenient and less error prone to parse the | |
288 // header length from the packet instead of relying on the caller to provide it. | |
289 void RtcEventLogImpl::LogRtpHeader(bool incoming, | 286 void RtcEventLogImpl::LogRtpHeader(bool incoming, |
290 MediaType media_type, | 287 MediaType media_type, |
291 const uint8_t* header, | 288 const uint8_t* header, |
292 size_t header_length, | 289 size_t packet_length) { |
293 size_t total_length) { | 290 // Read header length (in bytes) from packet data. |
| 291 if (packet_length < 12u) { |
| 292 return; // Don't read outside the packet. |
| 293 } |
| 294 const bool x = (header[0] & 0x10) != 0; |
| 295 const uint8_t cc = header[0] & 0x0f; |
| 296 size_t header_length = 12u + cc * 4u; |
| 297 |
| 298 if (x) { |
| 299 if (packet_length < 12u + cc * 4u + 4u) { |
| 300 return; // Don't read outside the packet. |
| 301 } |
| 302 size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4); |
| 303 header_length += (x_len + 1) * 4; |
| 304 } |
| 305 |
294 rtc::CritScope lock(&crit_); | 306 rtc::CritScope lock(&crit_); |
295 rtclog::Event rtp_event; | 307 rtclog::Event rtp_event; |
296 const int64_t timestamp = clock_->TimeInMicroseconds(); | 308 const int64_t timestamp = clock_->TimeInMicroseconds(); |
297 rtp_event.set_timestamp_us(timestamp); | 309 rtp_event.set_timestamp_us(timestamp); |
298 rtp_event.set_type(rtclog::Event::RTP_EVENT); | 310 rtp_event.set_type(rtclog::Event::RTP_EVENT); |
299 rtp_event.mutable_rtp_packet()->set_incoming(incoming); | 311 rtp_event.mutable_rtp_packet()->set_incoming(incoming); |
300 rtp_event.mutable_rtp_packet()->set_type(ConvertMediaType(media_type)); | 312 rtp_event.mutable_rtp_packet()->set_type(ConvertMediaType(media_type)); |
301 rtp_event.mutable_rtp_packet()->set_packet_length(total_length); | 313 rtp_event.mutable_rtp_packet()->set_packet_length(packet_length); |
302 rtp_event.mutable_rtp_packet()->set_header(header, header_length); | 314 rtp_event.mutable_rtp_packet()->set_header(header, header_length); |
303 HandleEvent(&rtp_event); | 315 HandleEvent(&rtp_event); |
304 } | 316 } |
305 | 317 |
306 void RtcEventLogImpl::LogRtcpPacket(bool incoming, | 318 void RtcEventLogImpl::LogRtcpPacket(bool incoming, |
307 MediaType media_type, | 319 MediaType media_type, |
308 const uint8_t* packet, | 320 const uint8_t* packet, |
309 size_t length) { | 321 size_t length) { |
310 rtc::CritScope lock(&crit_); | 322 rtc::CritScope lock(&crit_); |
311 rtclog::Event rtcp_event; | 323 rtclog::Event rtcp_event; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 return result->ParseFromString(dump_buffer); | 409 return result->ParseFromString(dump_buffer); |
398 } | 410 } |
399 | 411 |
400 #endif // ENABLE_RTC_EVENT_LOG | 412 #endif // ENABLE_RTC_EVENT_LOG |
401 | 413 |
402 // RtcEventLog member functions. | 414 // RtcEventLog member functions. |
403 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { | 415 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { |
404 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); | 416 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); |
405 } | 417 } |
406 } // namespace webrtc | 418 } // namespace webrtc |
OLD | NEW |