blob: c7ee07e215e5df83f6bab05fd59bb1e11bc461b2 [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 {
19namespace video_coding {
philipel4e702162020-11-27 17:56:37 +010020namespace internal {
21class RtpFrameReferenceFinderImpl;
22} // namespace internal
philipel17deeb42016-08-11 15:09:26 +020023
24// A complete frame is a frame which has received all its packets and all its
25// references are known.
26class OnCompleteFrameCallback {
27 public:
28 virtual ~OnCompleteFrameCallback() {}
philipele7c891f2018-02-22 14:35:06 +010029 virtual void OnCompleteFrame(std::unique_ptr<EncodedFrame> frame) = 0;
philipel17deeb42016-08-11 15:09:26 +020030};
philipel02447bc2016-05-13 06:01:03 -070031
32class RtpFrameReferenceFinder {
33 public:
philipel4e702162020-11-27 17:56:37 +010034 using ReturnVector = absl::InlinedVector<std::unique_ptr<RtpFrameObject>, 3>;
35
philipel02447bc2016-05-13 06:01:03 -070036 explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback);
philipel7acc4a42019-09-26 11:25:52 +020037 explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback,
38 int64_t picture_id_offset);
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020039 ~RtpFrameReferenceFinder();
philipel463d3012016-09-09 03:32:44 -070040
41 // Manage this frame until:
42 // - We have all information needed to determine its references, after
43 // which |frame_callback_| is called with the completed frame, or
philipelafcf7f52017-04-26 08:17:35 -070044 // - We have too many stashed frames (determined by |kMaxStashedFrames|)
philipel463d3012016-09-09 03:32:44 -070045 // so we drop this frame, or
46 // - It gets cleared by ClearTo, which also means we drop it.
philipel02447bc2016-05-13 06:01:03 -070047 void ManageFrame(std::unique_ptr<RtpFrameObject> frame);
philipel463d3012016-09-09 03:32:44 -070048
49 // Notifies that padding has been received, which the reference finder
50 // might need to calculate the references of a frame.
philipel9b2ce6b2016-07-05 05:04:46 -070051 void PaddingReceived(uint16_t seq_num);
philipel02447bc2016-05-13 06:01:03 -070052
philipel463d3012016-09-09 03:32:44 -070053 // Clear all stashed frames that include packets older than |seq_num|.
54 void ClearTo(uint16_t seq_num);
55
philipel02447bc2016-05-13 06:01:03 -070056 private:
philipel4e702162020-11-27 17:56:37 +010057 void HandOffFrames(ReturnVector frames);
philipel02447bc2016-05-13 06:01:03 -070058
philipel4e702162020-11-27 17:56:37 +010059 // How far frames have been cleared out of the buffer by RTP sequence number.
60 // A frame will be cleared if it contains a packet with a sequence number
61 // older than |cleared_to_seq_num_|.
62 int cleared_to_seq_num_ = -1;
philipel7acc4a42019-09-26 11:25:52 +020063 const int64_t picture_id_offset_;
philipel4e702162020-11-27 17:56:37 +010064 OnCompleteFrameCallback* frame_callback_;
65 std::unique_ptr<internal::RtpFrameReferenceFinderImpl> impl_;
philipel02447bc2016-05-13 06:01:03 -070066};
67
68} // namespace video_coding
69} // namespace webrtc
70
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020071#endif // MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_