1 /* 2 * Copyright (c) 2015 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 VP9 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 // 16 // After creating the packetizer, the method NextPacket is called 17 // repeatedly to get all packets for the frame. The method returns 18 // false as long as there are more packets left to fetch. 19 // 20 21 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP9_H_ 22 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP9_H_ 23 24 #include <queue> 25 #include <string> 26 27 #include "webrtc/base/constructormagic.h" 28 #include "webrtc/modules/include/module_common_types.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" 30 #include "webrtc/typedefs.h" 31 32 namespace webrtc { 33 34 class RtpPacketizerVp9 : public RtpPacketizer { 35 public: 36 RtpPacketizerVp9(const RTPVideoHeaderVP9& hdr, size_t max_payload_length); 37 38 virtual ~RtpPacketizerVp9(); 39 40 ProtectionType GetProtectionType() override; 41 42 StorageType GetStorageType(uint32_t retransmission_settings) override; 43 44 std::string ToString() override; 45 46 // The payload data must be one encoded VP9 frame. 47 void SetPayloadData(const uint8_t* payload, 48 size_t payload_size, 49 const RTPFragmentationHeader* fragmentation) override; 50 51 // Gets the next payload with VP9 payload header. 52 // Write payload and set marker bit of the |packet|. 53 // The parameter |last_packet| is true for the last packet of the frame, false 54 // otherwise (i.e., call the function again to get the next packet). 55 // Returns true on success, false otherwise. 56 bool NextPacket(RtpPacketToSend* packet, bool* last_packet) override; 57 58 typedef struct { 59 size_t payload_start_pos; 60 size_t size; 61 bool layer_begin; 62 bool layer_end; 63 } PacketInfo; 64 typedef std::queue<PacketInfo> PacketInfoQueue; 65 66 private: 67 // Calculates all packet sizes and loads info to packet queue. 68 void GeneratePackets(); 69 70 // Writes the payload descriptor header and copies payload to the |buffer|. 71 // |packet_info| determines which part of the payload to write. 72 // |bytes_to_send| contains the number of written bytes to the buffer. 73 // Returns true on success, false otherwise. 74 bool WriteHeaderAndPayload(const PacketInfo& packet_info, 75 RtpPacketToSend* packet) const; 76 77 // Writes payload descriptor header to |buffer|. 78 // Returns true on success, false otherwise. 79 bool WriteHeader(const PacketInfo& packet_info, 80 uint8_t* buffer, 81 size_t* header_length) const; 82 83 const RTPVideoHeaderVP9 hdr_; 84 const size_t max_payload_length_; // The max length in bytes of one packet. 85 const uint8_t* payload_; // The payload data to be packetized. 86 size_t payload_size_; // The size in bytes of the payload data. 87 PacketInfoQueue packets_; 88 89 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp9); 90 }; 91 92 93 class RtpDepacketizerVp9 : public RtpDepacketizer { 94 public: ~RtpDepacketizerVp9()95 virtual ~RtpDepacketizerVp9() {} 96 97 bool Parse(ParsedPayload* parsed_payload, 98 const uint8_t* payload, 99 size_t payload_length) override; 100 }; 101 102 } // namespace webrtc 103 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP9_H_ 104