libyuv_image_processor_backend.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2018 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_CHROMEOS_LIBYUV_IMAGE_PROCESSOR_BACKEND_H_
  5. #define MEDIA_GPU_CHROMEOS_LIBYUV_IMAGE_PROCESSOR_BACKEND_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "media/gpu/chromeos/fourcc.h"
  9. #include "media/gpu/chromeos/image_processor_backend.h"
  10. #include "media/gpu/media_gpu_export.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace media {
  13. class VideoFrameMapper;
  14. // A software image processor which uses libyuv to perform format conversion.
  15. // It expects input VideoFrame is mapped into CPU space, and output VideoFrame
  16. // is allocated in user space.
  17. class MEDIA_GPU_EXPORT LibYUVImageProcessorBackend
  18. : public ImageProcessorBackend {
  19. public:
  20. // Factory method to create LibYUVImageProcessorBackend to convert video
  21. // format specified in input_config and output_config. Provided |error_cb|
  22. // will be posted to the same thread Create() is called if an error occurs
  23. // after initialization. Returns nullptr if it fails to create
  24. // LibYUVImageProcessorBackend.
  25. static std::unique_ptr<ImageProcessorBackend> Create(
  26. const PortConfig& input_config,
  27. const PortConfig& output_config,
  28. OutputMode output_mode,
  29. VideoRotation relative_rotation,
  30. ErrorCB error_cb,
  31. scoped_refptr<base::SequencedTaskRunner> backend_task_runner);
  32. LibYUVImageProcessorBackend(const LibYUVImageProcessorBackend&) = delete;
  33. LibYUVImageProcessorBackend& operator=(const LibYUVImageProcessorBackend&) =
  34. delete;
  35. // ImageProcessorBackend override
  36. void Process(scoped_refptr<VideoFrame> input_frame,
  37. scoped_refptr<VideoFrame> output_frame,
  38. FrameReadyCB cb) override;
  39. bool needs_linear_output_buffers() const override;
  40. static std::vector<Fourcc> GetSupportedOutputFormats(Fourcc input_format);
  41. bool supports_incoherent_buffers() const override;
  42. private:
  43. LibYUVImageProcessorBackend(
  44. std::unique_ptr<VideoFrameMapper> input_frame_mapper,
  45. std::unique_ptr<VideoFrameMapper> output_frame_mapper,
  46. scoped_refptr<VideoFrame> intermediate_frame,
  47. const PortConfig& input_config,
  48. const PortConfig& output_config,
  49. OutputMode output_mode,
  50. VideoRotation relative_rotation,
  51. ErrorCB error_cb,
  52. scoped_refptr<base::SequencedTaskRunner> backend_task_runner);
  53. ~LibYUVImageProcessorBackend() override;
  54. void NotifyError();
  55. // Execute Libyuv function for the conversion from |input| to |output|.
  56. int DoConversion(const VideoFrame* const input, VideoFrame* const output);
  57. const gfx::Rect input_visible_rect_;
  58. const gfx::Rect output_visible_rect_;
  59. const std::unique_ptr<VideoFrameMapper> input_frame_mapper_;
  60. const std::unique_ptr<VideoFrameMapper> output_frame_mapper_;
  61. // A VideoFrame for intermediate format conversion when there is no direct
  62. // conversion method in libyuv, e.g., RGBA -> I420 (pivot) -> NV12.
  63. scoped_refptr<VideoFrame> intermediate_frame_;
  64. };
  65. } // namespace media
  66. #endif // MEDIA_GPU_CHROMEOS_LIBYUV_IMAGE_PROCESSOR_BACKEND_H_