Zero initialize the first allocation of a VideoFrame.

Replicates FFmpeg's behavior for frame allocation.  They do not zero
the frame on subsequent pool reuse, so I have not done so either.

BUG=390941,390944,390945
TEST=new unittest.

Review URL: https://codereview.chromium.org/383893002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282775 0039d316-1c4b-4281-b951-d872f2087c98
parent 8f539d2a
...@@ -618,10 +618,13 @@ void VideoFrame::AllocateYUV() { ...@@ -618,10 +618,13 @@ void VideoFrame::AllocateYUV() {
// overreads by one line in some cases, see libavcodec/utils.c: // overreads by one line in some cases, see libavcodec/utils.c:
// avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm: // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm:
// put_h264_chroma_mc4_ssse3(). // put_h264_chroma_mc4_ssse3().
const size_t data_size =
y_bytes + (uv_bytes * 2 + uv_stride) + a_bytes + kFrameSizePadding;
uint8* data = reinterpret_cast<uint8*>( uint8* data = reinterpret_cast<uint8*>(
base::AlignedAlloc( base::AlignedAlloc(data_size, kFrameAddressAlignment));
y_bytes + (uv_bytes * 2 + uv_stride) + a_bytes + kFrameSizePadding, // FFmpeg expects the initialize allocation to be zero-initialized. Failure
kFrameAddressAlignment)); // to do so can lead to unitialized value usage. See http://crbug.com/390941
memset(data, 0, data_size);
no_longer_needed_cb_ = base::Bind(&ReleaseData, data); no_longer_needed_cb_ = base::Bind(&ReleaseData, data);
COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0);
data_[VideoFrame::kYPlane] = data; data_[VideoFrame::kYPlane] = data;
......
...@@ -308,4 +308,17 @@ TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { ...@@ -308,4 +308,17 @@ TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) {
EXPECT_EQ(release_sync_points, called_sync_points); EXPECT_EQ(release_sync_points, called_sync_points);
} }
TEST(VideoFrame, ZeroInitialized) {
const int kWidth = 64;
const int kHeight = 48;
const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
gfx::Size size(kWidth, kHeight);
scoped_refptr<media::VideoFrame> frame = VideoFrame::CreateFrame(
media::VideoFrame::YV12, size, gfx::Rect(size), size, kTimestamp);
for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i)
EXPECT_EQ(0, frame->data(i)[0]);
}
} // namespace media } // namespace media
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment