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

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: 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
11 #include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h"
12 12
13 #include <string.h> 13 #include <string.h>
14
14 #include <memory> 15 #include <memory>
15 #include <utility> 16 #include <utility>
16 #include <vector> 17 #include <vector>
17 18
18 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
20 #include "webrtc/modules/include/module_common_types.h" 21 #include "webrtc/modules/include/module_common_types.h"
21 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 22 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
22 #include "webrtc/common_video/h264/sps_vui_rewriter.h" 23 #include "webrtc/common_video/h264/sps_vui_rewriter.h"
23 #include "webrtc/common_video/h264/h264_common.h" 24 #include "webrtc/common_video/h264/h264_common.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 length_remaining -= nalu_size; 71 length_remaining -= nalu_size;
71 72
72 offsets->push_back(offset + kStapAHeaderSize); 73 offsets->push_back(offset + kStapAHeaderSize);
73 offset += kLengthFieldSize + nalu_size; 74 offset += kLengthFieldSize + nalu_size;
74 } 75 }
75 return true; 76 return true;
76 } 77 }
77 78
78 } // namespace 79 } // namespace
79 80
80 RtpPacketizerH264::RtpPacketizerH264(FrameType frame_type, 81 RtpPacketizerH264::RtpPacketizerH264(size_t max_payload_len,
81 size_t max_payload_len) 82 H264PacketizationMode packetization_mode)
82 : max_payload_len_(max_payload_len) {} 83 : max_payload_len_(max_payload_len),
84 packetization_mode_(packetization_mode) {}
83 85
84 RtpPacketizerH264::~RtpPacketizerH264() { 86 RtpPacketizerH264::~RtpPacketizerH264() {
85 } 87 }
86 88
87 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length) 89 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length)
88 : buffer(buffer), length(length) {} 90 : buffer(buffer), length(length) {}
89 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment) 91 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment)
90 : buffer(fragment.buffer), length(fragment.length) {} 92 : buffer(fragment.buffer), length(fragment.length) {}
91 93
92 void RtpPacketizerH264::SetPayloadData( 94 void RtpPacketizerH264::SetPayloadData(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 157 }
156 158
157 if (!updated_sps) 159 if (!updated_sps)
158 input_fragments_.push_back(Fragment(buffer, length)); 160 input_fragments_.push_back(Fragment(buffer, length));
159 } 161 }
160 GeneratePackets(); 162 GeneratePackets();
161 } 163 }
162 164
163 void RtpPacketizerH264::GeneratePackets() { 165 void RtpPacketizerH264::GeneratePackets() {
164 for (size_t i = 0; i < input_fragments_.size();) { 166 for (size_t i = 0; i < input_fragments_.size();) {
165 if (input_fragments_[i].length > max_payload_len_) { 167 if (packetization_mode_ == kH264PacketizationMode0) {
166 PacketizeFuA(i); 168 PacketizeSingleNalu(i);
167 ++i; 169 ++i;
168 } else { 170 } else {
169 i = PacketizeStapA(i); 171 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1);
172 if (input_fragments_[i].length > max_payload_len_) {
173 PacketizeFuA(i);
174 ++i;
175 } else {
176 i = PacketizeStapA(i);
177 }
170 } 178 }
171 } 179 }
172 } 180 }
173 181
174 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) { 182 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) {
175 // Fragment payload into packets (FU-A). 183 // Fragment payload into packets (FU-A).
176 // Strip out the original header and leave room for the FU-A header. 184 // Strip out the original header and leave room for the FU-A header.
177 const Fragment& fragment = input_fragments_[fragment_index]; 185 const Fragment& fragment = input_fragments_[fragment_index];
178 186
179 size_t fragment_length = fragment.length - kNalHeaderSize; 187 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 230 // we need to add the STAP-A NALU header and a length field for the first
223 // NALU of this packet. 231 // NALU of this packet.
224 if (aggregated_fragments == 0) 232 if (aggregated_fragments == 0)
225 fragment_headers_length += kNalHeaderSize + kLengthFieldSize; 233 fragment_headers_length += kNalHeaderSize + kLengthFieldSize;
226 ++aggregated_fragments; 234 ++aggregated_fragments;
227 } 235 }
228 packets_.back().last_fragment = true; 236 packets_.back().last_fragment = true;
229 return fragment_index; 237 return fragment_index;
230 } 238 }
231 239
240 void RtpPacketizerH264::PacketizeSingleNalu(size_t fragment_index) {
241 // Add a single NALU to the queue, no aggregation.
242 size_t payload_size_left = max_payload_len_;
243 const Fragment* fragment = &input_fragments_[fragment_index];
244 RTC_CHECK_GE(payload_size_left, fragment->length);
245 RTC_CHECK_GT(fragment->length, 0u);
246 packets_.push(PacketUnit(*fragment, true /* first */, true /* last */,
247 false /* aggregated */, fragment->buffer[0]));
248 }
249
232 bool RtpPacketizerH264::NextPacket(uint8_t* buffer, 250 bool RtpPacketizerH264::NextPacket(uint8_t* buffer,
233 size_t* bytes_to_send, 251 size_t* bytes_to_send,
234 bool* last_packet) { 252 bool* last_packet) {
235 *bytes_to_send = 0; 253 *bytes_to_send = 0;
236 if (packets_.empty()) { 254 if (packets_.empty()) {
237 *bytes_to_send = 0; 255 *bytes_to_send = 0;
238 *last_packet = true; 256 *last_packet = true;
239 return false; 257 return false;
240 } 258 }
241 259
242 PacketUnit packet = packets_.front(); 260 PacketUnit packet = packets_.front();
243 261
244 if (packet.first_fragment && packet.last_fragment) { 262 if (packet.first_fragment && packet.last_fragment) {
245 // Single NAL unit packet. 263 // Single NAL unit packet.
246 *bytes_to_send = packet.source_fragment.length; 264 *bytes_to_send = packet.source_fragment.length;
247 memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send); 265 memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send);
248 packets_.pop(); 266 packets_.pop();
249 input_fragments_.pop_front(); 267 input_fragments_.pop_front();
250 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); 268 RTC_CHECK_LE(*bytes_to_send, max_payload_len_);
251 } else if (packet.aggregated) { 269 } else if (packet.aggregated) {
270 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1);
252 NextAggregatePacket(buffer, bytes_to_send); 271 NextAggregatePacket(buffer, bytes_to_send);
253 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); 272 RTC_CHECK_LE(*bytes_to_send, max_payload_len_);
254 } else { 273 } else {
274 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1);
255 NextFragmentPacket(buffer, bytes_to_send); 275 NextFragmentPacket(buffer, bytes_to_send);
256 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); 276 RTC_CHECK_LE(*bytes_to_send, max_payload_len_);
257 } 277 }
258 *last_packet = packets_.empty(); 278 *last_packet = packets_.empty();
259 return true; 279 return true;
260 } 280 }
261 281
262 void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer, 282 void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer,
263 size_t* bytes_to_send) { 283 size_t* bytes_to_send) {
264 PacketUnit* packet = &packets_.front(); 284 PacketUnit* packet = &packets_.front();
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 h264->packetization_type = kH264FuA; 615 h264->packetization_type = kH264FuA;
596 h264->nalu_type = original_nal_type; 616 h264->nalu_type = original_nal_type;
597 if (first_fragment) { 617 if (first_fragment) {
598 h264->nalus[h264->nalus_length] = nalu; 618 h264->nalus[h264->nalus_length] = nalu;
599 h264->nalus_length = 1; 619 h264->nalus_length = 1;
600 } 620 }
601 return true; 621 return true;
602 } 622 }
603 623
604 } // namespace webrtc 624 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698