Index: media/base/video_frame.cc |
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc |
index 08e7e1ad7a236f3ab29d5e7ee6fc9da2098fb630..2bf9b8ffdf8a81393400065c6a5875c8ab9986a9 100644 |
--- a/media/base/video_frame.cc |
+++ b/media/base/video_frame.cc |
@@ -124,9 +124,13 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( |
const gfx::Rect& visible_rect, |
const gfx::Size& natural_size, |
uint8* data, |
+ size_t data_size, |
base::SharedMemoryHandle handle, |
base::TimeDelta timestamp, |
const base::Closure& no_longer_needed_cb) { |
+ if (data_size < AllocationSize(format, coded_size)) |
+ return NULL; |
+ |
switch (format) { |
case I420: { |
scoped_refptr<VideoFrame> frame(new VideoFrame( |
@@ -243,6 +247,30 @@ size_t VideoFrame::NumPlanes(Format format) { |
return 0; |
} |
+// static |
+size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { |
ncarter (slow)
2013/08/15 20:46:59
The behavior of this function does not match the p
sheu
2013/08/15 21:30:48
The problem is that I'm doing a lot of "if format
|
+ switch (format) { |
+ case VideoFrame::RGB32: |
+ return coded_size.GetArea() * 4; |
+ case VideoFrame::YV12: |
+ case VideoFrame::I420: |
+ return coded_size.GetArea() * 3 / 2; |
+ case VideoFrame::YV16: |
+ return coded_size.GetArea() * 2; |
+ case VideoFrame::YV12A: |
+ return coded_size.GetArea() * 5 / 4; |
+ case VideoFrame::INVALID: |
+ case VideoFrame::EMPTY: |
+ case VideoFrame::NATIVE_TEXTURE: |
+#if defined(GOOGLE_TV) |
+ case VideoFrame::HOLE: |
+#endif |
+ break; |
+ } |
+ NOTREACHED() << "Unsupported video frame format: " << format; |
+ return 0; |
+} |
+ |
static inline size_t RoundUp(size_t value, size_t alignment) { |
// Check that |alignment| is a power of 2. |
DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); |