blob: 82fdbd31a1f7a6a23b2cf45bf65c8cd0c24627d8 [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_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"
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 RtpVp8RefFinder {
27 public:
28 RtpVp8RefFinder() = 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 kMaxLayerInfo = 50;
37 static constexpr int kMaxNotYetReceivedFrames = 100;
38 static constexpr int kMaxStashedFrames = 100;
39 static constexpr int kMaxTemporalLayers = 5;
40
philipel342c5112022-03-28 12:30:0641 struct UnwrappedTl0Frame {
42 int64_t unwrapped_tl0;
43 std::unique_ptr<RtpFrameObject> frame;
44 };
45
philipel4e702162020-11-27 16:56:3746 enum FrameDecision { kStash, kHandOff, kDrop };
47
philipel342c5112022-03-28 12:30:0648 FrameDecision ManageFrameInternal(RtpFrameObject* frame,
49 const RTPVideoHeaderVP8& codec_header,
50 int64_t unwrapped_tl0);
philipel4e702162020-11-27 16:56:3751 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res);
philipelca188092021-03-23 11:00:4952 void UpdateLayerInfoVp8(RtpFrameObject* frame,
philipel4e702162020-11-27 16:56:3753 int64_t unwrapped_tl0,
54 uint8_t temporal_idx);
philipelca188092021-03-23 11:00:4955 void UnwrapPictureIds(RtpFrameObject* frame);
philipel4e702162020-11-27 16:56:3756
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.
philipel342c5112022-03-28 12:30:0668 std::deque<UnwrappedTl0Frame> stashed_frames_;
philipel4e702162020-11-27 16:56:3769
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
philipel4e702162020-11-27 16:56:3781} // namespace webrtc
82
83#endif // MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_