Index: media/base/video_frame.cc |
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc |
index 661550e55803fc1df758f28e24fbb13bef69ca5e..72c6e6bc6f53b2bc945f878a64366efabe443a86 100644 |
--- a/media/base/video_frame.cc |
+++ b/media/base/video_frame.cc |
@@ -125,7 +125,7 @@ bool VideoFrame::IsValidConfig(VideoPixelFormat format, |
return true; |
// Make sure new formats are properly accounted for in the method. |
- static_assert(PIXEL_FORMAT_MAX == 21, |
+ static_assert(PIXEL_FORMAT_MAX == 23, |
"Added pixel format, please review IsValidConfig()"); |
if (format == PIXEL_FORMAT_UNKNOWN) { |
@@ -170,7 +170,8 @@ scoped_refptr<VideoFrame> VideoFrame::WrapNativeTextures( |
base::TimeDelta timestamp) { |
if (format != PIXEL_FORMAT_ARGB && format != PIXEL_FORMAT_XRGB && |
format != PIXEL_FORMAT_UYVY && format != PIXEL_FORMAT_NV12 && |
- format != PIXEL_FORMAT_I420) { |
+ format != PIXEL_FORMAT_I420 && format != PIXEL_FORMAT_Y8 && |
+ format != PIXEL_FORMAT_Y16) { |
LOG(DFATAL) << "Unsupported pixel format supported, got " |
<< VideoPixelFormatToString(format); |
return nullptr; |
@@ -218,6 +219,31 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( |
} |
// static |
+scoped_refptr<VideoFrame> VideoFrame::WrapExternalGpuMemoryBuffer( |
+ VideoPixelFormat format, |
+ const gfx::Size& coded_size, |
+ const gfx::Rect& visible_rect, |
+ const gfx::Size& natural_size, |
+ uint8_t* data, |
+ const gfx::GpuMemoryBufferHandle& handle, |
+ base::TimeDelta timestamp) { |
+ const StorageType storage = STORAGE_GPU_MEMORY_BUFFERS; |
+ if (!IsValidConfig(format, storage, coded_size, visible_rect, natural_size)) { |
+ LOG(DFATAL) << __func__ << " Invalid config." |
+ << ConfigToString(format, storage, coded_size, visible_rect, |
+ natural_size); |
+ return nullptr; |
+ } |
+ |
+ scoped_refptr<VideoFrame> frame(new VideoFrame( |
+ format, storage, coded_size, visible_rect, natural_size, timestamp)); |
+ frame->strides_[0] = coded_size.width() * BytesPerElement(format, 0); |
+ frame->data_[0] = data; |
+ frame->gpu_memory_buffer_handles_.push_back(handle); |
+ return frame; |
+} |
+ |
+// static |
scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( |
VideoPixelFormat format, |
const gfx::Size& coded_size, |
@@ -535,6 +561,8 @@ size_t VideoFrame::NumPlanes(VideoPixelFormat format) { |
case PIXEL_FORMAT_RGB24: |
case PIXEL_FORMAT_RGB32: |
case PIXEL_FORMAT_MJPEG: |
+ case PIXEL_FORMAT_Y8: |
+ case PIXEL_FORMAT_Y16: |
return 1; |
case PIXEL_FORMAT_NV12: |
case PIXEL_FORMAT_NV21: |
@@ -644,6 +672,24 @@ void VideoFrame::HashFrameForTesting(base::MD5Context* context, |
} |
} |
+// static |
+gfx::BufferFormat VideoFrame::BufferFormat(VideoPixelFormat format) { |
+ switch (format) { |
+ case PIXEL_FORMAT_I420: |
+ case PIXEL_FORMAT_Y8: |
+ return gfx::BufferFormat::R_8; |
+ case PIXEL_FORMAT_NV12: |
+ return gfx::BufferFormat::YUV_420_BIPLANAR; |
+ case PIXEL_FORMAT_UYVY: |
+ return gfx::BufferFormat::UYVY_422; |
+ case PIXEL_FORMAT_Y16: |
+ return gfx::BufferFormat::RG_88; |
+ default: |
+ NOTREACHED(); |
+ return gfx::BufferFormat::BGRA_8888; |
+ } |
+} |
+ |
bool VideoFrame::IsMappable() const { |
return IsStorageTypeMappable(storage_type_); |
} |
@@ -839,8 +885,10 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalStorage( |
// TODO(miu): This function should support any pixel format. |
// http://crbug.com/555909 |
- if (format != PIXEL_FORMAT_I420) { |
- LOG(DFATAL) << "Only PIXEL_FORMAT_I420 format supported: " |
+ if (format != PIXEL_FORMAT_I420 && format != PIXEL_FORMAT_Y8 && |
+ format != PIXEL_FORMAT_Y16) { |
+ LOG(DFATAL) << "Only PIXEL_FORMAT_I420, PIXEL_FORMAT_Y8 and " |
+ "PIXEL_FORMAT_Y16 formats are supported: " |
<< VideoPixelFormatToString(format); |
return nullptr; |
} |
@@ -861,6 +909,15 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalStorage( |
frame = new VideoFrame(format, storage_type, coded_size, visible_rect, |
natural_size, timestamp); |
} |
+ if (format == PIXEL_FORMAT_Y8 || format == PIXEL_FORMAT_Y16) { |
+ // TODO(astojilj) Make this code generic for all and move format specifics |
+ // to static methods. |
+ DCHECK_EQ(NumPlanes(format), 1U); |
+ const size_t i = 0; |
+ frame->strides_[i] = coded_size.width() * BytesPerElement(format, i); |
+ frame->data_[i] = data; |
+ return frame; |
+ } |
frame->strides_[kYPlane] = coded_size.width(); |
// TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes() |
// always rounds up. This inconsistency must be resolved. Perhaps a |
@@ -1040,6 +1097,8 @@ gfx::Size VideoFrame::SampleSize(VideoPixelFormat format, size_t plane) { |
case PIXEL_FORMAT_YV24: |
case PIXEL_FORMAT_YUV444P9: |
case PIXEL_FORMAT_YUV444P10: |
+ case PIXEL_FORMAT_Y8: |
+ case PIXEL_FORMAT_Y16: |
return gfx::Size(1, 1); |
case PIXEL_FORMAT_YV16: |
@@ -1090,6 +1149,7 @@ int VideoFrame::BytesPerElement(VideoPixelFormat format, size_t plane) { |
case PIXEL_FORMAT_YUV420P10: |
case PIXEL_FORMAT_YUV422P10: |
case PIXEL_FORMAT_YUV444P10: |
+ case PIXEL_FORMAT_Y16: |
return 2; |
case PIXEL_FORMAT_NV12: |
case PIXEL_FORMAT_NV21: |
@@ -1103,6 +1163,7 @@ int VideoFrame::BytesPerElement(VideoPixelFormat format, size_t plane) { |
case PIXEL_FORMAT_YV16: |
case PIXEL_FORMAT_YV12A: |
case PIXEL_FORMAT_YV24: |
+ case PIXEL_FORMAT_Y8: |
return 1; |
case PIXEL_FORMAT_MJPEG: |
return 0; |