rtp_vp9_ref_finder.h (3726B)
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_VP9_REF_FINDER_H_ 12 #define MODULES_VIDEO_CODING_RTP_VP9_REF_FINDER_H_ 13 14 #include <array> 15 #include <cstdint> 16 #include <deque> 17 #include <map> 18 #include <memory> 19 #include <set> 20 21 #include "modules/rtp_rtcp/source/frame_object.h" 22 #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" 23 #include "modules/video_coding/rtp_frame_reference_finder.h" 24 #include "rtc_base/numerics/sequence_number_unwrapper.h" 25 #include "rtc_base/numerics/sequence_number_util.h" 26 27 namespace webrtc { 28 29 class RtpVp9RefFinder { 30 public: 31 RtpVp9RefFinder() = default; 32 33 RtpFrameReferenceFinder::ReturnVector ManageFrame( 34 std::unique_ptr<RtpFrameObject> frame); 35 void ClearTo(uint16_t seq_num); 36 37 private: 38 static constexpr int kFrameIdLength = 1 << 15; 39 static constexpr int kMaxGofSaved = 50; 40 static constexpr int kMaxLayerInfo = 50; 41 static constexpr int kMaxNotYetReceivedFrames = 100; 42 static constexpr int kMaxStashedFrames = 100; 43 static constexpr int kMaxTemporalLayers = 5; 44 45 enum FrameDecision { kStash, kHandOff, kDrop }; 46 47 struct GofInfo { 48 GofInfo(GofInfoVP9* gof, uint16_t last_picture_id) 49 : gof(gof), last_picture_id(last_picture_id) {} 50 GofInfoVP9* gof; 51 uint16_t last_picture_id; 52 }; 53 54 struct UnwrappedTl0Frame { 55 int64_t unwrapped_tl0; 56 std::unique_ptr<RtpFrameObject> frame; 57 }; 58 59 FrameDecision ManageFrameFlexible(RtpFrameObject* frame, 60 const RTPVideoHeaderVP9& vp9_header); 61 FrameDecision ManageFrameGof(RtpFrameObject* frame, 62 const RTPVideoHeaderVP9& vp9_header, 63 int64_t unwrapped_tl0); 64 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res); 65 66 bool MissingRequiredFrameVp9(uint16_t picture_id, const GofInfo& info); 67 68 void FrameReceivedVp9(uint16_t picture_id, GofInfo* info); 69 bool UpSwitchInIntervalVp9(uint16_t picture_id, 70 uint8_t temporal_idx, 71 uint16_t pid_ref); 72 73 void FlattenFrameIdAndRefs(RtpFrameObject* frame, bool inter_layer_predicted); 74 75 // Frames that have been fully received but didn't have all the information 76 // needed to determine their references. 77 std::deque<UnwrappedTl0Frame> stashed_frames_; 78 79 // Where the current scalability structure is in the 80 // `scalability_structures_` array. 81 uint8_t current_ss_idx_ = 0; 82 83 // Holds received scalability structures. 84 std::array<GofInfoVP9, kMaxGofSaved> scalability_structures_; 85 86 // Holds the the Gof information for a given unwrapped TL0 picture index. 87 std::map<int64_t, GofInfo> gof_info_; 88 89 // Keep track of which picture id and which temporal layer that had the 90 // up switch flag set. 91 std::map<uint16_t, uint8_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>> 92 up_switch_; 93 94 // For every temporal layer, keep a set of which frames that are missing. 95 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>>, 96 kMaxTemporalLayers> 97 missing_frames_for_layer_; 98 99 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id 100 // specified. 101 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper_; 102 103 SeqNumUnwrapper<uint8_t> tl0_unwrapper_; 104 }; 105 106 } // namespace webrtc 107 108 #endif // MODULES_VIDEO_CODING_RTP_VP9_REF_FINDER_H_