blob: 9ce63cd8a48aad023ce6bcc7bf73e175cde1ede2 [file] [log] [blame]
philipel02447bc2016-05-13 06:01:03 -07001/*
2 * Copyright (c) 2016 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_
12#define MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_
philipel02447bc2016-05-13 06:01:03 -070013
kwibergfd8be342016-05-14 19:44:11 -070014#include <memory>
philipel02447bc2016-05-13 06:01:03 -070015
philipel4e702162020-11-27 17:56:37 +010016#include "modules/video_coding/frame_object.h"
philipel02447bc2016-05-13 06:01:03 -070017
18namespace webrtc {
philipel4e702162020-11-27 17:56:37 +010019namespace internal {
20class RtpFrameReferenceFinderImpl;
21} // namespace internal
philipel17deeb42016-08-11 15:09:26 +020022
philipel02447bc2016-05-13 06:01:03 -070023class RtpFrameReferenceFinder {
24 public:
philipelca188092021-03-23 12:00:49 +010025 using ReturnVector = absl::InlinedVector<std::unique_ptr<RtpFrameObject>, 3>;
philipel4e702162020-11-27 17:56:37 +010026
philipel21820962021-05-25 15:35:57 +020027 RtpFrameReferenceFinder();
28 explicit RtpFrameReferenceFinder(int64_t picture_id_offset);
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020029 ~RtpFrameReferenceFinder();
philipel463d3012016-09-09 03:32:44 -070030
philipel21820962021-05-25 15:35:57 +020031 // The RtpFrameReferenceFinder will hold onto the frame until:
32 // - the required information to determine its references has been received,
33 // in which case it (and possibly other) frames are returned, or
Artem Titovdcd7fc72021-08-09 13:02:57 +020034 // - There are too many stashed frames (determined by `kMaxStashedFrames`),
philipel21820962021-05-25 15:35:57 +020035 // in which case it gets dropped, or
36 // - It gets cleared by ClearTo, in which case its dropped.
37 // - The frame is old, in which case it also gets dropped.
38 ReturnVector ManageFrame(std::unique_ptr<RtpFrameObject> frame);
philipel463d3012016-09-09 03:32:44 -070039
40 // Notifies that padding has been received, which the reference finder
41 // might need to calculate the references of a frame.
philipel21820962021-05-25 15:35:57 +020042 ReturnVector PaddingReceived(uint16_t seq_num);
philipel02447bc2016-05-13 06:01:03 -070043
Artem Titovdcd7fc72021-08-09 13:02:57 +020044 // Clear all stashed frames that include packets older than `seq_num`.
philipel463d3012016-09-09 03:32:44 -070045 void ClearTo(uint16_t seq_num);
46
philipel02447bc2016-05-13 06:01:03 -070047 private:
philipel21820962021-05-25 15:35:57 +020048 void AddPictureIdOffset(ReturnVector& frames);
philipel02447bc2016-05-13 06:01:03 -070049
philipel4e702162020-11-27 17:56:37 +010050 // How far frames have been cleared out of the buffer by RTP sequence number.
51 // A frame will be cleared if it contains a packet with a sequence number
Artem Titovdcd7fc72021-08-09 13:02:57 +020052 // older than `cleared_to_seq_num_`.
philipel4e702162020-11-27 17:56:37 +010053 int cleared_to_seq_num_ = -1;
philipel7acc4a42019-09-26 11:25:52 +020054 const int64_t picture_id_offset_;
philipel4e702162020-11-27 17:56:37 +010055 std::unique_ptr<internal::RtpFrameReferenceFinderImpl> impl_;
philipel02447bc2016-05-13 06:01:03 -070056};
57
philipel02447bc2016-05-13 06:01:03 -070058} // namespace webrtc
59
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#endif // MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_