Commit 2c1c1bd3 authored by Miguel Casas-Sanchez's avatar Miguel Casas-Sanchez Committed by Commit Bot

VaJDA: a bit of a cleanup

A couple of cleanups I stumbled upon while reading the code:
- struct DecodeRequest can be made internal.
- unique_ptr<> doesn't need to be made const& (strange pattern).
- A few consts and initializing structs with = {} (ISO memset),
 using implicit initialization [1].
- Removed unnecessary |weak_this_|.

All in all, less lines of code :-)

TBR=dcastagna@chromium.org

[1] http://en.cppreference.com/w/c/language/struct_initialization

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: If1a4e781abfa7ae96b85a6d621f5c96d4effb162
Reviewed-on: https://chromium-review.googlesource.com/1100001Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567839}
parent 074de24d
...@@ -80,15 +80,21 @@ static unsigned int VaSurfaceFormatForJpeg( ...@@ -80,15 +80,21 @@ static unsigned int VaSurfaceFormatForJpeg(
} // namespace } // namespace
VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest( // An input buffer and the corresponding output video frame awaiting
int32_t bitstream_buffer_id, // consumption, provided by the client.
std::unique_ptr<UnalignedSharedMemory> shm, struct VaapiJpegDecodeAccelerator::DecodeRequest {
const scoped_refptr<VideoFrame>& video_frame) DecodeRequest(int32_t bitstream_buffer_id,
: bitstream_buffer_id(bitstream_buffer_id), std::unique_ptr<UnalignedSharedMemory> shm,
shm(std::move(shm)), const scoped_refptr<VideoFrame>& video_frame)
video_frame(video_frame) {} : bitstream_buffer_id(bitstream_buffer_id),
shm(std::move(shm)),
VaapiJpegDecodeAccelerator::DecodeRequest::~DecodeRequest() {} video_frame(video_frame) {}
~DecodeRequest() = default;
int32_t bitstream_buffer_id;
std::unique_ptr<UnalignedSharedMemory> shm;
scoped_refptr<VideoFrame> video_frame;
};
void VaapiJpegDecodeAccelerator::NotifyError(int32_t bitstream_buffer_id, void VaapiJpegDecodeAccelerator::NotifyError(int32_t bitstream_buffer_id,
Error error) { Error error) {
...@@ -102,9 +108,10 @@ void VaapiJpegDecodeAccelerator::NotifyErrorFromDecoderThread( ...@@ -102,9 +108,10 @@ void VaapiJpegDecodeAccelerator::NotifyErrorFromDecoderThread(
int32_t bitstream_buffer_id, int32_t bitstream_buffer_id,
Error error) { Error error) {
DCHECK(decoder_task_runner_->BelongsToCurrentThread()); DCHECK(decoder_task_runner_->BelongsToCurrentThread());
task_runner_->PostTask(FROM_HERE, task_runner_->PostTask(
base::Bind(&VaapiJpegDecodeAccelerator::NotifyError, FROM_HERE, base::BindOnce(&VaapiJpegDecodeAccelerator::NotifyError,
weak_this_, bitstream_buffer_id, error)); weak_this_factory_.GetWeakPtr(),
bitstream_buffer_id, error));
} }
void VaapiJpegDecodeAccelerator::VideoFrameReady(int32_t bitstream_buffer_id) { void VaapiJpegDecodeAccelerator::VideoFrameReady(int32_t bitstream_buffer_id) {
...@@ -118,9 +125,7 @@ VaapiJpegDecodeAccelerator::VaapiJpegDecodeAccelerator( ...@@ -118,9 +125,7 @@ VaapiJpegDecodeAccelerator::VaapiJpegDecodeAccelerator(
io_task_runner_(io_task_runner), io_task_runner_(io_task_runner),
decoder_thread_("VaapiJpegDecoderThread"), decoder_thread_("VaapiJpegDecoderThread"),
va_surface_id_(VA_INVALID_SURFACE), va_surface_id_(VA_INVALID_SURFACE),
weak_this_factory_(this) { weak_this_factory_(this) {}
weak_this_ = weak_this_factory_.GetWeakPtr();
}
VaapiJpegDecodeAccelerator::~VaapiJpegDecodeAccelerator() { VaapiJpegDecodeAccelerator::~VaapiJpegDecodeAccelerator() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
...@@ -167,12 +172,9 @@ bool VaapiJpegDecodeAccelerator::OutputPicture( ...@@ -167,12 +172,9 @@ bool VaapiJpegDecodeAccelerator::OutputPicture(
<< " into video_frame associated with input buffer id " << " into video_frame associated with input buffer id "
<< input_buffer_id; << input_buffer_id;
VAImage image; VAImage image = {};
VAImageFormat format; VAImageFormat format = {};
const uint32_t kI420Fourcc = VA_FOURCC('I', '4', '2', '0'); format.fourcc = VA_FOURCC_I420;
memset(&image, 0, sizeof(image));
memset(&format, 0, sizeof(format));
format.fourcc = kI420Fourcc;
format.byte_order = VA_LSB_FIRST; format.byte_order = VA_LSB_FIRST;
format.bits_per_pixel = 12; // 12 for I420 format.bits_per_pixel = 12; // 12 for I420
...@@ -216,14 +218,15 @@ bool VaapiJpegDecodeAccelerator::OutputPicture( ...@@ -216,14 +218,15 @@ bool VaapiJpegDecodeAccelerator::OutputPicture(
vaapi_wrapper_->ReturnVaImage(&image); vaapi_wrapper_->ReturnVaImage(&image);
task_runner_->PostTask( task_runner_->PostTask(
FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::VideoFrameReady, FROM_HERE,
weak_this_, input_buffer_id)); base::BindOnce(&VaapiJpegDecodeAccelerator::VideoFrameReady,
weak_this_factory_.GetWeakPtr(), input_buffer_id));
return true; return true;
} }
void VaapiJpegDecodeAccelerator::DecodeTask( void VaapiJpegDecodeAccelerator::DecodeTask(
const std::unique_ptr<DecodeRequest>& request) { std::unique_ptr<DecodeRequest> request) {
DVLOGF(4); DVLOGF(4);
DCHECK(decoder_task_runner_->BelongsToCurrentThread()); DCHECK(decoder_task_runner_->BelongsToCurrentThread());
TRACE_EVENT0("jpeg", "DecodeTask"); TRACE_EVENT0("jpeg", "DecodeTask");
...@@ -314,8 +317,9 @@ void VaapiJpegDecodeAccelerator::Decode( ...@@ -314,8 +317,9 @@ void VaapiJpegDecodeAccelerator::Decode(
new DecodeRequest(bitstream_buffer.id(), std::move(shm), video_frame)); new DecodeRequest(bitstream_buffer.id(), std::move(shm), video_frame));
decoder_task_runner_->PostTask( decoder_task_runner_->PostTask(
FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask, FROM_HERE,
base::Unretained(this), base::Passed(&request))); base::BindOnce(&VaapiJpegDecodeAccelerator::DecodeTask,
base::Unretained(this), base::Passed(std::move(request))));
} }
bool VaapiJpegDecodeAccelerator::IsSupported() { bool VaapiJpegDecodeAccelerator::IsSupported() {
......
...@@ -46,18 +46,7 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator ...@@ -46,18 +46,7 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator
bool IsSupported() override; bool IsSupported() override;
private: private:
// An input buffer and the corresponding output video frame awaiting struct DecodeRequest;
// consumption, provided by the client.
struct DecodeRequest {
DecodeRequest(int32_t bitstream_buffer_id,
std::unique_ptr<UnalignedSharedMemory> shm,
const scoped_refptr<VideoFrame>& video_frame);
~DecodeRequest();
int32_t bitstream_buffer_id;
std::unique_ptr<UnalignedSharedMemory> shm;
scoped_refptr<VideoFrame> video_frame;
};
// Notifies the client that an error has occurred and decoding cannot // Notifies the client that an error has occurred and decoding cannot
// continue. // continue.
...@@ -66,7 +55,7 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator ...@@ -66,7 +55,7 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator
void VideoFrameReady(int32_t bitstream_buffer_id); void VideoFrameReady(int32_t bitstream_buffer_id);
// Processes one decode |request|. // Processes one decode |request|.
void DecodeTask(const std::unique_ptr<DecodeRequest>& request); void DecodeTask(std::unique_ptr<DecodeRequest> request);
// Puts contents of |va_surface| into given |video_frame|, releases the // Puts contents of |va_surface| into given |video_frame|, releases the
// surface and passes the |input_buffer_id| of the resulting picture to // surface and passes the |input_buffer_id| of the resulting picture to
...@@ -76,22 +65,14 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator ...@@ -76,22 +65,14 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator
const scoped_refptr<VideoFrame>& video_frame); const scoped_refptr<VideoFrame>& video_frame);
// ChildThread's task runner. // ChildThread's task runner.
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// GPU IO task runner. // GPU IO task runner.
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
// The client of this class. // The client of this class.
Client* client_; Client* client_;
// WeakPtr<> pointing to |this| for use in posting tasks from the decoder
// thread back to the ChildThread. Because the decoder thread is a member of
// this class, any task running on the decoder thread is guaranteed that this
// object is still alive. As a result, tasks posted from ChildThread to
// decoder thread should use base::Unretained(this), and tasks posted from the
// decoder thread to the ChildThread should use |weak_this_|.
base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_;
scoped_refptr<VaapiWrapper> vaapi_wrapper_; scoped_refptr<VaapiWrapper> vaapi_wrapper_;
// Comes after vaapi_wrapper_ to ensure its destructor is executed before // Comes after vaapi_wrapper_ to ensure its destructor is executed before
...@@ -110,7 +91,11 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator ...@@ -110,7 +91,11 @@ class MEDIA_GPU_EXPORT VaapiJpegDecodeAccelerator
// The VA RT format associated with |va_surface_id_|. // The VA RT format associated with |va_surface_id_|.
unsigned int va_rt_format_; unsigned int va_rt_format_;
// The WeakPtrFactory for |weak_this_|. // WeakPtr factory for use in posting tasks from |decoder_task_runner_| back
// to |task_runner_|. Since |decoder_thread_| is a fully owned member of
// this class, tasks posted to it may use base::Unretained(this), and tasks
// posted from the |decoder_task_runner_| to |task_runner_| should use a
// WeakPtr (obtained via weak_this_factory_.GetWeakPtr()).
base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_; base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_;
DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator); DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator);
......
...@@ -189,41 +189,43 @@ bool VaapiJpegDecoder::Decode(VaapiWrapper* vaapi_wrapper, ...@@ -189,41 +189,43 @@ bool VaapiJpegDecoder::Decode(VaapiWrapper* vaapi_wrapper,
VAPictureParameterBufferJPEGBaseline pic_param; VAPictureParameterBufferJPEGBaseline pic_param;
FillPictureParameters(parse_result.frame_header, &pic_param); FillPictureParameters(parse_result.frame_header, &pic_param);
if (!vaapi_wrapper->SubmitBuffer(VAPictureParameterBufferType, if (!vaapi_wrapper->SubmitBuffer(VAPictureParameterBufferType,
sizeof(pic_param), &pic_param)) sizeof(pic_param), &pic_param)) {
return false; return false;
}
// Set quantization table. // Set quantization table.
VAIQMatrixBufferJPEGBaseline iq_matrix; VAIQMatrixBufferJPEGBaseline iq_matrix;
FillIQMatrix(parse_result.q_table, &iq_matrix); FillIQMatrix(parse_result.q_table, &iq_matrix);
if (!vaapi_wrapper->SubmitBuffer(VAIQMatrixBufferType, sizeof(iq_matrix), if (!vaapi_wrapper->SubmitBuffer(VAIQMatrixBufferType, sizeof(iq_matrix),
&iq_matrix)) &iq_matrix)) {
return false; return false;
}
// Set huffman table. // Set huffman table.
VAHuffmanTableBufferJPEGBaseline huffman_table; VAHuffmanTableBufferJPEGBaseline huffman_table;
FillHuffmanTable(parse_result.dc_table, parse_result.ac_table, FillHuffmanTable(parse_result.dc_table, parse_result.ac_table,
&huffman_table); &huffman_table);
if (!vaapi_wrapper->SubmitBuffer(VAHuffmanTableBufferType, if (!vaapi_wrapper->SubmitBuffer(VAHuffmanTableBufferType,
sizeof(huffman_table), &huffman_table)) sizeof(huffman_table), &huffman_table)) {
return false; return false;
}
// Set slice parameters. // Set slice parameters.
VASliceParameterBufferJPEGBaseline slice_param; VASliceParameterBufferJPEGBaseline slice_param;
FillSliceParameters(parse_result, &slice_param); FillSliceParameters(parse_result, &slice_param);
if (!vaapi_wrapper->SubmitBuffer(VASliceParameterBufferType, if (!vaapi_wrapper->SubmitBuffer(VASliceParameterBufferType,
sizeof(slice_param), &slice_param)) sizeof(slice_param), &slice_param)) {
return false; return false;
}
// Set scan data. // Set scan data.
if (!vaapi_wrapper->SubmitBuffer(VASliceDataBufferType, if (!vaapi_wrapper->SubmitBuffer(VASliceDataBufferType,
parse_result.data_size, parse_result.data_size,
const_cast<char*>(parse_result.data))) const_cast<char*>(parse_result.data))) {
return false;
if (!vaapi_wrapper->ExecuteAndDestroyPendingBuffers(va_surface))
return false; return false;
}
return true; return vaapi_wrapper->ExecuteAndDestroyPendingBuffers(va_surface);
} }
} // namespace media } // namespace media
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