philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |
| 12 | #define MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 13 | |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 14 | #include <memory> |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 15 | |
philipel | 4e70216 | 2020-11-27 17:56:37 +0100 | [diff] [blame^] | 16 | #include "modules/video_coding/frame_object.h" |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | namespace video_coding { |
philipel | 4e70216 | 2020-11-27 17:56:37 +0100 | [diff] [blame^] | 20 | namespace internal { |
| 21 | class RtpFrameReferenceFinderImpl; |
| 22 | } // namespace internal |
philipel | 17deeb4 | 2016-08-11 15:09:26 +0200 | [diff] [blame] | 23 | |
| 24 | // A complete frame is a frame which has received all its packets and all its |
| 25 | // references are known. |
| 26 | class OnCompleteFrameCallback { |
| 27 | public: |
| 28 | virtual ~OnCompleteFrameCallback() {} |
philipel | e7c891f | 2018-02-22 14:35:06 +0100 | [diff] [blame] | 29 | virtual void OnCompleteFrame(std::unique_ptr<EncodedFrame> frame) = 0; |
philipel | 17deeb4 | 2016-08-11 15:09:26 +0200 | [diff] [blame] | 30 | }; |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 31 | |
| 32 | class RtpFrameReferenceFinder { |
| 33 | public: |
philipel | 4e70216 | 2020-11-27 17:56:37 +0100 | [diff] [blame^] | 34 | using ReturnVector = absl::InlinedVector<std::unique_ptr<RtpFrameObject>, 3>; |
| 35 | |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 36 | explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback); |
philipel | 7acc4a4 | 2019-09-26 11:25:52 +0200 | [diff] [blame] | 37 | explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback, |
| 38 | int64_t picture_id_offset); |
Mirko Bonadei | 8fdcac3 | 2018-08-28 16:30:18 +0200 | [diff] [blame] | 39 | ~RtpFrameReferenceFinder(); |
philipel | 463d301 | 2016-09-09 03:32:44 -0700 | [diff] [blame] | 40 | |
| 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 |
philipel | afcf7f5 | 2017-04-26 08:17:35 -0700 | [diff] [blame] | 44 | // - We have too many stashed frames (determined by |kMaxStashedFrames|) |
philipel | 463d301 | 2016-09-09 03:32:44 -0700 | [diff] [blame] | 45 | // so we drop this frame, or |
| 46 | // - It gets cleared by ClearTo, which also means we drop it. |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 47 | void ManageFrame(std::unique_ptr<RtpFrameObject> frame); |
philipel | 463d301 | 2016-09-09 03:32:44 -0700 | [diff] [blame] | 48 | |
| 49 | // Notifies that padding has been received, which the reference finder |
| 50 | // might need to calculate the references of a frame. |
philipel | 9b2ce6b | 2016-07-05 05:04:46 -0700 | [diff] [blame] | 51 | void PaddingReceived(uint16_t seq_num); |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 52 | |
philipel | 463d301 | 2016-09-09 03:32:44 -0700 | [diff] [blame] | 53 | // Clear all stashed frames that include packets older than |seq_num|. |
| 54 | void ClearTo(uint16_t seq_num); |
| 55 | |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 56 | private: |
philipel | 4e70216 | 2020-11-27 17:56:37 +0100 | [diff] [blame^] | 57 | void HandOffFrames(ReturnVector frames); |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 58 | |
philipel | 4e70216 | 2020-11-27 17:56:37 +0100 | [diff] [blame^] | 59 | // 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; |
philipel | 7acc4a4 | 2019-09-26 11:25:52 +0200 | [diff] [blame] | 63 | const int64_t picture_id_offset_; |
philipel | 4e70216 | 2020-11-27 17:56:37 +0100 | [diff] [blame^] | 64 | OnCompleteFrameCallback* frame_callback_; |
| 65 | std::unique_ptr<internal::RtpFrameReferenceFinderImpl> impl_; |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace video_coding |
| 69 | } // namespace webrtc |
| 70 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 71 | #endif // MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |