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

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

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