mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Start implementing HttpCamera.
This is a work in progress that does not yet support camera settings.
This commit is contained in:
@@ -152,6 +152,12 @@ static void ReportError(JNIEnv *env, CS_Status status) {
|
||||
case CS_SOURCE_IS_DISCONNECTED:
|
||||
msg = "source is disconnected";
|
||||
break;
|
||||
case CS_EMPTY_VALUE:
|
||||
msg = "empty value";
|
||||
break;
|
||||
case CS_BAD_URL:
|
||||
msg = "bad URL";
|
||||
break;
|
||||
default: {
|
||||
llvm::raw_svector_ostream oss{msg};
|
||||
oss << "unknown error code=" << status;
|
||||
@@ -410,11 +416,11 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: createHTTPCamera
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
|
||||
* Method: createHttpCamera
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera
|
||||
(JNIEnv *env, jclass, jstring name, jstring url)
|
||||
(JNIEnv *env, jclass, jstring name, jstring url, jint kind)
|
||||
{
|
||||
if (!name) {
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
@@ -425,8 +431,45 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera
|
||||
return 0;
|
||||
}
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateHttpCamera(JStringRef{env, name},
|
||||
JStringRef{env, url}, &status);
|
||||
auto val =
|
||||
cs::CreateHttpCamera(JStringRef{env, name}, JStringRef{env, url},
|
||||
static_cast<CS_HttpCameraKind>(kind), &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: createHttpCameraMulti
|
||||
* Signature: (Ljava/lang/String;[Ljava/lang/String;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createHttpCameraMulti
|
||||
(JNIEnv *env, jclass, jstring name, jobjectArray urls, jint kind)
|
||||
{
|
||||
if (!name) {
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
return 0;
|
||||
}
|
||||
if (!urls) {
|
||||
nullPointerEx.Throw(env, "urls cannot be null");
|
||||
return 0;
|
||||
}
|
||||
size_t len = env->GetArrayLength(urls);
|
||||
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(urls, i))};
|
||||
if (!elem) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
vec.push_back(JStringRef{env, elem}.str());
|
||||
}
|
||||
CS_Status status = 0;
|
||||
auto val =
|
||||
cs::CreateHttpCamera(JStringRef{env, name}, vec,
|
||||
static_cast<CS_HttpCameraKind>(kind), &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
@@ -713,6 +756,63 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraPath
|
||||
return MakeJString(env, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: getHttpCameraKind
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getHttpCameraKind
|
||||
(JNIEnv *env, jclass, jint source)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto kind = cs::GetHttpCameraKind(source, &status);
|
||||
if (!CheckStatus(env, status)) return 0;
|
||||
return kind;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: setHttpCameraUrls
|
||||
* Signature: (I[Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setHttpCameraUrls
|
||||
(JNIEnv *env, jclass, jint source, jobjectArray urls)
|
||||
{
|
||||
if (!urls) {
|
||||
nullPointerEx.Throw(env, "urls cannot be null");
|
||||
return;
|
||||
}
|
||||
size_t len = env->GetArrayLength(urls);
|
||||
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(urls, i))};
|
||||
if (!elem) {
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
vec.push_back(JStringRef{env, elem}.str());
|
||||
}
|
||||
CS_Status status = 0;
|
||||
cs::SetHttpCameraUrls(source, vec, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: getHttpCameraUrls
|
||||
* Signature: (I)[Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_getHttpCameraUrls
|
||||
(JNIEnv *env, jclass, jint source)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto arr = cs::GetHttpCameraUrls(source, &status);
|
||||
if (!CheckStatus(env, status)) return nullptr;
|
||||
return MakeJStringArray(env, arr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: putSourceFrame
|
||||
|
||||
@@ -104,7 +104,8 @@ public class CameraServerJNI {
|
||||
//
|
||||
public static native int createUsbCameraDev(String name, int dev);
|
||||
public static native int createUsbCameraPath(String name, String path);
|
||||
public static native int createHttpCamera(String name, String url);
|
||||
public static native int createHttpCamera(String name, String url, int kind);
|
||||
public static native int createHttpCameraMulti(String name, String[] urls, int kind);
|
||||
public static native int createCvSource(String name, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
//
|
||||
@@ -132,6 +133,13 @@ public class CameraServerJNI {
|
||||
//
|
||||
public static native String getUsbCameraPath(int source);
|
||||
|
||||
//
|
||||
// HttpCamera Source Functions
|
||||
//
|
||||
public static native int getHttpCameraKind(int source);
|
||||
public static native void setHttpCameraUrls(int source, String[] urls);
|
||||
public static native String[] getHttpCameraUrls(int source);
|
||||
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
//
|
||||
|
||||
@@ -9,10 +9,72 @@ package edu.wpi.cscore;
|
||||
|
||||
/// A source that represents a MJPEG-over-HTTP (IP) camera.
|
||||
public class HttpCamera extends VideoSource {
|
||||
public enum CameraKind {
|
||||
kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
|
||||
private int value;
|
||||
|
||||
private CameraKind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static CameraKind getCameraKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 1: return CameraKind.kMJPGStreamer;
|
||||
case 2: return CameraKind.kCSCore;
|
||||
case 3: return CameraKind.kAxis;
|
||||
default: return CameraKind.kUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
|
||||
public HttpCamera(String name, String url) {
|
||||
super(CameraServerJNI.createHttpCamera(name, url));
|
||||
super(CameraServerJNI.createHttpCamera(name, url, CameraKind.kUnknown.getValue()));
|
||||
}
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
public HttpCamera(String name, String url, CameraKind kind) {
|
||||
super(CameraServerJNI.createHttpCamera(name, url, kind.getValue()));
|
||||
}
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param urls Array of Camera URLs
|
||||
public HttpCamera(String name, String[] urls) {
|
||||
super(CameraServerJNI.createHttpCameraMulti(name, urls, CameraKind.kUnknown.getValue()));
|
||||
}
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param urls Array of Camera URLs
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
public HttpCamera(String name, String[] urls, CameraKind kind) {
|
||||
super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
|
||||
}
|
||||
|
||||
/// Get the kind of HTTP camera.
|
||||
/// Autodetection can result in returning a different value than the camera
|
||||
/// was created with.
|
||||
CameraKind getCameraKind() {
|
||||
return getCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
|
||||
}
|
||||
|
||||
/// Change the URLs used to connect to the camera.
|
||||
void setUrls(String[] urls) {
|
||||
CameraServerJNI.setHttpCameraUrls(m_handle, urls);
|
||||
}
|
||||
|
||||
/// Get the URLs used to connect to the camera.
|
||||
String[] getUrls() {
|
||||
return CameraServerJNI.getHttpCameraUrls(m_handle);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user