mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Change acronym class names to use MixedCase (UsbCamera, MjpegServer). (#22)
This commit is contained in:
@@ -7,10 +7,10 @@ int main() {
|
||||
CS_Status status = 0;
|
||||
llvm::SmallString<64> buf;
|
||||
|
||||
for (const auto& caminfo : cs::EnumerateUSBCameras(&status)) {
|
||||
for (const auto& caminfo : cs::EnumerateUsbCameras(&status)) {
|
||||
llvm::outs() << caminfo.dev << ": " << caminfo.path << " (" << caminfo.name
|
||||
<< ")\n";
|
||||
cs::USBCamera camera{"usbcam", caminfo.dev};
|
||||
cs::UsbCamera camera{"usbcam", caminfo.dev};
|
||||
|
||||
llvm::outs() << "Properties:\n";
|
||||
for (const auto& prop : camera.EnumerateProperties()) {
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
cs::USBCamera camera{"usbcam", 0};
|
||||
cs::UsbCamera camera{"usbcam", 0};
|
||||
camera.SetVideoMode(cs::VideoMode::kMJPEG, 320, 240, 30);
|
||||
cs::MJPEGServer mjpegServer{"httpserver", 8081};
|
||||
cs::MjpegServer mjpegServer{"httpserver", 8081};
|
||||
mjpegServer.SetSource(camera);
|
||||
cs::CvSink cvsink{"cvsink"};
|
||||
cvsink.SetSource(camera);
|
||||
cs::CvSource cvsource{"cvsource", cs::VideoMode::kMJPEG, 320, 240, 30};
|
||||
cs::MJPEGServer cvMjpegServer{"cvhttpserver", 8082};
|
||||
cs::MjpegServer cvMjpegServer{"cvhttpserver", 8082};
|
||||
cvMjpegServer.SetSource(cvsource);
|
||||
|
||||
cv::Mat test;
|
||||
|
||||
@@ -9,9 +9,9 @@ int main() {
|
||||
llvm::outs() << "IPv4 network addresses:\n";
|
||||
for (const auto& addr : cs::GetNetworkInterfaces())
|
||||
llvm::outs() << " " << addr << '\n';
|
||||
cs::USBCamera camera{"usbcam", 1};
|
||||
cs::UsbCamera camera{"usbcam", 1};
|
||||
camera.SetVideoMode(cs::VideoMode::kMJPEG, 320, 240, 30);
|
||||
cs::MJPEGServer mjpegServer{"httpserver", 8081};
|
||||
cs::MjpegServer mjpegServer{"httpserver", 8081};
|
||||
mjpegServer.SetSource(camera);
|
||||
|
||||
getchar();
|
||||
|
||||
@@ -169,10 +169,10 @@ char** CS_GetEnumPropertyChoices(CS_Property property, int* count,
|
||||
//
|
||||
// Source Creation Functions
|
||||
//
|
||||
CS_Source CS_CreateUSBCameraDev(const char* name, int dev, CS_Status* status);
|
||||
CS_Source CS_CreateUSBCameraPath(const char* name, const char* path,
|
||||
CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status);
|
||||
CS_Source CS_CreateUsbCameraPath(const char* name, const char* path,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CreateHTTPCamera(const char* name, const char* url,
|
||||
CS_Source CS_CreateHttpCamera(const char* name, const char* url,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CreateCvSource(const char* name, const CS_VideoMode* mode,
|
||||
CS_Status* status);
|
||||
@@ -211,9 +211,9 @@ CS_Source CS_CopySource(CS_Source source, CS_Status* status);
|
||||
void CS_ReleaseSource(CS_Source source, CS_Status* status);
|
||||
|
||||
//
|
||||
// USBCamera Source Functions
|
||||
// UsbCamera Source Functions
|
||||
//
|
||||
char* CS_GetUSBCameraPath(CS_Source source, CS_Status* status);
|
||||
char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status);
|
||||
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
@@ -236,7 +236,7 @@ void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
//
|
||||
// Sink Creation Functions
|
||||
//
|
||||
CS_Sink CS_CreateMJPEGServer(const char* name, const char* listenAddress,
|
||||
CS_Sink CS_CreateMjpegServer(const char* name, const char* listenAddress,
|
||||
int port, CS_Status* status);
|
||||
CS_Sink CS_CreateCvSink(const char* name, CS_Status* status);
|
||||
CS_Sink CS_CreateCvSinkCallback(const char* name, void* data,
|
||||
@@ -257,10 +257,10 @@ CS_Sink CS_CopySink(CS_Sink sink, CS_Status* status);
|
||||
void CS_ReleaseSink(CS_Sink sink, CS_Status* status);
|
||||
|
||||
//
|
||||
// MJPEGServer Sink Functions
|
||||
// MjpegServer Sink Functions
|
||||
//
|
||||
char* CS_GetMJPEGServerListenAddress(CS_Sink sink, CS_Status* status);
|
||||
int CS_GetMJPEGServerPort(CS_Sink sink, CS_Status* status);
|
||||
char* CS_GetMjpegServerListenAddress(CS_Sink sink, CS_Status* status);
|
||||
int CS_GetMjpegServerPort(CS_Sink sink, CS_Status* status);
|
||||
|
||||
//
|
||||
// OpenCV Sink Functions
|
||||
@@ -288,14 +288,14 @@ int CS_NotifierDestroyed(void);
|
||||
//
|
||||
// Utility Functions
|
||||
//
|
||||
typedef struct CS_USBCameraInfo {
|
||||
typedef struct CS_UsbCameraInfo {
|
||||
int dev;
|
||||
char* path;
|
||||
char* name;
|
||||
} CS_USBCameraInfo;
|
||||
} CS_UsbCameraInfo;
|
||||
|
||||
CS_USBCameraInfo* CS_EnumerateUSBCameras(int* count, CS_Status* status);
|
||||
void CS_FreeEnumeratedUSBCameras(CS_USBCameraInfo* cameras, int count);
|
||||
CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status);
|
||||
void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count);
|
||||
|
||||
CS_Source* CS_EnumerateSources(int* count, CS_Status* status);
|
||||
void CS_ReleaseEnumeratedSources(CS_Source* sources, int count);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace cs {
|
||||
//
|
||||
|
||||
/// USB camera information
|
||||
struct USBCameraInfo {
|
||||
struct UsbCameraInfo {
|
||||
/// Device number (e.g. N in '/dev/videoN' on Linux)
|
||||
int dev;
|
||||
/// Path to device if available (e.g. '/dev/video0' on Linux)
|
||||
@@ -156,10 +156,10 @@ std::vector<std::string> GetEnumPropertyChoices(CS_Property property,
|
||||
//
|
||||
// Source Creation Functions
|
||||
//
|
||||
CS_Source CreateUSBCameraDev(llvm::StringRef name, int dev, CS_Status* status);
|
||||
CS_Source CreateUSBCameraPath(llvm::StringRef name, llvm::StringRef path,
|
||||
CS_Source CreateUsbCameraDev(llvm::StringRef name, int dev, CS_Status* status);
|
||||
CS_Source CreateUsbCameraPath(llvm::StringRef name, llvm::StringRef path,
|
||||
CS_Status* status);
|
||||
CS_Source CreateHTTPCamera(llvm::StringRef name, llvm::StringRef url,
|
||||
CS_Source CreateHttpCamera(llvm::StringRef name, llvm::StringRef url,
|
||||
CS_Status* status);
|
||||
CS_Source CreateCvSource(llvm::StringRef name, const VideoMode& mode,
|
||||
CS_Status* status);
|
||||
@@ -199,9 +199,9 @@ CS_Source CopySource(CS_Source source, CS_Status* status);
|
||||
void ReleaseSource(CS_Source source, CS_Status* status);
|
||||
|
||||
//
|
||||
// USBCamera Source Functions
|
||||
// UsbCamera Source Functions
|
||||
//
|
||||
std::string GetUSBCameraPath(CS_Source source, CS_Status* status);
|
||||
std::string GetUsbCameraPath(CS_Source source, CS_Status* status);
|
||||
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
@@ -223,7 +223,7 @@ void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
//
|
||||
// Sink Creation Functions
|
||||
//
|
||||
CS_Sink CreateMJPEGServer(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
CS_Sink CreateMjpegServer(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
int port, CS_Status* status);
|
||||
CS_Sink CreateCvSink(llvm::StringRef name, CS_Status* status);
|
||||
CS_Sink CreateCvSinkCallback(llvm::StringRef name,
|
||||
@@ -249,10 +249,10 @@ CS_Sink CopySink(CS_Sink sink, CS_Status* status);
|
||||
void ReleaseSink(CS_Sink sink, CS_Status* status);
|
||||
|
||||
//
|
||||
// MJPEGServer Sink Functions
|
||||
// MjpegServer Sink Functions
|
||||
//
|
||||
std::string GetMJPEGServerListenAddress(CS_Sink sink, CS_Status* status);
|
||||
int GetMJPEGServerPort(CS_Sink sink, CS_Status* status);
|
||||
std::string GetMjpegServerListenAddress(CS_Sink sink, CS_Status* status);
|
||||
int GetMjpegServerPort(CS_Sink sink, CS_Status* status);
|
||||
|
||||
//
|
||||
// OpenCV Sink Functions
|
||||
@@ -281,7 +281,7 @@ bool NotifierDestroyed();
|
||||
//
|
||||
// Utility Functions
|
||||
//
|
||||
std::vector<USBCameraInfo> EnumerateUSBCameras(CS_Status* status);
|
||||
std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status);
|
||||
|
||||
llvm::ArrayRef<CS_Source> EnumerateSourceHandles(
|
||||
llvm::SmallVectorImpl<CS_Source>& vec, CS_Status* status);
|
||||
|
||||
@@ -85,8 +85,8 @@ class VideoSource {
|
||||
public:
|
||||
enum Kind {
|
||||
kUnknown = CS_SOURCE_UNKNOWN,
|
||||
kUSB = CS_SOURCE_USB,
|
||||
kHTTP = CS_SOURCE_HTTP,
|
||||
kUsb = CS_SOURCE_USB,
|
||||
kHttp = CS_SOURCE_HTTP,
|
||||
kCv = CS_SOURCE_CV
|
||||
};
|
||||
|
||||
@@ -190,7 +190,7 @@ class VideoSource {
|
||||
};
|
||||
|
||||
/// A source that represents a USB camera.
|
||||
class USBCamera : public VideoSource {
|
||||
class UsbCamera : public VideoSource {
|
||||
private:
|
||||
static constexpr char const* kPropWbAuto = "white_balance_temperature_auto";
|
||||
static constexpr char const* kPropWbValue = "white_balance_temperature";
|
||||
@@ -207,21 +207,21 @@ class USBCamera : public VideoSource {
|
||||
kFixedFlourescent2 = 5200
|
||||
};
|
||||
|
||||
USBCamera() = default;
|
||||
UsbCamera() = default;
|
||||
|
||||
/// Create a source for a USB camera based on device number.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param dev Device number (e.g. 0 for /dev/video0)
|
||||
USBCamera(llvm::StringRef name, int dev);
|
||||
UsbCamera(llvm::StringRef name, int dev);
|
||||
|
||||
/// Create a source for a USB camera based on device path.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param path Path to device (e.g. "/dev/video0" on Linux)
|
||||
USBCamera(llvm::StringRef name, llvm::StringRef path);
|
||||
UsbCamera(llvm::StringRef name, llvm::StringRef path);
|
||||
|
||||
/// Enumerate USB cameras on the local system.
|
||||
/// @return Vector of USB camera information (one for each camera)
|
||||
static std::vector<USBCameraInfo> EnumerateUSBCameras();
|
||||
static std::vector<UsbCameraInfo> EnumerateUsbCameras();
|
||||
|
||||
/// Get the path to the device.
|
||||
std::string GetPath() const;
|
||||
@@ -252,12 +252,12 @@ class USBCamera : public VideoSource {
|
||||
};
|
||||
|
||||
/// A source that represents a MJPEG-over-HTTP (IP) camera.
|
||||
class HTTPCamera : public VideoSource {
|
||||
class HttpCamera : public VideoSource {
|
||||
public:
|
||||
/// 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")
|
||||
HTTPCamera(llvm::StringRef name, llvm::StringRef url);
|
||||
HttpCamera(llvm::StringRef name, llvm::StringRef url);
|
||||
};
|
||||
|
||||
/// A source for user code to provide OpenCV images as video frames.
|
||||
@@ -325,7 +325,7 @@ class VideoSink {
|
||||
public:
|
||||
enum Kind {
|
||||
kUnknown = CS_SINK_UNKNOWN,
|
||||
kMJPEG = CS_SINK_MJPEG,
|
||||
kMjpeg = CS_SINK_MJPEG,
|
||||
kCv = CS_SINK_CV
|
||||
};
|
||||
|
||||
@@ -391,20 +391,20 @@ class VideoSink {
|
||||
};
|
||||
|
||||
/// A sink that acts as a MJPEG-over-HTTP network server.
|
||||
class MJPEGServer : public VideoSink {
|
||||
class MjpegServer : public VideoSink {
|
||||
public:
|
||||
MJPEGServer() = default;
|
||||
MjpegServer() = default;
|
||||
|
||||
/// Create a MJPEG-over-HTTP server sink.
|
||||
/// @param name Sink name (arbitrary unique identifier)
|
||||
/// @param listenAddress TCP listen address (empty string for all addresses)
|
||||
/// @param port TCP port number
|
||||
MJPEGServer(llvm::StringRef name, llvm::StringRef listenAddress, int port);
|
||||
MjpegServer(llvm::StringRef name, llvm::StringRef listenAddress, int port);
|
||||
|
||||
/// Create a MJPEG-over-HTTP server sink.
|
||||
/// @param name Sink name (arbitrary unique identifier)
|
||||
/// @param port TCP port number
|
||||
MJPEGServer(llvm::StringRef name, int port) : MJPEGServer(name, "", port) {}
|
||||
MjpegServer(llvm::StringRef name, int port) : MjpegServer(name, "", port) {}
|
||||
|
||||
/// Get the listen address of the server.
|
||||
std::string GetListenAddress() const;
|
||||
|
||||
@@ -160,25 +160,25 @@ inline std::vector<VideoMode> VideoSource::EnumerateVideoModes() const {
|
||||
return EnumerateSourceVideoModes(m_handle, &status);
|
||||
}
|
||||
|
||||
inline USBCamera::USBCamera(llvm::StringRef name, int dev) {
|
||||
m_handle = CreateUSBCameraDev(name, dev, &m_status);
|
||||
inline UsbCamera::UsbCamera(llvm::StringRef name, int dev) {
|
||||
m_handle = CreateUsbCameraDev(name, dev, &m_status);
|
||||
}
|
||||
|
||||
inline USBCamera::USBCamera(llvm::StringRef name, llvm::StringRef path) {
|
||||
m_handle = CreateUSBCameraPath(name, path, &m_status);
|
||||
inline UsbCamera::UsbCamera(llvm::StringRef name, llvm::StringRef path) {
|
||||
m_handle = CreateUsbCameraPath(name, path, &m_status);
|
||||
}
|
||||
|
||||
inline std::vector<USBCameraInfo> USBCamera::EnumerateUSBCameras() {
|
||||
inline std::vector<UsbCameraInfo> UsbCamera::EnumerateUsbCameras() {
|
||||
CS_Status status = 0;
|
||||
return ::cs::EnumerateUSBCameras(&status);
|
||||
return ::cs::EnumerateUsbCameras(&status);
|
||||
}
|
||||
|
||||
inline std::string USBCamera::GetPath() const {
|
||||
CS_Status status = 0;
|
||||
return ::cs::GetUSBCameraPath(m_handle, &status);
|
||||
inline std::string UsbCamera::GetPath() const {
|
||||
m_status = 0;
|
||||
return ::cs::GetUsbCameraPath(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void USBCamera::SetBrightness(int brightness) {
|
||||
inline void UsbCamera::SetBrightness(int brightness) {
|
||||
if (brightness > 100) {
|
||||
brightness = 100;
|
||||
} else if (brightness < 0) {
|
||||
@@ -187,32 +187,32 @@ inline void USBCamera::SetBrightness(int brightness) {
|
||||
GetProperty(kPropBrValue).Set(brightness);
|
||||
}
|
||||
|
||||
inline int USBCamera::GetBrightness() {
|
||||
inline int UsbCamera::GetBrightness() {
|
||||
return GetProperty(kPropBrValue).Get();
|
||||
}
|
||||
|
||||
inline void USBCamera::SetWhiteBalanceAuto() {
|
||||
inline void UsbCamera::SetWhiteBalanceAuto() {
|
||||
GetProperty(kPropWbAuto).Set(1); // auto
|
||||
}
|
||||
|
||||
inline void USBCamera::SetWhiteBalanceHoldCurrent() {
|
||||
inline void UsbCamera::SetWhiteBalanceHoldCurrent() {
|
||||
GetProperty(kPropWbAuto).Set(0); // manual
|
||||
}
|
||||
|
||||
inline void USBCamera::SetWhiteBalanceManual(int value) {
|
||||
inline void UsbCamera::SetWhiteBalanceManual(int value) {
|
||||
GetProperty(kPropWbAuto).Set(0); // manual
|
||||
GetProperty(kPropWbValue).Set(value);
|
||||
}
|
||||
|
||||
inline void USBCamera::SetExposureAuto() {
|
||||
inline void UsbCamera::SetExposureAuto() {
|
||||
GetProperty(kPropExAuto).Set(0); // auto; yes, this is opposite of WB
|
||||
}
|
||||
|
||||
inline void USBCamera::SetExposureHoldCurrent() {
|
||||
inline void UsbCamera::SetExposureHoldCurrent() {
|
||||
GetProperty(kPropExAuto).Set(1); // manual
|
||||
}
|
||||
|
||||
inline void USBCamera::SetExposureManual(int value) {
|
||||
inline void UsbCamera::SetExposureManual(int value) {
|
||||
GetProperty(kPropExAuto).Set(1); // manual
|
||||
if (value > 100) {
|
||||
value = 100;
|
||||
@@ -222,8 +222,8 @@ inline void USBCamera::SetExposureManual(int value) {
|
||||
GetProperty(kPropExValue).Set(value);
|
||||
}
|
||||
|
||||
inline HTTPCamera::HTTPCamera(llvm::StringRef name, llvm::StringRef url) {
|
||||
m_handle = CreateHTTPCamera(name, url, &m_status);
|
||||
inline HttpCamera::HttpCamera(llvm::StringRef name, llvm::StringRef url) {
|
||||
m_handle = CreateHttpCamera(name, url, &m_status);
|
||||
}
|
||||
|
||||
inline CvSource::CvSource(llvm::StringRef name, const VideoMode& mode) {
|
||||
@@ -323,19 +323,19 @@ inline VideoProperty VideoSink::GetSourceProperty(llvm::StringRef name) {
|
||||
return VideoProperty{GetSinkSourceProperty(m_handle, name, &m_status)};
|
||||
}
|
||||
|
||||
inline MJPEGServer::MJPEGServer(llvm::StringRef name,
|
||||
inline MjpegServer::MjpegServer(llvm::StringRef name,
|
||||
llvm::StringRef listenAddress, int port) {
|
||||
m_handle = CreateMJPEGServer(name, listenAddress, port, &m_status);
|
||||
m_handle = CreateMjpegServer(name, listenAddress, port, &m_status);
|
||||
}
|
||||
|
||||
inline std::string MJPEGServer::GetListenAddress() const {
|
||||
inline std::string MjpegServer::GetListenAddress() const {
|
||||
m_status = 0;
|
||||
return cs::GetMJPEGServerListenAddress(m_handle, &m_status);
|
||||
return cs::GetMjpegServerListenAddress(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline int MJPEGServer::GetPort() const {
|
||||
inline int MjpegServer::GetPort() const {
|
||||
m_status = 0;
|
||||
return cs::GetMJPEGServerPort(m_handle, &m_status);
|
||||
return cs::GetMjpegServerPort(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline CvSink::CvSink(llvm::StringRef name) {
|
||||
|
||||
@@ -60,7 +60,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
// Cache references to classes
|
||||
jclass local;
|
||||
|
||||
local = env->FindClass("edu/wpi/cscore/USBCameraInfo");
|
||||
local = env->FindClass("edu/wpi/cscore/UsbCameraInfo");
|
||||
if (!local) return JNI_ERR;
|
||||
usbCameraInfoCls = static_cast<jclass>(env->NewGlobalRef(local));
|
||||
if (!usbCameraInfoCls) return JNI_ERR;
|
||||
@@ -183,7 +183,7 @@ static inline bool CheckStatus(JNIEnv *env, CS_Status status) {
|
||||
return status == CS_OK;
|
||||
}
|
||||
|
||||
static jobject MakeJObject(JNIEnv *env, const cs::USBCameraInfo &info) {
|
||||
static jobject MakeJObject(JNIEnv *env, const cs::UsbCameraInfo &info) {
|
||||
static jmethodID constructor = env->GetMethodID(
|
||||
usbCameraInfoCls, "<init>", "(ILjava/lang/String;Ljava/lang/String;)V");
|
||||
JLocal<jstring> path(env, MakeJString(env, info.path));
|
||||
@@ -382,28 +382,28 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_getEnumProper
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: createUSBCameraDev
|
||||
* Method: createUsbCameraDev
|
||||
* Signature: (Ljava/lang/String;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUSBCameraDev
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev
|
||||
(JNIEnv *env, jclass, jstring name, jint dev)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateUSBCameraDev(JStringRef{env, name}, dev, &status);
|
||||
auto val = cs::CreateUsbCameraDev(JStringRef{env, name}, dev, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: createUSBCameraPath
|
||||
* Method: createUsbCameraPath
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUSBCameraPath
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath
|
||||
(JNIEnv *env, jclass, jstring name, jstring path)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateUSBCameraPath(JStringRef{env, name},
|
||||
auto val = cs::CreateUsbCameraPath(JStringRef{env, name},
|
||||
JStringRef{env, path}, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
@@ -414,11 +414,11 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createUSBCameraPath
|
||||
* Method: createHTTPCamera
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createHTTPCamera
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera
|
||||
(JNIEnv *env, jclass, jstring name, jstring url)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateHTTPCamera(JStringRef{env, name},
|
||||
auto val = cs::CreateHttpCamera(JStringRef{env, name},
|
||||
JStringRef{env, url}, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
@@ -686,14 +686,14 @@ JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_releaseSource
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: getUSBCameraPath
|
||||
* Method: getUsbCameraPath
|
||||
* Signature: (I)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getUSBCameraPath
|
||||
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraPath
|
||||
(JNIEnv *env, jclass, jint source)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto str = cs::GetUSBCameraPath(source, &status);
|
||||
auto str = cs::GetUsbCameraPath(source, &status);
|
||||
if (!CheckStatus(env, status)) return nullptr;
|
||||
return MakeJString(env, str);
|
||||
}
|
||||
@@ -794,14 +794,14 @@ JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSourceEnumProperty
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: createMJPEGServer
|
||||
* Method: createMjpegServer
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createMJPEGServer
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_createMjpegServer
|
||||
(JNIEnv *env, jclass, jstring name, jstring listenAddress, jint port)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateMJPEGServer(
|
||||
auto val = cs::CreateMjpegServer(
|
||||
JStringRef{env, name}, JStringRef{env, listenAddress}, port, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
@@ -935,28 +935,28 @@ JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_releaseSink
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: getMJPEGServerListenAddress
|
||||
* Method: getMjpegServerListenAddress
|
||||
* Signature: (I)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getMJPEGServerListenAddress
|
||||
JNIEXPORT jstring JNICALL Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerListenAddress
|
||||
(JNIEnv *env, jclass, jint sink)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto str = cs::GetMJPEGServerListenAddress(sink, &status);
|
||||
auto str = cs::GetMjpegServerListenAddress(sink, &status);
|
||||
if (!CheckStatus(env, status)) return nullptr;
|
||||
return MakeJString(env, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: getMJPEGServerPort
|
||||
* Method: getMjpegServerPort
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getMJPEGServerPort
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerPort
|
||||
(JNIEnv *env, jclass, jint sink)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val = cs::GetMJPEGServerPort(sink, &status);
|
||||
auto val = cs::GetMjpegServerPort(sink, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
@@ -1082,14 +1082,14 @@ JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_removeListener
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: enumerateUSBCameras
|
||||
* Signature: ()[Ledu/wpi/cameraserver/USBCameraInfo;
|
||||
* Method: enumerateUsbCameras
|
||||
* Signature: ()[Ledu/wpi/cameraserver/UsbCameraInfo;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateUSBCameras
|
||||
JNIEXPORT jobjectArray JNICALL Java_edu_wpi_cscore_CameraServerJNI_enumerateUsbCameras
|
||||
(JNIEnv *env, jclass)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto arr = cs::EnumerateUSBCameras(&status);
|
||||
auto arr = cs::EnumerateUsbCameras(&status);
|
||||
if (!CheckStatus(env, status)) return nullptr;
|
||||
jobjectArray jarr =
|
||||
env->NewObjectArray(arr.size(), usbCameraInfoCls, nullptr);
|
||||
|
||||
@@ -102,9 +102,9 @@ public class CameraServerJNI {
|
||||
//
|
||||
// Source Creation Functions
|
||||
//
|
||||
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 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 createCvSource(String name, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
//
|
||||
@@ -128,9 +128,9 @@ public class CameraServerJNI {
|
||||
public static native void releaseSource(int source);
|
||||
|
||||
//
|
||||
// USBCamera Source Functions
|
||||
// UsbCamera Source Functions
|
||||
//
|
||||
public static native String getUSBCameraPath(int source);
|
||||
public static native String getUsbCameraPath(int source);
|
||||
|
||||
//
|
||||
// OpenCV Source Functions
|
||||
@@ -145,7 +145,7 @@ public class CameraServerJNI {
|
||||
//
|
||||
// Sink Creation Functions
|
||||
//
|
||||
public static native int createMJPEGServer(String name, String listenAddress, int port);
|
||||
public static native int createMjpegServer(String name, String listenAddress, int port);
|
||||
public static native int createCvSink(String name);
|
||||
//public static native int createCvSinkCallback(String name,
|
||||
// void (*processFrame)(long time));
|
||||
@@ -163,10 +163,10 @@ public class CameraServerJNI {
|
||||
public static native void releaseSink(int sink);
|
||||
|
||||
//
|
||||
// MJPEGServer Sink Functions
|
||||
// MjpegServer Sink Functions
|
||||
//
|
||||
public static native String getMJPEGServerListenAddress(int sink);
|
||||
public static native int getMJPEGServerPort(int sink);
|
||||
public static native String getMjpegServerListenAddress(int sink);
|
||||
public static native int getMjpegServerPort(int sink);
|
||||
|
||||
//
|
||||
// OpenCV Sink Functions
|
||||
@@ -187,7 +187,7 @@ public class CameraServerJNI {
|
||||
//
|
||||
// Utility Functions
|
||||
//
|
||||
public static native USBCameraInfo[] enumerateUSBCameras();
|
||||
public static native UsbCameraInfo[] enumerateUsbCameras();
|
||||
|
||||
public static native int[] enumerateSources();
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/// A source that represents a MJPEG-over-HTTP (IP) camera.
|
||||
public class HTTPCamera extends VideoSource {
|
||||
public class HttpCamera extends VideoSource {
|
||||
/// 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));
|
||||
public HttpCamera(String name, String url) {
|
||||
super(CameraServerJNI.createHttpCamera(name, url));
|
||||
}
|
||||
}
|
||||
@@ -8,29 +8,29 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/// A sink that acts as a MJPEG-over-HTTP network server.
|
||||
public class MJPEGServer extends VideoSink {
|
||||
public class MjpegServer extends VideoSink {
|
||||
/// Create a MJPEG-over-HTTP server sink.
|
||||
/// @param name Sink name (arbitrary unique identifier)
|
||||
/// @param listenAddress TCP listen address (empty string for all addresses)
|
||||
/// @param port TCP port number
|
||||
public MJPEGServer(String name, String listenAddress, int port) {
|
||||
super(CameraServerJNI.createMJPEGServer(name, listenAddress, port));
|
||||
public MjpegServer(String name, String listenAddress, int port) {
|
||||
super(CameraServerJNI.createMjpegServer(name, listenAddress, port));
|
||||
}
|
||||
|
||||
/// Create a MJPEG-over-HTTP server sink.
|
||||
/// @param name Sink name (arbitrary unique identifier)
|
||||
/// @param port TCP port number
|
||||
public MJPEGServer(String name, int port) {
|
||||
public MjpegServer(String name, int port) {
|
||||
this(name, "", port);
|
||||
}
|
||||
|
||||
/// Get the listen address of the server.
|
||||
public String getListenAddress() {
|
||||
return CameraServerJNI.getMJPEGServerListenAddress(m_handle);
|
||||
return CameraServerJNI.getMjpegServerListenAddress(m_handle);
|
||||
}
|
||||
|
||||
/// Get the port number of the server.
|
||||
public int getPort() {
|
||||
return CameraServerJNI.getMJPEGServerPort(m_handle);
|
||||
return CameraServerJNI.getMjpegServerPort(m_handle);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/// A source that represents a USB camera.
|
||||
public class USBCamera extends VideoSource {
|
||||
public class UsbCamera extends VideoSource {
|
||||
private static final String kPropWbAuto = "white_balance_temperature_auto";
|
||||
private static final String kPropWbValue = "white_balance_temperature";
|
||||
private static final String kPropExAuto = "exposure_auto";
|
||||
@@ -33,26 +33,26 @@ public class USBCamera extends VideoSource {
|
||||
/// Create a source for a USB camera based on device number.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param dev Device number (e.g. 0 for /dev/video0)
|
||||
public USBCamera(String name, int dev) {
|
||||
super(CameraServerJNI.createUSBCameraDev(name, dev));
|
||||
public UsbCamera(String name, int dev) {
|
||||
super(CameraServerJNI.createUsbCameraDev(name, dev));
|
||||
}
|
||||
|
||||
/// Create a source for a USB camera based on device path.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param path Path to device (e.g. "/dev/video0" on Linux)
|
||||
public USBCamera(String name, String path) {
|
||||
super(CameraServerJNI.createUSBCameraPath(name, path));
|
||||
public UsbCamera(String name, String path) {
|
||||
super(CameraServerJNI.createUsbCameraPath(name, path));
|
||||
}
|
||||
|
||||
/// Enumerate USB cameras on the local system.
|
||||
/// @return Vector of USB camera information (one for each camera)
|
||||
public static USBCameraInfo[] enumerateUSBCameras() {
|
||||
return CameraServerJNI.enumerateUSBCameras();
|
||||
public static UsbCameraInfo[] enumerateUsbCameras() {
|
||||
return CameraServerJNI.enumerateUsbCameras();
|
||||
}
|
||||
|
||||
/// Get the path to the device.
|
||||
public String getPath() {
|
||||
return CameraServerJNI.getUSBCameraPath(m_handle);
|
||||
return CameraServerJNI.getUsbCameraPath(m_handle);
|
||||
}
|
||||
|
||||
/// Set the brightness, as a percentage (0-100).
|
||||
@@ -8,8 +8,8 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/// USB camera information
|
||||
public class USBCameraInfo {
|
||||
public USBCameraInfo(int dev, String path, String name) {
|
||||
public class UsbCameraInfo {
|
||||
public UsbCameraInfo(int dev, String path, String name) {
|
||||
this.dev = dev;
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
@@ -12,7 +12,7 @@ package edu.wpi.cscore;
|
||||
/// are called channels.
|
||||
public class VideoSink {
|
||||
public enum Kind {
|
||||
kUnknown(0), kMJPEG(2), kCv(4);
|
||||
kUnknown(0), kMjpeg(2), kCv(4);
|
||||
private int value;
|
||||
|
||||
private Kind(int value) {
|
||||
@@ -26,7 +26,7 @@ public class VideoSink {
|
||||
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 2: return Kind.kMJPEG;
|
||||
case 2: return Kind.kMjpeg;
|
||||
case 4: return Kind.kCv;
|
||||
default: return Kind.kUnknown;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ package edu.wpi.cscore;
|
||||
/// are called channels.
|
||||
public class VideoSource {
|
||||
public enum Kind {
|
||||
kUnknown(0), kUSB(1), kHTTP(2), kCv(4);
|
||||
kUnknown(0), kUsb(1), kHttp(2), kCv(4);
|
||||
private int value;
|
||||
|
||||
private Kind(int value) {
|
||||
@@ -26,8 +26,8 @@ public class VideoSource {
|
||||
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 1: return Kind.kUSB;
|
||||
case 2: return Kind.kHTTP;
|
||||
case 1: return Kind.kUsb;
|
||||
case 2: return Kind.kHttp;
|
||||
case 4: return Kind.kCv;
|
||||
default: return Kind.kUnknown;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "MJPEGServerImpl.h"
|
||||
#include "MjpegServerImpl.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
@@ -74,7 +74,7 @@ static const unsigned char dhtData[] = {
|
||||
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa};
|
||||
|
||||
class MJPEGServerImpl::ConnThread : public wpi::SafeThread {
|
||||
class MjpegServerImpl::ConnThread : public wpi::SafeThread {
|
||||
public:
|
||||
void Main();
|
||||
|
||||
@@ -211,7 +211,7 @@ static bool UnescapeURI(llvm::StringRef str, llvm::SmallVectorImpl<char>& out) {
|
||||
}
|
||||
|
||||
// Perform a command specified by HTTP GET parameters.
|
||||
bool MJPEGServerImpl::ConnThread::ProcessCommand(llvm::raw_ostream& os,
|
||||
bool MjpegServerImpl::ConnThread::ProcessCommand(llvm::raw_ostream& os,
|
||||
SourceImpl& source,
|
||||
llvm::StringRef parameters,
|
||||
bool respond) {
|
||||
@@ -347,7 +347,7 @@ bool MJPEGServerImpl::ConnThread::ProcessCommand(llvm::raw_ostream& os,
|
||||
}
|
||||
|
||||
// Send a JSON file which is contains information about the source parameters.
|
||||
void MJPEGServerImpl::ConnThread::SendJSON(llvm::raw_ostream& os,
|
||||
void MjpegServerImpl::ConnThread::SendJSON(llvm::raw_ostream& os,
|
||||
SourceImpl& source, bool header) {
|
||||
if (header) SendHeader(os, 200, "OK", "application/x-javascript");
|
||||
|
||||
@@ -413,7 +413,7 @@ void MJPEGServerImpl::ConnThread::SendJSON(llvm::raw_ostream& os,
|
||||
os.flush();
|
||||
}
|
||||
|
||||
MJPEGServerImpl::MJPEGServerImpl(llvm::StringRef name,
|
||||
MjpegServerImpl::MjpegServerImpl(llvm::StringRef name,
|
||||
llvm::StringRef listenAddress, int port,
|
||||
std::unique_ptr<wpi::NetworkAcceptor> acceptor)
|
||||
: SinkImpl{name},
|
||||
@@ -427,12 +427,12 @@ MJPEGServerImpl::MJPEGServerImpl(llvm::StringRef name,
|
||||
desc << "HTTP Server on port " << port;
|
||||
SetDescription(desc.str());
|
||||
|
||||
m_serverThread = std::thread(&MJPEGServerImpl::ServerThreadMain, this);
|
||||
m_serverThread = std::thread(&MjpegServerImpl::ServerThreadMain, this);
|
||||
}
|
||||
|
||||
MJPEGServerImpl::~MJPEGServerImpl() { Stop(); }
|
||||
MjpegServerImpl::~MjpegServerImpl() { Stop(); }
|
||||
|
||||
void MJPEGServerImpl::Stop() {
|
||||
void MjpegServerImpl::Stop() {
|
||||
m_active = false;
|
||||
|
||||
// wake up server thread by shutting down the socket
|
||||
@@ -472,7 +472,7 @@ static bool NeedsDHT(const char* data, std::size_t* size, std::size_t* locSOF) {
|
||||
}
|
||||
|
||||
// Send HTTP response and a stream of JPG-frames
|
||||
void MJPEGServerImpl::ConnThread::SendStream(wpi::raw_socket_ostream& os) {
|
||||
void MjpegServerImpl::ConnThread::SendStream(wpi::raw_socket_ostream& os) {
|
||||
os.SetUnbuffered();
|
||||
|
||||
llvm::SmallString<256> header;
|
||||
@@ -546,7 +546,7 @@ void MJPEGServerImpl::ConnThread::SendStream(wpi::raw_socket_ostream& os) {
|
||||
StopStream();
|
||||
}
|
||||
|
||||
void MJPEGServerImpl::ConnThread::ProcessRequest() {
|
||||
void MjpegServerImpl::ConnThread::ProcessRequest() {
|
||||
wpi::raw_socket_istream is{*m_stream};
|
||||
wpi::raw_socket_ostream os{*m_stream, true};
|
||||
|
||||
@@ -645,7 +645,7 @@ void MJPEGServerImpl::ConnThread::ProcessRequest() {
|
||||
}
|
||||
|
||||
// worker thread for clients that connected to this server
|
||||
void MJPEGServerImpl::ConnThread::Main() {
|
||||
void MjpegServerImpl::ConnThread::Main() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
while (!m_stream) {
|
||||
@@ -660,7 +660,7 @@ void MJPEGServerImpl::ConnThread::Main() {
|
||||
}
|
||||
|
||||
// Main server thread
|
||||
void MJPEGServerImpl::ServerThreadMain() {
|
||||
void MjpegServerImpl::ServerThreadMain() {
|
||||
if (m_acceptor->start() != 0) {
|
||||
m_active = false;
|
||||
return;
|
||||
@@ -707,7 +707,7 @@ void MJPEGServerImpl::ServerThreadMain() {
|
||||
DEBUG("leaving server thread");
|
||||
}
|
||||
|
||||
void MJPEGServerImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {
|
||||
void MjpegServerImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (auto& connThread : m_connThreads) {
|
||||
if (auto thr = connThread.GetThread()) {
|
||||
@@ -723,10 +723,10 @@ void MJPEGServerImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {
|
||||
|
||||
namespace cs {
|
||||
|
||||
CS_Sink CreateMJPEGServer(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
CS_Sink CreateMjpegServer(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
int port, CS_Status* status) {
|
||||
llvm::SmallString<128> str{listenAddress};
|
||||
auto sink = std::make_shared<MJPEGServerImpl>(
|
||||
auto sink = std::make_shared<MjpegServerImpl>(
|
||||
name, listenAddress, port,
|
||||
std::unique_ptr<wpi::NetworkAcceptor>(
|
||||
new wpi::TCPAcceptor(port, str.c_str(), Logger::GetInstance())));
|
||||
@@ -735,39 +735,39 @@ CS_Sink CreateMJPEGServer(llvm::StringRef name, llvm::StringRef listenAddress,
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::string GetMJPEGServerListenAddress(CS_Sink sink, CS_Status* status) {
|
||||
std::string GetMjpegServerListenAddress(CS_Sink sink, CS_Status* status) {
|
||||
auto data = Sinks::GetInstance().Get(sink);
|
||||
if (!data || data->kind != CS_SINK_MJPEG) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return std::string{};
|
||||
}
|
||||
return static_cast<MJPEGServerImpl&>(*data->sink).GetListenAddress();
|
||||
return static_cast<MjpegServerImpl&>(*data->sink).GetListenAddress();
|
||||
}
|
||||
|
||||
int GetMJPEGServerPort(CS_Sink sink, CS_Status* status) {
|
||||
int GetMjpegServerPort(CS_Sink sink, CS_Status* status) {
|
||||
auto data = Sinks::GetInstance().Get(sink);
|
||||
if (!data || data->kind != CS_SINK_MJPEG) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return static_cast<MJPEGServerImpl&>(*data->sink).GetPort();
|
||||
return static_cast<MjpegServerImpl&>(*data->sink).GetPort();
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
|
||||
CS_Sink CS_CreateMJPEGServer(const char* name, const char* listenAddress,
|
||||
CS_Sink CS_CreateMjpegServer(const char* name, const char* listenAddress,
|
||||
int port, CS_Status* status) {
|
||||
return cs::CreateMJPEGServer(name, listenAddress, port, status);
|
||||
return cs::CreateMjpegServer(name, listenAddress, port, status);
|
||||
}
|
||||
|
||||
char* CS_GetMJPEGServerListenAddress(CS_Sink sink, CS_Status* status) {
|
||||
return ConvertToC(cs::GetMJPEGServerListenAddress(sink, status));
|
||||
char* CS_GetMjpegServerListenAddress(CS_Sink sink, CS_Status* status) {
|
||||
return ConvertToC(cs::GetMjpegServerListenAddress(sink, status));
|
||||
}
|
||||
|
||||
int CS_GetMJPEGServerPort(CS_Sink sink, CS_Status* status) {
|
||||
return cs::GetMJPEGServerPort(sink, status);
|
||||
int CS_GetMjpegServerPort(CS_Sink sink, CS_Status* status) {
|
||||
return cs::GetMjpegServerPort(sink, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -28,11 +28,11 @@ namespace cs {
|
||||
|
||||
class SourceImpl;
|
||||
|
||||
class MJPEGServerImpl : public SinkImpl {
|
||||
class MjpegServerImpl : public SinkImpl {
|
||||
public:
|
||||
MJPEGServerImpl(llvm::StringRef name, llvm::StringRef listenAddress, int port,
|
||||
MjpegServerImpl(llvm::StringRef name, llvm::StringRef listenAddress, int port,
|
||||
std::unique_ptr<wpi::NetworkAcceptor> acceptor);
|
||||
~MJPEGServerImpl() override;
|
||||
~MjpegServerImpl() override;
|
||||
|
||||
void Stop();
|
||||
std::string GetListenAddress() { return m_listenAddress; }
|
||||
@@ -14,21 +14,21 @@
|
||||
|
||||
namespace cs {
|
||||
|
||||
class USBCameraBuffer {
|
||||
class UsbCameraBuffer {
|
||||
public:
|
||||
USBCameraBuffer() noexcept : m_data{nullptr}, m_length{0} {}
|
||||
USBCameraBuffer(USBCameraBuffer&& other) noexcept : USBCameraBuffer() {
|
||||
UsbCameraBuffer() noexcept : m_data{nullptr}, m_length{0} {}
|
||||
UsbCameraBuffer(UsbCameraBuffer&& other) noexcept : UsbCameraBuffer() {
|
||||
swap(*this, other);
|
||||
}
|
||||
USBCameraBuffer& operator=(USBCameraBuffer&& other) noexcept {
|
||||
UsbCameraBuffer& operator=(UsbCameraBuffer&& other) noexcept {
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
USBCameraBuffer(const USBCameraBuffer&) = delete;
|
||||
USBCameraBuffer& operator=(const USBCameraBuffer&) = delete;
|
||||
UsbCameraBuffer(const UsbCameraBuffer&) = delete;
|
||||
UsbCameraBuffer& operator=(const UsbCameraBuffer&) = delete;
|
||||
|
||||
#ifdef __linux__
|
||||
USBCameraBuffer(int fd, size_t length, off_t offset) noexcept
|
||||
UsbCameraBuffer(int fd, size_t length, off_t offset) noexcept
|
||||
: m_length{length} {
|
||||
m_data =
|
||||
mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
|
||||
@@ -38,12 +38,12 @@ class USBCameraBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
~USBCameraBuffer() {
|
||||
~UsbCameraBuffer() {
|
||||
if (m_data) munmap(m_data, m_length);
|
||||
}
|
||||
#endif
|
||||
|
||||
friend void swap(USBCameraBuffer& first, USBCameraBuffer& second) noexcept {
|
||||
friend void swap(UsbCameraBuffer& first, UsbCameraBuffer& second) noexcept {
|
||||
using std::swap;
|
||||
swap(first.m_data, second.m_data);
|
||||
swap(first.m_length, second.m_length);
|
||||
@@ -5,7 +5,7 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "USBCameraImpl.h"
|
||||
#include "UsbCameraImpl.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -86,7 +86,7 @@ static llvm::StringRef NormalizeName(llvm::StringRef name,
|
||||
}
|
||||
|
||||
#ifdef VIDIOC_QUERY_EXT_CTRL
|
||||
USBCameraImpl::PropertyData::PropertyData(
|
||||
UsbCameraImpl::PropertyData::PropertyData(
|
||||
const struct v4l2_query_ext_ctrl& ctrl)
|
||||
: PropertyBase(llvm::StringRef{}, CS_PROP_NONE, ctrl.minimum, ctrl.maximum,
|
||||
ctrl.step, ctrl.default_value, 0),
|
||||
@@ -120,7 +120,7 @@ USBCameraImpl::PropertyData::PropertyData(
|
||||
}
|
||||
#endif
|
||||
|
||||
USBCameraImpl::PropertyData::PropertyData(const struct v4l2_queryctrl& ctrl)
|
||||
UsbCameraImpl::PropertyData::PropertyData(const struct v4l2_queryctrl& ctrl)
|
||||
: PropertyBase(llvm::StringRef{}, CS_PROP_NONE, ctrl.minimum, ctrl.maximum,
|
||||
ctrl.step, ctrl.default_value, 0),
|
||||
id(ctrl.id & V4L2_CTRL_ID_MASK),
|
||||
@@ -171,10 +171,10 @@ static inline int CheckedIoctl(int fd, unsigned long req, void* data,
|
||||
#define TryIoctl(fd, req, data) \
|
||||
CheckedIoctl(fd, req, data, #req, __FILE__, __LINE__, true)
|
||||
|
||||
static std::unique_ptr<USBCameraImpl::PropertyData> ExtCtrlIoctl(int fd,
|
||||
static std::unique_ptr<UsbCameraImpl::PropertyData> ExtCtrlIoctl(int fd,
|
||||
__u32* id) {
|
||||
int rc;
|
||||
std::unique_ptr<USBCameraImpl::PropertyData> prop;
|
||||
std::unique_ptr<UsbCameraImpl::PropertyData> prop;
|
||||
#ifdef VIDIOC_QUERY_EXT_CTRL
|
||||
v4l2_query_ext_ctrl qc_ext;
|
||||
std::memset(&qc_ext, 0, sizeof(qc_ext));
|
||||
@@ -184,7 +184,7 @@ static std::unique_ptr<USBCameraImpl::PropertyData> ExtCtrlIoctl(int fd,
|
||||
*id = qc_ext.id; // copy back
|
||||
// We don't support array types
|
||||
if (qc_ext.elems > 1 || qc_ext.nr_of_dims > 0) return nullptr;
|
||||
prop = llvm::make_unique<USBCameraImpl::PropertyData>(qc_ext);
|
||||
prop = llvm::make_unique<UsbCameraImpl::PropertyData>(qc_ext);
|
||||
}
|
||||
#endif
|
||||
if (!prop) {
|
||||
@@ -195,7 +195,7 @@ static std::unique_ptr<USBCameraImpl::PropertyData> ExtCtrlIoctl(int fd,
|
||||
rc = TryIoctl(fd, VIDIOC_QUERYCTRL, &qc);
|
||||
*id = qc.id; // copy back
|
||||
if (rc != 0) return nullptr;
|
||||
prop = llvm::make_unique<USBCameraImpl::PropertyData>(qc);
|
||||
prop = llvm::make_unique<UsbCameraImpl::PropertyData>(qc);
|
||||
}
|
||||
|
||||
// Cache enum property choices
|
||||
@@ -370,7 +370,7 @@ static std::string GetDescriptionImpl(const char* cpath) {
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
USBCameraImpl::USBCameraImpl(llvm::StringRef name, llvm::StringRef path)
|
||||
UsbCameraImpl::UsbCameraImpl(llvm::StringRef name, llvm::StringRef path)
|
||||
: SourceImpl{name},
|
||||
m_path{path},
|
||||
m_fd{-1},
|
||||
@@ -379,7 +379,7 @@ USBCameraImpl::USBCameraImpl(llvm::StringRef name, llvm::StringRef path)
|
||||
SetDescription(GetDescriptionImpl(m_path.c_str()));
|
||||
}
|
||||
|
||||
USBCameraImpl::~USBCameraImpl() {
|
||||
UsbCameraImpl::~UsbCameraImpl() {
|
||||
m_active = false;
|
||||
|
||||
// Just in case anyone is waiting...
|
||||
@@ -404,12 +404,12 @@ static inline void DoFdSet(int fd, fd_set* set, int* nfds) {
|
||||
}
|
||||
}
|
||||
|
||||
void USBCameraImpl::Start() {
|
||||
void UsbCameraImpl::Start() {
|
||||
// Kick off the camera thread
|
||||
m_cameraThread = std::thread(&USBCameraImpl::CameraThreadMain, this);
|
||||
m_cameraThread = std::thread(&UsbCameraImpl::CameraThreadMain, this);
|
||||
}
|
||||
|
||||
void USBCameraImpl::CameraThreadMain() {
|
||||
void UsbCameraImpl::CameraThreadMain() {
|
||||
// We want to be notified on file creation and deletion events in the device
|
||||
// path. This is used to detect disconnects and reconnects.
|
||||
std::unique_ptr<wpi::raw_fd_istream> notify_is;
|
||||
@@ -583,13 +583,13 @@ void USBCameraImpl::CameraThreadMain() {
|
||||
DeviceDisconnect();
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceDisconnect() {
|
||||
void UsbCameraImpl::DeviceDisconnect() {
|
||||
int fd = m_fd.exchange(-1);
|
||||
if (fd < 0) return; // already disconnected
|
||||
|
||||
// Unmap buffers
|
||||
for (int i = 0; i < kNumBuffers; ++i)
|
||||
m_buffers[i] = std::move(USBCameraBuffer{});
|
||||
m_buffers[i] = std::move(UsbCameraBuffer{});
|
||||
|
||||
// Close device
|
||||
close(fd);
|
||||
@@ -598,7 +598,7 @@ void USBCameraImpl::DeviceDisconnect() {
|
||||
Notifier::GetInstance().NotifySource(*this, CS_SOURCE_DISCONNECTED);
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceConnect() {
|
||||
void UsbCameraImpl::DeviceConnect() {
|
||||
if (m_fd >= 0) return;
|
||||
|
||||
INFO("Connecting to USB camera on " << m_path);
|
||||
@@ -673,11 +673,11 @@ void USBCameraImpl::DeviceConnect() {
|
||||
DEBUG4("USB " << m_path << ": buf " << i << " length=" << buf.length
|
||||
<< " offset=" << buf.m.offset);
|
||||
|
||||
m_buffers[i] = std::move(USBCameraBuffer(fd, buf.length, buf.m.offset));
|
||||
m_buffers[i] = std::move(UsbCameraBuffer(fd, buf.length, buf.m.offset));
|
||||
if (!m_buffers[i].m_data) {
|
||||
WARNING("USB " << m_path << ": could not map buffer " << i);
|
||||
// release other buffers
|
||||
for (int j = 0; j < i; ++j) m_buffers[j] = std::move(USBCameraBuffer{});
|
||||
for (int j = 0; j < i; ++j) m_buffers[j] = std::move(UsbCameraBuffer{});
|
||||
close(fd);
|
||||
m_fd = -1;
|
||||
return;
|
||||
@@ -694,7 +694,7 @@ void USBCameraImpl::DeviceConnect() {
|
||||
Notifier::GetInstance().NotifySource(*this, CS_SOURCE_CONNECTED);
|
||||
}
|
||||
|
||||
bool USBCameraImpl::DeviceStreamOn() {
|
||||
bool UsbCameraImpl::DeviceStreamOn() {
|
||||
if (m_streaming) return false; // ignore if already enabled
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return false;
|
||||
@@ -721,7 +721,7 @@ bool USBCameraImpl::DeviceStreamOn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::DeviceStreamOff() {
|
||||
bool UsbCameraImpl::DeviceStreamOff() {
|
||||
if (!m_streaming) return false; // ignore if already disabled
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return false;
|
||||
@@ -732,7 +732,7 @@ bool USBCameraImpl::DeviceStreamOff() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceProcessCommands() {
|
||||
void UsbCameraImpl::DeviceProcessCommands() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
if (m_commands.empty()) return;
|
||||
while (!m_commands.empty()) {
|
||||
@@ -877,7 +877,7 @@ done:
|
||||
m_responseCv.notify_all();
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceSetMode() {
|
||||
void UsbCameraImpl::DeviceSetMode() {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return;
|
||||
|
||||
@@ -918,7 +918,7 @@ void USBCameraImpl::DeviceSetMode() {
|
||||
}
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceSetFPS() {
|
||||
void UsbCameraImpl::DeviceSetFPS() {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return;
|
||||
|
||||
@@ -936,7 +936,7 @@ void USBCameraImpl::DeviceSetFPS() {
|
||||
INFO("USB " << m_path << ": set FPS to " << m_mode.fps);
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceCacheMode() {
|
||||
void UsbCameraImpl::DeviceCacheMode() {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return;
|
||||
|
||||
@@ -1044,7 +1044,7 @@ void USBCameraImpl::DeviceCacheMode() {
|
||||
Notifier::GetInstance().NotifySource(*this, CS_SOURCE_VIDEOMODE_CHANGED);
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceCacheProperty(std::unique_ptr<PropertyData> prop) {
|
||||
void UsbCameraImpl::DeviceCacheProperty(std::unique_ptr<PropertyData> prop) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
int& ndx = m_properties[prop->name];
|
||||
if (ndx == 0) {
|
||||
@@ -1087,7 +1087,7 @@ void USBCameraImpl::DeviceCacheProperty(std::unique_ptr<PropertyData> prop) {
|
||||
llvm::StringRef{});
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceCacheProperties() {
|
||||
void UsbCameraImpl::DeviceCacheProperties() {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return;
|
||||
|
||||
@@ -1116,7 +1116,7 @@ void USBCameraImpl::DeviceCacheProperties() {
|
||||
}
|
||||
}
|
||||
|
||||
void USBCameraImpl::DeviceCacheVideoModes() {
|
||||
void UsbCameraImpl::DeviceCacheVideoModes() {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return;
|
||||
|
||||
@@ -1164,7 +1164,7 @@ void USBCameraImpl::DeviceCacheVideoModes() {
|
||||
Notifier::GetInstance().NotifySource(*this, CS_SOURCE_VIDEOMODES_UPDATED);
|
||||
}
|
||||
|
||||
bool USBCameraImpl::DeviceGetProperty(PropertyData* prop) {
|
||||
bool UsbCameraImpl::DeviceGetProperty(PropertyData* prop) {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return true;
|
||||
int rv = 0;
|
||||
@@ -1189,7 +1189,7 @@ bool USBCameraImpl::DeviceGetProperty(PropertyData* prop) {
|
||||
return rv >= 0;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::DeviceSetProperty(std::unique_lock<std::mutex>& lock,
|
||||
bool UsbCameraImpl::DeviceSetProperty(std::unique_lock<std::mutex>& lock,
|
||||
const PropertyData& prop) {
|
||||
int fd = m_fd.load();
|
||||
if (fd < 0) return true;
|
||||
@@ -1224,7 +1224,7 @@ bool USBCameraImpl::DeviceSetProperty(std::unique_lock<std::mutex>& lock,
|
||||
return rv >= 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<USBCameraImpl::Message> USBCameraImpl::SendAndWait(
|
||||
std::unique_ptr<UsbCameraImpl::Message> UsbCameraImpl::SendAndWait(
|
||||
std::unique_ptr<Message> msg) const {
|
||||
int fd = m_command_fd.load();
|
||||
if (fd < 0) {
|
||||
@@ -1263,7 +1263,7 @@ std::unique_ptr<USBCameraImpl::Message> USBCameraImpl::SendAndWait(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void USBCameraImpl::Send(std::unique_ptr<Message> msg) const {
|
||||
void UsbCameraImpl::Send(std::unique_ptr<Message> msg) const {
|
||||
int fd = m_command_fd.load();
|
||||
if (fd < 0) {
|
||||
// not possible to signal, exit early
|
||||
@@ -1281,7 +1281,7 @@ void USBCameraImpl::Send(std::unique_ptr<Message> msg) const {
|
||||
eventfd_write(fd, 1);
|
||||
}
|
||||
|
||||
bool USBCameraImpl::CacheProperties(CS_Status* status) const {
|
||||
bool UsbCameraImpl::CacheProperties(CS_Status* status) const {
|
||||
// Wake up camera thread; this will try to reconnect
|
||||
auto msg = CreateMessage(Message::kNone);
|
||||
msg = std::move(SendAndWait(std::move(msg)));
|
||||
@@ -1297,9 +1297,9 @@ bool USBCameraImpl::CacheProperties(CS_Status* status) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::IsConnected() const { return m_fd >= 0; }
|
||||
bool UsbCameraImpl::IsConnected() const { return m_fd >= 0; }
|
||||
|
||||
void USBCameraImpl::SetProperty(int property, int value, CS_Status* status) {
|
||||
void UsbCameraImpl::SetProperty(int property, int value, CS_Status* status) {
|
||||
auto msg = CreateMessage(Message::kCmdSetProperty);
|
||||
msg->data[0] = property;
|
||||
msg->data[1] = value;
|
||||
@@ -1309,7 +1309,7 @@ void USBCameraImpl::SetProperty(int property, int value, CS_Status* status) {
|
||||
DestroyMessage(std::move(msg));
|
||||
}
|
||||
|
||||
void USBCameraImpl::SetStringProperty(int property, llvm::StringRef value,
|
||||
void UsbCameraImpl::SetStringProperty(int property, llvm::StringRef value,
|
||||
CS_Status* status) {
|
||||
auto msg = CreateMessage(Message::kCmdSetPropertyStr);
|
||||
msg->data[0] = property;
|
||||
@@ -1320,7 +1320,7 @@ void USBCameraImpl::SetStringProperty(int property, llvm::StringRef value,
|
||||
DestroyMessage(std::move(msg));
|
||||
}
|
||||
|
||||
bool USBCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
|
||||
bool UsbCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
|
||||
auto msg = CreateMessage(Message::kCmdSetMode);
|
||||
msg->data[0] = mode.pixelFormat;
|
||||
msg->data[1] = mode.width;
|
||||
@@ -1337,7 +1337,7 @@ bool USBCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::SetPixelFormat(VideoMode::PixelFormat pixelFormat,
|
||||
bool UsbCameraImpl::SetPixelFormat(VideoMode::PixelFormat pixelFormat,
|
||||
CS_Status* status) {
|
||||
auto msg = CreateMessage(Message::kCmdSetPixelFormat);
|
||||
msg->data[0] = pixelFormat;
|
||||
@@ -1352,7 +1352,7 @@ bool USBCameraImpl::SetPixelFormat(VideoMode::PixelFormat pixelFormat,
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::SetResolution(int width, int height, CS_Status* status) {
|
||||
bool UsbCameraImpl::SetResolution(int width, int height, CS_Status* status) {
|
||||
auto msg = CreateMessage(Message::kCmdSetResolution);
|
||||
msg->data[0] = width;
|
||||
msg->data[1] = height;
|
||||
@@ -1367,7 +1367,7 @@ bool USBCameraImpl::SetResolution(int width, int height, CS_Status* status) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool USBCameraImpl::SetFPS(int fps, CS_Status* status) {
|
||||
bool UsbCameraImpl::SetFPS(int fps, CS_Status* status) {
|
||||
auto msg = CreateMessage(Message::kCmdSetFPS);
|
||||
msg->data[0] = fps;
|
||||
msg = std::move(SendAndWait(std::move(msg)));
|
||||
@@ -1381,26 +1381,26 @@ bool USBCameraImpl::SetFPS(int fps, CS_Status* status) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
void USBCameraImpl::NumSinksChanged() {
|
||||
void UsbCameraImpl::NumSinksChanged() {
|
||||
Send(CreateMessage(Message::kNumSinksChanged));
|
||||
}
|
||||
|
||||
void USBCameraImpl::NumSinksEnabledChanged() {
|
||||
void UsbCameraImpl::NumSinksEnabledChanged() {
|
||||
Send(CreateMessage(Message::kNumSinksEnabledChanged));
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
|
||||
CS_Source CreateUSBCameraDev(llvm::StringRef name, int dev, CS_Status* status) {
|
||||
CS_Source CreateUsbCameraDev(llvm::StringRef name, int dev, CS_Status* status) {
|
||||
llvm::SmallString<32> path;
|
||||
llvm::raw_svector_ostream oss{path};
|
||||
oss << "/dev/video" << dev;
|
||||
return CreateUSBCameraPath(name, oss.str(), status);
|
||||
return CreateUsbCameraPath(name, oss.str(), status);
|
||||
}
|
||||
|
||||
CS_Source CreateUSBCameraPath(llvm::StringRef name, llvm::StringRef path,
|
||||
CS_Source CreateUsbCameraPath(llvm::StringRef name, llvm::StringRef path,
|
||||
CS_Status* status) {
|
||||
auto source = std::make_shared<USBCameraImpl>(name, path);
|
||||
auto source = std::make_shared<UsbCameraImpl>(name, path);
|
||||
auto handle = Sources::GetInstance().Allocate(CS_SOURCE_USB, source);
|
||||
Notifier::GetInstance().NotifySource(name, handle, CS_SOURCE_CREATED);
|
||||
// Start thread after the source created event to ensure other events
|
||||
@@ -1409,24 +1409,24 @@ CS_Source CreateUSBCameraPath(llvm::StringRef name, llvm::StringRef path,
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::string GetUSBCameraPath(CS_Source source, CS_Status* status) {
|
||||
std::string GetUsbCameraPath(CS_Source source, CS_Status* status) {
|
||||
auto data = Sources::GetInstance().Get(source);
|
||||
if (!data || data->kind != CS_SOURCE_USB) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return std::string{};
|
||||
}
|
||||
return static_cast<USBCameraImpl&>(*data->source).GetPath();
|
||||
return static_cast<UsbCameraImpl&>(*data->source).GetPath();
|
||||
}
|
||||
|
||||
std::vector<USBCameraInfo> EnumerateUSBCameras(CS_Status* status) {
|
||||
std::vector<USBCameraInfo> retval;
|
||||
std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
|
||||
std::vector<UsbCameraInfo> retval;
|
||||
|
||||
if (DIR* dp = opendir("/dev")) {
|
||||
while (struct dirent* ep = readdir(dp)) {
|
||||
llvm::StringRef fname{ep->d_name};
|
||||
if (!fname.startswith("video")) continue;
|
||||
|
||||
USBCameraInfo info;
|
||||
UsbCameraInfo info;
|
||||
info.dev = -1;
|
||||
fname.substr(5).getAsInteger(10, info.dev);
|
||||
llvm::SmallString<32> path{"/dev/"};
|
||||
@@ -1447,7 +1447,7 @@ std::vector<USBCameraInfo> EnumerateUSBCameras(CS_Status* status) {
|
||||
|
||||
// sort by device number
|
||||
std::sort(retval.begin(), retval.end(),
|
||||
[](const USBCameraInfo& a, const USBCameraInfo& b) {
|
||||
[](const UsbCameraInfo& a, const UsbCameraInfo& b) {
|
||||
return a.dev < b.dev;
|
||||
});
|
||||
|
||||
@@ -1458,23 +1458,23 @@ std::vector<USBCameraInfo> EnumerateUSBCameras(CS_Status* status) {
|
||||
|
||||
extern "C" {
|
||||
|
||||
CS_Source CS_CreateUSBCameraDev(const char* name, int dev, CS_Status* status) {
|
||||
return cs::CreateUSBCameraDev(name, dev, status);
|
||||
CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status) {
|
||||
return cs::CreateUsbCameraDev(name, dev, status);
|
||||
}
|
||||
|
||||
CS_Source CS_CreateUSBCameraPath(const char* name, const char* path,
|
||||
CS_Source CS_CreateUsbCameraPath(const char* name, const char* path,
|
||||
CS_Status* status) {
|
||||
return cs::CreateUSBCameraPath(name, path, status);
|
||||
return cs::CreateUsbCameraPath(name, path, status);
|
||||
}
|
||||
|
||||
char* CS_GetUSBCameraPath(CS_Source source, CS_Status* status) {
|
||||
return ConvertToC(cs::GetUSBCameraPath(source, status));
|
||||
char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status) {
|
||||
return ConvertToC(cs::GetUsbCameraPath(source, status));
|
||||
}
|
||||
|
||||
CS_USBCameraInfo* CS_EnumerateUSBCameras(int* count, CS_Status* status) {
|
||||
auto cameras = cs::EnumerateUSBCameras(status);
|
||||
CS_USBCameraInfo* out = static_cast<CS_USBCameraInfo*>(
|
||||
std::malloc(cameras.size() * sizeof(CS_USBCameraInfo)));
|
||||
CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status) {
|
||||
auto cameras = cs::EnumerateUsbCameras(status);
|
||||
CS_UsbCameraInfo* out = static_cast<CS_UsbCameraInfo*>(
|
||||
std::malloc(cameras.size() * sizeof(CS_UsbCameraInfo)));
|
||||
*count = cameras.size();
|
||||
for (std::size_t i = 0; i < cameras.size(); ++i) {
|
||||
out[i].dev = cameras[i].dev;
|
||||
@@ -1484,7 +1484,7 @@ CS_USBCameraInfo* CS_EnumerateUSBCameras(int* count, CS_Status* status) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void CS_FreeEnumeratedUSBCameras(CS_USBCameraInfo* cameras, int count) {
|
||||
void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count) {
|
||||
if (!cameras) return;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
std::free(cameras[i].path);
|
||||
@@ -22,14 +22,14 @@
|
||||
#include "support/raw_istream.h"
|
||||
|
||||
#include "SourceImpl.h"
|
||||
#include "USBCameraBuffer.h"
|
||||
#include "UsbCameraBuffer.h"
|
||||
|
||||
namespace cs {
|
||||
|
||||
class USBCameraImpl : public SourceImpl {
|
||||
class UsbCameraImpl : public SourceImpl {
|
||||
public:
|
||||
USBCameraImpl(llvm::StringRef name, llvm::StringRef path);
|
||||
~USBCameraImpl() override;
|
||||
UsbCameraImpl(llvm::StringRef name, llvm::StringRef path);
|
||||
~UsbCameraImpl() override;
|
||||
|
||||
void Start();
|
||||
|
||||
@@ -147,7 +147,7 @@ class USBCameraImpl : public SourceImpl {
|
||||
#endif
|
||||
// Number of buffers to ask OS for
|
||||
static constexpr int kNumBuffers = 4;
|
||||
std::array<USBCameraBuffer, kNumBuffers> m_buffers;
|
||||
std::array<UsbCameraBuffer, kNumBuffers> m_buffers;
|
||||
|
||||
//
|
||||
// Path never changes, so not protected by mutex.
|
||||
@@ -75,9 +75,9 @@ char** CS_GetEnumPropertyChoices(CS_Property property, int* count,
|
||||
return out;
|
||||
}
|
||||
|
||||
CS_Source CS_CreateHTTPCamera(const char* name, const char* url,
|
||||
CS_Source CS_CreateHttpCamera(const char* name, const char* url,
|
||||
CS_Status* status) {
|
||||
return cs::CreateHTTPCamera(name, url, status);
|
||||
return cs::CreateHttpCamera(name, url, status);
|
||||
}
|
||||
|
||||
CS_SourceKind CS_GetSourceKind(CS_Source source, CS_Status* status) {
|
||||
|
||||
@@ -152,7 +152,7 @@ std::vector<std::string> GetEnumPropertyChoices(CS_Property property,
|
||||
// Source Creation Functions
|
||||
//
|
||||
|
||||
CS_Source CreateHTTPCamera(llvm::StringRef name, llvm::StringRef url,
|
||||
CS_Source CreateHttpCamera(llvm::StringRef name, llvm::StringRef url,
|
||||
CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user