Index: webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc |
index 2344b2820c75b54f9df597445faedf7c8c6fab03..b82b66f5fe5a0e270a94b83041aaa18bc8150da8 100644 |
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc |
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc |
@@ -19,6 +19,7 @@ |
#include "webrtc/base/logging.h" |
#include "webrtc/modules/include/module_common_types.h" |
#include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
#include "webrtc/common_video/h264/sps_vui_rewriter.h" |
#include "webrtc/common_video/h264/h264_common.h" |
#include "webrtc/common_video/h264/pps_parser.h" |
@@ -229,54 +230,50 @@ size_t RtpPacketizerH264::PacketizeStapA(size_t fragment_index) { |
return fragment_index; |
} |
-bool RtpPacketizerH264::NextPacket(uint8_t* buffer, |
- size_t* bytes_to_send, |
+bool RtpPacketizerH264::NextPacket(RtpPacketToSend* rtp_packet, |
bool* last_packet) { |
- *bytes_to_send = 0; |
+ RTC_DCHECK(rtp_packet); |
+ RTC_DCHECK(last_packet); |
if (packets_.empty()) { |
- *bytes_to_send = 0; |
*last_packet = true; |
return false; |
} |
PacketUnit packet = packets_.front(); |
- |
if (packet.first_fragment && packet.last_fragment) { |
// Single NAL unit packet. |
- *bytes_to_send = packet.source_fragment.length; |
- memcpy(buffer, packet.source_fragment.buffer, *bytes_to_send); |
+ size_t bytes_to_send = packet.source_fragment.length; |
+ uint8_t* buffer = rtp_packet->AllocatePayload(bytes_to_send); |
+ memcpy(buffer, packet.source_fragment.buffer, bytes_to_send); |
packets_.pop(); |
input_fragments_.pop_front(); |
- RTC_CHECK_LE(*bytes_to_send, max_payload_len_); |
} else if (packet.aggregated) { |
- NextAggregatePacket(buffer, bytes_to_send); |
- RTC_CHECK_LE(*bytes_to_send, max_payload_len_); |
+ NextAggregatePacket(rtp_packet); |
} else { |
- NextFragmentPacket(buffer, bytes_to_send); |
- RTC_CHECK_LE(*bytes_to_send, max_payload_len_); |
+ NextFragmentPacket(rtp_packet); |
} |
+ RTC_DCHECK_LE(rtp_packet->payload_size(), max_payload_len_); |
*last_packet = packets_.empty(); |
+ rtp_packet->SetMarker(*last_packet); |
return true; |
} |
-void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer, |
- size_t* bytes_to_send) { |
+void RtpPacketizerH264::NextAggregatePacket(RtpPacketToSend* rtp_packet) { |
+ uint8_t* buffer = rtp_packet->AllocatePayload(max_payload_len_); |
+ RTC_DCHECK(buffer); |
PacketUnit* packet = &packets_.front(); |
RTC_CHECK(packet->first_fragment); |
// STAP-A NALU header. |
buffer[0] = (packet->header & (kFBit | kNriMask)) | H264::NaluType::kStapA; |
- int index = kNalHeaderSize; |
- *bytes_to_send += kNalHeaderSize; |
+ size_t index = kNalHeaderSize; |
while (packet->aggregated) { |
const Fragment& fragment = packet->source_fragment; |
// Add NAL unit length field. |
ByteWriter<uint16_t>::WriteBigEndian(&buffer[index], fragment.length); |
index += kLengthFieldSize; |
- *bytes_to_send += kLengthFieldSize; |
// Add NAL unit. |
memcpy(&buffer[index], fragment.buffer, fragment.length); |
index += fragment.length; |
- *bytes_to_send += fragment.length; |
packets_.pop(); |
input_fragments_.pop_front(); |
if (packet->last_fragment) |
@@ -284,10 +281,10 @@ void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer, |
packet = &packets_.front(); |
} |
RTC_CHECK(packet->last_fragment); |
+ rtp_packet->SetPayloadSize(index); |
} |
-void RtpPacketizerH264::NextFragmentPacket(uint8_t* buffer, |
- size_t* bytes_to_send) { |
+void RtpPacketizerH264::NextFragmentPacket(RtpPacketToSend* rtp_packet) { |
PacketUnit* packet = &packets_.front(); |
// NAL unit fragmented over multiple packets (FU-A). |
// We do not send original NALU header, so it will be replaced by the |
@@ -301,11 +298,11 @@ void RtpPacketizerH264::NextFragmentPacket(uint8_t* buffer, |
fu_header |= (packet->last_fragment ? kEBit : 0); |
uint8_t type = packet->header & kTypeMask; |
fu_header |= type; |
+ const Fragment& fragment = packet->source_fragment; |
+ uint8_t* buffer = |
+ rtp_packet->AllocatePayload(kFuAHeaderSize + fragment.length); |
buffer[0] = fu_indicator; |
buffer[1] = fu_header; |
- |
- const Fragment& fragment = packet->source_fragment; |
- *bytes_to_send = fragment.length + kFuAHeaderSize; |
memcpy(buffer + kFuAHeaderSize, fragment.buffer, fragment.length); |
if (packet->last_fragment) |
input_fragments_.pop_front(); |