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

Side by Side Diff: media/base/video_frame.cc

Issue 383893002: Zero initialize the first allocation of a VideoFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/video_frame_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 ? y_height / 2 611 ? y_height / 2
612 : y_height; 612 : y_height;
613 size_t y_bytes = y_height * y_stride; 613 size_t y_bytes = y_height * y_stride;
614 size_t uv_bytes = uv_height * uv_stride; 614 size_t uv_bytes = uv_height * uv_stride;
615 size_t a_bytes = format_ == VideoFrame::YV12A ? y_bytes : 0; 615 size_t a_bytes = format_ == VideoFrame::YV12A ? y_bytes : 0;
616 616
617 // The extra line of UV being allocated is because h264 chroma MC 617 // The extra line of UV being allocated is because h264 chroma MC
618 // overreads by one line in some cases, see libavcodec/utils.c: 618 // overreads by one line in some cases, see libavcodec/utils.c:
619 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm: 619 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm:
620 // put_h264_chroma_mc4_ssse3(). 620 // put_h264_chroma_mc4_ssse3().
621 const size_t data_size =
622 y_bytes + (uv_bytes * 2 + uv_stride) + a_bytes + kFrameSizePadding;
621 uint8* data = reinterpret_cast<uint8*>( 623 uint8* data = reinterpret_cast<uint8*>(
622 base::AlignedAlloc( 624 base::AlignedAlloc(data_size, kFrameAddressAlignment));
623 y_bytes + (uv_bytes * 2 + uv_stride) + a_bytes + kFrameSizePadding, 625 // FFmpeg expects the initialize allocation to be zero-initialized. Failure
624 kFrameAddressAlignment)); 626 // to do so can lead to unitialized value usage. See http://crbug.com/390941
627 memset(data, 0, data_size);
625 no_longer_needed_cb_ = base::Bind(&ReleaseData, data); 628 no_longer_needed_cb_ = base::Bind(&ReleaseData, data);
626 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); 629 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0);
627 data_[VideoFrame::kYPlane] = data; 630 data_[VideoFrame::kYPlane] = data;
628 data_[VideoFrame::kUPlane] = data + y_bytes; 631 data_[VideoFrame::kUPlane] = data + y_bytes;
629 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; 632 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
630 strides_[VideoFrame::kYPlane] = y_stride; 633 strides_[VideoFrame::kYPlane] = y_stride;
631 strides_[VideoFrame::kUPlane] = uv_stride; 634 strides_[VideoFrame::kUPlane] = uv_stride;
632 strides_[VideoFrame::kVPlane] = uv_stride; 635 strides_[VideoFrame::kVPlane] = uv_stride;
633 if (format_ == YV12A) { 636 if (format_ == YV12A) {
634 data_[VideoFrame::kAPlane] = data + y_bytes + (2 * uv_bytes); 637 data_[VideoFrame::kAPlane] = data + y_bytes + (2 * uv_bytes);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 break; 839 break;
837 for (int row = 0; row < rows(plane); ++row) { 840 for (int row = 0; row < rows(plane); ++row) {
838 base::MD5Update(context, base::StringPiece( 841 base::MD5Update(context, base::StringPiece(
839 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 842 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
840 row_bytes(plane))); 843 row_bytes(plane)));
841 } 844 }
842 } 845 }
843 } 846 }
844 847
845 } // namespace media 848 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/video_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698