aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_VIDEO_SEND_STREAM_H_ |
| 12 | #define CALL_VIDEO_SEND_STREAM_H_ |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 16 | #include <map> |
| 17 | #include <string> |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Henrik Boström | f4a9991 | 2020-06-11 12:07:14 +0200 | [diff] [blame] | 21 | #include "api/adaptation/resource.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/crypto/crypto_options.h" |
Marina Ciocea | e77912b | 2020-02-27 16:16:55 +0100 | [diff] [blame] | 24 | #include "api/frame_transformer_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "api/rtp_parameters.h" |
Henrik Boström | f4a9991 | 2020-06-11 12:07:14 +0200 | [diff] [blame] | 26 | #include "api/scoped_refptr.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 27 | #include "api/video/video_content_type.h" |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 28 | #include "api/video/video_frame.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 29 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 30 | #include "api/video/video_source_interface.h" |
Niels Möller | 213618e | 2018-07-24 09:29:58 +0200 | [diff] [blame] | 31 | #include "api/video/video_stream_encoder_settings.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 32 | #include "api/video_codecs/video_encoder_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "call/rtp_config.h" |
Niels Möller | a8327d4 | 2020-08-25 10:28:50 +0200 | [diff] [blame] | 34 | #include "common_video/frame_counts.h" |
Henrik Boström | ce33b6a | 2019-05-28 17:42:38 +0200 | [diff] [blame] | 35 | #include "common_video/include/quality_limitation_reason.h" |
Henrik Boström | 87e3f9d | 2019-05-27 10:44:24 +0200 | [diff] [blame] | 36 | #include "modules/rtp_rtcp/include/report_block_data.h" |
Niels Möller | 53382cb | 2018-11-27 14:05:08 +0100 | [diff] [blame] | 37 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 38 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 39 | |
| 40 | namespace webrtc { |
| 41 | |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 42 | class FrameEncryptorInterface; |
| 43 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 44 | class VideoSendStream { |
| 45 | public: |
Henrik Boström | f45ca37 | 2020-03-24 13:30:50 +0100 | [diff] [blame] | 46 | // Multiple StreamStats objects are present if simulcast is used (multiple |
| 47 | // kMedia streams) or if RTX or FlexFEC is negotiated. Multiple SVC layers, on |
| 48 | // the other hand, does not cause additional StreamStats. |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 49 | struct StreamStats { |
Henrik Boström | f45ca37 | 2020-03-24 13:30:50 +0100 | [diff] [blame] | 50 | enum class StreamType { |
| 51 | // A media stream is an RTP stream for audio or video. Retransmissions and |
| 52 | // FEC is either sent over the same SSRC or negotiated to be sent over |
| 53 | // separate SSRCs, in which case separate StreamStats objects exist with |
| 54 | // references to this media stream's SSRC. |
| 55 | kMedia, |
| 56 | // RTX streams are streams dedicated to retransmissions. They have a |
| 57 | // dependency on a single kMedia stream: |referenced_media_ssrc|. |
| 58 | kRtx, |
| 59 | // FlexFEC streams are streams dedicated to FlexFEC. They have a |
| 60 | // dependency on a single kMedia stream: |referenced_media_ssrc|. |
| 61 | kFlexfec, |
| 62 | }; |
| 63 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 64 | StreamStats(); |
| 65 | ~StreamStats(); |
| 66 | |
| 67 | std::string ToString() const; |
| 68 | |
Henrik Boström | f45ca37 | 2020-03-24 13:30:50 +0100 | [diff] [blame] | 69 | StreamType type = StreamType::kMedia; |
| 70 | // If |type| is kRtx or kFlexfec this value is present. The referenced SSRC |
| 71 | // is the kMedia stream that this stream is performing retransmissions or |
| 72 | // FEC for. If |type| is kMedia, this value is null. |
| 73 | absl::optional<uint32_t> referenced_media_ssrc; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 74 | FrameCounts frame_counts; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 75 | int width = 0; |
| 76 | int height = 0; |
| 77 | // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer. |
| 78 | int total_bitrate_bps = 0; |
| 79 | int retransmit_bitrate_bps = 0; |
| 80 | int avg_delay_ms = 0; |
| 81 | int max_delay_ms = 0; |
Henrik Boström | 9fe1834 | 2019-05-16 18:38:20 +0200 | [diff] [blame] | 82 | uint64_t total_packet_send_delay_ms = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 83 | StreamDataCounters rtp_stats; |
| 84 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 85 | RtcpStatistics rtcp_stats; |
Henrik Boström | 87e3f9d | 2019-05-27 10:44:24 +0200 | [diff] [blame] | 86 | // A snapshot of the most recent Report Block with additional data of |
| 87 | // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats. |
| 88 | absl::optional<ReportBlockData> report_block_data; |
Henrik Boström | a0ff50c | 2020-05-05 15:54:46 +0200 | [diff] [blame] | 89 | double encode_frame_rate = 0.0; |
| 90 | int frames_encoded = 0; |
| 91 | absl::optional<uint64_t> qp_sum; |
| 92 | uint64_t total_encode_time_ms = 0; |
| 93 | uint64_t total_encoded_bytes_target = 0; |
| 94 | uint32_t huge_frames_sent = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | struct Stats { |
| 98 | Stats(); |
| 99 | ~Stats(); |
| 100 | std::string ToString(int64_t time_ms) const; |
| 101 | std::string encoder_implementation_name = "unknown"; |
| 102 | int input_frame_rate = 0; |
| 103 | int encode_frame_rate = 0; |
| 104 | int avg_encode_time_ms = 0; |
| 105 | int encode_usage_percent = 0; |
| 106 | uint32_t frames_encoded = 0; |
Henrik Boström | 5684af5 | 2019-04-02 15:05:21 +0200 | [diff] [blame] | 107 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime |
| 108 | uint64_t total_encode_time_ms = 0; |
Henrik Boström | 23aff9b | 2019-05-20 15:15:38 +0200 | [diff] [blame] | 109 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget |
| 110 | uint64_t total_encoded_bytes_target = 0; |
Di Wu | 668dbf6 | 2021-02-27 00:29:15 -0800 | [diff] [blame^] | 111 | uint32_t frames = 0; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 112 | uint32_t frames_dropped_by_capturer = 0; |
| 113 | uint32_t frames_dropped_by_encoder_queue = 0; |
| 114 | uint32_t frames_dropped_by_rate_limiter = 0; |
Ying Wang | 9b881ab | 2020-02-07 14:29:32 +0100 | [diff] [blame] | 115 | uint32_t frames_dropped_by_congestion_window = 0; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 116 | uint32_t frames_dropped_by_encoder = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 117 | // Bitrate the encoder is currently configured to use due to bandwidth |
| 118 | // limitations. |
| 119 | int target_media_bitrate_bps = 0; |
| 120 | // Bitrate the encoder is actually producing. |
| 121 | int media_bitrate_bps = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 122 | bool suspended = false; |
| 123 | bool bw_limited_resolution = false; |
| 124 | bool cpu_limited_resolution = false; |
| 125 | bool bw_limited_framerate = false; |
| 126 | bool cpu_limited_framerate = false; |
Henrik Boström | ce33b6a | 2019-05-28 17:42:38 +0200 | [diff] [blame] | 127 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason |
| 128 | QualityLimitationReason quality_limitation_reason = |
| 129 | QualityLimitationReason::kNone; |
| 130 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations |
| 131 | std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms; |
Evan Shrubsole | cc62b16 | 2019-09-09 11:26:45 +0200 | [diff] [blame] | 132 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges |
| 133 | uint32_t quality_limitation_resolution_changes = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 134 | // Total number of times resolution as been requested to be changed due to |
| 135 | // CPU/quality adaptation. |
| 136 | int number_of_cpu_adapt_changes = 0; |
| 137 | int number_of_quality_adapt_changes = 0; |
Åsa Persson | c3ed630 | 2017-11-16 14:04:52 +0100 | [diff] [blame] | 138 | bool has_entered_low_resolution = false; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 139 | std::map<uint32_t, StreamStats> substreams; |
ilnik | 50864a8 | 2017-09-06 12:32:35 -0700 | [diff] [blame] | 140 | webrtc::VideoContentType content_type = |
| 141 | webrtc::VideoContentType::UNSPECIFIED; |
Henrik Boström | a0ff50c | 2020-05-05 15:54:46 +0200 | [diff] [blame] | 142 | uint32_t frames_sent = 0; |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 143 | uint32_t huge_frames_sent = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | struct Config { |
| 147 | public: |
| 148 | Config() = delete; |
| 149 | Config(Config&&); |
| 150 | explicit Config(Transport* send_transport); |
| 151 | |
| 152 | Config& operator=(Config&&); |
| 153 | Config& operator=(const Config&) = delete; |
| 154 | |
| 155 | ~Config(); |
| 156 | |
| 157 | // Mostly used by tests. Avoid creating copies if you can. |
| 158 | Config Copy() const { return Config(*this); } |
| 159 | |
| 160 | std::string ToString() const; |
| 161 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 162 | RtpConfig rtp; |
| 163 | |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 164 | VideoStreamEncoderSettings encoder_settings; |
| 165 | |
Jiawei Ou | 5571812 | 2018-11-09 13:17:39 -0800 | [diff] [blame] | 166 | // Time interval between RTCP report for video |
| 167 | int rtcp_report_interval_ms = 1000; |
Jiawei Ou | 3587b83 | 2018-01-31 22:08:26 -0800 | [diff] [blame] | 168 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 169 | // Transport for outgoing packets. |
| 170 | Transport* send_transport = nullptr; |
| 171 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 172 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 173 | // this many milliseconds, if possible, earlier than expected render time. |
| 174 | // Only valid if |local_renderer| is set. |
| 175 | int render_delay_ms = 0; |
| 176 | |
| 177 | // Target delay in milliseconds. A positive value indicates this stream is |
| 178 | // used for streaming instead of a real-time call. |
| 179 | int target_delay_ms = 0; |
| 180 | |
| 181 | // True if the stream should be suspended when the available bitrate fall |
| 182 | // below the minimum configured bitrate. If this variable is false, the |
| 183 | // stream may send at a rate higher than the estimated available bitrate. |
| 184 | bool suspend_below_min_bitrate = false; |
| 185 | |
| 186 | // Enables periodic bandwidth probing in application-limited region. |
| 187 | bool periodic_alr_bandwidth_probing = false; |
| 188 | |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 189 | // An optional custom frame encryptor that allows the entire frame to be |
| 190 | // encrypted in whatever way the caller chooses. This is not required by |
| 191 | // default. |
| 192 | rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor; |
| 193 | |
| 194 | // Per PeerConnection cryptography options. |
| 195 | CryptoOptions crypto_options; |
| 196 | |
Marina Ciocea | e77912b | 2020-02-27 16:16:55 +0100 | [diff] [blame] | 197 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer; |
| 198 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | // Access to the copy constructor is private to force use of the Copy() |
| 201 | // method for those exceptional cases where we do use it. |
| 202 | Config(const Config&); |
| 203 | }; |
| 204 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 205 | // Updates the sending state for all simulcast layers that the video send |
| 206 | // stream owns. This can mean updating the activity one or for multiple |
| 207 | // layers. The ordering of active layers is the order in which the |
| 208 | // rtp modules are stored in the VideoSendStream. |
| 209 | // Note: This starts stream activity if it is inactive and one of the layers |
| 210 | // is active. This stops stream activity if it is active and all layers are |
| 211 | // inactive. |
| 212 | virtual void UpdateActiveSimulcastLayers( |
| 213 | const std::vector<bool> active_layers) = 0; |
| 214 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 215 | // Starts stream activity. |
| 216 | // When a stream is active, it can receive, process and deliver packets. |
| 217 | virtual void Start() = 0; |
| 218 | // Stops stream activity. |
| 219 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 220 | virtual void Stop() = 0; |
| 221 | |
Henrik Boström | f4a9991 | 2020-06-11 12:07:14 +0200 | [diff] [blame] | 222 | // If the resource is overusing, the VideoSendStream will try to reduce |
| 223 | // resolution or frame rate until no resource is overusing. |
| 224 | // TODO(https://crbug.com/webrtc/11565): When the ResourceAdaptationProcessor |
| 225 | // is moved to Call this method could be deleted altogether in favor of |
| 226 | // Call-level APIs only. |
| 227 | virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0; |
| 228 | virtual std::vector<rtc::scoped_refptr<Resource>> |
| 229 | GetAdaptationResources() = 0; |
| 230 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 231 | virtual void SetSource( |
| 232 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source, |
| 233 | const DegradationPreference& degradation_preference) = 0; |
| 234 | |
| 235 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 236 | // in the config. Encoder settings are passed on to the encoder instance along |
| 237 | // with the VideoStream settings. |
| 238 | virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0; |
| 239 | |
| 240 | virtual Stats GetStats() = 0; |
| 241 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 242 | protected: |
| 243 | virtual ~VideoSendStream() {} |
| 244 | }; |
| 245 | |
| 246 | } // namespace webrtc |
| 247 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 248 | #endif // CALL_VIDEO_SEND_STREAM_H_ |