philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 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 <deque> |
| 15 | #include <map> |
| 16 | #include <memory> |
| 17 | #include <set> |
| 18 | |
| 19 | #include "absl/container/inlined_vector.h" |
Tony Herre | be9b576 | 2023-02-03 11:29:04 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/frame_object.h" |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 21 | #include "modules/video_coding/rtp_frame_reference_finder.h" |
Evan Shrubsole | 097fc34 | 2023-01-09 10:21:43 | [diff] [blame] | 22 | #include "rtc_base/numerics/sequence_number_unwrapper.h" |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 25 | |
| 26 | class RtpVp8RefFinder { |
| 27 | public: |
| 28 | RtpVp8RefFinder() = default; |
| 29 | |
| 30 | RtpFrameReferenceFinder::ReturnVector ManageFrame( |
philipel | ca18809 | 2021-03-23 11:00:49 | [diff] [blame] | 31 | std::unique_ptr<RtpFrameObject> frame); |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 32 | 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 | |
philipel | 342c511 | 2022-03-28 12:30:06 | [diff] [blame] | 41 | struct UnwrappedTl0Frame { |
| 42 | int64_t unwrapped_tl0; |
| 43 | std::unique_ptr<RtpFrameObject> frame; |
| 44 | }; |
| 45 | |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 46 | enum FrameDecision { kStash, kHandOff, kDrop }; |
| 47 | |
philipel | 342c511 | 2022-03-28 12:30:06 | [diff] [blame] | 48 | FrameDecision ManageFrameInternal(RtpFrameObject* frame, |
| 49 | const RTPVideoHeaderVP8& codec_header, |
| 50 | int64_t unwrapped_tl0); |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 51 | void RetryStashedFrames(RtpFrameReferenceFinder::ReturnVector& res); |
philipel | ca18809 | 2021-03-23 11:00:49 | [diff] [blame] | 52 | void UpdateLayerInfoVp8(RtpFrameObject* frame, |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 53 | int64_t unwrapped_tl0, |
| 54 | uint8_t temporal_idx); |
philipel | ca18809 | 2021-03-23 11:00:49 | [diff] [blame] | 55 | void UnwrapPictureIds(RtpFrameObject* frame); |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 56 | |
| 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. |
philipel | 342c511 | 2022-03-28 12:30:06 | [diff] [blame] | 68 | std::deque<UnwrappedTl0Frame> stashed_frames_; |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 69 | |
| 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 | |
philipel | 4e70216 | 2020-11-27 16:56:37 | [diff] [blame] | 81 | } // namespace webrtc |
| 82 | |
| 83 | #endif // MODULES_VIDEO_CODING_RTP_VP8_REF_FINDER_H_ |