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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc

Issue 2500743002: Revert of H.264 packetization mode 0 (try 2) (Closed)
Patch Set: Created 4 years, 1 month 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 length_remaining -= nalu_size; 70 length_remaining -= nalu_size;
71 71
72 offsets->push_back(offset + kStapAHeaderSize); 72 offsets->push_back(offset + kStapAHeaderSize);
73 offset += kLengthFieldSize + nalu_size; 73 offset += kLengthFieldSize + nalu_size;
74 } 74 }
75 return true; 75 return true;
76 } 76 }
77 77
78 } // namespace 78 } // namespace
79 79
80 RtpPacketizerH264::RtpPacketizerH264(size_t max_payload_len, 80 RtpPacketizerH264::RtpPacketizerH264(FrameType frame_type,
81 H264PacketizationMode packetization_mode) 81 size_t max_payload_len)
82 : max_payload_len_(max_payload_len), 82 : max_payload_len_(max_payload_len) {}
83 packetization_mode_(packetization_mode) {}
84 83
85 RtpPacketizerH264::~RtpPacketizerH264() { 84 RtpPacketizerH264::~RtpPacketizerH264() {
86 } 85 }
87 86
88 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length) 87 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length)
89 : buffer(buffer), length(length) {} 88 : buffer(buffer), length(length) {}
90 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment) 89 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment)
91 : buffer(fragment.buffer), length(fragment.length) {} 90 : buffer(fragment.buffer), length(fragment.length) {}
92 91
93 void RtpPacketizerH264::SetPayloadData( 92 void RtpPacketizerH264::SetPayloadData(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 155 }
157 156
158 if (!updated_sps) 157 if (!updated_sps)
159 input_fragments_.push_back(Fragment(buffer, length)); 158 input_fragments_.push_back(Fragment(buffer, length));
160 } 159 }
161 GeneratePackets(); 160 GeneratePackets();
162 } 161 }
163 162
164 void RtpPacketizerH264::GeneratePackets() { 163 void RtpPacketizerH264::GeneratePackets() {
165 for (size_t i = 0; i < input_fragments_.size();) { 164 for (size_t i = 0; i < input_fragments_.size();) {
166 if (packetization_mode_ == kH264PacketizationMode0) { 165 if (input_fragments_[i].length > max_payload_len_) {
167 PacketizeSingleNalu(i); 166 PacketizeFuA(i);
168 ++i; 167 ++i;
169 } else { 168 } else {
170 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1); 169 i = PacketizeStapA(i);
171 if (input_fragments_[i].length > max_payload_len_) {
172 PacketizeFuA(i);
173 ++i;
174 } else {
175 i = PacketizeStapA(i);
176 }
177 } 170 }
178 } 171 }
179 } 172 }
180 173
181 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) { 174 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) {
182 // Fragment payload into packets (FU-A). 175 // Fragment payload into packets (FU-A).
183 // Strip out the original header and leave room for the FU-A header. 176 // Strip out the original header and leave room for the FU-A header.
184 const Fragment& fragment = input_fragments_[fragment_index]; 177 const Fragment& fragment = input_fragments_[fragment_index];
185 178
186 size_t fragment_length = fragment.length - kNalHeaderSize; 179 size_t fragment_length = fragment.length - kNalHeaderSize;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // we need to add the STAP-A NALU header and a length field for the first 222 // we need to add the STAP-A NALU header and a length field for the first
230 // NALU of this packet. 223 // NALU of this packet.
231 if (aggregated_fragments == 0) 224 if (aggregated_fragments == 0)
232 fragment_headers_length += kNalHeaderSize + kLengthFieldSize; 225 fragment_headers_length += kNalHeaderSize + kLengthFieldSize;
233 ++aggregated_fragments; 226 ++aggregated_fragments;
234 } 227 }
235 packets_.back().last_fragment = true; 228 packets_.back().last_fragment = true;
236 return fragment_index; 229 return fragment_index;
237 } 230 }
238 231
239 void RtpPacketizerH264::PacketizeSingleNalu(size_t fragment_index) {
240 // Add a single NALU to the queue, no aggregation.
241 size_t payload_size_left = max_payload_len_;
242 const Fragment* fragment = &input_fragments_[fragment_index];
243 RTC_CHECK_GE(payload_size_left, fragment->length);
244 RTC_CHECK_GT(fragment->length, 0u);
245 packets_.push(PacketUnit(*fragment, true /* first */, true /* last */,
246 false /* aggregated */, fragment->buffer[0]));
247 }
248
249 bool RtpPacketizerH264::NextPacket(uint8_t* buffer, 232 bool RtpPacketizerH264::NextPacket(uint8_t* buffer,
250 size_t* bytes_to_send, 233 size_t* bytes_to_send,
251 bool* last_packet) { 234 bool* last_packet) {
252 *bytes_to_send = 0; 235 *bytes_to_send = 0;
253 if (packets_.empty()) { 236 if (packets_.empty()) {
254 *bytes_to_send = 0; 237 *bytes_to_send = 0;
255 *last_packet = true; 238 *last_packet = true;
256 return false; 239 return false;
257 } 240 }
258 241
259 PacketUnit packet = packets_.front(); 242 PacketUnit packet = packets_.front();
260 243
261 if (packet.first_fragment && packet.last_fragment) { 244 if (packet.first_fragment && packet.last_fragment) {
262 // Single NAL unit packet. 245 // Single NAL unit packet.
263 *bytes_to_send = packet.source_fragment.length; 246 *bytes_to_send = packet.source_fragment.length;
264 memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send); 247 memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send);
265 packets_.pop(); 248 packets_.pop();
266 input_fragments_.pop_front(); 249 input_fragments_.pop_front();
267 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); 250 RTC_CHECK_LE(*bytes_to_send, max_payload_len_);
268 } else if (packet.aggregated) { 251 } else if (packet.aggregated) {
269 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1);
270 NextAggregatePacket(buffer, bytes_to_send); 252 NextAggregatePacket(buffer, bytes_to_send);
271 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); 253 RTC_CHECK_LE(*bytes_to_send, max_payload_len_);
272 } else { 254 } else {
273 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1);
274 NextFragmentPacket(buffer, bytes_to_send); 255 NextFragmentPacket(buffer, bytes_to_send);
275 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); 256 RTC_CHECK_LE(*bytes_to_send, max_payload_len_);
276 } 257 }
277 *last_packet = packets_.empty(); 258 *last_packet = packets_.empty();
278 return true; 259 return true;
279 } 260 }
280 261
281 void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer, 262 void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer,
282 size_t* bytes_to_send) { 263 size_t* bytes_to_send) {
283 PacketUnit* packet = &packets_.front(); 264 PacketUnit* packet = &packets_.front();
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 h264->packetization_type = kH264FuA; 595 h264->packetization_type = kH264FuA;
615 h264->nalu_type = original_nal_type; 596 h264->nalu_type = original_nal_type;
616 if (first_fragment) { 597 if (first_fragment) {
617 h264->nalus[h264->nalus_length] = nalu; 598 h264->nalus[h264->nalus_length] = nalu;
618 h264->nalus_length = 1; 599 h264->nalus_length = 1;
619 } 600 }
620 return true; 601 return true;
621 } 602 }
622 603
623 } // namespace webrtc 604 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_format_h264.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698