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.
5 // Copyright (C) 2020 Intel Corporation
7 #ifndef OPENCV_GAPI_MEDIA_HPP
8 #define OPENCV_GAPI_MEDIA_HPP
10 #include <memory> // unique_ptr<>, shared_ptr<>
11 #include <array> // array<>
12 #include <functional> // function<>
13 #include <utility> // forward<>()
15 #include <opencv2/gapi/gframe.hpp>
19 class GAPI_EXPORTS MediaFrame {
21 enum class Access { R, W };
24 using AdapterPtr = std::unique_ptr<IAdapter>;
27 explicit MediaFrame(AdapterPtr &&);
28 template<class T, class... Args> static cv::MediaFrame Create(Args&&...);
30 View access(Access) const;
31 cv::GFrameDesc desc() const;
35 std::shared_ptr<Priv> m;
38 template<class T, class... Args>
39 inline cv::MediaFrame cv::MediaFrame::Create(Args&&... args) {
40 std::unique_ptr<T> ptr(new T(std::forward<Args>(args)...));
41 return cv::MediaFrame(std::move(ptr));
44 class GAPI_EXPORTS MediaFrame::View final {
46 static constexpr const size_t MAX_PLANES = 4;
47 using Ptrs = std::array<void*, MAX_PLANES>;
48 using Strides = std::array<std::size_t, MAX_PLANES>; // in bytes
49 using Callback = std::function<void()>;
51 View(Ptrs&& ptrs, Strides&& strs, Callback &&cb = [](){});
52 View(const View&) = delete;
53 View(View&&) = default;
63 class GAPI_EXPORTS MediaFrame::IAdapter {
65 virtual ~IAdapter() = 0;
66 virtual cv::GFrameDesc meta() const = 0;
67 virtual MediaFrame::View access(MediaFrame::Access) = 0;
72 #endif // OPENCV_GAPI_MEDIA_HPP