• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 namespace webrtc {
19 
20 namespace {
21 
StreamTypeToString(VideoSendStream::StreamStats::StreamType type)22 const char* StreamTypeToString(VideoSendStream::StreamStats::StreamType type) {
23   switch (type) {
24     case VideoSendStream::StreamStats::StreamType::kMedia:
25       return "media";
26     case VideoSendStream::StreamStats::StreamType::kRtx:
27       return "rtx";
28     case VideoSendStream::StreamStats::StreamType::kFlexfec:
29       return "flexfec";
30   }
31 }
32 
33 }  // namespace
34 
35 VideoSendStream::StreamStats::StreamStats() = default;
36 VideoSendStream::StreamStats::~StreamStats() = default;
37 
ToString() const38 std::string VideoSendStream::StreamStats::ToString() const {
39   char buf[1024];
40   rtc::SimpleStringBuilder ss(buf);
41   ss << "type: " << StreamTypeToString(type);
42   if (referenced_media_ssrc.has_value())
43     ss << " (for: " << referenced_media_ssrc.value() << ")";
44   ss << ", ";
45   ss << "width: " << width << ", ";
46   ss << "height: " << height << ", ";
47   ss << "key: " << frame_counts.key_frames << ", ";
48   ss << "delta: " << frame_counts.delta_frames << ", ";
49   ss << "total_bps: " << total_bitrate_bps << ", ";
50   ss << "retransmit_bps: " << retransmit_bitrate_bps << ", ";
51   ss << "avg_delay_ms: " << avg_delay_ms << ", ";
52   ss << "max_delay_ms: " << max_delay_ms << ", ";
53   ss << "cum_loss: " << rtcp_stats.packets_lost << ", ";
54   ss << "max_ext_seq: " << rtcp_stats.extended_highest_sequence_number << ", ";
55   ss << "nack: " << rtcp_packet_type_counts.nack_packets << ", ";
56   ss << "fir: " << rtcp_packet_type_counts.fir_packets << ", ";
57   ss << "pli: " << rtcp_packet_type_counts.pli_packets;
58   return ss.str();
59 }
60 
61 VideoSendStream::Stats::Stats() = default;
62 VideoSendStream::Stats::~Stats() = default;
63 
ToString(int64_t time_ms) const64 std::string VideoSendStream::Stats::ToString(int64_t time_ms) const {
65   char buf[2048];
66   rtc::SimpleStringBuilder ss(buf);
67   ss << "VideoSendStream stats: " << time_ms << ", {";
68   ss << "input_fps: " << input_frame_rate << ", ";
69   ss << "encode_fps: " << encode_frame_rate << ", ";
70   ss << "encode_ms: " << avg_encode_time_ms << ", ";
71   ss << "encode_usage_perc: " << encode_usage_percent << ", ";
72   ss << "target_bps: " << target_media_bitrate_bps << ", ";
73   ss << "media_bps: " << media_bitrate_bps << ", ";
74   ss << "suspended: " << (suspended ? "true" : "false") << ", ";
75   ss << "bw_adapted_res: " << (bw_limited_resolution ? "true" : "false")
76      << ", ";
77   ss << "cpu_adapted_res: " << (cpu_limited_resolution ? "true" : "false")
78      << ", ";
79   ss << "bw_adapted_fps: " << (bw_limited_framerate ? "true" : "false") << ", ";
80   ss << "cpu_adapted_fps: " << (cpu_limited_framerate ? "true" : "false")
81      << ", ";
82   ss << "#cpu_adaptations: " << number_of_cpu_adapt_changes << ", ";
83   ss << "#quality_adaptations: " << number_of_quality_adapt_changes;
84   ss << '}';
85   for (const auto& substream : substreams) {
86     if (substream.second.type ==
87         VideoSendStream::StreamStats::StreamType::kMedia) {
88       ss << " {ssrc: " << substream.first << ", ";
89       ss << substream.second.ToString();
90       ss << '}';
91     }
92   }
93   return ss.str();
94 }
95 
96 VideoSendStream::Config::Config(const Config&) = default;
97 VideoSendStream::Config::Config(Config&&) = default;
Config(Transport * send_transport)98 VideoSendStream::Config::Config(Transport* send_transport)
99     : rtp(),
100       encoder_settings(VideoEncoder::Capabilities(rtp.lntf.enabled)),
101       send_transport(send_transport) {}
102 
103 VideoSendStream::Config& VideoSendStream::Config::operator=(Config&&) = default;
104 VideoSendStream::Config::Config::~Config() = default;
105 
ToString() const106 std::string VideoSendStream::Config::ToString() const {
107   char buf[2 * 1024];
108   rtc::SimpleStringBuilder ss(buf);
109   ss << "{encoder_settings: { experiment_cpu_load_estimator: "
110      << (encoder_settings.experiment_cpu_load_estimator ? "on" : "off") << "}}";
111   ss << ", rtp: " << rtp.ToString();
112   ss << ", rtcp_report_interval_ms: " << rtcp_report_interval_ms;
113   ss << ", send_transport: " << (send_transport ? "(Transport)" : "nullptr");
114   ss << ", render_delay_ms: " << render_delay_ms;
115   ss << ", target_delay_ms: " << target_delay_ms;
116   ss << ", suspend_below_min_bitrate: "
117      << (suspend_below_min_bitrate ? "on" : "off");
118   ss << '}';
119   return ss.str();
120 }
121 
122 }  // namespace webrtc
123