rtp_packetizer_av1.h 2.4 KB

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