video_send_stream.cc (4796B)
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 "call/video_send_stream.h" 12 13 #include <cstdint> 14 #include <string> 15 #include <utility> 16 17 #include "api/call/transport.h" 18 #include "api/video_codecs/video_encoder.h" 19 #include "rtc_base/checks.h" 20 #include "rtc_base/strings/string_builder.h" 21 #include "rtc_base/strings/string_format.h" 22 23 namespace webrtc { 24 25 namespace { 26 27 const char* StreamTypeToString(VideoSendStream::StreamStats::StreamType type) { 28 switch (type) { 29 case VideoSendStream::StreamStats::StreamType::kMedia: 30 return "media"; 31 case VideoSendStream::StreamStats::StreamType::kRtx: 32 return "rtx"; 33 case VideoSendStream::StreamStats::StreamType::kFlexfec: 34 return "flexfec"; 35 } 36 RTC_CHECK_NOTREACHED(); 37 } 38 39 } // namespace 40 41 VideoSendStream::StreamStats::StreamStats() = default; 42 VideoSendStream::StreamStats::~StreamStats() = default; 43 44 std::string VideoSendStream::StreamStats::ToString() const { 45 StringBuilder ss; 46 ss << "type: " << StreamTypeToString(type); 47 if (referenced_media_ssrc.has_value()) 48 ss << " (for: " << referenced_media_ssrc.value() << ")"; 49 ss << ", "; 50 ss << "width: " << width << ", "; 51 ss << "height: " << height << ", "; 52 ss << "key: " << frame_counts.key_frames << ", "; 53 ss << "delta: " << frame_counts.delta_frames << ", "; 54 ss << "total_bps: " << total_bitrate_bps << ", "; 55 ss << "retransmit_bps: " << retransmit_bitrate_bps << ", "; 56 ss << "avg_delay_ms: " << avg_delay_ms << ", "; 57 ss << "max_delay_ms: " << max_delay_ms << ", "; 58 if (report_block_data) { 59 ss << "cum_loss: " << report_block_data->cumulative_lost() << ", "; 60 ss << "max_ext_seq: " 61 << report_block_data->extended_highest_sequence_number() << ", "; 62 } 63 ss << "nack: " << rtcp_packet_type_counts.nack_packets << ", "; 64 ss << "fir: " << rtcp_packet_type_counts.fir_packets << ", "; 65 ss << "pli: " << rtcp_packet_type_counts.pli_packets; 66 return ss.str(); 67 } 68 69 VideoSendStream::Stats::Stats() = default; 70 VideoSendStream::Stats::~Stats() = default; 71 72 std::string VideoSendStream::Stats::ToString(int64_t time_ms) const { 73 StringBuilder ss; 74 ss << "VideoSendStream stats: " << time_ms << ", {"; 75 ss << "input_fps: " << StringFormat("%.1f", input_frame_rate) << ", "; 76 ss << "encode_fps: " << encode_frame_rate << ", "; 77 ss << "encode_ms: " << avg_encode_time_ms << ", "; 78 ss << "encode_usage_perc: " << encode_usage_percent << ", "; 79 ss << "target_bps: " << target_media_bitrate_bps << ", "; 80 ss << "media_bps: " << media_bitrate_bps << ", "; 81 ss << "suspended: " << (suspended ? "true" : "false") << ", "; 82 ss << "bw_adapted_res: " << (bw_limited_resolution ? "true" : "false") 83 << ", "; 84 ss << "cpu_adapted_res: " << (cpu_limited_resolution ? "true" : "false") 85 << ", "; 86 ss << "bw_adapted_fps: " << (bw_limited_framerate ? "true" : "false") << ", "; 87 ss << "cpu_adapted_fps: " << (cpu_limited_framerate ? "true" : "false") 88 << ", "; 89 ss << "#cpu_adaptations: " << number_of_cpu_adapt_changes << ", "; 90 ss << "#quality_adaptations: " << number_of_quality_adapt_changes; 91 ss << "}"; 92 for (const auto& substream : substreams) { 93 if (substream.second.type == 94 VideoSendStream::StreamStats::StreamType::kMedia) { 95 ss << " {ssrc: " << substream.first << ", "; 96 ss << substream.second.ToString(); 97 ss << "}"; 98 } 99 } 100 return ss.str(); 101 } 102 103 VideoSendStream::Config::Config(const Config&) = default; 104 VideoSendStream::Config::Config(Config&&) = default; 105 VideoSendStream::Config::Config(Transport* send_transport) 106 : rtp(), 107 encoder_settings(VideoEncoder::Capabilities(rtp.lntf.enabled)), 108 send_transport(send_transport) {} 109 110 VideoSendStream::Config& VideoSendStream::Config::operator=(Config&&) = default; 111 VideoSendStream::Config::Config::~Config() = default; 112 113 std::string VideoSendStream::Config::ToString() const { 114 StringBuilder ss; 115 ss << "{encoder_settings: { experiment_cpu_load_estimator: " 116 << (encoder_settings.experiment_cpu_load_estimator ? "on" : "off") << "}}"; 117 ss << ", rtp: " << rtp.ToString(); 118 ss << ", rtcp_report_interval_ms: " << rtcp_report_interval_ms; 119 ss << ", send_transport: " << (send_transport ? "(Transport)" : "nullptr"); 120 ss << ", render_delay_ms: " << render_delay_ms; 121 ss << ", target_delay_ms: " << target_delay_ms; 122 ss << ", suspend_below_min_bitrate: " 123 << (suspend_below_min_bitrate ? "on" : "off"); 124 ss << "}"; 125 return ss.str(); 126 } 127 128 } // namespace webrtc