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

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

Issue 1227383003: Remove memset from VideoFrame and mark buffer as unpoisoned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dalecurtis@ comments. Created 5 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
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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 541
542 // static 542 // static
543 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { 543 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) {
544 size_t total = 0; 544 size_t total = 0;
545 for (size_t i = 0; i < NumPlanes(format); ++i) 545 for (size_t i = 0; i < NumPlanes(format); ++i)
546 total += PlaneSize(format, i, coded_size).GetArea(); 546 total += PlaneSize(format, i, coded_size).GetArea();
547 return total; 547 return total;
548 } 548 }
549 549
550 // static 550 // static
551 size_t VideoFrame::AlignedAllocationSize(
552 const scoped_refptr<VideoFrame>& frame) {
553 DCHECK(IsYuvPlanar(frame->format()));
554 DCHECK_EQ(frame->storage_type(), STORAGE_OWNED_MEMORY);
555
556 // This method is expected to called only after CreateFrame(). Therefore, the
557 // buffer size needs to the same as the allocated size of AllocateYUV().
558 size_t data_size = 0;
559 for (size_t plane = 0; plane < NumPlanes(frame->format()); ++plane) {
560 const size_t height = RoundUp(frame->rows(plane), kFrameSizeAlignment * 2);
561 data_size += height * frame->stride(plane);
562 }
563 data_size += frame->stride(kUPlane) + kFrameSizePadding;
564 return data_size;
565 }
566
567 // static
551 gfx::Size VideoFrame::PlaneSize(Format format, 568 gfx::Size VideoFrame::PlaneSize(Format format,
552 size_t plane, 569 size_t plane,
553 const gfx::Size& coded_size) { 570 const gfx::Size& coded_size) {
554 DCHECK(IsValidPlane(plane, format)); 571 DCHECK(IsValidPlane(plane, format));
555 572
556 int width = coded_size.width(); 573 int width = coded_size.width();
557 int height = coded_size.height(); 574 int height = coded_size.height();
558 if (format != ARGB) { 575 if (format != ARGB) {
559 // Align to multiple-of-two size overall. This ensures that non-subsampled 576 // Align to multiple-of-two size overall. This ensures that non-subsampled
560 // planes can be addressed by pixel with the same scaling as the subsampled 577 // planes can be addressed by pixel with the same scaling as the subsampled
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 data_size += height * strides_[plane]; 910 data_size += height * strides_[plane];
894 } 911 }
895 912
896 // The extra line of UV being allocated is because h264 chroma MC 913 // The extra line of UV being allocated is because h264 chroma MC
897 // overreads by one line in some cases, see libavcodec/utils.c: 914 // overreads by one line in some cases, see libavcodec/utils.c:
898 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm: 915 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm:
899 // put_h264_chroma_mc4_ssse3(). 916 // put_h264_chroma_mc4_ssse3().
900 DCHECK(IsValidPlane(kUPlane, format_)); 917 DCHECK(IsValidPlane(kUPlane, format_));
901 data_size += strides_[kUPlane] + kFrameSizePadding; 918 data_size += strides_[kUPlane] + kFrameSizePadding;
902 919
903 // FFmpeg expects the initialize allocation to be zero-initialized. Failure
904 // to do so can lead to unitialized value usage. See http://crbug.com/390941
905 uint8* data = reinterpret_cast<uint8*>( 920 uint8* data = reinterpret_cast<uint8*>(
906 base::AlignedAlloc(data_size, kFrameAddressAlignment)); 921 base::AlignedAlloc(data_size, kFrameAddressAlignment));
907 memset(data, 0, data_size);
908
909 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 922 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
910 data_[plane] = data + offset[plane]; 923 data_[plane] = data + offset[plane];
911 924
912 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 925 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
926
927 // Make sure that AlignedAllocationSize() returns the same size as allocated
928 // here.
929 DCHECK_EQ(data_size, VideoFrame::AlignedAllocationSize(this));
913 } 930 }
914 931
915 } // namespace media 932 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698