OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 kNumModes, | 45 kNumModes, |
46 }; | 46 }; |
47 | 47 |
48 // Packetizer for VP8. | 48 // Packetizer for VP8. |
49 class RtpPacketizerVp8 : public RtpPacketizer { | 49 class RtpPacketizerVp8 : public RtpPacketizer { |
50 public: | 50 public: |
51 // Initialize with payload from encoder and fragmentation info. | 51 // Initialize with payload from encoder and fragmentation info. |
52 // The payload_data must be exactly one encoded VP8 frame. | 52 // The payload_data must be exactly one encoded VP8 frame. |
53 RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info, | 53 RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info, |
54 size_t max_payload_len, | 54 size_t max_payload_len, |
55 size_t last_packet_reduction_len, | |
55 VP8PacketizerMode mode); | 56 VP8PacketizerMode mode); |
56 | 57 |
57 // Initialize without fragmentation info. Mode kEqualSize will be used. | 58 // Initialize without fragmentation info. Mode kEqualSize will be used. |
58 // The payload_data must be exactly one encoded VP8 frame. | 59 // The payload_data must be exactly one encoded VP8 frame. |
59 RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info, size_t max_payload_len); | 60 RtpPacketizerVp8(const RTPVideoHeaderVP8& hdr_info, |
61 size_t max_payload_len, | |
62 size_t last_packet_reduction_len); | |
60 | 63 |
61 virtual ~RtpPacketizerVp8(); | 64 virtual ~RtpPacketizerVp8(); |
62 | 65 |
63 void SetPayloadData(const uint8_t* payload_data, | 66 size_t SetPayloadData(const uint8_t* payload_data, |
64 size_t payload_size, | 67 size_t payload_size, |
65 const RTPFragmentationHeader* fragmentation) override; | 68 const RTPFragmentationHeader* fragmentation) override; |
66 | 69 |
67 // Get the next payload with VP8 payload header. | 70 // Get the next payload with VP8 payload header. |
68 // Write payload and set marker bit of the |packet|. | 71 // Write payload and set marker bit of the |packet|. |
69 // The parameter |last_packet| is true for the last packet of the frame, false | 72 bool NextPacket(RtpPacketToSend* packet) override; |
70 // otherwise (i.e., call the function again to get the next packet). | |
71 // Returns true on success, false otherwise. | |
danilchap
2017/05/23 15:55:03
may be do not delete comment about return value.
(
ilnik
2017/05/23 16:14:29
Done.
| |
72 bool NextPacket(RtpPacketToSend* packet, bool* last_packet) override; | |
73 | 73 |
74 ProtectionType GetProtectionType() override; | 74 ProtectionType GetProtectionType() override; |
75 | 75 |
76 StorageType GetStorageType(uint32_t retransmission_settings) override; | 76 StorageType GetStorageType(uint32_t retransmission_settings) override; |
77 | 77 |
78 std::string ToString() override; | 78 std::string ToString() override; |
79 | 79 |
80 private: | 80 private: |
81 typedef struct { | 81 typedef struct { |
82 size_t payload_start_pos; | 82 size_t payload_start_pos; |
83 size_t size; | 83 size_t size; |
84 bool first_fragment; | 84 bool first_fragment; |
85 size_t first_partition_ix; | 85 size_t first_partition_ix; |
86 } InfoStruct; | 86 } InfoStruct; |
87 typedef std::queue<InfoStruct> InfoQueue; | 87 typedef std::queue<InfoStruct> InfoQueue; |
88 enum AggregationMode { | |
89 kAggrNone = 0, // No aggregation. | |
90 kAggrPartitions, // Aggregate intact partitions. | |
91 kAggrFragments // Aggregate intact and fragmented partitions. | |
92 }; | |
93 | 88 |
94 static const AggregationMode aggr_modes_[kNumModes]; | |
95 static const bool balance_modes_[kNumModes]; | |
96 static const bool separate_first_modes_[kNumModes]; | |
97 static const int kXBit = 0x80; | 89 static const int kXBit = 0x80; |
98 static const int kNBit = 0x20; | 90 static const int kNBit = 0x20; |
99 static const int kSBit = 0x10; | 91 static const int kSBit = 0x10; |
100 static const int kPartIdField = 0x0F; | 92 static const int kPartIdField = 0x0F; |
101 static const int kKeyIdxField = 0x1F; | 93 static const int kKeyIdxField = 0x1F; |
102 static const int kIBit = 0x80; | 94 static const int kIBit = 0x80; |
103 static const int kLBit = 0x40; | 95 static const int kLBit = 0x40; |
104 static const int kTBit = 0x20; | 96 static const int kTBit = 0x20; |
105 static const int kKBit = 0x10; | 97 static const int kKBit = 0x10; |
106 static const int kYBit = 0x20; | 98 static const int kYBit = 0x20; |
107 | 99 |
108 // Calculate size of next chunk to send. Returns 0 if none can be sent. | |
109 size_t CalcNextSize(size_t max_payload_len, | |
110 size_t remaining_bytes, | |
111 bool split_payload) const; | |
112 | |
113 // Calculate all packet sizes and load to packet info queue. | 100 // Calculate all packet sizes and load to packet info queue. |
114 int GeneratePackets(); | 101 int GeneratePackets(); |
115 | 102 |
116 // Calculate all packet sizes using Vp8PartitionAggregator and load to packet | 103 // Splits given part of payload (one or more partitions) |
117 // info queue. | 104 // to packets with a given capacity. If |last_partition| flag is set then the |
118 int GeneratePacketsBalancedAggregates(); | 105 // packet should be reduced by last_packet_reduction_len_. |
danilchap
2017/05/23 15:55:03
then the \last/ packet
ilnik
2017/05/23 16:14:29
Done.
| |
106 void GeneratePacketsSplitPayloadBalanced(size_t payload_offset, | |
107 size_t payload_len, | |
108 size_t capacity, | |
109 bool last_partition, | |
110 size_t part_idx); | |
119 | 111 |
120 // Helper function to GeneratePacketsBalancedAggregates(). Find all | 112 // Aggregates partitions starting at |part_idx| to packets of |
121 // continuous sets of partitions smaller than the max payload size (not | 113 // given capacity. Last packet, if containing last partition of the frame |
danilchap
2017/05/23 15:55:03
may be |capacity|
ilnik
2017/05/23 16:14:29
Done.
| |
122 // max_size), and aggregate them into balanced packets. The result is written | 114 // should be reduced by last_packet_reduction_len_. |
123 // to partition_vec, which is of the same length as the number of partitions. | 115 // Returns the first unaggregated partition index. |
124 // A value of -1 indicates that the partition is too large and must be split. | 116 size_t GeneratePacketsAggregatePartitions(size_t part_idx, size_t capacity); |
125 // Aggregates are numbered 0, 1, 2, etc. For each set of small partitions, | |
126 // the aggregate numbers restart at 0. Output values min_size and max_size | |
127 // will hold the smallest and largest resulting aggregates (i.e., not counting | |
128 // those that must be split). | |
129 void AggregateSmallPartitions(std::vector<int>* partition_vec, | |
130 int* min_size, | |
131 int* max_size); | |
132 | 117 |
133 // Insert packet into packet queue. | 118 // Insert packet into packet queue. |
134 void QueuePacket(size_t start_pos, | 119 void QueuePacket(size_t start_pos, |
135 size_t packet_size, | 120 size_t packet_size, |
136 size_t first_partition_in_packet, | 121 size_t first_partition_in_packet, |
137 bool start_on_new_fragment); | 122 bool start_on_new_fragment); |
138 | 123 |
139 // Write the payload header and copy the payload to the buffer. | 124 // Write the payload header and copy the payload to the buffer. |
140 // The info in packet_info determines which part of the payload is written | 125 // The info in packet_info determines which part of the payload is written |
141 // and what to write in the header fields. | 126 // and what to write in the header fields. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 bool TIDFieldPresent() const; | 173 bool TIDFieldPresent() const; |
189 bool KeyIdxFieldPresent() const; | 174 bool KeyIdxFieldPresent() const; |
190 bool TL0PicIdxFieldPresent() const; | 175 bool TL0PicIdxFieldPresent() const; |
191 bool PictureIdPresent() const { return (PictureIdLength() > 0); } | 176 bool PictureIdPresent() const { return (PictureIdLength() > 0); } |
192 | 177 |
193 const uint8_t* payload_data_; | 178 const uint8_t* payload_data_; |
194 size_t payload_size_; | 179 size_t payload_size_; |
195 RTPFragmentationHeader part_info_; | 180 RTPFragmentationHeader part_info_; |
196 const size_t vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload | 181 const size_t vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload |
197 // descriptors' fixed part. | 182 // descriptors' fixed part. |
198 const AggregationMode aggr_mode_; | 183 const VP8PacketizerMode mode_; |
199 const bool balance_; | |
200 const bool separate_first_; | |
201 const RTPVideoHeaderVP8 hdr_info_; | 184 const RTPVideoHeaderVP8 hdr_info_; |
202 size_t num_partitions_; | 185 size_t num_partitions_; |
203 const size_t max_payload_len_; | 186 const size_t max_payload_len_; |
187 const size_t last_packet_reduction_len_; | |
204 InfoQueue packets_; | 188 InfoQueue packets_; |
205 bool packets_calculated_; | |
206 | 189 |
207 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8); | 190 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8); |
208 }; | 191 }; |
209 | 192 |
210 // Depacketizer for VP8. | 193 // Depacketizer for VP8. |
211 class RtpDepacketizerVp8 : public RtpDepacketizer { | 194 class RtpDepacketizerVp8 : public RtpDepacketizer { |
212 public: | 195 public: |
213 virtual ~RtpDepacketizerVp8() {} | 196 virtual ~RtpDepacketizerVp8() {} |
214 | 197 |
215 bool Parse(ParsedPayload* parsed_payload, | 198 bool Parse(ParsedPayload* parsed_payload, |
216 const uint8_t* payload_data, | 199 const uint8_t* payload_data, |
217 size_t payload_data_length) override; | 200 size_t payload_data_length) override; |
218 }; | 201 }; |
219 } // namespace webrtc | 202 } // namespace webrtc |
220 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ | 203 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ |
OLD | NEW |