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