OLD | NEW |
(Empty) | |
| 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 #include <vector> |
| 27 |
| 28 #include "webrtc/base/constructormagic.h" |
| 29 #include "webrtc/modules/interface/module_common_types.h" |
| 30 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" |
| 31 #include "webrtc/typedefs.h" |
| 32 |
| 33 namespace webrtc { |
| 34 |
| 35 // Packetizer for VP9. |
| 36 class RtpPacketizerVp9 : public RtpPacketizer { |
| 37 public: |
| 38 // Initialize without fragmentation info. Mode kEqualSize will be used. |
| 39 // The payload_data must be exactly one encoded VP9 frame. |
| 40 RtpPacketizerVp9(const RTPVideoHeaderVP9& hdr, size_t max_payload_len); |
| 41 |
| 42 virtual ~RtpPacketizerVp9(); |
| 43 |
| 44 void SetPayloadData(const uint8_t* payload_data, |
| 45 size_t payload_size, |
| 46 const RTPFragmentationHeader* fragmentation) override; |
| 47 |
| 48 // Get the next payload with VP9 payload header. |
| 49 // |buffer| is a pointer to where the output will be written. |
| 50 // |bytes_to_send| is an output variable that will contain number of bytes |
| 51 // written to buffer. Parameter |last_packet| is true for the last packet of |
| 52 // the frame, false otherwise (i.e. call the function again to get the |
| 53 // next packet). |
| 54 // Returns true on success, false otherwise. |
| 55 bool NextPacket(uint8_t* buffer, |
| 56 size_t* bytes_to_send, |
| 57 bool* last_packet) override; |
| 58 |
| 59 ProtectionType GetProtectionType() override; |
| 60 |
| 61 StorageType GetStorageType(uint32_t retransmission_settings) override; |
| 62 |
| 63 std::string ToString() override; |
| 64 |
| 65 typedef struct { |
| 66 size_t payload_start_pos; |
| 67 size_t size; |
| 68 bool layer_begin; |
| 69 bool layer_end; |
| 70 } InfoStruct; |
| 71 typedef std::queue<InfoStruct> InfoQueue; |
| 72 |
| 73 private: |
| 74 // Calculate size of next chunk to send. Returns 0 if none can be sent. |
| 75 size_t CalcNextSize(size_t max_payload_len, size_t remaining_bytes) const; |
| 76 |
| 77 // Calculate all packet sizes and load to packet info queue. |
| 78 void GeneratePackets(); |
| 79 |
| 80 // Write the payload header and copy the payload to the |buffer|. |
| 81 // |packet_info| determines which part of the payload to write. |
| 82 // |bytes_to_send| contains the number of written bytes to the buffer. |
| 83 // Returns true on success, false otherwise. |
| 84 bool WriteHeaderAndPayload(const InfoStruct& packet_info, |
| 85 uint8_t* buffer, |
| 86 size_t* bytes_to_send) const; |
| 87 |
| 88 // Write payload descriptor to |buffer|. |
| 89 // Returns true on success, false otherwise. |
| 90 bool WriteHeader(const InfoStruct& packet_info, |
| 91 uint8_t* buffer, |
| 92 size_t* extension_length) const; |
| 93 |
| 94 const uint8_t* payload_data_; |
| 95 size_t payload_size_; |
| 96 const bool balance_; |
| 97 const RTPVideoHeaderVP9 hdr_; |
| 98 const size_t max_payload_len_; |
| 99 InfoQueue packets_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp9); |
| 102 }; |
| 103 |
| 104 // Depacketizer for VP9. |
| 105 class RtpDepacketizerVp9 : public RtpDepacketizer { |
| 106 public: |
| 107 virtual ~RtpDepacketizerVp9() {} |
| 108 |
| 109 bool Parse(ParsedPayload* parsed_payload, |
| 110 const uint8_t* payload_data, |
| 111 size_t payload_data_length) override; |
| 112 }; |
| 113 } // namespace webrtc |
| 114 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP9_H_ |
OLD | NEW |