2016-08-26 09:31:42 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
|
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-11-05 22:11:55 -07:00
|
|
|
#include "edu_wpi_cscore_CameraServerJNI.h"
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-18 01:13:15 -08:00
|
|
|
#include "llvm/raw_ostream.h"
|
2016-08-26 09:31:42 -07:00
|
|
|
#include "llvm/SmallString.h"
|
2016-08-28 21:20:40 -07:00
|
|
|
#include "support/jni_util.h"
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-05 22:11:55 -07:00
|
|
|
#include "cscore_cpp.h"
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-08-28 21:20:40 -07:00
|
|
|
using namespace wpi::java;
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
//
|
|
|
|
|
// Globals and load/unload
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Used for callback.
|
|
|
|
|
static JavaVM *jvm = nullptr;
|
2016-12-17 23:50:50 -08:00
|
|
|
static JClass usbCameraInfoCls;
|
|
|
|
|
static JClass videoModeCls;
|
|
|
|
|
static JClass videoEventCls;
|
|
|
|
|
static JException videoEx;
|
|
|
|
|
static JException nullPointerEx;
|
2016-11-05 13:13:09 -07:00
|
|
|
// Thread-attached environment for listener callbacks.
|
|
|
|
|
static JNIEnv *listenerEnv = nullptr;
|
|
|
|
|
|
|
|
|
|
static void ListenerOnStart() {
|
|
|
|
|
if (!jvm) return;
|
|
|
|
|
JNIEnv *env;
|
|
|
|
|
JavaVMAttachArgs args;
|
|
|
|
|
args.version = JNI_VERSION_1_2;
|
|
|
|
|
args.name = const_cast<char*>("CSListener");
|
|
|
|
|
args.group = nullptr;
|
|
|
|
|
if (jvm->AttachCurrentThreadAsDaemon(reinterpret_cast<void **>(&env),
|
|
|
|
|
&args) != JNI_OK)
|
|
|
|
|
return;
|
|
|
|
|
if (!env || !env->functions) return;
|
|
|
|
|
listenerEnv = env;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ListenerOnExit() {
|
|
|
|
|
listenerEnv = nullptr;
|
|
|
|
|
if (!jvm) return;
|
|
|
|
|
jvm->DetachCurrentThread();
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
|
|
|
jvm = vm;
|
|
|
|
|
|
|
|
|
|
JNIEnv *env;
|
|
|
|
|
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
|
|
|
|
|
return JNI_ERR;
|
|
|
|
|
|
2016-08-26 10:46:10 -07:00
|
|
|
// Cache references to classes
|
2016-12-17 23:50:50 -08:00
|
|
|
usbCameraInfoCls = JClass{env, "edu/wpi/cscore/UsbCameraInfo"};
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!usbCameraInfoCls) return JNI_ERR;
|
|
|
|
|
|
2016-12-17 23:50:50 -08:00
|
|
|
videoModeCls = JClass{env, "edu/wpi/cscore/VideoMode"};
|
2016-09-29 00:04:16 -07:00
|
|
|
if (!videoModeCls) return JNI_ERR;
|
|
|
|
|
|
2016-12-17 23:50:50 -08:00
|
|
|
videoEventCls = JClass{env, "edu/wpi/cscore/VideoEvent"};
|
2016-11-05 13:13:09 -07:00
|
|
|
if (!videoEventCls) return JNI_ERR;
|
|
|
|
|
|
2016-12-17 23:50:50 -08:00
|
|
|
videoEx = JException{env, "edu/wpi/cscore/VideoException"};
|
|
|
|
|
if (!videoEx) return JNI_ERR;
|
|
|
|
|
|
|
|
|
|
nullPointerEx = JException(env, "java/lang/NullPointerException");
|
|
|
|
|
if (!nullPointerEx) return JNI_ERR;
|
2016-11-18 01:13:15 -08:00
|
|
|
|
2016-11-05 13:13:09 -07:00
|
|
|
// Initial configuration of listener start/exit
|
|
|
|
|
cs::SetListenerOnStart(ListenerOnStart);
|
|
|
|
|
cs::SetListenerOnExit(ListenerOnExit);
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
return JNI_VERSION_1_6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
|
|
|
|
|
JNIEnv *env;
|
|
|
|
|
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
|
|
|
|
|
return;
|
2016-08-26 10:46:10 -07:00
|
|
|
// Delete global references
|
2016-12-17 23:50:50 -08:00
|
|
|
usbCameraInfoCls.free(env);
|
|
|
|
|
videoModeCls.free(env);
|
|
|
|
|
videoEventCls.free(env);
|
|
|
|
|
videoEx.free(env);
|
|
|
|
|
nullPointerEx.free(env);
|
2016-08-26 09:31:42 -07:00
|
|
|
jvm = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
|
2016-11-05 13:13:09 -07:00
|
|
|
//
|
|
|
|
|
// Helper class to create and clean up a global reference
|
|
|
|
|
//
|
|
|
|
|
template <typename T>
|
|
|
|
|
class JGlobal {
|
|
|
|
|
public:
|
|
|
|
|
JGlobal(JNIEnv *env, T obj)
|
|
|
|
|
: m_obj(static_cast<T>(env->NewGlobalRef(obj))) {}
|
|
|
|
|
~JGlobal() {
|
|
|
|
|
if (!jvm || cs::NotifierDestroyed()) return;
|
|
|
|
|
JNIEnv *env;
|
|
|
|
|
bool attached = false;
|
|
|
|
|
// don't attach and de-attach if already attached to a thread.
|
|
|
|
|
if (jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) ==
|
|
|
|
|
JNI_EDETACHED) {
|
|
|
|
|
if (jvm->AttachCurrentThread(reinterpret_cast<void **>(&env), nullptr) !=
|
|
|
|
|
JNI_OK)
|
|
|
|
|
return;
|
|
|
|
|
attached = true;
|
|
|
|
|
}
|
|
|
|
|
if (!env || !env->functions) return;
|
|
|
|
|
env->DeleteGlobalRef(m_obj);
|
|
|
|
|
if (attached) jvm->DetachCurrentThread();
|
|
|
|
|
}
|
|
|
|
|
operator T() { return m_obj; }
|
|
|
|
|
T obj() { return m_obj; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
T m_obj;
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-18 01:13:15 -08:00
|
|
|
static void ReportError(JNIEnv *env, CS_Status status) {
|
|
|
|
|
if (status == CS_OK) return;
|
|
|
|
|
llvm::SmallString<64> msg;
|
|
|
|
|
switch (status) {
|
|
|
|
|
case CS_PROPERTY_WRITE_FAILED:
|
|
|
|
|
msg = "property write failed";
|
|
|
|
|
break;
|
|
|
|
|
case CS_INVALID_HANDLE:
|
|
|
|
|
msg = "invalid handle";
|
|
|
|
|
break;
|
|
|
|
|
case CS_WRONG_HANDLE_SUBTYPE:
|
|
|
|
|
msg = "wrong handle subtype";
|
|
|
|
|
break;
|
|
|
|
|
case CS_INVALID_PROPERTY:
|
|
|
|
|
msg = "invalid property";
|
|
|
|
|
break;
|
|
|
|
|
case CS_WRONG_PROPERTY_TYPE:
|
|
|
|
|
msg = "wrong property type";
|
|
|
|
|
break;
|
|
|
|
|
case CS_READ_FAILED:
|
|
|
|
|
msg = "read failed";
|
|
|
|
|
break;
|
|
|
|
|
case CS_SOURCE_IS_DISCONNECTED:
|
|
|
|
|
msg = "source is disconnected";
|
|
|
|
|
break;
|
|
|
|
|
default: {
|
|
|
|
|
llvm::raw_svector_ostream oss{msg};
|
|
|
|
|
oss << "unknown error code=" << status;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 23:50:50 -08:00
|
|
|
videoEx.Throw(env, msg);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-18 01:13:15 -08:00
|
|
|
static inline bool CheckStatus(JNIEnv *env, CS_Status status) {
|
|
|
|
|
if (status != CS_OK) ReportError(env, status);
|
|
|
|
|
return status == CS_OK;
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
|
|
|
|
|
2016-12-04 00:08:47 -08:00
|
|
|
static jobject MakeJObject(JNIEnv *env, const cs::UsbCameraInfo &info) {
|
2016-08-26 10:46:10 -07:00
|
|
|
static jmethodID constructor = env->GetMethodID(
|
2016-09-18 14:14:35 -07:00
|
|
|
usbCameraInfoCls, "<init>", "(ILjava/lang/String;Ljava/lang/String;)V");
|
2016-08-28 21:20:40 -07:00
|
|
|
JLocal<jstring> path(env, MakeJString(env, info.path));
|
|
|
|
|
JLocal<jstring> name(env, MakeJString(env, info.name));
|
2016-08-26 10:46:10 -07:00
|
|
|
return env->NewObject(usbCameraInfoCls, constructor,
|
2016-09-18 14:14:35 -07:00
|
|
|
static_cast<jint>(info.dev), path.obj(), name.obj());
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-29 00:04:16 -07:00
|
|
|
static jobject MakeJObject(JNIEnv *env, const cs::VideoMode &videoMode) {
|
|
|
|
|
static jmethodID constructor =
|
|
|
|
|
env->GetMethodID(videoModeCls, "<init>", "(IIII)V");
|
|
|
|
|
return env->NewObject(
|
|
|
|
|
videoModeCls, constructor, static_cast<jint>(videoMode.pixelFormat),
|
|
|
|
|
static_cast<jint>(videoMode.width), static_cast<jint>(videoMode.height),
|
|
|
|
|
static_cast<jint>(videoMode.fps));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 13:13:09 -07:00
|
|
|
static jobject MakeJObject(JNIEnv *env, const cs::RawEvent &event) {
|
|
|
|
|
static jmethodID constructor =
|
|
|
|
|
env->GetMethodID(videoEventCls, "<init>",
|
|
|
|
|
"(IIILjava/lang/String;IIIIIIILjava/lang/String;)V");
|
|
|
|
|
JLocal<jstring> name(env, MakeJString(env, event.name));
|
|
|
|
|
JLocal<jstring> valueStr(env, MakeJString(env, event.valueStr));
|
|
|
|
|
return env->NewObject(
|
|
|
|
|
videoEventCls,
|
|
|
|
|
constructor,
|
2016-11-15 23:54:50 -08:00
|
|
|
static_cast<jint>(event.kind),
|
2016-11-05 13:13:09 -07:00
|
|
|
static_cast<jint>(event.sourceHandle),
|
|
|
|
|
static_cast<jint>(event.sinkHandle),
|
|
|
|
|
name.obj(),
|
|
|
|
|
static_cast<jint>(event.mode.pixelFormat),
|
|
|
|
|
static_cast<jint>(event.mode.width),
|
|
|
|
|
static_cast<jint>(event.mode.height),
|
|
|
|
|
static_cast<jint>(event.mode.fps),
|
|
|
|
|
static_cast<jint>(event.propertyHandle),
|
2016-11-15 23:54:50 -08:00
|
|
|
static_cast<jint>(event.propertyKind),
|
2016-11-05 13:13:09 -07:00
|
|
|
static_cast<jint>(event.value),
|
|
|
|
|
valueStr.obj());
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-11-15 23:54:50 -08:00
|
|
|
* Method: getPropertyKind
|
2016-08-26 09:31:42 -07:00
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-11-15 23:54:50 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyKind
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-11-15 23:54:50 -08:00
|
|
|
auto val = cs::GetPropertyKind(property, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getPropertyName
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyName
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetPropertyName(property, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-20 22:17:12 -07:00
|
|
|
* Method: getProperty
|
|
|
|
|
* Signature: (I)I
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getProperty
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-20 22:17:12 -07:00
|
|
|
auto val = cs::GetProperty(property, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-20 22:17:12 -07:00
|
|
|
* Method: setProperty
|
|
|
|
|
* Signature: (II)V
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setProperty
|
2016-09-20 22:17:12 -07:00
|
|
|
(JNIEnv *env, jclass, jint property, jint value)
|
2016-08-26 10:46:10 -07:00
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-20 22:17:12 -07:00
|
|
|
cs::SetProperty(property, value, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-16 21:00:19 -07:00
|
|
|
* Method: getPropertyMin
|
2016-09-20 22:17:12 -07:00
|
|
|
* Signature: (I)I
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyMin
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-16 21:00:19 -07:00
|
|
|
auto val = cs::GetPropertyMin(property, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-16 21:00:19 -07:00
|
|
|
* Method: getPropertyMax
|
2016-09-20 22:17:12 -07:00
|
|
|
* Signature: (I)I
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyMax
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-16 21:00:19 -07:00
|
|
|
auto val = cs::GetPropertyMax(property, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-16 21:00:19 -07:00
|
|
|
* Method: getPropertyStep
|
2016-09-20 22:17:12 -07:00
|
|
|
* Signature: (I)I
|
2016-09-16 21:00:19 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyStep
|
2016-09-16 21:00:19 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-16 21:00:19 -07:00
|
|
|
auto val = cs::GetPropertyStep(property, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-16 21:00:19 -07:00
|
|
|
* Method: getPropertyDefault
|
2016-09-20 22:17:12 -07:00
|
|
|
* Signature: (I)I
|
2016-09-16 21:00:19 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getPropertyDefault
|
2016-09-16 21:00:19 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-16 21:00:19 -07:00
|
|
|
auto val = cs::GetPropertyDefault(property, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getStringProperty
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getStringProperty
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetStringProperty(property, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: setStringProperty
|
|
|
|
|
* Signature: (ILjava/lang/String;)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setStringProperty
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property, jstring value)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!value) {
|
|
|
|
|
nullPointerEx.Throw(env, "value cannot be null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-28 21:20:40 -07:00
|
|
|
cs::SetStringProperty(property, JStringRef{env, value}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getEnumPropertyChoices
|
|
|
|
|
* Signature: (I)[Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_getEnumPropertyChoices
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint property)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
auto arr = cs::GetEnumPropertyChoices(property, &status);
|
|
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJStringArray(env, arr);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: createUsbCameraDev
|
2016-08-26 09:31:42 -07:00
|
|
|
* Signature: (Ljava/lang/String;I)I
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jstring name, jint dev)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto val = cs::CreateUsbCameraDev(JStringRef{env, name}, dev, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: createUsbCameraPath
|
2016-08-26 09:31:42 -07:00
|
|
|
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jstring name, jstring path)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!path) {
|
|
|
|
|
nullPointerEx.Throw(env, "path cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto val = cs::CreateUsbCameraPath(JStringRef{env, name},
|
2016-08-28 21:20:40 -07:00
|
|
|
JStringRef{env, path}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-10-15 23:07:28 -07:00
|
|
|
* Method: createHTTPCamera
|
2016-08-26 09:31:42 -07:00
|
|
|
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jstring name, jstring url)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!url) {
|
|
|
|
|
nullPointerEx.Throw(env, "url cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto val = cs::CreateHttpCamera(JStringRef{env, name},
|
2016-08-28 21:20:40 -07:00
|
|
|
JStringRef{env, url}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: createCvSource
|
2016-09-29 00:04:16 -07:00
|
|
|
* Signature: (Ljava/lang/String;IIII)I
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createCvSource
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jstring name, jint pixelFormat, jint width, jint height,
|
|
|
|
|
jint fps)
|
2016-08-26 10:46:10 -07:00
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto val = cs::CreateCvSource(
|
|
|
|
|
JStringRef{env, name},
|
|
|
|
|
cs::VideoMode{static_cast<cs::VideoMode::PixelFormat>(pixelFormat),
|
|
|
|
|
static_cast<int>(width), static_cast<int>(height),
|
|
|
|
|
static_cast<int>(fps)},
|
|
|
|
|
&status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-15 22:18:32 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-11-15 23:54:50 -08:00
|
|
|
* Method: getSourceKind
|
2016-11-15 22:18:32 -08:00
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-11-15 23:54:50 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceKind
|
2016-11-15 22:18:32 -08:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
|
|
|
|
CS_Status status = 0;
|
2016-11-15 23:54:50 -08:00
|
|
|
auto val = cs::GetSourceKind(source, &status);
|
2016-11-15 22:18:32 -08:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSourceName
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceName
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetSourceName(source, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSourceDescription
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceDescription
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetSourceDescription(source, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSourceLastFrameTime
|
|
|
|
|
* Signature: (I)J
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jlong JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceLastFrameTime
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
auto val = cs::GetSourceLastFrameTime(source, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: isSourceConnected
|
|
|
|
|
* Signature: (I)Z
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_cscore_CameraServerJNI_isSourceConnected
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
auto val = cs::IsSourceConnected(source, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSourceProperty
|
|
|
|
|
* Signature: (ILjava/lang/String;)I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceProperty
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jstring name)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-28 21:20:40 -07:00
|
|
|
auto val = cs::GetSourceProperty(source, JStringRef{env, name}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: enumerateSourceProperties
|
|
|
|
|
* Signature: (I)[I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jintArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceProperties
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallVector<CS_Property, 32> buf;
|
|
|
|
|
auto arr = cs::EnumerateSourceProperties(source, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJIntArray(env, arr);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-09-29 00:04:16 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-29 00:04:16 -07:00
|
|
|
* Method: getSourceVideoMode
|
|
|
|
|
* Signature: (I)Ledu/wpi/cameraserver/VideoMode;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jobject JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSourceVideoMode
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto val = cs::GetSourceVideoMode(source, &status);
|
|
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
|
|
|
|
return MakeJObject(env, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-29 00:04:16 -07:00
|
|
|
* Method: setSourceVideoMode
|
|
|
|
|
* Signature: (IIIII)Z
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceVideoMode
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jint pixelFormat, jint width, jint height,
|
|
|
|
|
jint fps)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto val = cs::SetSourceVideoMode(
|
|
|
|
|
source,
|
|
|
|
|
cs::VideoMode(static_cast<cs::VideoMode::PixelFormat>(pixelFormat), width,
|
|
|
|
|
height, fps),
|
|
|
|
|
&status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-29 00:04:16 -07:00
|
|
|
* Method: setSourcePixelFormat
|
|
|
|
|
* Signature: (II)Z
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourcePixelFormat
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jint pixelFormat)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto val = cs::SetSourcePixelFormat(
|
|
|
|
|
source, static_cast<cs::VideoMode::PixelFormat>(pixelFormat), &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-29 00:04:16 -07:00
|
|
|
* Method: setSourceResolution
|
|
|
|
|
* Signature: (III)Z
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceResolution
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jint width, jint height)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto val = cs::SetSourceResolution(source, width, height, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-29 00:04:16 -07:00
|
|
|
* Method: setSourceFPS
|
|
|
|
|
* Signature: (II)Z
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceFPS
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jint fps)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto val = cs::SetSourceFPS(source, fps, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-09-29 00:04:16 -07:00
|
|
|
* Method: enumerateSourceVideoModes
|
|
|
|
|
* Signature: (I)[Ledu/wpi/cameraserver/VideoMode;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceVideoModes
|
2016-09-29 00:04:16 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-29 00:04:16 -07:00
|
|
|
auto arr = cs::EnumerateSourceVideoModes(source, &status);
|
|
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
|
|
|
|
jobjectArray jarr =
|
|
|
|
|
env->NewObjectArray(arr.size(), videoModeCls, nullptr);
|
|
|
|
|
if (!jarr) return nullptr;
|
|
|
|
|
for (size_t i = 0; i < arr.size(); ++i) {
|
|
|
|
|
JLocal<jobject> jelem{env, MakeJObject(env, arr[i])};
|
|
|
|
|
env->SetObjectArrayElement(jarr, i, jelem);
|
|
|
|
|
}
|
|
|
|
|
return jarr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 22:18:32 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
|
|
|
|
* Method: enumerateSourceSinks
|
|
|
|
|
* Signature: (I)[I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jintArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceSinks
|
|
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
|
|
|
|
CS_Status status = 0;
|
|
|
|
|
llvm::SmallVector<CS_Sink, 16> buf;
|
|
|
|
|
auto arr = cs::EnumerateSourceSinks(source, buf, &status);
|
|
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
|
|
|
|
return MakeJIntArray(env, arr);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: copySource
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_copySource
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
auto val = cs::CopySource(source, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: releaseSource
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_releaseSource
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
cs::ReleaseSource(source, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-19 19:02:20 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: getUsbCameraPath
|
2016-11-19 19:02:20 -08:00
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraPath
|
2016-11-19 19:02:20 -08:00
|
|
|
(JNIEnv *env, jclass, jint source)
|
|
|
|
|
{
|
|
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto str = cs::GetUsbCameraPath(source, &status);
|
2016-11-19 19:02:20 -08:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
|
|
|
|
return MakeJString(env, str);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 14:50:24 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-10-21 14:50:24 -07:00
|
|
|
* Method: putSourceFrame
|
|
|
|
|
* Signature: (IJ)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_putSourceFrame
|
2016-10-21 14:50:24 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jlong imageNativeObj)
|
|
|
|
|
{
|
|
|
|
|
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-10-21 14:50:24 -07:00
|
|
|
cs::PutSourceFrame(source, image, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: notifySourceError
|
|
|
|
|
* Signature: (ILjava/lang/String;)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_notifySourceError
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jstring msg)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!msg) {
|
|
|
|
|
nullPointerEx.Throw(env, "msg cannot be null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-28 21:20:40 -07:00
|
|
|
cs::NotifySourceError(source, JStringRef{env, msg}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: setSourceConnected
|
|
|
|
|
* Signature: (IZ)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceConnected
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jboolean connected)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
cs::SetSourceConnected(source, connected, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-10-23 08:43:06 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-10-23 08:43:06 -07:00
|
|
|
* Method: setSourceDescription
|
|
|
|
|
* Signature: (ILjava/lang/String;)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceDescription
|
2016-10-23 08:43:06 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jstring description)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!description) {
|
|
|
|
|
nullPointerEx.Throw(env, "description cannot be null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-23 08:43:06 -07:00
|
|
|
CS_Status status = 0;
|
|
|
|
|
cs::SetSourceDescription(source, JStringRef{env, description}, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: createSourceProperty
|
2016-10-23 08:43:06 -07:00
|
|
|
* Signature: (ILjava/lang/String;IIIIII)I
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createSourceProperty
|
2016-11-15 23:54:50 -08:00
|
|
|
(JNIEnv *env, jclass, jint source, jstring name, jint kind, jint minimum, jint maximum, jint step, jint defaultValue, jint value)
|
2016-08-26 10:46:10 -07:00
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-10-23 08:43:06 -07:00
|
|
|
auto val = cs::CreateSourceProperty(
|
2016-11-15 23:54:50 -08:00
|
|
|
source, JStringRef{env, name}, static_cast<CS_PropertyKind>(kind),
|
2016-10-23 08:43:06 -07:00
|
|
|
minimum, maximum, step, defaultValue, value, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-10-23 08:43:06 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-10-23 08:43:06 -07:00
|
|
|
* Method: setSourceEnumPropertyChoices
|
|
|
|
|
* Signature: (II[Ljava/lang/String;)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceEnumPropertyChoices
|
2016-10-23 08:43:06 -07:00
|
|
|
(JNIEnv *env, jclass, jint source, jint property, jobjectArray choices)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!choices) {
|
|
|
|
|
nullPointerEx.Throw(env, "choices cannot be null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-23 08:43:06 -07:00
|
|
|
size_t len = env->GetArrayLength(choices);
|
|
|
|
|
llvm::SmallVector<std::string, 8> vec;
|
|
|
|
|
vec.reserve(len);
|
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
|
JLocal<jstring> elem{
|
|
|
|
|
env, static_cast<jstring>(env->GetObjectArrayElement(choices, i))};
|
|
|
|
|
if (!elem) {
|
|
|
|
|
// TODO
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
vec.push_back(JStringRef{env, elem}.str());
|
|
|
|
|
}
|
|
|
|
|
CS_Status status = 0;
|
|
|
|
|
cs::SetSourceEnumPropertyChoices(source, property, vec, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: createMjpegServer
|
2016-08-26 09:31:42 -07:00
|
|
|
* Signature: (Ljava/lang/String;Ljava/lang/String;I)I
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createMjpegServer
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jstring name, jstring listenAddress, jint port)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!listenAddress) {
|
|
|
|
|
nullPointerEx.Throw(env, "listenAddress cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto val = cs::CreateMjpegServer(
|
2016-10-15 22:44:26 -07:00
|
|
|
JStringRef{env, name}, JStringRef{env, listenAddress}, port, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: createCvSink
|
|
|
|
|
* Signature: (Ljava/lang/String;)I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createCvSink
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jstring name)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-28 21:20:40 -07:00
|
|
|
auto val = cs::CreateCvSink(JStringRef{env, name}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-15 22:18:32 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-11-15 23:54:50 -08:00
|
|
|
* Method: getSinkKind
|
2016-11-15 22:18:32 -08:00
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-11-15 23:54:50 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkKind
|
2016-11-15 22:18:32 -08:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
|
|
|
|
CS_Status status = 0;
|
2016-11-15 23:54:50 -08:00
|
|
|
auto val = cs::GetSinkKind(sink, &status);
|
2016-11-15 22:18:32 -08:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSinkName
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkName
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetSinkName(sink, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSinkDescription
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkDescription
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetSinkDescription(sink, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: setSinkSource
|
|
|
|
|
* Signature: (II)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSinkSource
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink, jint source)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
cs::SetSinkSource(sink, source, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSinkSourceProperty
|
|
|
|
|
* Signature: (ILjava/lang/String;)I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkSourceProperty
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink, jstring name)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!name) {
|
|
|
|
|
nullPointerEx.Throw(env, "name cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-28 21:20:40 -07:00
|
|
|
auto val = cs::GetSinkSourceProperty(sink, JStringRef{env, name}, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSinkSource
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkSource
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
auto val = cs::GetSinkSource(sink, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: copySink
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_copySink
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
auto val = cs::CopySink(sink, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: releaseSink
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_releaseSink
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
cs::ReleaseSink(sink, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-19 19:02:20 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: getMjpegServerListenAddress
|
2016-11-19 19:02:20 -08:00
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerListenAddress
|
2016-11-19 19:02:20 -08:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
|
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto str = cs::GetMjpegServerListenAddress(sink, &status);
|
2016-11-19 19:02:20 -08:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
|
|
|
|
return MakeJString(env, str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: getMjpegServerPort
|
2016-11-19 19:02:20 -08:00
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerPort
|
2016-11-19 19:02:20 -08:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
|
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto val = cs::GetMjpegServerPort(sink, &status);
|
2016-11-19 19:02:20 -08:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 23:37:00 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-10-26 23:37:00 -07:00
|
|
|
* Method: setSinkDescription
|
|
|
|
|
* Signature: (ILjava/lang/String;)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSinkDescription
|
2016-10-26 23:37:00 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink, jstring description)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!description) {
|
|
|
|
|
nullPointerEx.Throw(env, "description cannot be null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-26 23:37:00 -07:00
|
|
|
CS_Status status = 0;
|
|
|
|
|
cs::SetSinkDescription(sink, JStringRef{env, description}, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 14:50:24 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-10-21 14:50:24 -07:00
|
|
|
* Method: grabSinkFrame
|
|
|
|
|
* Signature: (IJ)J
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jlong JNICALL Java_edu_wpi_cscore_CameraServerJNI_grabSinkFrame
|
2016-10-21 14:50:24 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink, jlong imageNativeObj)
|
|
|
|
|
{
|
|
|
|
|
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-10-21 14:50:24 -07:00
|
|
|
auto rv = cs::GrabSinkFrame(sink, image, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: getSinkError
|
|
|
|
|
* Signature: (I)Ljava/lang/String;
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getSinkError
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
auto str = cs::GetSinkError(sink, buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJString(env, str);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: setSinkEnabled
|
|
|
|
|
* Signature: (IZ)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSinkEnabled
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint sink, jboolean enabled)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-08-26 10:46:10 -07:00
|
|
|
cs::SetSinkEnabled(sink, enabled, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-05 13:13:09 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-11-05 13:13:09 -07:00
|
|
|
* Method: addListener
|
2016-11-13 17:02:38 -08:00
|
|
|
* Signature: (Ljava/util/function/Consumer;IZ)I
|
2016-11-05 13:13:09 -07:00
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_addListener
|
2016-11-05 13:13:09 -07:00
|
|
|
(JNIEnv *envouter, jclass, jobject listener, jint eventMask, jboolean immediateNotify)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!listener) {
|
|
|
|
|
nullPointerEx.Throw(envouter, "listener cannot be null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-11-05 13:13:09 -07:00
|
|
|
// the shared pointer to the weak global will keep it around until the
|
|
|
|
|
// entry listener is destroyed
|
|
|
|
|
auto listener_global =
|
|
|
|
|
std::make_shared<JGlobal<jobject>>(envouter, listener);
|
|
|
|
|
|
|
|
|
|
// cls is a temporary here; cannot be used within callback functor
|
|
|
|
|
jclass cls = envouter->GetObjectClass(listener);
|
|
|
|
|
if (!cls) return 0;
|
|
|
|
|
|
|
|
|
|
// method ids, on the other hand, are safe to retain
|
2016-11-13 17:02:38 -08:00
|
|
|
jmethodID mid = envouter->GetMethodID(cls, "accept", "(Ljava/lang/Object;)V");
|
2016-11-05 13:13:09 -07:00
|
|
|
if (!mid) return 0;
|
|
|
|
|
|
|
|
|
|
CS_Status status = 0;
|
|
|
|
|
CS_Listener handle = cs::AddListener(
|
|
|
|
|
[=](const cs::RawEvent &event) {
|
|
|
|
|
JNIEnv *env = listenerEnv;
|
|
|
|
|
if (!env || !env->functions) return;
|
|
|
|
|
|
|
|
|
|
// get the handler
|
|
|
|
|
auto handler = listener_global->obj();
|
|
|
|
|
|
|
|
|
|
// convert into the appropriate Java type
|
|
|
|
|
JLocal<jobject> jobj{env, MakeJObject(env, event)};
|
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
|
env->ExceptionClear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!jobj) return;
|
|
|
|
|
|
|
|
|
|
env->CallVoidMethod(handler, mid, jobj.obj());
|
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
|
env->ExceptionClear();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
eventMask, immediateNotify != JNI_FALSE, &status);
|
|
|
|
|
CheckStatus(envouter, status);
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-11-04 12:46:22 -07:00
|
|
|
* Method: removeListener
|
2016-08-26 09:31:42 -07:00
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_removeListener
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass, jint handle)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-11-04 12:46:22 -07:00
|
|
|
cs::RemoveListener(handle, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-12-04 00:08:47 -08:00
|
|
|
* Method: enumerateUsbCameras
|
|
|
|
|
* Signature: ()[Ledu/wpi/cameraserver/UsbCameraInfo;
|
2016-08-26 09:31:42 -07:00
|
|
|
*/
|
2016-12-04 00:08:47 -08:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateUsbCameras
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-12-04 00:08:47 -08:00
|
|
|
auto arr = cs::EnumerateUsbCameras(&status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
|
|
|
|
jobjectArray jarr =
|
|
|
|
|
env->NewObjectArray(arr.size(), usbCameraInfoCls, nullptr);
|
|
|
|
|
if (!jarr) return nullptr;
|
|
|
|
|
for (size_t i = 0; i < arr.size(); ++i) {
|
2016-08-28 21:20:40 -07:00
|
|
|
JLocal<jobject> jelem{env, MakeJObject(env, arr[i])};
|
2016-08-26 10:46:10 -07:00
|
|
|
env->SetObjectArrayElement(jarr, i, jelem);
|
|
|
|
|
}
|
|
|
|
|
return jarr;
|
|
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: enumerateSources
|
|
|
|
|
* Signature: ()[I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jintArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateSources
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallVector<CS_Source, 16> buf;
|
|
|
|
|
auto arr = cs::EnumerateSourceHandles(buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJIntArray(env, arr);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
|
|
|
|
/*
|
2016-11-06 19:28:14 -08:00
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
2016-08-26 09:31:42 -07:00
|
|
|
* Method: enumerateSinks
|
|
|
|
|
* Signature: ()[I
|
|
|
|
|
*/
|
2016-11-06 19:28:14 -08:00
|
|
|
JNIEXPORT jintArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateSinks
|
2016-08-26 10:46:10 -07:00
|
|
|
(JNIEnv *env, jclass)
|
|
|
|
|
{
|
2016-10-21 14:52:21 -07:00
|
|
|
CS_Status status = 0;
|
2016-09-10 21:30:39 -07:00
|
|
|
llvm::SmallVector<CS_Sink, 16> buf;
|
|
|
|
|
auto arr = cs::EnumerateSinkHandles(buf, &status);
|
2016-08-26 10:46:10 -07:00
|
|
|
if (!CheckStatus(env, status)) return nullptr;
|
2016-08-28 21:20:40 -07:00
|
|
|
return MakeJIntArray(env, arr);
|
2016-08-26 10:46:10 -07:00
|
|
|
}
|
2016-08-26 09:31:42 -07:00
|
|
|
|
2016-11-18 11:44:25 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
|
|
|
|
* Method: getHostname
|
|
|
|
|
* Signature: ()Ljava/lang/String;
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getHostname
|
|
|
|
|
(JNIEnv *env, jclass)
|
|
|
|
|
{
|
|
|
|
|
return MakeJString(env, cs::GetHostname());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
|
|
|
|
* Method: getNetworkInterfaces
|
|
|
|
|
* Signature: ()[Ljava/lang/String;
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_getNetworkInterfaces
|
|
|
|
|
(JNIEnv *env, jclass)
|
|
|
|
|
{
|
|
|
|
|
return MakeJStringArray(env, cs::GetNetworkInterfaces());
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 09:31:42 -07:00
|
|
|
} // extern "C"
|
2016-12-10 23:49:50 -08:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct LogMessage {
|
|
|
|
|
public:
|
|
|
|
|
LogMessage(unsigned int level, const char *file, unsigned int line,
|
|
|
|
|
const char *msg)
|
|
|
|
|
: m_level(level), m_file(file), m_line(line), m_msg(msg) {}
|
|
|
|
|
|
|
|
|
|
void CallJava(JNIEnv* env, jobject func, jmethodID mid) {
|
|
|
|
|
JLocal<jstring> file{env, MakeJString(env, m_file)};
|
|
|
|
|
JLocal<jstring> msg{env, MakeJString(env, m_msg)};
|
|
|
|
|
env->CallVoidMethod(func, mid, (jint)m_level, file.obj(),
|
|
|
|
|
(jint)m_line, msg.obj());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-17 23:50:50 -08:00
|
|
|
static const char* GetName() { return "CSLogger"; }
|
2016-12-10 23:49:50 -08:00
|
|
|
static JavaVM* GetJVM() { return jvm; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
unsigned int m_level;
|
|
|
|
|
const char* m_file;
|
|
|
|
|
unsigned int m_line;
|
|
|
|
|
std::string m_msg;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef JSingletonCallbackManager<LogMessage> LoggerJNI;
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
ATOMIC_STATIC_INIT(LoggerJNI)
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_cscore_CameraServerJNI
|
|
|
|
|
* Method: setLogger
|
|
|
|
|
* Signature: (Ledu/wpi/cscore/CameraServerJNI/LoggerFunction;I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setLogger
|
|
|
|
|
(JNIEnv *env, jclass, jobject func, jint minLevel)
|
|
|
|
|
{
|
2016-12-17 23:50:50 -08:00
|
|
|
if (!func) {
|
|
|
|
|
nullPointerEx.Throw(env, "func cannot be null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-10 23:49:50 -08:00
|
|
|
// cls is a temporary here; cannot be used within callback functor
|
|
|
|
|
jclass cls = env->GetObjectClass(func);
|
|
|
|
|
if (!cls) return;
|
|
|
|
|
|
|
|
|
|
// method ids, on the other hand, are safe to retain
|
|
|
|
|
jmethodID mid = env->GetMethodID(
|
|
|
|
|
cls, "apply", "(ILjava/lang/String;ILjava/lang/String;)V");
|
|
|
|
|
if (!mid) return;
|
|
|
|
|
|
|
|
|
|
auto& logger = LoggerJNI::GetInstance();
|
|
|
|
|
logger.Start();
|
|
|
|
|
logger.SetFunc(env, func, mid);
|
|
|
|
|
|
|
|
|
|
cs::SetLogger(
|
|
|
|
|
[](unsigned int level, const char *file, unsigned int line,
|
|
|
|
|
const char *msg) {
|
|
|
|
|
LoggerJNI::GetInstance().Send(level, file, line, msg);
|
|
|
|
|
},
|
|
|
|
|
minLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // extern "C"
|