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