blob: 08806ec2ec14f9d746e01172526e1195b8b24732 [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ömf45ca372020-03-24 13:30:50 +010086
87 // These booleans are redundant; this information is already exposed in
88 // |type|.
89 // TODO(hbos): Update downstream projects to use |type| instead and delete
90 // these members.
91 bool is_flexfec = false;
92 bool is_rtx = false;
aleloi440b6d92017-08-22 05:43:23 -070093 };
94
95 struct Stats {
96 Stats();
97 ~Stats();
98 std::string ToString(int64_t time_ms) const;
99 std::string encoder_implementation_name = "unknown";
100 int input_frame_rate = 0;
101 int encode_frame_rate = 0;
102 int avg_encode_time_ms = 0;
103 int encode_usage_percent = 0;
104 uint32_t frames_encoded = 0;
Henrik Boström5684af52019-04-02 15:05:21 +0200105 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
106 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200107 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
108 uint64_t total_encoded_bytes_target = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200109 uint32_t frames_dropped_by_capturer = 0;
110 uint32_t frames_dropped_by_encoder_queue = 0;
111 uint32_t frames_dropped_by_rate_limiter = 0;
Ying Wang9b881ab2020-02-07 14:29:32 +0100112 uint32_t frames_dropped_by_congestion_window = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200113 uint32_t frames_dropped_by_encoder = 0;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200114 absl::optional<uint64_t> qp_sum;
aleloi440b6d92017-08-22 05:43:23 -0700115 // Bitrate the encoder is currently configured to use due to bandwidth
116 // limitations.
117 int target_media_bitrate_bps = 0;
118 // Bitrate the encoder is actually producing.
119 int media_bitrate_bps = 0;
aleloi440b6d92017-08-22 05:43:23 -0700120 bool suspended = false;
121 bool bw_limited_resolution = false;
122 bool cpu_limited_resolution = false;
123 bool bw_limited_framerate = false;
124 bool cpu_limited_framerate = false;
Henrik Boströmce33b6a2019-05-28 17:42:38 +0200125 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
126 QualityLimitationReason quality_limitation_reason =
127 QualityLimitationReason::kNone;
128 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
129 std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms;
Evan Shrubsolecc62b162019-09-09 11:26:45 +0200130 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
131 uint32_t quality_limitation_resolution_changes = 0;
aleloi440b6d92017-08-22 05:43:23 -0700132 // Total number of times resolution as been requested to be changed due to
133 // CPU/quality adaptation.
134 int number_of_cpu_adapt_changes = 0;
135 int number_of_quality_adapt_changes = 0;
Åsa Perssonc3ed6302017-11-16 14:04:52 +0100136 bool has_entered_low_resolution = false;
aleloi440b6d92017-08-22 05:43:23 -0700137 std::map<uint32_t, StreamStats> substreams;
ilnik50864a82017-09-06 12:32:35 -0700138 webrtc::VideoContentType content_type =
139 webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100140 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -0700141 };
142
143 struct Config {
144 public:
145 Config() = delete;
146 Config(Config&&);
147 explicit Config(Transport* send_transport);
148
149 Config& operator=(Config&&);
150 Config& operator=(const Config&) = delete;
151
152 ~Config();
153
154 // Mostly used by tests. Avoid creating copies if you can.
155 Config Copy() const { return Config(*this); }
156
157 std::string ToString() const;
158
Philip Eliasson49d661a2019-06-11 11:55:47 +0000159 RtpConfig rtp;
160
Elad Alon370f93a2019-06-11 14:57:57 +0200161 VideoStreamEncoderSettings encoder_settings;
162
Jiawei Ou55718122018-11-09 13:17:39 -0800163 // Time interval between RTCP report for video
164 int rtcp_report_interval_ms = 1000;
Jiawei Ou3587b832018-01-31 22:08:26 -0800165
aleloi440b6d92017-08-22 05:43:23 -0700166 // Transport for outgoing packets.
167 Transport* send_transport = nullptr;
168
aleloi440b6d92017-08-22 05:43:23 -0700169 // Expected delay needed by the renderer, i.e. the frame will be delivered
170 // this many milliseconds, if possible, earlier than expected render time.
171 // Only valid if |local_renderer| is set.
172 int render_delay_ms = 0;
173
174 // Target delay in milliseconds. A positive value indicates this stream is
175 // used for streaming instead of a real-time call.
176 int target_delay_ms = 0;
177
178 // True if the stream should be suspended when the available bitrate fall
179 // below the minimum configured bitrate. If this variable is false, the
180 // stream may send at a rate higher than the estimated available bitrate.
181 bool suspend_below_min_bitrate = false;
182
183 // Enables periodic bandwidth probing in application-limited region.
184 bool periodic_alr_bandwidth_probing = false;
185
Benjamin Wright192eeec2018-10-17 17:27:25 -0700186 // An optional custom frame encryptor that allows the entire frame to be
187 // encrypted in whatever way the caller chooses. This is not required by
188 // default.
189 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
190
191 // Per PeerConnection cryptography options.
192 CryptoOptions crypto_options;
193
Marina Cioceae77912b2020-02-27 16:16:55 +0100194 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
195
aleloi440b6d92017-08-22 05:43:23 -0700196 private:
197 // Access to the copy constructor is private to force use of the Copy()
198 // method for those exceptional cases where we do use it.
199 Config(const Config&);
200 };
201
Seth Hampsoncc7125f2018-02-02 08:46:16 -0800202 // Updates the sending state for all simulcast layers that the video send
203 // stream owns. This can mean updating the activity one or for multiple
204 // layers. The ordering of active layers is the order in which the
205 // rtp modules are stored in the VideoSendStream.
206 // Note: This starts stream activity if it is inactive and one of the layers
207 // is active. This stops stream activity if it is active and all layers are
208 // inactive.
209 virtual void UpdateActiveSimulcastLayers(
210 const std::vector<bool> active_layers) = 0;
211
aleloi440b6d92017-08-22 05:43:23 -0700212 // Starts stream activity.
213 // When a stream is active, it can receive, process and deliver packets.
214 virtual void Start() = 0;
215 // Stops stream activity.
216 // When a stream is stopped, it can't receive, process or deliver packets.
217 virtual void Stop() = 0;
218
aleloi440b6d92017-08-22 05:43:23 -0700219 virtual void SetSource(
220 rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
221 const DegradationPreference& degradation_preference) = 0;
222
223 // Set which streams to send. Must have at least as many SSRCs as configured
224 // in the config. Encoder settings are passed on to the encoder instance along
225 // with the VideoStream settings.
226 virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
227
228 virtual Stats GetStats() = 0;
229
aleloi440b6d92017-08-22 05:43:23 -0700230 protected:
231 virtual ~VideoSendStream() {}
232};
233
234} // namespace webrtc
235
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200236#endif // CALL_VIDEO_SEND_STREAM_H_