1 /* 2 * Copyright (c) 2020 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 MODULES_VIDEO_CODING_RTP_SEQ_NUM_ONLY_REF_FINDER_H_ 12 #define MODULES_VIDEO_CODING_RTP_SEQ_NUM_ONLY_REF_FINDER_H_ 13 14 #include <deque> 15 #include <map> 16 #include <memory> 17 #include <set> 18 #include <utility> 19 20 #include "absl/container/inlined_vector.h" 21 #include "modules/video_coding/frame_object.h" 22 #include "modules/video_coding/rtp_frame_reference_finder.h" 23 #include "rtc_base/numerics/sequence_number_util.h" 24 25 namespace webrtc { 26 27 class RtpSeqNumOnlyRefFinder { 28 public: 29 RtpSeqNumOnlyRefFinder() = default; 30 31 RtpFrameReferenceFinder::ReturnVector ManageFrame( 32 std::unique_ptr<RtpFrameObject> frame); 33 RtpFrameReferenceFinder::ReturnVector PaddingReceived(uint16_t seq_num); 34 void ClearTo(uint16_t seq_num); 35 36 private: 37 static constexpr int kMaxStashedFrames = 100; 38 static constexpr int kMaxPaddingAge = 100; 39 40 enum FrameDecision { kStash, kHandOff, kDrop }; 41 42 FrameDecision ManageFrameInternal(RtpFrameObject* frame); 43 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res); 44 void UpdateLastPictureIdWithPadding(uint16_t seq_num); 45 46 // For every group of pictures, hold two sequence numbers. The first being 47 // the sequence number of the last packet of the last completed frame, and 48 // the second being the sequence number of the last packet of the last 49 // completed frame advanced by any potential continuous packets of padding. 50 std::map<uint16_t, 51 std::pair<uint16_t, uint16_t>, 52 DescendingSeqNumComp<uint16_t>> 53 last_seq_num_gop_; 54 55 // Padding packets that have been received but that are not yet continuous 56 // with any group of pictures. 57 std::set<uint16_t, DescendingSeqNumComp<uint16_t>> stashed_padding_; 58 59 // Frames that have been fully received but didn't have all the information 60 // needed to determine their references. 61 std::deque<std::unique_ptr<RtpFrameObject>> stashed_frames_; 62 63 // Unwrapper used to unwrap generic RTP streams. In a generic stream we derive 64 // a picture id from the packet sequence number. 65 SeqNumUnwrapper<uint16_t> rtp_seq_num_unwrapper_; 66 }; 67 68 } // namespace webrtc 69 70 #endif // MODULES_VIDEO_CODING_RTP_SEQ_NUM_ONLY_REF_FINDER_H_ 71