forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencv#18415 from dmatveev:dm/gframe_01_new_host_type
* G-API: Introduce cv::MediaFrame, a host type for cv::GFrame * G-API: RMat -- address review comments
- Loading branch information
Showing
6 changed files
with
258 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
// | ||
// Copyright (C) 2020 Intel Corporation | ||
|
||
#ifndef OPENCV_GAPI_MEDIA_HPP | ||
#define OPENCV_GAPI_MEDIA_HPP | ||
|
||
#include <memory> // unique_ptr<>, shared_ptr<> | ||
#include <array> // array<> | ||
#include <functional> // function<> | ||
#include <utility> // forward<>() | ||
|
||
#include <opencv2/gapi/gframe.hpp> | ||
|
||
namespace cv { | ||
|
||
class GAPI_EXPORTS MediaFrame { | ||
public: | ||
enum class Access { R, W }; | ||
class IAdapter; | ||
class View; | ||
using AdapterPtr = std::unique_ptr<IAdapter>; | ||
|
||
MediaFrame(); | ||
explicit MediaFrame(AdapterPtr &&); | ||
template<class T, class... Args> static cv::MediaFrame Create(Args&&...); | ||
|
||
View access(Access); | ||
cv::GFrameDesc desc() const; | ||
|
||
private: | ||
struct Priv; | ||
std::shared_ptr<Priv> m; | ||
}; | ||
|
||
template<class T, class... Args> | ||
inline cv::MediaFrame cv::MediaFrame::Create(Args&&... args) { | ||
std::unique_ptr<T> ptr(new T(std::forward<Args>(args)...)); | ||
return cv::MediaFrame(std::move(ptr)); | ||
} | ||
|
||
class GAPI_EXPORTS MediaFrame::View final { | ||
public: | ||
static constexpr const size_t MAX_PLANES = 4; | ||
using Ptrs = std::array<void*, MAX_PLANES>; | ||
using Strides = std::array<std::size_t, MAX_PLANES>; // in bytes | ||
using Callback = std::function<void()>; | ||
|
||
View(Ptrs&& ptrs, Strides&& strs, Callback &&cb = [](){}); | ||
View(const View&) = delete; | ||
View(View&&) = default; | ||
~View(); | ||
|
||
Ptrs ptr; | ||
Strides stride; | ||
|
||
private: | ||
Callback m_cb; | ||
}; | ||
|
||
class GAPI_EXPORTS MediaFrame::IAdapter { | ||
public: | ||
virtual ~IAdapter() = 0; | ||
virtual cv::GFrameDesc meta() const = 0; | ||
virtual MediaFrame::View access(MediaFrame::Access) = 0; | ||
}; | ||
|
||
} //namespace cv | ||
|
||
#endif // OPENCV_GAPI_MEDIA_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
// | ||
// Copyright (C) 2020 Intel Corporation | ||
|
||
#include "precomp.hpp" | ||
#include <opencv2/gapi/media.hpp> | ||
|
||
struct cv::MediaFrame::Priv { | ||
std::unique_ptr<IAdapter> adapter; | ||
}; | ||
|
||
cv::MediaFrame::MediaFrame() { | ||
} | ||
|
||
cv::MediaFrame::MediaFrame(AdapterPtr &&ptr) | ||
: m(new Priv{std::move(ptr)}) { | ||
} | ||
|
||
cv::GFrameDesc cv::MediaFrame::desc() const { | ||
return m->adapter->meta(); | ||
} | ||
|
||
cv::MediaFrame::View cv::MediaFrame::access(Access code) { | ||
return m->adapter->access(code); | ||
} | ||
|
||
cv::MediaFrame::View::View(Ptrs&& ptrs, Strides&& strs, Callback &&cb) | ||
: ptr (std::move(ptrs)) | ||
, stride(std::move(strs)) | ||
, m_cb (std::move(cb)) { | ||
} | ||
|
||
cv::MediaFrame::View::~View() { | ||
if (m_cb) { | ||
m_cb(); | ||
} | ||
} | ||
|
||
cv::MediaFrame::IAdapter::~IAdapter() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters