Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h

Issue 2871173008: Fix packetization logic to leave space for extensions in the last packet (Closed)
Patch Set: Implemented danilchap@ comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
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 { 88 enum AggregationMode {
89 kAggrNone = 0, // No aggregation. 89 kAggrNone = 0, // No aggregation.
90 kAggrPartitions, // Aggregate intact partitions. 90 kAggrPartitions, // Aggregate intact partitions.
91 kAggrFragments // Aggregate intact and fragmented partitions. 91 kAggrFragments // Aggregate intact and fragmented partitions.
92 }; 92 };
93 93
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; 94 static const int kXBit = 0x80;
98 static const int kNBit = 0x20; 95 static const int kNBit = 0x20;
99 static const int kSBit = 0x10; 96 static const int kSBit = 0x10;
100 static const int kPartIdField = 0x0F; 97 static const int kPartIdField = 0x0F;
101 static const int kKeyIdxField = 0x1F; 98 static const int kKeyIdxField = 0x1F;
102 static const int kIBit = 0x80; 99 static const int kIBit = 0x80;
103 static const int kLBit = 0x40; 100 static const int kLBit = 0x40;
104 static const int kTBit = 0x20; 101 static const int kTBit = 0x20;
105 static const int kKBit = 0x10; 102 static const int kKBit = 0x10;
106 static const int kYBit = 0x20; 103 static const int kYBit = 0x20;
107 104
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. 105 // Calculate all packet sizes and load to packet info queue.
114 int GeneratePackets(); 106 int GeneratePackets();
115 107
116 // Calculate all packet sizes using Vp8PartitionAggregator and load to packet 108 // Helper function which splits given part of payload (one or more partitions)
117 // info queue. 109 // to packets with a given capacity. If |last| flag is set then the packet
118 int GeneratePacketsBalancedAggregates(); 110 // should be reduced by last_packet_reduction_len_.
111 void SplitPayloadBalanced(size_t payload_offset,
112 size_t payload_len,
113 size_t capacity,
114 bool last,
115 size_t part_ix);
119 116
120 // Helper function to GeneratePacketsBalancedAggregates(). Find all 117 // Helper function. Aggregates partitions starting at |part_ix| to packets of
121 // continuous sets of partitions smaller than the max payload size (not 118 // given capacity. Last packet, if containing last partition of the frame
122 // max_size), and aggregate them into balanced packets. The result is written 119 // should be reduced by last_packet_reduction_len_.
123 // to partition_vec, which is of the same length as the number of partitions. 120 // Returns the first unaggregated partition index.
124 // A value of -1 indicates that the partition is too large and must be split. 121 size_t AgregatePartitions(size_t part_ix, size_t capacity);
sprang_webrtc 2017/05/17 13:10:07 nit: AggregatePartitions
ilnik 2017/05/17 15:06:34 Done.
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 122
133 // Insert packet into packet queue. 123 // Insert packet into packet queue.
134 void QueuePacket(size_t start_pos, 124 void QueuePacket(size_t start_pos,
135 size_t packet_size, 125 size_t packet_size,
136 size_t first_partition_in_packet, 126 size_t first_partition_in_packet,
137 bool start_on_new_fragment); 127 bool start_on_new_fragment);
138 128
139 // Write the payload header and copy the payload to the buffer. 129 // 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 130 // The info in packet_info determines which part of the payload is written
141 // and what to write in the header fields. 131 // and what to write in the header fields.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 bool TIDFieldPresent() const; 178 bool TIDFieldPresent() const;
189 bool KeyIdxFieldPresent() const; 179 bool KeyIdxFieldPresent() const;
190 bool TL0PicIdxFieldPresent() const; 180 bool TL0PicIdxFieldPresent() const;
191 bool PictureIdPresent() const { return (PictureIdLength() > 0); } 181 bool PictureIdPresent() const { return (PictureIdLength() > 0); }
192 182
193 const uint8_t* payload_data_; 183 const uint8_t* payload_data_;
194 size_t payload_size_; 184 size_t payload_size_;
195 RTPFragmentationHeader part_info_; 185 RTPFragmentationHeader part_info_;
196 const size_t vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload 186 const size_t vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload
197 // descriptors' fixed part. 187 // descriptors' fixed part.
198 const AggregationMode aggr_mode_; 188 const VP8PacketizerMode mode_;
199 const bool balance_;
200 const bool separate_first_;
201 const RTPVideoHeaderVP8 hdr_info_; 189 const RTPVideoHeaderVP8 hdr_info_;
202 size_t num_partitions_; 190 size_t num_partitions_;
203 const size_t max_payload_len_; 191 const size_t max_payload_len_;
192 const size_t last_packet_reduction_len_;
204 InfoQueue packets_; 193 InfoQueue packets_;
205 bool packets_calculated_;
206 194
207 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8); 195 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8);
208 }; 196 };
209 197
210 // Depacketizer for VP8. 198 // Depacketizer for VP8.
211 class RtpDepacketizerVp8 : public RtpDepacketizer { 199 class RtpDepacketizerVp8 : public RtpDepacketizer {
212 public: 200 public:
213 virtual ~RtpDepacketizerVp8() {} 201 virtual ~RtpDepacketizerVp8() {}
214 202
215 bool Parse(ParsedPayload* parsed_payload, 203 bool Parse(ParsedPayload* parsed_payload,
216 const uint8_t* payload_data, 204 const uint8_t* payload_data,
217 size_t payload_data_length) override; 205 size_t payload_data_length) override;
218 }; 206 };
219 } // namespace webrtc 207 } // namespace webrtc
220 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ 208 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698