1 /* 2 * Copyright (c) 2011 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 /* 12 * This file contains the declaration of the VP8 packetizer class. 13 * A packetizer object is created for each encoded video frame. The 14 * constructor is called with the payload data and size, 15 * together with the fragmentation information and a packetizer mode 16 * of choice. Alternatively, if no fragmentation info is available, the 17 * second constructor can be used with only payload data and size; in that 18 * case the mode kEqualSize is used. 19 * 20 * After creating the packetizer, the method NextPacket is called 21 * repeatedly to get all packets for the frame. The method returns 22 * false as long as there are more packets left to fetch. 23 */ 24 25 #ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ 26 #define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ 27 28 #include <stddef.h> 29 30 #include <cstdint> 31 #include <vector> 32 33 #include "absl/container/inlined_vector.h" 34 #include "api/array_view.h" 35 #include "modules/rtp_rtcp/source/rtp_format.h" 36 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" 37 #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" 38 39 namespace webrtc { 40 41 // Packetizer for VP8. 42 class RtpPacketizerVp8 : public RtpPacketizer { 43 public: 44 // Initialize with payload from encoder. 45 // The payload_data must be exactly one encoded VP8 frame. 46 RtpPacketizerVp8(rtc::ArrayView<const uint8_t> payload, 47 PayloadSizeLimits limits, 48 const RTPVideoHeaderVP8& hdr_info); 49 50 ~RtpPacketizerVp8() override; 51 52 RtpPacketizerVp8(const RtpPacketizerVp8&) = delete; 53 RtpPacketizerVp8& operator=(const RtpPacketizerVp8&) = delete; 54 55 size_t NumPackets() const override; 56 57 // Get the next payload with VP8 payload header. 58 // Write payload and set marker bit of the `packet`. 59 // Returns true on success, false otherwise. 60 bool NextPacket(RtpPacketToSend* packet) override; 61 62 private: 63 // VP8 header can use up to 6 bytes. 64 using RawHeader = absl::InlinedVector<uint8_t, 6>; 65 static RawHeader BuildHeader(const RTPVideoHeaderVP8& header); 66 67 RawHeader hdr_; 68 rtc::ArrayView<const uint8_t> remaining_payload_; 69 std::vector<int> payload_sizes_; 70 std::vector<int>::const_iterator current_packet_; 71 }; 72 73 } // namespace webrtc 74 #endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ 75