media.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2020 Intel Corporation
  6. #ifndef OPENCV_GAPI_MEDIA_HPP
  7. #define OPENCV_GAPI_MEDIA_HPP
  8. #include <memory> // unique_ptr<>, shared_ptr<>
  9. #include <array> // array<>
  10. #include <functional> // function<>
  11. #include <utility> // forward<>()
  12. #include <opencv2/gapi/gframe.hpp>
  13. namespace cv {
  14. class GAPI_EXPORTS MediaFrame {
  15. public:
  16. enum class Access { R, W };
  17. class IAdapter;
  18. class View;
  19. using AdapterPtr = std::unique_ptr<IAdapter>;
  20. MediaFrame();
  21. explicit MediaFrame(AdapterPtr &&);
  22. template<class T, class... Args> static cv::MediaFrame Create(Args&&...);
  23. View access(Access) const;
  24. cv::GFrameDesc desc() const;
  25. private:
  26. struct Priv;
  27. std::shared_ptr<Priv> m;
  28. };
  29. template<class T, class... Args>
  30. inline cv::MediaFrame cv::MediaFrame::Create(Args&&... args) {
  31. std::unique_ptr<T> ptr(new T(std::forward<Args>(args)...));
  32. return cv::MediaFrame(std::move(ptr));
  33. }
  34. class GAPI_EXPORTS MediaFrame::View final {
  35. public:
  36. static constexpr const size_t MAX_PLANES = 4;
  37. using Ptrs = std::array<void*, MAX_PLANES>;
  38. using Strides = std::array<std::size_t, MAX_PLANES>; // in bytes
  39. using Callback = std::function<void()>;
  40. View(Ptrs&& ptrs, Strides&& strs, Callback &&cb = [](){});
  41. View(const View&) = delete;
  42. View(View&&) = default;
  43. View& operator = (const View&) = delete;
  44. ~View();
  45. Ptrs ptr;
  46. Strides stride;
  47. private:
  48. Callback m_cb;
  49. };
  50. class GAPI_EXPORTS MediaFrame::IAdapter {
  51. public:
  52. virtual ~IAdapter() = 0;
  53. virtual cv::GFrameDesc meta() const = 0;
  54. virtual MediaFrame::View access(MediaFrame::Access) = 0;
  55. };
  56. } //namespace cv
  57. #endif // OPENCV_GAPI_MEDIA_HPP