mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #19934 from alalek:videoio_plugin_query_api
This commit is contained in:
@@ -27,6 +27,7 @@ class IBackendFactory
|
||||
public:
|
||||
virtual ~IBackendFactory() {}
|
||||
virtual Ptr<IBackend> getBackend() const = 0;
|
||||
virtual bool isBuiltIn() const = 0;
|
||||
};
|
||||
|
||||
//=============================================================================
|
||||
@@ -48,6 +49,17 @@ Ptr<IBackendFactory> createPluginBackendFactory(VideoCaptureAPIs id, const char*
|
||||
|
||||
void applyParametersFallback(const Ptr<IVideoCapture>& cap, const VideoCaptureParameters& params);
|
||||
|
||||
std::string getCapturePluginVersion(
|
||||
const Ptr<IBackendFactory>& backend_factory,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
);
|
||||
std::string getWriterPluginVersion(
|
||||
const Ptr<IBackendFactory>& backend_factory,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
);
|
||||
|
||||
} // namespace cv::
|
||||
|
||||
#endif // BACKEND_HPP_DEFINED
|
||||
|
||||
@@ -210,6 +210,24 @@ public:
|
||||
Ptr<IVideoCapture> createCapture(const std::string &filename, const VideoCaptureParameters& params) const CV_OVERRIDE;
|
||||
Ptr<IVideoWriter> createWriter(const std::string& filename, int fourcc, double fps,
|
||||
const cv::Size& sz, const VideoWriterParameters& params) const CV_OVERRIDE;
|
||||
|
||||
std::string getCapturePluginVersion(CV_OUT int& version_ABI, CV_OUT int& version_API)
|
||||
{
|
||||
CV_Assert(capture_api_ || plugin_api_);
|
||||
const OpenCV_API_Header& api_header = capture_api_ ? capture_api_->api_header : plugin_api_->api_header;
|
||||
version_ABI = api_header.min_api_version;
|
||||
version_API = api_header.api_version;
|
||||
return api_header.api_description;
|
||||
}
|
||||
|
||||
std::string getWriterPluginVersion(CV_OUT int& version_ABI, CV_OUT int& version_API)
|
||||
{
|
||||
CV_Assert(writer_api_ || plugin_api_);
|
||||
const OpenCV_API_Header& api_header = writer_api_ ? writer_api_->api_header : plugin_api_->api_header;
|
||||
version_ABI = api_header.min_api_version;
|
||||
version_API = api_header.api_version;
|
||||
return api_header.api_description;
|
||||
}
|
||||
};
|
||||
|
||||
class PluginBackendFactory : public IBackendFactory
|
||||
@@ -229,14 +247,41 @@ public:
|
||||
|
||||
Ptr<IBackend> getBackend() const CV_OVERRIDE
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
const_cast<PluginBackendFactory*>(this)->initBackend();
|
||||
}
|
||||
initBackend();
|
||||
return backend.staticCast<IBackend>();
|
||||
}
|
||||
|
||||
bool isBuiltIn() const CV_OVERRIDE { return false; }
|
||||
|
||||
std::string getCapturePluginVersion(
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API) const
|
||||
{
|
||||
initBackend();
|
||||
if (!backend)
|
||||
CV_Error_(Error::StsNotImplemented, ("Backend '%s' is not available", baseName_));
|
||||
return backend->getCapturePluginVersion(version_ABI, version_API);
|
||||
}
|
||||
|
||||
std::string getWriterPluginVersion(
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API) const
|
||||
{
|
||||
initBackend();
|
||||
if (!backend)
|
||||
CV_Error_(Error::StsNotImplemented, ("Backend '%s' is not available", baseName_));
|
||||
return backend->getWriterPluginVersion(version_ABI, version_API);
|
||||
}
|
||||
|
||||
protected:
|
||||
void initBackend()
|
||||
inline void initBackend() const
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
const_cast<PluginBackendFactory*>(this)->initBackend_();
|
||||
}
|
||||
}
|
||||
void initBackend_()
|
||||
{
|
||||
AutoLock lock(getInitializationMutex());
|
||||
try {
|
||||
@@ -690,4 +735,43 @@ Ptr<IBackendFactory> createPluginBackendFactory(VideoCaptureAPIs id, const char*
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string getCapturePluginVersion(
|
||||
const Ptr<IBackendFactory>& backend_factory,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT && defined(ENABLE_PLUGINS)
|
||||
using namespace impl;
|
||||
CV_Assert(backend_factory);
|
||||
PluginBackendFactory* plugin_backend_factory = dynamic_cast<PluginBackendFactory*>(backend_factory.get());
|
||||
CV_Assert(plugin_backend_factory);
|
||||
return plugin_backend_factory->getCapturePluginVersion(version_ABI, version_API);
|
||||
#else
|
||||
CV_UNUSED(version_ABI);
|
||||
CV_UNUSED(version_API);
|
||||
CV_Error(Error::StsBadFunc, "Plugins are not available in this build");
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string getWriterPluginVersion(
|
||||
const Ptr<IBackendFactory>& backend_factory,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT && defined(ENABLE_PLUGINS)
|
||||
using namespace impl;
|
||||
CV_Assert(backend_factory);
|
||||
PluginBackendFactory* plugin_backend_factory = dynamic_cast<PluginBackendFactory*>(backend_factory.get());
|
||||
CV_Assert(plugin_backend_factory);
|
||||
return plugin_backend_factory->getWriterPluginVersion(version_ABI, version_API);
|
||||
#else
|
||||
CV_UNUSED(version_ABI);
|
||||
CV_UNUSED(version_API);
|
||||
CV_Error(Error::StsBadFunc, "Plugins are not available in this build");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -99,6 +99,8 @@ public:
|
||||
{
|
||||
return backend.staticCast<IBackend>();
|
||||
}
|
||||
|
||||
bool isBuiltIn() const CV_OVERRIDE { return true; }
|
||||
};
|
||||
|
||||
|
||||
@@ -165,6 +167,8 @@ public:
|
||||
{
|
||||
return backend.staticCast<IBackend>();
|
||||
}
|
||||
|
||||
bool isBuiltIn() const CV_OVERRIDE { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -403,6 +403,81 @@ bool hasBackend(VideoCaptureAPIs api)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isBackendBuiltIn(VideoCaptureAPIs api)
|
||||
{
|
||||
std::vector<VideoBackendInfo> backends = VideoBackendRegistry::getInstance().getEnabledBackends();
|
||||
for (size_t i = 0; i < backends.size(); i++)
|
||||
{
|
||||
const VideoBackendInfo& info = backends[i];
|
||||
if (api == info.id)
|
||||
{
|
||||
CV_Assert(!info.backendFactory.empty());
|
||||
return info.backendFactory->isBuiltIn();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string getCameraBackendPluginVersion(VideoCaptureAPIs api,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
)
|
||||
{
|
||||
const std::vector<VideoBackendInfo> backends = VideoBackendRegistry::getInstance().getAvailableBackends_CaptureByIndex();
|
||||
for (size_t i = 0; i < backends.size(); i++)
|
||||
{
|
||||
const VideoBackendInfo& info = backends[i];
|
||||
if (api == info.id)
|
||||
{
|
||||
CV_Assert(!info.backendFactory.empty());
|
||||
CV_Assert(!info.backendFactory->isBuiltIn());
|
||||
return getCapturePluginVersion(info.backendFactory, version_ABI, version_API);
|
||||
}
|
||||
}
|
||||
CV_Error(Error::StsError, "Unknown or wrong backend ID");
|
||||
}
|
||||
|
||||
std::string getStreamBackendPluginVersion(VideoCaptureAPIs api,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
)
|
||||
{
|
||||
const std::vector<VideoBackendInfo> backends = VideoBackendRegistry::getInstance().getAvailableBackends_CaptureByFilename();
|
||||
for (size_t i = 0; i < backends.size(); i++)
|
||||
{
|
||||
const VideoBackendInfo& info = backends[i];
|
||||
if (api == info.id)
|
||||
{
|
||||
CV_Assert(!info.backendFactory.empty());
|
||||
CV_Assert(!info.backendFactory->isBuiltIn());
|
||||
return getCapturePluginVersion(info.backendFactory, version_ABI, version_API);
|
||||
}
|
||||
}
|
||||
CV_Error(Error::StsError, "Unknown or wrong backend ID");
|
||||
}
|
||||
|
||||
|
||||
/** @brief Returns description and ABI/API version of videoio plugin's writer interface */
|
||||
std::string getWriterBackendPluginVersion(VideoCaptureAPIs api,
|
||||
CV_OUT int& version_ABI,
|
||||
CV_OUT int& version_API
|
||||
)
|
||||
{
|
||||
const std::vector<VideoBackendInfo> backends = VideoBackendRegistry::getInstance().getAvailableBackends_Writer();
|
||||
for (size_t i = 0; i < backends.size(); i++)
|
||||
{
|
||||
const VideoBackendInfo& info = backends[i];
|
||||
if (api == info.id)
|
||||
{
|
||||
CV_Assert(!info.backendFactory.empty());
|
||||
CV_Assert(!info.backendFactory->isBuiltIn());
|
||||
return getWriterPluginVersion(info.backendFactory, version_ABI, version_API);
|
||||
}
|
||||
}
|
||||
CV_Error(Error::StsError, "Unknown or wrong backend ID");
|
||||
}
|
||||
|
||||
|
||||
} // namespace registry
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user