OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/vpx_video_decoder.h" | 5 #include "media/filters/vpx_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 CopyVpxImageTo(vpx_image, vpx_image_alpha, video_frame); | 443 CopyVpxImageTo(vpx_image, vpx_image_alpha, video_frame); |
444 (*video_frame)->set_timestamp(base::TimeDelta::FromMicroseconds(timestamp)); | 444 (*video_frame)->set_timestamp(base::TimeDelta::FromMicroseconds(timestamp)); |
445 return true; | 445 return true; |
446 } | 446 } |
447 | 447 |
448 void VpxVideoDecoder::CopyVpxImageTo(const vpx_image* vpx_image, | 448 void VpxVideoDecoder::CopyVpxImageTo(const vpx_image* vpx_image, |
449 const struct vpx_image* vpx_image_alpha, | 449 const struct vpx_image* vpx_image_alpha, |
450 scoped_refptr<VideoFrame>* video_frame) { | 450 scoped_refptr<VideoFrame>* video_frame) { |
451 CHECK(vpx_image); | 451 CHECK(vpx_image); |
452 CHECK(vpx_image->fmt == VPX_IMG_FMT_I420 || | 452 CHECK(vpx_image->fmt == VPX_IMG_FMT_I420 || |
453 vpx_image->fmt == VPX_IMG_FMT_YV12); | 453 vpx_image->fmt == VPX_IMG_FMT_YV12 || |
| 454 vpx_image->fmt == VPX_IMG_FMT_I444); |
| 455 |
| 456 VideoFrame::Format codec_format = VideoFrame::YV12; |
| 457 int uv_rows = (vpx_image->d_h + 1) / 2; |
| 458 |
| 459 if (vpx_image->fmt == VPX_IMG_FMT_I444) { |
| 460 CHECK(!vpx_codec_alpha_); |
| 461 codec_format = VideoFrame::YV24; |
| 462 uv_rows = vpx_image->d_h; |
| 463 } else if (vpx_codec_alpha_) { |
| 464 codec_format = VideoFrame::YV12A; |
| 465 } |
454 | 466 |
455 gfx::Size size(vpx_image->d_w, vpx_image->d_h); | 467 gfx::Size size(vpx_image->d_w, vpx_image->d_h); |
456 | 468 |
457 if (!vpx_codec_alpha_ && memory_pool_) { | 469 if (!vpx_codec_alpha_ && memory_pool_) { |
458 *video_frame = VideoFrame::WrapExternalYuvData( | 470 *video_frame = VideoFrame::WrapExternalYuvData( |
459 VideoFrame::YV12, | 471 codec_format, |
460 size, gfx::Rect(size), config_.natural_size(), | 472 size, gfx::Rect(size), config_.natural_size(), |
461 vpx_image->stride[VPX_PLANE_Y], | 473 vpx_image->stride[VPX_PLANE_Y], |
462 vpx_image->stride[VPX_PLANE_U], | 474 vpx_image->stride[VPX_PLANE_U], |
463 vpx_image->stride[VPX_PLANE_V], | 475 vpx_image->stride[VPX_PLANE_V], |
464 vpx_image->planes[VPX_PLANE_Y], | 476 vpx_image->planes[VPX_PLANE_Y], |
465 vpx_image->planes[VPX_PLANE_U], | 477 vpx_image->planes[VPX_PLANE_U], |
466 vpx_image->planes[VPX_PLANE_V], | 478 vpx_image->planes[VPX_PLANE_V], |
467 kNoTimestamp(), | 479 kNoTimestamp(), |
468 memory_pool_->CreateFrameCallback(vpx_image->fb_priv)); | 480 memory_pool_->CreateFrameCallback(vpx_image->fb_priv)); |
469 return; | 481 return; |
470 } | 482 } |
471 | 483 |
472 *video_frame = frame_pool_.CreateFrame( | 484 *video_frame = frame_pool_.CreateFrame( |
473 vpx_codec_alpha_ ? VideoFrame::YV12A : VideoFrame::YV12, | 485 codec_format, |
474 size, | 486 size, |
475 gfx::Rect(size), | 487 gfx::Rect(size), |
476 config_.natural_size(), | 488 config_.natural_size(), |
477 kNoTimestamp()); | 489 kNoTimestamp()); |
478 | 490 |
479 CopyYPlane(vpx_image->planes[VPX_PLANE_Y], | 491 CopyYPlane(vpx_image->planes[VPX_PLANE_Y], |
480 vpx_image->stride[VPX_PLANE_Y], | 492 vpx_image->stride[VPX_PLANE_Y], |
481 vpx_image->d_h, | 493 vpx_image->d_h, |
482 video_frame->get()); | 494 video_frame->get()); |
483 CopyUPlane(vpx_image->planes[VPX_PLANE_U], | 495 CopyUPlane(vpx_image->planes[VPX_PLANE_U], |
484 vpx_image->stride[VPX_PLANE_U], | 496 vpx_image->stride[VPX_PLANE_U], |
485 (vpx_image->d_h + 1) / 2, | 497 uv_rows, |
486 video_frame->get()); | 498 video_frame->get()); |
487 CopyVPlane(vpx_image->planes[VPX_PLANE_V], | 499 CopyVPlane(vpx_image->planes[VPX_PLANE_V], |
488 vpx_image->stride[VPX_PLANE_V], | 500 vpx_image->stride[VPX_PLANE_V], |
489 (vpx_image->d_h + 1) / 2, | 501 uv_rows, |
490 video_frame->get()); | 502 video_frame->get()); |
491 if (!vpx_codec_alpha_) | 503 if (!vpx_codec_alpha_) |
492 return; | 504 return; |
493 if (!vpx_image_alpha) { | 505 if (!vpx_image_alpha) { |
494 MakeOpaqueAPlane( | 506 MakeOpaqueAPlane( |
495 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 507 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
496 return; | 508 return; |
497 } | 509 } |
498 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 510 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
499 vpx_image->stride[VPX_PLANE_Y], | 511 vpx_image->stride[VPX_PLANE_Y], |
500 vpx_image->d_h, | 512 vpx_image->d_h, |
501 video_frame->get()); | 513 video_frame->get()); |
502 } | 514 } |
503 | 515 |
504 } // namespace media | 516 } // namespace media |
OLD | NEW |