Allocate extra buffer space in FrameObject in case of H264.

Since ffmpeg use an optimized bitstream reader that reads in chunks of 32/64
bits the bitstream buffer has to be increased in order for the reader to not
read out of bounds.

BUG=webrtc:5514
R=stefan@webrtc.org

Review URL: https://codereview.webrtc.org/2476513004 .

Cr-Commit-Position: refs/heads/master@{#14941}
This commit is contained in:
philipel
2016-11-07 10:42:36 +01:00
parent 18ee17d1e7
commit 36928454fa
2 changed files with 47 additions and 7 deletions

View File

@ -34,6 +34,10 @@ RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer,
times_nacked_(times_nacked) {
VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num);
if (packet) {
// RtpFrameObject members
frame_type_ = packet->frameType;
codec_type_ = packet->codec;
// TODO(philipel): Remove when encoded image is replaced by FrameObject.
// VCMEncodedFrame members
CopyCodecSpecific(&packet->video_header);
@ -41,16 +45,23 @@ RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer,
_payloadType = packet->payloadType;
_timeStamp = packet->timestamp;
ntp_time_ms_ = packet->ntp_time_ms_;
_buffer = new uint8_t[frame_size]();
_size = frame_size;
// Since FFmpeg use an optimized bitstream reader that reads in chunks of
// 32/64 bits we have to add at least that much padding to the buffer
// to make sure the decoder doesn't read out of bounds.
// NOTE! EncodedImage::_size is the size of the buffer (think capacity of
// an std::vector) and EncodedImage::_length is the actual size of
// the bitstream (think size of an std::vector).
if (codec_type_ == kVideoCodecH264)
_size = frame_size + EncodedImage::kBufferPaddingBytesH264;
else
_size = frame_size;
_buffer = new uint8_t[_size];
_length = frame_size;
_frameType = packet->frameType;
GetBitstream(_buffer);
// RtpFrameObject members
frame_type_ = packet->frameType;
codec_type_ = packet->codec;
// FrameObject members
timestamp = packet->timestamp;
}