Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: webrtc/logging/rtc_event_log/rtc_event_log.cc

Issue 2666533002: Add probe logging to RtcEventLog. (Closed)
Patch Set: Fix comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 LogBwePacketLossEvent(int32_t bitrate, 82 void LogBwePacketLossEvent(int32_t bitrate,
78 uint8_t fraction_loss, 83 uint8_t fraction_loss,
79 int32_t total_packets) override; 84 int32_t total_packets) override;
80 void LogAudioNetworkAdaptation( 85 void LogAudioNetworkAdaptation(
81 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) override; 86 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) override;
87 void LogProbeClusterCreated(int id,
88 int bitrate_bps,
89 int min_probes,
90 int min_bytes) override;
91 void LogProbeResultSuccess(int id, int bitrate_bps) override;
92 void LogProbeResultFailure(int id,
93 ProbeFailureReason failure_reason) override;
82 94
83 private: 95 private:
84 void StoreEvent(std::unique_ptr<rtclog::Event>* event); 96 void StoreEvent(std::unique_ptr<rtclog::Event>* event);
97 void LogProbeResult(int id,
98 rtclog::BweProbeResult::ResultType result,
99 int bitrate_bps);
85 100
86 // Message queue for passing control messages to the logging thread. 101 // Message queue for passing control messages to the logging thread.
87 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_; 102 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_;
88 103
89 // Message queue for passing events to the logging thread. 104 // Message queue for passing events to the logging thread.
90 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_; 105 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_;
91 106
92 RtcEventLogHelperThread helper_thread_; 107 RtcEventLogHelperThread helper_thread_;
93 rtc::ThreadChecker thread_checker_; 108 rtc::ThreadChecker thread_checker_;
94 109
(...skipping 27 matching lines...) Expand all
122 return rtclog::MediaType::AUDIO; 137 return rtclog::MediaType::AUDIO;
123 case MediaType::VIDEO: 138 case MediaType::VIDEO:
124 return rtclog::MediaType::VIDEO; 139 return rtclog::MediaType::VIDEO;
125 case MediaType::DATA: 140 case MediaType::DATA:
126 return rtclog::MediaType::DATA; 141 return rtclog::MediaType::DATA;
127 } 142 }
128 RTC_NOTREACHED(); 143 RTC_NOTREACHED();
129 return rtclog::ANY; 144 return rtclog::ANY;
130 } 145 }
131 146
147 rtclog::BweProbeResult::ResultType ConvertProbeResultType(
148 ProbeFailureReason failure_reason) {
149 switch (failure_reason) {
150 case kInvalidSendReceiveInterval:
151 return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_INTERVAL;
152 case kInvalidSendReceiveRatio:
153 return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO;
154 case kTimeout:
155 return rtclog::BweProbeResult::TIMEOUT;
156 }
157 RTC_NOTREACHED();
158 return rtclog::BweProbeResult::SUCCESS;
159 }
160
132 // The RTP and RTCP buffers reserve space for twice the expected number of 161 // The RTP and RTCP buffers reserve space for twice the expected number of
133 // sent packets because they also contain received packets. 162 // sent packets because they also contain received packets.
134 static const int kEventsPerSecond = 1000; 163 static const int kEventsPerSecond = 1000;
135 static const int kControlMessagesPerSecond = 10; 164 static const int kControlMessagesPerSecond = 10;
136 } // namespace 165 } // namespace
137 166
138 // RtcEventLogImpl member functions. 167 // RtcEventLogImpl member functions.
139 RtcEventLogImpl::RtcEventLogImpl() 168 RtcEventLogImpl::RtcEventLogImpl()
140 // Allocate buffers for roughly one second of history. 169 // Allocate buffers for roughly one second of history.
141 : message_queue_(kControlMessagesPerSecond), 170 : message_queue_(kControlMessagesPerSecond),
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 extension->set_id(e.id); 360 extension->set_id(e.id);
332 } 361 }
333 362
334 StoreEvent(&event); 363 StoreEvent(&event);
335 } 364 }
336 365
337 void RtcEventLogImpl::LogRtpHeader(PacketDirection direction, 366 void RtcEventLogImpl::LogRtpHeader(PacketDirection direction,
338 MediaType media_type, 367 MediaType media_type,
339 const uint8_t* header, 368 const uint8_t* header,
340 size_t packet_length) { 369 size_t packet_length) {
370 LogRtpHeader(direction, media_type, header, packet_length,
371 PacketInfo::kNotAProbe);
372 }
373
374 void RtcEventLogImpl::LogRtpHeader(PacketDirection direction,
375 MediaType media_type,
376 const uint8_t* header,
377 size_t packet_length,
378 int probe_cluster_id) {
341 // Read header length (in bytes) from packet data. 379 // Read header length (in bytes) from packet data.
342 if (packet_length < 12u) { 380 if (packet_length < 12u) {
343 return; // Don't read outside the packet. 381 return; // Don't read outside the packet.
344 } 382 }
345 const bool x = (header[0] & 0x10) != 0; 383 const bool x = (header[0] & 0x10) != 0;
346 const uint8_t cc = header[0] & 0x0f; 384 const uint8_t cc = header[0] & 0x0f;
347 size_t header_length = 12u + cc * 4u; 385 size_t header_length = 12u + cc * 4u;
348 386
349 if (x) { 387 if (x) {
350 if (packet_length < 12u + cc * 4u + 4u) { 388 if (packet_length < 12u + cc * 4u + 4u) {
351 return; // Don't read outside the packet. 389 return; // Don't read outside the packet.
352 } 390 }
353 size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4); 391 size_t x_len = ByteReader<uint16_t>::ReadBigEndian(header + 14 + cc * 4);
354 header_length += (x_len + 1) * 4; 392 header_length += (x_len + 1) * 4;
355 } 393 }
356 394
357 std::unique_ptr<rtclog::Event> rtp_event(new rtclog::Event()); 395 std::unique_ptr<rtclog::Event> rtp_event(new rtclog::Event());
358 rtp_event->set_timestamp_us(rtc::TimeMicros()); 396 rtp_event->set_timestamp_us(rtc::TimeMicros());
359 rtp_event->set_type(rtclog::Event::RTP_EVENT); 397 rtp_event->set_type(rtclog::Event::RTP_EVENT);
360 rtp_event->mutable_rtp_packet()->set_incoming(direction == kIncomingPacket); 398 rtp_event->mutable_rtp_packet()->set_incoming(direction == kIncomingPacket);
361 rtp_event->mutable_rtp_packet()->set_type(ConvertMediaType(media_type)); 399 rtp_event->mutable_rtp_packet()->set_type(ConvertMediaType(media_type));
362 rtp_event->mutable_rtp_packet()->set_packet_length(packet_length); 400 rtp_event->mutable_rtp_packet()->set_packet_length(packet_length);
363 rtp_event->mutable_rtp_packet()->set_header(header, header_length); 401 rtp_event->mutable_rtp_packet()->set_header(header, header_length);
402 if (probe_cluster_id != PacketInfo::kNotAProbe)
403 rtp_event->mutable_rtp_packet()->set_probe_cluster_id(probe_cluster_id);
364 StoreEvent(&rtp_event); 404 StoreEvent(&rtp_event);
365 } 405 }
366 406
367 void RtcEventLogImpl::LogRtcpPacket(PacketDirection direction, 407 void RtcEventLogImpl::LogRtcpPacket(PacketDirection direction,
368 MediaType media_type, 408 MediaType media_type,
369 const uint8_t* packet, 409 const uint8_t* packet,
370 size_t length) { 410 size_t length) {
371 std::unique_ptr<rtclog::Event> rtcp_event(new rtclog::Event()); 411 std::unique_ptr<rtclog::Event> rtcp_event(new rtclog::Event());
372 rtcp_event->set_timestamp_us(rtc::TimeMicros()); 412 rtcp_event->set_timestamp_us(rtc::TimeMicros());
373 rtcp_event->set_type(rtclog::Event::RTCP_EVENT); 413 rtcp_event->set_type(rtclog::Event::RTCP_EVENT);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 492 }
453 if (config.enable_fec) 493 if (config.enable_fec)
454 audio_network_adaptation->set_enable_fec(*config.enable_fec); 494 audio_network_adaptation->set_enable_fec(*config.enable_fec);
455 if (config.enable_dtx) 495 if (config.enable_dtx)
456 audio_network_adaptation->set_enable_dtx(*config.enable_dtx); 496 audio_network_adaptation->set_enable_dtx(*config.enable_dtx);
457 if (config.num_channels) 497 if (config.num_channels)
458 audio_network_adaptation->set_num_channels(*config.num_channels); 498 audio_network_adaptation->set_num_channels(*config.num_channels);
459 StoreEvent(&event); 499 StoreEvent(&event);
460 } 500 }
461 501
502 void RtcEventLogImpl::LogProbeClusterCreated(int id,
503 int bitrate_bps,
504 int min_probes,
505 int min_bytes) {
506 std::unique_ptr<rtclog::Event> event(new rtclog::Event());
507 event->set_timestamp_us(rtc::TimeMicros());
508 event->set_type(rtclog::Event::BWE_PROBE_CLUSTER_CREATED_EVENT);
509
510 auto probe_cluster = event->mutable_probe_cluster();
511 probe_cluster->set_id(id);
512 probe_cluster->set_bitrate_bps(bitrate_bps);
513 probe_cluster->set_min_probes(min_probes);
514 probe_cluster->set_min_bytes(min_bytes);
515 StoreEvent(&event);
516 }
517
518 void RtcEventLogImpl::LogProbeResultSuccess(int id, int bitrate_bps) {
519 LogProbeResult(id, rtclog::BweProbeResult::SUCCESS, bitrate_bps);
520 }
521
522 void RtcEventLogImpl::LogProbeResultFailure(int id,
523 ProbeFailureReason failure_reason) {
524 rtclog::BweProbeResult::ResultType result =
525 ConvertProbeResultType(failure_reason);
526 LogProbeResult(id, result, -1);
527 }
528
529 void RtcEventLogImpl::LogProbeResult(int id,
530 rtclog::BweProbeResult::ResultType result,
531 int bitrate_bps) {
532 std::unique_ptr<rtclog::Event> event(new rtclog::Event());
533 event->set_timestamp_us(rtc::TimeMicros());
534 event->set_type(rtclog::Event::BWE_PROBE_RESULT_EVENT);
535
536 auto probe_result = event->mutable_probe_result();
537 probe_result->set_id(id);
538 probe_result->set_result(result);
539 if (result == rtclog::BweProbeResult::SUCCESS)
540 probe_result->set_bitrate_bps(bitrate_bps);
541 StoreEvent(&event);
542 }
543
462 void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) { 544 void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) {
463 if (!event_queue_.Insert(event)) { 545 if (!event_queue_.Insert(event)) {
464 LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event."; 546 LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event.";
465 } 547 }
466 helper_thread_.SignalNewEvent(); 548 helper_thread_.SignalNewEvent();
467 } 549 }
468 550
469 bool RtcEventLog::ParseRtcEventLog(const std::string& file_name, 551 bool RtcEventLog::ParseRtcEventLog(const std::string& file_name,
470 rtclog::EventStream* result) { 552 rtclog::EventStream* result) {
471 char tmp_buffer[1024]; 553 char tmp_buffer[1024];
(...skipping 28 matching lines...) Expand all
500 #else 582 #else
501 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); 583 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
502 #endif // ENABLE_RTC_EVENT_LOG 584 #endif // ENABLE_RTC_EVENT_LOG
503 } 585 }
504 586
505 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { 587 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() {
506 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); 588 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
507 } 589 }
508 590
509 } // namespace webrtc 591 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698