blob: 241d44a2303a10c7a13557080665ee677835c4d0 [file] [log] [blame]
aleloi440b6d92017-08-22 05:43:23 -07001/*
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 06:47:31 +020011#include "call/video_send_stream.h"
Yves Gerey988cc082018-10-23 12:03:01 +020012
13#include <utility>
14
Steve Anton10542f22019-01-11 09:11:00 -080015#include "api/crypto/frame_encryptor_interface.h"
Jonas Olsson0a713b62018-04-04 15:49:32 +020016#include "rtc_base/strings/string_builder.h"
Byoungchan Leeefe46b62021-11-10 11:23:56 +090017#include "rtc_base/strings/string_format.h"
aleloi440b6d92017-08-22 05:43:23 -070018
19namespace webrtc {
20
Henrik Boströmf45ca372020-03-24 13:30:50 +010021namespace {
22
23const 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 }
Karl Wibergc95b9392020-11-08 00:49:37 +010032 RTC_CHECK_NOTREACHED();
Henrik Boströmf45ca372020-03-24 13:30:50 +010033}
34
35} // namespace
36
aleloi440b6d92017-08-22 05:43:23 -070037VideoSendStream::StreamStats::StreamStats() = default;
38VideoSendStream::StreamStats::~StreamStats() = default;
39
40std::string VideoSendStream::StreamStats::ToString() const {
Jonas Olsson0a713b62018-04-04 15:49:32 +020041 char buf[1024];
42 rtc::SimpleStringBuilder ss(buf);
Henrik Boströmf45ca372020-03-24 13:30:50 +010043 ss << "type: " << StreamTypeToString(type);
44 if (referenced_media_ssrc.has_value())
45 ss << " (for: " << referenced_media_ssrc.value() << ")";
46 ss << ", ";
aleloi440b6d92017-08-22 05:43:23 -070047 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 << ", ";
Danil Chapovalovea7474e2021-05-18 12:48:12 +020055 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 }
aleloi440b6d92017-08-22 05:43:23 -070062 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
68VideoSendStream::Stats::Stats() = default;
69VideoSendStream::Stats::~Stats() = default;
70
71std::string VideoSendStream::Stats::ToString(int64_t time_ms) const {
Rasmus Brandtd42a4492019-04-16 16:51:24 +020072 char buf[2048];
Jonas Olsson0a713b62018-04-04 15:49:32 +020073 rtc::SimpleStringBuilder ss(buf);
aleloi440b6d92017-08-22 05:43:23 -070074 ss << "VideoSendStream stats: " << time_ms << ", {";
Byoungchan Leeefe46b62021-11-10 11:23:56 +090075 ss << "input_fps: " << rtc::StringFormat("%.1f", input_frame_rate) << ", ";
aleloi440b6d92017-08-22 05:43:23 -070076 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 << ", ";
aleloi440b6d92017-08-22 05:43:23 -070081 ss << "suspended: " << (suspended ? "true" : "false") << ", ";
Rasmus Brandtd42a4492019-04-16 16:51:24 +020082 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;
aleloi440b6d92017-08-22 05:43:23 -070091 ss << '}';
92 for (const auto& substream : substreams) {
Henrik Boströmf45ca372020-03-24 13:30:50 +010093 if (substream.second.type ==
94 VideoSendStream::StreamStats::StreamType::kMedia) {
aleloi440b6d92017-08-22 05:43:23 -070095 ss << " {ssrc: " << substream.first << ", ";
96 ss << substream.second.ToString();
97 ss << '}';
98 }
99 }
100 return ss.str();
101}
102
103VideoSendStream::Config::Config(const Config&) = default;
104VideoSendStream::Config::Config(Config&&) = default;
Bjorn A Mellem7a9a0922019-11-26 09:19:40 -0800105VideoSendStream::Config::Config(Transport* send_transport)
Elad Alon370f93a2019-06-11 14:57:57 +0200106 : rtp(),
107 encoder_settings(VideoEncoder::Capabilities(rtp.lntf.enabled)),
Bjorn A Mellem7a9a0922019-11-26 09:19:40 -0800108 send_transport(send_transport) {}
aleloi440b6d92017-08-22 05:43:23 -0700109
110VideoSendStream::Config& VideoSendStream::Config::operator=(Config&&) = default;
111VideoSendStream::Config::Config::~Config() = default;
112
113std::string VideoSendStream::Config::ToString() const {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200114 char buf[2 * 1024];
115 rtc::SimpleStringBuilder ss(buf);
Niels Möller213618e2018-07-24 09:29:58 +0200116 ss << "{encoder_settings: { experiment_cpu_load_estimator: "
117 << (encoder_settings.experiment_cpu_load_estimator ? "on" : "off") << "}}";
aleloi440b6d92017-08-22 05:43:23 -0700118 ss << ", rtp: " << rtp.ToString();
Jiawei Ou55718122018-11-09 13:17:39 -0800119 ss << ", rtcp_report_interval_ms: " << rtcp_report_interval_ms;
Niels Möller46879152019-01-07 15:54:47 +0100120 ss << ", send_transport: " << (send_transport ? "(Transport)" : "nullptr");
aleloi440b6d92017-08-22 05:43:23 -0700121 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
aleloi440b6d92017-08-22 05:43:23 -0700129} // namespace webrtc