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 <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 RtpVp9RefFinder { 27 public: 28 RtpVp9RefFinder() = 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 kMaxGofSaved = 50; 37 static constexpr int kMaxLayerInfo = 50; 38 static constexpr int kMaxNotYetReceivedFrames = 100; 39 static constexpr int kMaxStashedFrames = 100; 40 static constexpr int kMaxTemporalLayers = 5; 41 42 enum FrameDecision { kStash, kHandOff, kDrop }; 43 44 struct GofInfo { GofInfoGofInfo45 GofInfo(GofInfoVP9* gof, uint16_t last_picture_id) 46 : gof(gof), last_picture_id(last_picture_id) {} 47 GofInfoVP9* gof; 48 uint16_t last_picture_id; 49 }; 50 51 struct UnwrappedTl0Frame { 52 int64_t unwrapped_tl0; 53 std::unique_ptr<RtpFrameObject> frame; 54 }; 55 56 FrameDecision ManageFrameFlexible(RtpFrameObject* frame, 57 const RTPVideoHeaderVP9& vp9_header); 58 FrameDecision ManageFrameGof(RtpFrameObject* frame, 59 const RTPVideoHeaderVP9& vp9_header, 60 int64_t unwrapped_tl0); 61 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res); 62 63 bool MissingRequiredFrameVp9(uint16_t picture_id, const GofInfo& info); 64 65 void FrameReceivedVp9(uint16_t picture_id, GofInfo* info); 66 bool UpSwitchInIntervalVp9(uint16_t picture_id, 67 uint8_t temporal_idx, 68 uint16_t pid_ref); 69 70 void FlattenFrameIdAndRefs(RtpFrameObject* frame, bool inter_layer_predicted); 71 72 // Frames that have been fully received but didn't have all the information 73 // needed to determine their references. 74 std::deque<UnwrappedTl0Frame> stashed_frames_; 75 76 // Where the current scalability structure is in the 77 // `scalability_structures_` array. 78 uint8_t current_ss_idx_ = 0; 79 80 // Holds received scalability structures. 81 std::array<GofInfoVP9, kMaxGofSaved> scalability_structures_; 82 83 // Holds the the Gof information for a given unwrapped TL0 picture index. 84 std::map<int64_t, GofInfo> gof_info_; 85 86 // Keep track of which picture id and which temporal layer that had the 87 // up switch flag set. 88 std::map<uint16_t, uint8_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>> 89 up_switch_; 90 91 // For every temporal layer, keep a set of which frames that are missing. 92 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>>, 93 kMaxTemporalLayers> 94 missing_frames_for_layer_; 95 96 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id 97 // specified. 98 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper_; 99 100 SeqNumUnwrapper<uint8_t> tl0_unwrapper_; 101 }; 102 103 } // namespace webrtc 104 105 #endif // MODULES_VIDEO_CODING_RTP_VP9_REF_FINDER_H_ 106