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

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

Issue 1267003004: Revert to zero-initializing buffers for FFmpegVideoDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 // static 531 // static
532 size_t VideoFrame::AllocationSize(VideoPixelFormat format, 532 size_t VideoFrame::AllocationSize(VideoPixelFormat format,
533 const gfx::Size& coded_size) { 533 const gfx::Size& coded_size) {
534 size_t total = 0; 534 size_t total = 0;
535 for (size_t i = 0; i < NumPlanes(format); ++i) 535 for (size_t i = 0; i < NumPlanes(format); ++i)
536 total += PlaneSize(format, i, coded_size).GetArea(); 536 total += PlaneSize(format, i, coded_size).GetArea();
537 return total; 537 return total;
538 } 538 }
539 539
540 // static 540 // static
541 size_t VideoFrame::AlignedAllocationSize(
542 const scoped_refptr<VideoFrame>& frame) {
543 DCHECK(IsYuvPlanar(frame->format()));
544 DCHECK_EQ(frame->storage_type(), STORAGE_OWNED_MEMORY);
545
546 // This method is expected to called only after CreateFrame(). Therefore, the
547 // buffer size needs to the same as the allocated size of AllocateYUV().
548 size_t data_size = 0;
549 for (size_t plane = 0; plane < NumPlanes(frame->format()); ++plane) {
550 const size_t height = RoundUp(frame->rows(plane), kFrameSizeAlignment * 2);
551 data_size += height * frame->stride(plane);
552 }
553 data_size += frame->stride(kUPlane) + kFrameSizePadding;
554 return data_size;
555 }
556
557 // static
541 gfx::Size VideoFrame::PlaneSize(VideoPixelFormat format, 558 gfx::Size VideoFrame::PlaneSize(VideoPixelFormat format,
542 size_t plane, 559 size_t plane,
543 const gfx::Size& coded_size) { 560 const gfx::Size& coded_size) {
544 DCHECK(IsValidPlane(plane, format)); 561 DCHECK(IsValidPlane(plane, format));
545 562
546 int width = coded_size.width(); 563 int width = coded_size.width();
547 int height = coded_size.height(); 564 int height = coded_size.height();
548 if (format != PIXEL_FORMAT_ARGB) { 565 if (format != PIXEL_FORMAT_ARGB) {
549 // Align to multiple-of-two size overall. This ensures that non-subsampled 566 // Align to multiple-of-two size overall. This ensures that non-subsampled
550 // planes can be addressed by pixel with the same scaling as the subsampled 567 // planes can be addressed by pixel with the same scaling as the subsampled
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 905
889 // The extra line of UV being allocated is because h264 chroma MC 906 // The extra line of UV being allocated is because h264 chroma MC
890 // overreads by one line in some cases, see libavcodec/utils.c: 907 // overreads by one line in some cases, see libavcodec/utils.c:
891 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm: 908 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm:
892 // put_h264_chroma_mc4_ssse3(). 909 // put_h264_chroma_mc4_ssse3().
893 DCHECK(IsValidPlane(kUPlane, format_)); 910 DCHECK(IsValidPlane(kUPlane, format_));
894 data_size += strides_[kUPlane] + kFrameSizePadding; 911 data_size += strides_[kUPlane] + kFrameSizePadding;
895 912
896 uint8* data = reinterpret_cast<uint8*>( 913 uint8* data = reinterpret_cast<uint8*>(
897 base::AlignedAlloc(data_size, kFrameAddressAlignment)); 914 base::AlignedAlloc(data_size, kFrameAddressAlignment));
898
899 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 915 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
900 data_[plane] = data + offset[plane]; 916 data_[plane] = data + offset[plane];
901 917
902 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 918 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
919
920 // Make sure that AlignedAllocationSize() returns the same size as allocated
921 // here.
922 DCHECK_EQ(data_size, VideoFrame::AlignedAllocationSize(this));
903 } 923 }
904 924
905 } // namespace media 925 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698