提交 962cdc2d 编写于 作者: A Alexander Alekhin

videoio: split capture/writer plugin APIs

- migrate GStreamer backed
- migrate FFmpeg backend (with switch on legacy API)
- cv_videoio_capture_retrieve_cb_t uses Mat type instead of number of channels
上级 71acf078
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "backend.hpp" #include "backend.hpp"
#include "plugin_api.hpp" #include "plugin_api.hpp"
#include "plugin_capture_api.hpp"
#include "plugin_writer_api.hpp"
#include "opencv2/core/utils/filesystem.hpp" #include "opencv2/core/utils/filesystem.hpp"
#include "opencv2/core/utils/configuration.private.hpp" #include "opencv2/core/utils/configuration.private.hpp"
...@@ -25,6 +27,8 @@ using namespace std; ...@@ -25,6 +27,8 @@ using namespace std;
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
#include "backend_plugin_legacy.impl.hpp"
namespace cv { namespace impl { namespace cv { namespace impl {
#if defined(_WIN32) #if defined(_WIN32)
...@@ -164,7 +168,7 @@ public: ...@@ -164,7 +168,7 @@ public:
} }
void * res = getSymbol_(handle, symbolName); void * res = getSymbol_(handle, symbolName);
if (!res) if (!res)
CV_LOG_ERROR(NULL, "No symbol '" << symbolName << "' in " << toPrintablePath(fname)); CV_LOG_DEBUG(NULL, "No symbol '" << symbolName << "' in " << toPrintablePath(fname));
return res; return res;
} }
const std::string getName() const { return toPrintablePath(fname); } const std::string getName() const { return toPrintablePath(fname); }
...@@ -194,76 +198,168 @@ private: ...@@ -194,76 +198,168 @@ private:
class PluginBackend: public IBackend class PluginBackend: public IBackend
{ {
public: protected:
Ptr<DynamicLib> lib_;
const OpenCV_VideoIO_Plugin_API_preview* plugin_api_;
PluginBackend(const Ptr<DynamicLib>& lib) : void initCaptureAPI()
lib_(lib), plugin_api_(NULL)
{ {
const char* init_name = "opencv_videoio_plugin_init_v0"; const char* init_name = "opencv_videoio_capture_plugin_init_v1";
FN_opencv_videoio_plugin_init_t fn_init = reinterpret_cast<FN_opencv_videoio_plugin_init_t>(lib_->getSymbol(init_name)); FN_opencv_videoio_capture_plugin_init_t fn_init = reinterpret_cast<FN_opencv_videoio_capture_plugin_init_t>(lib_->getSymbol(init_name));
if (fn_init) if (fn_init)
{ {
for (int supported_api_version = API_VERSION; supported_api_version >= 0; supported_api_version--) CV_LOG_INFO(NULL, "Found entry: '" << init_name << "'");
for (int supported_api_version = CAPTURE_API_VERSION; supported_api_version >= 0; supported_api_version--)
{ {
plugin_api_ = fn_init(ABI_VERSION, supported_api_version, NULL); capture_api_ = fn_init(CAPTURE_ABI_VERSION, supported_api_version, NULL);
if (plugin_api_) if (capture_api_)
break; break;
} }
if (!plugin_api_) if (!capture_api_)
{ {
CV_LOG_INFO(NULL, "Video I/O: plugin is incompatible (can't be initialized): " << lib->getName()); CV_LOG_INFO(NULL, "Video I/O: plugin is incompatible (can't be initialized): " << lib_->getName());
return; return;
} }
if (plugin_api_->api_header.opencv_version_major != CV_VERSION_MAJOR) if (!checkCompatibility(
capture_api_->api_header, CAPTURE_ABI_VERSION, CAPTURE_API_VERSION,
capture_api_->v0.id != CAP_FFMPEG))
{ {
CV_LOG_ERROR(NULL, "Video I/O: wrong OpenCV major version used by plugin '" << plugin_api_->api_header.api_description << "': " << capture_api_ = NULL;
cv::format("%d.%d, OpenCV version is '" CV_VERSION "'", plugin_api_->api_header.opencv_version_major, plugin_api_->api_header.opencv_version_minor))
plugin_api_ = NULL;
return; return;
} }
#ifdef HAVE_FFMPEG_WRAPPER CV_LOG_INFO(NULL, "Video I/O: plugin is ready to use '" << capture_api_->api_header.api_description << "'");
if (plugin_api_->v0.captureAPI == CAP_FFMPEG) }
else
{
CV_LOG_INFO(NULL, "Video I/O: missing plugin init function: '" << init_name << "', file: " << lib_->getName());
}
}
void initWriterAPI()
{
const char* init_name = "opencv_videoio_writer_plugin_init_v1";
FN_opencv_videoio_writer_plugin_init_t fn_init = reinterpret_cast<FN_opencv_videoio_writer_plugin_init_t>(lib_->getSymbol(init_name));
if (fn_init)
{
CV_LOG_INFO(NULL, "Found entry: '" << init_name << "'");
for (int supported_api_version = WRITER_API_VERSION; supported_api_version >= 0; supported_api_version--)
{ {
// no checks for OpenCV minor version writer_api_ = fn_init(WRITER_ABI_VERSION, supported_api_version, NULL);
if (writer_api_)
break;
} }
else if (!writer_api_)
#endif
if (plugin_api_->api_header.opencv_version_minor != CV_VERSION_MINOR)
{ {
CV_LOG_ERROR(NULL, "Video I/O: wrong OpenCV minor version used by plugin '" << plugin_api_->api_header.api_description << "': " << CV_LOG_INFO(NULL, "Video I/O: plugin is incompatible (can't be initialized): " << lib_->getName());
cv::format("%d.%d, OpenCV version is '" CV_VERSION "'", plugin_api_->api_header.opencv_version_major, plugin_api_->api_header.opencv_version_minor))
plugin_api_ = NULL;
return; return;
} }
CV_LOG_INFO(NULL, "Video I/O: initialized '" << plugin_api_->api_header.api_description << "': built with " if (!checkCompatibility(
<< cv::format("OpenCV %d.%d (ABI/API = %d/%d)", writer_api_->api_header, WRITER_ABI_VERSION, WRITER_API_VERSION,
plugin_api_->api_header.opencv_version_major, plugin_api_->api_header.opencv_version_minor, writer_api_->v0.id != CAP_FFMPEG))
plugin_api_->api_header.min_api_version, plugin_api_->api_header.api_version)
<< ", current OpenCV version is '" CV_VERSION "' (ABI/API = " << ABI_VERSION << "/" << API_VERSION << ")"
);
if (plugin_api_->api_header.min_api_version != ABI_VERSION) // future: range can be here
{ {
// actually this should never happen due to checks in plugin's init() function writer_api_ = NULL;
CV_LOG_ERROR(NULL, "Video I/O: plugin is not supported due to incompatible ABI = " << plugin_api_->api_header.min_api_version);
plugin_api_ = NULL;
return; return;
} }
if (plugin_api_->api_header.api_version != API_VERSION) CV_LOG_INFO(NULL, "Video I/O: plugin is ready to use '" << writer_api_->api_header.api_description << "'");
}
else
{
CV_LOG_INFO(NULL, "Video I/O: missing plugin init function: '" << init_name << "', file: " << lib_->getName());
}
}
void initPluginLegacyAPI()
{
const char* init_name = "opencv_videoio_plugin_init_v0";
FN_opencv_videoio_plugin_init_t fn_init = reinterpret_cast<FN_opencv_videoio_plugin_init_t>(lib_->getSymbol(init_name));
if (fn_init)
{
CV_LOG_INFO(NULL, "Found entry: '" << init_name << "'");
for (int supported_api_version = API_VERSION; supported_api_version >= 0; supported_api_version--)
{ {
CV_LOG_INFO(NULL, "Video I/O: NOTE: plugin is supported, but there is API version mismath: " plugin_api_ = fn_init(ABI_VERSION, supported_api_version, NULL);
<< cv::format("plugin API level (%d) != OpenCV API level (%d)", plugin_api_->api_header.api_version, API_VERSION)); if (plugin_api_)
if (plugin_api_->api_header.api_version < API_VERSION) break;
{ }
CV_LOG_INFO(NULL, "Video I/O: NOTE: some functionality may be unavailable due to lack of support by plugin implementation"); if (!plugin_api_)
} {
CV_LOG_INFO(NULL, "Video I/O: plugin is incompatible (can't be initialized): " << lib_->getName());
return;
}
if (!checkCompatibility(
plugin_api_->api_header, ABI_VERSION, API_VERSION,
plugin_api_->v0.captureAPI != CAP_FFMPEG))
{
plugin_api_ = NULL;
return;
} }
CV_LOG_INFO(NULL, "Video I/O: plugin is ready to use '" << plugin_api_->api_header.api_description << "'"); CV_LOG_INFO(NULL, "Video I/O: plugin is ready to use '" << plugin_api_->api_header.api_description << "'");
} }
else else
{ {
CV_LOG_INFO(NULL, "Video I/O: plugin is incompatible, missing init function: '" << init_name << "', file: " << lib->getName()); CV_LOG_INFO(NULL, "Video I/O: plugin is incompatible, missing init function: '" << init_name << "', file: " << lib_->getName());
}
}
bool checkCompatibility(const OpenCV_API_Header& api_header, unsigned int abi_version, unsigned int api_version, bool checkMinorOpenCVVersion)
{
if (api_header.opencv_version_major != CV_VERSION_MAJOR)
{
CV_LOG_ERROR(NULL, "Video I/O: wrong OpenCV major version used by plugin '" << api_header.api_description << "': " <<
cv::format("%d.%d, OpenCV version is '" CV_VERSION "'", api_header.opencv_version_major, api_header.opencv_version_minor))
return false;
}
if (!checkMinorOpenCVVersion)
{
// no checks for OpenCV minor version
}
else if (api_header.opencv_version_minor != CV_VERSION_MINOR)
{
CV_LOG_ERROR(NULL, "Video I/O: wrong OpenCV minor version used by plugin '" << api_header.api_description << "': " <<
cv::format("%d.%d, OpenCV version is '" CV_VERSION "'", api_header.opencv_version_major, api_header.opencv_version_minor))
return false;
}
CV_LOG_INFO(NULL, "Video I/O: initialized '" << api_header.api_description << "': built with "
<< cv::format("OpenCV %d.%d (ABI/API = %d/%d)",
api_header.opencv_version_major, api_header.opencv_version_minor,
api_header.min_api_version, api_header.api_version)
<< ", current OpenCV version is '" CV_VERSION "' (ABI/API = " << abi_version << "/" << api_version << ")"
);
if (api_header.min_api_version != abi_version) // future: range can be here
{
// actually this should never happen due to checks in plugin's init() function
CV_LOG_ERROR(NULL, "Video I/O: plugin is not supported due to incompatible ABI = " << api_header.min_api_version);
return false;
}
if (api_header.api_version != api_version)
{
CV_LOG_INFO(NULL, "Video I/O: NOTE: plugin is supported, but there is API version mismath: "
<< cv::format("plugin API level (%d) != OpenCV API level (%d)", api_header.api_version, api_version));
if (api_header.api_version < api_version)
{
CV_LOG_INFO(NULL, "Video I/O: NOTE: some functionality may be unavailable due to lack of support by plugin implementation");
}
}
return true;
}
public:
Ptr<DynamicLib> lib_;
const OpenCV_VideoIO_Capture_Plugin_API* capture_api_;
const OpenCV_VideoIO_Writer_Plugin_API* writer_api_;
const OpenCV_VideoIO_Plugin_API_preview* plugin_api_; //!< deprecated
PluginBackend(const Ptr<DynamicLib>& lib)
: lib_(lib)
, capture_api_(NULL), writer_api_(NULL)
, plugin_api_(NULL)
{
initCaptureAPI();
initWriterAPI();
if (capture_api_ == NULL && writer_api_ == NULL)
{
initPluginLegacyAPI();
} }
} }
...@@ -407,20 +503,46 @@ void PluginBackendFactory::loadPlugin() ...@@ -407,20 +503,46 @@ void PluginBackendFactory::loadPlugin()
try try
{ {
Ptr<PluginBackend> pluginBackend = makePtr<PluginBackend>(lib); Ptr<PluginBackend> pluginBackend = makePtr<PluginBackend>(lib);
if (pluginBackend && pluginBackend->plugin_api_) if (!pluginBackend)
return;
if (pluginBackend->capture_api_)
{
if (pluginBackend->capture_api_->v0.id != id_)
{
CV_LOG_ERROR(NULL, "Video I/O: plugin '" << pluginBackend->capture_api_->api_header.api_description <<
"': unexpected backend ID: " <<
pluginBackend->capture_api_->v0.id << " vs " << (int)id_ << " (expected)");
return;
}
}
if (pluginBackend->writer_api_)
{
if (pluginBackend->writer_api_->v0.id != id_)
{
CV_LOG_ERROR(NULL, "Video I/O: plugin '" << pluginBackend->writer_api_->api_header.api_description <<
"': unexpected backend ID: " <<
pluginBackend->writer_api_->v0.id << " vs " << (int)id_ << " (expected)");
return;
}
}
if (pluginBackend->plugin_api_)
{ {
if (pluginBackend->plugin_api_->v0.captureAPI != id_) if (pluginBackend->plugin_api_->v0.captureAPI != id_)
{ {
CV_LOG_ERROR(NULL, "Video I/O: plugin '" << pluginBackend->plugin_api_->api_header.api_description << CV_LOG_ERROR(NULL, "Video I/O: plugin '" << pluginBackend->plugin_api_->api_header.api_description <<
"': unexpected backend ID: " << "': unexpected backend ID: " <<
pluginBackend->plugin_api_->v0.captureAPI << " vs " << (int)id_ << " (expected)"); pluginBackend->plugin_api_->v0.captureAPI << " vs " << (int)id_ << " (expected)");
}
else
{
backend = pluginBackend;
return; return;
} }
} }
if (pluginBackend->capture_api_ == NULL && pluginBackend->writer_api_ == NULL
&& pluginBackend->plugin_api_ == NULL)
{
CV_LOG_ERROR(NULL, "Video I/O: no compatible plugin API for backend ID: " << (int)id_);
return;
}
backend = pluginBackend;
return;
} }
catch (...) catch (...)
{ {
...@@ -434,16 +556,17 @@ void PluginBackendFactory::loadPlugin() ...@@ -434,16 +556,17 @@ void PluginBackendFactory::loadPlugin()
class PluginCapture : public cv::IVideoCapture class PluginCapture : public cv::IVideoCapture
{ {
const OpenCV_VideoIO_Plugin_API_preview* plugin_api_; const OpenCV_VideoIO_Capture_Plugin_API* plugin_api_;
CvPluginCapture capture_; CvPluginCapture capture_;
public: public:
static static
Ptr<PluginCapture> create(const OpenCV_VideoIO_Plugin_API_preview* plugin_api, Ptr<PluginCapture> create(const OpenCV_VideoIO_Capture_Plugin_API* plugin_api,
const std::string &filename, int camera) const std::string &filename, int camera)
{ {
CV_Assert(plugin_api); CV_Assert(plugin_api);
CvPluginCapture capture = NULL; CvPluginCapture capture = NULL;
if (plugin_api->v0.Capture_open) if (plugin_api->v0.Capture_open)
{ {
CV_Assert(plugin_api->v0.Capture_release); CV_Assert(plugin_api->v0.Capture_release);
...@@ -456,7 +579,7 @@ public: ...@@ -456,7 +579,7 @@ public:
return Ptr<PluginCapture>(); return Ptr<PluginCapture>();
} }
PluginCapture(const OpenCV_VideoIO_Plugin_API_preview* plugin_api, CvPluginCapture capture) PluginCapture(const OpenCV_VideoIO_Capture_Plugin_API* plugin_api, CvPluginCapture capture)
: plugin_api_(plugin_api), capture_(capture) : plugin_api_(plugin_api), capture_(capture)
{ {
CV_Assert(plugin_api_); CV_Assert(capture_); CV_Assert(plugin_api_); CV_Assert(capture_);
...@@ -491,13 +614,13 @@ public: ...@@ -491,13 +614,13 @@ public:
return true; return true;
return false; return false;
} }
static CvResult CV_API_CALL retrieve_callback(int stream_idx, const unsigned char* data, int step, int width, int height, int cn, void* userdata) static CvResult CV_API_CALL retrieve_callback(int stream_idx, const unsigned char* data, int step, int width, int height, int type, void* userdata)
{ {
CV_UNUSED(stream_idx); CV_UNUSED(stream_idx);
cv::_OutputArray* dst = static_cast<cv::_OutputArray*>(userdata); cv::_OutputArray* dst = static_cast<cv::_OutputArray*>(userdata);
if (!dst) if (!dst)
return CV_ERROR_FAIL; return CV_ERROR_FAIL;
cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, cn), (void*)data, step).copyTo(*dst); cv::Mat(cv::Size(width, height), type, (void*)data, step).copyTo(*dst);
return CV_ERROR_OK; return CV_ERROR_OK;
} }
bool retrieveFrame(int idx, cv::OutputArray img) CV_OVERRIDE bool retrieveFrame(int idx, cv::OutputArray img) CV_OVERRIDE
...@@ -514,7 +637,7 @@ public: ...@@ -514,7 +637,7 @@ public:
} }
int getCaptureDomain() CV_OVERRIDE int getCaptureDomain() CV_OVERRIDE
{ {
return plugin_api_->v0.captureAPI; return plugin_api_->v0.id;
} }
}; };
...@@ -523,12 +646,12 @@ public: ...@@ -523,12 +646,12 @@ public:
class PluginWriter : public cv::IVideoWriter class PluginWriter : public cv::IVideoWriter
{ {
const OpenCV_VideoIO_Plugin_API_preview* plugin_api_; const OpenCV_VideoIO_Writer_Plugin_API* plugin_api_;
CvPluginWriter writer_; CvPluginWriter writer_;
public: public:
static static
Ptr<PluginWriter> create(const OpenCV_VideoIO_Plugin_API_preview* plugin_api, Ptr<PluginWriter> create(const OpenCV_VideoIO_Writer_Plugin_API* plugin_api,
const std::string& filename, int fourcc, double fps, const cv::Size& sz, const std::string& filename, int fourcc, double fps, const cv::Size& sz,
const VideoWriterParameters& params) const VideoWriterParameters& params)
{ {
...@@ -568,7 +691,7 @@ public: ...@@ -568,7 +691,7 @@ public:
return Ptr<PluginWriter>(); return Ptr<PluginWriter>();
} }
PluginWriter(const OpenCV_VideoIO_Plugin_API_preview* plugin_api, CvPluginWriter writer) PluginWriter(const OpenCV_VideoIO_Writer_Plugin_API* plugin_api, CvPluginWriter writer)
: plugin_api_(plugin_api), writer_(writer) : plugin_api_(plugin_api), writer_(writer)
{ {
CV_Assert(plugin_api_); CV_Assert(writer_); CV_Assert(plugin_api_); CV_Assert(writer_);
...@@ -613,7 +736,7 @@ public: ...@@ -613,7 +736,7 @@ public:
} }
int getCaptureDomain() const CV_OVERRIDE int getCaptureDomain() const CV_OVERRIDE
{ {
return plugin_api_->v0.captureAPI; return plugin_api_->v0.id;
} }
}; };
...@@ -622,8 +745,10 @@ Ptr<IVideoCapture> PluginBackend::createCapture(int camera) const ...@@ -622,8 +745,10 @@ Ptr<IVideoCapture> PluginBackend::createCapture(int camera) const
{ {
try try
{ {
if (capture_api_)
return PluginCapture::create(capture_api_, std::string(), camera); //.staticCast<IVideoCapture>();
if (plugin_api_) if (plugin_api_)
return PluginCapture::create(plugin_api_, std::string(), camera); //.staticCast<IVideoCapture>(); return legacy::PluginCapture::create(plugin_api_, std::string(), camera); //.staticCast<IVideoCapture>();
} }
catch (...) catch (...)
{ {
...@@ -636,8 +761,10 @@ Ptr<IVideoCapture> PluginBackend::createCapture(const std::string &filename) con ...@@ -636,8 +761,10 @@ Ptr<IVideoCapture> PluginBackend::createCapture(const std::string &filename) con
{ {
try try
{ {
if (capture_api_)
return PluginCapture::create(capture_api_, filename, 0); //.staticCast<IVideoCapture>();
if (plugin_api_) if (plugin_api_)
return PluginCapture::create(plugin_api_, filename, 0); //.staticCast<IVideoCapture>(); return legacy::PluginCapture::create(plugin_api_, filename, 0); //.staticCast<IVideoCapture>();
} }
catch (...) catch (...)
{ {
...@@ -651,8 +778,10 @@ Ptr<IVideoWriter> PluginBackend::createWriter(const std::string& filename, int f ...@@ -651,8 +778,10 @@ Ptr<IVideoWriter> PluginBackend::createWriter(const std::string& filename, int f
{ {
try try
{ {
if (writer_api_)
return PluginWriter::create(writer_api_, filename, fourcc, fps, sz, params); //.staticCast<IVideoWriter>();
if (plugin_api_) if (plugin_api_)
return PluginWriter::create(plugin_api_, filename, fourcc, fps, sz, params); //.staticCast<IVideoWriter>(); return legacy::PluginWriter::create(plugin_api_, filename, fourcc, fps, sz, params); //.staticCast<IVideoWriter>();
} }
catch (...) catch (...)
{ {
......
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory // 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. // of this distribution and at http://opencv.org/license.html.
// NOT A STANDALONE HEADER //
// Not a standalone header.
//
namespace cv { namespace impl { namespace legacy {
//================================================================================================== //==================================================================================================
...@@ -190,3 +194,6 @@ public: ...@@ -190,3 +194,6 @@ public:
return plugin_api_->v0.captureAPI; return plugin_api_->v0.captureAPI;
} }
}; };
}}} // namespace
...@@ -217,9 +217,20 @@ cv::Ptr<cv::IVideoWriter> cvCreateVideoWriter_FFMPEG_proxy(const std::string& fi ...@@ -217,9 +217,20 @@ cv::Ptr<cv::IVideoWriter> cvCreateVideoWriter_FFMPEG_proxy(const std::string& fi
#if defined(BUILD_PLUGIN) #if defined(BUILD_PLUGIN)
#define NEW_PLUGIN
#ifndef NEW_PLUGIN
#define ABI_VERSION 0 #define ABI_VERSION 0
#define API_VERSION 0 #define API_VERSION 0
#include "plugin_api.hpp" #include "plugin_api.hpp"
#else
#define CAPTURE_ABI_VERSION 1
#define CAPTURE_API_VERSION 0
#include "plugin_capture_api.hpp"
#define WRITER_ABI_VERSION 1
#define WRITER_API_VERSION 0
#include "plugin_writer_api.hpp"
#endif
namespace cv { namespace cv {
...@@ -312,6 +323,7 @@ CvResult CV_API_CALL cv_capture_grab(CvPluginCapture handle) ...@@ -312,6 +323,7 @@ CvResult CV_API_CALL cv_capture_grab(CvPluginCapture handle)
} }
} }
#ifndef NEW_PLUGIN
static static
CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, cv_videoio_retrieve_cb_t callback, void* userdata) CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, cv_videoio_retrieve_cb_t callback, void* userdata)
{ {
...@@ -331,6 +343,27 @@ CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, ...@@ -331,6 +343,27 @@ CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx,
return CV_ERROR_FAIL; return CV_ERROR_FAIL;
} }
} }
#else
static
CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, cv_videoio_capture_retrieve_cb_t callback, void* userdata)
{
if (!handle)
return CV_ERROR_FAIL;
try
{
CvCapture_FFMPEG_proxy* instance = (CvCapture_FFMPEG_proxy*)handle;
Mat img;
// TODO: avoid unnecessary copying
if (instance->retrieveFrame(stream_idx, img))
return callback(stream_idx, img.data, img.step, img.cols, img.rows, img.type(), userdata);
return CV_ERROR_FAIL;
}
catch(...)
{
return CV_ERROR_FAIL;
}
}
#endif
static static
CvResult CV_API_CALL cv_writer_open(const char* filename, int fourcc, double fps, int width, int height, int isColor, CvResult CV_API_CALL cv_writer_open(const char* filename, int fourcc, double fps, int width, int height, int isColor,
...@@ -395,6 +428,10 @@ CvResult CV_API_CALL cv_writer_write(CvPluginWriter handle, const unsigned char ...@@ -395,6 +428,10 @@ CvResult CV_API_CALL cv_writer_write(CvPluginWriter handle, const unsigned char
} }
} }
} // namespace
#ifndef NEW_PLUGIN
static const OpenCV_VideoIO_Plugin_API_preview plugin_api = static const OpenCV_VideoIO_Plugin_API_preview plugin_api =
{ {
{ {
...@@ -418,13 +455,64 @@ static const OpenCV_VideoIO_Plugin_API_preview plugin_api = ...@@ -418,13 +455,64 @@ static const OpenCV_VideoIO_Plugin_API_preview plugin_api =
} }
}; };
} // namespace
const OpenCV_VideoIO_Plugin_API_preview* opencv_videoio_plugin_init_v0(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT const OpenCV_VideoIO_Plugin_API_preview* opencv_videoio_plugin_init_v0(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT
{ {
if (requested_abi_version == ABI_VERSION && requested_api_version <= API_VERSION) if (requested_abi_version == ABI_VERSION && requested_api_version <= API_VERSION)
return &cv::plugin_api; return &plugin_api;
return NULL; return NULL;
} }
#else // NEW_PLUGIN
static const OpenCV_VideoIO_Capture_Plugin_API capture_plugin_api =
{
{
sizeof(OpenCV_VideoIO_Capture_Plugin_API), CAPTURE_ABI_VERSION, CAPTURE_API_VERSION,
CV_VERSION_MAJOR, CV_VERSION_MINOR, CV_VERSION_REVISION, CV_VERSION_STATUS,
"FFmpeg OpenCV Video I/O Capture plugin"
},
{
/* 1*/CAP_FFMPEG,
/* 2*/cv_capture_open,
/* 3*/cv_capture_release,
/* 4*/cv_capture_get_prop,
/* 5*/cv_capture_set_prop,
/* 6*/cv_capture_grab,
/* 7*/cv_capture_retrieve,
}
};
const OpenCV_VideoIO_Capture_Plugin_API* opencv_videoio_capture_plugin_init_v1(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT
{
if (requested_abi_version == CAPTURE_ABI_VERSION && requested_api_version <= CAPTURE_API_VERSION)
return &capture_plugin_api;
return NULL;
}
static const OpenCV_VideoIO_Writer_Plugin_API writer_plugin_api =
{
{
sizeof(OpenCV_VideoIO_Writer_Plugin_API), WRITER_ABI_VERSION, WRITER_API_VERSION,
CV_VERSION_MAJOR, CV_VERSION_MINOR, CV_VERSION_REVISION, CV_VERSION_STATUS,
"FFmpeg OpenCV Video I/O Writer plugin"
},
{
/* 1*/CAP_FFMPEG,
/* 2*/cv_writer_open,
/* 3*/cv_writer_release,
/* 4*/cv_writer_get_prop,
/* 5*/cv_writer_set_prop,
/* 6*/cv_writer_write
}
};
const OpenCV_VideoIO_Writer_Plugin_API* opencv_videoio_writer_plugin_init_v1(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT
{
if (requested_abi_version == WRITER_ABI_VERSION && requested_api_version <= WRITER_API_VERSION)
return &writer_plugin_api;
return NULL;
}
#endif // NEW_PLUGIN
#endif // BUILD_PLUGIN #endif // BUILD_PLUGIN
...@@ -1846,9 +1846,12 @@ void handleMessage(GstElement * pipeline) ...@@ -1846,9 +1846,12 @@ void handleMessage(GstElement * pipeline)
#if defined(BUILD_PLUGIN) #if defined(BUILD_PLUGIN)
#define ABI_VERSION 0 #define CAPTURE_ABI_VERSION 1
#define API_VERSION 1 #define CAPTURE_API_VERSION 0
#include "plugin_api.hpp" #include "plugin_capture_api.hpp"
#define WRITER_ABI_VERSION 1
#define WRITER_API_VERSION 1
#include "plugin_writer_api.hpp"
namespace cv { namespace cv {
...@@ -1946,7 +1949,7 @@ CvResult CV_API_CALL cv_capture_grab(CvPluginCapture handle) ...@@ -1946,7 +1949,7 @@ CvResult CV_API_CALL cv_capture_grab(CvPluginCapture handle)
} }
static static
CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, cv_videoio_retrieve_cb_t callback, void* userdata) CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, cv_videoio_capture_retrieve_cb_t callback, void* userdata)
{ {
if (!handle) if (!handle)
return CV_ERROR_FAIL; return CV_ERROR_FAIL;
...@@ -1956,7 +1959,7 @@ CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx, ...@@ -1956,7 +1959,7 @@ CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx,
Mat img; Mat img;
// TODO: avoid unnecessary copying - implement lower level GStreamerCapture::retrieve // TODO: avoid unnecessary copying - implement lower level GStreamerCapture::retrieve
if (instance->retrieveFrame(stream_idx, img)) if (instance->retrieveFrame(stream_idx, img))
return callback(stream_idx, img.data, img.step, img.cols, img.rows, img.channels(), userdata); return callback(stream_idx, img.data, img.step, img.cols, img.rows, img.type(), userdata);
return CV_ERROR_FAIL; return CV_ERROR_FAIL;
} }
catch(...) catch(...)
...@@ -2063,12 +2066,12 @@ CvResult CV_API_CALL cv_writer_write(CvPluginWriter handle, const unsigned char ...@@ -2063,12 +2066,12 @@ CvResult CV_API_CALL cv_writer_write(CvPluginWriter handle, const unsigned char
} }
} }
static const OpenCV_VideoIO_Plugin_API_preview plugin_api = static const OpenCV_VideoIO_Capture_Plugin_API capture_api =
{ {
{ {
sizeof(OpenCV_VideoIO_Plugin_API_preview), ABI_VERSION, API_VERSION, sizeof(OpenCV_VideoIO_Capture_Plugin_API), CAPTURE_ABI_VERSION, CAPTURE_API_VERSION,
CV_VERSION_MAJOR, CV_VERSION_MINOR, CV_VERSION_REVISION, CV_VERSION_STATUS, CV_VERSION_MAJOR, CV_VERSION_MINOR, CV_VERSION_REVISION, CV_VERSION_STATUS,
"GStreamer OpenCV Video I/O plugin" "GStreamer OpenCV Video I/O Capture plugin"
}, },
{ {
/* 1*/CAP_GSTREAMER, /* 1*/CAP_GSTREAMER,
...@@ -2078,23 +2081,42 @@ static const OpenCV_VideoIO_Plugin_API_preview plugin_api = ...@@ -2078,23 +2081,42 @@ static const OpenCV_VideoIO_Plugin_API_preview plugin_api =
/* 5*/cv_capture_set_prop, /* 5*/cv_capture_set_prop,
/* 6*/cv_capture_grab, /* 6*/cv_capture_grab,
/* 7*/cv_capture_retrieve, /* 7*/cv_capture_retrieve,
/* 8*/cv_writer_open, }
/* 9*/cv_writer_release, };
/* 10*/cv_writer_get_prop,
/* 11*/cv_writer_set_prop, static const OpenCV_VideoIO_Writer_Plugin_API writer_api =
/* 12*/cv_writer_write {
{
sizeof(OpenCV_VideoIO_Writer_Plugin_API), WRITER_ABI_VERSION, WRITER_API_VERSION,
CV_VERSION_MAJOR, CV_VERSION_MINOR, CV_VERSION_REVISION, CV_VERSION_STATUS,
"GStreamer OpenCV Video I/O Writer plugin"
}, },
{ {
/* 13*/cv_writer_open_with_params /* 1*/CAP_GSTREAMER,
/* 2*/cv_writer_open,
/* 3*/cv_writer_release,
/* 4*/cv_writer_get_prop,
/* 5*/cv_writer_set_prop,
/* 6*/cv_writer_write
},
{
/* 7*/cv_writer_open_with_params
} }
}; };
} // namespace } // namespace
const OpenCV_VideoIO_Plugin_API_preview* opencv_videoio_plugin_init_v0(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT const OpenCV_VideoIO_Capture_Plugin_API* opencv_videoio_capture_plugin_init_v1(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT
{
if (requested_abi_version == CAPTURE_ABI_VERSION && requested_api_version <= CAPTURE_API_VERSION)
return &cv::capture_api;
return NULL;
}
const OpenCV_VideoIO_Writer_Plugin_API* opencv_videoio_writer_plugin_init_v1(int requested_abi_version, int requested_api_version, void* /*reserved=NULL*/) CV_NOEXCEPT
{ {
if (requested_abi_version == ABI_VERSION && requested_api_version <= API_VERSION) if (requested_abi_version == WRITER_ABI_VERSION && requested_api_version <= WRITER_API_VERSION)
return &cv::plugin_api; return &cv::writer_api;
return NULL; return NULL;
} }
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory // 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. // of this distribution and at http://opencv.org/license.html.
//
// DEPRECATED. Do not use in new plugins
//
#ifndef PLUGIN_API_HPP #ifndef PLUGIN_API_HPP
#define PLUGIN_API_HPP #define PLUGIN_API_HPP
...@@ -129,7 +133,7 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries ...@@ -129,7 +133,7 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries
/** @brief Get property value /** @brief Get property value
@param handle Capture handle @param handle Writer handle
@param prop Property index @param prop Property index
@param[out] val property value @param[out] val property value
...@@ -139,7 +143,7 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries ...@@ -139,7 +143,7 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries
/** @brief Set property value /** @brief Set property value
@param handle Capture handle @param handle Writer handle
@param prop Property index @param prop Property index
@param val property value @param val property value
...@@ -149,8 +153,8 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries ...@@ -149,8 +153,8 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries
/** @brief Write frame /** @brief Write frame
@param handle Capture handle @param handle Writer handle
@param data Capture handle @param data frame data
@param step step in bytes @param step step in bytes
@param width frame width in pixels @param width frame width in pixels
@param height frame height @param height frame height
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory // 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. // of this distribution and at http://opencv.org/license.html.
#ifndef PLUGIN_API_HPP #ifndef PLUGIN_CAPTURE_API_HPP
#define PLUGIN_API_HPP #define PLUGIN_CAPTURE_API_HPP
#include <opencv2/core/cvdef.h> #include <opencv2/core/cvdef.h>
#include <opencv2/core/llapi/llapi.h> #include <opencv2/core/llapi/llapi.h>
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
/// increased for backward-compatible changes, e.g. add new function /// increased for backward-compatible changes, e.g. add new function
/// Caller API <= Plugin API -> plugin is fully compatible /// Caller API <= Plugin API -> plugin is fully compatible
/// Caller API > Plugin API -> plugin is not fully compatible, caller should use extra checks to use plugins with older API /// Caller API > Plugin API -> plugin is not fully compatible, caller should use extra checks to use plugins with older API
#define API_VERSION 1 // preview #define CAPTURE_API_VERSION 0
/// increased for incompatible changes, e.g. remove function argument /// increased for incompatible changes, e.g. remove function argument
/// Caller ABI == Plugin ABI -> plugin is compatible /// Caller ABI == Plugin ABI -> plugin is compatible
/// Caller ABI > Plugin ABI -> plugin is not compatible, caller should use shim code to use old ABI plugins (caller may know how lower ABI works, so it is possible) /// Caller ABI > Plugin ABI -> plugin is not compatible, caller should use shim code to use old ABI plugins (caller may know how lower ABI works, so it is possible)
/// Caller ABI < Plugin ABI -> plugin can't be used (plugin should provide interface with lower ABI to handle that) /// Caller ABI < Plugin ABI -> plugin can't be used (plugin should provide interface with lower ABI to handle that)
#define ABI_VERSION 0 // preview #define CAPTURE_ABI_VERSION 1
#else // !defined(BUILD_PLUGIN) #else // !defined(BUILD_PLUGIN)
#if !defined(ABI_VERSION) || !defined(API_VERSION) #if !defined(CAPTURE_ABI_VERSION) || !defined(CAPTURE_API_VERSION)
#error "Plugin must define ABI_VERSION and API_VERSION before including plugin_api.hpp" #error "Plugin must define CAPTURE_ABI_VERSION and CAPTURE_API_VERSION before including plugin_capture_api.hpp"
#endif #endif
#endif // !defined(BUILD_PLUGIN) #endif // !defined(BUILD_PLUGIN)
...@@ -34,17 +34,16 @@ ...@@ -34,17 +34,16 @@
extern "C" { extern "C" {
#endif #endif
typedef CvResult (CV_API_CALL *cv_videoio_retrieve_cb_t)(int stream_idx, unsigned const char* data, int step, int width, int height, int cn, void* userdata); typedef CvResult (CV_API_CALL *cv_videoio_capture_retrieve_cb_t)(int stream_idx, unsigned const char* data, int step, int width, int height, int type, void* userdata);
typedef struct CvPluginCapture_t* CvPluginCapture; typedef struct CvPluginCapture_t* CvPluginCapture;
typedef struct CvPluginWriter_t* CvPluginWriter;
struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries struct OpenCV_VideoIO_Capture_Plugin_API_v1_0_api_entries
{ {
/** OpenCV capture ID (VideoCaptureAPIs) /** OpenCV capture ID (VideoCaptureAPIs)
@note API-ENTRY 1, API-Version == 0 @note API-ENTRY 1, API-Version == 0
*/ */
int captureAPI; int id;
/** @brief Open video capture /** @brief Open video capture
...@@ -101,108 +100,43 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries ...@@ -101,108 +100,43 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries
@note API-CALL 7, API-Version == 0 @note API-CALL 7, API-Version == 0
*/ */
CvResult (CV_API_CALL *Capture_retreive)(CvPluginCapture handle, int stream_idx, cv_videoio_retrieve_cb_t callback, void* userdata); CvResult (CV_API_CALL *Capture_retreive)(CvPluginCapture handle, int stream_idx, cv_videoio_capture_retrieve_cb_t callback, void* userdata);
}; // OpenCV_VideoIO_Capture_Plugin_API_v1_0_api_entries
#if 0
/** @brief Try to open video writer struct OpenCV_VideoIO_Capture_Plugin_API_v1_1_api_entries
@param filename Destination location
@param fourcc FOURCC code
@param fps FPS
@param width frame width
@param height frame height
@param isColor true if video stream should save color frames
@param[out] handle pointer on Writer handle
@note API-CALL 8, API-Version == 0
*/
CvResult (CV_API_CALL *Writer_open)(const char* filename, int fourcc, double fps, int width, int height, int isColor,
CV_OUT CvPluginWriter* handle);
/** @brief Release Writer handle
@param handle Writer handle
@note API-CALL 9, API-Version == 0
*/
CvResult (CV_API_CALL *Writer_release)(CvPluginWriter handle);
/** @brief Get property value
@param handle Capture handle
@param prop Property index
@param[out] val property value
@note API-CALL 10, API-Version == 0
*/
CvResult (CV_API_CALL *Writer_getProperty)(CvPluginWriter handle, int prop, CV_OUT double* val);
/** @brief Set property value
@param handle Capture handle
@param prop Property index
@param val property value
@note API-CALL 11, API-Version == 0
*/
CvResult (CV_API_CALL *Writer_setProperty)(CvPluginWriter handle, int prop, double val);
/** @brief Write frame
@param handle Capture handle
@param data Capture handle
@param step step in bytes
@param width frame width in pixels
@param height frame height
@param cn number of channels per pixel
@note API-CALL 12, API-Version == 0
*/
CvResult (CV_API_CALL *Writer_write)(CvPluginWriter handle, const unsigned char *data, int step, int width, int height, int cn);
}; // OpenCV_VideoIO_Plugin_API_v0_0_api_entries
struct OpenCV_VideoIO_Plugin_API_v0_1_api_entries
{ {
/** @brief Try to open video writer /** @brief TBD
@param filename Destination location @note API-CALL XXX, API-Version == YYY
@param fourcc FOURCC code
@param fps FPS
@param width frame width
@param height frame height
@param params pointer on 2*n_params array of 'key,value' pairs
@param n_params number of passed parameters
@param[out] handle pointer on Writer handle
@note API-CALL 13, API-Version == 1
*/ */
CvResult (CV_API_CALL* Writer_open_with_params)( CvResult (CV_API_CALL* zzz)(
const char* filename, int fourcc, double fps, int width, int height, ...
int* params, unsigned n_params,
CV_OUT CvPluginWriter* handle
); );
}; // OpenCV_VideoIO_Plugin_API_v0_1_api_entries }; // OpenCV_VideoIO_Capture_Plugin_API_v1_1_api_entries
#endif
typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 typedef struct OpenCV_VideoIO_Capture_Plugin_API_v1_0
{ {
OpenCV_API_Header api_header; OpenCV_API_Header api_header;
struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries v0; struct OpenCV_VideoIO_Capture_Plugin_API_v1_0_api_entries v0;
} OpenCV_VideoIO_Plugin_API_preview_v0; } OpenCV_VideoIO_Capture_Plugin_API_v1_0;
typedef struct OpenCV_VideoIO_Plugin_API_preview_v1 #if 0
typedef struct OpenCV_VideoIO_Capture_Plugin_API_v1_1
{ {
OpenCV_API_Header api_header; OpenCV_API_Header api_header;
struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries v0; struct OpenCV_VideoIO_Capture_Plugin_API_v1_0_api_entries v0;
struct OpenCV_VideoIO_Plugin_API_v0_1_api_entries v1; struct OpenCV_VideoIO_Capture_Plugin_API_v1_1_api_entries v1;
} OpenCV_VideoIO_Plugin_API_preview_v1; } OpenCV_VideoIO_Capture_Plugin_API_v1_1;
#endif
#if ABI_VERSION == 0 && API_VERSION == 1 #if 0 //CAPTURE_ABI_VERSION == 1 && CAPTURE_API_VERSION == 1
typedef struct OpenCV_VideoIO_Plugin_API_preview_v1 OpenCV_VideoIO_Plugin_API_preview; typedef struct OpenCV_VideoIO_Capture_Plugin_API_v1_1 OpenCV_VideoIO_Capture_Plugin_API;
#elif ABI_VERSION == 0 && API_VERSION == 0 #elif CAPTURE_ABI_VERSION == 1 && CAPTURE_API_VERSION == 0
typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 OpenCV_VideoIO_Plugin_API_preview; typedef struct OpenCV_VideoIO_Capture_Plugin_API_v1_0 OpenCV_VideoIO_Capture_Plugin_API;
#else #else
#error "Not supported configuration: check ABI_VERSION/API_VERSION" #error "Not supported configuration: check CAPTURE_ABI_VERSION/CAPTURE_API_VERSION"
#endif #endif
#ifdef BUILD_PLUGIN #ifdef BUILD_PLUGIN
...@@ -216,11 +150,11 @@ typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 OpenCV_VideoIO_Plugin_API_pr ...@@ -216,11 +150,11 @@ typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 OpenCV_VideoIO_Plugin_API_pr
#endif #endif
CV_PLUGIN_EXPORTS CV_PLUGIN_EXPORTS
const OpenCV_VideoIO_Plugin_API_preview* CV_API_CALL opencv_videoio_plugin_init_v0 const OpenCV_VideoIO_Capture_Plugin_API* CV_API_CALL opencv_videoio_capture_plugin_init_v1
(int requested_abi_version, int requested_api_version, void* reserved /*NULL*/) CV_NOEXCEPT; (int requested_abi_version, int requested_api_version, void* reserved /*NULL*/) CV_NOEXCEPT;
#else // BUILD_PLUGIN #else // BUILD_PLUGIN
typedef const OpenCV_VideoIO_Plugin_API_preview* (CV_API_CALL *FN_opencv_videoio_plugin_init_t) typedef const OpenCV_VideoIO_Capture_Plugin_API* (CV_API_CALL *FN_opencv_videoio_capture_plugin_init_t)
(int requested_abi_version, int requested_api_version, void* reserved /*NULL*/); (int requested_abi_version, int requested_api_version, void* reserved /*NULL*/);
#endif // BUILD_PLUGIN #endif // BUILD_PLUGIN
...@@ -229,4 +163,4 @@ typedef const OpenCV_VideoIO_Plugin_API_preview* (CV_API_CALL *FN_opencv_videoio ...@@ -229,4 +163,4 @@ typedef const OpenCV_VideoIO_Plugin_API_preview* (CV_API_CALL *FN_opencv_videoio
} }
#endif #endif
#endif // PLUGIN_API_HPP #endif // PLUGIN_CAPTURE_API_HPP
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory // 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. // of this distribution and at http://opencv.org/license.html.
#ifndef PLUGIN_API_HPP #ifndef PLUGIN_WRITER_API_HPP
#define PLUGIN_API_HPP #define PLUGIN_WRITER_API_HPP
#include <opencv2/core/cvdef.h> #include <opencv2/core/cvdef.h>
#include <opencv2/core/llapi/llapi.h> #include <opencv2/core/llapi/llapi.h>
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
/// increased for backward-compatible changes, e.g. add new function /// increased for backward-compatible changes, e.g. add new function
/// Caller API <= Plugin API -> plugin is fully compatible /// Caller API <= Plugin API -> plugin is fully compatible
/// Caller API > Plugin API -> plugin is not fully compatible, caller should use extra checks to use plugins with older API /// Caller API > Plugin API -> plugin is not fully compatible, caller should use extra checks to use plugins with older API
#define API_VERSION 1 // preview #define WRITER_API_VERSION 1
/// increased for incompatible changes, e.g. remove function argument /// increased for incompatible changes, e.g. remove function argument
/// Caller ABI == Plugin ABI -> plugin is compatible /// Caller ABI == Plugin ABI -> plugin is compatible
/// Caller ABI > Plugin ABI -> plugin is not compatible, caller should use shim code to use old ABI plugins (caller may know how lower ABI works, so it is possible) /// Caller ABI > Plugin ABI -> plugin is not compatible, caller should use shim code to use old ABI plugins (caller may know how lower ABI works, so it is possible)
/// Caller ABI < Plugin ABI -> plugin can't be used (plugin should provide interface with lower ABI to handle that) /// Caller ABI < Plugin ABI -> plugin can't be used (plugin should provide interface with lower ABI to handle that)
#define ABI_VERSION 0 // preview #define WRITER_ABI_VERSION 1
#else // !defined(BUILD_PLUGIN) #else // !defined(BUILD_PLUGIN)
#if !defined(ABI_VERSION) || !defined(API_VERSION) #if !defined(WRITER_ABI_VERSION) || !defined(WRITER_API_VERSION)
#error "Plugin must define ABI_VERSION and API_VERSION before including plugin_api.hpp" #error "Plugin must define WRITER_ABI_VERSION and WRITER_API_VERSION before including plugin_writer_api.hpp"
#endif #endif
#endif // !defined(BUILD_PLUGIN) #endif // !defined(BUILD_PLUGIN)
...@@ -34,75 +34,14 @@ ...@@ -34,75 +34,14 @@
extern "C" { extern "C" {
#endif #endif
typedef CvResult (CV_API_CALL *cv_videoio_retrieve_cb_t)(int stream_idx, unsigned const char* data, int step, int width, int height, int cn, void* userdata);
typedef struct CvPluginCapture_t* CvPluginCapture;
typedef struct CvPluginWriter_t* CvPluginWriter; typedef struct CvPluginWriter_t* CvPluginWriter;
struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries struct OpenCV_VideoIO_Writer_Plugin_API_v1_0_api_entries
{ {
/** OpenCV capture ID (VideoCaptureAPIs) /** OpenCV capture ID (VideoCaptureAPIs)
@note API-ENTRY 1, API-Version == 0 @note API-ENTRY 1, API-Version == 0
*/ */
int captureAPI; int id;
/** @brief Open video capture
@param filename File name or NULL to use camera_index instead
@param camera_index Camera index (used if filename == NULL)
@param[out] handle pointer on Capture handle
@note API-CALL 2, API-Version == 0
*/
CvResult (CV_API_CALL *Capture_open)(const char* filename, int camera_index, CV_OUT CvPluginCapture* handle);
/** @brief Release Capture handle
@param handle Capture handle
@note API-CALL 3, API-Version == 0
*/
CvResult (CV_API_CALL *Capture_release)(CvPluginCapture handle);
/** @brief Get property value
@param handle Capture handle
@param prop Property index
@param[out] val property value
@note API-CALL 4, API-Version == 0
*/
CvResult (CV_API_CALL *Capture_getProperty)(CvPluginCapture handle, int prop, CV_OUT double* val);
/** @brief Set property value
@param handle Capture handle
@param prop Property index
@param val property value
@note API-CALL 5, API-Version == 0
*/
CvResult (CV_API_CALL *Capture_setProperty)(CvPluginCapture handle, int prop, double val);
/** @brief Grab frame
@param handle Capture handle
@note API-CALL 6, API-Version == 0
*/
CvResult (CV_API_CALL *Capture_grab)(CvPluginCapture handle);
/** @brief Retrieve frame
@param handle Capture handle
@param stream_idx stream index to retrieve (BGR/IR/depth data)
@param callback retrieve callback (synchronous)
@param userdata callback context data
@note API-CALL 7, API-Version == 0
*/
CvResult (CV_API_CALL *Capture_retreive)(CvPluginCapture handle, int stream_idx, cv_videoio_retrieve_cb_t callback, void* userdata);
/** @brief Try to open video writer /** @brief Try to open video writer
...@@ -114,7 +53,7 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries ...@@ -114,7 +53,7 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries
@param isColor true if video stream should save color frames @param isColor true if video stream should save color frames
@param[out] handle pointer on Writer handle @param[out] handle pointer on Writer handle
@note API-CALL 8, API-Version == 0 @note API-CALL 2, API-Version == 0
*/ */
CvResult (CV_API_CALL *Writer_open)(const char* filename, int fourcc, double fps, int width, int height, int isColor, CvResult (CV_API_CALL *Writer_open)(const char* filename, int fourcc, double fps, int width, int height, int isColor,
CV_OUT CvPluginWriter* handle); CV_OUT CvPluginWriter* handle);
...@@ -123,45 +62,45 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries ...@@ -123,45 +62,45 @@ struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries
@param handle Writer handle @param handle Writer handle
@note API-CALL 9, API-Version == 0 @note API-CALL 3, API-Version == 0
*/ */
CvResult (CV_API_CALL *Writer_release)(CvPluginWriter handle); CvResult (CV_API_CALL *Writer_release)(CvPluginWriter handle);
/** @brief Get property value /** @brief Get property value
@param handle Capture handle @param handle Writer handle
@param prop Property index @param prop Property index
@param[out] val property value @param[out] val property value
@note API-CALL 10, API-Version == 0 @note API-CALL 4, API-Version == 0
*/ */
CvResult (CV_API_CALL *Writer_getProperty)(CvPluginWriter handle, int prop, CV_OUT double* val); CvResult (CV_API_CALL *Writer_getProperty)(CvPluginWriter handle, int prop, CV_OUT double* val);
/** @brief Set property value /** @brief Set property value
@param handle Capture handle @param handle Writer handle
@param prop Property index @param prop Property index
@param val property value @param val property value
@note API-CALL 11, API-Version == 0 @note API-CALL 5, API-Version == 0
*/ */
CvResult (CV_API_CALL *Writer_setProperty)(CvPluginWriter handle, int prop, double val); CvResult (CV_API_CALL *Writer_setProperty)(CvPluginWriter handle, int prop, double val);
/** @brief Write frame /** @brief Write frame
@param handle Capture handle @param handle Writer handle
@param data Capture handle @param data frame data
@param step step in bytes @param step step in bytes
@param width frame width in pixels @param width frame width in pixels
@param height frame height @param height frame height
@param cn number of channels per pixel @param cn number of channels per pixel
@note API-CALL 12, API-Version == 0 @note API-CALL 6, API-Version == 0
*/ */
CvResult (CV_API_CALL *Writer_write)(CvPluginWriter handle, const unsigned char *data, int step, int width, int height, int cn); CvResult (CV_API_CALL *Writer_write)(CvPluginWriter handle, const unsigned char *data, int step, int width, int height, int cn);
}; // OpenCV_VideoIO_Plugin_API_v0_0_api_entries }; // OpenCV_VideoIO_Writer_Plugin_API_v1_0_api_entries
struct OpenCV_VideoIO_Plugin_API_v0_1_api_entries struct OpenCV_VideoIO_Writer_Plugin_API_v1_1_api_entries
{ {
/** @brief Try to open video writer /** @brief Try to open video writer
...@@ -174,35 +113,35 @@ struct OpenCV_VideoIO_Plugin_API_v0_1_api_entries ...@@ -174,35 +113,35 @@ struct OpenCV_VideoIO_Plugin_API_v0_1_api_entries
@param n_params number of passed parameters @param n_params number of passed parameters
@param[out] handle pointer on Writer handle @param[out] handle pointer on Writer handle
@note API-CALL 13, API-Version == 1 @note API-CALL 7, API-Version == 1
*/ */
CvResult (CV_API_CALL* Writer_open_with_params)( CvResult (CV_API_CALL* Writer_open_with_params)(
const char* filename, int fourcc, double fps, int width, int height, const char* filename, int fourcc, double fps, int width, int height,
int* params, unsigned n_params, int* params, unsigned n_params,
CV_OUT CvPluginWriter* handle CV_OUT CvPluginWriter* handle
); );
}; // OpenCV_VideoIO_Plugin_API_v0_1_api_entries }; // OpenCV_VideoIO_Writer_Plugin_API_v1_1_api_entries
typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 typedef struct OpenCV_VideoIO_Writer_Plugin_API_v1_0
{ {
OpenCV_API_Header api_header; OpenCV_API_Header api_header;
struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries v0; struct OpenCV_VideoIO_Writer_Plugin_API_v1_0_api_entries v0;
} OpenCV_VideoIO_Plugin_API_preview_v0; } OpenCV_VideoIO_Writer_Plugin_API_v1_0;
typedef struct OpenCV_VideoIO_Plugin_API_preview_v1 typedef struct OpenCV_VideoIO_Writer_Plugin_API_v1_1
{ {
OpenCV_API_Header api_header; OpenCV_API_Header api_header;
struct OpenCV_VideoIO_Plugin_API_v0_0_api_entries v0; struct OpenCV_VideoIO_Writer_Plugin_API_v1_0_api_entries v0;
struct OpenCV_VideoIO_Plugin_API_v0_1_api_entries v1; struct OpenCV_VideoIO_Writer_Plugin_API_v1_1_api_entries v1;
} OpenCV_VideoIO_Plugin_API_preview_v1; } OpenCV_VideoIO_Writer_Plugin_API_v1_1;
#if ABI_VERSION == 0 && API_VERSION == 1 #if WRITER_ABI_VERSION == 1 && WRITER_API_VERSION == 1
typedef struct OpenCV_VideoIO_Plugin_API_preview_v1 OpenCV_VideoIO_Plugin_API_preview; typedef struct OpenCV_VideoIO_Writer_Plugin_API_v1_1 OpenCV_VideoIO_Writer_Plugin_API;
#elif ABI_VERSION == 0 && API_VERSION == 0 #elif WRITER_ABI_VERSION == 1 && WRITER_API_VERSION == 0
typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 OpenCV_VideoIO_Plugin_API_preview; typedef struct OpenCV_VideoIO_Writer_Plugin_API_v1_0 OpenCV_VideoIO_Writer_Plugin_API;
#else #else
#error "Not supported configuration: check ABI_VERSION/API_VERSION" #error "Not supported configuration: check WRITER_ABI_VERSION/WRITER_API_VERSION"
#endif #endif
#ifdef BUILD_PLUGIN #ifdef BUILD_PLUGIN
...@@ -216,11 +155,11 @@ typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 OpenCV_VideoIO_Plugin_API_pr ...@@ -216,11 +155,11 @@ typedef struct OpenCV_VideoIO_Plugin_API_preview_v0 OpenCV_VideoIO_Plugin_API_pr
#endif #endif
CV_PLUGIN_EXPORTS CV_PLUGIN_EXPORTS
const OpenCV_VideoIO_Plugin_API_preview* CV_API_CALL opencv_videoio_plugin_init_v0 const OpenCV_VideoIO_Writer_Plugin_API* CV_API_CALL opencv_videoio_writer_plugin_init_v1
(int requested_abi_version, int requested_api_version, void* reserved /*NULL*/) CV_NOEXCEPT; (int requested_abi_version, int requested_api_version, void* reserved /*NULL*/) CV_NOEXCEPT;
#else // BUILD_PLUGIN #else // BUILD_PLUGIN
typedef const OpenCV_VideoIO_Plugin_API_preview* (CV_API_CALL *FN_opencv_videoio_plugin_init_t) typedef const OpenCV_VideoIO_Writer_Plugin_API* (CV_API_CALL *FN_opencv_videoio_writer_plugin_init_t)
(int requested_abi_version, int requested_api_version, void* reserved /*NULL*/); (int requested_abi_version, int requested_api_version, void* reserved /*NULL*/);
#endif // BUILD_PLUGIN #endif // BUILD_PLUGIN
...@@ -229,4 +168,4 @@ typedef const OpenCV_VideoIO_Plugin_API_preview* (CV_API_CALL *FN_opencv_videoio ...@@ -229,4 +168,4 @@ typedef const OpenCV_VideoIO_Plugin_API_preview* (CV_API_CALL *FN_opencv_videoio
} }
#endif #endif
#endif // PLUGIN_API_HPP #endif // PLUGIN_WRITER_API_HPP
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册