blob: 392c955f4778e3dc46121d51eb317cfc571e8458 [file] [log] [blame]
aleloi440b6d92017-08-22 05:43:23 -07001/*
2 * Copyright (c) 2013 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#ifndef CALL_VIDEO_SEND_STREAM_H_
12#define CALL_VIDEO_SEND_STREAM_H_
aleloi440b6d92017-08-22 05:43:23 -070013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
aleloi440b6d92017-08-22 05:43:23 -070016#include <map>
17#include <string>
aleloi440b6d92017-08-22 05:43:23 -070018#include <vector>
19
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/call/transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/crypto/crypto_options.h"
Marina Cioceae77912b2020-02-27 16:16:55 +010023#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/rtp_parameters.h"
Yves Gerey988cc082018-10-23 12:03:01 +020025#include "api/video/video_content_type.h"
Niels Möller88be9722018-10-10 10:58:52 +020026#include "api/video/video_frame.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020027#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020028#include "api/video/video_source_interface.h"
Niels Möller213618e2018-07-24 09:29:58 +020029#include "api/video/video_stream_encoder_settings.h"
Niels Möller0a8f4352018-05-18 11:37:23 +020030#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "call/rtp_config.h"
Henrik Boströmce33b6a2019-05-28 17:42:38 +020032#include "common_video/include/quality_limitation_reason.h"
Henrik Boström87e3f9d2019-05-27 10:44:24 +020033#include "modules/rtp_rtcp/include/report_block_data.h"
Niels Möller53382cb2018-11-27 14:05:08 +010034#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010035#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070036
37namespace webrtc {
38
Benjamin Wright192eeec2018-10-17 17:27:25 -070039class FrameEncryptorInterface;
40
aleloi440b6d92017-08-22 05:43:23 -070041class VideoSendStream {
42 public:
Henrik Boströmf45ca372020-03-24 13:30:50 +010043 // Multiple StreamStats objects are present if simulcast is used (multiple
44 // kMedia streams) or if RTX or FlexFEC is negotiated. Multiple SVC layers, on
45 // the other hand, does not cause additional StreamStats.
aleloi440b6d92017-08-22 05:43:23 -070046 struct StreamStats {
Henrik Boströmf45ca372020-03-24 13:30:50 +010047 enum class StreamType {
48 // A media stream is an RTP stream for audio or video. Retransmissions and
49 // FEC is either sent over the same SSRC or negotiated to be sent over
50 // separate SSRCs, in which case separate StreamStats objects exist with
51 // references to this media stream's SSRC.
52 kMedia,
53 // RTX streams are streams dedicated to retransmissions. They have a
54 // dependency on a single kMedia stream: |referenced_media_ssrc|.
55 kRtx,
56 // FlexFEC streams are streams dedicated to FlexFEC. They have a
57 // dependency on a single kMedia stream: |referenced_media_ssrc|.
58 kFlexfec,
59 };
60
aleloi440b6d92017-08-22 05:43:23 -070061 StreamStats();
62 ~StreamStats();
63
64 std::string ToString() const;
65
Henrik Boströmf45ca372020-03-24 13:30:50 +010066 StreamType type = StreamType::kMedia;
67 // If |type| is kRtx or kFlexfec this value is present. The referenced SSRC
68 // is the kMedia stream that this stream is performing retransmissions or
69 // FEC for. If |type| is kMedia, this value is null.
70 absl::optional<uint32_t> referenced_media_ssrc;
aleloi440b6d92017-08-22 05:43:23 -070071 FrameCounts frame_counts;
aleloi440b6d92017-08-22 05:43:23 -070072 int width = 0;
73 int height = 0;
74 // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
75 int total_bitrate_bps = 0;
76 int retransmit_bitrate_bps = 0;
77 int avg_delay_ms = 0;
78 int max_delay_ms = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +020079 uint64_t total_packet_send_delay_ms = 0;
aleloi440b6d92017-08-22 05:43:23 -070080 StreamDataCounters rtp_stats;
81 RtcpPacketTypeCounter rtcp_packet_type_counts;
82 RtcpStatistics rtcp_stats;
Henrik Boström87e3f9d2019-05-27 10:44:24 +020083 // A snapshot of the most recent Report Block with additional data of
84 // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats.
85 absl::optional<ReportBlockData> report_block_data;
Henrik Boströma0ff50c2020-05-05 15:54:46 +020086 double encode_frame_rate = 0.0;
87 int frames_encoded = 0;
88 absl::optional<uint64_t> qp_sum;
89 uint64_t total_encode_time_ms = 0;
90 uint64_t total_encoded_bytes_target = 0;
91 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -070092 };
93
94 struct Stats {
95 Stats();
96 ~Stats();
97 std::string ToString(int64_t time_ms) const;
98 std::string encoder_implementation_name = "unknown";
99 int input_frame_rate = 0;
100 int encode_frame_rate = 0;
101 int avg_encode_time_ms = 0;
102 int encode_usage_percent = 0;
103 uint32_t frames_encoded = 0;
Henrik Boström5684af52019-04-02 15:05:21 +0200104 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
105 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200106 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
107 uint64_t total_encoded_bytes_target = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200108 uint32_t frames_dropped_by_capturer = 0;
109 uint32_t frames_dropped_by_encoder_queue = 0;
110 uint32_t frames_dropped_by_rate_limiter = 0;
Ying Wang9b881ab2020-02-07 14:29:32 +0100111 uint32_t frames_dropped_by_congestion_window = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200112 uint32_t frames_dropped_by_encoder = 0;
aleloi440b6d92017-08-22 05:43:23 -0700113 // Bitrate the encoder is currently configured to use due to bandwidth
114 // limitations.
115 int target_media_bitrate_bps = 0;
116 // Bitrate the encoder is actually producing.
117 int media_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -0700118 bool suspended = false;
119 bool bw_limited_resolution = false;
120 bool cpu_limited_resolution = false;
121 bool bw_limited_framerate = false;
122 bool cpu_limited_framerate = false;
Henrik Boströmce33b6a2019-05-28 17:42:38 +0200123 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
124 QualityLimitationReason quality_limitation_reason =
125 QualityLimitationReason::kNone;
126 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
127 std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms;
Evan Shrubsolecc62b162019-09-09 11:26:45 +0200128 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
129 uint32_t quality_limitation_resolution_changes = 0;
aleloi440b6d92017-08-22 05:43:23 -0700130 // Total number of times resolution as been requested to be changed due to
131 // CPU/quality adaptation.
132 int number_of_cpu_adapt_changes = 0;
133 int number_of_quality_adapt_changes = 0;
Åsa Perssonc3ed6302017-11-16 14:04:52 +0100134 bool has_entered_low_resolution = false;
aleloi440b6d92017-08-22 05:43:23 -0700135 std::map<uint32_t, StreamStats> substreams;
ilnik50864a82017-09-06 12:32:35 -0700136 webrtc::VideoContentType content_type =
137 webrtc::VideoContentType::UNSPECIFIED;
Henrik Boströma0ff50c2020-05-05 15:54:46 +0200138 uint32_t frames_sent = 0;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100139 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -0700140 };
141
142 struct Config {
143 public:
144 Config() = delete;
145 Config(Config&&);
146 explicit Config(Transport* send_transport);
147
148 Config& operator=(Config&&);
149 Config& operator=(const Config&) = delete;
150
151 ~Config();
152
153 // Mostly used by tests. Avoid creating copies if you can.
154 Config Copy() const { return Config(*this); }
155
156 std::string ToString() const;
157
Philip Eliasson49d661a2019-06-11 11:55:47 +0000158 RtpConfig rtp;
159
Elad Alon370f93a2019-06-11 14:57:57 +0200160 VideoStreamEncoderSettings encoder_settings;
161
Jiawei Ou55718122018-11-09 13:17:39 -0800162 // Time interval between RTCP report for video
163 int rtcp_report_interval_ms = 1000;
Jiawei Ou3587b832018-01-31 22:08:26 -0800164
aleloi440b6d92017-08-22 05:43:23 -0700165 // Transport for outgoing packets.
166 Transport* send_transport = nullptr;
167
aleloi440b6d92017-08-22 05:43:23 -0700168 // Expected delay needed by the renderer, i.e. the frame will be delivered
169 // this many milliseconds, if possible, earlier than expected render time.
170 // Only valid if |local_renderer| is set.
171 int render_delay_ms = 0;
172
173 // Target delay in milliseconds. A positive value indicates this stream is
174 // used for streaming instead of a real-time call.
175 int target_delay_ms = 0;
176
177 // True if the stream should be suspended when the available bitrate fall
178 // below the minimum configured bitrate. If this variable is false, the
179 // stream may send at a rate higher than the estimated available bitrate.
180 bool suspend_below_min_bitrate = false;
181
182 // Enables periodic bandwidth probing in application-limited region.
183 bool periodic_alr_bandwidth_probing = false;
184
Benjamin Wright192eeec2018-10-17 17:27:25 -0700185 // An optional custom frame encryptor that allows the entire frame to be
186 // encrypted in whatever way the caller chooses. This is not required by
187 // default.
188 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
189
190 // Per PeerConnection cryptography options.
191 CryptoOptions crypto_options;
192
Marina Cioceae77912b2020-02-27 16:16:55 +0100193 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
194
aleloi440b6d92017-08-22 05:43:23 -0700195 private:
196 // Access to the copy constructor is private to force use of the Copy()
197 // method for those exceptional cases where we do use it.
198 Config(const Config&);
199 };
200
Seth Hampsoncc7125f2018-02-02 08:46:16 -0800201 // Updates the sending state for all simulcast layers that the video send
202 // stream owns. This can mean updating the activity one or for multiple
203 // layers. The ordering of active layers is the order in which the
204 // rtp modules are stored in the VideoSendStream.
205 // Note: This starts stream activity if it is inactive and one of the layers
206 // is active. This stops stream activity if it is active and all layers are
207 // inactive.
208 virtual void UpdateActiveSimulcastLayers(
209 const std::vector<bool> active_layers) = 0;
210
aleloi440b6d92017-08-22 05:43:23 -0700211 // Starts stream activity.
212 // When a stream is active, it can receive, process and deliver packets.
213 virtual void Start() = 0;
214 // Stops stream activity.
215 // When a stream is stopped, it can't receive, process or deliver packets.
216 virtual void Stop() = 0;
217
aleloi440b6d92017-08-22 05:43:23 -0700218 virtual void SetSource(
219 rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
220 const DegradationPreference& degradation_preference) = 0;
221
222 // Set which streams to send. Must have at least as many SSRCs as configured
223 // in the config. Encoder settings are passed on to the encoder instance along
224 // with the VideoStream settings.
225 virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
226
227 virtual Stats GetStats() = 0;
228
aleloi440b6d92017-08-22 05:43:23 -0700229 protected:
230 virtual ~VideoSendStream() {}
231};
232
233} // namespace webrtc
234
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200235#endif // CALL_VIDEO_SEND_STREAM_H_