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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « media/video/hybrid_video_frame_pool.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/video/hybrid_video_frame_pool.h"
6
7 #include "media/base/video_frame_pool.h"
8
9 namespace media {
10
11 namespace {
12
13 class VideoFrameFutureImpl : public VideoFrameFuture {
14 public:
15 explicit VideoFrameFutureImpl(const scoped_refptr<VideoFrame>& video_frame)
16 : VideoFrameFuture(), video_frame_(video_frame) {}
17
18 ~VideoFrameFutureImpl() override {}
19
20 scoped_refptr<VideoFrame> Release() override {
21 DCHECK(!released_);
22 released_ = true;
23 return video_frame_;
24 }
25
26 uint8_t* data(size_t plane) const override {
27 DCHECK(!released_);
28 return video_frame_->data(plane);
29 }
30
31 int stride(size_t plane) const override {
32 DCHECK(!released_);
33 return video_frame_->stride(plane);
34 }
35
36 const gfx::Size& coded_size() const override {
37 DCHECK(!released_);
38 return video_frame_->coded_size();
39 }
40
41 private:
42 scoped_refptr<VideoFrame> video_frame_;
43 bool released_ = false;
44 };
45
46 } // unnamed namespace
47
48 class HybridVideoFramePool::PoolImpl {
49 public:
50 PoolImpl(std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool)
51 : gpu_video_frame_pool_(std::move(gpu_video_frame_pool)),
52 video_frame_pool_(new VideoFramePool) {}
53 ~PoolImpl() {}
54
55 std::unique_ptr<VideoFrameFuture> CreateFrame(VideoPixelFormat format,
56 const gfx::Size& coded_size,
57 const gfx::Rect& visible_rect,
58 const gfx::Size& natural_size,
59 base::TimeDelta timestamp) {
60 if (IsGpuSupported(format)) {
61 return gpu_video_frame_pool_->CreateFrame(
62 format, coded_size, visible_rect, natural_size, timestamp);
63 }
64
65 scoped_refptr<VideoFrame> video_frame = video_frame_pool_->CreateFrame(
66 format, coded_size, visible_rect, natural_size, timestamp);
67 DCHECK(video_frame);
68 return std::unique_ptr<VideoFrameFuture>(
69 new VideoFrameFutureImpl(video_frame));
70 }
71
72 private:
73 bool IsGpuSupported(VideoPixelFormat format) {
74 if (!gpu_video_frame_pool_)
75 return false;
76
77 #if defined(OS_MACOSX)
78 // TODO(dshwang): Currently GpuMemoryBufferVideoFrameCopier converts
79 // VideoFrame backed by system memory to hardware VideoFrame backed by
80 // YUV_420_BIPLANAR/UYVY_422. GpuMemoryBufferVideoFrameCopier will convert
81 // it by GPU-GPU copy. crbug.com/356871
82 return false;
83 #endif
84
85 switch (format) {
86 // TODO(dshwang): support more YUV format. crbug.com/356871
87 case PIXEL_FORMAT_I420:
88 case PIXEL_FORMAT_YV12:
89 return true;
90 default:
91 return false;
92 }
93 }
94
95 // When GpuMemoryBuffer support the given format, it produces new
96 // VideoFrameFuture.
97 std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool_;
98
99 // Otherwise, it produces new VideoFrameFuture.
100 std::unique_ptr<VideoFramePool> video_frame_pool_;
101
102 DISALLOW_COPY_AND_ASSIGN(PoolImpl);
103 };
104
105 HybridVideoFramePool::HybridVideoFramePool(
106 std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool)
107 : pool_impl_(new PoolImpl(std::move(gpu_video_frame_pool))) {}
108
109 HybridVideoFramePool::~HybridVideoFramePool() {}
110
111 std::unique_ptr<VideoFrameFuture> HybridVideoFramePool::CreateFrame(
112 VideoPixelFormat format,
113 const gfx::Size& coded_size,
114 const gfx::Rect& visible_rect,
115 const gfx::Size& natural_size,
116 base::TimeDelta timestamp) {
117 return pool_impl_->CreateFrame(format, coded_size, visible_rect, natural_size,
118 timestamp);
119 }
120
121 } // namespace media
OLDNEW
« 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