blob: ed4b3617e53cd39b0cf78d7f7dd7e6b9d16ddd47 [file] [log] [blame]
// Copyright 2015 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 "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/task_runner.h"
#include "media/base/video_frame.h"
namespace base {
class SingleThreadTaskRunner;
namespace media {
class GpuVideoAcceleratorFactories;
// Interface to a pool of GpuMemoryBuffers/textures/images that can be used to
// transform software VideoFrames to VideoFrames backed by native textures.
// The resources used by the VideoFrame created by the pool will be
// automatically put back into the pool once the frame is destroyed.
// The pool recycles resources to a void unnecessarily allocating and
// destroying textures, images and GpuMemoryBuffer that could result
// in a round trip to the browser/GPU process.
class MEDIA_EXPORT GpuMemoryBufferVideoFramePool {
const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
const scoped_refptr<base::TaskRunner>& worker_task_runner,
GpuVideoAcceleratorFactories* gpu_factories);
virtual ~GpuMemoryBufferVideoFramePool();
// Callback used by MaybeCreateHardwareFrame to deliver a new VideoFrame
// after it has been copied to GpuMemoryBuffers.
typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> FrameReadyCB;
// Calls |cb| on |media_worker_pool| with a new VideoFrame containing only
// mailboxes to native resources. |cb| will be destroyed on
// |media_worker_pool|.
// The content of the new object is copied from the software-allocated
// |video_frame|.
// If it's not possible to create a new hardware VideoFrame, |video_frame|
// itself will passed to |cb|.
virtual void MaybeCreateHardwareFrame(
const scoped_refptr<VideoFrame>& video_frame,
const FrameReadyCB& frame_ready_cb);
class PoolImpl;
scoped_refptr<PoolImpl> pool_impl_;
} // namespace media