blob: 20f6cefc3e3347773aa5a7752f948f5a9da7c24a [file] [log] [blame]
aleloi440b6d92017-08-22 12:43:231/*
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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "call/video_send_stream.h"
Yves Gerey988cc082018-10-23 10:03:0112
Harald Alvestrand93c9aa12024-09-02 20:55:5213#include <cstdint>
14#include <string>
Yves Gerey988cc082018-10-23 10:03:0115#include <utility>
16
Harald Alvestrand93c9aa12024-09-02 20:55:5217#include "api/call/transport.h"
18#include "api/video_codecs/video_encoder.h"
19#include "rtc_base/checks.h"
Jonas Olsson0a713b62018-04-04 13:49:3220#include "rtc_base/strings/string_builder.h"
Byoungchan Leeefe46b62021-11-10 02:23:5621#include "rtc_base/strings/string_format.h"
aleloi440b6d92017-08-22 12:43:2322
23namespace webrtc {
24
Henrik Boströmf45ca372020-03-24 12:30:5025namespace {
26
27const 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 }
Karl Wibergc95b9392020-11-07 23:49:3736 RTC_CHECK_NOTREACHED();
Henrik Boströmf45ca372020-03-24 12:30:5037}
38
39} // namespace
40
aleloi440b6d92017-08-22 12:43:2341VideoSendStream::StreamStats::StreamStats() = default;
42VideoSendStream::StreamStats::~StreamStats() = default;
43
44std::string VideoSendStream::StreamStats::ToString() const {
Jonas Olsson0a713b62018-04-04 13:49:3245 char buf[1024];
46 rtc::SimpleStringBuilder ss(buf);
Henrik Boströmf45ca372020-03-24 12:30:5047 ss << "type: " << StreamTypeToString(type);
48 if (referenced_media_ssrc.has_value())
49 ss << " (for: " << referenced_media_ssrc.value() << ")";
50 ss << ", ";
aleloi440b6d92017-08-22 12:43:2351 ss << "width: " << width << ", ";
52 ss << "height: " << height << ", ";
53 ss << "key: " << frame_counts.key_frames << ", ";
54 ss << "delta: " << frame_counts.delta_frames << ", ";
55 ss << "total_bps: " << total_bitrate_bps << ", ";
56 ss << "retransmit_bps: " << retransmit_bitrate_bps << ", ";
57 ss << "avg_delay_ms: " << avg_delay_ms << ", ";
58 ss << "max_delay_ms: " << max_delay_ms << ", ";
Danil Chapovalovea7474e2021-05-18 10:48:1259 if (report_block_data) {
Danil Chapovalovea33f7f2023-05-04 10:12:3360 ss << "cum_loss: " << report_block_data->cumulative_lost() << ", ";
Danil Chapovalovea7474e2021-05-18 10:48:1261 ss << "max_ext_seq: "
Danil Chapovalovea33f7f2023-05-04 10:12:3362 << report_block_data->extended_highest_sequence_number() << ", ";
Danil Chapovalovea7474e2021-05-18 10:48:1263 }
aleloi440b6d92017-08-22 12:43:2364 ss << "nack: " << rtcp_packet_type_counts.nack_packets << ", ";
65 ss << "fir: " << rtcp_packet_type_counts.fir_packets << ", ";
66 ss << "pli: " << rtcp_packet_type_counts.pli_packets;
67 return ss.str();
68}
69
70VideoSendStream::Stats::Stats() = default;
71VideoSendStream::Stats::~Stats() = default;
72
73std::string VideoSendStream::Stats::ToString(int64_t time_ms) const {
Rasmus Brandtd42a4492019-04-16 14:51:2474 char buf[2048];
Jonas Olsson0a713b62018-04-04 13:49:3275 rtc::SimpleStringBuilder ss(buf);
aleloi440b6d92017-08-22 12:43:2376 ss << "VideoSendStream stats: " << time_ms << ", {";
Byoungchan Leeefe46b62021-11-10 02:23:5677 ss << "input_fps: " << rtc::StringFormat("%.1f", input_frame_rate) << ", ";
aleloi440b6d92017-08-22 12:43:2378 ss << "encode_fps: " << encode_frame_rate << ", ";
79 ss << "encode_ms: " << avg_encode_time_ms << ", ";
80 ss << "encode_usage_perc: " << encode_usage_percent << ", ";
81 ss << "target_bps: " << target_media_bitrate_bps << ", ";
82 ss << "media_bps: " << media_bitrate_bps << ", ";
aleloi440b6d92017-08-22 12:43:2383 ss << "suspended: " << (suspended ? "true" : "false") << ", ";
Rasmus Brandtd42a4492019-04-16 14:51:2484 ss << "bw_adapted_res: " << (bw_limited_resolution ? "true" : "false")
85 << ", ";
86 ss << "cpu_adapted_res: " << (cpu_limited_resolution ? "true" : "false")
87 << ", ";
88 ss << "bw_adapted_fps: " << (bw_limited_framerate ? "true" : "false") << ", ";
89 ss << "cpu_adapted_fps: " << (cpu_limited_framerate ? "true" : "false")
90 << ", ";
91 ss << "#cpu_adaptations: " << number_of_cpu_adapt_changes << ", ";
92 ss << "#quality_adaptations: " << number_of_quality_adapt_changes;
aleloi440b6d92017-08-22 12:43:2393 ss << '}';
94 for (const auto& substream : substreams) {
Henrik Boströmf45ca372020-03-24 12:30:5095 if (substream.second.type ==
96 VideoSendStream::StreamStats::StreamType::kMedia) {
aleloi440b6d92017-08-22 12:43:2397 ss << " {ssrc: " << substream.first << ", ";
98 ss << substream.second.ToString();
99 ss << '}';
100 }
101 }
102 return ss.str();
103}
104
105VideoSendStream::Config::Config(const Config&) = default;
106VideoSendStream::Config::Config(Config&&) = default;
Bjorn A Mellem7a9a0922019-11-26 17:19:40107VideoSendStream::Config::Config(Transport* send_transport)
Elad Alon370f93a2019-06-11 12:57:57108 : rtp(),
109 encoder_settings(VideoEncoder::Capabilities(rtp.lntf.enabled)),
Bjorn A Mellem7a9a0922019-11-26 17:19:40110 send_transport(send_transport) {}
aleloi440b6d92017-08-22 12:43:23111
112VideoSendStream::Config& VideoSendStream::Config::operator=(Config&&) = default;
113VideoSendStream::Config::Config::~Config() = default;
114
115std::string VideoSendStream::Config::ToString() const {
Jonas Olsson0a713b62018-04-04 13:49:32116 char buf[2 * 1024];
117 rtc::SimpleStringBuilder ss(buf);
Niels Möller213618e2018-07-24 07:29:58118 ss << "{encoder_settings: { experiment_cpu_load_estimator: "
119 << (encoder_settings.experiment_cpu_load_estimator ? "on" : "off") << "}}";
aleloi440b6d92017-08-22 12:43:23120 ss << ", rtp: " << rtp.ToString();
Jiawei Ou55718122018-11-09 21:17:39121 ss << ", rtcp_report_interval_ms: " << rtcp_report_interval_ms;
Niels Möller46879152019-01-07 14:54:47122 ss << ", send_transport: " << (send_transport ? "(Transport)" : "nullptr");
aleloi440b6d92017-08-22 12:43:23123 ss << ", render_delay_ms: " << render_delay_ms;
124 ss << ", target_delay_ms: " << target_delay_ms;
125 ss << ", suspend_below_min_bitrate: "
126 << (suspend_below_min_bitrate ? "on" : "off");
127 ss << '}';
128 return ss.str();
129}
130
aleloi440b6d92017-08-22 12:43:23131} // namespace webrtc