blob: 34b00dfa1ab9c97cc2472738bf3f47cf9cb9c326 [file] [log] [blame]
Tommid3807da2020-05-22 15:36:361/*
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
Tommid3807da2020-05-22 15:36:3614#include <map>
15#include <memory>
Florent Castelli8037fc62024-08-29 13:00:4016#include <optional>
Tommid3807da2020-05-22 15:36:3617#include <string>
18#include <vector>
19
Fanny Linderborg1869afa2024-10-02 12:34:4920#include "absl/types/variant.h"
Tommid3807da2020-05-22 15:36:3621#include "api/crypto/frame_decryptor_interface.h"
Danil Chapovalove2fee232024-08-29 09:50:3322#include "api/environment/environment.h"
Artem Titovd15a5752021-02-10 13:31:2423#include "api/sequence_checker.h"
philipelce423ce2021-04-12 11:42:0324#include "api/units/timestamp.h"
Tommid3807da2020-05-22 15:36:3625#include "api/video/color_space.h"
Danil Chapovalov5653c952021-08-10 14:57:5626#include "api/video/video_codec_type.h"
Tommid3807da2020-05-22 15:36:3627#include "call/rtp_packet_sink_interface.h"
28#include "call/syncable.h"
29#include "call/video_receive_stream.h"
Fanny Linderborg1869afa2024-10-02 12:34:4930#include "common_video/frame_instrumentation_data.h"
Tommid3807da2020-05-22 15:36:3631#include "modules/rtp_rtcp/include/receive_statistics.h"
Per K5e5d0172022-12-22 12:43:4132#include "modules/rtp_rtcp/include/recovered_packet_receiver.h"
Tommid3807da2020-05-22 15:36:3633#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
34#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
Minyue Li63b30952021-05-19 12:38:2535#include "modules/rtp_rtcp/source/absolute_capture_time_interpolator.h"
36#include "modules/rtp_rtcp/source/capture_clock_offset_updater.h"
Tommid3807da2020-05-22 15:36:3637#include "modules/rtp_rtcp/source/rtp_dependency_descriptor_extension.h"
38#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Tomas Gunnarssonf25761d2020-06-03 20:55:3339#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
40#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
Tommid3807da2020-05-22 15:36:3641#include "modules/rtp_rtcp/source/rtp_video_header.h"
Tony Herrebe9b5762023-02-03 11:29:0442#include "modules/rtp_rtcp/source/rtp_video_stream_receiver_frame_transformer_delegate.h"
Tommid3807da2020-05-22 15:36:3643#include "modules/rtp_rtcp/source/video_rtp_depacketizer.h"
44#include "modules/video_coding/h264_sps_pps_tracker.h"
Jianjun Zhu326df692024-04-15 01:11:2545#include "modules/video_coding/h26x_packet_buffer.h"
Tommid3807da2020-05-22 15:36:3646#include "modules/video_coding/loss_notification_controller.h"
Markus Handell06a2bf02021-07-22 13:09:3947#include "modules/video_coding/nack_requester.h"
Tommid3807da2020-05-22 15:36:3648#include "modules/video_coding/packet_buffer.h"
49#include "modules/video_coding/rtp_frame_reference_finder.h"
Tommid3807da2020-05-22 15:36:3650#include "rtc_base/experiments/field_trial_parser.h"
Evan Shrubsole097fc342023-01-09 10:21:4351#include "rtc_base/numerics/sequence_number_unwrapper.h"
Mirko Bonadei20e4c802020-11-23 10:07:4252#include "rtc_base/system/no_unique_address.h"
Tommid3807da2020-05-22 15:36:3653#include "rtc_base/thread_annotations.h"
Tommid3807da2020-05-22 15:36:3654#include "video/buffered_frame_decryptor.h"
Rasmus Brandtfbf66dd2022-05-23 07:53:3255#include "video/unique_timestamp_counter.h"
Tommid3807da2020-05-22 15:36:3656
57namespace webrtc {
58
Markus Handell06a2bf02021-07-22 13:09:3959class NackRequester;
Tommid3807da2020-05-22 15:36:3660class PacketRouter;
Tommid3807da2020-05-22 15:36:3661class ReceiveStatistics;
62class RtcpRttStats;
63class RtpPacketReceived;
64class Transport;
65class UlpfecReceiver;
66
67class RtpVideoStreamReceiver2 : public LossNotificationSender,
68 public RecoveredPacketReceiver,
69 public RtpPacketSinkInterface,
70 public KeyFrameRequestSender,
philipelb9813942022-07-05 09:31:3671 public NackSender,
Tommid3807da2020-05-22 15:36:3672 public OnDecryptedFrameCallback,
73 public OnDecryptionStatusChangeCallback,
74 public RtpVideoFrameReceiver {
75 public:
philipel21820962021-05-25 13:35:5776 // 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
Tommid3807da2020-05-22 15:36:3684 RtpVideoStreamReceiver2(
Danil Chapovalove2fee232024-08-29 09:50:3385 const Environment& env,
Tommi63673fe2020-05-27 10:55:3886 TaskQueueBase* current_queue,
Tommid3807da2020-05-22 15:36:3687 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,
Tommif6f45432022-05-20 13:21:2093 const VideoReceiveStreamInterface::Config* config,
Tommid3807da2020-05-22 15:36:3694 ReceiveStatistics* rtp_receive_statistics,
95 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer,
96 RtcpCnameCallback* rtcp_cname_callback,
Markus Handell0e62f7a2021-07-20 11:32:0297 NackPeriodicProcessor* nack_periodic_processor,
Tommid3807da2020-05-22 15:36:3698 // The KeyFrameRequestSender is optional; if not provided, key frame
99 // requests are sent via the internal RtpRtcp module.
philipel6a671502021-03-22 13:17:09100 OnCompleteFrameCallback* complete_frame_callback,
Danil Chapovalove2fee232024-08-29 09:50:33101 scoped_refptr<FrameDecryptorInterface> frame_decryptor,
102 scoped_refptr<FrameTransformerInterface> frame_transformer);
Tommid3807da2020-05-22 15:36:36103 ~RtpVideoStreamReceiver2() override;
104
Niels Möller5401bad2020-08-11 10:17:42105 void AddReceiveCodec(uint8_t payload_type,
Danil Chapovalov5653c952021-08-10 14:57:56106 VideoCodecType video_codec,
Philipp Hanckede172522023-12-14 08:45:39107 const webrtc::CodecParameterMap& codec_params,
Tommid3807da2020-05-22 15:36:36108 bool raw_payload);
Tommi96c1a9b2022-09-29 10:24:02109
110 // Clears state for all receive codecs added via `AddReceiveCodec`.
111 void RemoveReceiveCodecs();
Tommid3807da2020-05-22 15:36:36112
113 void StartReceive();
114 void StopReceive();
115
116 // Produces the transport-related timestamps; current_delay_ms is left unset.
Florent Castelli8037fc62024-08-29 13:00:40117 std::optional<Syncable::Info> GetSyncInfo() const;
Tommid3807da2020-05-22 15:36:36118
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 {
Tommi376cf072021-05-31 17:14:38129 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36130 return frame_counter_.GetUniqueSeen();
131 }
132
133 // Implements RtpPacketSinkInterface.
134 void OnRtpPacket(const RtpPacketReceived& packet) override;
135
Niels Möller3a749332020-09-03 13:40:44136 // Public only for tests.
philipel7aff4d12024-01-17 18:26:58137 // Returns true if the packet should be stashed and retried at a later stage.
138 bool OnReceivedPayloadData(rtc::CopyOnWriteBuffer codec_payload,
Tommid3807da2020-05-22 15:36:36139 const RtpPacketReceived& rtp_packet,
philipel7aff4d12024-01-17 18:26:58140 const RTPVideoHeader& video,
141 int times_nacked);
Tommid3807da2020-05-22 15:36:36142
143 // Implements RecoveredPacketReceiver.
Per K5e5d0172022-12-22 12:43:41144 void OnRecoveredPacket(const RtpPacketReceived& packet) override;
Tommid3807da2020-05-22 15:36:36145
146 // Send an RTCP keyframe request.
147 void RequestKeyFrame() override;
148
philipelb9813942022-07-05 09:31:36149 // Implements NackSender.
150 void SendNack(const std::vector<uint16_t>& sequence_numbers,
151 bool buffering_allowed) override;
152
Tommid3807da2020-05-22 15:36:36153 // 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
Tommid3807da2020-05-22 15:36:36159 // 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
Tommid3807da2020-05-22 15:36:36164 // Implements OnDecryptedFrameCallback.
philipelca188092021-03-23 11:00:49165 void OnDecryptedFrame(std::unique_ptr<RtpFrameObject> frame) override;
Tommid3807da2020-05-22 15:36:36166
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
Tommif6f45432022-05-20 13:21:20181 // Called by VideoReceiveStreamInterface when stats are updated.
Tommid3807da2020-05-22 15:36:36182 void UpdateRtt(int64_t max_rtt_ms);
183
Tommi1331c182022-05-17 08:13:52184 // Called when the local_ssrc is changed to match with a sender.
185 void OnLocalSsrcChange(uint32_t local_ssrc);
186
Tommiaeb44122022-07-14 16:33:42187 // Forwards the call to set rtcp_sender_ to the RTCP mode of the rtcp sender.
188 void SetRtcpMode(RtcpMode mode);
189
Tommi2e809362022-08-12 20:06:20190 void SetReferenceTimeReport(bool enabled);
191
Tommi185f10c2022-08-02 09:51:20192 // 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
Tommie644a4b2022-08-03 14:13:53199 // Turns on/off loss notifications. Must be called on the packet delivery
200 // thread.
201 void SetLossNotificationEnabled(bool enabled);
202
Tommi3900f212022-08-05 14:21:54203 void SetNackHistory(TimeDelta history);
204
Tommi66d20c42022-08-12 13:05:17205 int ulpfec_payload_type() const;
Tommi1c5f3172022-08-13 08:43:59206 int red_payload_type() const;
Tommie1bd8332022-08-13 08:44:10207 void SetProtectionPayloadTypes(int red_payload_type, int ulpfec_payload_type);
Tommi1c5f3172022-08-13 08:43:59208
Florent Castelli8037fc62024-08-29 13:00:40209 std::optional<int64_t> LastReceivedPacketMs() const;
210 std::optional<uint32_t> LastReceivedFrameRtpTimestamp() const;
211 std::optional<int64_t> LastReceivedKeyframePacketMs() const;
Tommid3807da2020-05-22 15:36:36212
Florent Castelli8037fc62024-08-29 13:00:40213 std::optional<RtpRtcpInterface::SenderReportStats> GetSenderReportStats()
Philipp Hancke8f162892024-04-09 23:50:20214 const;
215
Tommid3807da2020-05-22 15:36:36216 private:
217 // Implements RtpVideoFrameReceiver.
philipelca188092021-03-23 11:00:49218 void ManageFrame(std::unique_ptr<RtpFrameObject> frame) override;
Tommid3807da2020-05-22 15:36:36219
Tommi376cf072021-05-31 17:14:38220 void OnCompleteFrames(RtpFrameReferenceFinder::ReturnVector frame)
221 RTC_RUN_ON(packet_sequence_checker_);
222
Tommid3807da2020-05-22 15:36:36223 // 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.
Tommi63673fe2020-05-27 10:55:38240 void RequestKeyFrame() override;
Tommid3807da2020-05-22 15:36:36241
242 // NackSender implementation.
243 void SendNack(const std::vector<uint16_t>& sequence_numbers,
Tommi63673fe2020-05-27 10:55:38244 bool buffering_allowed) override;
Tommid3807da2020-05-22 15:36:36245
246 // LossNotificationSender implementation.
247 void SendLossNotification(uint16_t last_decoded_seq_num,
248 uint16_t last_received_seq_num,
249 bool decodability_flag,
Tommi63673fe2020-05-27 10:55:38250 bool buffering_allowed) override;
Tommid3807da2020-05-22 15:36:36251
252 // Send all RTCP feedback messages buffered thus far.
Tommi63673fe2020-05-27 10:55:38253 void SendBufferedRtcpFeedback();
Tommid3807da2020-05-22 15:36:36254
Tommie644a4b2022-08-03 14:13:53255 void ClearLossNotificationState();
256
Tommid3807da2020-05-22 15:36:36257 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 };
Tommid3807da2020-05-22 15:36:36271
Tommi376cf072021-05-31 17:14:38272 RTC_NO_UNIQUE_ADDRESS SequenceChecker packet_sequence_checker_;
Tommid3807da2020-05-22 15:36:36273 KeyFrameRequestSender* const key_frame_request_sender_;
274 NackSender* const nack_sender_;
275 LossNotificationSender* const loss_notification_sender_;
276
Tommid3807da2020-05-22 15:36:36277 // Key-frame-request-related state.
Tommi376cf072021-05-31 17:14:38278 bool request_key_frame_ RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36279
280 // NACK-related state.
Tommi63673fe2020-05-27 10:55:38281 std::vector<uint16_t> nack_sequence_numbers_
Tommi376cf072021-05-31 17:14:38282 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36283
Florent Castelli8037fc62024-08-29 13:00:40284 std::optional<LossNotificationState> lntf_state_
Tommi376cf072021-05-31 17:14:38285 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36286 };
287 enum ParseGenericDependenciesResult {
philipel7aff4d12024-01-17 18:26:58288 kStashPacket,
Tommid3807da2020-05-22 15:36:36289 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.
Tommi376cf072021-05-31 17:14:38296 void ReceivePacket(const RtpPacketReceived& packet)
297 RTC_RUN_ON(packet_sequence_checker_);
298
Tommid3807da2020-05-22 15:36:36299 // Parses and handles RED headers.
300 // This function assumes that it's being called from only one thread.
Tommi376cf072021-05-31 17:14:38301 void ParseAndHandleEncapsulatingHeader(const RtpPacketReceived& packet)
302 RTC_RUN_ON(packet_sequence_checker_);
Shunbo Li6f866342024-12-17 03:39:55303 void NotifyReceiverOfEmptyPacket(uint16_t seq_num, bool is_h26x)
Tommi376cf072021-05-31 17:14:38304 RTC_RUN_ON(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36305 bool IsRedEnabled() const;
Tommi376cf072021-05-31 17:14:38306 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_);
Tommid3807da2020-05-22 15:36:36310 ParseGenericDependenciesResult ParseGenericDependenciesExtension(
311 const RtpPacketReceived& rtp_packet,
Tommi376cf072021-05-31 17:14:38312 RTPVideoHeader* video_header) RTC_RUN_ON(packet_sequence_checker_);
313 void OnAssembledFrame(std::unique_ptr<RtpFrameObject> frame)
314 RTC_RUN_ON(packet_sequence_checker_);
philipelce423ce2021-04-12 11:42:03315 void UpdatePacketReceiveTimestamps(const RtpPacketReceived& packet,
316 bool is_keyframe)
Tommi376cf072021-05-31 17:14:38317 RTC_RUN_ON(packet_sequence_checker_);
Fanny Linderborg1869afa2024-10-02 12:34:49318 void SetLastCorruptionDetectionIndex(
319 const absl::variant<FrameInstrumentationSyncData,
Erik Språng5fc74892024-11-29 11:03:51320 FrameInstrumentationData>& frame_instrumentation_data,
321 int spatial_idx);
Tommid3807da2020-05-22 15:36:36322
Shunbo Li6f866342024-12-17 03:39:55323 bool IsH26xPayloadType(uint8_t payload_type) const
324 RTC_RUN_ON(packet_sequence_checker_);
325
Danil Chapovalove2fee232024-08-29 09:50:33326 const Environment env_;
Tommi3900f212022-08-05 14:21:54327 TaskQueueBase* const worker_queue_;
Danil Chapovalove2fee232024-08-29 09:50:33328
Tommif6f45432022-05-20 13:21:20329 // Ownership of this object lies with VideoReceiveStreamInterface, which owns
330 // `this`.
331 const VideoReceiveStreamInterface::Config& config_;
Tommid3807da2020-05-22 15:36:36332 PacketRouter* const packet_router_;
Tommid3807da2020-05-22 15:36:36333
334 RemoteNtpTimeEstimator ntp_estimator_;
335
Tommid3807da2020-05-22 15:36:36336 // 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_;
Tommi66d20c42022-08-12 13:05:17341 std::unique_ptr<UlpfecReceiver> ulpfec_receiver_
342 RTC_GUARDED_BY(packet_sequence_checker_);
Tommi1c5f3172022-08-13 08:43:59343 int red_payload_type_ RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36344
Mirko Bonadei20e4c802020-11-23 10:07:42345 RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_task_checker_;
Tommi376cf072021-05-31 17:14:38346 // 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_;
Tommi185f10c2022-08-02 09:51:20354 RtpPacketSinkInterface* packet_sink_ RTC_GUARDED_BY(packet_sequence_checker_);
Tommi376cf072021-05-31 17:14:38355 bool receiving_ RTC_GUARDED_BY(packet_sequence_checker_);
356 int64_t last_packet_log_ms_ RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36357
Tomas Gunnarssonf25761d2020-06-03 20:55:33358 const std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_;
Tommid3807da2020-05-22 15:36:36359
Tommi3900f212022-08-05 14:21:54360 NackPeriodicProcessor* const nack_periodic_processor_;
philipel6a671502021-03-22 13:17:09361 OnCompleteFrameCallback* complete_frame_callback_;
Nico Grunbauma36f10b2021-12-09 04:59:31362 const KeyFrameReqMethod keyframe_request_method_;
Tommid3807da2020-05-22 15:36:36363
364 RtcpFeedbackBuffer rtcp_feedback_buffer_;
Florent Castelli8037fc62024-08-29 13:00:40365 // TODO(tommi): Consider std::optional<NackRequester> instead of unique_ptr
Tommi3900f212022-08-05 14:21:54366 // since nack is usually configured.
367 std::unique_ptr<NackRequester> nack_module_
368 RTC_GUARDED_BY(packet_sequence_checker_);
Tommie644a4b2022-08-03 14:13:53369 std::unique_ptr<LossNotificationController> loss_notification_controller_
370 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36371
philipeldad500a2021-04-14 14:23:34372 video_coding::PacketBuffer packet_buffer_
Tommi376cf072021-05-31 17:14:38373 RTC_GUARDED_BY(packet_sequence_checker_);
Jianjun Zhu326df692024-04-15 01:11:25374 // 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_);
Tommi376cf072021-05-31 17:14:38378 UniqueTimestampCounter frame_counter_
379 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36380 SeqNumUnwrapper<uint16_t> frame_id_unwrapper_
Tommi376cf072021-05-31 17:14:38381 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36382
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_
Tommi376cf072021-05-31 17:14:38387 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36388 // Frame id of the last frame with the attached video structure.
Florent Castelli8037fc62024-08-29 13:00:40389 // std::nullopt when `video_structure_ == nullptr`;
390 std::optional<int64_t> video_structure_frame_id_
Tommi376cf072021-05-31 17:14:38391 RTC_GUARDED_BY(packet_sequence_checker_);
philipelc4ea5ae2023-01-20 12:13:01392 Timestamp last_logged_failed_to_parse_dd_
393 RTC_GUARDED_BY(packet_sequence_checker_) = Timestamp::MinusInfinity();
Tommid3807da2020-05-22 15:36:36394
philipel6a671502021-03-22 13:17:09395 std::unique_ptr<RtpFrameReferenceFinder> reference_finder_
Tommi376cf072021-05-31 17:14:38396 RTC_GUARDED_BY(packet_sequence_checker_);
Florent Castelli8037fc62024-08-29 13:00:40397 std::optional<VideoCodecType> current_codec_
Tommi376cf072021-05-31 17:14:38398 RTC_GUARDED_BY(packet_sequence_checker_);
Tommi63673fe2020-05-27 10:55:38399 uint32_t last_assembled_frame_rtp_timestamp_
Tommi376cf072021-05-31 17:14:38400 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36401
Tommid3807da2020-05-22 15:36:36402 std::map<int64_t, uint16_t> last_seq_num_for_pic_id_
Tommi376cf072021-05-31 17:14:38403 RTC_GUARDED_BY(packet_sequence_checker_);
404 video_coding::H264SpsPpsTracker tracker_
405 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36406
407 // Maps payload id to the depacketizer.
Tommi63673fe2020-05-27 10:55:38408 std::map<uint8_t, std::unique_ptr<VideoRtpDepacketizer>> payload_type_map_
Tommi376cf072021-05-31 17:14:38409 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36410
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 Hanckede172522023-12-14 08:45:39414 std::map<uint8_t, webrtc::CodecParameterMap> pt_codec_params_
Tommi376cf072021-05-31 17:14:38415 RTC_GUARDED_BY(packet_sequence_checker_);
Shunbo Li6f866342024-12-17 03:39:55416
417 // Maps payload type to the VideoCodecType.
418 std::map<uint8_t, webrtc::VideoCodecType> pt_codec_
419 RTC_GUARDED_BY(packet_sequence_checker_);
420
Tommi376cf072021-05-31 17:14:38421 int16_t last_payload_type_ RTC_GUARDED_BY(packet_sequence_checker_) = -1;
Tommid3807da2020-05-22 15:36:36422
Tommi376cf072021-05-31 17:14:38423 bool has_received_frame_ RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36424
Florent Castelli8037fc62024-08-29 13:00:40425 std::optional<uint32_t> last_received_rtp_timestamp_
Tommi376cf072021-05-31 17:14:38426 RTC_GUARDED_BY(packet_sequence_checker_);
Florent Castelli8037fc62024-08-29 13:00:40427 std::optional<uint32_t> last_received_keyframe_rtp_timestamp_
Tommi376cf072021-05-31 17:14:38428 RTC_GUARDED_BY(packet_sequence_checker_);
Florent Castelli8037fc62024-08-29 13:00:40429 std::optional<Timestamp> last_received_rtp_system_time_
Tommi376cf072021-05-31 17:14:38430 RTC_GUARDED_BY(packet_sequence_checker_);
Florent Castelli8037fc62024-08-29 13:00:40431 std::optional<Timestamp> last_received_keyframe_rtp_system_time_
Tommi376cf072021-05-31 17:14:38432 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36433
Tommid3807da2020-05-22 15:36:36434 // 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_
Tommi376cf072021-05-31 17:14:38437 RTC_PT_GUARDED_BY(packet_sequence_checker_);
Tommi63673fe2020-05-27 10:55:38438 bool frames_decryptable_ RTC_GUARDED_BY(worker_task_checker_);
Florent Castelli8037fc62024-08-29 13:00:40439 std::optional<ColorSpace> last_color_space_;
Tommid3807da2020-05-22 15:36:36440
Minyue Li63b30952021-05-19 12:38:25441 AbsoluteCaptureTimeInterpolator absolute_capture_time_interpolator_
Tommi376cf072021-05-31 17:14:38442 RTC_GUARDED_BY(packet_sequence_checker_);
Minyue Li63b30952021-05-19 12:38:25443
444 CaptureClockOffsetUpdater capture_clock_offset_updater_
Tommi376cf072021-05-31 17:14:38445 RTC_GUARDED_BY(packet_sequence_checker_);
Tommid3807da2020-05-22 15:36:36446
447 int64_t last_completed_picture_id_ = 0;
448
449 rtc::scoped_refptr<RtpVideoStreamReceiverFrameTransformerDelegate>
450 frame_transformer_delegate_;
philipel9599b3c2021-05-11 09:30:52451
452 SeqNumUnwrapper<uint16_t> rtp_seq_num_unwrapper_
Tommi376cf072021-05-31 17:14:38453 RTC_GUARDED_BY(packet_sequence_checker_);
philipel9599b3c2021-05-11 09:30:52454 std::map<int64_t, RtpPacketInfo> packet_infos_
Tommi376cf072021-05-31 17:14:38455 RTC_GUARDED_BY(packet_sequence_checker_);
philipel7aff4d12024-01-17 18:26:58456 std::vector<RtpPacketReceived> stashed_packets_
457 RTC_GUARDED_BY(packet_sequence_checker_);
philipel17093412022-06-13 11:14:43458
459 Timestamp next_keyframe_request_for_missing_video_structure_ =
460 Timestamp::MinusInfinity();
Jianjun Zhu326df692024-04-15 01:11:25461 bool sps_pps_idr_is_h264_keyframe_ = false;
Erik Språng5fc74892024-11-29 11:03:51462
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_;
Tommid3807da2020-05-22 15:36:36469};
470
471} // namespace webrtc
472
473#endif // VIDEO_RTP_VIDEO_STREAM_RECEIVER2_H_