blob: 0a6cd7e10de1393c0f0cf73b64b215f6a706013c [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 {
philipel4e702162020-11-27 17:56:37 +010025
26class RtpVp8RefFinder {
27 public:
28 RtpVp8RefFinder() = default;
29
30 RtpFrameReferenceFinder::ReturnVector ManageFrame(
philipelca188092021-03-23 12:00:49 +010031 std::unique_ptr<RtpFrameObject> frame);
philipel4e702162020-11-27 17:56:37 +010032 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
41 enum FrameDecision { kStash, kHandOff, kDrop };
42
philipelca188092021-03-23 12:00:49 +010043 FrameDecision ManageFrameInternal(RtpFrameObject* frame);
philipel4e702162020-11-27 17:56:37 +010044 void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res);
philipelca188092021-03-23 12:00:49 +010045 void UpdateLayerInfoVp8(RtpFrameObject* frame,
philipel4e702162020-11-27 17:56:37 +010046 int64_t unwrapped_tl0,
47 uint8_t temporal_idx);
philipelca188092021-03-23 12:00:49 +010048 void UnwrapPictureIds(RtpFrameObject* frame);
philipel4e702162020-11-27 17:56:37 +010049
50 // Save the last picture id in order to detect when there is a gap in frames
51 // that have not yet been fully received.
52 int last_picture_id_ = -1;
53
54 // Frames earlier than the last received frame that have not yet been
55 // fully received.
56 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kFrameIdLength>>
57 not_yet_received_frames_;
58
59 // Frames that have been fully received but didn't have all the information
60 // needed to determine their references.
philipelca188092021-03-23 12:00:49 +010061 std::deque<std::unique_ptr<RtpFrameObject>> stashed_frames_;
philipel4e702162020-11-27 17:56:37 +010062
63 // Holds the information about the last completed frame for a given temporal
64 // layer given an unwrapped Tl0 picture index.
65 std::map<int64_t, std::array<int64_t, kMaxTemporalLayers>> layer_info_;
66
67 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id
68 // specified.
69 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper_;
70
71 SeqNumUnwrapper<uint8_t> tl0_unwrapper_;
72};
73
philipel4e702162020-11-27 17:56:37 +010074} // namespace webrtc
75
76#endif // MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_