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..2d937a226b1c82064ee2295fbd909fa9abd56450 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,20 @@ void GpuMemoryBufferVideoFramePool::PoolImpl:: |
frame_ready_cb.Run(frame); |
} |
+// static |
+bool GpuMemoryBufferVideoFramePool::PoolImpl::AreFrameResourcesCompatible( |
+ const FrameResources* resources, |
+ const gfx::Size& size) { |
+ if (size != resources->size) |
+ return false; |
+ for (const PlaneResource& plane : resources->plane_resources) { |
+ if (!plane.gpu_memory_buffer && |
+ plane.texture_id) // This happens if we failed to allocate a GMB |
+ return false; |
reveman
2015/09/09 22:45:28
Not needed as discussed.
Daniele Castagna
2015/09/10 00:04:20
Done. Also removed the second part of the test tha
|
+ } |
+ return true; |
+} |
+ |
// Destroy all the resources posting one task per FrameResources |
// to the |media_task_runner_|. |
GpuMemoryBufferVideoFramePool::PoolImpl::~PoolImpl() { |