tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtp_packetizer_av1.h (2711B)


      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(ArrayView<const uint8_t> payload,
     28                   PayloadSizeLimits limits,
     29                   VideoFrameType frame_type,
     30                   bool is_last_frame_in_picture);
     31  ~RtpPacketizerAv1() override = default;
     32 
     33  size_t NumPackets() const override { return packets_.size() - packet_index_; }
     34  bool NextPacket(RtpPacketToSend* packet) override;
     35 
     36 private:
     37  struct Obu {
     38    uint8_t header;
     39    uint8_t extension_header;  // undefined if (header & kXbit) == 0
     40    ArrayView<const uint8_t> payload;
     41    int size;  // size of the header and payload combined.
     42  };
     43  struct Packet {
     44    explicit Packet(int first_obu_index) : first_obu(first_obu_index) {}
     45    // Indexes into obus_ vector of the first and last obus that should put into
     46    // the packet.
     47    int first_obu;
     48    int num_obu_elements = 0;
     49    int first_obu_offset = 0;
     50    int last_obu_size;
     51    // Total size consumed by the packet.
     52    int packet_size = 0;
     53  };
     54 
     55  // Parses the payload into serie of OBUs.
     56  static std::vector<Obu> ParseObus(ArrayView<const uint8_t> payload);
     57  // Returns the number of additional bytes needed to store the previous OBU
     58  // element if an additonal OBU element is added to the packet.
     59  static int AdditionalBytesForPreviousObuElement(const Packet& packet);
     60  static std::vector<Packet> PacketizeInternal(ArrayView<const Obu> obus,
     61                                               PayloadSizeLimits limits);
     62  // Packetize and try to distribute the payload evenly across packets.
     63  static std::vector<Packet> Packetize(ArrayView<const Obu> obus,
     64                                       PayloadSizeLimits limits);
     65 
     66  uint8_t AggregationHeader() const;
     67 
     68  const VideoFrameType frame_type_;
     69  const std::vector<Obu> obus_;
     70  const std::vector<Packet> packets_;
     71  const bool is_last_frame_in_picture_;
     72  size_t packet_index_ = 0;
     73 };
     74 
     75 }  // namespace webrtc
     76 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_PACKETIZER_AV1_H_