| OLD | NEW |
| 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 Loading... |
| 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(const RTPVideoHeaderH264& parameters, |
| 81 size_t max_payload_len) | 82 size_t max_payload_len) |
| 82 : max_payload_len_(max_payload_len) {} | 83 : packetization_mode_(parameters.packetization_mode), |
| 84 max_payload_len_(max_payload_len) { |
| 85 if (packetization_mode_ == kH264PacketizationModeNotSet) { |
| 86 LOG(LS_WARNING) |
| 87 << "Creating H.264 RTP packetizer with default packetization mode"; |
| 88 packetization_mode_ = kH264PacketizationMode1; |
| 89 } |
| 90 } |
| 83 | 91 |
| 84 RtpPacketizerH264::~RtpPacketizerH264() { | 92 RtpPacketizerH264::~RtpPacketizerH264() { |
| 85 } | 93 } |
| 86 | 94 |
| 87 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length) | 95 RtpPacketizerH264::Fragment::Fragment(const uint8_t* buffer, size_t length) |
| 88 : buffer(buffer), length(length) {} | 96 : buffer(buffer), length(length) {} |
| 89 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment) | 97 RtpPacketizerH264::Fragment::Fragment(const Fragment& fragment) |
| 90 : buffer(fragment.buffer), length(fragment.length) {} | 98 : buffer(fragment.buffer), length(fragment.length) {} |
| 91 | 99 |
| 92 void RtpPacketizerH264::SetPayloadData( | 100 void RtpPacketizerH264::SetPayloadData( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 164 |
| 157 if (!updated_sps) | 165 if (!updated_sps) |
| 158 input_fragments_.push_back(Fragment(buffer, length)); | 166 input_fragments_.push_back(Fragment(buffer, length)); |
| 159 } | 167 } |
| 160 GeneratePackets(); | 168 GeneratePackets(); |
| 161 } | 169 } |
| 162 | 170 |
| 163 void RtpPacketizerH264::GeneratePackets() { | 171 void RtpPacketizerH264::GeneratePackets() { |
| 164 for (size_t i = 0; i < input_fragments_.size();) { | 172 for (size_t i = 0; i < input_fragments_.size();) { |
| 165 if (input_fragments_[i].length > max_payload_len_) { | 173 if (input_fragments_[i].length > max_payload_len_) { |
| 174 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1); |
| 166 PacketizeFuA(i); | 175 PacketizeFuA(i); |
| 167 ++i; | 176 ++i; |
| 168 } else { | 177 } else { |
| 169 i = PacketizeStapA(i); | 178 i = PacketizeStapA(i); |
| 170 } | 179 } |
| 171 } | 180 } |
| 172 } | 181 } |
| 173 | 182 |
| 174 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) { | 183 void RtpPacketizerH264::PacketizeFuA(size_t fragment_index) { |
| 175 // Fragment payload into packets (FU-A). | 184 // Fragment payload into packets (FU-A). |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 PacketUnit packet = packets_.front(); | 251 PacketUnit packet = packets_.front(); |
| 243 | 252 |
| 244 if (packet.first_fragment && packet.last_fragment) { | 253 if (packet.first_fragment && packet.last_fragment) { |
| 245 // Single NAL unit packet. | 254 // Single NAL unit packet. |
| 246 *bytes_to_send = packet.source_fragment.length; | 255 *bytes_to_send = packet.source_fragment.length; |
| 247 memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send); | 256 memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send); |
| 248 packets_.pop(); | 257 packets_.pop(); |
| 249 input_fragments_.pop_front(); | 258 input_fragments_.pop_front(); |
| 250 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); | 259 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); |
| 251 } else if (packet.aggregated) { | 260 } else if (packet.aggregated) { |
| 261 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1); |
| 252 NextAggregatePacket(buffer, bytes_to_send); | 262 NextAggregatePacket(buffer, bytes_to_send); |
| 253 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); | 263 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); |
| 254 } else { | 264 } else { |
| 265 RTC_CHECK_EQ(packetization_mode_, kH264PacketizationMode1); |
| 255 NextFragmentPacket(buffer, bytes_to_send); | 266 NextFragmentPacket(buffer, bytes_to_send); |
| 256 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); | 267 RTC_CHECK_LE(*bytes_to_send, max_payload_len_); |
| 257 } | 268 } |
| 258 *last_packet = packets_.empty(); | 269 *last_packet = packets_.empty(); |
| 259 return true; | 270 return true; |
| 260 } | 271 } |
| 261 | 272 |
| 262 void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer, | 273 void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer, |
| 263 size_t* bytes_to_send) { | 274 size_t* bytes_to_send) { |
| 264 PacketUnit* packet = &packets_.front(); | 275 PacketUnit* packet = &packets_.front(); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 h264->packetization_type = kH264FuA; | 604 h264->packetization_type = kH264FuA; |
| 594 h264->nalu_type = original_nal_type; | 605 h264->nalu_type = original_nal_type; |
| 595 if (first_fragment) { | 606 if (first_fragment) { |
| 596 h264->nalus[h264->nalus_length] = nalu; | 607 h264->nalus[h264->nalus_length] = nalu; |
| 597 h264->nalus_length = 1; | 608 h264->nalus_length = 1; |
| 598 } | 609 } |
| 599 return true; | 610 return true; |
| 600 } | 611 } |
| 601 | 612 |
| 602 } // namespace webrtc | 613 } // namespace webrtc |
| OLD | NEW |