mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Remove support for multiple channels.
This commit is contained in:
@@ -88,8 +88,7 @@ CS_Source CS_CreateUSBSourcePath(const char* name, const char* path,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CreateHTTPSource(const char* name, const char* url,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CreateCvSource(const char* name, int numChannels,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CreateCvSource(const char* name, CS_Status* status);
|
||||
|
||||
//
|
||||
// Source Functions
|
||||
@@ -97,7 +96,6 @@ CS_Source CS_CreateCvSource(const char* name, int numChannels,
|
||||
char* CS_GetSourceName(CS_Source source, CS_Status* status);
|
||||
char* CS_GetSourceDescription(CS_Source source, CS_Status* status);
|
||||
uint64_t CS_GetSourceLastFrameTime(CS_Source source, CS_Status* status);
|
||||
int CS_GetSourceNumChannels(CS_Source source, CS_Status* status);
|
||||
CS_Bool CS_IsSourceConnected(CS_Source source, CS_Status* status);
|
||||
CS_Property CS_GetSourceProperty(CS_Source source, const char* name,
|
||||
CS_Status* status);
|
||||
@@ -109,9 +107,6 @@ void CS_ReleaseSource(CS_Source source, CS_Status* status);
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
//
|
||||
void CS_PutSourceImage(CS_Source source, int channel, struct CvMat* image,
|
||||
CS_Status* status);
|
||||
void CS_NotifySourceFrame(CS_Source source, CS_Status* status);
|
||||
void CS_PutSourceFrame(CS_Source source, struct CvMat* image,
|
||||
CS_Status* status);
|
||||
void CS_NotifySourceError(CS_Source source, const char* msg, CS_Status* status);
|
||||
@@ -150,17 +145,9 @@ CS_Source CS_GetSinkSource(CS_Sink sink, CS_Status* status);
|
||||
CS_Sink CS_CopySink(CS_Sink sink, CS_Status* status);
|
||||
void CS_ReleaseSink(CS_Sink sink, CS_Status* status);
|
||||
|
||||
//
|
||||
// Server Sink (e.g. HTTP) Functions
|
||||
//
|
||||
void CS_SetSinkSourceChannel(CS_Sink sink, int channel, CS_Status* status);
|
||||
|
||||
//
|
||||
// OpenCV Sink Functions
|
||||
//
|
||||
uint64_t CS_SinkWaitForFrame(CS_Sink sink, CS_Status* status);
|
||||
CS_Bool CS_GetSinkImage(CS_Sink sink, int channel, struct CvMat* image,
|
||||
CS_Status* status);
|
||||
uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image, CS_Status* status);
|
||||
char* CS_GetSinkError(CS_Sink sink, CS_Status* status);
|
||||
void CS_SetSinkEnabled(CS_Sink sink, CS_Bool enabled, CS_Status* status);
|
||||
@@ -203,7 +190,6 @@ typedef struct CS_USBCameraInfo {
|
||||
int dev;
|
||||
char* path;
|
||||
char* name;
|
||||
int channels;
|
||||
} CS_USBCameraInfo;
|
||||
|
||||
CS_USBCameraInfo* CS_EnumerateUSBCameras(int* count, CS_Status* status);
|
||||
|
||||
@@ -40,9 +40,6 @@ struct USBCameraInfo {
|
||||
std::string path;
|
||||
/// Vendor/model name of the camera as provided by the USB driver
|
||||
std::string name;
|
||||
/// Number of channels the camera provides (usually 1, but some cameras such
|
||||
/// as stereo or depth cameras may provide multiple channels).
|
||||
int channels;
|
||||
};
|
||||
|
||||
//
|
||||
@@ -79,8 +76,7 @@ CS_Source CreateUSBSourcePath(llvm::StringRef name, llvm::StringRef path,
|
||||
CS_Status* status);
|
||||
CS_Source CreateHTTPSource(llvm::StringRef name, llvm::StringRef url,
|
||||
CS_Status* status);
|
||||
CS_Source CreateCvSource(llvm::StringRef name, int numChannels,
|
||||
CS_Status* status);
|
||||
CS_Source CreateCvSource(llvm::StringRef name, CS_Status* status);
|
||||
|
||||
//
|
||||
// Source Functions
|
||||
@@ -94,7 +90,6 @@ llvm::StringRef GetSourceDescription(CS_Source source,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status);
|
||||
uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status* status);
|
||||
int GetSourceNumChannels(CS_Source source, CS_Status* status);
|
||||
bool IsSourceConnected(CS_Source source, CS_Status* status);
|
||||
CS_Property GetSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_Status* status);
|
||||
@@ -107,9 +102,6 @@ void ReleaseSource(CS_Source source, CS_Status* status);
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
//
|
||||
void PutSourceImage(CS_Source source, int channel, cv::Mat* image,
|
||||
CS_Status* status);
|
||||
void NotifySourceFrame(CS_Source source, CS_Status* status);
|
||||
void PutSourceFrame(CS_Source source, cv::Mat* image, CS_Status* status);
|
||||
void NotifySourceError(CS_Source source, llvm::StringRef msg,
|
||||
CS_Status* status);
|
||||
@@ -151,16 +143,9 @@ CS_Source GetSinkSource(CS_Sink sink, CS_Status* status);
|
||||
CS_Sink CopySink(CS_Sink sink, CS_Status* status);
|
||||
void ReleaseSink(CS_Sink sink, CS_Status* status);
|
||||
|
||||
//
|
||||
// Server Sink (e.g. HTTP) Functions
|
||||
//
|
||||
void SetSinkSourceChannel(CS_Sink sink, int channel, CS_Status* status);
|
||||
|
||||
//
|
||||
// OpenCV Sink Functions
|
||||
//
|
||||
uint64_t SinkWaitForFrame(CS_Sink sink, CS_Status* status);
|
||||
bool GetSinkImage(CS_Sink sink, int channel, cv::Mat* image, CS_Status* status);
|
||||
uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat* image, CS_Status* status);
|
||||
std::string GetSinkError(CS_Sink sink, CS_Status* status);
|
||||
llvm::StringRef GetSinkError(CS_Sink sink, llvm::SmallVectorImpl<char>& buf,
|
||||
|
||||
@@ -81,9 +81,7 @@ class VideoProperty {
|
||||
Type m_type;
|
||||
};
|
||||
|
||||
/// A source for video that provides a sequence of frames. Each frame may
|
||||
/// consist of multiple images (e.g. from a stereo or depth camera); these
|
||||
/// are called channels.
|
||||
/// A source for video that provides a sequence of frames.
|
||||
class VideoSource {
|
||||
friend class SourceListener;
|
||||
friend class VideoSink;
|
||||
@@ -107,9 +105,6 @@ class VideoSource {
|
||||
/// Get the last time a frame was captured.
|
||||
uint64_t GetLastFrameTime() const;
|
||||
|
||||
/// Get the number of channels this source provides.
|
||||
int GetNumChannels() const;
|
||||
|
||||
/// Is the source currently connected to whatever is providing the images?
|
||||
bool IsConnected() const;
|
||||
|
||||
@@ -167,19 +162,9 @@ class CvSource : public VideoSource {
|
||||
public:
|
||||
/// Create an OpenCV source.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param numChannels Number of channels
|
||||
CvSource(llvm::StringRef name, int numChannels = 1);
|
||||
CvSource(llvm::StringRef name);
|
||||
|
||||
/// Put an OpenCV image onto the specified channel.
|
||||
/// @param channel Channel number (range 0 to numChannels-1)
|
||||
/// @param image OpenCV image
|
||||
void PutImage(int channel, cv::Mat* image);
|
||||
|
||||
/// Signal sinks connected to this source that all new channel images have
|
||||
/// been put to the stream and are ready to be read.
|
||||
void NotifyFrame();
|
||||
|
||||
/// Put an OpenCV image onto channel 0 and notify sinks.
|
||||
/// Put an OpenCV image and notify sinks.
|
||||
/// This is identical in behavior to calling PutImage(0, image) followed by
|
||||
/// NotifyFrame().
|
||||
/// @param image OpenCV image
|
||||
@@ -217,9 +202,7 @@ class CvSource : public VideoSource {
|
||||
void RemoveProperty(llvm::StringRef name);
|
||||
};
|
||||
|
||||
/// A sink for video that accepts a sequence of frames. Each frame may
|
||||
/// consist of multiple images (e.g. from a stereo or depth camera); these are
|
||||
/// called channels.
|
||||
/// A sink for video that accepts a sequence of frames.
|
||||
class VideoSink {
|
||||
friend class SinkListener;
|
||||
|
||||
@@ -281,12 +264,6 @@ class HTTPSink : public VideoSink {
|
||||
/// @param name Sink name (arbitrary unique identifier)
|
||||
/// @param port TCP port number
|
||||
HTTPSink(llvm::StringRef name, int port) : HTTPSink(name, "", port) {}
|
||||
|
||||
/// Set what video channel should be served.
|
||||
/// MJPEG-HTTP can only serve a single channel of video.
|
||||
/// By default, channel 0 is served.
|
||||
/// @param channel video channel to serve to clients
|
||||
void SetSourceChannel(int channel);
|
||||
};
|
||||
|
||||
/// A sink for user code to accept video frames as OpenCV images.
|
||||
@@ -308,18 +285,7 @@ class CvSink : public VideoSink {
|
||||
/// unusual circumstances) WaitForImage().
|
||||
CvSink(llvm::StringRef name, std::function<void(uint64_t time)> processFrame);
|
||||
|
||||
/// Wait for the next frame. This is a blocking call.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message).
|
||||
uint64_t WaitForFrame() const;
|
||||
|
||||
/// Get an OpenCV image from the specified channel.
|
||||
/// @return False if image could not be obtained for some reason (e.g.
|
||||
/// channel out of range)
|
||||
bool GetImage(int channel, cv::Mat* image) const;
|
||||
|
||||
/// Wait for the next frame and get the image from channel 0. Equivalent
|
||||
/// to calling WaitForFrame() followed by GetImage(0, image).
|
||||
/// Wait for the next frame and get the image.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message);
|
||||
uint64_t GrabFrame(cv::Mat* image) const;
|
||||
|
||||
@@ -122,11 +122,6 @@ inline uint64_t VideoSource::GetLastFrameTime() const {
|
||||
return GetSourceLastFrameTime(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline int VideoSource::GetNumChannels() const {
|
||||
m_status = 0;
|
||||
return GetSourceNumChannels(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline bool VideoSource::IsConnected() const {
|
||||
m_status = 0;
|
||||
return IsSourceConnected(m_handle, &m_status);
|
||||
@@ -154,18 +149,8 @@ inline HTTPCamera::HTTPCamera(llvm::StringRef name, llvm::StringRef url) {
|
||||
m_handle = CreateHTTPSource(name, url, &m_status);
|
||||
}
|
||||
|
||||
inline CvSource::CvSource(llvm::StringRef name, int numChannels) {
|
||||
m_handle = CreateCvSource(name, numChannels, &m_status);
|
||||
}
|
||||
|
||||
inline void CvSource::PutImage(int channel, cv::Mat* image) {
|
||||
m_status = 0;
|
||||
PutSourceImage(m_handle, channel, image, &m_status);
|
||||
}
|
||||
|
||||
inline void CvSource::NotifyFrame() {
|
||||
m_status = 0;
|
||||
NotifySourceFrame(m_handle, &m_status);
|
||||
inline CvSource::CvSource(llvm::StringRef name) {
|
||||
m_handle = CreateCvSource(name, &m_status);
|
||||
}
|
||||
|
||||
inline void CvSource::PutFrame(cv::Mat* image) {
|
||||
@@ -265,11 +250,6 @@ inline HTTPSink::HTTPSink(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
m_handle = CreateHTTPSink(name, listenAddress, port, &m_status);
|
||||
}
|
||||
|
||||
inline void HTTPSink::SetSourceChannel(int channel) {
|
||||
m_status = 0;
|
||||
SetSinkSourceChannel(m_handle, channel, &m_status);
|
||||
}
|
||||
|
||||
inline CvSink::CvSink(llvm::StringRef name) {
|
||||
m_handle = CreateCvSink(name, &m_status);
|
||||
}
|
||||
@@ -279,16 +259,6 @@ inline CvSink::CvSink(llvm::StringRef name,
|
||||
m_handle = CreateCvSinkCallback(name, processFrame, &m_status);
|
||||
}
|
||||
|
||||
inline uint64_t CvSink::WaitForFrame() const {
|
||||
m_status = 0;
|
||||
return SinkWaitForFrame(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline bool CvSink::GetImage(int channel, cv::Mat* image) const {
|
||||
m_status = 0;
|
||||
return GetSinkImage(m_handle, channel, image, &m_status);
|
||||
}
|
||||
|
||||
inline uint64_t CvSink::GrabFrame(cv::Mat* image) const {
|
||||
m_status = 0;
|
||||
return GrabSinkFrame(m_handle, image, &m_status);
|
||||
|
||||
@@ -66,12 +66,11 @@ static inline bool CheckStatus(JNIEnv *env, CS_Status status,
|
||||
|
||||
static jobject MakeJObject(JNIEnv *env, const cs::USBCameraInfo &info) {
|
||||
static jmethodID constructor = env->GetMethodID(
|
||||
usbCameraInfoCls, "<init>", "(ILjava/lang/String;Ljava/lang/String;I)V");
|
||||
usbCameraInfoCls, "<init>", "(ILjava/lang/String;Ljava/lang/String;)V");
|
||||
JLocal<jstring> path(env, MakeJString(env, info.path));
|
||||
JLocal<jstring> name(env, MakeJString(env, info.name));
|
||||
return env->NewObject(usbCameraInfoCls, constructor,
|
||||
static_cast<jint>(info.dev), path.obj(), name.obj(),
|
||||
static_cast<jint>(info.channels));
|
||||
static_cast<jint>(info.dev), path.obj(), name.obj());
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -303,13 +302,13 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_createHTTPSourc
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: createCvSource
|
||||
* Signature: (Ljava/lang/String;I)I
|
||||
* Signature: (Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_createCvSource
|
||||
(JNIEnv *env, jclass, jstring name, jint numChannels)
|
||||
(JNIEnv *env, jclass, jstring name)
|
||||
{
|
||||
CS_Status status;
|
||||
auto val = cs::CreateCvSource(JStringRef{env, name}, numChannels, &status);
|
||||
auto val = cs::CreateCvSource(JStringRef{env, name}, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
@@ -358,20 +357,6 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getSourceLastF
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getSourceNumChannels
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_getSourceNumChannels
|
||||
(JNIEnv *env, jclass, jint source)
|
||||
{
|
||||
CS_Status status;
|
||||
auto val = cs::GetSourceNumChannels(source, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: isSourceConnected
|
||||
@@ -442,19 +427,6 @@ JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_releaseSource
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: notifySourceFrame
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_notifySourceFrame
|
||||
(JNIEnv *env, jclass, jint source)
|
||||
{
|
||||
CS_Status status;
|
||||
cs::NotifySourceFrame(source, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: notifySourceError
|
||||
@@ -651,33 +623,6 @@ JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_releaseSink
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: setSinkSourceChannel
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setSinkSourceChannel
|
||||
(JNIEnv *env, jclass, jint sink, jint channel)
|
||||
{
|
||||
CS_Status status;
|
||||
cs::SetSinkSourceChannel(sink, channel, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: sinkWaitForFrame
|
||||
* Signature: (I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_sinkWaitForFrame
|
||||
(JNIEnv *env, jclass, jint sink)
|
||||
{
|
||||
CS_Status status;
|
||||
auto val = cs::SinkWaitForFrame(sink, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: getSinkError
|
||||
|
||||
@@ -95,7 +95,7 @@ public class CameraServerJNI {
|
||||
public static native int createUSBSourceDev(String name, int dev);
|
||||
public static native int createUSBSourcePath(String name, String path);
|
||||
public static native int createHTTPSource(String name, String url);
|
||||
public static native int createCvSource(String name, int numChannels);
|
||||
public static native int createCvSource(String name);
|
||||
|
||||
//
|
||||
// Source Functions
|
||||
@@ -103,7 +103,6 @@ public class CameraServerJNI {
|
||||
public static native String getSourceName(int source);
|
||||
public static native String getSourceDescription(int source);
|
||||
public static native long getSourceLastFrameTime(int source);
|
||||
public static native int getSourceNumChannels(int source);
|
||||
public static native boolean isSourceConnected(int source);
|
||||
public static native int getSourceProperty(int source, String name);
|
||||
public static native int[] enumerateSourceProperties(int source);
|
||||
@@ -113,8 +112,6 @@ public class CameraServerJNI {
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
//
|
||||
//public static native void putSourceImage(int source, int channel, CvMat image);
|
||||
public static native void notifySourceFrame(int source);
|
||||
//public static native void putSourceFrame(int source, CvMat image);
|
||||
public static native void notifySourceError(int source, String msg);
|
||||
public static native void setSourceConnected(int source, boolean connected);
|
||||
@@ -145,16 +142,9 @@ public class CameraServerJNI {
|
||||
public static native int copySink(int sink);
|
||||
public static native void releaseSink(int sink);
|
||||
|
||||
//
|
||||
// Server Sink (e.g. HTTP) Functions
|
||||
//
|
||||
public static native void setSinkSourceChannel(int sink, int channel);
|
||||
|
||||
//
|
||||
// OpenCV Sink Functions
|
||||
//
|
||||
public static native long sinkWaitForFrame(int sink);
|
||||
//public static native int getSinkImage(int sink, CvMat image);
|
||||
//public static native int grabSinkFrame(int sink, CvMat image);
|
||||
public static native String getSinkError(int sink);
|
||||
public static native void setSinkEnabled(int sink, boolean enabled);
|
||||
|
||||
@@ -30,22 +30,7 @@ public class CvSink extends VideoSink {
|
||||
// super(CameraServerJNI.createCvSinkCallback(name, processFrame));
|
||||
//}
|
||||
|
||||
/// Wait for the next frame. This is a blocking call.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message).
|
||||
public long waitForFrame() {
|
||||
return CameraServerJNI.sinkWaitForFrame(m_handle);
|
||||
}
|
||||
|
||||
/// Get an OpenCV image from the specified channel.
|
||||
/// @return False if image could not be obtained for some reason (e.g.
|
||||
/// channel out of range)
|
||||
//public boolean getImage(int channel, CvMat image) {
|
||||
// return CameraServerJNI.getSinkImage(m_handle, channel, image);
|
||||
//}
|
||||
|
||||
/// Wait for the next frame and get the image from channel 0. Equivalent
|
||||
/// to calling WaitForFrame() followed by GetImage(0, image).
|
||||
/// Wait for the next frame and get the image.
|
||||
/// @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
/// message);
|
||||
//public long grabFrame(CvMat image) {
|
||||
|
||||
@@ -9,33 +9,13 @@ package edu.wpi.cameraserver;
|
||||
|
||||
/// A source that represents a video camera.
|
||||
public class CvSource extends VideoSource {
|
||||
/// Create an OpenCV source with a single channel.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
public CvSource(String name) {
|
||||
super(CameraServerJNI.createCvSource(name, 1));
|
||||
}
|
||||
|
||||
/// Create an OpenCV source.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param numChannels Number of channels
|
||||
public CvSource(String name, int numChannels) {
|
||||
super(CameraServerJNI.createCvSource(name, numChannels));
|
||||
public CvSource(String name) {
|
||||
super(CameraServerJNI.createCvSource(name));
|
||||
}
|
||||
|
||||
/// Put an OpenCV image onto the specified channel.
|
||||
/// @param channel Channel number (range 0 to nChannels-1)
|
||||
/// @param image OpenCV image
|
||||
//public void putImage(int channel, Mat image);
|
||||
|
||||
/// Signal sinks connected to this source that all new channel images have
|
||||
/// been put to the stream and are ready to be read.
|
||||
public void notifyFrame() {
|
||||
CameraServerJNI.notifySourceFrame(m_handle);
|
||||
}
|
||||
|
||||
/// Put an OpenCV image onto channel 0 and notify sinks.
|
||||
/// This is identical in behavior to calling PutImage(0, image) followed by
|
||||
/// NotifyFrame().
|
||||
/// Put an OpenCV image and notify sinks.
|
||||
/// @param image OpenCV image
|
||||
//public void putFrame(Mat image);
|
||||
|
||||
|
||||
@@ -23,12 +23,4 @@ public class HTTPSink extends VideoSink {
|
||||
public HTTPSink(String name, int port) {
|
||||
this(name, "", port);
|
||||
}
|
||||
|
||||
/// Set what video channel should be served.
|
||||
/// MJPEG-HTTP can only serve a single channel of video.
|
||||
/// By default, channel 0 is served.
|
||||
/// @param channel video channel to serve to clients
|
||||
public void setSourceChannel(int channel) {
|
||||
CameraServerJNI.setSinkSourceChannel(m_handle, channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,10 @@ package edu.wpi.cameraserver;
|
||||
|
||||
/// USB camera information
|
||||
public class USBCameraInfo {
|
||||
public USBCameraInfo(int dev, String path, String name, int channels) {
|
||||
public USBCameraInfo(int dev, String path, String name) {
|
||||
this.dev = dev;
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
/// Device number (e.g. N in '/dev/videoN' on Linux)
|
||||
@@ -22,7 +21,4 @@ public class USBCameraInfo {
|
||||
public String path;
|
||||
/// Vendor/model name of the camera as provided by the USB driver
|
||||
public String name;
|
||||
/// Number of channels the camera provides (usually 1, but some cameras such
|
||||
/// as stereo or depth cameras may provide multiple channels).
|
||||
public int channels;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,6 @@ public class VideoSource {
|
||||
return CameraServerJNI.getSourceLastFrameTime(m_handle);
|
||||
}
|
||||
|
||||
/// Get the number of channels this source provides.
|
||||
public int getNumChannels() {
|
||||
return CameraServerJNI.getSourceNumChannels(m_handle);
|
||||
}
|
||||
|
||||
/// Is the source currently connected to whatever is providing the images?
|
||||
public boolean isConnected() {
|
||||
return CameraServerJNI.isSourceConnected(m_handle);
|
||||
|
||||
14
src/Frame.h
14
src/Frame.h
@@ -25,7 +25,7 @@ class Frame {
|
||||
struct Data {
|
||||
std::atomic_int refcount{0};
|
||||
std::chrono::system_clock::time_point timestamp;
|
||||
llvm::SmallVector<Image, 4> images;
|
||||
Image image;
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -53,14 +53,14 @@ class Frame {
|
||||
|
||||
explicit operator bool() const { return m_data; }
|
||||
|
||||
std::size_t size(std::size_t channel) const {
|
||||
if (!m_data || channel >= m_data->images.size()) return 0;
|
||||
return m_data->images[channel].size();
|
||||
std::size_t size() const {
|
||||
if (!m_data) return 0;
|
||||
return m_data->image.size();
|
||||
}
|
||||
|
||||
const char* data(std::size_t channel) const {
|
||||
if (!m_data || channel >= m_data->images.size()) return nullptr;
|
||||
return m_data->images[channel].data();
|
||||
const char* data() const {
|
||||
if (!m_data) return nullptr;
|
||||
return m_data->image.data();
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point time() const {
|
||||
|
||||
@@ -321,11 +321,11 @@ void HTTPSinkImpl::SendStream(wpi::raw_socket_ostream& os) {
|
||||
.count();
|
||||
header.clear();
|
||||
oss << "Content-Type: image/jpeg\r\n"
|
||||
<< "Content-Length: " << frame.size(m_sourceChannel) << "\r\n"
|
||||
<< "Content-Length: " << frame.size() << "\r\n"
|
||||
<< "X-Timestamp: " << timestamp << "\r\n"
|
||||
<< "\r\n";
|
||||
os << oss.str();
|
||||
os << frame.data(m_sourceChannel);
|
||||
os << frame.data();
|
||||
os << "\r\n--" BOUNDARY "\r\n";
|
||||
// os.flush();
|
||||
}
|
||||
@@ -454,19 +454,6 @@ CS_Sink CreateHTTPSink(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
return Sinks::GetInstance().Allocate(SinkData::kHTTP, sink);
|
||||
}
|
||||
|
||||
void SetSinkSourceChannel(CS_Sink sink, int channel, CS_Status* status) {
|
||||
auto data = Sinks::GetInstance().Get(sink);
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
if (data->type != SinkData::kHTTP) {
|
||||
*status = CS_WRONG_HANDLE_SUBTYPE;
|
||||
return;
|
||||
}
|
||||
static_cast<HTTPSinkImpl*>(data->sink.get())->SetSourceChannel(channel);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
@@ -476,8 +463,4 @@ CS_Sink CS_CreateHTTPSink(const char* name, const char* listenAddress, int port,
|
||||
return cs::CreateHTTPSink(name, listenAddress, port, status);
|
||||
}
|
||||
|
||||
void CS_SetSinkSourceChannel(CS_Sink sink, int channel, CS_Status* status) {
|
||||
return cs::SetSinkSourceChannel(sink, channel, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -38,8 +38,6 @@ class HTTPSinkImpl : public SinkImpl {
|
||||
llvm::StringRef GetDescription(
|
||||
llvm::SmallVectorImpl<char>& buf) const override;
|
||||
|
||||
void SetSourceChannel(int channel) { m_sourceChannel.store(channel); }
|
||||
|
||||
void Stop();
|
||||
|
||||
static void SendHeader(llvm::raw_ostream& os, int code,
|
||||
@@ -64,7 +62,6 @@ class HTTPSinkImpl : public SinkImpl {
|
||||
std::string m_description;
|
||||
|
||||
std::unique_ptr<wpi::NetworkAcceptor> m_acceptor;
|
||||
std::atomic_int m_sourceChannel;
|
||||
std::atomic_bool m_active; // set to false to terminate threads
|
||||
std::thread m_serverThread;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ void SourceImpl::StartFrame() {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Image& SourceImpl::AddImage(std::size_t channel, std::size_t size) {}
|
||||
//TODO: Image& SourceImpl::AddImage(std::size_t size) {}
|
||||
|
||||
void SourceImpl::FinishFrame() {
|
||||
{
|
||||
@@ -62,9 +62,8 @@ void SourceImpl::FinishFrame() {
|
||||
|
||||
void SourceImpl::ReleaseFrame(Frame::Data* data) {
|
||||
std::lock_guard<std::mutex> lock{m_mutex};
|
||||
// Return the images to the pool
|
||||
for (auto&& image : data->images)
|
||||
m_imagesAvail.emplace_back(std::move(image));
|
||||
// Return the image to the pool
|
||||
m_imagesAvail.emplace_back(std::move(data->image));
|
||||
// Return the frame to the pool
|
||||
m_framesAvail.emplace_back(data);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ class SourceImpl {
|
||||
llvm::StringRef GetName() const { return m_name; }
|
||||
virtual llvm::StringRef GetDescription(
|
||||
llvm::SmallVectorImpl<char>& buf) const = 0;
|
||||
int GetNumChannels() const { return m_numChannels; }
|
||||
bool IsConnected() const { return m_connected; }
|
||||
|
||||
// Functions to keep track of the overall number of sinks connected to this
|
||||
@@ -101,10 +100,9 @@ class SourceImpl {
|
||||
|
||||
protected:
|
||||
void StartFrame();
|
||||
Image& AddImage(std::size_t channel, std::size_t size);
|
||||
Image& AddImage(std::size_t size);
|
||||
void FinishFrame();
|
||||
|
||||
std::atomic_int m_numChannels{0};
|
||||
std::atomic_bool m_connected{false};
|
||||
std::atomic_int m_numSinks{0};
|
||||
|
||||
|
||||
@@ -108,9 +108,8 @@ CS_Source CS_CreateHTTPSource(const char* name, const char* url,
|
||||
return cs::CreateHTTPSource(name, url, status);
|
||||
}
|
||||
|
||||
CS_Source CS_CreateCvSource(const char* name, int numChannels,
|
||||
CS_Status* status) {
|
||||
return cs::CreateCvSource(name, numChannels, status);
|
||||
CS_Source CS_CreateCvSource(const char* name, CS_Status* status) {
|
||||
return cs::CreateCvSource(name, status);
|
||||
}
|
||||
|
||||
char* CS_GetSourceName(CS_Source source, CS_Status* status) {
|
||||
@@ -131,10 +130,6 @@ uint64_t CS_GetSourceLastFrameTime(CS_Source source, CS_Status* status) {
|
||||
return cs::GetSourceLastFrameTime(source, status);
|
||||
}
|
||||
|
||||
int CS_GetSourceNumChannels(CS_Source source, CS_Status* status) {
|
||||
return cs::GetSourceNumChannels(source, status);
|
||||
}
|
||||
|
||||
CS_Bool CS_IsSourceConnected(CS_Source source, CS_Status* status) {
|
||||
return cs::IsSourceConnected(source, status);
|
||||
}
|
||||
@@ -163,15 +158,6 @@ void CS_ReleaseSource(CS_Source source, CS_Status* status) {
|
||||
return cs::ReleaseSource(source, status);
|
||||
}
|
||||
|
||||
void CS_PutSourceImage(CS_Source source, int channel, struct CvMat* image,
|
||||
CS_Status* status) {
|
||||
//TODO: return cs::PutSourceImage(source, channel, image, status);
|
||||
}
|
||||
|
||||
void CS_NotifySourceFrame(CS_Source source, CS_Status* status) {
|
||||
return cs::NotifySourceFrame(source, status);
|
||||
}
|
||||
|
||||
void CS_PutSourceFrame(CS_Source source, struct CvMat* image,
|
||||
CS_Status* status) {
|
||||
//TODO: return cs::PutSourceFrame(source, image, status);
|
||||
@@ -258,15 +244,6 @@ void CS_ReleaseSink(CS_Sink sink, CS_Status* status) {
|
||||
return cs::ReleaseSink(sink, status);
|
||||
}
|
||||
|
||||
uint64_t CS_SinkWaitForFrame(CS_Sink sink, CS_Status* status) {
|
||||
return cs::SinkWaitForFrame(sink, status);
|
||||
}
|
||||
|
||||
CS_Bool CS_GetSinkImage(CS_Sink sink, int channel, struct CvMat* image,
|
||||
CS_Status* status) {
|
||||
return 0; //TODO: cs::GetSinkImage(sink, channel, image, status);
|
||||
}
|
||||
|
||||
uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image,
|
||||
CS_Status* status) {
|
||||
return 0; // TODO: cs::GrabSinkFrame(sink, image, status);
|
||||
@@ -334,7 +311,6 @@ CS_USBCameraInfo* CS_EnumerateUSBCameras(int* count, CS_Status* status) {
|
||||
out[i].dev = cameras[i].dev;
|
||||
out[i].path = ConvertToC(cameras[i].path);
|
||||
out[i].name = ConvertToC(cameras[i].name);
|
||||
out[i].channels = cameras[i].channels;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -172,8 +172,7 @@ CS_Source CreateHTTPSource(llvm::StringRef name, llvm::StringRef url,
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
CS_Source CreateCvSource(llvm::StringRef name, int numChannels,
|
||||
CS_Status* status) {
|
||||
CS_Source CreateCvSource(llvm::StringRef name, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
@@ -226,15 +225,6 @@ uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
int GetSourceNumChannels(CS_Source source, CS_Status* status) {
|
||||
auto data = Sources::GetInstance().Get(source);
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return data->source->GetNumChannels();
|
||||
}
|
||||
|
||||
bool IsSourceConnected(CS_Source source, CS_Status* status) {
|
||||
auto data = Sources::GetInstance().Get(source);
|
||||
if (!data) {
|
||||
@@ -292,15 +282,6 @@ void ReleaseSource(CS_Source source, CS_Status* status) {
|
||||
// OpenCV Source Functions
|
||||
//
|
||||
|
||||
void PutSourceImage(CS_Source source, int channel, cv::Mat* image,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void NotifySourceFrame(CS_Source source, CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void PutSourceFrame(CS_Source source, cv::Mat* image, CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
@@ -452,15 +433,6 @@ void ReleaseSink(CS_Sink sink, CS_Status* status) {
|
||||
// OpenCV Sink Functions
|
||||
//
|
||||
|
||||
uint64_t SinkWaitForFrame(CS_Sink sink, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
bool GetSinkImage(CS_Sink sink, int channel, cv::Mat* image,
|
||||
CS_Status* status) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat* image, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user