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

Side by Side Diff: media/video/gpu_memory_buffer_video_frame_pool.h

Issue 1874733002: media: split GpuMemoryBufferVideoFramePool into GpuMemoryBufferVideoFrameCopier/Pool Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add GpuMemoryBufferVideoFramePoolTest 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef MEDIA_VIDEO_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_ 5 #ifndef MEDIA_VIDEO_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_
6 #define MEDIA_VIDEO_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_ 6 #define MEDIA_VIDEO_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/task_runner.h"
11 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
12 11
13 namespace base { 12 namespace base {
14 class SingleThreadTaskRunner; 13 class SingleThreadTaskRunner;
15 } 14 }
16 15
17 namespace media { 16 namespace media {
18 class GpuVideoAcceleratorFactories; 17 class GpuVideoAcceleratorFactories;
19 18
20 // Interface to a pool of GpuMemoryBuffers/textures/images that can be used to 19 // A VideoFrameFuture allows to access GpuMemoryBuffer memory. When finishing
21 // transform software VideoFrames to VideoFrames backed by native textures. 20 // to use the instance, it will be released as a VideoFrame instance.
21 // EXAMPLE:
22 //
23 // std::unique_ptr<VideoFrameFuture> video_frame_future =
24 // video_frame_pool_->CreateFrame(PIXEL_FORMAT_I420, coded_size,
25 // visible_rect, natural_size, timestamp);
26 //
27 // // Decode into or encode from |video_frame_future->data(plane)|
28 //
29 // // Release as a VideoFrame backed by native textures.
30 // scoped_refptr<VideoFrame> video_frame = video_frame_future->Release();
31 //
32 // After released, all the VideoFrameFuture instance can do is destruction.
33 class MEDIA_EXPORT VideoFrameFuture {
34 public:
35 virtual ~VideoFrameFuture() {}
36 virtual scoped_refptr<VideoFrame> Release() = 0;
37 virtual uint8_t* data(size_t plane) const = 0;
38 virtual int stride(size_t plane) const = 0;
39 virtual const gfx::Size& coded_size() const = 0;
40
41 protected:
42 VideoFrameFuture() {}
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(VideoFrameFuture);
46 };
47
48 // Interface to a pool of GpuMemoryBuffers/textures/images which produces
49 // VideoFrames backed by native textures.
22 // The resources used by the VideoFrame created by the pool will be 50 // The resources used by the VideoFrame created by the pool will be
23 // automatically put back into the pool once the frame is destroyed. 51 // automatically put back into the pool once the frame is destroyed.
24 // The pool recycles resources to a void unnecessarily allocating and 52 // The pool recycles resources to a void unnecessarily allocating and
25 // destroying textures, images and GpuMemoryBuffer that could result 53 // destroying textures, images and GpuMemoryBuffer that could result
26 // in a round trip to the browser/GPU process. 54 // in a round trip to the browser/GPU process.
27 class MEDIA_EXPORT GpuMemoryBufferVideoFramePool { 55 class MEDIA_EXPORT GpuMemoryBufferVideoFramePool {
28 public: 56 public:
29 GpuMemoryBufferVideoFramePool();
30 GpuMemoryBufferVideoFramePool( 57 GpuMemoryBufferVideoFramePool(
31 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, 58 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
32 const scoped_refptr<base::TaskRunner>& worker_task_runner,
33 GpuVideoAcceleratorFactories* gpu_factories); 59 GpuVideoAcceleratorFactories* gpu_factories);
34 virtual ~GpuMemoryBufferVideoFramePool(); 60 virtual ~GpuMemoryBufferVideoFramePool();
35 61
36 // Callback used by MaybeCreateHardwareFrame to deliver a new VideoFrame 62 // Create VideoFrameFuture backed by native textures.
37 // after it has been copied to GpuMemoryBuffers. 63 std::unique_ptr<VideoFrameFuture> CreateFrame(VideoPixelFormat format,
38 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> FrameReadyCB; 64 const gfx::Size& coded_size,
65 const gfx::Rect& visible_rect,
66 const gfx::Size& natural_size,
67 base::TimeDelta timestamp);
39 68
40 // Calls |cb| on |media_worker_pool| with a new VideoFrame containing only 69 // The number of output planes to be copied in each iteration.
41 // mailboxes to native resources. |cb| will be destroyed on 70 static size_t PlanesPerCopy(VideoPixelFormat format, size_t plane);
42 // |media_worker_pool|. 71
43 // The content of the new object is copied from the software-allocated 72 protected:
44 // |video_frame|. 73 friend class GpuMemoryBufferVideoFramePoolTest;
45 // If it's not possible to create a new hardware VideoFrame, |video_frame| 74
46 // itself will passed to |cb|. 75 // Returns the number of frames in the pool for testing purposes.
47 virtual void MaybeCreateHardwareFrame( 76 size_t GetPoolSizeForTesting() const;
48 const scoped_refptr<VideoFrame>& video_frame,
49 const FrameReadyCB& frame_ready_cb);
50 77
51 private: 78 private:
52 class PoolImpl; 79 class PoolImpl;
53 scoped_refptr<PoolImpl> pool_impl_; 80 scoped_refptr<PoolImpl> pool_impl_;
54 81
55 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferVideoFramePool); 82 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferVideoFramePool);
56 }; 83 };
57 84
58 } // namespace media 85 } // namespace media
59 86
60 #endif // MEDIA_VIDEO_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_ 87 #endif // MEDIA_VIDEO_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_
OLDNEW
« no previous file with comments | « media/video/gpu_memory_buffer_video_frame_copier_unittest.cc ('k') | media/video/gpu_memory_buffer_video_frame_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698