Commit 0af86b11 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

media/gpu: Pass GpuMemoryBufferFactory to VideoDecoderPipeline.

We plan to support ImageProcessor (IP) inside VideoDecoderPipeline
(VDPipeline) in the future. When VDPipeline creates IP, there are 2
components (VD and IP) that need frame pool instances. In this case,
VDPipeline needs to create one more frame pool. Then passes the
original one to IP, and passes the new created frame pool to VD.

This CL passes one GpuMemoryBufferFactory to VDPipeline, which is
necessary to create one more PlatformVideoFramePool instance in the
future.

BUG=chromium:1004727
TEST=Run video_decode_accelerator_tests on Kevin and Eve
TEST=play crosvideo.appspot.com on Kevin and Eve

Change-Id: Ib370b693a99acd0df1d2a9fa57c38d77a6d7beb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868573Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708501}
parent 1ca2c6e4
......@@ -78,11 +78,13 @@ ChromeosVideoDecoderFactory::GetSupportedConfigs() {
std::unique_ptr<VideoDecoder> ChromeosVideoDecoderFactory::Create(
scoped_refptr<base::SequencedTaskRunner> client_task_runner,
std::unique_ptr<DmabufVideoFramePool> frame_pool,
std::unique_ptr<VideoFrameConverter> frame_converter) {
std::unique_ptr<VideoFrameConverter> frame_converter,
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory) {
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
return VideoDecoderPipeline::Create(
std::move(client_task_runner), std::move(frame_pool),
std::move(frame_converter), base::BindRepeating(&GetCreateVDFunctions));
std::move(frame_converter), gpu_memory_buffer_factory,
base::BindRepeating(&GetCreateVDFunctions));
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
return nullptr;
......
......@@ -15,6 +15,10 @@ namespace base {
class SequencedTaskRunner;
} // namespace base
namespace gpu {
class GpuMemoryBufferFactory;
} // namespace gpu
namespace media {
class DmabufVideoFramePool;
......@@ -27,10 +31,13 @@ class MEDIA_GPU_EXPORT ChromeosVideoDecoderFactory {
// Create VideoDecoder instance that allocates VideoFrame from |frame_pool|
// and converts the output VideoFrame |frame_converter|.
// Note the caller is responsible for keeping |gpu_memory_buffer_factory|
// alive during the returned VideoDecoder lifetime.
static std::unique_ptr<VideoDecoder> Create(
scoped_refptr<base::SequencedTaskRunner> client_task_runner,
std::unique_ptr<DmabufVideoFramePool> frame_pool,
std::unique_ptr<VideoFrameConverter> frame_converter);
std::unique_ptr<VideoFrameConverter> frame_converter,
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory);
};
} // namespace media
......
......@@ -3,12 +3,14 @@
// found in the LICENSE file.
#include "media/gpu/linux/video_decoder_pipeline.h"
#include <memory>
#include "base/bind.h"
#include "base/sequenced_task_runner.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "media/gpu/linux/dmabuf_video_frame_pool.h"
#include "media/gpu/linux/platform_video_frame_pool.h"
#include "media/gpu/macros.h"
namespace media {
......@@ -18,6 +20,7 @@ std::unique_ptr<VideoDecoder> VideoDecoderPipeline::Create(
scoped_refptr<base::SequencedTaskRunner> client_task_runner,
std::unique_ptr<DmabufVideoFramePool> frame_pool,
std::unique_ptr<VideoFrameConverter> frame_converter,
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory,
GetCreateVDFunctionsCB get_create_vd_functions_cb) {
if (!client_task_runner || !frame_pool || !frame_converter) {
VLOGF(1) << "One of arguments is nullptr.";
......@@ -31,32 +34,36 @@ std::unique_ptr<VideoDecoder> VideoDecoderPipeline::Create(
return base::WrapUnique<VideoDecoder>(new VideoDecoderPipeline(
std::move(client_task_runner), std::move(frame_pool),
std::move(frame_converter), std::move(get_create_vd_functions_cb)));
std::move(frame_converter), gpu_memory_buffer_factory,
std::move(get_create_vd_functions_cb)));
}
VideoDecoderPipeline::VideoDecoderPipeline(
scoped_refptr<base::SequencedTaskRunner> client_task_runner,
std::unique_ptr<DmabufVideoFramePool> frame_pool,
std::unique_ptr<VideoFrameConverter> frame_converter,
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory,
GetCreateVDFunctionsCB get_create_vd_functions_cb)
: client_task_runner_(std::move(client_task_runner)),
decoder_task_runner_(base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::WithBaseSyncPrimitives(),
base::TaskPriority::USER_VISIBLE},
base::SingleThreadTaskRunnerThreadMode::DEDICATED)),
frame_pool_(std::move(frame_pool)),
main_frame_pool_(std::move(frame_pool)),
gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
frame_converter_(std::move(frame_converter)),
get_create_vd_functions_cb_(std::move(get_create_vd_functions_cb)) {
DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
DETACH_FROM_SEQUENCE(decoder_sequence_checker_);
DCHECK(frame_pool_);
DCHECK(main_frame_pool_);
DCHECK(frame_converter_);
DCHECK(client_task_runner_);
DVLOGF(2);
client_weak_this_ = client_weak_this_factory_.GetWeakPtr();
decoder_weak_this_ = decoder_weak_this_factory_.GetWeakPtr();
frame_pool_->set_parent_task_runner(decoder_task_runner_);
main_frame_pool_->set_parent_task_runner(decoder_task_runner_);
frame_converter_->Initialize(
decoder_task_runner_,
base::BindRepeating(&VideoDecoderPipeline::OnFrameConverted,
......@@ -64,7 +71,7 @@ VideoDecoderPipeline::VideoDecoderPipeline(
}
VideoDecoderPipeline::~VideoDecoderPipeline() {
// We have to destroy |frame_pool_| on |decoder_task_runner_|, so the
// We have to destroy |main_frame_pool_| on |decoder_task_runner_|, so the
// destructor is also called on |decoder_task_runner_|.
DCHECK_CALLED_ON_VALID_SEQUENCE(decoder_sequence_checker_);
DVLOGF(3);
......@@ -87,10 +94,8 @@ void VideoDecoderPipeline::DestroyTask() {
decoder_weak_this_factory_.InvalidateWeakPtrs();
// |frame_pool_| and |frame_converter_| should be destroyed on
// |decoder_task_runner_|, which is set by
// frame_pool_->set_parent_task_runner() and frame_converter_->Initialize().
frame_pool_.reset();
// The frame pool and converter should be destroyed on |decoder_task_runner_|.
main_frame_pool_.reset();
frame_converter_.reset();
decoder_.reset();
......@@ -126,7 +131,7 @@ bool VideoDecoderPipeline::NeedsBitstreamConversion() const {
bool VideoDecoderPipeline::CanReadWithoutStalling() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
return frame_pool_ && !frame_pool_->IsExhausted();
return main_frame_pool_ && !main_frame_pool_->IsExhausted();
}
void VideoDecoderPipeline::Initialize(const VideoDecoderConfig& config,
......@@ -378,7 +383,7 @@ void VideoDecoderPipeline::CallFlushCbIfNeeded(DecodeStatus status) {
}
DmabufVideoFramePool* VideoDecoderPipeline::GetVideoFramePool() const {
return frame_pool_.get();
return main_frame_pool_.get();
}
} // namespace media
......@@ -20,6 +20,10 @@ namespace base {
class SequencedTaskRunner;
}
namespace gpu {
class GpuMemoryBufferFactory;
} // namespace gpu
namespace media {
class DmabufVideoFramePool;
......@@ -95,6 +99,7 @@ class MEDIA_GPU_EXPORT VideoDecoderPipeline : public VideoDecoder {
scoped_refptr<base::SequencedTaskRunner> client_task_runner,
std::unique_ptr<DmabufVideoFramePool> frame_pool,
std::unique_ptr<VideoFrameConverter> frame_converter,
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory,
GetCreateVDFunctionsCB get_create_vd_functions_cb);
~VideoDecoderPipeline() override;
......@@ -124,6 +129,7 @@ class MEDIA_GPU_EXPORT VideoDecoderPipeline : public VideoDecoder {
scoped_refptr<base::SequencedTaskRunner> client_task_runner,
std::unique_ptr<DmabufVideoFramePool> frame_pool,
std::unique_ptr<VideoFrameConverter> frame_converter,
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory,
GetCreateVDFunctionsCB get_create_vd_functions_cb);
void Destroy() override;
void DestroyTask();
......@@ -163,8 +169,16 @@ class MEDIA_GPU_EXPORT VideoDecoderPipeline : public VideoDecoder {
const scoped_refptr<base::SequencedTaskRunner> decoder_task_runner_;
SEQUENCE_CHECKER(decoder_sequence_checker_);
// The frame pool passed from the client. Destroyed on |decoder_task_runner_|.
std::unique_ptr<DmabufVideoFramePool> frame_pool_;
// The frame pool passed from the client. While internally other additional
// frame pools might be used for intermediate results, all frames passed to
// the client should be created using this pool.
// Used on |decoder_task_runner_|.
std::unique_ptr<DmabufVideoFramePool> main_frame_pool_;
// Used to generate additional frame pools for intermediate results if
// required. The instance is indirectly owned by GpuChildThread, therefore
// alive as long as the GPU process is.
gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
// The frame converter passed from the client. Destroyed on
// |client_task_runner_|.
std::unique_ptr<VideoFrameConverter> frame_converter_;
......
......@@ -185,7 +185,7 @@ void VideoDecoderClient::CreateDecoderTask(bool* success,
decoder_ = ChromeosVideoDecoderFactory::Create(
base::ThreadTaskRunnerHandle::Get(),
std::make_unique<PlatformVideoFramePool>(gpu_memory_buffer_factory_),
std::make_unique<VideoFrameConverter>());
std::make_unique<VideoFrameConverter>(), gpu_memory_buffer_factory_);
} else {
LOG(ERROR) << "VD-based video decoders only support import mode";
}
......
......@@ -253,7 +253,8 @@ std::unique_ptr<VideoDecoder> GpuMojoMediaClient::CreateVideoDecoder(
command_buffer_id->channel_token,
command_buffer_id->route_id));
video_decoder = ChromeosVideoDecoderFactory::Create(
task_runner, std::move(frame_pool), std::move(frame_converter));
task_runner, std::move(frame_pool), std::move(frame_converter),
gpu_memory_buffer_factory_);
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
} else {
video_decoder = VdaVideoDecoder::Create(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment