-
-
Notifications
You must be signed in to change notification settings - Fork 55.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
G-API: Introduce cv::MediaFrame, a host type for cv::GFrame #18415
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. relative paths should be used (opencv_world build with PCH is broken - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in a follow-up MR, thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait.. We've been never using relative paths for
Is this something new we should follow now? |
||
#include <opencv2/gapi/media.hpp> | ||
|
||
struct cv::MediaFrame::Priv { | ||
std::unique_ptr<IAdapter> adapter; | ||
}; | ||
|
||
cv::MediaFrame::MediaFrame() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simply write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same concern as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that's a .cpp, you can ask your compiler to generate this constructor here by
|
||
} | ||
|
||
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() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This = 0 looks misleading since ~IAdapter is implemented. So it simply can be = default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never misleading as it was quite common in pre-Cxx11 era.
My main concern about
= default
is that when amedia.hpp
is included in the user application, its destructor will be generated by the user's compiler (different from ours)? I don't trust much to this :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my point here is that
= 0
usually says that user must implement this method in a derived class, but actually it turns out that there is an implementation in a base class and user can utilize this base class implementation, that's what I meant by misleading. You can ask your compiler to generate a destructor by putting= default
in a destructor definition at .cpp file