blob: 715d5d73e7bc2f9551893b193b5de6e3a06799fa [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"
Henrik Boströmf4a99912020-06-11 12:07:14 +020021#include "api/adaptation/resource.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/call/transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/crypto/crypto_options.h"
Marina Cioceae77912b2020-02-27 16:16:55 +010024#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/rtp_parameters.h"
Henrik Boströmf4a99912020-06-11 12:07:14 +020026#include "api/scoped_refptr.h"
Yves Gerey988cc082018-10-23 12:03:01 +020027#include "api/video/video_content_type.h"
Niels Möller88be9722018-10-10 10:58:52 +020028#include "api/video/video_frame.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020029#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020030#include "api/video/video_source_interface.h"
Niels Möller213618e2018-07-24 09:29:58 +020031#include "api/video/video_stream_encoder_settings.h"
Niels Möller0a8f4352018-05-18 11:37:23 +020032#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "call/rtp_config.h"
Henrik Boströmce33b6a2019-05-28 17:42:38 +020034#include "common_video/include/quality_limitation_reason.h"
Henrik Boström87e3f9d2019-05-27 10:44:24 +020035#include "modules/rtp_rtcp/include/report_block_data.h"
Niels Möller53382cb2018-11-27 14:05:08 +010036#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010037#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
aleloi440b6d92017-08-22 05:43:23 -070038
39namespace webrtc {
40
Benjamin Wright192eeec2018-10-17 17:27:25 -070041class FrameEncryptorInterface;
42
aleloi440b6d92017-08-22 05:43:23 -070043class VideoSendStream {
44 public:
Henrik Boströmf45ca372020-03-24 13:30:50 +010045 // Multiple StreamStats objects are present if simulcast is used (multiple
46 // kMedia streams) or if RTX or FlexFEC is negotiated. Multiple SVC layers, on
47 // the other hand, does not cause additional StreamStats.
aleloi440b6d92017-08-22 05:43:23 -070048 struct StreamStats {
Henrik Boströmf45ca372020-03-24 13:30:50 +010049 enum class StreamType {
50 // A media stream is an RTP stream for audio or video. Retransmissions and
51 // FEC is either sent over the same SSRC or negotiated to be sent over
52 // separate SSRCs, in which case separate StreamStats objects exist with
53 // references to this media stream's SSRC.
54 kMedia,
55 // RTX streams are streams dedicated to retransmissions. They have a
56 // dependency on a single kMedia stream: |referenced_media_ssrc|.
57 kRtx,
58 // FlexFEC streams are streams dedicated to FlexFEC. They have a
59 // dependency on a single kMedia stream: |referenced_media_ssrc|.
60 kFlexfec,
61 };
62
aleloi440b6d92017-08-22 05:43:23 -070063 StreamStats();
64 ~StreamStats();
65
66 std::string ToString() const;
67
Henrik Boströmf45ca372020-03-24 13:30:50 +010068 StreamType type = StreamType::kMedia;
69 // If |type| is kRtx or kFlexfec this value is present. The referenced SSRC
70 // is the kMedia stream that this stream is performing retransmissions or
71 // FEC for. If |type| is kMedia, this value is null.
72 absl::optional<uint32_t> referenced_media_ssrc;
aleloi440b6d92017-08-22 05:43:23 -070073 FrameCounts frame_counts;
aleloi440b6d92017-08-22 05:43:23 -070074 int width = 0;
75 int height = 0;
76 // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
77 int total_bitrate_bps = 0;
78 int retransmit_bitrate_bps = 0;
79 int avg_delay_ms = 0;
80 int max_delay_ms = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +020081 uint64_t total_packet_send_delay_ms = 0;
aleloi440b6d92017-08-22 05:43:23 -070082 StreamDataCounters rtp_stats;
83 RtcpPacketTypeCounter rtcp_packet_type_counts;
84 RtcpStatistics rtcp_stats;
Henrik Boström87e3f9d2019-05-27 10:44:24 +020085 // A snapshot of the most recent Report Block with additional data of
86 // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats.
87 absl::optional<ReportBlockData> report_block_data;
Henrik Boströma0ff50c2020-05-05 15:54:46 +020088 double encode_frame_rate = 0.0;
89 int frames_encoded = 0;
90 absl::optional<uint64_t> qp_sum;
91 uint64_t total_encode_time_ms = 0;
92 uint64_t total_encoded_bytes_target = 0;
93 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -070094 };
95
96 struct Stats {
97 Stats();
98 ~Stats();
99 std::string ToString(int64_t time_ms) const;
100 std::string encoder_implementation_name = "unknown";
101 int input_frame_rate = 0;
102 int encode_frame_rate = 0;
103 int avg_encode_time_ms = 0;
104 int encode_usage_percent = 0;
105 uint32_t frames_encoded = 0;
Henrik Boström5684af52019-04-02 15:05:21 +0200106 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
107 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200108 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
109 uint64_t total_encoded_bytes_target = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200110 uint32_t frames_dropped_by_capturer = 0;
111 uint32_t frames_dropped_by_encoder_queue = 0;
112 uint32_t frames_dropped_by_rate_limiter = 0;
Ying Wang9b881ab2020-02-07 14:29:32 +0100113 uint32_t frames_dropped_by_congestion_window = 0;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200114 uint32_t frames_dropped_by_encoder = 0;
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;
Henrik Boströma0ff50c2020-05-05 15:54:46 +0200140 uint32_t frames_sent = 0;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100141 uint32_t huge_frames_sent = 0;
aleloi440b6d92017-08-22 05:43:23 -0700142 };
143
144 struct Config {
145 public:
146 Config() = delete;
147 Config(Config&&);
148 explicit Config(Transport* send_transport);
149
150 Config& operator=(Config&&);
151 Config& operator=(const Config&) = delete;
152
153 ~Config();
154
155 // Mostly used by tests. Avoid creating copies if you can.
156 Config Copy() const { return Config(*this); }
157
158 std::string ToString() const;
159
Philip Eliasson49d661a2019-06-11 11:55:47 +0000160 RtpConfig rtp;
161
Elad Alon370f93a2019-06-11 14:57:57 +0200162 VideoStreamEncoderSettings encoder_settings;
163
Jiawei Ou55718122018-11-09 13:17:39 -0800164 // Time interval between RTCP report for video
165 int rtcp_report_interval_ms = 1000;
Jiawei Ou3587b832018-01-31 22:08:26 -0800166
aleloi440b6d92017-08-22 05:43:23 -0700167 // Transport for outgoing packets.
168 Transport* send_transport = nullptr;
169
aleloi440b6d92017-08-22 05:43:23 -0700170 // Expected delay needed by the renderer, i.e. the frame will be delivered
171 // this many milliseconds, if possible, earlier than expected render time.
172 // Only valid if |local_renderer| is set.
173 int render_delay_ms = 0;
174
175 // Target delay in milliseconds. A positive value indicates this stream is
176 // used for streaming instead of a real-time call.
177 int target_delay_ms = 0;
178
179 // True if the stream should be suspended when the available bitrate fall
180 // below the minimum configured bitrate. If this variable is false, the
181 // stream may send at a rate higher than the estimated available bitrate.
182 bool suspend_below_min_bitrate = false;
183
184 // Enables periodic bandwidth probing in application-limited region.
185 bool periodic_alr_bandwidth_probing = false;
186
Benjamin Wright192eeec2018-10-17 17:27:25 -0700187 // An optional custom frame encryptor that allows the entire frame to be
188 // encrypted in whatever way the caller chooses. This is not required by
189 // default.
190 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
191
192 // Per PeerConnection cryptography options.
193 CryptoOptions crypto_options;
194
Marina Cioceae77912b2020-02-27 16:16:55 +0100195 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
196
aleloi440b6d92017-08-22 05:43:23 -0700197 private:
198 // Access to the copy constructor is private to force use of the Copy()
199 // method for those exceptional cases where we do use it.
200 Config(const Config&);
201 };
202
Seth Hampsoncc7125f2018-02-02 08:46:16 -0800203 // Updates the sending state for all simulcast layers that the video send
204 // stream owns. This can mean updating the activity one or for multiple
205 // layers. The ordering of active layers is the order in which the
206 // rtp modules are stored in the VideoSendStream.
207 // Note: This starts stream activity if it is inactive and one of the layers
208 // is active. This stops stream activity if it is active and all layers are
209 // inactive.
210 virtual void UpdateActiveSimulcastLayers(
211 const std::vector<bool> active_layers) = 0;
212
aleloi440b6d92017-08-22 05:43:23 -0700213 // Starts stream activity.
214 // When a stream is active, it can receive, process and deliver packets.
215 virtual void Start() = 0;
216 // Stops stream activity.
217 // When a stream is stopped, it can't receive, process or deliver packets.
218 virtual void Stop() = 0;
219
Henrik Boströmf4a99912020-06-11 12:07:14 +0200220 // If the resource is overusing, the VideoSendStream will try to reduce
221 // resolution or frame rate until no resource is overusing.
222 // TODO(https://crbug.com/webrtc/11565): When the ResourceAdaptationProcessor
223 // is moved to Call this method could be deleted altogether in favor of
224 // Call-level APIs only.
225 virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
226 virtual std::vector<rtc::scoped_refptr<Resource>>
227 GetAdaptationResources() = 0;
228
aleloi440b6d92017-08-22 05:43:23 -0700229 virtual void SetSource(
230 rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
231 const DegradationPreference& degradation_preference) = 0;
232
233 // Set which streams to send. Must have at least as many SSRCs as configured
234 // in the config. Encoder settings are passed on to the encoder instance along
235 // with the VideoStream settings.
236 virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
237
238 virtual Stats GetStats() = 0;
239
aleloi440b6d92017-08-22 05:43:23 -0700240 protected:
241 virtual ~VideoSendStream() {}
242};
243
244} // namespace webrtc
245
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200246#endif // CALL_VIDEO_SEND_STREAM_H_