mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1294407: Clean up H264 STAP-A handling r=pkerr
This commit is contained in:
parent
2f4c72af04
commit
c6f55e903d
@ -113,8 +113,11 @@ VCMFrameBuffer::InsertPacket(const VCMPacket& packet,
|
||||
}
|
||||
}
|
||||
|
||||
// add safety margin because STAP-A packets can cause it to expand by
|
||||
// ~two bytes per NAL
|
||||
uint32_t requiredSizeBytes = Length() + packet.sizeBytes +
|
||||
(packet.insertStartCode ? kH264StartCodeLengthBytes : 0);
|
||||
(packet.insertStartCode ? kH264StartCodeLengthBytes : 0) +
|
||||
kBufferSafetyMargin;
|
||||
if (requiredSizeBytes >= _size) {
|
||||
const uint8_t* prevBuffer = _buffer;
|
||||
const uint32_t increments = requiredSizeBytes /
|
||||
|
@ -30,7 +30,8 @@ enum VCMJitterBufferEnum {
|
||||
kMaxConsecutiveOldPackets = 300,
|
||||
kMaxPacketsInSession = 800,
|
||||
kBufferIncStepSizeBytes = 30000, // >20 packets.
|
||||
kMaxJBFrameSizeBytes = 4000000 // sanity don't go above 4Mbyte.
|
||||
kMaxJBFrameSizeBytes = 4000000, // sanity don't go above 4Mbyte.
|
||||
kBufferSafetyMargin = 100 // enough for ~50 NALs in a STAP-A
|
||||
};
|
||||
|
||||
enum VCMFrameBufferEnum {
|
||||
|
@ -178,16 +178,31 @@ size_t VCMSessionInfo::InsertBuffer(uint8_t* frame_buffer,
|
||||
packet.codecSpecificHeader.codecHeader.H264.stap_a) {
|
||||
size_t required_length = 0;
|
||||
const uint8_t* nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes;
|
||||
while (nalu_ptr < packet_buffer + packet.sizeBytes) {
|
||||
// Must check that incoming data length doesn't extend past end of buffer.
|
||||
// We allow for 100 bytes of expansion due to startcodes being longer than
|
||||
// length fields.
|
||||
while (nalu_ptr + kLengthFieldLength <= packet_buffer + packet.sizeBytes) {
|
||||
size_t length = BufferToUWord16(nalu_ptr);
|
||||
required_length +=
|
||||
if (nalu_ptr + kLengthFieldLength + length <= packet_buffer + packet.sizeBytes) {
|
||||
required_length +=
|
||||
length + (packet.insertStartCode ? kH264StartCodeLengthBytes : 0);
|
||||
nalu_ptr += kLengthFieldLength + length;
|
||||
nalu_ptr += kLengthFieldLength + length;
|
||||
} else {
|
||||
// Something is very wrong!
|
||||
LOG(LS_ERROR) << "Failed to insert packet due to corrupt H264 STAP-A";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (required_length > packet.sizeBytes + kBufferSafetyMargin) {
|
||||
LOG(LS_ERROR) << "Failed to insert packet due to too many NALs in a STAP-A";
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShiftSubsequentPackets(packet_it, required_length);
|
||||
nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes;
|
||||
uint8_t* frame_buffer_ptr = frame_buffer + offset;
|
||||
while (nalu_ptr < packet_buffer + packet.sizeBytes) {
|
||||
// we already know we won't go past end-of-buffer
|
||||
while (nalu_ptr + kLengthFieldLength <= packet_buffer + packet.sizeBytes) {
|
||||
size_t length = BufferToUWord16(nalu_ptr);
|
||||
nalu_ptr += kLengthFieldLength;
|
||||
frame_buffer_ptr += Insert(nalu_ptr,
|
||||
|
Loading…
Reference in New Issue
Block a user