Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/video/gpu_memory_buffer_video_frame_pool.h" | 5 #include "media/video/gpu_memory_buffer_video_frame_pool.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 TRACE_EVENT2("media", "CopyRowsToNV12Buffer", "bytes_per_row", bytes_per_row, | 250 TRACE_EVENT2("media", "CopyRowsToNV12Buffer", "bytes_per_row", bytes_per_row, |
| 251 "rows", rows); | 251 "rows", rows); |
| 252 if (dest_y && dest_uv) { | 252 if (dest_y && dest_uv) { |
| 253 DCHECK_NE(dest_stride_y, 0); | 253 DCHECK_NE(dest_stride_y, 0); |
| 254 DCHECK_NE(dest_stride_uv, 0); | 254 DCHECK_NE(dest_stride_uv, 0); |
| 255 DCHECK_LE(bytes_per_row, std::abs(dest_stride_y)); | 255 DCHECK_LE(bytes_per_row, std::abs(dest_stride_y)); |
| 256 DCHECK_LE(bytes_per_row, std::abs(dest_stride_uv)); | 256 DCHECK_LE(bytes_per_row, std::abs(dest_stride_uv)); |
| 257 DCHECK_EQ(0, first_row % 2); | 257 DCHECK_EQ(0, first_row % 2); |
| 258 | 258 |
| 259 libyuv::I420ToNV12( | 259 libyuv::I420ToNV12( |
| 260 source_frame->data(VideoFrame::kYPlane) + | 260 source_frame->visible_data(VideoFrame::kYPlane) + |
| 261 first_row * source_frame->stride(VideoFrame::kYPlane), | 261 first_row * source_frame->stride(VideoFrame::kYPlane), |
| 262 source_frame->stride(VideoFrame::kYPlane), | 262 source_frame->stride(VideoFrame::kYPlane), |
| 263 source_frame->data(VideoFrame::kUPlane) + | 263 source_frame->visible_data(VideoFrame::kUPlane) + |
| 264 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), | 264 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
| 265 source_frame->stride(VideoFrame::kUPlane), | 265 source_frame->stride(VideoFrame::kUPlane), |
| 266 source_frame->data(VideoFrame::kVPlane) + | 266 source_frame->visible_data(VideoFrame::kVPlane) + |
| 267 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), | 267 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
| 268 source_frame->stride(VideoFrame::kVPlane), | 268 source_frame->stride(VideoFrame::kVPlane), |
| 269 dest_y + first_row * dest_stride_y, dest_stride_y, | 269 dest_y + first_row * dest_stride_y, dest_stride_y, |
| 270 dest_uv + first_row / 2 * dest_stride_uv, dest_stride_uv, bytes_per_row, | 270 dest_uv + first_row / 2 * dest_stride_uv, dest_stride_uv, bytes_per_row, |
| 271 rows); | 271 rows); |
| 272 } | 272 } |
| 273 done.Run(); | 273 done.Run(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void CopyRowsToUYVYBuffer(int first_row, | 276 void CopyRowsToUYVYBuffer(int first_row, |
| 277 int rows, | 277 int rows, |
| 278 int width, | 278 int width, |
| 279 const scoped_refptr<VideoFrame>& source_frame, | 279 const scoped_refptr<VideoFrame>& source_frame, |
| 280 uint8* output, | 280 uint8* output, |
| 281 int dest_stride, | 281 int dest_stride, |
| 282 const base::Closure& done) { | 282 const base::Closure& done) { |
| 283 TRACE_EVENT2("media", "CopyRowsToUYVYBuffer", "bytes_per_row", width * 2, | 283 TRACE_EVENT2("media", "CopyRowsToUYVYBuffer", "bytes_per_row", width * 2, |
| 284 "rows", rows); | 284 "rows", rows); |
| 285 if (output) { | 285 if (output) { |
| 286 DCHECK_NE(dest_stride, 0); | 286 DCHECK_NE(dest_stride, 0); |
| 287 DCHECK_LE(width, std::abs(dest_stride / 2)); | 287 DCHECK_LE(width, std::abs(dest_stride / 2)); |
| 288 DCHECK_EQ(0, first_row % 2); | 288 DCHECK_EQ(0, first_row % 2); |
| 289 libyuv::I420ToUYVY( | 289 libyuv::I420ToUYVY( |
| 290 source_frame->data(VideoFrame::kYPlane) + | 290 source_frame->visible_data(VideoFrame::kYPlane) + |
| 291 first_row * source_frame->stride(VideoFrame::kYPlane), | 291 first_row * source_frame->stride(VideoFrame::kYPlane), |
| 292 source_frame->stride(VideoFrame::kYPlane), | 292 source_frame->stride(VideoFrame::kYPlane), |
| 293 source_frame->data(VideoFrame::kUPlane) + | 293 source_frame->visible_data(VideoFrame::kUPlane) + |
| 294 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), | 294 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
| 295 source_frame->stride(VideoFrame::kUPlane), | 295 source_frame->stride(VideoFrame::kUPlane), |
| 296 source_frame->data(VideoFrame::kVPlane) + | 296 source_frame->visible_data(VideoFrame::kVPlane) + |
| 297 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), | 297 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
| 298 source_frame->stride(VideoFrame::kVPlane), | 298 source_frame->stride(VideoFrame::kVPlane), |
| 299 output + first_row * dest_stride, dest_stride, width, rows); | 299 output + first_row * dest_stride, dest_stride, width, rows); |
| 300 } | 300 } |
| 301 done.Run(); | 301 done.Run(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 } // unnamed namespace | 304 } // unnamed namespace |
| 305 | 305 |
| 306 // Creates a VideoFrame backed by native textures starting from a software | 306 // Creates a VideoFrame backed by native textures starting from a software |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 case PIXEL_FORMAT_XRGB: | 343 case PIXEL_FORMAT_XRGB: |
| 344 case PIXEL_FORMAT_RGB24: | 344 case PIXEL_FORMAT_RGB24: |
| 345 case PIXEL_FORMAT_RGB32: | 345 case PIXEL_FORMAT_RGB32: |
| 346 case PIXEL_FORMAT_MJPEG: | 346 case PIXEL_FORMAT_MJPEG: |
| 347 case PIXEL_FORMAT_MT21: | 347 case PIXEL_FORMAT_MT21: |
| 348 case PIXEL_FORMAT_UNKNOWN: | 348 case PIXEL_FORMAT_UNKNOWN: |
| 349 frame_ready_cb.Run(video_frame); | 349 frame_ready_cb.Run(video_frame); |
| 350 return; | 350 return; |
| 351 } | 351 } |
| 352 | 352 |
| 353 DCHECK(video_frame->visible_rect().origin().IsOrigin()); | |
| 354 const gfx::Size size = video_frame->visible_rect().size(); | 353 const gfx::Size size = video_frame->visible_rect().size(); |
| 355 | 354 |
| 356 // Acquire resources. Incompatible ones will be dropped from the pool. | 355 // Acquire resources. Incompatible ones will be dropped from the pool. |
| 357 FrameResources* frame_resources = | 356 FrameResources* frame_resources = |
| 358 GetOrCreateFrameResources(size, output_format_); | 357 GetOrCreateFrameResources(size, output_format_); |
| 359 if (!frame_resources) { | 358 if (!frame_resources) { |
| 360 frame_ready_cb.Run(video_frame); | 359 frame_ready_cb.Run(video_frame); |
| 361 return; | 360 return; |
| 362 } | 361 } |
| 363 | 362 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 384 // Copies |video_frame| into |frame_resources| asynchronously, posting n tasks | 383 // Copies |video_frame| into |frame_resources| asynchronously, posting n tasks |
| 385 // that will be synchronized by a barrier. | 384 // that will be synchronized by a barrier. |
| 386 // After the barrier is passed OnCopiesDone will be called. | 385 // After the barrier is passed OnCopiesDone will be called. |
| 387 void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( | 386 void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( |
| 388 const scoped_refptr<VideoFrame>& video_frame, | 387 const scoped_refptr<VideoFrame>& video_frame, |
| 389 FrameResources* frame_resources, | 388 FrameResources* frame_resources, |
| 390 const FrameReadyCB& frame_ready_cb) { | 389 const FrameReadyCB& frame_ready_cb) { |
| 391 // Compute the number of tasks to post and create the barrier. | 390 // Compute the number of tasks to post and create the barrier. |
| 392 const size_t num_planes = VideoFrame::NumPlanes(output_format_); | 391 const size_t num_planes = VideoFrame::NumPlanes(output_format_); |
| 393 const size_t planes_per_copy = PlanesPerCopy(output_format_); | 392 const size_t planes_per_copy = PlanesPerCopy(output_format_); |
| 394 gfx::Size size = video_frame->visible_rect().size(); | 393 gfx::Size size = video_frame->visible_rect().size(); |
|
emircan
2015/09/26 02:20:12
const
Daniele Castagna
2015/09/28 15:46:57
Done.
| |
| 395 size_t copies = 0; | 394 size_t copies = 0; |
| 396 for (size_t i = 0; i < num_planes; i += planes_per_copy) { | 395 for (size_t i = 0; i < num_planes; i += planes_per_copy) { |
| 397 const int rows = VideoFrame::Rows(i, output_format_, size.height()); | 396 const int rows = VideoFrame::Rows(i, output_format_, size.height()); |
| 398 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); | 397 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); |
| 399 copies += rows / rows_per_copy; | 398 copies += rows / rows_per_copy; |
| 400 if (rows % rows_per_copy) | 399 if (rows % rows_per_copy) |
| 401 ++copies; | 400 ++copies; |
| 402 } | 401 } |
| 403 base::Closure copies_done = | 402 base::Closure copies_done = |
| 404 base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources, | 403 base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 422 const int rows = VideoFrame::Rows(i, output_format_, size.height()); | 421 const int rows = VideoFrame::Rows(i, output_format_, size.height()); |
| 423 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); | 422 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); |
| 424 | 423 |
| 425 for (int row = 0; row < rows; row += rows_per_copy) { | 424 for (int row = 0; row < rows; row += rows_per_copy) { |
| 426 const int rows_to_copy = std::min(rows_per_copy, rows - row); | 425 const int rows_to_copy = std::min(rows_per_copy, rows - row); |
| 427 switch (output_format_) { | 426 switch (output_format_) { |
| 428 case PIXEL_FORMAT_I420: { | 427 case PIXEL_FORMAT_I420: { |
| 429 const int bytes_per_row = | 428 const int bytes_per_row = |
| 430 VideoFrame::RowBytes(i, output_format_, size.width()); | 429 VideoFrame::RowBytes(i, output_format_, size.width()); |
| 431 worker_task_runner_->PostTask( | 430 worker_task_runner_->PostTask( |
| 432 FROM_HERE, | 431 FROM_HERE, base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy, |
| 433 base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy, | 432 bytes_per_row, video_frame->visible_data(i), |
| 434 bytes_per_row, video_frame->data(i), | 433 video_frame->stride(i), dest_buffers[0], |
| 435 video_frame->stride(i), dest_buffers[0], | 434 dest_strides[0], barrier)); |
| 436 dest_strides[0], barrier)); | |
| 437 break; | 435 break; |
| 438 } | 436 } |
| 439 case PIXEL_FORMAT_NV12: | 437 case PIXEL_FORMAT_NV12: |
| 440 worker_task_runner_->PostTask( | 438 worker_task_runner_->PostTask( |
| 441 FROM_HERE, | 439 FROM_HERE, |
| 442 base::Bind(&CopyRowsToNV12Buffer, row, rows_to_copy, | 440 base::Bind(&CopyRowsToNV12Buffer, row, rows_to_copy, |
| 443 size.width(), video_frame, dest_buffers[0], | 441 size.width(), video_frame, dest_buffers[0], |
| 444 dest_strides[0], dest_buffers[1], dest_strides[1], | 442 dest_strides[0], dest_buffers[1], dest_strides[1], |
| 445 barrier)); | 443 barrier)); |
| 446 break; | 444 break; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 | 502 |
| 505 scoped_refptr<VideoFrame> frame; | 503 scoped_refptr<VideoFrame> frame; |
| 506 // Create the VideoFrame backed by native textures. | 504 // Create the VideoFrame backed by native textures. |
| 507 switch (output_format_) { | 505 switch (output_format_) { |
| 508 case PIXEL_FORMAT_I420: | 506 case PIXEL_FORMAT_I420: |
| 509 frame = VideoFrame::WrapYUV420NativeTextures( | 507 frame = VideoFrame::WrapYUV420NativeTextures( |
| 510 mailbox_holders[VideoFrame::kYPlane], | 508 mailbox_holders[VideoFrame::kYPlane], |
| 511 mailbox_holders[VideoFrame::kUPlane], | 509 mailbox_holders[VideoFrame::kUPlane], |
| 512 mailbox_holders[VideoFrame::kVPlane], | 510 mailbox_holders[VideoFrame::kVPlane], |
| 513 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources), | 511 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources), |
| 514 size, video_frame->visible_rect(), video_frame->natural_size(), | 512 size, gfx::Rect(size), size, video_frame->timestamp()); |
| 515 video_frame->timestamp()); | |
| 516 if (video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY)) | 513 if (video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY)) |
| 517 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); | 514 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); |
| 518 break; | 515 break; |
| 519 case PIXEL_FORMAT_NV12: | 516 case PIXEL_FORMAT_NV12: |
| 520 case PIXEL_FORMAT_UYVY: | 517 case PIXEL_FORMAT_UYVY: |
| 521 frame = VideoFrame::WrapNativeTexture( | 518 frame = VideoFrame::WrapNativeTexture( |
| 522 output_format_, mailbox_holders[VideoFrame::kYPlane], | 519 output_format_, mailbox_holders[VideoFrame::kYPlane], |
| 523 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources), | 520 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources), |
| 524 size, video_frame->visible_rect(), video_frame->natural_size(), | 521 size, gfx::Rect(size), size, video_frame->timestamp()); |
| 525 video_frame->timestamp()); | |
| 526 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); | 522 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, true); |
| 527 break; | 523 break; |
| 528 default: | 524 default: |
| 529 NOTREACHED(); | 525 NOTREACHED(); |
| 530 } | 526 } |
| 531 frame_ready_cb.Run(frame); | 527 frame_ready_cb.Run(frame); |
| 532 } | 528 } |
| 533 | 529 |
| 534 // Destroy all the resources posting one task per FrameResources | 530 // Destroy all the resources posting one task per FrameResources |
| 535 // to the |media_task_runner_|. | 531 // to the |media_task_runner_|. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 } | 649 } |
| 654 | 650 |
| 655 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( | 651 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( |
| 656 const scoped_refptr<VideoFrame>& video_frame, | 652 const scoped_refptr<VideoFrame>& video_frame, |
| 657 const FrameReadyCB& frame_ready_cb) { | 653 const FrameReadyCB& frame_ready_cb) { |
| 658 DCHECK(video_frame); | 654 DCHECK(video_frame); |
| 659 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); | 655 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); |
| 660 } | 656 } |
| 661 | 657 |
| 662 } // namespace media | 658 } // namespace media |
| OLD | NEW |