philipel | e9a74c9 | 2021-06-24 14:41:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 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 API_VIDEO_RTP_VIDEO_FRAME_ASSEMBLER_H_ |
| 12 | #define API_VIDEO_RTP_VIDEO_FRAME_ASSEMBLER_H_ |
| 13 | |
| 14 | #include <cstdint> |
| 15 | #include <memory> |
philipel | 6aa61a3 | 2021-10-15 10:57:10 +0200 | [diff] [blame] | 16 | #include <utility> |
philipel | e9a74c9 | 2021-06-24 14:41:23 +0200 | [diff] [blame] | 17 | |
| 18 | #include "absl/container/inlined_vector.h" |
| 19 | #include "api/video/encoded_frame.h" |
| 20 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | // The RtpVideoFrameAssembler takes RtpPacketReceived and assembles them into |
| 24 | // complete frames. A frame is considered complete when all packets of the frame |
| 25 | // has been received, the bitstream data has successfully extracted, an ID has |
| 26 | // been assigned, and all dependencies are known. Frame IDs are strictly |
| 27 | // monotonic in decode order, dependencies are expressed as frame IDs. |
| 28 | class RtpVideoFrameAssembler { |
| 29 | public: |
philipel | 6aa61a3 | 2021-10-15 10:57:10 +0200 | [diff] [blame] | 30 | // The RtpVideoFrameAssembler should return "RTP frames", but for now there |
| 31 | // is no good class for this purpose. For now return an EncodedFrame bundled |
| 32 | // with some minimal RTP information. |
| 33 | class AssembledFrame { |
| 34 | public: |
| 35 | AssembledFrame(uint16_t rtp_seq_num_start, |
| 36 | uint16_t rtp_seq_num_end, |
| 37 | std::unique_ptr<EncodedFrame> frame) |
| 38 | : rtp_seq_num_start_(rtp_seq_num_start), |
| 39 | rtp_seq_num_end_(rtp_seq_num_end), |
| 40 | frame_(std::move(frame)) {} |
| 41 | |
| 42 | uint16_t RtpSeqNumStart() const { return rtp_seq_num_start_; } |
| 43 | uint16_t RtpSeqNumEnd() const { return rtp_seq_num_end_; } |
| 44 | std::unique_ptr<EncodedFrame> ExtractFrame() { return std::move(frame_); } |
| 45 | |
| 46 | private: |
| 47 | uint16_t rtp_seq_num_start_; |
| 48 | uint16_t rtp_seq_num_end_; |
| 49 | std::unique_ptr<EncodedFrame> frame_; |
| 50 | }; |
| 51 | |
philipel | e9a74c9 | 2021-06-24 14:41:23 +0200 | [diff] [blame] | 52 | // FrameVector is just a vector-like type of std::unique_ptr<EncodedFrame>. |
| 53 | // The vector type may change without notice. |
philipel | 6aa61a3 | 2021-10-15 10:57:10 +0200 | [diff] [blame] | 54 | using FrameVector = absl::InlinedVector<AssembledFrame, 3>; |
philipel | e9a74c9 | 2021-06-24 14:41:23 +0200 | [diff] [blame] | 55 | enum PayloadFormat { kRaw, kH264, kVp8, kVp9, kAv1, kGeneric }; |
| 56 | |
| 57 | explicit RtpVideoFrameAssembler(PayloadFormat payload_format); |
| 58 | RtpVideoFrameAssembler(const RtpVideoFrameAssembler& other) = delete; |
| 59 | RtpVideoFrameAssembler& operator=(const RtpVideoFrameAssembler& other) = |
| 60 | delete; |
| 61 | ~RtpVideoFrameAssembler(); |
| 62 | |
| 63 | // Typically when a packet is inserted zero or one frame is completed. In the |
| 64 | // case of RTP packets being inserted out of order then sometime multiple |
| 65 | // frames could be completed from a single packet, hence the 'FrameVector' |
| 66 | // return type. |
| 67 | FrameVector InsertPacket(const RtpPacketReceived& packet); |
| 68 | |
| 69 | private: |
| 70 | class Impl; |
| 71 | std::unique_ptr<Impl> impl_; |
| 72 | }; |
| 73 | |
| 74 | } // namespace webrtc |
| 75 | |
| 76 | #endif // API_VIDEO_RTP_VIDEO_FRAME_ASSEMBLER_H_ |