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_VP8_REF_FINDER_H_ 12 #define MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_ 13 14 #include <deque> 15 #include <map> 16 #include <memory> 17 #include <set> 18 19 #include "absl/container/inlined_vector.h" 20 #include "modules/video_coding/frame_object.h" 21 #include "modules/video_coding/rtp_frame_reference_finder.h" 22 #include "rtc_base/numerics/sequence_number_util.h" 23 24 namespace webrtc { 25 26 class RtpVp8RefFinder { 27 public: 28 RtpVp8RefFinder() = default; 29 30 RtpFrameReferenceFinder::ReturnVector ManageFrame( 31 std::unique_ptr<RtpFrameObject> frame); 32 void ClearTo(uint16_t seq_num); 33 34 private: 35 static constexpr int kFrameIdLength = 1 << 15; 36 static constexpr int kMaxLayerInfo = 50; 37 static constexpr int kMaxNotYetReceivedFrames = 100; 38 static constexpr int kMaxStashedFrames = 100; 39 static constexpr int kMaxTemporalLayers = 5; 40 41 struct UnwrappedTl0Frame { 42 int64_t unwrapped_tl0; 43 std::unique_ptr<RtpFrameObject> frame; 44 }; 45 46 enum FrameDecision { kStash, kHandOff, kDrop }; 47 48 FrameDecision ManageFrameInternal(RtpFrameObject* frame, 49 const RTPVideoHeaderVP8& codec_header, 50 int64_t unwrapped_tl0); 51 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res); 52 void UpdateLayerInfoVp8(RtpFrameObject* frame, 53 int64_t unwrapped_tl0, 54 uint8_t temporal_idx); 55 void UnwrapPictureIds(RtpFrameObject* frame); 56 57 // Save the last picture id in order to detect when there is a gap in frames 58 // that have not yet been fully received. 59 int last_picture_id_ = -1; 60 61 // Frames earlier than the last received frame that have not yet been 62 // fully received. 63 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>> 64 not_yet_received_frames_; 65 66 // Frames that have been fully received but didn't have all the information 67 // needed to determine their references. 68 std::deque<UnwrappedTl0Frame> stashed_frames_; 69 70 // Holds the information about the last completed frame for a given temporal 71 // layer given an unwrapped Tl0 picture index. 72 std::map<int64_t, std::array<int64_t, kMaxTemporalLayers>> layer_info_; 73 74 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id 75 // specified. 76 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper_; 77 78 SeqNumUnwrapper<uint8_t> tl0_unwrapper_; 79 }; 80 81 } // namespace webrtc 82 83 #endif // MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_ 84