Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: media/video/gpu_memory_buffer_video_frame_pool.cc

Issue 2648633005: cros: Support YUYV format for GPU memory buffer video frames
Patch Set: Enable YUYV GPU memory buffer video frames Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return gfx::BufferFormat::R_8; 175 return gfx::BufferFormat::R_8;
176 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: 176 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
177 DCHECK_LE(plane, 1u); 177 DCHECK_LE(plane, 1u);
178 return gfx::BufferFormat::YUV_420_BIPLANAR; 178 return gfx::BufferFormat::YUV_420_BIPLANAR;
179 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: 179 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB:
180 DCHECK_LE(plane, 1u); 180 DCHECK_LE(plane, 1u);
181 return plane == 0 ? gfx::BufferFormat::R_8 : gfx::BufferFormat::RG_88; 181 return plane == 0 ? gfx::BufferFormat::R_8 : gfx::BufferFormat::RG_88;
182 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 182 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
183 DCHECK_EQ(0u, plane); 183 DCHECK_EQ(0u, plane);
184 return gfx::BufferFormat::UYVY_422; 184 return gfx::BufferFormat::UYVY_422;
185 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
186 DCHECK_EQ(0u, plane);
187 return gfx::BufferFormat::YUYV_422;
185 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: 188 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
186 NOTREACHED(); 189 NOTREACHED();
187 break; 190 break;
188 } 191 }
189 return gfx::BufferFormat::BGRA_8888; 192 return gfx::BufferFormat::BGRA_8888;
190 } 193 }
191 194
192 unsigned ImageInternalFormat(GpuVideoAcceleratorFactories::OutputFormat format, 195 unsigned ImageInternalFormat(GpuVideoAcceleratorFactories::OutputFormat format,
193 size_t plane) { 196 size_t plane) {
194 switch (format) { 197 switch (format) {
195 case GpuVideoAcceleratorFactories::OutputFormat::I420: 198 case GpuVideoAcceleratorFactories::OutputFormat::I420:
196 DCHECK_LE(plane, 2u); 199 DCHECK_LE(plane, 2u);
197 return GL_RED_EXT; 200 return GL_RED_EXT;
198 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: 201 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB:
199 DCHECK_LE(plane, 1u); 202 DCHECK_LE(plane, 1u);
200 return plane == 0 ? GL_RED_EXT : GL_RG_EXT; 203 return plane == 0 ? GL_RED_EXT : GL_RG_EXT;
201 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: 204 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
202 DCHECK_LE(plane, 1u); 205 DCHECK_LE(plane, 1u);
203 return GL_RGB_YCBCR_420V_CHROMIUM; 206 return GL_RGB_YCBCR_420V_CHROMIUM;
204 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 207 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
208 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
205 DCHECK_EQ(0u, plane); 209 DCHECK_EQ(0u, plane);
206 return GL_RGB_YCBCR_422_CHROMIUM; 210 return GL_RGB_YCBCR_422_CHROMIUM;
207 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: 211 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
208 NOTREACHED(); 212 NOTREACHED();
209 break; 213 break;
210 } 214 }
211 return 0; 215 return 0;
212 } 216 }
213 217
214 // The number of output planes to be copied in each iteration. 218 // The number of output planes to be copied in each iteration.
215 size_t PlanesPerCopy(GpuVideoAcceleratorFactories::OutputFormat format) { 219 size_t PlanesPerCopy(GpuVideoAcceleratorFactories::OutputFormat format) {
216 switch (format) { 220 switch (format) {
217 case GpuVideoAcceleratorFactories::OutputFormat::I420: 221 case GpuVideoAcceleratorFactories::OutputFormat::I420:
218 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 222 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
223 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
219 return 1; 224 return 1;
220 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: 225 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB:
221 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: 226 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
222 return 2; 227 return 2;
223 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: 228 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
224 NOTREACHED(); 229 NOTREACHED();
225 break; 230 break;
226 } 231 }
227 return 0; 232 return 0;
228 } 233 }
229 234
230 VideoPixelFormat VideoFormat( 235 VideoPixelFormat VideoFormat(
231 GpuVideoAcceleratorFactories::OutputFormat format) { 236 GpuVideoAcceleratorFactories::OutputFormat format) {
232 switch (format) { 237 switch (format) {
233 case GpuVideoAcceleratorFactories::OutputFormat::I420: 238 case GpuVideoAcceleratorFactories::OutputFormat::I420:
234 return PIXEL_FORMAT_I420; 239 return PIXEL_FORMAT_I420;
235 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: 240 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
236 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: 241 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB:
237 return PIXEL_FORMAT_NV12; 242 return PIXEL_FORMAT_NV12;
238 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 243 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
239 return PIXEL_FORMAT_UYVY; 244 return PIXEL_FORMAT_UYVY;
245 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
246 return PIXEL_FORMAT_YUY2;
240 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: 247 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
241 NOTREACHED(); 248 NOTREACHED();
242 break; 249 break;
243 } 250 }
244 return PIXEL_FORMAT_UNKNOWN; 251 return PIXEL_FORMAT_UNKNOWN;
245 } 252 }
246 253
247 VideoPixelFormat FinalVideoFormat( 254 VideoPixelFormat FinalVideoFormat(
248 GpuVideoAcceleratorFactories::OutputFormat format) { 255 GpuVideoAcceleratorFactories::OutputFormat format) {
249 // Consumers should sample from NV12 textures as if they're XRGB. 256 // Consumers should sample from NV12 textures as if they're XRGB.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), 353 first_row / 2 * source_frame->stride(VideoFrame::kUPlane),
347 source_frame->stride(VideoFrame::kUPlane), 354 source_frame->stride(VideoFrame::kUPlane),
348 source_frame->visible_data(VideoFrame::kVPlane) + 355 source_frame->visible_data(VideoFrame::kVPlane) +
349 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), 356 first_row / 2 * source_frame->stride(VideoFrame::kVPlane),
350 source_frame->stride(VideoFrame::kVPlane), 357 source_frame->stride(VideoFrame::kVPlane),
351 output + first_row * dest_stride, dest_stride, width, rows); 358 output + first_row * dest_stride, dest_stride, width, rows);
352 } 359 }
353 done.Run(); 360 done.Run();
354 } 361 }
355 362
363 void CopyRowsToYUYVBuffer(int first_row,
364 int rows,
365 int width,
366 const scoped_refptr<VideoFrame>& source_frame,
367 uint8_t* output,
368 int dest_stride,
369 const base::Closure& done) {
370 TRACE_EVENT2("media", "CopyRowsToYUYVBuffer", "bytes_per_row", width * 2,
371 "rows", rows);
372 if (output) {
373 DCHECK_NE(dest_stride, 0);
374 DCHECK_LE(width, std::abs(dest_stride / 2));
375 DCHECK_EQ(0, first_row % 2);
376 libyuv::I420ToYUY2(
377 source_frame->visible_data(VideoFrame::kYPlane) +
378 first_row * source_frame->stride(VideoFrame::kYPlane),
379 source_frame->stride(VideoFrame::kYPlane),
380 source_frame->visible_data(VideoFrame::kUPlane) +
381 first_row / 2 * source_frame->stride(VideoFrame::kUPlane),
382 source_frame->stride(VideoFrame::kUPlane),
383 source_frame->visible_data(VideoFrame::kVPlane) +
384 first_row / 2 * source_frame->stride(VideoFrame::kVPlane),
385 source_frame->stride(VideoFrame::kVPlane),
386 output + first_row * dest_stride, dest_stride, width, rows);
387 }
388 done.Run();
389 }
390
356 gfx::Size CodedSize(const scoped_refptr<VideoFrame>& video_frame, 391 gfx::Size CodedSize(const scoped_refptr<VideoFrame>& video_frame,
357 GpuVideoAcceleratorFactories::OutputFormat output_format) { 392 GpuVideoAcceleratorFactories::OutputFormat output_format) {
358 DCHECK(gfx::Rect(video_frame->coded_size()) 393 DCHECK(gfx::Rect(video_frame->coded_size())
359 .Contains(video_frame->visible_rect())); 394 .Contains(video_frame->visible_rect()));
360 DCHECK((video_frame->visible_rect().x() & 1) == 0); 395 DCHECK((video_frame->visible_rect().x() & 1) == 0);
361 gfx::Size output; 396 gfx::Size output;
362 switch (output_format) { 397 switch (output_format) {
363 case GpuVideoAcceleratorFactories::OutputFormat::I420: 398 case GpuVideoAcceleratorFactories::OutputFormat::I420:
364 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: 399 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
365 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: 400 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB:
366 DCHECK((video_frame->visible_rect().y() & 1) == 0); 401 DCHECK((video_frame->visible_rect().y() & 1) == 0);
367 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1, 402 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1,
368 (video_frame->visible_rect().height() + 1) & ~1); 403 (video_frame->visible_rect().height() + 1) & ~1);
369 break; 404 break;
405
370 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 406 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
407 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
371 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1, 408 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1,
372 video_frame->visible_rect().height()); 409 video_frame->visible_rect().height());
373 break; 410 break;
374 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: 411 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
375 NOTREACHED(); 412 NOTREACHED();
376 } 413 }
377 DCHECK(gfx::Rect(video_frame->coded_size()).Contains(gfx::Rect(output))); 414 DCHECK(gfx::Rect(video_frame->coded_size()).Contains(gfx::Rect(output)));
378 return output; 415 return output;
379 } 416 }
380 } // unnamed namespace 417 } // unnamed namespace
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 break; 621 break;
585 } 622 }
586 623
587 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 624 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
588 worker_task_runner_->PostTask( 625 worker_task_runner_->PostTask(
589 FROM_HERE, base::Bind(&CopyRowsToUYVYBuffer, row, rows_to_copy, 626 FROM_HERE, base::Bind(&CopyRowsToUYVYBuffer, row, rows_to_copy,
590 coded_size.width(), video_frame, 627 coded_size.width(), video_frame,
591 static_cast<uint8_t*>(buffer->memory(0)), 628 static_cast<uint8_t*>(buffer->memory(0)),
592 buffer->stride(0), barrier)); 629 buffer->stride(0), barrier));
593 break; 630 break;
631 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
632 worker_task_runner_->PostTask(
633 FROM_HERE, base::Bind(&CopyRowsToYUYVBuffer, row, rows_to_copy,
634 coded_size.width(), video_frame,
635 static_cast<uint8_t*>(buffer->memory(0)),
636 buffer->stride(0), barrier));
637 break;
638
594 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: 639 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
595 NOTREACHED(); 640 NOTREACHED();
596 } 641 }
597 } 642 }
598 } 643 }
599 } 644 }
600 645
601 void GpuMemoryBufferVideoFramePool::PoolImpl:: 646 void GpuMemoryBufferVideoFramePool::PoolImpl::
602 BindAndCreateMailboxesHardwareFrameResources( 647 BindAndCreateMailboxesHardwareFrameResources(
603 const scoped_refptr<VideoFrame>& video_frame, 648 const scoped_refptr<VideoFrame>& video_frame,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 bool allow_overlay = false; 717 bool allow_overlay = false;
673 switch (output_format_) { 718 switch (output_format_) {
674 case GpuVideoAcceleratorFactories::OutputFormat::I420: 719 case GpuVideoAcceleratorFactories::OutputFormat::I420:
675 allow_overlay = 720 allow_overlay =
676 video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY); 721 video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY);
677 break; 722 break;
678 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: 723 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
679 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: 724 case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
680 allow_overlay = true; 725 allow_overlay = true;
681 break; 726 break;
727 case GpuVideoAcceleratorFactories::OutputFormat::YUYV:
728 // IA ChromeOS doesn't support overlay for YUYV GPU_READ_CPU_READ_WRITE
729 // plane.
730 break;
682 default: 731 default:
683 break; 732 break;
684 } 733 }
685 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY, 734 frame->metadata()->SetBoolean(VideoFrameMetadata::ALLOW_OVERLAY,
686 allow_overlay); 735 allow_overlay);
687 736
688 base::TimeTicks render_time; 737 base::TimeTicks render_time;
689 if (video_frame->metadata()->GetTimeTicks(VideoFrameMetadata::REFERENCE_TIME, 738 if (video_frame->metadata()->GetTimeTicks(VideoFrameMetadata::REFERENCE_TIME,
690 &render_time)) { 739 &render_time)) {
691 frame->metadata()->SetTimeTicks(VideoFrameMetadata::REFERENCE_TIME, 740 frame->metadata()->SetTimeTicks(VideoFrameMetadata::REFERENCE_TIME,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 } 875 }
827 876
828 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( 877 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame(
829 const scoped_refptr<VideoFrame>& video_frame, 878 const scoped_refptr<VideoFrame>& video_frame,
830 const FrameReadyCB& frame_ready_cb) { 879 const FrameReadyCB& frame_ready_cb) {
831 DCHECK(video_frame); 880 DCHECK(video_frame);
832 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); 881 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb);
833 } 882 }
834 883
835 } // namespace media 884 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/mock_gpu_video_accelerator_factories.cc ('k') | media/video/gpu_memory_buffer_video_frame_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698