add hikvision camera
This commit is contained in:
parent
2eefd845f9
commit
a6f00ceb6c
@ -78,4 +78,24 @@ camera {
|
|||||||
sync: false
|
sync: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cameras {
|
||||||
|
id: "hikvision_cam"
|
||||||
|
hikvision {
|
||||||
|
ip: "192.168.1.64"
|
||||||
|
port: 8000
|
||||||
|
username: "admin"
|
||||||
|
password: "admin"
|
||||||
|
channel: 1
|
||||||
|
stream_type: 0
|
||||||
|
link_mode: 0
|
||||||
|
width: 1920
|
||||||
|
height: 1080
|
||||||
|
fps: 25
|
||||||
|
codec: "H264"
|
||||||
|
camera_mode: CAMERA_MODE_VIDEO
|
||||||
|
stream_mode: STREAM_MODE_RGB
|
||||||
|
buffer_size: 30
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ device_manager {
|
|||||||
id: "aubo_arm"
|
id: "aubo_arm"
|
||||||
type: DEVICE_TYPE_ROBOT_ARM
|
type: DEVICE_TYPE_ROBOT_ARM
|
||||||
config_file: "devices/arm/aubo_arm.pb.txt"
|
config_file: "devices/arm/aubo_arm.pb.txt"
|
||||||
enable: true
|
enable: false
|
||||||
}
|
}
|
||||||
|
|
||||||
devices {
|
devices {
|
||||||
@ -63,6 +63,14 @@ device_manager {
|
|||||||
id: "src1100"
|
id: "src1100"
|
||||||
type: DEVICE_TYPE_AGV
|
type: DEVICE_TYPE_AGV
|
||||||
config_file: "devices/agv/src1100.pb.txt"
|
config_file: "devices/agv/src1100.pb.txt"
|
||||||
enable: true
|
enable: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devices {
|
||||||
|
id: "hikvision_cam"
|
||||||
|
type: DEVICE_TYPE_CAMERA
|
||||||
|
config_file: "devices/camera/camera.pb.txt"
|
||||||
|
enable: true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,10 @@ target_link_libraries(hikvision_camera
|
|||||||
-lhcnetsdk
|
-lhcnetsdk
|
||||||
pthread
|
pthread
|
||||||
)
|
)
|
||||||
|
set_target_properties(hikvision_camera PROPERTIES
|
||||||
|
BUILD_RPATH "${HIKVISION_SDK_LIB_DIR};${HIKVISION_SDK_LIB_DIR}/HCNetSDKCom"
|
||||||
|
INSTALL_RPATH "$ORIGIN;$ORIGIN/HCNetSDKCom"
|
||||||
|
)
|
||||||
add_library(cmvr_es::device::hikvision_camera ALIAS hikvision_camera)
|
add_library(cmvr_es::device::hikvision_camera ALIAS hikvision_camera)
|
||||||
install(TARGETS hikvision_camera LIBRARY DESTINATION lib)
|
install(TARGETS hikvision_camera LIBRARY DESTINATION lib)
|
||||||
install(DIRECTORY "${HIKVISION_SDK_LIB_DIR}/HCNetSDKCom" DESTINATION lib)
|
install(DIRECTORY "${HIKVISION_SDK_LIB_DIR}/HCNetSDKCom" DESTINATION lib)
|
||||||
|
|||||||
@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "HCNetSDK.h"
|
#include "HCNetSDK.h"
|
||||||
#include "common/base/logging/logger.h"
|
#include "common/base/logging/logger.h"
|
||||||
|
|
||||||
#ifndef HIKVISION_SDK_LIB_DIR
|
|
||||||
#define HIKVISION_SDK_LIB_DIR ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::mutex g_sdk_mutex;
|
std::mutex g_sdk_mutex;
|
||||||
@ -28,6 +30,21 @@ std::string normalizeSdkPath(std::string path)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string defaultRuntimeSdkPath()
|
||||||
|
{
|
||||||
|
#if defined(__linux__)
|
||||||
|
char executable_path[PATH_MAX] = {0};
|
||||||
|
const ssize_t count = readlink("/proc/self/exe", executable_path, PATH_MAX - 1);
|
||||||
|
if (count > 0) {
|
||||||
|
executable_path[count] = '\0';
|
||||||
|
const auto lib_path =
|
||||||
|
std::filesystem::path(executable_path).parent_path() / ".." / "lib";
|
||||||
|
return normalizeSdkPath(std::filesystem::weakly_canonical(lib_path).string());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return normalizeSdkPath((std::filesystem::current_path() / ".." / "lib").string());
|
||||||
|
}
|
||||||
|
|
||||||
void copyCString(char* dest, size_t dest_size, const std::string& source)
|
void copyCString(char* dest, size_t dest_size, const std::string& source)
|
||||||
{
|
{
|
||||||
if (dest_size == 0) {
|
if (dest_size == 0) {
|
||||||
@ -67,7 +84,7 @@ HikvisionCamera::HikvisionCamera(const config::HikvisionCameraConfig& camera)
|
|||||||
buffer_size_ = camera_.buffer_size() > 0 ? static_cast<size_t>(camera_.buffer_size()) : 30;
|
buffer_size_ = camera_.buffer_size() > 0 ? static_cast<size_t>(camera_.buffer_size()) : 30;
|
||||||
codec_ = camera_.codec().empty() ? "H264" : camera_.codec();
|
codec_ = camera_.codec().empty() ? "H264" : camera_.codec();
|
||||||
sdk_path_ = normalizeSdkPath(
|
sdk_path_ = normalizeSdkPath(
|
||||||
camera_.sdk_path().empty() ? std::string(HIKVISION_SDK_LIB_DIR) : camera_.sdk_path());
|
camera_.sdk_path().empty() ? defaultRuntimeSdkPath() : camera_.sdk_path());
|
||||||
|
|
||||||
state_.fps = fps_;
|
state_.fps = fps_;
|
||||||
state_.width = width_;
|
state_.width = width_;
|
||||||
@ -328,19 +345,6 @@ bool HikvisionCamera::initSdk_()
|
|||||||
|
|
||||||
std::lock_guard<std::mutex> lock(g_sdk_mutex);
|
std::lock_guard<std::mutex> lock(g_sdk_mutex);
|
||||||
if (g_sdk_ref_count == 0) {
|
if (g_sdk_ref_count == 0) {
|
||||||
if (!sdk_path_.empty()) {
|
|
||||||
NET_DVR_LOCAL_SDK_PATH sdk_path_cfg{};
|
|
||||||
copyCString(sdk_path_cfg.sPath, sizeof(sdk_path_cfg.sPath), sdk_path_);
|
|
||||||
NET_DVR_SetSDKInitCfg(NET_SDK_INIT_CFG_SDK_PATH, &sdk_path_cfg);
|
|
||||||
|
|
||||||
const std::string crypto_path = sdk_path_ + "libcrypto.so.3";
|
|
||||||
const std::string ssl_path = sdk_path_ + "libssl.so.3";
|
|
||||||
NET_DVR_SetSDKInitCfg(
|
|
||||||
NET_SDK_INIT_CFG_LIBEAY_PATH, const_cast<char*>(crypto_path.c_str()));
|
|
||||||
NET_DVR_SetSDKInitCfg(
|
|
||||||
NET_SDK_INIT_CFG_SSLEAY_PATH, const_cast<char*>(ssl_path.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!NET_DVR_Init()) {
|
if (!NET_DVR_Init()) {
|
||||||
setError_(sdkError_("NET_DVR_Init"));
|
setError_(sdkError_("NET_DVR_Init"));
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue
Block a user