Chromium Code Reviews| Index: media/video/gpu_memory_buffer_video_frame_pool.cc |
| diff --git a/media/video/gpu_memory_buffer_video_frame_pool.cc b/media/video/gpu_memory_buffer_video_frame_pool.cc |
| index ec93342042195c02efd34d3a83c79b76b0d74b31..43bc8aed399b1069ecfce01476439e430a729525 100644 |
| --- a/media/video/gpu_memory_buffer_video_frame_pool.cc |
| +++ b/media/video/gpu_memory_buffer_video_frame_pool.cc |
| @@ -104,9 +104,7 @@ class GpuMemoryBufferVideoFramePool::PoolImpl |
| // Return true if |resources| can be used to represent a frame for |
| // specific |format| and |size|. |
| static bool AreFrameResourcesCompatible(const FrameResources* resources, |
| - const gfx::Size& size) { |
| - return size == resources->size; |
| - } |
| + const gfx::Size& size); |
| // Get the resources needed for a frame out of the pool, or create them if |
| // necessary. |
| @@ -226,12 +224,14 @@ void CopyRowsToI420Buffer(int first_row, |
| const base::Closure& done) { |
| TRACE_EVENT2("media", "CopyRowsToI420Buffer", "bytes_per_row", bytes_per_row, |
| "rows", rows); |
| - DCHECK_NE(dest_stride, 0); |
| - DCHECK_LE(bytes_per_row, std::abs(dest_stride)); |
| - DCHECK_LE(bytes_per_row, source_stride); |
| - for (int row = first_row; row < first_row + rows; ++row) { |
| - memcpy(output + dest_stride * row, source + source_stride * row, |
| - bytes_per_row); |
| + if (output) { |
| + DCHECK_NE(dest_stride, 0); |
| + DCHECK_LE(bytes_per_row, std::abs(dest_stride)); |
| + DCHECK_LE(bytes_per_row, source_stride); |
| + for (int row = first_row; row < first_row + rows; ++row) { |
| + memcpy(output + dest_stride * row, source + source_stride * row, |
| + bytes_per_row); |
| + } |
| } |
| done.Run(); |
| } |
| @@ -247,24 +247,27 @@ void CopyRowsToNV12Buffer(int first_row, |
| const base::Closure& done) { |
| TRACE_EVENT2("media", "CopyRowsToNV12Buffer", "bytes_per_row", bytes_per_row, |
| "rows", rows); |
| - DCHECK_NE(dest_stride_y, 0); |
| - DCHECK_NE(dest_stride_uv, 0); |
| - DCHECK_LE(bytes_per_row, std::abs(dest_stride_y)); |
| - DCHECK_LE(bytes_per_row, std::abs(dest_stride_uv)); |
| - DCHECK_EQ(0, first_row % 2); |
| - libyuv::I420ToNV12( |
| - source_frame->data(VideoFrame::kYPlane) + |
| - first_row * source_frame->stride(VideoFrame::kYPlane), |
| - source_frame->stride(VideoFrame::kYPlane), |
| - source_frame->data(VideoFrame::kUPlane) + |
| - first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
| - source_frame->stride(VideoFrame::kUPlane), |
| - source_frame->data(VideoFrame::kVPlane) + |
| - first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
| - source_frame->stride(VideoFrame::kVPlane), |
| - dest_y + first_row * dest_stride_y, dest_stride_y, |
| - dest_uv + first_row / 2 * dest_stride_uv, dest_stride_uv, |
| - bytes_per_row, rows); |
| + if (dest_y && dest_uv) { |
| + DCHECK_NE(dest_stride_y, 0); |
| + DCHECK_NE(dest_stride_uv, 0); |
| + DCHECK_LE(bytes_per_row, std::abs(dest_stride_y)); |
| + DCHECK_LE(bytes_per_row, std::abs(dest_stride_uv)); |
| + DCHECK_EQ(0, first_row % 2); |
| + |
| + libyuv::I420ToNV12( |
| + source_frame->data(VideoFrame::kYPlane) + |
| + first_row * source_frame->stride(VideoFrame::kYPlane), |
| + source_frame->stride(VideoFrame::kYPlane), |
| + source_frame->data(VideoFrame::kUPlane) + |
| + first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
| + source_frame->stride(VideoFrame::kUPlane), |
| + source_frame->data(VideoFrame::kVPlane) + |
| + first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
| + source_frame->stride(VideoFrame::kVPlane), |
| + dest_y + first_row * dest_stride_y, dest_stride_y, |
| + dest_uv + first_row / 2 * dest_stride_uv, dest_stride_uv, bytes_per_row, |
| + rows); |
| + } |
| done.Run(); |
| } |
| @@ -277,20 +280,22 @@ void CopyRowsToUYVYBuffer(int first_row, |
| const base::Closure& done) { |
| TRACE_EVENT2("media", "CopyRowsToUYVYBuffer", "bytes_per_row", width * 2, |
| "rows", rows); |
| - DCHECK_NE(dest_stride, 0); |
| - DCHECK_LE(width, std::abs(dest_stride / 2)); |
| - DCHECK_EQ(0, first_row % 2); |
| - libyuv::I420ToUYVY( |
| - source_frame->data(VideoFrame::kYPlane) + |
| - first_row * source_frame->stride(VideoFrame::kYPlane), |
| - source_frame->stride(VideoFrame::kYPlane), |
| - source_frame->data(VideoFrame::kUPlane) + |
| - first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
| - source_frame->stride(VideoFrame::kUPlane), |
| - source_frame->data(VideoFrame::kVPlane) + |
| - first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
| - source_frame->stride(VideoFrame::kVPlane), |
| - output + first_row * dest_stride, dest_stride, width, rows); |
| + if (output) { |
| + DCHECK_NE(dest_stride, 0); |
| + DCHECK_LE(width, std::abs(dest_stride / 2)); |
| + DCHECK_EQ(0, first_row % 2); |
| + libyuv::I420ToUYVY( |
| + source_frame->data(VideoFrame::kYPlane) + |
| + first_row * source_frame->stride(VideoFrame::kYPlane), |
| + source_frame->stride(VideoFrame::kYPlane), |
| + source_frame->data(VideoFrame::kUPlane) + |
| + first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
| + source_frame->stride(VideoFrame::kUPlane), |
| + source_frame->data(VideoFrame::kVPlane) + |
| + first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
| + source_frame->stride(VideoFrame::kVPlane), |
| + output + first_row * dest_stride, dest_stride, width, rows); |
| + } |
| done.Run(); |
| } |
| @@ -401,14 +406,15 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( |
| for (size_t i = 0; i < num_planes; i += planes_per_copy) { |
| gfx::GpuMemoryBuffer* buffer = |
| frame_resources->plane_resources[i].gpu_memory_buffer.get(); |
| - DCHECK(buffer); |
| - DCHECK_EQ(planes_per_copy, |
| - gfx::NumberOfPlanesForBufferFormat(buffer->GetFormat())); |
| - uint8* dest_buffers[VideoFrame::kMaxPlanes]; |
| - int dest_strides[VideoFrame::kMaxPlanes]; |
| - bool rv = buffer->Map(reinterpret_cast<void**>(dest_buffers)); |
| - DCHECK(rv); |
| - buffer->GetStride(dest_strides); |
| + uint8* dest_buffers[VideoFrame::kMaxPlanes] = {0}; |
| + int dest_strides[VideoFrame::kMaxPlanes] = {0}; |
| + if (buffer) { |
| + DCHECK_EQ(planes_per_copy, |
| + gfx::NumberOfPlanesForBufferFormat(buffer->GetFormat())); |
| + bool rv = buffer->Map(reinterpret_cast<void**>(dest_buffers)); |
| + DCHECK(rv); |
| + buffer->GetStride(dest_strides); |
| + } |
| const int rows = VideoFrame::Rows(i, output_format_, size.height()); |
| const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); |
| @@ -467,21 +473,21 @@ void GpuMemoryBufferVideoFramePool::PoolImpl:: |
| // Set up the planes creating the mailboxes needed to refer to the textures. |
| for (size_t i = 0; i < num_planes; i += planes_per_copy) { |
| PlaneResource& plane_resource = frame_resources->plane_resources[i]; |
| - DCHECK(plane_resource.gpu_memory_buffer); |
| // Bind the texture and create or rebind the image. |
| gles2->BindTexture(texture_target_, plane_resource.texture_id); |
| - if (!plane_resource.image_id) { |
| + if (plane_resource.gpu_memory_buffer && !plane_resource.image_id) { |
| const size_t width = VideoFrame::Columns(i, output_format_, size.width()); |
| const size_t height = VideoFrame::Rows(i, output_format_, size.height()); |
| plane_resource.image_id = gles2->CreateImageCHROMIUM( |
| plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, |
| ImageInternalFormat(output_format_, i)); |
| - } else { |
| + } else if (plane_resource.image_id) { |
| gles2->ReleaseTexImage2DCHROMIUM(texture_target_, |
| plane_resource.image_id); |
| } |
| - gles2->BindTexImage2DCHROMIUM(texture_target_, plane_resource.image_id); |
| + if (plane_resource.image_id) |
| + gles2->BindTexImage2DCHROMIUM(texture_target_, plane_resource.image_id); |
| mailbox_holders[i] = |
| gpu::MailboxHolder(plane_resource.mailbox, texture_target_, 0); |
| } |
| @@ -522,6 +528,13 @@ void GpuMemoryBufferVideoFramePool::PoolImpl:: |
| frame_ready_cb.Run(frame); |
| } |
| +// static |
| +bool GpuMemoryBufferVideoFramePool::PoolImpl::AreFrameResourcesCompatible( |
| + const FrameResources* resources, |
| + const gfx::Size& size) { |
| + return size == resources->size; |
| +} |
|
reveman
2015/09/10 00:09:12
is this just being moved from the header? necessar
Daniele Castagna
2015/09/10 00:15:34
Nop.
|
| + |
| // Destroy all the resources posting one task per FrameResources |
| // to the |media_task_runner_|. |
| GpuMemoryBufferVideoFramePool::PoolImpl::~PoolImpl() { |