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

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

Issue 2558463002: Reland of H.264 packetization mode 0 (try 3) (Closed)
Patch Set: Lengthened timeout Created 4 years 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 length_remaining -= nalu_size; 71 length_remaining -= nalu_size;
72 72
73 offsets->push_back(offset + kStapAHeaderSize); 73 offsets->push_back(offset + kStapAHeaderSize);
74 offset += kLengthFieldSize + nalu_size; 74 offset += kLengthFieldSize + nalu_size;
75 } 75 }
76 return true; 76 return true;
77 } 77 }
78 78
79 } // namespace 79 } // namespace
80 80
81 RtpPacketizerH264::RtpPacketizerH264(FrameType frame_type, 81 RtpPacketizerH264::RtpPacketizerH264(size_t max_payload_len,
82 size_t max_payload_len) 82 H264PacketizationMode packetization_mode)
83 : max_payload_len_(max_payload_len) {} 83 : max_payload_len_(max_payload_len),
84 packetization_mode_(packetization_mode) {}
84 85
85 RtpPacketizerH264::~RtpPacketizerH264() { 86 RtpPacketizerH264::~RtpPacketizerH264() {
86 } 87 }
87 88
88 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length) 89 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length)
89 : buffer(buffer), length(length) {} 90 : buffer(buffer), length(length) {}
90 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment) 91 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment)
91 : buffer(fragment.buffer), length(fragment.length) {} 92 : buffer(fragment.buffer), length(fragment.length) {}
92 93
93 void RtpPacketizerH264::SetPayloadData( 94 void RtpPacketizerH264::SetPayloadData(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 157 }
157 158
158 if (!updated_sps) 159 if (!updated_sps)
159 input_fragments_.push_back(Fragment(buffer, length)); 160 input_fragments_.push_back(Fragment(buffer, length));
160 } 161 }
161 GeneratePackets(); 162 GeneratePackets();
162 } 163 }
163 164
164 void RtpPacketizerH264::GeneratePackets() { 165 void RtpPacketizerH264::GeneratePackets() {
165 for (size_t i = 0; i < input_fragments_.size();) { 166 for (size_t i = 0; i < input_fragments_.size();) {
166 if (input_fragments_[i].length > max_payload_len_) { 167 switch (packetization_mode_) {
167 PacketizeFuA(i); 168 case H264PacketizationMode::SingleNalUnit:
168 ++i; 169 PacketizeSingleNalu(i);
169 } else { 170 ++i;
170 i = PacketizeStapA(i); 171 break;
172 case H264PacketizationMode::NonInterleaved:
173 if (input_fragments_[i].length > max_payload_len_) {
174 PacketizeFuA(i);
175 ++i;
176 } else {
177 i = PacketizeStapA(i);
178 }
179 break;
171 } 180 }
172 } 181 }
173 } 182 }
174 183
175 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) { 184 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) {
176 // Fragment payload into packets (FU-A). 185 // Fragment payload into packets (FU-A).
177 // Strip out the original header and leave room for the FU-A header. 186 // Strip out the original header and leave room for the FU-A header.
178 const Fragment& fragment = input_fragments_[fragment_index]; 187 const Fragment& fragment = input_fragments_[fragment_index];
179 188
180 size_t fragment_length = fragment.length - kNalHeaderSize; 189 size_t fragment_length = fragment.length - kNalHeaderSize;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // we need to add the STAP-A NALU header and a length field for the first 232 // we need to add the STAP-A NALU header and a length field for the first
224 // NALU of this packet. 233 // NALU of this packet.
225 if (aggregated_fragments == 0) 234 if (aggregated_fragments == 0)
226 fragment_headers_length += kNalHeaderSize + kLengthFieldSize; 235 fragment_headers_length += kNalHeaderSize + kLengthFieldSize;
227 ++aggregated_fragments; 236 ++aggregated_fragments;
228 } 237 }
229 packets_.back().last_fragment = true; 238 packets_.back().last_fragment = true;
230 return fragment_index; 239 return fragment_index;
231 } 240 }
232 241
242 void RtpPacketizerH264::PacketizeSingleNalu(size_t fragment_index) {
243 // Add a single NALU to the queue, no aggregation.
244 size_t payload_size_left = max_payload_len_;
245 const Fragment* fragment = &input_fragments_[fragment_index];
246 RTC_CHECK_GE(payload_size_left, fragment->length)
247 << "Payload size left " << payload_size_left << ", fragment length "
248 << fragment->length << ", packetization mode "
249 << (packetization_mode_ == H264PacketizationMode::SingleNalUnit
250 ? "SingleNalUnit"
251 : "NonInterleaved");
252 RTC_CHECK_GT(fragment->length, 0u);
253 packets_.push(PacketUnit(*fragment, true /* first */, true /* last */,
254 false /* aggregated */, fragment->buffer[0]));
255 }
256
233 bool RtpPacketizerH264::NextPacket(RtpPacketToSend* rtp_packet, 257 bool RtpPacketizerH264::NextPacket(RtpPacketToSend* rtp_packet,
234 bool* last_packet) { 258 bool* last_packet) {
235 RTC_DCHECK(rtp_packet); 259 RTC_DCHECK(rtp_packet);
236 RTC_DCHECK(last_packet); 260 RTC_DCHECK(last_packet);
237 if (packets_.empty()) { 261 if (packets_.empty()) {
238 *last_packet = true; 262 *last_packet = true;
239 return false; 263 return false;
240 } 264 }
241 265
242 PacketUnit packet = packets_.front(); 266 PacketUnit packet = packets_.front();
243 if (packet.first_fragment && packet.last_fragment) { 267 if (packet.first_fragment && packet.last_fragment) {
244 // Single NAL unit packet. 268 // Single NAL unit packet.
245 size_t bytes_to_send = packet.source_fragment.length; 269 size_t bytes_to_send = packet.source_fragment.length;
246 uint8_t* buffer = rtp_packet->AllocatePayload(bytes_to_send); 270 uint8_t* buffer = rtp_packet->AllocatePayload(bytes_to_send);
247 memcpy(buffer, packet.source_fragment.buffer, bytes_to_send); 271 memcpy(buffer, packet.source_fragment.buffer, bytes_to_send);
248 packets_.pop(); 272 packets_.pop();
249 input_fragments_.pop_front(); 273 input_fragments_.pop_front();
250 } else if (packet.aggregated) { 274 } else if (packet.aggregated) {
275 RTC_CHECK(packetization_mode_ == H264PacketizationMode::NonInterleaved);
251 NextAggregatePacket(rtp_packet); 276 NextAggregatePacket(rtp_packet);
252 } else { 277 } else {
278 RTC_CHECK(packetization_mode_ == H264PacketizationMode::NonInterleaved);
253 NextFragmentPacket(rtp_packet); 279 NextFragmentPacket(rtp_packet);
254 } 280 }
255 RTC_DCHECK_LE(rtp_packet->payload_size(), max_payload_len_); 281 RTC_DCHECK_LE(rtp_packet->payload_size(), max_payload_len_);
256 *last_packet = packets_.empty(); 282 *last_packet = packets_.empty();
257 rtp_packet->SetMarker(*last_packet); 283 rtp_packet->SetMarker(*last_packet);
258 return true; 284 return true;
259 } 285 }
260 286
261 void RtpPacketizerH264::NextAggregatePacket(RtpPacketToSend* rtp_packet) { 287 void RtpPacketizerH264::NextAggregatePacket(RtpPacketToSend* rtp_packet) {
262 uint8_t* buffer = rtp_packet->AllocatePayload(max_payload_len_); 288 uint8_t* buffer = rtp_packet->AllocatePayload(max_payload_len_);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 h264->packetization_type = kH264FuA; 618 h264->packetization_type = kH264FuA;
593 h264->nalu_type = original_nal_type; 619 h264->nalu_type = original_nal_type;
594 if (first_fragment) { 620 if (first_fragment) {
595 h264->nalus[h264->nalus_length] = nalu; 621 h264->nalus[h264->nalus_length] = nalu;
596 h264->nalus_length = 1; 622 h264->nalus_length = 1;
597 } 623 }
598 return true; 624 return true;
599 } 625 }
600 626
601 } // namespace webrtc 627 } // 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