diff options
author | mcasas <mcasas@chromium.org> | 2015-11-10 17:09:02 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-11 01:10:05 +0000 |
commit | 3b51c67c2f6b31381a2874b71b11af1ae8c77093 (patch) | |
tree | 1a95a2bf4423dc8e813a7120f059c1f642424831 /media/cast/receiver/video_decoder.cc | |
parent | 37479296f57012c4b5d6ad7c186fcae1294e0073 (diff) | |
download | chromium_src-3b51c67c2f6b31381a2874b71b11af1ae8c77093.zip chromium_src-3b51c67c2f6b31381a2874b71b11af1ae8c77093.tar.gz chromium_src-3b51c67c2f6b31381a2874b71b11af1ae8c77093.tar.bz2 |
cast/receiver/video_decoder: use a pool of VideoFrames and libyuv::I420Copy()
As said in the bug, use a Pool and libyuv, which is
usually faster than I420Copy() (e.g. for bulk copies,
those involving SSE etc).
BUG=552614, 554196
TEST= all cast video test involving rx working like before,
and hopefully faster and with less memory trashing.
Review URL: https://codereview.chromium.org/1428413004
Cr-Commit-Position: refs/heads/master@{#358990}
Diffstat (limited to 'media/cast/receiver/video_decoder.cc')
-rw-r--r-- | media/cast/receiver/video_decoder.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/media/cast/receiver/video_decoder.cc b/media/cast/receiver/video_decoder.cc index 534eac0..dca038c 100644 --- a/media/cast/receiver/video_decoder.cc +++ b/media/cast/receiver/video_decoder.cc @@ -10,6 +10,7 @@ #include "base/location.h" #include "base/logging.h" #include "base/values.h" +#include "media/base/video_frame_pool.h" #include "media/base/video_util.h" #include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" @@ -18,6 +19,7 @@ #define VPX_CODEC_DISABLE_COMPAT 1 #include "third_party/libvpx_new/source/libvpx/vpx/vp8dx.h" #include "third_party/libvpx_new/source/libvpx/vpx/vpx_decoder.h" +#include "third_party/libyuv/include/libyuv/convert.h" #include "ui/gfx/geometry/size.h" namespace media { @@ -91,6 +93,9 @@ class VideoDecoder::ImplBase // Subclass' ctor is expected to set this to STATUS_INITIALIZED. OperationalStatus operational_status_; + // Pool of VideoFrames to decode incoming frames into. + media::VideoFramePool video_frame_pool_; + private: bool seen_first_frame_; uint32 last_frame_id_; @@ -140,8 +145,8 @@ class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase { vpx_image_t* const image = vpx_codec_get_frame(&context_, &iter); if (!image) return NULL; - if (image->fmt != VPX_IMG_FMT_I420 && image->fmt != VPX_IMG_FMT_YV12) { - NOTREACHED(); + if (image->fmt != VPX_IMG_FMT_I420) { + NOTREACHED() << "Only pixel format supported is I420, got " << image->fmt; return NULL; } DCHECK(vpx_codec_get_frame(&context_, &iter) == NULL) @@ -149,21 +154,22 @@ class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase { const gfx::Size frame_size(image->d_w, image->d_h); // Note: Timestamp for the VideoFrame will be set in VideoReceiver. - const scoped_refptr<VideoFrame> decoded_frame = VideoFrame::CreateFrame( - PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), frame_size, - base::TimeDelta()); - CopyYPlane(image->planes[VPX_PLANE_Y], - image->stride[VPX_PLANE_Y], - image->d_h, - decoded_frame.get()); - CopyUPlane(image->planes[VPX_PLANE_U], - image->stride[VPX_PLANE_U], - (image->d_h + 1) / 2, - decoded_frame.get()); - CopyVPlane(image->planes[VPX_PLANE_V], - image->stride[VPX_PLANE_V], - (image->d_h + 1) / 2, - decoded_frame.get()); + // |decoded_frame| will be returned to |video_frame_pool_| on destruction to + // be reused. + const scoped_refptr<VideoFrame> decoded_frame = + video_frame_pool_.CreateFrame(PIXEL_FORMAT_I420, frame_size, + gfx::Rect(frame_size), frame_size, + base::TimeDelta()); + libyuv::I420Copy(image->planes[VPX_PLANE_Y], image->stride[VPX_PLANE_Y], + image->planes[VPX_PLANE_U], image->stride[VPX_PLANE_U], + image->planes[VPX_PLANE_V], image->stride[VPX_PLANE_V], + decoded_frame->visible_data(media::VideoFrame::kYPlane), + decoded_frame->stride(media::VideoFrame::kYPlane), + decoded_frame->visible_data(media::VideoFrame::kUPlane), + decoded_frame->stride(media::VideoFrame::kUPlane), + decoded_frame->visible_data(media::VideoFrame::kVPlane), + decoded_frame->stride(media::VideoFrame::kVPlane), + frame_size.width(), frame_size.height()); return decoded_frame; } |