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

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: Impelement 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
70 // otherwise (i.e., call the function again to get the next packet).
71 // Returns true on success, false otherwise. 72 // Returns true on success, false otherwise.
72 bool NextPacket(RtpPacketToSend* packet, bool* last_packet) override; 73 bool NextPacket(RtpPacketToSend* packet) override;
73 74
74 ProtectionType GetProtectionType() override; 75 ProtectionType GetProtectionType() override;
75 76
76 StorageType GetStorageType(uint32_t retransmission_settings) override; 77 StorageType GetStorageType(uint32_t retransmission_settings) override;
77 78
78 std::string ToString() override; 79 std::string ToString() override;
79 80
80 private: 81 private:
81 typedef struct { 82 typedef struct {
82 size_t payload_start_pos; 83 size_t payload_start_pos;
83 size_t size; 84 size_t size;
84 bool first_fragment; 85 bool first_fragment;
85 size_t first_partition_ix; 86 size_t first_partition_ix;
86 } InfoStruct; 87 } InfoStruct;
87 typedef std::queue<InfoStruct> InfoQueue; 88 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 89
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; 90 static const int kXBit = 0x80;
98 static const int kNBit = 0x20; 91 static const int kNBit = 0x20;
99 static const int kSBit = 0x10; 92 static const int kSBit = 0x10;
100 static const int kPartIdField = 0x0F; 93 static const int kPartIdField = 0x0F;
101 static const int kKeyIdxField = 0x1F; 94 static const int kKeyIdxField = 0x1F;
102 static const int kIBit = 0x80; 95 static const int kIBit = 0x80;
103 static const int kLBit = 0x40; 96 static const int kLBit = 0x40;
104 static const int kTBit = 0x20; 97 static const int kTBit = 0x20;
105 static const int kKBit = 0x10; 98 static const int kKBit = 0x10;
106 static const int kYBit = 0x20; 99 static const int kYBit = 0x20;
107 100
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. 101 // Calculate all packet sizes and load to packet info queue.
114 int GeneratePackets(); 102 int GeneratePackets();
115 103
116 // Calculate all packet sizes using Vp8PartitionAggregator and load to packet 104 // Splits given part of payload (one or more partitions)
117 // info queue. 105 // to packets with a given capacity. If |last_partition| flag is set then the
118 int GeneratePacketsBalancedAggregates(); 106 // last packet should be reduced by last_packet_reduction_len_.
107 void GeneratePacketsSplitPayloadBalanced(size_t payload_offset,
108 size_t payload_len,
109 size_t capacity,
110 bool last_partition,
111 size_t part_idx);
119 112
120 // Helper function to GeneratePacketsBalancedAggregates(). Find all 113 // Aggregates partitions starting at |part_idx| to packets of
121 // continuous sets of partitions smaller than the max payload size (not 114 // given |capacity|. Last packet, if containing last partition of the frame
122 // max_size), and aggregate them into balanced packets. The result is written 115 // should be reduced by last_packet_reduction_len_.
123 // to partition_vec, which is of the same length as the number of partitions. 116 // Returns the first unaggregated partition index.
124 // A value of -1 indicates that the partition is too large and must be split. 117 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 118
133 // Insert packet into packet queue. 119 // Insert packet into packet queue.
134 void QueuePacket(size_t start_pos, 120 void QueuePacket(size_t start_pos,
135 size_t packet_size, 121 size_t packet_size,
136 size_t first_partition_in_packet, 122 size_t first_partition_in_packet,
137 bool start_on_new_fragment); 123 bool start_on_new_fragment);
138 124
139 // Write the payload header and copy the payload to the buffer. 125 // 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 126 // The info in packet_info determines which part of the payload is written
141 // and what to write in the header fields. 127 // and what to write in the header fields.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 bool TIDFieldPresent() const; 174 bool TIDFieldPresent() const;
189 bool KeyIdxFieldPresent() const; 175 bool KeyIdxFieldPresent() const;
190 bool TL0PicIdxFieldPresent() const; 176 bool TL0PicIdxFieldPresent() const;
191 bool PictureIdPresent() const { return (PictureIdLength() > 0); } 177 bool PictureIdPresent() const { return (PictureIdLength() > 0); }
192 178
193 const uint8_t* payload_data_; 179 const uint8_t* payload_data_;
194 size_t payload_size_; 180 size_t payload_size_;
195 RTPFragmentationHeader part_info_; 181 RTPFragmentationHeader part_info_;
196 const size_t vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload 182 const size_t vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload
197 // descriptors' fixed part. 183 // descriptors' fixed part.
198 const AggregationMode aggr_mode_; 184 const VP8PacketizerMode mode_;
199 const bool balance_;
200 const bool separate_first_;
201 const RTPVideoHeaderVP8 hdr_info_; 185 const RTPVideoHeaderVP8 hdr_info_;
202 size_t num_partitions_; 186 size_t num_partitions_;
203 const size_t max_payload_len_; 187 const size_t max_payload_len_;
188 const size_t last_packet_reduction_len_;
204 InfoQueue packets_; 189 InfoQueue packets_;
205 bool packets_calculated_;
206 190
207 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8); 191 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8);
208 }; 192 };
209 193
210 // Depacketizer for VP8. 194 // Depacketizer for VP8.
211 class RtpDepacketizerVp8 : public RtpDepacketizer { 195 class RtpDepacketizerVp8 : public RtpDepacketizer {
212 public: 196 public:
213 virtual ~RtpDepacketizerVp8() {} 197 virtual ~RtpDepacketizerVp8() {}
214 198
215 bool Parse(ParsedPayload* parsed_payload, 199 bool Parse(ParsedPayload* parsed_payload,
216 const uint8_t* payload_data, 200 const uint8_t* payload_data,
217 size_t payload_data_length) override; 201 size_t payload_data_length) override;
218 }; 202 };
219 } // namespace webrtc 203 } // namespace webrtc
220 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_ 204 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_format_video_generic_unittest.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_format_vp8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698