Index: media/capture/video/video_capture_device_client.cc |
diff --git a/media/capture/video/video_capture_device_client.cc b/media/capture/video/video_capture_device_client.cc |
index 368af81f9ce73b41bba132c1f54cd4b23a8d0470..f142ee104ef45c2ea362f5260ab1698deb92fa76 100644 |
--- a/media/capture/video/video_capture_device_client.cc |
+++ b/media/capture/video/video_capture_device_client.cc |
@@ -28,6 +28,15 @@ using media::VideoCaptureFormat; |
using media::VideoFrame; |
using media::VideoFrameMetadata; |
+namespace { |
+ |
+bool isFormatSupported(media::VideoPixelFormat pixel_format) { |
+ // Currently, only I420 and Y16 pixel formats are supported. |
+ return (pixel_format == media::PIXEL_FORMAT_I420 || |
+ pixel_format == media::PIXEL_FORMAT_Y16); |
+} |
+} |
+ |
namespace media { |
// Class combining a Client::Buffer interface implementation and a pool buffer |
@@ -106,12 +115,22 @@ void VideoCaptureDeviceClient::OnIncomingCapturedData( |
if (!frame_format.IsValid()) |
return; |
+ // The input |length| can be greater than the required buffer size because of |
+ // paddings and/or alignments, but it cannot be smaller. |
+ DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); |
+ |
+ const bool useFullSize = frame_format.pixel_format == media::PIXEL_FORMAT_Y16; |
+ |
// |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest |
// bit decomposition of {width, height}, grabbing the odd and even parts. |
const int chopped_width = frame_format.frame_size.width() & 1; |
const int chopped_height = frame_format.frame_size.height() & 1; |
- const int new_unrotated_width = frame_format.frame_size.width() & ~1; |
- const int new_unrotated_height = frame_format.frame_size.height() & ~1; |
+ const int new_unrotated_width = (useFullSize) |
+ ? frame_format.frame_size.width() |
+ : (frame_format.frame_size.width() & ~1); |
+ const int new_unrotated_height = |
+ (useFullSize) ? frame_format.frame_size.height() |
+ : (frame_format.frame_size.height() & ~1); |
int destination_width = new_unrotated_width; |
int destination_height = new_unrotated_height; |
@@ -132,19 +151,36 @@ void VideoCaptureDeviceClient::OnIncomingCapturedData( |
const media::VideoPixelStorage output_pixel_storage = |
use_gpu_memory_buffers_ ? media::PIXEL_STORAGE_GPUMEMORYBUFFER |
: media::PIXEL_STORAGE_CPU; |
- uint8_t *y_plane_data, *u_plane_data, *v_plane_data; |
+ uint8_t* y_plane_data = 0; |
+ uint8_t* u_plane_data = 0; |
+ uint8_t* v_plane_data = 0; |
+ |
std::unique_ptr<Buffer> buffer( |
- ReserveI420OutputBuffer(dimensions, output_pixel_storage, &y_plane_data, |
- &u_plane_data, &v_plane_data)); |
+ (frame_format.pixel_format == media::PIXEL_FORMAT_Y16) |
+ ? ReserveOutputBuffer(dimensions, frame_format.pixel_format, |
+ output_pixel_storage) |
+ : ReserveI420OutputBuffer(dimensions, output_pixel_storage, |
+ &y_plane_data, &u_plane_data, |
+ &v_plane_data)); |
#if DCHECK_IS_ON() |
dropped_frame_counter_ = buffer.get() ? 0 : dropped_frame_counter_ + 1; |
if (dropped_frame_counter_ >= kMaxDroppedFrames) |
OnError(FROM_HERE, "Too many frames dropped"); |
#endif |
- // Failed to reserve I420 output buffer, so drop the frame. |
+ // Failed to reserve output buffer, so drop the frame. |
if (!buffer.get()) |
return; |
+ if (frame_format.pixel_format == media::PIXEL_FORMAT_Y16) { |
+ memcpy(buffer->data(), data, length); |
+ const VideoCaptureFormat output_format = |
+ VideoCaptureFormat(dimensions, frame_format.frame_rate, |
+ frame_format.pixel_format, output_pixel_storage); |
+ OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
+ timestamp); |
+ return; |
+ } |
+ |
const int yplane_stride = dimensions.width(); |
const int uv_plane_stride = yplane_stride / 2; |
int crop_x = 0; |
@@ -260,8 +296,7 @@ VideoCaptureDeviceClient::ReserveOutputBuffer( |
media::VideoPixelStorage pixel_storage) { |
DCHECK_GT(frame_size.width(), 0); |
DCHECK_GT(frame_size.height(), 0); |
- // Currently, only I420 pixel format is supported. |
- DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
+ DCHECK(isFormatSupported(pixel_format)); |
// TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if |
// it's a ShMem GMB or a DmaBuf GMB. |
@@ -281,29 +316,39 @@ void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( |
const VideoCaptureFormat& frame_format, |
base::TimeTicks reference_time, |
base::TimeDelta timestamp) { |
- // Currently, only I420 pixel format is supported. |
- DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format); |
+ DCHECK(isFormatSupported(frame_format.pixel_format)); |
scoped_refptr<VideoFrame> frame; |
switch (frame_format.pixel_storage) { |
case media::PIXEL_STORAGE_GPUMEMORYBUFFER: { |
+ DCHECK(isFormatSupported(frame_format.pixel_format)); |
// Create a VideoFrame to set the correct storage_type and pixel_format. |
gfx::GpuMemoryBufferHandle handle; |
- frame = VideoFrame::WrapExternalYuvGpuMemoryBuffers( |
- media::PIXEL_FORMAT_I420, frame_format.frame_size, |
- gfx::Rect(frame_format.frame_size), frame_format.frame_size, 0, 0, 0, |
- reinterpret_cast<uint8_t*>(buffer->data(media::VideoFrame::kYPlane)), |
- reinterpret_cast<uint8_t*>(buffer->data(media::VideoFrame::kUPlane)), |
- reinterpret_cast<uint8_t*>(buffer->data(media::VideoFrame::kVPlane)), |
- handle, handle, handle, timestamp); |
+ frame = |
+ (frame_format.pixel_format == media::PIXEL_FORMAT_I420) |
+ ? VideoFrame::WrapExternalYuvGpuMemoryBuffers( |
+ media::PIXEL_FORMAT_I420, frame_format.frame_size, |
+ gfx::Rect(frame_format.frame_size), frame_format.frame_size, |
+ 0, 0, 0, reinterpret_cast<uint8_t*>( |
+ buffer->data(media::VideoFrame::kYPlane)), |
+ reinterpret_cast<uint8_t*>( |
+ buffer->data(media::VideoFrame::kUPlane)), |
+ reinterpret_cast<uint8_t*>( |
+ buffer->data(media::VideoFrame::kVPlane)), |
+ handle, handle, handle, timestamp) |
+ : VideoFrame::WrapExternalGpuMemoryBuffer( |
+ frame_format.pixel_format, frame_format.frame_size, |
+ gfx::Rect(frame_format.frame_size), frame_format.frame_size, |
+ reinterpret_cast<uint8_t*>(buffer->data()), handle, |
+ timestamp); |
break; |
} |
case media::PIXEL_STORAGE_CPU: |
frame = VideoFrame::WrapExternalSharedMemory( |
- media::PIXEL_FORMAT_I420, frame_format.frame_size, |
+ frame_format.pixel_format, frame_format.frame_size, |
gfx::Rect(frame_format.frame_size), frame_format.frame_size, |
reinterpret_cast<uint8_t*>(buffer->data()), |
- VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, |
+ VideoFrame::AllocationSize(frame_format.pixel_format, |
frame_format.frame_size), |
base::SharedMemory::NULLHandle(), 0u, timestamp); |
break; |