blob: fb14417ac323fdd574ed07a0cf33cc03bf5acfa6 [file] [log] [blame]
philipel4e702162020-11-27 16:56:371/*
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"
Tony Herrebe9b5762023-02-03 11:29:0420#include "modules/rtp_rtcp/source/frame_object.h"
philipel4e702162020-11-27 16:56:3721#include "modules/video_coding/rtp_frame_reference_finder.h"
Evan Shrubsole097fc342023-01-09 10:21:4322#include "rtc_base/numerics/sequence_number_unwrapper.h"
philipel4e702162020-11-27 16:56:3723
24namespace webrtc {
philipel4e702162020-11-27 16:56:3725
26class RtpVp9RefFinder {
27 public:
28 RtpVp9RefFinder() = default;
29
30 RtpFrameReferenceFinder::ReturnVector ManageFrame(
philipelca188092021-03-23 11:00:4931 std::unique_ptr<RtpFrameObject> frame);
philipel4e702162020-11-27 16:56:3732 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 {
philipel0d175352021-08-27 16:29:1945 GofInfo(GofInfoVP9* gof, uint16_t last_picture_id)
46 : gof(gof), last_picture_id(last_picture_id) {}
philipel4e702162020-11-27 16:56:3747 GofInfoVP9* gof;
48 uint16_t last_picture_id;
49 };
50
philipel773205d2022-03-07 17:12:2651 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);
philipel4e702162020-11-27 16:56:3761 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
philipelca188092021-03-23 11:00:4970 void FlattenFrameIdAndRefs(RtpFrameObject* frame, bool inter_layer_predicted);
philipel4e702162020-11-27 16:56:3771
philipel4e702162020-11-27 16:56:3772 // Frames that have been fully received but didn't have all the information
73 // needed to determine their references.
philipel773205d2022-03-07 17:12:2674 std::deque<UnwrappedTl0Frame> stashed_frames_;
philipel4e702162020-11-27 16:56:3775
76 // Where the current scalability structure is in the
Artem Titovdcd7fc72021-08-09 11:02:5777 // `scalability_structures_` array.
philipel4e702162020-11-27 16:56:3778 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
philipel4e702162020-11-27 16:56:37103} // namespace webrtc
104
105#endif // MODULES_VIDEO_CODING_RTP_VP9_REF_FINDER_H_