mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Add GetNextFrame timeout to CvSink and MjpegServer.
MjpegServer uses the timeout to generate keep-alives to any clients (which helps detect disconnects and avoid stale client threads). CvSink GrabFrame now defaults to a timeout, but the timeout can be changed by the user, or the old no-timeout version is now available as GrabFrameNoTimeout.
This commit is contained in:
@@ -1261,6 +1261,21 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_cscore_CameraServerJNI_grabSinkFrame
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: grabSinkFrameTimeout
|
||||
* Signature: (IJD)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_edu_wpi_cscore_CameraServerJNI_grabSinkFrameTimeout
|
||||
(JNIEnv *env, jclass, jint sink, jlong imageNativeObj, jdouble timeout)
|
||||
{
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrameTimeout(sink, image, timeout, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: getSinkError
|
||||
|
||||
@@ -193,6 +193,7 @@ public class CameraServerJNI {
|
||||
//
|
||||
public static native void setSinkDescription(int sink, String description);
|
||||
public static native long grabSinkFrame(int sink, long imageNativeObj);
|
||||
public static native long grabSinkFrameTimeout(int sink, long imageNativeObj, double timeout);
|
||||
public static native String getSinkError(int sink);
|
||||
public static native void setSinkEnabled(int sink, boolean enabled);
|
||||
|
||||
|
||||
@@ -39,10 +39,28 @@ public class CvSink extends VideoSink {
|
||||
}
|
||||
|
||||
/// Wait for the next frame and get the image.
|
||||
/// Times out (returning 0) after 0.225 seconds.
|
||||
/// The provided image will have three 3-bit channels stored in BGR order.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message);
|
||||
public long grabFrame(Mat image) {
|
||||
return grabFrame(image, 0.225);
|
||||
}
|
||||
|
||||
/// Wait for the next frame and get the image.
|
||||
/// Times out (returning 0) after timeout seconds.
|
||||
/// The provided image will have three 3-bit channels stored in BGR order.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message);
|
||||
public long grabFrame(Mat image, double timeout) {
|
||||
return CameraServerJNI.grabSinkFrameTimeout(m_handle, image.nativeObj, timeout);
|
||||
}
|
||||
|
||||
/// Wait for the next frame and get the image. May block forever.
|
||||
/// The provided image will have three 3-bit channels stored in BGR order.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message);
|
||||
public long grabFrameNoTimeout(Mat image) {
|
||||
return CameraServerJNI.grabSinkFrame(m_handle, image.nativeObj);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user