| 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 |
| 11 | #ifndef CALL_VIDEO_SEND_STREAM_H_ |
| 12 | #define CALL_VIDEO_SEND_STREAM_H_ |
| 13 |
| 14 | #include <stdint.h> |
| 15 |
| 16 | #include <map> |
| 17 | #include <string> |
| 18 | #include <vector> |
| 19 |
| 20 | #include "absl/types/optional.h" |
| 21 | #include "api/adaptation/resource.h" |
| 22 | #include "api/call/transport.h" |
| 23 | #include "api/crypto/crypto_options.h" |
| 24 | #include "api/frame_transformer_interface.h" |
| 25 | #include "api/rtp_parameters.h" |
| 26 | #include "api/rtp_sender_interface.h" |
| 27 | #include "api/scoped_refptr.h" |
| 28 | #include "api/video/video_content_type.h" |
| 29 | #include "api/video/video_frame.h" |
| 30 | #include "api/video/video_sink_interface.h" |
| 31 | #include "api/video/video_source_interface.h" |
| 32 | #include "api/video/video_stream_encoder_settings.h" |
| 33 | #include "api/video_codecs/scalability_mode.h" |
| 34 | #include "call/rtp_config.h" |
| 35 | #include "common_video/frame_counts.h" |
| 36 | #include "common_video/include/quality_limitation_reason.h" |
| 37 | #include "modules/rtp_rtcp/include/report_block_data.h" |
| 38 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
| 39 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 40 | #include "video/config/video_encoder_config.h" |
| 41 |
| 42 | namespace webrtc { |
| 43 |
| 44 | class FrameEncryptorInterface; |
| 45 |
| 46 | class VideoSendStream { |
| 47 | public: |
| 48 | // Multiple StreamStats objects are present if simulcast is used (multiple |
| 49 | // kMedia streams) or if RTX or FlexFEC is negotiated. Multiple SVC layers, on |
| 50 | // the other hand, does not cause additional StreamStats. |
| 51 | struct StreamStats { |
| 52 | enum class StreamType { |
| 53 | // A media stream is an RTP stream for audio or video. Retransmissions and |
| 54 | // FEC is either sent over the same SSRC or negotiated to be sent over |
| 55 | // separate SSRCs, in which case separate StreamStats objects exist with |
| 56 | // references to this media stream's SSRC. |
| 57 | kMedia, |
| 58 | // RTX streams are streams dedicated to retransmissions. They have a |
| 59 | // dependency on a single kMedia stream: `referenced_media_ssrc`. |
| 60 | kRtx, |
| 61 | // FlexFEC streams are streams dedicated to FlexFEC. They have a |
| 62 | // dependency on a single kMedia stream: `referenced_media_ssrc`. |
| 63 | kFlexfec, |
| 64 | }; |
| 65 |
| 66 | StreamStats(); |
| 67 | ~StreamStats(); |
| 68 |
| 69 | std::string ToString() const; |
| 70 |
| 71 | StreamType type = StreamType::kMedia; |
| 72 | // If `type` is kRtx or kFlexfec this value is present. The referenced SSRC |
| 73 | // is the kMedia stream that this stream is performing retransmissions or |
| 74 | // FEC for. If `type` is kMedia, this value is null. |
| 75 | absl::optional<uint32_t> referenced_media_ssrc; |
| 76 | FrameCounts frame_counts; |
| 77 | int width = 0; |
| 78 | int height = 0; |
| 79 | // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer. |
| 80 | int total_bitrate_bps = 0; |
| 81 | int retransmit_bitrate_bps = 0; |
| 82 | // `avg_delay_ms` and `max_delay_ms` are only used in tests. Consider |
| 83 | // deleting. |
| 84 | int avg_delay_ms = 0; |
| 85 | int max_delay_ms = 0; |
| 86 | StreamDataCounters rtp_stats; |
| 87 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 88 | // A snapshot of the most recent Report Block with additional data of |
| 89 | // interest to statistics. Used to implement RTCRemoteInboundRtpStreamStats. |
| 90 | absl::optional<ReportBlockData> report_block_data; |
| 91 | double encode_frame_rate = 0.0; |
| 92 | int frames_encoded = 0; |
| 93 | absl::optional<uint64_t> qp_sum; |
| 94 | uint64_t total_encode_time_ms = 0; |
| 95 | uint64_t total_encoded_bytes_target = 0; |
| 96 | uint32_t huge_frames_sent = 0; |
| 97 | absl::optional<ScalabilityMode> scalability_mode; |
| 98 | }; |
| 99 |
| 100 | struct Stats { |
| 101 | Stats(); |
| 102 | ~Stats(); |
| 103 | std::string ToString(int64_t time_ms) const; |
| 104 | absl::optional<std::string> encoder_implementation_name; |
| 105 | double input_frame_rate = 0; |
| 106 | int encode_frame_rate = 0; |
| 107 | int avg_encode_time_ms = 0; |
| 108 | int encode_usage_percent = 0; |
| 109 | uint32_t frames_encoded = 0; |
| 110 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime |
| 111 | uint64_t total_encode_time_ms = 0; |
| 112 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget |
| 113 | uint64_t total_encoded_bytes_target = 0; |
| 114 | uint32_t frames = 0; |
| 115 | uint32_t frames_dropped_by_capturer = 0; |
| 116 | uint32_t frames_dropped_by_bad_timestamp = 0; |
| 117 | uint32_t frames_dropped_by_encoder_queue = 0; |
| 118 | uint32_t frames_dropped_by_rate_limiter = 0; |
| 119 | uint32_t frames_dropped_by_congestion_window = 0; |
| 120 | uint32_t frames_dropped_by_encoder = 0; |
| 121 | // Bitrate the encoder is currently configured to use due to bandwidth |
| 122 | // limitations. |
| 123 | int target_media_bitrate_bps = 0; |
| 124 | // Bitrate the encoder is actually producing. |
| 125 | int media_bitrate_bps = 0; |
| 126 | bool suspended = false; |
| 127 | bool bw_limited_resolution = false; |
| 128 | bool cpu_limited_resolution = false; |
| 129 | bool bw_limited_framerate = false; |
| 130 | bool cpu_limited_framerate = false; |
| 131 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason |
| 132 | QualityLimitationReason quality_limitation_reason = |
| 133 | QualityLimitationReason::kNone; |
| 134 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations |
| 135 | std::map<QualityLimitationReason, int64_t> quality_limitation_durations_ms; |
| 136 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges |
| 137 | uint32_t quality_limitation_resolution_changes = 0; |
| 138 | // Total number of times resolution as been requested to be changed due to |
| 139 | // CPU/quality adaptation. |
| 140 | int number_of_cpu_adapt_changes = 0; |
| 141 | int number_of_quality_adapt_changes = 0; |
| 142 | bool has_entered_low_resolution = false; |
| 143 | std::map<uint32_t, StreamStats> substreams; |
| 144 | webrtc::VideoContentType content_type = |
| 145 | webrtc::VideoContentType::UNSPECIFIED; |
| 146 | uint32_t frames_sent = 0; |
| 147 | uint32_t huge_frames_sent = 0; |
| 148 | absl::optional<bool> power_efficient_encoder; |
| 149 | }; |
| 150 |
| 151 | struct Config { |
| 152 | public: |
| 153 | Config() = delete; |
| 154 | Config(Config&&); |
| 155 | explicit Config(Transport* send_transport); |
| 156 |
| 157 | Config& operator=(Config&&); |
| 158 | Config& operator=(const Config&) = delete; |
| 159 |
| 160 | ~Config(); |
| 161 |
| 162 | // Mostly used by tests. Avoid creating copies if you can. |
| 163 | Config Copy() const { return Config(*this); } |
| 164 |
| 165 | std::string ToString() const; |
| 166 |
| 167 | RtpConfig rtp; |
| 168 |
| 169 | VideoStreamEncoderSettings encoder_settings; |
| 170 |
| 171 | // Time interval between RTCP report for video |
| 172 | int rtcp_report_interval_ms = 1000; |
| 173 |
| 174 | // Transport for outgoing packets. |
| 175 | Transport* send_transport = nullptr; |
| 176 |
| 177 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 178 | // this many milliseconds, if possible, earlier than expected render time. |
| 179 | // Only valid if `local_renderer` is set. |
| 180 | int render_delay_ms = 0; |
| 181 |
| 182 | // Target delay in milliseconds. A positive value indicates this stream is |
| 183 | // used for streaming instead of a real-time call. |
| 184 | int target_delay_ms = 0; |
| 185 |
| 186 | // True if the stream should be suspended when the available bitrate fall |
| 187 | // below the minimum configured bitrate. If this variable is false, the |
| 188 | // stream may send at a rate higher than the estimated available bitrate. |
| 189 | bool suspend_below_min_bitrate = false; |
| 190 |
| 191 | // Enables periodic bandwidth probing in application-limited region. |
| 192 | bool periodic_alr_bandwidth_probing = false; |
| 193 |
| 194 | // An optional custom frame encryptor that allows the entire frame to be |
| 195 | // encrypted in whatever way the caller chooses. This is not required by |
| 196 | // default. |
| 197 | rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor; |
| 198 |
| 199 | // An optional encoder selector provided by the user. |
| 200 | // Overrides VideoEncoderFactory::GetEncoderSelector(). |
| 201 | // Owned by RtpSenderBase. |
| 202 | VideoEncoderFactory::EncoderSelectorInterface* encoder_selector = nullptr; |
| 203 |
| 204 | // Per PeerConnection cryptography options. |
| 205 | CryptoOptions crypto_options; |
| 206 |
| 207 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer; |
| 208 |
| 209 | private: |
| 210 | // Access to the copy constructor is private to force use of the Copy() |
| 211 | // method for those exceptional cases where we do use it. |
| 212 | Config(const Config&); |
| 213 | }; |
| 214 |
| 215 | // Starts stream activity. |
| 216 | // When a stream is active, it can receive, process and deliver packets. |
| 217 | virtual void Start() = 0; |
| 218 |
| 219 | // Stops stream activity. |
| 220 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 221 | virtual void Stop() = 0; |
| 222 |
| 223 | // Accessor for determining if the stream is active. This is an inexpensive |
| 224 | // call that must be made on the same thread as `Start()` and `Stop()` methods |
| 225 | // are called on and will return `true` iff activity has been started |
| 226 | // via `Start()`. |
| 227 | virtual bool started() = 0; |
| 228 |
| 229 | // If the resource is overusing, the VideoSendStream will try to reduce |
| 230 | // resolution or frame rate until no resource is overusing. |
| 231 | // TODO(https://crbug.com/webrtc/11565): When the ResourceAdaptationProcessor |
| 232 | // is moved to Call this method could be deleted altogether in favor of |
| 233 | // Call-level APIs only. |
| 234 | virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0; |
| 235 | virtual std::vector<rtc::scoped_refptr<Resource>> |
| 236 | GetAdaptationResources() = 0; |
| 237 |
| 238 | virtual void SetSource( |
| 239 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source, |
| 240 | const DegradationPreference& degradation_preference) = 0; |
| 241 |
| 242 | // Set which streams to send. Must have at least as many SSRCs as configured |
| 243 | // in the config. Encoder settings are passed on to the encoder instance along |
| 244 | // with the VideoStream settings. |
| 245 | virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0; |
| 246 |
| 247 | virtual void ReconfigureVideoEncoder(VideoEncoderConfig config, |
| 248 | SetParametersCallback callback) = 0; |
| 249 |
| 250 | virtual Stats GetStats() = 0; |
| 251 |
| 252 | virtual void GenerateKeyFrame(const std::vector<std::string>& rids) = 0; |
| 253 |
| 254 | protected: |
| 255 | virtual ~VideoSendStream() {} |
| 256 | }; |
| 257 |
| 258 | } // namespace webrtc |
| 259 |
| 260 | #endif // CALL_VIDEO_SEND_STREAM_H_ |
| 261 |