2018-10-23 22:59:47 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-05-17 17:35:09 -07:00
|
|
|
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
2018-10-23 22:59:47 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "cscore_c.h" // NOLINT(build/include_order)
|
|
|
|
|
|
|
|
|
|
#include "c_util.h"
|
|
|
|
|
#include "cscore_cpp.h"
|
|
|
|
|
|
|
|
|
|
using namespace cs;
|
|
|
|
|
|
2018-12-30 11:48:18 -08:00
|
|
|
static void ConvertToC(CS_UsbCameraInfo* out, const UsbCameraInfo& in) {
|
|
|
|
|
out->dev = in.dev;
|
|
|
|
|
out->path = ConvertToC(in.path);
|
|
|
|
|
out->name = ConvertToC(in.name);
|
|
|
|
|
out->otherPaths = static_cast<char**>(
|
2019-04-27 20:33:08 -07:00
|
|
|
wpi::safe_malloc(in.otherPaths.size() * sizeof(char*)));
|
2018-12-30 11:48:18 -08:00
|
|
|
out->otherPathsCount = in.otherPaths.size();
|
|
|
|
|
for (size_t i = 0; i < in.otherPaths.size(); ++i)
|
|
|
|
|
out->otherPaths[i] = cs::ConvertToC(in.otherPaths[i]);
|
2019-10-20 14:12:00 -07:00
|
|
|
out->vendorId = in.vendorId;
|
|
|
|
|
out->productId = in.productId;
|
2018-12-30 11:48:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void FreeUsbCameraInfo(CS_UsbCameraInfo* info) {
|
|
|
|
|
std::free(info->path);
|
|
|
|
|
std::free(info->name);
|
|
|
|
|
for (int i = 0; i < info->otherPathsCount; ++i)
|
|
|
|
|
std::free(info->otherPaths[i]);
|
|
|
|
|
std::free(info->otherPaths);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 22:59:47 -07:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status) {
|
|
|
|
|
return cs::CreateUsbCameraDev(name, dev, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CS_Source CS_CreateUsbCameraPath(const char* name, const char* path,
|
|
|
|
|
CS_Status* status) {
|
|
|
|
|
return cs::CreateUsbCameraPath(name, path, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status) {
|
|
|
|
|
return ConvertToC(cs::GetUsbCameraPath(source, status));
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-30 11:48:18 -08:00
|
|
|
CS_UsbCameraInfo* CS_GetUsbCameraInfo(CS_Source source, CS_Status* status) {
|
|
|
|
|
auto info = cs::GetUsbCameraInfo(source, status);
|
|
|
|
|
if (*status != CS_OK) return nullptr;
|
|
|
|
|
CS_UsbCameraInfo* out = static_cast<CS_UsbCameraInfo*>(
|
2019-04-27 20:33:08 -07:00
|
|
|
wpi::safe_malloc(sizeof(CS_UsbCameraInfo)));
|
2018-12-30 11:48:18 -08:00
|
|
|
ConvertToC(out, info);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 22:59:47 -07:00
|
|
|
CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status) {
|
|
|
|
|
auto cameras = cs::EnumerateUsbCameras(status);
|
|
|
|
|
CS_UsbCameraInfo* out = static_cast<CS_UsbCameraInfo*>(
|
2019-04-27 20:33:08 -07:00
|
|
|
wpi::safe_malloc(cameras.size() * sizeof(CS_UsbCameraInfo)));
|
2018-10-23 22:59:47 -07:00
|
|
|
*count = cameras.size();
|
2018-12-30 11:48:18 -08:00
|
|
|
for (size_t i = 0; i < cameras.size(); ++i) ConvertToC(&out[i], cameras[i]);
|
2018-10-23 22:59:47 -07:00
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count) {
|
|
|
|
|
if (!cameras) return;
|
2018-12-30 11:48:18 -08:00
|
|
|
for (int i = 0; i < count; ++i) FreeUsbCameraInfo(&cameras[i]);
|
2018-10-23 22:59:47 -07:00
|
|
|
std::free(cameras);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-30 11:48:18 -08:00
|
|
|
void CS_FreeUsbCameraInfo(CS_UsbCameraInfo* info) {
|
|
|
|
|
if (!info) return;
|
|
|
|
|
FreeUsbCameraInfo(info);
|
|
|
|
|
std::free(info);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 22:59:47 -07:00
|
|
|
} // extern "C"
|