vaapi_image_processor_backend.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2021 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_IMAGE_PROCESSOR_BACKEND_H_
  5. #define MEDIA_GPU_VAAPI_VAAPI_IMAGE_PROCESSOR_BACKEND_H_
  6. #include <memory>
  7. #include "base/containers/small_map.h"
  8. #include "media/gpu/chromeos/image_processor_backend.h"
  9. #include "media/gpu/media_gpu_export.h"
  10. #include "ui/gfx/gpu_memory_buffer.h"
  11. namespace media {
  12. class VaapiWrapper;
  13. class VASurface;
  14. // ImageProcessor that is hardware accelerated with VA-API. This ImageProcessor
  15. // supports only dma-buf and GpuMemoryBuffer VideoFrames for both input and
  16. // output.
  17. class VaapiImageProcessorBackend : public ImageProcessorBackend {
  18. public:
  19. VaapiImageProcessorBackend(const VaapiImageProcessorBackend&) = delete;
  20. VaapiImageProcessorBackend& operator=(const VaapiImageProcessorBackend&) =
  21. delete;
  22. // Factory method to create a VaapiImageProcessorBackend for processing frames
  23. // as specified by |input_config| and |output_config|. The provided |error_cb|
  24. // will be posted to the same thread that executes Create() if an error occurs
  25. // after initialization.
  26. // Returns nullptr if it fails to create a VaapiImageProcessorBackend.
  27. static std::unique_ptr<ImageProcessorBackend> Create(
  28. const PortConfig& input_config,
  29. const PortConfig& output_config,
  30. OutputMode output_mode,
  31. VideoRotation relative_rotation,
  32. ErrorCB error_cb,
  33. scoped_refptr<base::SequencedTaskRunner> backend_task_runner);
  34. // ImageProcessor implementation.
  35. void Process(scoped_refptr<VideoFrame> input_frame,
  36. scoped_refptr<VideoFrame> output_frame,
  37. FrameReadyCB cb) override;
  38. void Reset() override;
  39. private:
  40. VaapiImageProcessorBackend(
  41. const PortConfig& input_config,
  42. const PortConfig& output_config,
  43. OutputMode output_mode,
  44. VideoRotation relative_rotation,
  45. ErrorCB error_cb,
  46. scoped_refptr<base::SequencedTaskRunner> backend_task_runner);
  47. ~VaapiImageProcessorBackend() override;
  48. const VASurface* GetSurfaceForVideoFrame(scoped_refptr<VideoFrame> frame,
  49. bool use_protected);
  50. scoped_refptr<VaapiWrapper> vaapi_wrapper_;
  51. bool needs_context_ = false;
  52. // VASurfaces are created via importing dma-bufs into libva using
  53. // |vaapi_wrapper_|->CreateVASurfaceForPixmap(). The following map keeps those
  54. // VASurfaces for reuse according to the expectations of libva
  55. // vaDestroySurfaces(): "Surfaces can only be destroyed after all contexts
  56. // using these surfaces have been destroyed."
  57. base::small_map<std::map<gfx::GpuMemoryBufferId, scoped_refptr<VASurface>>>
  58. allocated_va_surfaces_;
  59. };
  60. } // namespace media
  61. #endif // MEDIA_GPU_VAAPI_VAAPI_IMAGE_PROCESSOR_BACKEND_H_