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

Unified Diff: media/video/hybrid_video_frame_pool.cc

Issue 1871383003: media: Implement zero-copy video playback for ffmpeg. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/video/hybrid_video_frame_pool.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/hybrid_video_frame_pool.cc
diff --git a/media/video/hybrid_video_frame_pool.cc b/media/video/hybrid_video_frame_pool.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6da3f64d24ec7042692157f2f46f8e331baf265e
--- /dev/null
+++ b/media/video/hybrid_video_frame_pool.cc
@@ -0,0 +1,121 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/video/hybrid_video_frame_pool.h"
+
+#include "media/base/video_frame_pool.h"
+
+namespace media {
+
+namespace {
+
+class VideoFrameFutureImpl : public VideoFrameFuture {
+ public:
+ explicit VideoFrameFutureImpl(const scoped_refptr<VideoFrame>& video_frame)
+ : VideoFrameFuture(), video_frame_(video_frame) {}
+
+ ~VideoFrameFutureImpl() override {}
+
+ scoped_refptr<VideoFrame> Release() override {
+ DCHECK(!released_);
+ released_ = true;
+ return video_frame_;
+ }
+
+ uint8_t* data(size_t plane) const override {
+ DCHECK(!released_);
+ return video_frame_->data(plane);
+ }
+
+ int stride(size_t plane) const override {
+ DCHECK(!released_);
+ return video_frame_->stride(plane);
+ }
+
+ const gfx::Size& coded_size() const override {
+ DCHECK(!released_);
+ return video_frame_->coded_size();
+ }
+
+ private:
+ scoped_refptr<VideoFrame> video_frame_;
+ bool released_ = false;
+};
+
+} // unnamed namespace
+
+class HybridVideoFramePool::PoolImpl {
+ public:
+ PoolImpl(std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool)
+ : gpu_video_frame_pool_(std::move(gpu_video_frame_pool)),
+ video_frame_pool_(new VideoFramePool) {}
+ ~PoolImpl() {}
+
+ std::unique_ptr<VideoFrameFuture> CreateFrame(VideoPixelFormat format,
+ const gfx::Size& coded_size,
+ const gfx::Rect& visible_rect,
+ const gfx::Size& natural_size,
+ base::TimeDelta timestamp) {
+ if (IsGpuSupported(format)) {
+ return gpu_video_frame_pool_->CreateFrame(
+ format, coded_size, visible_rect, natural_size, timestamp);
+ }
+
+ scoped_refptr<VideoFrame> video_frame = video_frame_pool_->CreateFrame(
+ format, coded_size, visible_rect, natural_size, timestamp);
+ DCHECK(video_frame);
+ return std::unique_ptr<VideoFrameFuture>(
+ new VideoFrameFutureImpl(video_frame));
+ }
+
+ private:
+ bool IsGpuSupported(VideoPixelFormat format) {
+ if (!gpu_video_frame_pool_)
+ return false;
+
+#if defined(OS_MACOSX)
+ // TODO(dshwang): Currently GpuMemoryBufferVideoFrameCopier converts
+ // VideoFrame backed by system memory to hardware VideoFrame backed by
+ // YUV_420_BIPLANAR/UYVY_422. GpuMemoryBufferVideoFrameCopier will convert
+ // it by GPU-GPU copy. crbug.com/356871
+ return false;
+#endif
+
+ switch (format) {
+ // TODO(dshwang): support more YUV format. crbug.com/356871
+ case PIXEL_FORMAT_I420:
+ case PIXEL_FORMAT_YV12:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ // When GpuMemoryBuffer support the given format, it produces new
+ // VideoFrameFuture.
+ std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool_;
+
+ // Otherwise, it produces new VideoFrameFuture.
+ std::unique_ptr<VideoFramePool> video_frame_pool_;
+
+ DISALLOW_COPY_AND_ASSIGN(PoolImpl);
+};
+
+HybridVideoFramePool::HybridVideoFramePool(
+ std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool)
+ : pool_impl_(new PoolImpl(std::move(gpu_video_frame_pool))) {}
+
+HybridVideoFramePool::~HybridVideoFramePool() {}
+
+std::unique_ptr<VideoFrameFuture> HybridVideoFramePool::CreateFrame(
+ VideoPixelFormat format,
+ const gfx::Size& coded_size,
+ const gfx::Rect& visible_rect,
+ const gfx::Size& natural_size,
+ base::TimeDelta timestamp) {
+ return pool_impl_->CreateFrame(format, coded_size, visible_rect, natural_size,
+ timestamp);
+}
+
+} // namespace media
« no previous file with comments | « media/video/hybrid_video_frame_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698