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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: media/base/video_frame.cc
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc
index e0367c83a649f8ec4c34a7d822ee2a97e6d9b119..baa012c7aab6d93224f3983b994e9501f2fac843 100644
--- a/media/base/video_frame.cc
+++ b/media/base/video_frame.cc
@@ -548,6 +548,23 @@ size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) {
}
// static
+size_t VideoFrame::AlignedAllocationSize(
+ const scoped_refptr<VideoFrame>& frame) {
+ DCHECK(IsYuvPlanar(frame->format()));
+ DCHECK_EQ(frame->storage_type(), STORAGE_OWNED_MEMORY);
+
+ // This method is expected to called only after CreateFrame(). Therefore, the
+ // buffer size needs to the same as the allocated size of AllocateYUV().
+ size_t data_size = 0;
+ for (size_t plane = 0; plane < NumPlanes(frame->format()); ++plane) {
+ const size_t height = RoundUp(frame->rows(plane), kFrameSizeAlignment * 2);
+ data_size += height * frame->stride(plane);
+ }
+ data_size += frame->stride(kUPlane) + kFrameSizePadding;
+ return data_size;
+}
+
+// static
gfx::Size VideoFrame::PlaneSize(Format format,
size_t plane,
const gfx::Size& coded_size) {
@@ -900,16 +917,16 @@ void VideoFrame::AllocateYUV() {
DCHECK(IsValidPlane(kUPlane, format_));
data_size += strides_[kUPlane] + kFrameSizePadding;
- // FFmpeg expects the initialize allocation to be zero-initialized. Failure
- // to do so can lead to unitialized value usage. See http://crbug.com/390941
uint8* data = reinterpret_cast<uint8*>(
base::AlignedAlloc(data_size, kFrameAddressAlignment));
- memset(data, 0, data_size);
-
for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
data_[plane] = data + offset[plane];
AddDestructionObserver(base::Bind(&base::AlignedFree, data));
+
+ // Make sure that AlignedAllocationSize() returns the same size as allocated
+ // here.
+ DCHECK_EQ(data_size, VideoFrame::AlignedAllocationSize(this));
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698