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

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

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