vaapi_jpeg_decoder.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_VAAPI_VAAPI_JPEG_DECODER_H_
  5. #define MEDIA_GPU_VAAPI_VAAPI_JPEG_DECODER_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "media/gpu/vaapi/vaapi_image_decoder.h"
  9. namespace media {
  10. namespace fuzzing {
  11. class VaapiJpegDecoderWrapper;
  12. } // namespace fuzzing
  13. struct JpegFrameHeader;
  14. struct JpegParseResult;
  15. class ScopedVAImage;
  16. // Returns the internal format required for a JPEG image given its parsed
  17. // |frame_header|. If the image's subsampling format is not one of 4:2:0, 4:2:2,
  18. // or 4:4:4, returns kInvalidVaRtFormat.
  19. unsigned int VaSurfaceFormatForJpeg(const JpegFrameHeader& frame_header);
  20. class VaapiJpegDecoder : public VaapiImageDecoder {
  21. public:
  22. VaapiJpegDecoder();
  23. VaapiJpegDecoder(const VaapiJpegDecoder&) = delete;
  24. VaapiJpegDecoder& operator=(const VaapiJpegDecoder&) = delete;
  25. ~VaapiJpegDecoder() override;
  26. // VaapiImageDecoder implementation.
  27. gpu::ImageDecodeAcceleratorType GetType() const override;
  28. SkYUVColorSpace GetYUVColorSpace() const override;
  29. // Get the decoded data from the last Decode() call as a ScopedVAImage. The
  30. // VAImage's format will be either |preferred_image_fourcc| if the conversion
  31. // from the internal format is supported or a fallback FOURCC (see
  32. // VaapiWrapper::GetJpegDecodeSuitableImageFourCC() for details). Returns
  33. // nullptr on failure and sets *|status| to the reason for failure.
  34. std::unique_ptr<ScopedVAImage> GetImage(uint32_t preferred_image_fourcc,
  35. VaapiImageDecodeStatus* status);
  36. private:
  37. friend class fuzzing::VaapiJpegDecoderWrapper;
  38. // VaapiImageDecoder implementation.
  39. VaapiImageDecodeStatus AllocateVASurfaceAndSubmitVABuffers(
  40. base::span<const uint8_t> encoded_image) override;
  41. // AllocateVASurfaceAndSubmitVABuffers() is implemented by calling the
  42. // following methods. They are here so that a fuzzer can inject (almost)
  43. // arbitrary data into libva by skipping the parsing and image support checks
  44. // in AllocateVASurfaceAndSubmitVABuffers().
  45. bool MaybeCreateSurface(unsigned int picture_va_rt_format,
  46. const gfx::Size& new_coded_size,
  47. const gfx::Size& new_visible_size);
  48. bool SubmitBuffers(const JpegParseResult& parse_result);
  49. };
  50. } // namespace media
  51. #endif // MEDIA_GPU_VAAPI_VAAPI_JPEG_DECODER_H_