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