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_RECEIVE_STREAM_H_ |
| 12 | #define CALL_VIDEO_RECEIVE_STREAM_H_ |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 13 | |
| 14 | #include <limits> |
| 15 | #include <map> |
Mirta Dvornicic | fe68daa | 2019-05-23 13:21:12 +0200 | [diff] [blame] | 16 | #include <set> |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 17 | #include <string> |
Markus Handell | 269ac81 | 2019-12-03 14:31:45 +0100 | [diff] [blame] | 18 | #include <utility> |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "api/crypto/crypto_options.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 23 | #include "api/crypto/frame_decryptor_interface.h" |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 24 | #include "api/rtp_headers.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "api/rtp_parameters.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 26 | #include "api/transport/rtp/rtp_source.h" |
Markus Handell | 269ac81 | 2019-12-03 14:31:45 +0100 | [diff] [blame] | 27 | #include "api/video/recordable_encoded_frame.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 28 | #include "api/video/video_content_type.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 29 | #include "api/video/video_frame.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 30 | #include "api/video/video_sink_interface.h" |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 31 | #include "api/video/video_timing.h" |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 32 | #include "api/video_codecs/sdp_video_format.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "call/rtp_config.h" |
Niels Möller | 53382cb | 2018-11-27 14:05:08 +0100 | [diff] [blame] | 34 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 35 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 36 | |
| 37 | namespace webrtc { |
| 38 | |
| 39 | class RtpPacketSinkInterface; |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 40 | class VideoDecoderFactory; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 41 | |
| 42 | class VideoReceiveStream { |
| 43 | public: |
Markus Handell | 269ac81 | 2019-12-03 14:31:45 +0100 | [diff] [blame] | 44 | // Class for handling moving in/out recording state. |
| 45 | struct RecordingState { |
| 46 | RecordingState() = default; |
| 47 | explicit RecordingState( |
| 48 | std::function<void(const RecordableEncodedFrame&)> callback) |
| 49 | : callback(std::move(callback)) {} |
| 50 | |
| 51 | // Callback stored from the VideoReceiveStream. The VideoReceiveStream |
| 52 | // client should not interpret the attribute. |
| 53 | std::function<void(const RecordableEncodedFrame&)> callback; |
| 54 | // Memento of internal state in VideoReceiveStream, recording wether |
| 55 | // we're currently causing generation of a keyframe from the sender. Needed |
| 56 | // to avoid sending double keyframe requests. The VideoReceiveStream client |
| 57 | // should not interpret the attribute. |
| 58 | bool keyframe_needed = false; |
| 59 | // Memento of when a keyframe request was last sent. The VideoReceiveStream |
| 60 | // client should not interpret the attribute. |
| 61 | absl::optional<int64_t> last_keyframe_request_ms; |
| 62 | }; |
| 63 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 64 | // TODO(mflodman) Move all these settings to VideoDecoder and move the |
| 65 | // declaration to common_types.h. |
| 66 | struct Decoder { |
| 67 | Decoder(); |
| 68 | Decoder(const Decoder&); |
| 69 | ~Decoder(); |
| 70 | std::string ToString() const; |
| 71 | |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 72 | // Ownership stays with WebrtcVideoEngine (delegated from PeerConnection). |
| 73 | // TODO(nisse): Move one level out, to VideoReceiveStream::Config, and later |
| 74 | // to the configuration of VideoStreamDecoder. |
| 75 | VideoDecoderFactory* decoder_factory = nullptr; |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 76 | SdpVideoFormat video_format; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 77 | |
| 78 | // Received RTP packets with this payload type will be sent to this decoder |
| 79 | // instance. |
| 80 | int payload_type = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | struct Stats { |
| 84 | Stats(); |
| 85 | ~Stats(); |
| 86 | std::string ToString(int64_t time_ms) const; |
| 87 | |
| 88 | int network_frame_rate = 0; |
| 89 | int decode_frame_rate = 0; |
| 90 | int render_frame_rate = 0; |
| 91 | uint32_t frames_rendered = 0; |
| 92 | |
| 93 | // Decoder stats. |
| 94 | std::string decoder_implementation_name = "unknown"; |
| 95 | FrameCounts frame_counts; |
| 96 | int decode_ms = 0; |
| 97 | int max_decode_ms = 0; |
| 98 | int current_delay_ms = 0; |
| 99 | int target_delay_ms = 0; |
| 100 | int jitter_buffer_ms = 0; |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 101 | // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferdelay |
| 102 | double jitter_buffer_delay_seconds = 0; |
| 103 | // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferemittedcount |
| 104 | uint64_t jitter_buffer_emitted_count = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 105 | int min_playout_delay_ms = 0; |
| 106 | int render_delay_ms = 10; |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 107 | int64_t interframe_delay_max_ms = -1; |
Johannes Kron | 0c141c5 | 2019-08-26 15:04:43 +0200 | [diff] [blame] | 108 | // Frames dropped due to decoding failures or if the system is too slow. |
| 109 | // https://www.w3.org/TR/webrtc-stats/#dom-rtcvideoreceiverstats-framesdropped |
| 110 | uint32_t frames_dropped = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 111 | uint32_t frames_decoded = 0; |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 112 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime |
| 113 | uint64_t total_decode_time_ms = 0; |
Johannes Kron | 00376e1 | 2019-11-25 10:25:42 +0100 | [diff] [blame] | 114 | // Total inter frame delay in seconds. |
| 115 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalinterframedelay |
| 116 | double total_inter_frame_delay = 0; |
| 117 | // Total squared inter frame delay in seconds^2. |
| 118 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalsqauredinterframedelay |
| 119 | double total_squared_inter_frame_delay = 0; |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 120 | int64_t first_frame_received_to_decoded_ms = -1; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 121 | absl::optional<uint64_t> qp_sum; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 122 | |
| 123 | int current_payload_type = -1; |
| 124 | |
| 125 | int total_bitrate_bps = 0; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 126 | |
| 127 | int width = 0; |
| 128 | int height = 0; |
| 129 | |
Sergey Silkin | 0237106 | 2019-01-31 16:45:42 +0100 | [diff] [blame] | 130 | uint32_t freeze_count = 0; |
| 131 | uint32_t pause_count = 0; |
| 132 | uint32_t total_freezes_duration_ms = 0; |
| 133 | uint32_t total_pauses_duration_ms = 0; |
| 134 | uint32_t total_frames_duration_ms = 0; |
| 135 | double sum_squared_frame_durations = 0.0; |
| 136 | |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 137 | VideoContentType content_type = VideoContentType::UNSPECIFIED; |
| 138 | |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 139 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp |
| 140 | absl::optional<int64_t> estimated_playout_ntp_timestamp_ms; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 141 | int sync_offset_ms = std::numeric_limits<int>::max(); |
| 142 | |
| 143 | uint32_t ssrc = 0; |
| 144 | std::string c_name; |
Niels Möller | d77cc24 | 2019-08-22 09:40:25 +0200 | [diff] [blame] | 145 | RtpReceiveStats rtp_stats; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 146 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 147 | |
| 148 | // Timing frame info: all important timestamps for a full lifetime of a |
| 149 | // single 'timing frame'. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 150 | absl::optional<webrtc::TimingFrameInfo> timing_frame_info; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | struct Config { |
| 154 | private: |
| 155 | // Access to the copy constructor is private to force use of the Copy() |
| 156 | // method for those exceptional cases where we do use it. |
| 157 | Config(const Config&); |
| 158 | |
| 159 | public: |
| 160 | Config() = delete; |
| 161 | Config(Config&&); |
| 162 | explicit Config(Transport* rtcp_send_transport); |
| 163 | Config& operator=(Config&&); |
| 164 | Config& operator=(const Config&) = delete; |
| 165 | ~Config(); |
| 166 | |
| 167 | // Mostly used by tests. Avoid creating copies if you can. |
| 168 | Config Copy() const { return Config(*this); } |
| 169 | |
| 170 | std::string ToString() const; |
| 171 | |
| 172 | // Decoders for every payload that we can receive. |
| 173 | std::vector<Decoder> decoders; |
| 174 | |
| 175 | // Receive-stream specific RTP settings. |
| 176 | struct Rtp { |
| 177 | Rtp(); |
| 178 | Rtp(const Rtp&); |
| 179 | ~Rtp(); |
| 180 | std::string ToString() const; |
| 181 | |
| 182 | // Synchronization source (stream identifier) to be received. |
| 183 | uint32_t remote_ssrc = 0; |
| 184 | |
| 185 | // Sender SSRC used for sending RTCP (such as receiver reports). |
| 186 | uint32_t local_ssrc = 0; |
| 187 | |
| 188 | // See RtcpMode for description. |
| 189 | RtcpMode rtcp_mode = RtcpMode::kCompound; |
| 190 | |
| 191 | // Extended RTCP settings. |
| 192 | struct RtcpXr { |
| 193 | // True if RTCP Receiver Reference Time Report Block extension |
| 194 | // (RFC 3611) should be enabled. |
| 195 | bool receiver_reference_time_report = false; |
| 196 | } rtcp_xr; |
| 197 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 198 | // See draft-holmer-rmcat-transport-wide-cc-extensions for details. |
| 199 | bool transport_cc = false; |
| 200 | |
Elad Alon | fadb181 | 2019-05-24 13:40:02 +0200 | [diff] [blame] | 201 | // See LntfConfig for description. |
| 202 | LntfConfig lntf; |
| 203 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 204 | // See NackConfig for description. |
| 205 | NackConfig nack; |
| 206 | |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 207 | // Payload types for ULPFEC and RED, respectively. |
| 208 | int ulpfec_payload_type = -1; |
| 209 | int red_payload_type = -1; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 210 | |
| 211 | // SSRC for retransmissions. |
| 212 | uint32_t rtx_ssrc = 0; |
| 213 | |
| 214 | // Set if the stream is protected using FlexFEC. |
| 215 | bool protected_by_flexfec = false; |
| 216 | |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 217 | // Map from rtx payload type -> media payload type. |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 218 | // For RTX to be enabled, both an SSRC and this mapping are needed. |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 219 | std::map<int, int> rtx_associated_payload_types; |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 220 | |
Mirta Dvornicic | fe68daa | 2019-05-23 13:21:12 +0200 | [diff] [blame] | 221 | // Payload types that should be depacketized using raw depacketizer |
| 222 | // (payload header will not be parsed and must not be present, additional |
| 223 | // meta data is expected to be present in generic frame descriptor |
| 224 | // RTP header extension). |
| 225 | std::set<int> raw_payload_types; |
| 226 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 227 | // RTP header extensions used for the received stream. |
| 228 | std::vector<RtpExtension> extensions; |
| 229 | } rtp; |
| 230 | |
| 231 | // Transport for outgoing packets (RTCP). |
| 232 | Transport* rtcp_send_transport = nullptr; |
| 233 | |
Rasmus Brandt | 1e27fec | 2019-01-23 09:47:50 +0100 | [diff] [blame] | 234 | // Must always be set. |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 235 | rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
| 236 | |
| 237 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 238 | // this many milliseconds, if possible, earlier than the ideal render time. |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 239 | int render_delay_ms = 10; |
| 240 | |
Rasmus Brandt | 1e27fec | 2019-01-23 09:47:50 +0100 | [diff] [blame] | 241 | // If false, pass frames on to the renderer as soon as they are |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 242 | // available. |
Rasmus Brandt | 1e27fec | 2019-01-23 09:47:50 +0100 | [diff] [blame] | 243 | bool enable_prerenderer_smoothing = true; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 244 | |
| 245 | // Identifier for an A/V synchronization group. Empty string to disable. |
| 246 | // TODO(pbos): Synchronize streams in a sync group, not just video streams |
| 247 | // to one of the audio streams. |
| 248 | std::string sync_group; |
| 249 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 250 | // Target delay in milliseconds. A positive value indicates this stream is |
| 251 | // used for streaming instead of a real-time call. |
| 252 | int target_delay_ms = 0; |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 253 | |
| 254 | // TODO(nisse): Used with VideoDecoderFactory::LegacyCreateVideoDecoder. |
| 255 | // Delete when that method is retired. |
| 256 | std::string stream_id; |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 257 | |
| 258 | // An optional custom frame decryptor that allows the entire frame to be |
| 259 | // decrypted in whatever way the caller choses. This is not required by |
| 260 | // default. |
| 261 | rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor; |
| 262 | |
| 263 | // Per PeerConnection cryptography options. |
| 264 | CryptoOptions crypto_options; |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | // Starts stream activity. |
| 268 | // When a stream is active, it can receive, process and deliver packets. |
| 269 | virtual void Start() = 0; |
| 270 | // Stops stream activity. |
| 271 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 272 | virtual void Stop() = 0; |
| 273 | |
| 274 | // TODO(pbos): Add info on currently-received codec to Stats. |
| 275 | virtual Stats GetStats() const = 0; |
| 276 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 277 | // RtpDemuxer only forwards a given RTP packet to one sink. However, some |
| 278 | // sinks, such as FlexFEC, might wish to be informed of all of the packets |
| 279 | // a given sink receives (or any set of sinks). They may do so by registering |
| 280 | // themselves as secondary sinks. |
| 281 | virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0; |
| 282 | virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0; |
| 283 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 284 | virtual std::vector<RtpSource> GetSources() const = 0; |
| 285 | |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 286 | // Sets a base minimum for the playout delay. Base minimum delay sets lower |
| 287 | // bound on minimum delay value determining lower bound on playout delay. |
| 288 | // |
| 289 | // Returns true if value was successfully set, false overwise. |
| 290 | virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; |
| 291 | |
| 292 | // Returns current value of base minimum delay in milliseconds. |
| 293 | virtual int GetBaseMinimumPlayoutDelayMs() const = 0; |
| 294 | |
Benjamin Wright | a556448 | 2019-04-03 10:44:18 -0700 | [diff] [blame] | 295 | // Allows a FrameDecryptor to be attached to a VideoReceiveStream after |
| 296 | // creation without resetting the decoder state. |
| 297 | virtual void SetFrameDecryptor( |
| 298 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) = 0; |
| 299 | |
Markus Handell | 269ac81 | 2019-12-03 14:31:45 +0100 | [diff] [blame] | 300 | // Sets and returns recording state. The old state is moved out |
| 301 | // of the video receive stream and returned to the caller, and |state| |
| 302 | // is moved in. If the state's callback is set, it will be called with |
| 303 | // recordable encoded frames as they arrive. |
| 304 | // If |generate_key_frame| is true, the method will generate a key frame. |
| 305 | // When the function returns, it's guaranteed that all old callouts |
| 306 | // to the returned callback has ceased. |
| 307 | // Note: the client should not interpret the returned state's attributes, but |
| 308 | // instead treat it as opaque data. |
| 309 | virtual RecordingState SetAndGetRecordingState(RecordingState state, |
| 310 | bool generate_key_frame) = 0; |
| 311 | |
| 312 | // Cause eventual generation of a key frame from the sender. |
| 313 | virtual void GenerateKeyFrame() = 0; |
| 314 | |
aleloi | 440b6d9 | 2017-08-22 05:43:23 -0700 | [diff] [blame] | 315 | protected: |
| 316 | virtual ~VideoReceiveStream() {} |
| 317 | }; |
| 318 | |
| 319 | } // namespace webrtc |
| 320 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 321 | #endif // CALL_VIDEO_RECEIVE_STREAM_H_ |