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 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 void LogVideoReceiveStreamConfig( | 62 void LogVideoReceiveStreamConfig( |
63 const VideoReceiveStream::Config& config) override; | 63 const VideoReceiveStream::Config& config) override; |
64 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; | 64 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; |
65 void LogAudioReceiveStreamConfig( | 65 void LogAudioReceiveStreamConfig( |
66 const AudioReceiveStream::Config& config) override; | 66 const AudioReceiveStream::Config& config) override; |
67 void LogAudioSendStreamConfig(const AudioSendStream::Config& config) override; | 67 void LogAudioSendStreamConfig(const AudioSendStream::Config& config) override; |
68 void LogRtpHeader(PacketDirection direction, | 68 void LogRtpHeader(PacketDirection direction, |
69 MediaType media_type, | 69 MediaType media_type, |
70 const uint8_t* header, | 70 const uint8_t* header, |
71 size_t packet_length) override; | 71 size_t packet_length) override; |
| 72 void LogRtpHeader(PacketDirection direction, |
| 73 MediaType media_type, |
| 74 const uint8_t* header, |
| 75 size_t packet_length, |
| 76 int probe_cluster_id) override; |
72 void LogRtcpPacket(PacketDirection direction, | 77 void LogRtcpPacket(PacketDirection direction, |
73 MediaType media_type, | 78 MediaType media_type, |
74 const uint8_t* packet, | 79 const uint8_t* packet, |
75 size_t length) override; | 80 size_t length) override; |
76 void LogAudioPlayout(uint32_t ssrc) override; | 81 void LogAudioPlayout(uint32_t ssrc) override; |
77 void LogLossBasedBweUpdate(int32_t bitrate_bps, | 82 void LogLossBasedBweUpdate(int32_t bitrate_bps, |
78 uint8_t fraction_loss, | 83 uint8_t fraction_loss, |
79 int32_t total_packets) override; | 84 int32_t total_packets) override; |
80 void LogDelayBasedBweUpdate(int32_t bitrate_bps, | 85 void LogDelayBasedBweUpdate(int32_t bitrate_bps, |
81 BandwidthUsage detector_state) override; | 86 BandwidthUsage detector_state) override; |
82 void LogAudioNetworkAdaptation( | 87 void LogAudioNetworkAdaptation( |
83 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) override; | 88 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) override; |
| 89 void LogProbeClusterCreated(int id, |
| 90 int bitrate_bps, |
| 91 int min_probes, |
| 92 int min_bytes) override; |
| 93 void LogProbeResultSuccess(int id, int bitrate_bps) override; |
| 94 void LogProbeResultFailure(int id, |
| 95 ProbeFailureReason failure_reason) override; |
84 | 96 |
85 private: | 97 private: |
86 void StoreEvent(std::unique_ptr<rtclog::Event>* event); | 98 void StoreEvent(std::unique_ptr<rtclog::Event>* event); |
| 99 void LogProbeResult(int id, |
| 100 rtclog::BweProbeResult::ResultType result, |
| 101 int bitrate_bps); |
87 | 102 |
88 // Message queue for passing control messages to the logging thread. | 103 // Message queue for passing control messages to the logging thread. |
89 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_; | 104 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_; |
90 | 105 |
91 // Message queue for passing events to the logging thread. | 106 // Message queue for passing events to the logging thread. |
92 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_; | 107 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_; |
93 | 108 |
94 RtcEventLogHelperThread helper_thread_; | 109 RtcEventLogHelperThread helper_thread_; |
95 rtc::ThreadChecker thread_checker_; | 110 rtc::ThreadChecker thread_checker_; |
96 | 111 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return rtclog::DelayBasedBweUpdate::BWE_NORMAL; | 153 return rtclog::DelayBasedBweUpdate::BWE_NORMAL; |
139 case BandwidthUsage::kBwUnderusing: | 154 case BandwidthUsage::kBwUnderusing: |
140 return rtclog::DelayBasedBweUpdate::BWE_UNDERUSING; | 155 return rtclog::DelayBasedBweUpdate::BWE_UNDERUSING; |
141 case BandwidthUsage::kBwOverusing: | 156 case BandwidthUsage::kBwOverusing: |
142 return rtclog::DelayBasedBweUpdate::BWE_OVERUSING; | 157 return rtclog::DelayBasedBweUpdate::BWE_OVERUSING; |
143 } | 158 } |
144 RTC_NOTREACHED(); | 159 RTC_NOTREACHED(); |
145 return rtclog::DelayBasedBweUpdate::BWE_NORMAL; | 160 return rtclog::DelayBasedBweUpdate::BWE_NORMAL; |
146 } | 161 } |
147 | 162 |
| 163 rtclog::BweProbeResult::ResultType ConvertProbeResultType( |
| 164 ProbeFailureReason failure_reason) { |
| 165 switch (failure_reason) { |
| 166 case kInvalidSendReceiveInterval: |
| 167 return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_INTERVAL; |
| 168 case kInvalidSendReceiveRatio: |
| 169 return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO; |
| 170 case kTimeout: |
| 171 return rtclog::BweProbeResult::TIMEOUT; |
| 172 } |
| 173 RTC_NOTREACHED(); |
| 174 return rtclog::BweProbeResult::SUCCESS; |
| 175 } |
| 176 |
148 // The RTP and RTCP buffers reserve space for twice the expected number of | 177 // The RTP and RTCP buffers reserve space for twice the expected number of |
149 // sent packets because they also contain received packets. | 178 // sent packets because they also contain received packets. |
150 static const int kEventsPerSecond = 1000; | 179 static const int kEventsPerSecond = 1000; |
151 static const int kControlMessagesPerSecond = 10; | 180 static const int kControlMessagesPerSecond = 10; |
152 } // namespace | 181 } // namespace |
153 | 182 |
154 // RtcEventLogImpl member functions. | 183 // RtcEventLogImpl member functions. |
155 RtcEventLogImpl::RtcEventLogImpl() | 184 RtcEventLogImpl::RtcEventLogImpl() |
156 // Allocate buffers for roughly one second of history. | 185 // Allocate buffers for roughly one second of history. |
157 : message_queue_(kControlMessagesPerSecond), | 186 : message_queue_(kControlMessagesPerSecond), |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 extension->set_id(e.id); | 376 extension->set_id(e.id); |
348 } | 377 } |
349 | 378 |
350 StoreEvent(&event); | 379 StoreEvent(&event); |
351 } | 380 } |
352 | 381 |
353 void RtcEventLogImpl::LogRtpHeader(PacketDirection direction, | 382 void RtcEventLogImpl::LogRtpHeader(PacketDirection direction, |
354 MediaType media_type, | 383 MediaType media_type, |
355 const uint8_t* header, | 384 const uint8_t* header, |
356 size_t packet_length) { | 385 size_t packet_length) { |
| 386 LogRtpHeader(direction, media_type, header, packet_length, |
| 387 PacedPacketInfo::kNotAProbe); |
| 388 } |
| 389 |
| 390 void RtcEventLogImpl::LogRtpHeader(PacketDirection direction, |
| 391 MediaType media_type, |
| 392 const uint8_t* header, |
| 393 size_t packet_length, |
| 394 int probe_cluster_id) { |
357 // Read header length (in bytes) from packet data. | 395 // Read header length (in bytes) from packet data. |
358 if (packet_length < 12u) { | 396 if (packet_length < 12u) { |
359 return; // Don't read outside the packet. | 397 return; // Don't read outside the packet. |
360 } | 398 } |
361 const bool x = (header[0] & 0x10) != 0; | 399 const bool x = (header[0] & 0x10) != 0; |
362 const uint8_t cc = header[0] & 0x0f; | 400 const uint8_t cc = header[0] & 0x0f; |
363 size_t header_length = 12u + cc * 4u; | 401 size_t header_length = 12u + cc * 4u; |
364 | 402 |
365 if (x) { | 403 if (x) { |
366 if (packet_length < 12u + cc * 4u + 4u) { | 404 if (packet_length < 12u + cc * 4u + 4u) { |
367 return; // Don't read outside the packet. | 405 return; // Don't read outside the packet. |
368 } | 406 } |
369 size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4); | 407 size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4); |
370 header_length += (x_len + 1) * 4; | 408 header_length += (x_len + 1) * 4; |
371 } | 409 } |
372 | 410 |
373 std::unique_ptr<rtclog::Event> rtp_event(new rtclog::Event()); | 411 std::unique_ptr<rtclog::Event> rtp_event(new rtclog::Event()); |
374 rtp_event->set_timestamp_us(rtc::TimeMicros()); | 412 rtp_event->set_timestamp_us(rtc::TimeMicros()); |
375 rtp_event->set_type(rtclog::Event::RTP_EVENT); | 413 rtp_event->set_type(rtclog::Event::RTP_EVENT); |
376 rtp_event->mutable_rtp_packet()->set_incoming(direction == kIncomingPacket); | 414 rtp_event->mutable_rtp_packet()->set_incoming(direction == kIncomingPacket); |
377 rtp_event->mutable_rtp_packet()->set_type(ConvertMediaType(media_type)); | 415 rtp_event->mutable_rtp_packet()->set_type(ConvertMediaType(media_type)); |
378 rtp_event->mutable_rtp_packet()->set_packet_length(packet_length); | 416 rtp_event->mutable_rtp_packet()->set_packet_length(packet_length); |
379 rtp_event->mutable_rtp_packet()->set_header(header, header_length); | 417 rtp_event->mutable_rtp_packet()->set_header(header, header_length); |
| 418 if (probe_cluster_id != PacedPacketInfo::kNotAProbe) |
| 419 rtp_event->mutable_rtp_packet()->set_probe_cluster_id(probe_cluster_id); |
380 StoreEvent(&rtp_event); | 420 StoreEvent(&rtp_event); |
381 } | 421 } |
382 | 422 |
383 void RtcEventLogImpl::LogRtcpPacket(PacketDirection direction, | 423 void RtcEventLogImpl::LogRtcpPacket(PacketDirection direction, |
384 MediaType media_type, | 424 MediaType media_type, |
385 const uint8_t* packet, | 425 const uint8_t* packet, |
386 size_t length) { | 426 size_t length) { |
387 std::unique_ptr<rtclog::Event> rtcp_event(new rtclog::Event()); | 427 std::unique_ptr<rtclog::Event> rtcp_event(new rtclog::Event()); |
388 rtcp_event->set_timestamp_us(rtc::TimeMicros()); | 428 rtcp_event->set_timestamp_us(rtc::TimeMicros()); |
389 rtcp_event->set_type(rtclog::Event::RTCP_EVENT); | 429 rtcp_event->set_type(rtclog::Event::RTCP_EVENT); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } | 519 } |
480 if (config.enable_fec) | 520 if (config.enable_fec) |
481 audio_network_adaptation->set_enable_fec(*config.enable_fec); | 521 audio_network_adaptation->set_enable_fec(*config.enable_fec); |
482 if (config.enable_dtx) | 522 if (config.enable_dtx) |
483 audio_network_adaptation->set_enable_dtx(*config.enable_dtx); | 523 audio_network_adaptation->set_enable_dtx(*config.enable_dtx); |
484 if (config.num_channels) | 524 if (config.num_channels) |
485 audio_network_adaptation->set_num_channels(*config.num_channels); | 525 audio_network_adaptation->set_num_channels(*config.num_channels); |
486 StoreEvent(&event); | 526 StoreEvent(&event); |
487 } | 527 } |
488 | 528 |
| 529 void RtcEventLogImpl::LogProbeClusterCreated(int id, |
| 530 int bitrate_bps, |
| 531 int min_probes, |
| 532 int min_bytes) { |
| 533 std::unique_ptr<rtclog::Event> event(new rtclog::Event()); |
| 534 event->set_timestamp_us(rtc::TimeMicros()); |
| 535 event->set_type(rtclog::Event::BWE_PROBE_CLUSTER_CREATED_EVENT); |
| 536 |
| 537 auto probe_cluster = event->mutable_probe_cluster(); |
| 538 probe_cluster->set_id(id); |
| 539 probe_cluster->set_bitrate_bps(bitrate_bps); |
| 540 probe_cluster->set_min_packets(min_probes); |
| 541 probe_cluster->set_min_bytes(min_bytes); |
| 542 StoreEvent(&event); |
| 543 } |
| 544 |
| 545 void RtcEventLogImpl::LogProbeResultSuccess(int id, int bitrate_bps) { |
| 546 LogProbeResult(id, rtclog::BweProbeResult::SUCCESS, bitrate_bps); |
| 547 } |
| 548 |
| 549 void RtcEventLogImpl::LogProbeResultFailure(int id, |
| 550 ProbeFailureReason failure_reason) { |
| 551 rtclog::BweProbeResult::ResultType result = |
| 552 ConvertProbeResultType(failure_reason); |
| 553 LogProbeResult(id, result, -1); |
| 554 } |
| 555 |
| 556 void RtcEventLogImpl::LogProbeResult(int id, |
| 557 rtclog::BweProbeResult::ResultType result, |
| 558 int bitrate_bps) { |
| 559 std::unique_ptr<rtclog::Event> event(new rtclog::Event()); |
| 560 event->set_timestamp_us(rtc::TimeMicros()); |
| 561 event->set_type(rtclog::Event::BWE_PROBE_RESULT_EVENT); |
| 562 |
| 563 auto probe_result = event->mutable_probe_result(); |
| 564 probe_result->set_id(id); |
| 565 probe_result->set_result(result); |
| 566 if (result == rtclog::BweProbeResult::SUCCESS) |
| 567 probe_result->set_bitrate_bps(bitrate_bps); |
| 568 StoreEvent(&event); |
| 569 } |
| 570 |
489 void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) { | 571 void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) { |
490 if (!event_queue_.Insert(event)) { | 572 if (!event_queue_.Insert(event)) { |
491 LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event."; | 573 LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event."; |
492 } | 574 } |
493 helper_thread_.SignalNewEvent(); | 575 helper_thread_.SignalNewEvent(); |
494 } | 576 } |
495 | 577 |
496 bool RtcEventLog::ParseRtcEventLog(const std::string& file_name, | 578 bool RtcEventLog::ParseRtcEventLog(const std::string& file_name, |
497 rtclog::EventStream* result) { | 579 rtclog::EventStream* result) { |
498 char tmp_buffer[1024]; | 580 char tmp_buffer[1024]; |
(...skipping 28 matching lines...) Expand all Loading... |
527 #else | 609 #else |
528 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 610 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
529 #endif // ENABLE_RTC_EVENT_LOG | 611 #endif // ENABLE_RTC_EVENT_LOG |
530 } | 612 } |
531 | 613 |
532 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { | 614 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { |
533 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 615 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
534 } | 616 } |
535 | 617 |
536 } // namespace webrtc | 618 } // namespace webrtc |
OLD | NEW |