rtp_vp8_ref_finder.h (2988B)
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 <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/vp8/include/vp8_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 RtpVp8RefFinder { 30 public: 31 RtpVp8RefFinder() = 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 kMaxLayerInfo = 50; 40 static constexpr int kMaxNotYetReceivedFrames = 100; 41 static constexpr int kMaxStashedFrames = 100; 42 static constexpr int kMaxTemporalLayers = 5; 43 44 struct UnwrappedTl0Frame { 45 int64_t unwrapped_tl0; 46 std::unique_ptr<RtpFrameObject> frame; 47 }; 48 49 enum FrameDecision { kStash, kHandOff, kDrop }; 50 51 FrameDecision ManageFrameInternal(RtpFrameObject* frame, 52 const RTPVideoHeaderVP8& codec_header, 53 int64_t unwrapped_tl0); 54 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res); 55 void UpdateLayerInfoVp8(RtpFrameObject* frame, 56 int64_t unwrapped_tl0, 57 uint8_t temporal_idx); 58 void UnwrapPictureIds(RtpFrameObject* frame); 59 60 // Save the last picture id in order to detect when there is a gap in frames 61 // that have not yet been fully received. 62 int last_picture_id_ = -1; 63 64 // Frames earlier than the last received frame that have not yet been 65 // fully received. 66 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>> 67 not_yet_received_frames_; 68 69 // Frames that have been fully received but didn't have all the information 70 // needed to determine their references. 71 std::deque<UnwrappedTl0Frame> stashed_frames_; 72 73 // Holds the information about the last completed frame for a given temporal 74 // layer given an unwrapped Tl0 picture index. 75 std::map<int64_t, std::array<int64_t, kMaxTemporalLayers>> layer_info_; 76 77 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id 78 // specified. 79 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper_; 80 81 SeqNumUnwrapper<uint8_t> tl0_unwrapper_; 82 }; 83 84 } // namespace webrtc 85 86 #endif // MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_