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