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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 if (!vpx_image) { | 456 if (!vpx_image) { |
457 *video_frame = nullptr; | 457 *video_frame = nullptr; |
458 return true; | 458 return true; |
459 } | 459 } |
460 | 460 |
461 if (vpx_image->user_priv != user_priv) { | 461 if (vpx_image->user_priv != user_priv) { |
462 DLOG(ERROR) << "Invalid output timestamp."; | 462 DLOG(ERROR) << "Invalid output timestamp."; |
463 return false; | 463 return false; |
464 } | 464 } |
465 | 465 |
466 CopyVpxImageToVideoFrame(vpx_image, video_frame); | 466 if (!CopyVpxImageToVideoFrame(vpx_image, video_frame)) |
467 return false; | |
468 | |
467 (*video_frame)->set_timestamp(base::TimeDelta::FromMicroseconds(timestamp)); | 469 (*video_frame)->set_timestamp(base::TimeDelta::FromMicroseconds(timestamp)); |
468 | 470 |
469 // Default to the color space from the config, but if the bistream specifies | 471 // Default to the color space from the config, but if the bistream specifies |
470 // one, prefer that instead. | 472 // one, prefer that instead. |
471 ColorSpace color_space = config_.color_space(); | 473 ColorSpace color_space = config_.color_space(); |
472 if (vpx_image->cs == VPX_CS_BT_709) | 474 if (vpx_image->cs == VPX_CS_BT_709) |
473 color_space = COLOR_SPACE_HD_REC709; | 475 color_space = COLOR_SPACE_HD_REC709; |
474 else if (vpx_image->cs == VPX_CS_BT_601) | 476 else if (vpx_image->cs == VPX_CS_BT_601) |
475 color_space = COLOR_SPACE_SD_REC601; | 477 color_space = COLOR_SPACE_SD_REC601; |
476 (*video_frame) | 478 (*video_frame) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 | 538 |
537 libyuv::CopyPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 539 libyuv::CopyPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
538 vpx_image_alpha->stride[VPX_PLANE_Y], | 540 vpx_image_alpha->stride[VPX_PLANE_Y], |
539 (*video_frame)->visible_data(VideoFrame::kAPlane), | 541 (*video_frame)->visible_data(VideoFrame::kAPlane), |
540 (*video_frame)->stride(VideoFrame::kAPlane), | 542 (*video_frame)->stride(VideoFrame::kAPlane), |
541 (*video_frame)->visible_rect().width(), | 543 (*video_frame)->visible_rect().width(), |
542 (*video_frame)->visible_rect().height()); | 544 (*video_frame)->visible_rect().height()); |
543 return true; | 545 return true; |
544 } | 546 } |
545 | 547 |
546 void VpxVideoDecoder::CopyVpxImageToVideoFrame( | 548 bool VpxVideoDecoder::CopyVpxImageToVideoFrame( |
547 const struct vpx_image* vpx_image, | 549 const struct vpx_image* vpx_image, |
548 scoped_refptr<VideoFrame>* video_frame) { | 550 scoped_refptr<VideoFrame>* video_frame) { |
549 DCHECK(vpx_image); | 551 DCHECK(vpx_image); |
550 DCHECK(vpx_image->fmt == VPX_IMG_FMT_I420 || | |
551 vpx_image->fmt == VPX_IMG_FMT_I444); | |
552 | 552 |
553 VideoPixelFormat codec_format = PIXEL_FORMAT_YV12; | 553 VideoPixelFormat codec_format; |
554 if (vpx_image->fmt == VPX_IMG_FMT_I444) | 554 switch (vpx_image->fmt) { |
555 codec_format = PIXEL_FORMAT_YV24; | 555 case VPX_IMG_FMT_I420: |
556 else if (vpx_codec_alpha_) | 556 codec_format = vpx_codec_alpha_ ? PIXEL_FORMAT_YV12A : PIXEL_FORMAT_YV12; |
mcasas
2015/12/15 17:04:54
VpxVideoDecoder should not be used for YV12
if th
vignesh
2015/12/15 17:10:23
The comment on [1] may be perceived as ambiguous.
| |
557 codec_format = PIXEL_FORMAT_YV12A; | 557 break; |
558 | |
559 case VPX_IMG_FMT_I444: | |
560 codec_format = PIXEL_FORMAT_YV24; | |
561 break; | |
562 | |
563 default: | |
564 DLOG(ERROR) << "Unsupported pixel format: " << vpx_image->fmt; | |
565 return false; | |
566 } | |
558 | 567 |
559 // The mixed |w|/|d_h| in |coded_size| is intentional. Setting the correct | 568 // The mixed |w|/|d_h| in |coded_size| is intentional. Setting the correct |
560 // coded width is necessary to allow coalesced memory access, which may avoid | 569 // coded width is necessary to allow coalesced memory access, which may avoid |
561 // frame copies. Setting the correct coded height however does not have any | 570 // frame copies. Setting the correct coded height however does not have any |
562 // benefit, and only risk copying too much data. | 571 // benefit, and only risk copying too much data. |
563 const gfx::Size coded_size(vpx_image->w, vpx_image->d_h); | 572 const gfx::Size coded_size(vpx_image->w, vpx_image->d_h); |
564 const gfx::Size visible_size(vpx_image->d_w, vpx_image->d_h); | 573 const gfx::Size visible_size(vpx_image->d_w, vpx_image->d_h); |
565 | 574 |
566 if (memory_pool_.get()) { | 575 if (memory_pool_.get()) { |
567 DCHECK_EQ(kCodecVP9, config_.codec()); | 576 DCHECK_EQ(kCodecVP9, config_.codec()); |
(...skipping 10 matching lines...) Expand all Loading... | |
578 kNoTimestamp()); | 587 kNoTimestamp()); |
579 video_frame->get()->AddDestructionObserver( | 588 video_frame->get()->AddDestructionObserver( |
580 memory_pool_->CreateFrameCallback(vpx_image->fb_priv)); | 589 memory_pool_->CreateFrameCallback(vpx_image->fb_priv)); |
581 | 590 |
582 UMA_HISTOGRAM_COUNTS("Media.Vpx.VideoDecoderBuffersInUseByDecoder", | 591 UMA_HISTOGRAM_COUNTS("Media.Vpx.VideoDecoderBuffersInUseByDecoder", |
583 memory_pool_->NumberOfFrameBuffersInUseByDecoder()); | 592 memory_pool_->NumberOfFrameBuffersInUseByDecoder()); |
584 UMA_HISTOGRAM_COUNTS( | 593 UMA_HISTOGRAM_COUNTS( |
585 "Media.Vpx.VideoDecoderBuffersInUseByDecoderAndVideoFrame", | 594 "Media.Vpx.VideoDecoderBuffersInUseByDecoderAndVideoFrame", |
586 memory_pool_->NumberOfFrameBuffersInUseByDecoderAndVideoFrame()); | 595 memory_pool_->NumberOfFrameBuffersInUseByDecoderAndVideoFrame()); |
587 | 596 |
588 return; | 597 return true; |
589 } | 598 } |
590 | 599 |
591 DCHECK(codec_format == PIXEL_FORMAT_YV12 || | 600 DCHECK(codec_format == PIXEL_FORMAT_YV12 || |
592 codec_format == PIXEL_FORMAT_YV12A); | 601 codec_format == PIXEL_FORMAT_YV12A); |
593 | 602 |
594 *video_frame = frame_pool_.CreateFrame( | 603 *video_frame = frame_pool_.CreateFrame( |
595 codec_format, visible_size, gfx::Rect(visible_size), | 604 codec_format, visible_size, gfx::Rect(visible_size), |
596 config_.natural_size(), kNoTimestamp()); | 605 config_.natural_size(), kNoTimestamp()); |
597 | 606 |
598 libyuv::I420Copy( | 607 libyuv::I420Copy( |
599 vpx_image->planes[VPX_PLANE_Y], vpx_image->stride[VPX_PLANE_Y], | 608 vpx_image->planes[VPX_PLANE_Y], vpx_image->stride[VPX_PLANE_Y], |
600 vpx_image->planes[VPX_PLANE_U], vpx_image->stride[VPX_PLANE_U], | 609 vpx_image->planes[VPX_PLANE_U], vpx_image->stride[VPX_PLANE_U], |
601 vpx_image->planes[VPX_PLANE_V], vpx_image->stride[VPX_PLANE_V], | 610 vpx_image->planes[VPX_PLANE_V], vpx_image->stride[VPX_PLANE_V], |
602 (*video_frame)->visible_data(VideoFrame::kYPlane), | 611 (*video_frame)->visible_data(VideoFrame::kYPlane), |
603 (*video_frame)->stride(VideoFrame::kYPlane), | 612 (*video_frame)->stride(VideoFrame::kYPlane), |
604 (*video_frame)->visible_data(VideoFrame::kUPlane), | 613 (*video_frame)->visible_data(VideoFrame::kUPlane), |
605 (*video_frame)->stride(VideoFrame::kUPlane), | 614 (*video_frame)->stride(VideoFrame::kUPlane), |
606 (*video_frame)->visible_data(VideoFrame::kVPlane), | 615 (*video_frame)->visible_data(VideoFrame::kVPlane), |
607 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), | 616 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), |
608 coded_size.height()); | 617 coded_size.height()); |
618 | |
619 return true; | |
609 } | 620 } |
610 | 621 |
611 } // namespace media | 622 } // namespace media |
OLD | NEW |