Commit ab977781 authored by dcastagna's avatar dcastagna Committed by Commit bot

media: GMBVideoFramePool, crop VideoFrame using visible_rect.

VideoFrame::visible_rect could be different than natural_size when the
VideoFrame is coming from a media stream that is from a camera.
crrev.com/1358883003 is planning to convert the video frames coming from
different media sources.

This CL crops VideoFrame using visible_rect when it gets converted to
a new VideoFrame backed by GpuMemoryBuffers.

BUG=

Review URL: https://codereview.chromium.org/1371683002

Cr-Commit-Position: refs/heads/master@{#351149}
parent f10715e2
...@@ -257,13 +257,13 @@ void CopyRowsToNV12Buffer(int first_row, ...@@ -257,13 +257,13 @@ void CopyRowsToNV12Buffer(int first_row,
DCHECK_EQ(0, first_row % 2); DCHECK_EQ(0, first_row % 2);
libyuv::I420ToNV12( libyuv::I420ToNV12(
source_frame->data(VideoFrame::kYPlane) + source_frame->visible_data(VideoFrame::kYPlane) +
first_row * source_frame->stride(VideoFrame::kYPlane), first_row * source_frame->stride(VideoFrame::kYPlane),
source_frame->stride(VideoFrame::kYPlane), source_frame->stride(VideoFrame::kYPlane),
source_frame->data(VideoFrame::kUPlane) + source_frame->visible_data(VideoFrame::kUPlane) +
first_row / 2 * source_frame->stride(VideoFrame::kUPlane), first_row / 2 * source_frame->stride(VideoFrame::kUPlane),
source_frame->stride(VideoFrame::kUPlane), source_frame->stride(VideoFrame::kUPlane),
source_frame->data(VideoFrame::kVPlane) + source_frame->visible_data(VideoFrame::kVPlane) +
first_row / 2 * source_frame->stride(VideoFrame::kVPlane), first_row / 2 * source_frame->stride(VideoFrame::kVPlane),
source_frame->stride(VideoFrame::kVPlane), source_frame->stride(VideoFrame::kVPlane),
dest_y + first_row * dest_stride_y, dest_stride_y, dest_y + first_row * dest_stride_y, dest_stride_y,
...@@ -287,13 +287,13 @@ void CopyRowsToUYVYBuffer(int first_row, ...@@ -287,13 +287,13 @@ void CopyRowsToUYVYBuffer(int first_row,
DCHECK_LE(width, std::abs(dest_stride / 2)); DCHECK_LE(width, std::abs(dest_stride / 2));
DCHECK_EQ(0, first_row % 2); DCHECK_EQ(0, first_row % 2);
libyuv::I420ToUYVY( libyuv::I420ToUYVY(
source_frame->data(VideoFrame::kYPlane) + source_frame->visible_data(VideoFrame::kYPlane) +
first_row * source_frame->stride(VideoFrame::kYPlane), first_row * source_frame->stride(VideoFrame::kYPlane),
source_frame->stride(VideoFrame::kYPlane), source_frame->stride(VideoFrame::kYPlane),
source_frame->data(VideoFrame::kUPlane) + source_frame->visible_data(VideoFrame::kUPlane) +
first_row / 2 * source_frame->stride(VideoFrame::kUPlane), first_row / 2 * source_frame->stride(VideoFrame::kUPlane),
source_frame->stride(VideoFrame::kUPlane), source_frame->stride(VideoFrame::kUPlane),
source_frame->data(VideoFrame::kVPlane) + source_frame->visible_data(VideoFrame::kVPlane) +
first_row / 2 * source_frame->stride(VideoFrame::kVPlane), first_row / 2 * source_frame->stride(VideoFrame::kVPlane),
source_frame->stride(VideoFrame::kVPlane), source_frame->stride(VideoFrame::kVPlane),
output + first_row * dest_stride, dest_stride, width, rows); output + first_row * dest_stride, dest_stride, width, rows);
...@@ -350,7 +350,6 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CreateHardwareFrame( ...@@ -350,7 +350,6 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CreateHardwareFrame(
return; return;
} }
DCHECK(video_frame->visible_rect().origin().IsOrigin());
const gfx::Size size = video_frame->visible_rect().size(); const gfx::Size size = video_frame->visible_rect().size();
// Acquire resources. Incompatible ones will be dropped from the pool. // Acquire resources. Incompatible ones will be dropped from the pool.
...@@ -391,7 +390,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( ...@@ -391,7 +390,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers(
// Compute the number of tasks to post and create the barrier. // Compute the number of tasks to post and create the barrier.
const size_t num_planes = VideoFrame::NumPlanes(output_format_); const size_t num_planes = VideoFrame::NumPlanes(output_format_);
const size_t planes_per_copy = PlanesPerCopy(output_format_); const size_t planes_per_copy = PlanesPerCopy(output_format_);
gfx::Size size = video_frame->visible_rect().size(); const gfx::Size size = video_frame->visible_rect().size();
size_t copies = 0; size_t copies = 0;
for (size_t i = 0; i < num_planes; i += planes_per_copy) { for (size_t i = 0; i < num_planes; i += planes_per_copy) {
const int rows = VideoFrame::Rows(i, output_format_, size.height()); const int rows = VideoFrame::Rows(i, output_format_, size.height());
...@@ -429,11 +428,10 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( ...@@ -429,11 +428,10 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers(
const int bytes_per_row = const int bytes_per_row =
VideoFrame::RowBytes(i, output_format_, size.width()); VideoFrame::RowBytes(i, output_format_, size.width());
worker_task_runner_->PostTask( worker_task_runner_->PostTask(
FROM_HERE, FROM_HERE, base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy,
base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy, bytes_per_row, video_frame->visible_data(i),
bytes_per_row, video_frame->data(i), video_frame->stride(i), dest_buffers[0],
video_frame->stride(i), dest_buffers[0], dest_strides[0], barrier));
dest_strides[0], barrier));
break; break;
} }
case PIXEL_FORMAT_NV12: case PIXEL_FORMAT_NV12:
...@@ -511,8 +509,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl:: ...@@ -511,8 +509,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::
mailbox_holders[VideoFrame::kUPlane], mailbox_holders[VideoFrame::kUPlane],
mailbox_holders[VideoFrame::kVPlane], mailbox_holders[VideoFrame::kVPlane],
base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources), base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources),
size, video_frame->visible_rect(), video_frame->natural_size(), size, gfx::Rect(size), size, video_frame->timestamp());
video_frame->timestamp());
if (video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY)) if (video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY))
frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true);
break; break;
...@@ -521,8 +518,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl:: ...@@ -521,8 +518,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::
frame = VideoFrame::WrapNativeTexture( frame = VideoFrame::WrapNativeTexture(
output_format_, mailbox_holders[VideoFrame::kYPlane], output_format_, mailbox_holders[VideoFrame::kYPlane],
base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources), base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources),
size, video_frame->visible_rect(), video_frame->natural_size(), size, gfx::Rect(size), size, video_frame->timestamp());
video_frame->timestamp());
frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true);
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment