Commit 7b7810ca authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/vaapi/AVE: Treat EncodeJob with std::unique_ptr

Although EncodeJob is treated with scoped_refptr, its ownership is not shared at
all. Therefore, this CL lets EncodeJob treat with std::unique_ptr in order to
clarify its ownership and improve a performance a little bit.

Bug: 1016219
Test: vaapi_video_encode_accelerator_unittest on atlas
Test: https://appr.tc/?debug=loopback&vsc=vp8
Change-Id: Ib7f5c5fda806b11e590e9dd219c585900ae52b57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874992Reviewed-by: default avatarPawel Osciak <posciak@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710198}
parent cf918f24
......@@ -53,7 +53,7 @@ class AcceleratedVideoEncoder {
// provided by the accelerator itself, based on these parameters.
// Accelerators are also responsible for providing any resources (such as
// memory for output and reference pictures, etc.) as needed.
class EncodeJob : public base::RefCounted<EncodeJob> {
class EncodeJob {
public:
// Creates an EncodeJob to encode |input_frame|, which will be executed
// by calling |execute_cb|. If |keyframe| is true, requests this job
......@@ -61,6 +61,7 @@ class AcceleratedVideoEncoder {
EncodeJob(scoped_refptr<VideoFrame> input_frame,
bool keyframe,
base::OnceClosure execute_cb);
virtual ~EncodeJob();
// Schedules a callback to be run immediately before this job is executed.
// Can be called multiple times to schedule multiple callbacks, and all
......@@ -98,10 +99,6 @@ class AcceleratedVideoEncoder {
virtual VaapiEncodeJob* AsVaapiEncodeJob();
protected:
friend class base::RefCounted<EncodeJob>;
virtual ~EncodeJob();
private:
// Input VideoFrame to be encoded.
const scoped_refptr<VideoFrame> input_frame_;
......
......@@ -119,6 +119,7 @@ class VaapiEncodeJob : public AcceleratedVideoEncoder::EncodeJob {
scoped_refptr<VASurface> input_surface,
scoped_refptr<VASurface> reconstructed_surface,
VABufferID coded_buffer_id);
~VaapiEncodeJob() override = default;
VaapiEncodeJob* AsVaapiEncodeJob() override { return this; }
......@@ -131,8 +132,6 @@ class VaapiEncodeJob : public AcceleratedVideoEncoder::EncodeJob {
}
private:
~VaapiEncodeJob() override = default;
// Input surface for video frame data or scaled data.
const scoped_refptr<VASurface> input_surface_;
......@@ -518,14 +517,14 @@ void VaapiVideoEncodeAccelerator::TryToReturnBitstreamBuffer() {
auto buffer = std::move(available_bitstream_buffers_.front());
available_bitstream_buffers_.pop();
auto encode_job = submitted_encode_jobs_.front();
auto encode_job = std::move(submitted_encode_jobs_.front());
submitted_encode_jobs_.pop();
ReturnBitstreamBuffer(encode_job, std::move(buffer));
ReturnBitstreamBuffer(std::move(encode_job), std::move(buffer));
}
void VaapiVideoEncodeAccelerator::ReturnBitstreamBuffer(
scoped_refptr<VaapiEncodeJob> encode_job,
std::unique_ptr<VaapiEncodeJob> encode_job,
std::unique_ptr<BitstreamBufferRef> buffer) {
DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread());
......@@ -572,7 +571,7 @@ void VaapiVideoEncodeAccelerator::EncodeTask(scoped_refptr<VideoFrame> frame,
EncodePendingInputs();
}
scoped_refptr<VaapiEncodeJob> VaapiVideoEncodeAccelerator::CreateEncodeJob(
std::unique_ptr<VaapiEncodeJob> VaapiVideoEncodeAccelerator::CreateEncodeJob(
scoped_refptr<VideoFrame> frame,
bool force_keyframe) {
DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread());
......@@ -668,7 +667,7 @@ scoped_refptr<VaapiEncodeJob> VaapiVideoEncodeAccelerator::CreateEncodeJob(
kVaSurfaceFormat, base::BindOnce(va_surface_release_cb_));
available_va_surface_ids_.pop_back();
auto job = base::MakeRefCounted<VaapiEncodeJob>(
auto job = std::make_unique<VaapiEncodeJob>(
frame, force_keyframe,
base::BindOnce(&VaapiVideoEncodeAccelerator::ExecuteEncode,
base::Unretained(this), input_surface->id()),
......@@ -692,7 +691,7 @@ void VaapiVideoEncodeAccelerator::EncodePendingInputs() {
// If this is a flush (null) frame, don't create/submit a new encode job for
// it, but forward a null job to the submitted_encode_jobs_ queue.
scoped_refptr<VaapiEncodeJob> job;
std::unique_ptr<VaapiEncodeJob> job;
TRACE_EVENT0("media,gpu", "VAVEA::FromCreateEncodeJobToReturn");
if (input_frame) {
job = CreateEncodeJob(input_frame->frame, input_frame->force_keyframe);
......@@ -714,7 +713,7 @@ void VaapiVideoEncodeAccelerator::EncodePendingInputs() {
job->Execute();
}
submitted_encode_jobs_.push(job);
submitted_encode_jobs_.push(std::move(job));
TryToReturnBitstreamBuffer();
}
}
......
......@@ -94,8 +94,9 @@ class MEDIA_GPU_EXPORT VaapiVideoEncodeAccelerator
// Checks if sufficient resources for a new encode job with |frame| as input
// are available, and if so, claims them by associating them with
// a VaapiEncodeJob, and returns the newly-created job, nullptr otherwise.
scoped_refptr<VaapiEncodeJob> CreateEncodeJob(scoped_refptr<VideoFrame> frame,
bool force_keyframe);
std::unique_ptr<VaapiEncodeJob> CreateEncodeJob(
scoped_refptr<VideoFrame> frame,
bool force_keyframe);
// Continues encoding frames as long as input_queue_ is not empty, and we are
// able to create new EncodeJobs.
......@@ -123,7 +124,7 @@ class MEDIA_GPU_EXPORT VaapiVideoEncodeAccelerator
// Downloads encoded data produced as a result of running |encode_job| into
// |buffer|, and returns it to the client.
void ReturnBitstreamBuffer(scoped_refptr<VaapiEncodeJob> encode_job,
void ReturnBitstreamBuffer(std::unique_ptr<VaapiEncodeJob> encode_job,
std::unique_ptr<BitstreamBufferRef> buffer);
// Puts the encoder into en error state and notifies the client
......@@ -202,7 +203,7 @@ class MEDIA_GPU_EXPORT VaapiVideoEncodeAccelerator
// Jobs submitted to driver for encode, awaiting bitstream buffers to become
// available.
base::queue<scoped_refptr<VaapiEncodeJob>> submitted_encode_jobs_;
base::queue<std::unique_ptr<VaapiEncodeJob>> submitted_encode_jobs_;
// Encoder thread. All tasks are executed on it.
base::Thread encoder_thread_;
......
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