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 <utility>
14
15 #include "api/crypto/frame_encryptor_interface.h"
16 #include "rtc_base/strings/string_builder.h"
17 #include "rtc_base/strings/string_format.h"
18
19 namespace webrtc {
20
21 namespace {
22
StreamTypeToString(VideoSendStream::StreamStats::StreamType type)23 const char* StreamTypeToString(VideoSendStream::StreamStats::StreamType type) {
24 switch (type) {
25 case VideoSendStream::StreamStats::StreamType::kMedia:
26 return "media";
27 case VideoSendStream::StreamStats::StreamType::kRtx:
28 return "rtx";
29 case VideoSendStream::StreamStats::StreamType::kFlexfec:
30 return "flexfec";
31 }
32 RTC_CHECK_NOTREACHED();
33 }
34
35 } // namespace
36
37 VideoSendStream::StreamStats::StreamStats() = default;
38 VideoSendStream::StreamStats::~StreamStats() = default;
39
ToString() const40 std::string VideoSendStream::StreamStats::ToString() const {
41 char buf[1024];
42 rtc::SimpleStringBuilder ss(buf);
43 ss << "type: " << StreamTypeToString(type);
44 if (referenced_media_ssrc.has_value())
45 ss << " (for: " << referenced_media_ssrc.value() << ")";
46 ss << ", ";
47 ss << "width: " << width << ", ";
48 ss << "height: " << height << ", ";
49 ss << "key: " << frame_counts.key_frames << ", ";
50 ss << "delta: " << frame_counts.delta_frames << ", ";
51 ss << "total_bps: " << total_bitrate_bps << ", ";
52 ss << "retransmit_bps: " << retransmit_bitrate_bps << ", ";
53 ss << "avg_delay_ms: " << avg_delay_ms << ", ";
54 ss << "max_delay_ms: " << max_delay_ms << ", ";
55 if (report_block_data) {
56 ss << "cum_loss: " << report_block_data->report_block().packets_lost
57 << ", ";
58 ss << "max_ext_seq: "
59 << report_block_data->report_block().extended_highest_sequence_number
60 << ", ";
61 }
62 ss << "nack: " << rtcp_packet_type_counts.nack_packets << ", ";
63 ss << "fir: " << rtcp_packet_type_counts.fir_packets << ", ";
64 ss << "pli: " << rtcp_packet_type_counts.pli_packets;
65 return ss.str();
66 }
67
68 VideoSendStream::Stats::Stats() = default;
69 VideoSendStream::Stats::~Stats() = default;
70
ToString(int64_t time_ms) const71 std::string VideoSendStream::Stats::ToString(int64_t time_ms) const {
72 char buf[2048];
73 rtc::SimpleStringBuilder ss(buf);
74 ss << "VideoSendStream stats: " << time_ms << ", {";
75 ss << "input_fps: " << rtc::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;
Config(Transport * send_transport)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
ToString() const113 std::string VideoSendStream::Config::ToString() const {
114 char buf[2 * 1024];
115 rtc::SimpleStringBuilder ss(buf);
116 ss << "{encoder_settings: { experiment_cpu_load_estimator: "
117 << (encoder_settings.experiment_cpu_load_estimator ? "on" : "off") << "}}";
118 ss << ", rtp: " << rtp.ToString();
119 ss << ", rtcp_report_interval_ms: " << rtcp_report_interval_ms;
120 ss << ", send_transport: " << (send_transport ? "(Transport)" : "nullptr");
121 ss << ", render_delay_ms: " << render_delay_ms;
122 ss << ", target_delay_ms: " << target_delay_ms;
123 ss << ", suspend_below_min_bitrate: "
124 << (suspend_below_min_bitrate ? "on" : "off");
125 ss << '}';
126 return ss.str();
127 }
128
129 } // namespace webrtc
130