Commit 2c830e80 authored by Gil Dekel's avatar Gil Dekel Committed by Commit Bot

media/gpu: Minor consolidation & refactoring

This CL consolidates some of the error types in VaapiImageDecodeStatus
in preperation for the implementation of VaapiWebPDecoder.
This CL also moves the protected members from VaapiImageDecoder to the
implementing subclasses. This is done to address a concern raised by
andrescj@ on a future CL.
See here:
https://crrev.com/c/1672404/5/media/gpu/vaapi/vaapi_image_decoder.cc#20

Bug: 877694
Test: jpeg_decode_accelerator_unittest
Change-Id: I2192ce81b3366a0e284a3f3c7bdac5c229bb0dff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1673576
Commit-Queue: Gil Dekel <gildekel@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672597}
parent 60abae9c
...@@ -11,9 +11,7 @@ ...@@ -11,9 +11,7 @@
namespace media { namespace media {
VaapiImageDecoder::VaapiImageDecoder(VAProfile va_profile) VaapiImageDecoder::VaapiImageDecoder(VAProfile va_profile)
: va_profile_(va_profile), : va_profile_(va_profile) {}
va_surface_id_(VA_INVALID_SURFACE),
va_rt_format_(kInvalidVaRtFormat) {}
VaapiImageDecoder::~VaapiImageDecoder() = default; VaapiImageDecoder::~VaapiImageDecoder() = default;
......
...@@ -14,26 +14,19 @@ ...@@ -14,26 +14,19 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "gpu/config/gpu_info.h" #include "gpu/config/gpu_info.h"
#include "ui/gfx/geometry/size.h"
namespace media { namespace media {
class VASurface; class VASurface;
class VaapiWrapper; class VaapiWrapper;
constexpr unsigned int kInvalidVaRtFormat = 0u;
enum class VaapiImageDecodeStatus : uint32_t { enum class VaapiImageDecodeStatus : uint32_t {
kSuccess, kSuccess,
kParseJpegFailed, kParseFailed,
kUnsupportedJpeg, kUnsupportedImage,
kUnsupportedSubsampling, kUnsupportedSubsampling,
kSurfaceCreationFailed, kSurfaceCreationFailed,
kSubmitPicParamsFailed, kSubmitVABuffersFailed,
kSubmitIQMatrixFailed,
kSubmitHuffmanFailed,
kSubmitSliceParamsFailed,
kSubmitSliceDataFailed,
kExecuteDecodeFailed, kExecuteDecodeFailed,
kUnsupportedSurfaceFormat, kUnsupportedSurfaceFormat,
kCannotGetImage, kCannotGetImage,
...@@ -77,14 +70,9 @@ class VaapiImageDecoder { ...@@ -77,14 +70,9 @@ class VaapiImageDecoder {
scoped_refptr<VaapiWrapper> vaapi_wrapper_; scoped_refptr<VaapiWrapper> vaapi_wrapper_;
private:
// The VA profile used for the current image decoder. // The VA profile used for the current image decoder.
const VAProfile va_profile_; const VAProfile va_profile_;
// The current VA surface for decoding.
VASurfaceID va_surface_id_;
// The coded size associated with |va_surface_id_|.
gfx::Size coded_size_;
// The VA RT format associated with |va_surface_id_|.
unsigned int va_rt_format_;
DISALLOW_COPY_AND_ASSIGN(VaapiImageDecoder); DISALLOW_COPY_AND_ASSIGN(VaapiImageDecoder);
}; };
......
...@@ -213,7 +213,9 @@ unsigned int VaSurfaceFormatForJpeg(const JpegFrameHeader& frame_header) { ...@@ -213,7 +213,9 @@ unsigned int VaSurfaceFormatForJpeg(const JpegFrameHeader& frame_header) {
} }
VaapiJpegDecoder::VaapiJpegDecoder() VaapiJpegDecoder::VaapiJpegDecoder()
: VaapiImageDecoder(VAProfileJPEGBaseline) {} : VaapiImageDecoder(VAProfileJPEGBaseline),
va_surface_id_(VA_INVALID_SURFACE),
va_rt_format_(kInvalidVaRtFormat) {}
VaapiJpegDecoder::~VaapiJpegDecoder() { VaapiJpegDecoder::~VaapiJpegDecoder() {
if (vaapi_wrapper_) { if (vaapi_wrapper_) {
...@@ -236,7 +238,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -236,7 +238,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
if (!ParseJpegPicture(encoded_image.data(), encoded_image.size(), if (!ParseJpegPicture(encoded_image.data(), encoded_image.size(),
&parse_result)) { &parse_result)) {
VLOGF(1) << "ParseJpegPicture failed"; VLOGF(1) << "ParseJpegPicture failed";
*status = VaapiImageDecodeStatus::kParseJpegFailed; *status = VaapiImageDecodeStatus::kParseFailed;
return nullptr; return nullptr;
} }
...@@ -252,7 +254,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -252,7 +254,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
// Make sure this JPEG can be decoded. // Make sure this JPEG can be decoded.
if (!IsVaapiSupportedJpeg(parse_result)) { if (!IsVaapiSupportedJpeg(parse_result)) {
VLOGF(1) << "The supplied JPEG is unsupported"; VLOGF(1) << "The supplied JPEG is unsupported";
*status = VaapiImageDecodeStatus::kUnsupportedJpeg; *status = VaapiImageDecodeStatus::kUnsupportedImage;
return nullptr; return nullptr;
} }
...@@ -283,7 +285,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -283,7 +285,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
FillPictureParameters(parse_result.frame_header, &pic_param); FillPictureParameters(parse_result.frame_header, &pic_param);
if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType, &pic_param)) { if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType, &pic_param)) {
VLOGF(1) << "Could not submit VAPictureParameterBufferType"; VLOGF(1) << "Could not submit VAPictureParameterBufferType";
*status = VaapiImageDecodeStatus::kSubmitPicParamsFailed; *status = VaapiImageDecodeStatus::kSubmitVABuffersFailed;
return nullptr; return nullptr;
} }
...@@ -292,7 +294,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -292,7 +294,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
FillIQMatrix(parse_result.q_table, &iq_matrix); FillIQMatrix(parse_result.q_table, &iq_matrix);
if (!vaapi_wrapper_->SubmitBuffer(VAIQMatrixBufferType, &iq_matrix)) { if (!vaapi_wrapper_->SubmitBuffer(VAIQMatrixBufferType, &iq_matrix)) {
VLOGF(1) << "Could not submit VAIQMatrixBufferType"; VLOGF(1) << "Could not submit VAIQMatrixBufferType";
*status = VaapiImageDecodeStatus::kSubmitIQMatrixFailed; *status = VaapiImageDecodeStatus::kSubmitVABuffersFailed;
return nullptr; return nullptr;
} }
...@@ -302,7 +304,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -302,7 +304,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
&huffman_table); &huffman_table);
if (!vaapi_wrapper_->SubmitBuffer(VAHuffmanTableBufferType, &huffman_table)) { if (!vaapi_wrapper_->SubmitBuffer(VAHuffmanTableBufferType, &huffman_table)) {
VLOGF(1) << "Could not submit VAHuffmanTableBufferType"; VLOGF(1) << "Could not submit VAHuffmanTableBufferType";
*status = VaapiImageDecodeStatus::kSubmitHuffmanFailed; *status = VaapiImageDecodeStatus::kSubmitVABuffersFailed;
return nullptr; return nullptr;
} }
...@@ -311,7 +313,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -311,7 +313,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
FillSliceParameters(parse_result, &slice_param); FillSliceParameters(parse_result, &slice_param);
if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType, &slice_param)) { if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType, &slice_param)) {
VLOGF(1) << "Could not submit VASliceParameterBufferType"; VLOGF(1) << "Could not submit VASliceParameterBufferType";
*status = VaapiImageDecodeStatus::kSubmitSliceParamsFailed; *status = VaapiImageDecodeStatus::kSubmitVABuffersFailed;
return nullptr; return nullptr;
} }
...@@ -320,7 +322,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode( ...@@ -320,7 +322,7 @@ scoped_refptr<VASurface> VaapiJpegDecoder::Decode(
parse_result.data_size, parse_result.data_size,
const_cast<char*>(parse_result.data))) { const_cast<char*>(parse_result.data))) {
VLOGF(1) << "Could not submit VASliceDataBufferType"; VLOGF(1) << "Could not submit VASliceDataBufferType";
*status = VaapiImageDecodeStatus::kSubmitSliceDataFailed; *status = VaapiImageDecodeStatus::kSubmitVABuffersFailed;
return nullptr; return nullptr;
} }
......
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
#include "base/macros.h" #include "base/macros.h"
#include "media/gpu/vaapi/vaapi_image_decoder.h" #include "media/gpu/vaapi/vaapi_image_decoder.h"
#include "ui/gfx/geometry/size.h"
namespace media { namespace media {
struct JpegFrameHeader; struct JpegFrameHeader;
class ScopedVAImage; class ScopedVAImage;
constexpr unsigned int kInvalidVaRtFormat = 0u;
// Returns the internal format required for a JPEG image given its parsed // Returns the internal format required for a JPEG image given its parsed
// |frame_header|. If the image's subsampling format is not one of 4:2:0, 4:2:2, // |frame_header|. If the image's subsampling format is not one of 4:2:0, 4:2:2,
// or 4:4:4, returns kInvalidVaRtFormat. // or 4:4:4, returns kInvalidVaRtFormat.
...@@ -42,6 +45,14 @@ class VaapiJpegDecoder : public VaapiImageDecoder { ...@@ -42,6 +45,14 @@ class VaapiJpegDecoder : public VaapiImageDecoder {
std::unique_ptr<ScopedVAImage> GetImage(uint32_t preferred_image_fourcc, std::unique_ptr<ScopedVAImage> GetImage(uint32_t preferred_image_fourcc,
VaapiImageDecodeStatus* status); VaapiImageDecodeStatus* status);
private:
// The current VA surface for decoding.
VASurfaceID va_surface_id_;
// The coded size associated with |va_surface_id_|.
gfx::Size coded_size_;
// The VA RT format associated with |va_surface_id_|.
unsigned int va_rt_format_;
DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecoder); DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecoder);
}; };
......
...@@ -590,7 +590,7 @@ TEST_F(VaapiJpegDecoderTest, DecodeFailsForBelowMinSize) { ...@@ -590,7 +590,7 @@ TEST_F(VaapiJpegDecoderTest, DecodeFailsForBelowMinSize) {
jpeg_data.size()), jpeg_data.size()),
&status)) &status))
<< "Decode unexpectedly succeeded for size = " << test_size.ToString(); << "Decode unexpectedly succeeded for size = " << test_size.ToString();
EXPECT_EQ(VaapiImageDecodeStatus::kUnsupportedJpeg, status); EXPECT_EQ(VaapiImageDecodeStatus::kUnsupportedImage, status);
} }
} }
...@@ -639,7 +639,7 @@ TEST_F(VaapiJpegDecoderTest, DecodeFailsForAboveMaxSize) { ...@@ -639,7 +639,7 @@ TEST_F(VaapiJpegDecoderTest, DecodeFailsForAboveMaxSize) {
jpeg_data.size()), jpeg_data.size()),
&status)) &status))
<< "Decode unexpectedly succeeded for size = " << test_size.ToString(); << "Decode unexpectedly succeeded for size = " << test_size.ToString();
EXPECT_EQ(VaapiImageDecodeStatus::kUnsupportedJpeg, status); EXPECT_EQ(VaapiImageDecodeStatus::kUnsupportedImage, status);
} }
} }
......
...@@ -58,7 +58,7 @@ VaapiJpegDecodeStatusToError(VaapiImageDecodeStatus status) { ...@@ -58,7 +58,7 @@ VaapiJpegDecodeStatusToError(VaapiImageDecodeStatus status) {
switch (status) { switch (status) {
case VaapiImageDecodeStatus::kSuccess: case VaapiImageDecodeStatus::kSuccess:
return chromeos_camera::MjpegDecodeAccelerator::Error::NO_ERRORS; return chromeos_camera::MjpegDecodeAccelerator::Error::NO_ERRORS;
case VaapiImageDecodeStatus::kParseJpegFailed: case VaapiImageDecodeStatus::kParseFailed:
return chromeos_camera::MjpegDecodeAccelerator::Error::PARSE_JPEG_FAILED; return chromeos_camera::MjpegDecodeAccelerator::Error::PARSE_JPEG_FAILED;
case VaapiImageDecodeStatus::kUnsupportedSubsampling: case VaapiImageDecodeStatus::kUnsupportedSubsampling:
return chromeos_camera::MjpegDecodeAccelerator::Error::UNSUPPORTED_JPEG; return chromeos_camera::MjpegDecodeAccelerator::Error::UNSUPPORTED_JPEG;
......
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