image_framework_ymj/image_framework/driver/camera/CameraHelper.cpp

77 lines
1.5 KiB
C++
Raw Normal View History

2024-12-06 16:25:16 +08:00
#include "CameraHelper.h"
#include "IniHelper.h"
#include <cassert>
#ifndef _WIN32
#include <dlfcn.h> // Linux for so
#endif
#include <iostream>
CCameraHelper* CCameraHelper::m_instance;
CCameraHelper* CCameraHelper::Get()
{
if (CCameraHelper::m_instance == nullptr) {
CCameraHelper::m_instance = new CCameraHelper();
// 待优化
}
return CCameraHelper::m_instance;
}
CCameraHelper::CCameraHelper()
{
}
CCameraHelper::~CCameraHelper()
{
}
int CCameraHelper::Init()
{
#ifndef _WIN32
const char* libPath = "./libCameraDriver.so";
void* handle = dlopen(libPath, RTLD_LAZY);
if (!handle) {
// Linux
std::cerr << "无法加载动态库: " << dlerror() << std::endl;
return CAMERA_DLL_INIT_ERROR;
}
pfuccamera_init = (PFuccamera_init)dlsym(handle, "camera_init");
pfuccamera_start = (PFuccamera_start)dlsym(handle, "camera_start");
pfuccamera_stop = (PFuccamera_stop)dlsym(handle, "camera_stop");
pfuccamera_cap = (PFuccamera_cap)dlsym(handle, "camera_cap");
if (G(camera_cap_fake) == "true")
return 0;
else
{
this->pfuccamera_init();
//this->pfuccamera_start(12 * 10000);
return 0;
//return this->pfuccamera_init();
}
#endif
return 0;
}
int CCameraHelper::Start(int epx_time)
{
return this->pfuccamera_start(epx_time);
}
int CCameraHelper::Stop()
{
return this->pfuccamera_stop();
}
int CCameraHelper::Cap(void** data, int& w, int& h, int timeout)
{
return this->pfuccamera_cap(data, w, h, timeout);
}
#ifndef _WIN32
#endif