1 /* 2 * Copyright (c) 2013 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_FORMAT_VIDEO_GENERIC_H_ 11 #define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VIDEO_GENERIC_H_ 12 13 #include <stdint.h> 14 15 #include <vector> 16 17 #include "api/array_view.h" 18 #include "modules/rtp_rtcp/source/rtp_format.h" 19 20 namespace webrtc { 21 22 class RtpPacketToSend; 23 struct RTPVideoHeader; 24 25 namespace RtpFormatVideoGeneric { 26 static const uint8_t kKeyFrameBit = 0x01; 27 static const uint8_t kFirstPacketBit = 0x02; 28 // If this bit is set, there will be an extended header contained in this 29 // packet. This was added later so old clients will not send this. 30 static const uint8_t kExtendedHeaderBit = 0x04; 31 } // namespace RtpFormatVideoGeneric 32 33 class RtpPacketizerGeneric : public RtpPacketizer { 34 public: 35 // Initialize with payload from encoder. 36 // The payload_data must be exactly one encoded generic frame. 37 // Packets returned by `NextPacket` will contain the generic payload header. 38 RtpPacketizerGeneric(rtc::ArrayView<const uint8_t> payload, 39 PayloadSizeLimits limits, 40 const RTPVideoHeader& rtp_video_header); 41 // Initialize with payload from encoder. 42 // The payload_data must be exactly one encoded generic frame. 43 // Packets returned by `NextPacket` will contain raw payload without the 44 // generic payload header. 45 RtpPacketizerGeneric(rtc::ArrayView<const uint8_t> payload, 46 PayloadSizeLimits limits); 47 48 ~RtpPacketizerGeneric() override; 49 50 RtpPacketizerGeneric(const RtpPacketizerGeneric&) = delete; 51 RtpPacketizerGeneric& operator=(const RtpPacketizerGeneric&) = delete; 52 53 size_t NumPackets() const override; 54 55 // Get the next payload. 56 // Write payload and set marker bit of the `packet`. 57 // Returns true on success, false otherwise. 58 bool NextPacket(RtpPacketToSend* packet) override; 59 60 private: 61 // Fills header_ and header_size_ members. 62 void BuildHeader(const RTPVideoHeader& rtp_video_header); 63 64 uint8_t header_[3]; 65 size_t header_size_; 66 rtc::ArrayView<const uint8_t> remaining_payload_; 67 std::vector<int> payload_sizes_; 68 std::vector<int>::const_iterator current_packet_; 69 }; 70 } // namespace webrtc 71 #endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VIDEO_GENERIC_H_ 72