rtp_packetizer_h265.h (2152B)
1 /* 2 * Copyright (c) 2023 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_RTP_RTCP_SOURCE_RTP_PACKETIZER_H265_H_ 12 #define MODULES_RTP_RTCP_SOURCE_RTP_PACKETIZER_H265_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <deque> 17 #include <queue> 18 19 #include "api/array_view.h" 20 #include "modules/rtp_rtcp/source/rtp_format.h" 21 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" 22 23 namespace webrtc { 24 25 class RtpPacketizerH265 : public RtpPacketizer { 26 public: 27 // Initialize with payload from encoder. 28 // The payload_data must be exactly one encoded H.265 frame. 29 // For H265 we only support tx-mode SRST. 30 RtpPacketizerH265(ArrayView<const uint8_t> payload, PayloadSizeLimits limits); 31 32 RtpPacketizerH265(const RtpPacketizerH265&) = delete; 33 RtpPacketizerH265& operator=(const RtpPacketizerH265&) = delete; 34 35 ~RtpPacketizerH265() override; 36 37 size_t NumPackets() const override; 38 39 // Get the next payload with H.265 payload header. 40 // Write payload and set marker bit of the `packet`. 41 // Returns true on success or false if there was no payload to packetize. 42 bool NextPacket(RtpPacketToSend* rtp_packet) override; 43 44 private: 45 struct PacketUnit { 46 ArrayView<const uint8_t> source_fragment; 47 bool first_fragment = false; 48 bool last_fragment = false; 49 bool aggregated = false; 50 uint16_t header = 0; 51 }; 52 std::deque<ArrayView<const uint8_t>> input_fragments_; 53 std::queue<PacketUnit> packets_; 54 55 bool GeneratePackets(); 56 bool PacketizeFu(size_t fragment_index); 57 int PacketizeAp(size_t fragment_index); 58 59 void NextAggregatePacket(RtpPacketToSend* rtp_packet); 60 void NextFragmentPacket(RtpPacketToSend* rtp_packet); 61 62 const PayloadSizeLimits limits_; 63 size_t num_packets_left_ = 0; 64 }; 65 } // namespace webrtc 66 #endif // MODULES_RTP_RTCP_SOURCE_RTP_PACKETIZER_H265_H_