Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
| 11 | #ifndef VIDEO_RTP_VIDEO_STREAM_RECEIVER2_H_ |
| 12 | #define VIDEO_RTP_VIDEO_STREAM_RECEIVER2_H_ |
| 13 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "absl/types/optional.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 20 | #include "api/crypto/frame_decryptor_interface.h" |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 21 | #include "api/sequence_checker.h" |
philipel | ce423ce | 2021-04-12 11:42:03 | [diff] [blame] | 22 | #include "api/units/timestamp.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 23 | #include "api/video/color_space.h" |
Danil Chapovalov | 5653c95 | 2021-08-10 14:57:56 | [diff] [blame] | 24 | #include "api/video/video_codec_type.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 25 | #include "call/rtp_packet_sink_interface.h" |
| 26 | #include "call/syncable.h" |
| 27 | #include "call/video_receive_stream.h" |
| 28 | #include "modules/rtp_rtcp/include/receive_statistics.h" |
Per K | 5e5d017 | 2022-12-22 12:43:41 | [diff] [blame] | 29 | #include "modules/rtp_rtcp/include/recovered_packet_receiver.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 30 | #include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h" |
| 31 | #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" |
Minyue Li | 63b3095 | 2021-05-19 12:38:25 | [diff] [blame] | 32 | #include "modules/rtp_rtcp/source/absolute_capture_time_interpolator.h" |
| 33 | #include "modules/rtp_rtcp/source/capture_clock_offset_updater.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 34 | #include "modules/rtp_rtcp/source/rtp_dependency_descriptor_extension.h" |
| 35 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
Tomas Gunnarsson | f25761d | 2020-06-03 20:55:33 | [diff] [blame] | 36 | #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h" |
| 37 | #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 38 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
Tony Herre | be9b576 | 2023-02-03 11:29:04 | [diff] [blame] | 39 | #include "modules/rtp_rtcp/source/rtp_video_stream_receiver_frame_transformer_delegate.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 40 | #include "modules/rtp_rtcp/source/video_rtp_depacketizer.h" |
| 41 | #include "modules/video_coding/h264_sps_pps_tracker.h" |
| 42 | #include "modules/video_coding/loss_notification_controller.h" |
Markus Handell | 06a2bf0 | 2021-07-22 13:09:39 | [diff] [blame] | 43 | #include "modules/video_coding/nack_requester.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 44 | #include "modules/video_coding/packet_buffer.h" |
| 45 | #include "modules/video_coding/rtp_frame_reference_finder.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 46 | #include "rtc_base/experiments/field_trial_parser.h" |
Evan Shrubsole | 097fc34 | 2023-01-09 10:21:43 | [diff] [blame] | 47 | #include "rtc_base/numerics/sequence_number_unwrapper.h" |
Mirko Bonadei | 20e4c80 | 2020-11-23 10:07:42 | [diff] [blame] | 48 | #include "rtc_base/system/no_unique_address.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 49 | #include "rtc_base/thread_annotations.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 50 | #include "video/buffered_frame_decryptor.h" |
Rasmus Brandt | fbf66dd | 2022-05-23 07:53:32 | [diff] [blame] | 51 | #include "video/unique_timestamp_counter.h" |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 52 | |
| 53 | namespace webrtc { |
| 54 | |
Markus Handell | 06a2bf0 | 2021-07-22 13:09:39 | [diff] [blame] | 55 | class NackRequester; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 56 | class PacketRouter; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 57 | class ReceiveStatistics; |
| 58 | class RtcpRttStats; |
| 59 | class RtpPacketReceived; |
| 60 | class Transport; |
| 61 | class UlpfecReceiver; |
| 62 | |
| 63 | class RtpVideoStreamReceiver2 : public LossNotificationSender, |
| 64 | public RecoveredPacketReceiver, |
| 65 | public RtpPacketSinkInterface, |
| 66 | public KeyFrameRequestSender, |
philipel | b981394 | 2022-07-05 09:31:36 | [diff] [blame] | 67 | public NackSender, |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 68 | public OnDecryptedFrameCallback, |
| 69 | public OnDecryptionStatusChangeCallback, |
| 70 | public RtpVideoFrameReceiver { |
| 71 | public: |
philipel | 2182096 | 2021-05-25 13:35:57 | [diff] [blame] | 72 | // A complete frame is a frame which has received all its packets and all its |
| 73 | // references are known. |
| 74 | class OnCompleteFrameCallback { |
| 75 | public: |
| 76 | virtual ~OnCompleteFrameCallback() {} |
| 77 | virtual void OnCompleteFrame(std::unique_ptr<EncodedFrame> frame) = 0; |
| 78 | }; |
| 79 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 80 | RtpVideoStreamReceiver2( |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 81 | TaskQueueBase* current_queue, |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 82 | Clock* clock, |
| 83 | Transport* transport, |
| 84 | RtcpRttStats* rtt_stats, |
| 85 | // The packet router is optional; if provided, the RtpRtcp module for this |
| 86 | // stream is registered as a candidate for sending REMB and transport |
| 87 | // feedback. |
| 88 | PacketRouter* packet_router, |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 89 | const VideoReceiveStreamInterface::Config* config, |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 90 | ReceiveStatistics* rtp_receive_statistics, |
| 91 | RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, |
| 92 | RtcpCnameCallback* rtcp_cname_callback, |
Markus Handell | 0e62f7a | 2021-07-20 11:32:02 | [diff] [blame] | 93 | NackPeriodicProcessor* nack_periodic_processor, |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 94 | // The KeyFrameRequestSender is optional; if not provided, key frame |
| 95 | // requests are sent via the internal RtpRtcp module. |
philipel | 6a67150 | 2021-03-22 13:17:09 | [diff] [blame] | 96 | OnCompleteFrameCallback* complete_frame_callback, |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 97 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor, |
Jonas Oreland | 8ca0613 | 2022-03-14 11:52:48 | [diff] [blame] | 98 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, |
Brett Hebert | e04d0fa | 2022-08-09 18:25:04 | [diff] [blame] | 99 | const FieldTrialsView& field_trials, |
| 100 | RtcEventLog* event_log); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 101 | ~RtpVideoStreamReceiver2() override; |
| 102 | |
Niels Möller | 5401bad | 2020-08-11 10:17:42 | [diff] [blame] | 103 | void AddReceiveCodec(uint8_t payload_type, |
Danil Chapovalov | 5653c95 | 2021-08-10 14:57:56 | [diff] [blame] | 104 | VideoCodecType video_codec, |
Mirko Bonadei | 6c9c958 | 2023-12-13 16:26:57 | [diff] [blame] | 105 | const std::map<std::string, std::string>& codec_params, |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 106 | bool raw_payload); |
Tommi | 96c1a9b | 2022-09-29 10:24:02 | [diff] [blame] | 107 | void RemoveReceiveCodec(uint8_t payload_type); |
| 108 | |
| 109 | // Clears state for all receive codecs added via `AddReceiveCodec`. |
| 110 | void RemoveReceiveCodecs(); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 111 | |
| 112 | void StartReceive(); |
| 113 | void StopReceive(); |
| 114 | |
| 115 | // Produces the transport-related timestamps; current_delay_ms is left unset. |
| 116 | absl::optional<Syncable::Info> GetSyncInfo() const; |
| 117 | |
| 118 | bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); |
| 119 | |
| 120 | void FrameContinuous(int64_t seq_num); |
| 121 | |
| 122 | void FrameDecoded(int64_t seq_num); |
| 123 | |
| 124 | void SignalNetworkState(NetworkState state); |
| 125 | |
| 126 | // Returns number of different frames seen. |
| 127 | int GetUniqueFramesSeen() const { |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 128 | RTC_DCHECK_RUN_ON(&packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 129 | return frame_counter_.GetUniqueSeen(); |
| 130 | } |
| 131 | |
| 132 | // Implements RtpPacketSinkInterface. |
| 133 | void OnRtpPacket(const RtpPacketReceived& packet) override; |
| 134 | |
Niels Möller | 3a74933 | 2020-09-03 13:40:44 | [diff] [blame] | 135 | // Public only for tests. |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 136 | void OnReceivedPayloadData(rtc::CopyOnWriteBuffer codec_payload, |
| 137 | const RtpPacketReceived& rtp_packet, |
| 138 | const RTPVideoHeader& video); |
| 139 | |
| 140 | // Implements RecoveredPacketReceiver. |
Per K | 5e5d017 | 2022-12-22 12:43:41 | [diff] [blame] | 141 | void OnRecoveredPacket(const RtpPacketReceived& packet) override; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 142 | |
| 143 | // Send an RTCP keyframe request. |
| 144 | void RequestKeyFrame() override; |
| 145 | |
philipel | b981394 | 2022-07-05 09:31:36 | [diff] [blame] | 146 | // Implements NackSender. |
| 147 | void SendNack(const std::vector<uint16_t>& sequence_numbers, |
| 148 | bool buffering_allowed) override; |
| 149 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 150 | // Implements LossNotificationSender. |
| 151 | void SendLossNotification(uint16_t last_decoded_seq_num, |
| 152 | uint16_t last_received_seq_num, |
| 153 | bool decodability_flag, |
| 154 | bool buffering_allowed) override; |
| 155 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 156 | // Returns true if a decryptor is attached and frames can be decrypted. |
| 157 | // Updated by OnDecryptionStatusChangeCallback. Note this refers to Frame |
| 158 | // Decryption not SRTP. |
| 159 | bool IsDecryptable() const; |
| 160 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 161 | // Implements OnDecryptedFrameCallback. |
philipel | ca18809 | 2021-03-23 11:00:49 | [diff] [blame] | 162 | void OnDecryptedFrame(std::unique_ptr<RtpFrameObject> frame) override; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 163 | |
| 164 | // Implements OnDecryptionStatusChangeCallback. |
| 165 | void OnDecryptionStatusChange( |
| 166 | FrameDecryptorInterface::Status status) override; |
| 167 | |
| 168 | // Optionally set a frame decryptor after a stream has started. This will not |
| 169 | // reset the decoder state. |
| 170 | void SetFrameDecryptor( |
| 171 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor); |
| 172 | |
| 173 | // Sets a frame transformer after a stream has started, if no transformer |
| 174 | // has previously been set. Does not reset the decoder state. |
| 175 | void SetDepacketizerToDecoderFrameTransformer( |
| 176 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer); |
| 177 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 178 | // Called by VideoReceiveStreamInterface when stats are updated. |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 179 | void UpdateRtt(int64_t max_rtt_ms); |
| 180 | |
Tommi | 1331c18 | 2022-05-17 08:13:52 | [diff] [blame] | 181 | // Called when the local_ssrc is changed to match with a sender. |
| 182 | void OnLocalSsrcChange(uint32_t local_ssrc); |
| 183 | |
Tommi | aeb4412 | 2022-07-14 16:33:42 | [diff] [blame] | 184 | // Forwards the call to set rtcp_sender_ to the RTCP mode of the rtcp sender. |
| 185 | void SetRtcpMode(RtcpMode mode); |
| 186 | |
Tommi | 2e80936 | 2022-08-12 20:06:20 | [diff] [blame] | 187 | void SetReferenceTimeReport(bool enabled); |
| 188 | |
Tommi | 185f10c | 2022-08-02 09:51:20 | [diff] [blame] | 189 | // Sets or clears the callback sink that gets called for RTP packets. Used for |
| 190 | // packet handlers such as FlexFec. Must be called on the packet delivery |
| 191 | // thread (same context as `OnRtpPacket` is called on). |
| 192 | // TODO(bugs.webrtc.org/11993): Packet delivery thread today means `worker |
| 193 | // thread` but will be `network thread`. |
| 194 | void SetPacketSink(RtpPacketSinkInterface* packet_sink); |
| 195 | |
Tommi | e644a4b | 2022-08-03 14:13:53 | [diff] [blame] | 196 | // Turns on/off loss notifications. Must be called on the packet delivery |
| 197 | // thread. |
| 198 | void SetLossNotificationEnabled(bool enabled); |
| 199 | |
Tommi | 3900f21 | 2022-08-05 14:21:54 | [diff] [blame] | 200 | void SetNackHistory(TimeDelta history); |
| 201 | |
Tommi | 66d20c4 | 2022-08-12 13:05:17 | [diff] [blame] | 202 | int ulpfec_payload_type() const; |
Tommi | 1c5f317 | 2022-08-13 08:43:59 | [diff] [blame] | 203 | int red_payload_type() const; |
Tommi | e1bd833 | 2022-08-13 08:44:10 | [diff] [blame] | 204 | void SetProtectionPayloadTypes(int red_payload_type, int ulpfec_payload_type); |
Tommi | 1c5f317 | 2022-08-13 08:43:59 | [diff] [blame] | 205 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 206 | absl::optional<int64_t> LastReceivedPacketMs() const; |
Philipp Hancke | 5f4a7e0 | 2023-07-03 09:18:37 | [diff] [blame] | 207 | absl::optional<uint32_t> LastReceivedFrameRtpTimestamp() const; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 208 | absl::optional<int64_t> LastReceivedKeyframePacketMs() const; |
| 209 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 210 | private: |
| 211 | // Implements RtpVideoFrameReceiver. |
philipel | ca18809 | 2021-03-23 11:00:49 | [diff] [blame] | 212 | void ManageFrame(std::unique_ptr<RtpFrameObject> frame) override; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 213 | |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 214 | void OnCompleteFrames(RtpFrameReferenceFinder::ReturnVector frame) |
| 215 | RTC_RUN_ON(packet_sequence_checker_); |
| 216 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 217 | // Used for buffering RTCP feedback messages and sending them all together. |
| 218 | // Note: |
| 219 | // 1. Key frame requests and NACKs are mutually exclusive, with the |
| 220 | // former taking precedence over the latter. |
| 221 | // 2. Loss notifications are orthogonal to either. (That is, may be sent |
| 222 | // alongside either.) |
| 223 | class RtcpFeedbackBuffer : public KeyFrameRequestSender, |
| 224 | public NackSender, |
| 225 | public LossNotificationSender { |
| 226 | public: |
| 227 | RtcpFeedbackBuffer(KeyFrameRequestSender* key_frame_request_sender, |
| 228 | NackSender* nack_sender, |
| 229 | LossNotificationSender* loss_notification_sender); |
| 230 | |
| 231 | ~RtcpFeedbackBuffer() override = default; |
| 232 | |
| 233 | // KeyFrameRequestSender implementation. |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 234 | void RequestKeyFrame() override; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 235 | |
| 236 | // NackSender implementation. |
| 237 | void SendNack(const std::vector<uint16_t>& sequence_numbers, |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 238 | bool buffering_allowed) override; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 239 | |
| 240 | // LossNotificationSender implementation. |
| 241 | void SendLossNotification(uint16_t last_decoded_seq_num, |
| 242 | uint16_t last_received_seq_num, |
| 243 | bool decodability_flag, |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 244 | bool buffering_allowed) override; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 245 | |
| 246 | // Send all RTCP feedback messages buffered thus far. |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 247 | void SendBufferedRtcpFeedback(); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 248 | |
Tommi | e644a4b | 2022-08-03 14:13:53 | [diff] [blame] | 249 | void ClearLossNotificationState(); |
| 250 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 251 | private: |
| 252 | // LNTF-related state. |
| 253 | struct LossNotificationState { |
| 254 | LossNotificationState(uint16_t last_decoded_seq_num, |
| 255 | uint16_t last_received_seq_num, |
| 256 | bool decodability_flag) |
| 257 | : last_decoded_seq_num(last_decoded_seq_num), |
| 258 | last_received_seq_num(last_received_seq_num), |
| 259 | decodability_flag(decodability_flag) {} |
| 260 | |
| 261 | uint16_t last_decoded_seq_num; |
| 262 | uint16_t last_received_seq_num; |
| 263 | bool decodability_flag; |
| 264 | }; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 265 | |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 266 | RTC_NO_UNIQUE_ADDRESS SequenceChecker packet_sequence_checker_; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 267 | KeyFrameRequestSender* const key_frame_request_sender_; |
| 268 | NackSender* const nack_sender_; |
| 269 | LossNotificationSender* const loss_notification_sender_; |
| 270 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 271 | // Key-frame-request-related state. |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 272 | bool request_key_frame_ RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 273 | |
| 274 | // NACK-related state. |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 275 | std::vector<uint16_t> nack_sequence_numbers_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 276 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 277 | |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 278 | absl::optional<LossNotificationState> lntf_state_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 279 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 280 | }; |
| 281 | enum ParseGenericDependenciesResult { |
| 282 | kDropPacket, |
| 283 | kHasGenericDescriptor, |
| 284 | kNoGenericDescriptor |
| 285 | }; |
| 286 | |
| 287 | // Entry point doing non-stats work for a received packet. Called |
| 288 | // for the same packet both before and after RED decapsulation. |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 289 | void ReceivePacket(const RtpPacketReceived& packet) |
| 290 | RTC_RUN_ON(packet_sequence_checker_); |
| 291 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 292 | // Parses and handles RED headers. |
| 293 | // This function assumes that it's being called from only one thread. |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 294 | void ParseAndHandleEncapsulatingHeader(const RtpPacketReceived& packet) |
| 295 | RTC_RUN_ON(packet_sequence_checker_); |
| 296 | void NotifyReceiverOfEmptyPacket(uint16_t seq_num) |
| 297 | RTC_RUN_ON(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 298 | bool IsRedEnabled() const; |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 299 | void InsertSpsPpsIntoTracker(uint8_t payload_type) |
| 300 | RTC_RUN_ON(packet_sequence_checker_); |
| 301 | void OnInsertedPacket(video_coding::PacketBuffer::InsertResult result) |
| 302 | RTC_RUN_ON(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 303 | ParseGenericDependenciesResult ParseGenericDependenciesExtension( |
| 304 | const RtpPacketReceived& rtp_packet, |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 305 | RTPVideoHeader* video_header) RTC_RUN_ON(packet_sequence_checker_); |
| 306 | void OnAssembledFrame(std::unique_ptr<RtpFrameObject> frame) |
| 307 | RTC_RUN_ON(packet_sequence_checker_); |
philipel | ce423ce | 2021-04-12 11:42:03 | [diff] [blame] | 308 | void UpdatePacketReceiveTimestamps(const RtpPacketReceived& packet, |
| 309 | bool is_keyframe) |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 310 | RTC_RUN_ON(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 311 | |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 312 | const FieldTrialsView& field_trials_; |
Tommi | 3900f21 | 2022-08-05 14:21:54 | [diff] [blame] | 313 | TaskQueueBase* const worker_queue_; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 314 | Clock* const clock_; |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 315 | // Ownership of this object lies with VideoReceiveStreamInterface, which owns |
| 316 | // `this`. |
| 317 | const VideoReceiveStreamInterface::Config& config_; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 318 | PacketRouter* const packet_router_; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 319 | |
| 320 | RemoteNtpTimeEstimator ntp_estimator_; |
| 321 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 322 | // Set by the field trial WebRTC-ForcePlayoutDelay to override any playout |
| 323 | // delay that is specified in the received packets. |
| 324 | FieldTrialOptional<int> forced_playout_delay_max_ms_; |
| 325 | FieldTrialOptional<int> forced_playout_delay_min_ms_; |
| 326 | ReceiveStatistics* const rtp_receive_statistics_; |
Tommi | 66d20c4 | 2022-08-12 13:05:17 | [diff] [blame] | 327 | std::unique_ptr<UlpfecReceiver> ulpfec_receiver_ |
| 328 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | 1c5f317 | 2022-08-13 08:43:59 | [diff] [blame] | 329 | int red_payload_type_ RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 330 | |
Mirko Bonadei | 20e4c80 | 2020-11-23 10:07:42 | [diff] [blame] | 331 | RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_task_checker_; |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 332 | // TODO(bugs.webrtc.org/11993): This checker conceptually represents |
| 333 | // operations that belong to the network thread. The Call class is currently |
| 334 | // moving towards handling network packets on the network thread and while |
| 335 | // that work is ongoing, this checker may in practice represent the worker |
| 336 | // thread, but still serves as a mechanism of grouping together concepts |
| 337 | // that belong to the network thread. Once the packets are fully delivered |
| 338 | // on the network thread, this comment will be deleted. |
| 339 | RTC_NO_UNIQUE_ADDRESS SequenceChecker packet_sequence_checker_; |
Tommi | 185f10c | 2022-08-02 09:51:20 | [diff] [blame] | 340 | RtpPacketSinkInterface* packet_sink_ RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 341 | bool receiving_ RTC_GUARDED_BY(packet_sequence_checker_); |
| 342 | int64_t last_packet_log_ms_ RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 343 | |
Tomas Gunnarsson | f25761d | 2020-06-03 20:55:33 | [diff] [blame] | 344 | const std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 345 | |
Tommi | 3900f21 | 2022-08-05 14:21:54 | [diff] [blame] | 346 | NackPeriodicProcessor* const nack_periodic_processor_; |
philipel | 6a67150 | 2021-03-22 13:17:09 | [diff] [blame] | 347 | OnCompleteFrameCallback* complete_frame_callback_; |
Nico Grunbaum | a36f10b | 2021-12-09 04:59:31 | [diff] [blame] | 348 | const KeyFrameReqMethod keyframe_request_method_; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 349 | |
| 350 | RtcpFeedbackBuffer rtcp_feedback_buffer_; |
Tommi | 3900f21 | 2022-08-05 14:21:54 | [diff] [blame] | 351 | // TODO(tommi): Consider absl::optional<NackRequester> instead of unique_ptr |
| 352 | // since nack is usually configured. |
| 353 | std::unique_ptr<NackRequester> nack_module_ |
| 354 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | e644a4b | 2022-08-03 14:13:53 | [diff] [blame] | 355 | std::unique_ptr<LossNotificationController> loss_notification_controller_ |
| 356 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 357 | |
philipel | dad500a | 2021-04-14 14:23:34 | [diff] [blame] | 358 | video_coding::PacketBuffer packet_buffer_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 359 | RTC_GUARDED_BY(packet_sequence_checker_); |
| 360 | UniqueTimestampCounter frame_counter_ |
| 361 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 362 | SeqNumUnwrapper<uint16_t> frame_id_unwrapper_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 363 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 364 | |
| 365 | // Video structure provided in the dependency descriptor in a first packet |
| 366 | // of a key frame. It is required to parse dependency descriptor in the |
| 367 | // following delta packets. |
| 368 | std::unique_ptr<FrameDependencyStructure> video_structure_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 369 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 370 | // Frame id of the last frame with the attached video structure. |
| 371 | // absl::nullopt when `video_structure_ == nullptr`; |
| 372 | absl::optional<int64_t> video_structure_frame_id_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 373 | RTC_GUARDED_BY(packet_sequence_checker_); |
philipel | c4ea5ae | 2023-01-20 12:13:01 | [diff] [blame] | 374 | Timestamp last_logged_failed_to_parse_dd_ |
| 375 | RTC_GUARDED_BY(packet_sequence_checker_) = Timestamp::MinusInfinity(); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 376 | |
philipel | 6a67150 | 2021-03-22 13:17:09 | [diff] [blame] | 377 | std::unique_ptr<RtpFrameReferenceFinder> reference_finder_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 378 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 379 | absl::optional<VideoCodecType> current_codec_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 380 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 381 | uint32_t last_assembled_frame_rtp_timestamp_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 382 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 383 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 384 | std::map<int64_t, uint16_t> last_seq_num_for_pic_id_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 385 | RTC_GUARDED_BY(packet_sequence_checker_); |
| 386 | video_coding::H264SpsPpsTracker tracker_ |
| 387 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 388 | |
| 389 | // Maps payload id to the depacketizer. |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 390 | std::map<uint8_t, std::unique_ptr<VideoRtpDepacketizer>> payload_type_map_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 391 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 392 | |
| 393 | // TODO(johan): Remove pt_codec_params_ once |
| 394 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6883 is resolved. |
| 395 | // Maps a payload type to a map of out-of-band supplied codec parameters. |
Mirko Bonadei | 6c9c958 | 2023-12-13 16:26:57 | [diff] [blame] | 396 | std::map<uint8_t, std::map<std::string, std::string>> pt_codec_params_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 397 | RTC_GUARDED_BY(packet_sequence_checker_); |
| 398 | int16_t last_payload_type_ RTC_GUARDED_BY(packet_sequence_checker_) = -1; |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 399 | |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 400 | bool has_received_frame_ RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 401 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 402 | absl::optional<uint32_t> last_received_rtp_timestamp_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 403 | RTC_GUARDED_BY(packet_sequence_checker_); |
philipel | b849311 | 2021-04-16 10:10:22 | [diff] [blame] | 404 | absl::optional<uint32_t> last_received_keyframe_rtp_timestamp_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 405 | RTC_GUARDED_BY(packet_sequence_checker_); |
philipel | ce423ce | 2021-04-12 11:42:03 | [diff] [blame] | 406 | absl::optional<Timestamp> last_received_rtp_system_time_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 407 | RTC_GUARDED_BY(packet_sequence_checker_); |
philipel | ce423ce | 2021-04-12 11:42:03 | [diff] [blame] | 408 | absl::optional<Timestamp> last_received_keyframe_rtp_system_time_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 409 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 410 | |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 411 | // Handles incoming encrypted frames and forwards them to the |
| 412 | // rtp_reference_finder if they are decryptable. |
| 413 | std::unique_ptr<BufferedFrameDecryptor> buffered_frame_decryptor_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 414 | RTC_PT_GUARDED_BY(packet_sequence_checker_); |
Tommi | 63673fe | 2020-05-27 10:55:38 | [diff] [blame] | 415 | bool frames_decryptable_ RTC_GUARDED_BY(worker_task_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 416 | absl::optional<ColorSpace> last_color_space_; |
| 417 | |
Minyue Li | 63b3095 | 2021-05-19 12:38:25 | [diff] [blame] | 418 | AbsoluteCaptureTimeInterpolator absolute_capture_time_interpolator_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 419 | RTC_GUARDED_BY(packet_sequence_checker_); |
Minyue Li | 63b3095 | 2021-05-19 12:38:25 | [diff] [blame] | 420 | |
| 421 | CaptureClockOffsetUpdater capture_clock_offset_updater_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 422 | RTC_GUARDED_BY(packet_sequence_checker_); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 423 | |
| 424 | int64_t last_completed_picture_id_ = 0; |
| 425 | |
| 426 | rtc::scoped_refptr<RtpVideoStreamReceiverFrameTransformerDelegate> |
| 427 | frame_transformer_delegate_; |
philipel | 9599b3c | 2021-05-11 09:30:52 | [diff] [blame] | 428 | |
| 429 | SeqNumUnwrapper<uint16_t> rtp_seq_num_unwrapper_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 430 | RTC_GUARDED_BY(packet_sequence_checker_); |
philipel | 9599b3c | 2021-05-11 09:30:52 | [diff] [blame] | 431 | std::map<int64_t, RtpPacketInfo> packet_infos_ |
Tommi | 376cf07 | 2021-05-31 17:14:38 | [diff] [blame] | 432 | RTC_GUARDED_BY(packet_sequence_checker_); |
philipel | 1709341 | 2022-06-13 11:14:43 | [diff] [blame] | 433 | |
| 434 | Timestamp next_keyframe_request_for_missing_video_structure_ = |
| 435 | Timestamp::MinusInfinity(); |
Tommi | d3807da | 2020-05-22 15:36:36 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | } // namespace webrtc |
| 439 | |
| 440 | #endif // VIDEO_RTP_VIDEO_STREAM_RECEIVER2_H_ |