vaapi_jpeg_encoder.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2017 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_ENCODER_H_
  5. #define MEDIA_GPU_VAAPI_VAAPI_JPEG_ENCODER_H_
  6. #include <va/va.h>
  7. #include <memory>
  8. #include "base/memory/scoped_refptr.h"
  9. #include "media/gpu/media_gpu_export.h"
  10. #include "ui/gfx/geometry/size.h"
  11. namespace media {
  12. class VaapiWrapper;
  13. // A collection of methods that utilize VA-API hardware video encode
  14. // acceleration on Intel systems. Provides functionality to allow plugging VAAPI
  15. // HW acceleration into the JpegEncodeAccelerator framework.
  16. //
  17. // Clients are expected to manage VA surfaces and VA buffers created via
  18. // VaapiWrapper, and pass them to this class.
  19. class MEDIA_GPU_EXPORT VaapiJpegEncoder {
  20. public:
  21. // |vaapi_wrapper| should be initialized in
  22. // VaapiWrapper::kEncodeConstantBitrate mode with VAProfileJPEGBaseline
  23. // profile.
  24. explicit VaapiJpegEncoder(scoped_refptr<VaapiWrapper> vaapi_wrapper);
  25. VaapiJpegEncoder(const VaapiJpegEncoder&) = delete;
  26. VaapiJpegEncoder& operator=(const VaapiJpegEncoder&) = delete;
  27. ~VaapiJpegEncoder();
  28. // Encode a JPEG picture. It will fill VA-API parameters and call
  29. // corresponding VA-API methods according to |input_size|.
  30. // |exif_buffer| contains the EXIF data that will be inserted to the JPEG
  31. // image.
  32. // |exif_buffer_size| is the size of |exif_buffer|.
  33. // |quality| is the JPEG image quality
  34. // |surface_id| is the VA surface that contains input image.
  35. // |output_buffer_id| is the ID of VA buffer that encoded image will be
  36. // stored. The size of it should be at least as large as
  37. // GetMaxCodedBufferSize().
  38. // |exif_offset| is the offset where Exif data should be filled into.
  39. // Return false on failure.
  40. bool Encode(const gfx::Size& input_size,
  41. const uint8_t* exif_buffer,
  42. size_t exif_buffer_size,
  43. int quality,
  44. VASurfaceID surface_id,
  45. VABufferID output_buffer_id,
  46. size_t* exif_offset);
  47. // Gets the maximum possible encoded result size.
  48. // |size| is the dimension of the YUV image to be encoded.
  49. static size_t GetMaxCodedBufferSize(const gfx::Size& size);
  50. private:
  51. scoped_refptr<VaapiWrapper> vaapi_wrapper_;
  52. // |q_matrix_cached_|, |huff_table_param_cached_| and |slice_param_cached_|
  53. // are created when Encode() is called the first time. After that, they will
  54. // directly be used for all the subsequent Encode() calls.
  55. std::unique_ptr<VAQMatrixBufferJPEG> q_matrix_cached_;
  56. std::unique_ptr<VAHuffmanTableBufferJPEGBaseline> huff_table_param_cached_;
  57. std::unique_ptr<VAEncSliceParameterBufferJPEG> slice_param_cached_;
  58. };
  59. } // namespace media
  60. #endif // MEDIA_GPU_VAAPI_VAAPI_JPEG_ENCODER_H_