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

Unified Diff: webrtc/modules/video_coding/frame_object.cc

Issue 2476513004: Allocate extra buffer space in FrameObject in case of H264. (Closed)
Patch Set: Comment fix 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/frame_object.cc
diff --git a/webrtc/modules/video_coding/frame_object.cc b/webrtc/modules/video_coding/frame_object.cc
index acfb25d28d3594e4a0d2047091f20c2238ff8a3a..88205277af1c5fa7c0e2a3ec9e06788a96aff263 100644
--- a/webrtc/modules/video_coding/frame_object.cc
+++ b/webrtc/modules/video_coding/frame_object.cc
@@ -35,6 +35,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);
@@ -42,16 +46,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;
}

Powered by Google App Engine
This is Rietveld 408576698