blob: 55d2de921ec9ed0120e373231bcf94876f0de081 [file] [log] [blame]
philipel4e702162020-11-27 17:56:37 +01001/*
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"
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
24namespace webrtc {
25namespace video_coding {
26
27class RtpVp8RefFinder {
28 public:
29 RtpVp8RefFinder() = default;
30
31 RtpFrameReferenceFinder::ReturnVector ManageFrame(
32 std::unique_ptr<RtpFrameObject> frame);
33 void ClearTo(uint16_t seq_num);
34
35 private:
36 static constexpr int kFrameIdLength = 1 << 15;
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 FrameDecision ManageFrameInternal(RtpFrameObject* frame);
45 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res);
46 void UpdateLayerInfoVp8(RtpFrameObject* frame,
47 int64_t unwrapped_tl0,
48 uint8_t temporal_idx);
49 void UnwrapPictureIds(RtpFrameObject* frame);
50
51 // Save the last picture id in order to detect when there is a gap in frames
52 // that have not yet been fully received.
53 int last_picture_id_ = -1;
54
55 // Frames earlier than the last received frame that have not yet been
56 // fully received.
57 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>>
58 not_yet_received_frames_;
59
60 // Frames that have been fully received but didn't have all the information
61 // needed to determine their references.
62 std::deque<std::unique_ptr<RtpFrameObject>> stashed_frames_;
63
64 // Holds the information about the last completed frame for a given temporal
65 // layer given an unwrapped Tl0 picture index.
66 std::map<int64_t, std::array<int64_t, kMaxTemporalLayers>> layer_info_;
67
68 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id
69 // specified.
70 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper_;
71
72 SeqNumUnwrapper<uint8_t> tl0_unwrapper_;
73};
74
75} // namespace video_coding
76} // namespace webrtc
77
78#endif // MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_