1 /* 2 * Copyright (c) 2019 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_AV1_H_ 12 #define MODULES_RTP_RTCP_SOURCE_RTP_PACKETIZER_AV1_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <vector> 18 19 #include "api/array_view.h" 20 #include "api/video/video_frame_type.h" 21 #include "modules/rtp_rtcp/source/rtp_format.h" 22 23 namespace webrtc { 24 25 class RtpPacketizerAv1 : public RtpPacketizer { 26 public: 27 RtpPacketizerAv1(rtc::ArrayView<const uint8_t> payload, 28 PayloadSizeLimits limits, 29 VideoFrameType frame_type); 30 ~RtpPacketizerAv1() override = default; 31 NumPackets()32 size_t NumPackets() const override { return packets_.size() - packet_index_; } 33 bool NextPacket(RtpPacketToSend* packet) override; 34 35 private: 36 struct Obu { 37 uint8_t header; 38 uint8_t extension_header; // undefined if (header & kXbit) == 0 39 rtc::ArrayView<const uint8_t> payload; 40 int size; // size of the header and payload combined. 41 }; 42 struct Packet { PacketPacket43 explicit Packet(int first_obu_index) : first_obu(first_obu_index) {} 44 // Indexes into obus_ vector of the first and last obus that should put into 45 // the packet. 46 int first_obu; 47 int num_obu_elements = 0; 48 int first_obu_offset = 0; 49 int last_obu_size; 50 // Total size consumed by the packet. 51 int packet_size = 0; 52 }; 53 54 // Parses the payload into serie of OBUs. 55 static std::vector<Obu> ParseObus(rtc::ArrayView<const uint8_t> payload); 56 // Returns the number of additional bytes needed to store the previous OBU 57 // element if an additonal OBU element is added to the packet. 58 static int AdditionalBytesForPreviousObuElement(const Packet& packet); 59 static std::vector<Packet> Packetize(rtc::ArrayView<const Obu> obus, 60 PayloadSizeLimits limits); 61 uint8_t AggregationHeader() const; 62 63 const VideoFrameType frame_type_; 64 const std::vector<Obu> obus_; 65 const std::vector<Packet> packets_; 66 size_t packet_index_ = 0; 67 }; 68 69 } // namespace webrtc 70 #endif // MODULES_RTP_RTCP_SOURCE_RTP_PACKETIZER_AV1_H_ 71