mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Add methods to get property name and enumerate properties.
Also add method to remove property by handle.
This commit is contained in:
@@ -52,6 +52,7 @@ enum CS_PropertyType {
|
||||
|
||||
enum CS_PropertyType CS_GetPropertyType(CS_Property property,
|
||||
CS_Status* status);
|
||||
char* CS_GetPropertyName(CS_Property property, CS_Status* status);
|
||||
CS_Bool CS_GetBooleanProperty(CS_Property property, CS_Status* status);
|
||||
void CS_SetBooleanProperty(CS_Property property, CS_Bool value,
|
||||
CS_Status* status);
|
||||
@@ -93,6 +94,8 @@ 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* EnumerateSourceProperties(CS_Source source, int* count,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CopySource(CS_Source source, CS_Status* status);
|
||||
void CS_ReleaseSource(CS_Source source, CS_Status* status);
|
||||
|
||||
@@ -112,10 +115,11 @@ CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
CS_Status* status);
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, void* data,
|
||||
void (*onChange)(void* data, const char* name, CS_Property property),
|
||||
CS_Status* status);
|
||||
void CS_RemoveSourceProperty(CS_Source source, const char* name,
|
||||
void (*onChange)(void* data, CS_Property property), CS_Status* status);
|
||||
void CS_RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status);
|
||||
void CS_RemoveSourcePropertyByName(CS_Source source, const char* name,
|
||||
CS_Status* status);
|
||||
|
||||
//
|
||||
// Sink Creation Functions
|
||||
@@ -205,6 +209,8 @@ void CS_ReleaseEnumeratedSinks(CS_Sink* sinks, int count);
|
||||
void CS_FreeString(char* str);
|
||||
void CS_FreeEnumPropertyChoices(char** choices, int count);
|
||||
|
||||
void CS_FreeEnumeratedProperties(CS_Property* properties, int count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -49,6 +49,9 @@ struct USBCameraInfo {
|
||||
//
|
||||
|
||||
CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status);
|
||||
std::string GetPropertyName(CS_Property property, CS_Status* status);
|
||||
void GetPropertyName(CS_Property property, llvm::SmallVectorImpl<char>& name,
|
||||
CS_Status* status);
|
||||
bool GetBooleanProperty(CS_Property property, CS_Status* status);
|
||||
void SetBooleanProperty(CS_Property property, bool value, CS_Status* status);
|
||||
double GetDoubleProperty(CS_Property property, CS_Status* status);
|
||||
@@ -94,6 +97,9 @@ void GetSourceDescription(CS_Source source, llvm::SmallVectorImpl<char>& desc,
|
||||
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);
|
||||
void EnumerateSourceProperties(CS_Source source,
|
||||
llvm::SmallVectorImpl<CS_Property>& properties,
|
||||
CS_Status* status);
|
||||
CS_Source CopySource(CS_Source source, CS_Status* status);
|
||||
void ReleaseSource(CS_Source source, CS_Status* status);
|
||||
|
||||
@@ -111,8 +117,9 @@ CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_PropertyType type, CS_Status* status);
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type,
|
||||
std::function<void(llvm::StringRef name, CS_Property property)> onChange,
|
||||
CS_Status* status);
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status);
|
||||
void RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status);
|
||||
void RemoveSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_Status* status);
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ class VideoProperty {
|
||||
|
||||
VideoProperty() : m_handle(0), m_type(kNone) {}
|
||||
|
||||
std::string GetName() const;
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
explicit operator bool() const { return m_type != kNone; }
|
||||
@@ -117,6 +119,9 @@ class VideoSource {
|
||||
/// the given name exists)
|
||||
VideoProperty GetProperty(llvm::StringRef name);
|
||||
|
||||
/// Enumerate all properties of this source.
|
||||
std::vector<VideoProperty> EnumerateProperties() const;
|
||||
|
||||
CS_Status GetLastStatus() const { return m_status; }
|
||||
|
||||
/// Enumerate all existing sources.
|
||||
@@ -200,8 +205,11 @@ class CvSource : public VideoSource {
|
||||
/// @return Property
|
||||
VideoProperty CreateProperty(
|
||||
llvm::StringRef name, VideoProperty::Type type,
|
||||
std::function<void(llvm::StringRef name, VideoProperty property)>
|
||||
onChange);
|
||||
std::function<void(VideoProperty property)> onChange);
|
||||
|
||||
/// Remove a property.
|
||||
/// @param property Property
|
||||
void RemoveProperty(VideoProperty property);
|
||||
|
||||
/// Remove a property.
|
||||
/// @param name Property name
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
namespace cs {
|
||||
|
||||
inline std::string VideoProperty::GetName() const {
|
||||
m_status = 0;
|
||||
return GetPropertyName(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline bool VideoProperty::GetBoolean() const {
|
||||
m_status = 0;
|
||||
return GetBooleanProperty(m_handle, &m_status);
|
||||
@@ -187,17 +192,19 @@ inline VideoProperty CvSource::CreateProperty(llvm::StringRef name,
|
||||
|
||||
inline VideoProperty CvSource::CreateProperty(
|
||||
llvm::StringRef name, VideoProperty::Type type,
|
||||
std::function<void(llvm::StringRef name, VideoProperty property)>
|
||||
onChange) {
|
||||
std::function<void(VideoProperty property)> onChange) {
|
||||
m_status = 0;
|
||||
return VideoProperty{CreateSourcePropertyCallback(
|
||||
m_handle, name, static_cast<CS_PropertyType>(static_cast<int>(type)),
|
||||
[=](llvm::StringRef name, CS_Property property) {
|
||||
onChange(name, VideoProperty{property});
|
||||
},
|
||||
[=](CS_Property property) { onChange(VideoProperty{property}); },
|
||||
&m_status)};
|
||||
}
|
||||
|
||||
inline void CvSource::RemoveProperty(VideoProperty property) {
|
||||
m_status = 0;
|
||||
RemoveSourceProperty(m_handle, property.m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void CvSource::RemoveProperty(llvm::StringRef name) {
|
||||
m_status = 0;
|
||||
RemoveSourceProperty(m_handle, name, &m_status);
|
||||
|
||||
@@ -69,6 +69,7 @@ public class CameraServerJNI {
|
||||
// Property Functions
|
||||
//
|
||||
public static native int getPropertyType(int property);
|
||||
public static native String getPropertyName(int property);
|
||||
public static native boolean getBooleanProperty(int property);
|
||||
public static native void setBooleanProperty(int property, boolean value);
|
||||
public static native double getDoubleProperty(int property);
|
||||
@@ -102,6 +103,7 @@ public class CameraServerJNI {
|
||||
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[] enumerateSourceProperties(int source);
|
||||
public static native int copySource(int source);
|
||||
public static native void releaseSource(int source);
|
||||
|
||||
@@ -118,7 +120,8 @@ public class CameraServerJNI {
|
||||
// int type,
|
||||
// void (*onChange)(String name,
|
||||
// int property));
|
||||
public static native void removeSourceProperty(int source, String name);
|
||||
public static native void removeSourceProperty(int source, int property);
|
||||
public static native void removeSourcePropertyByName(int source, String name);
|
||||
|
||||
//
|
||||
// Sink Creation Functions
|
||||
|
||||
@@ -60,9 +60,15 @@ public class CvSource extends VideoSource {
|
||||
// std::function<void(String name, VideoProperty property)>
|
||||
// onChange);
|
||||
|
||||
/// Remove a property.
|
||||
/// @param name Property name
|
||||
//public void removeProperty(VdeoProperty property) {
|
||||
// CameraServerJNI.removeSourceProperty(m_handle, property.m_handle);
|
||||
//}
|
||||
|
||||
/// Remove a property.
|
||||
/// @param name Property name
|
||||
public void removeProperty(String name) {
|
||||
CameraServerJNI.removeSourceProperty(m_handle, name);
|
||||
CameraServerJNI.removeSourcePropertyByName(m_handle, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ public class VideoSource {
|
||||
/// the given name exists)
|
||||
//public VideoProperty getProperty(String name);
|
||||
|
||||
/// Enumerate all properties of this source.
|
||||
//public VideoProperty[] enumerateProperties();
|
||||
|
||||
/// Enumerate all existing sources.
|
||||
/// @return Vector of sources.
|
||||
public static VideoSource[] enumerateSources() {
|
||||
|
||||
@@ -31,6 +31,13 @@ CS_PropertyType CS_GetPropertyType(CS_Property property, CS_Status* status) {
|
||||
return cs::GetPropertyType(property, status);
|
||||
}
|
||||
|
||||
char* CS_GetPropertyName(CS_Property property, CS_Status* status) {
|
||||
llvm::SmallString<128> str;
|
||||
cs::GetPropertyName(property, str, status);
|
||||
if (*status != 0) return nullptr;
|
||||
return ConvertToC(str);
|
||||
}
|
||||
|
||||
CS_Bool CS_GetBooleanProperty(CS_Property property, CS_Status* status) {
|
||||
return cs::GetBooleanProperty(property, status);
|
||||
}
|
||||
@@ -137,6 +144,17 @@ CS_Bool CS_IsSourceConnected(CS_Source source, CS_Status* status) {
|
||||
return cs::IsSourceConnected(source, status);
|
||||
}
|
||||
|
||||
CS_Property* EnumerateSourceProperties(CS_Source source, int* count,
|
||||
CS_Status* status) {
|
||||
llvm::SmallVector<CS_Property, 32> vec;
|
||||
cs::EnumerateSourceProperties(source, vec, status);
|
||||
CS_Property* out =
|
||||
static_cast<CS_Property*>(std::malloc(vec.size() * sizeof(CS_Property)));
|
||||
*count = vec.size();
|
||||
std::copy(vec.begin(), vec.end(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
CS_Source CS_CopySource(CS_Source source, CS_Status* status) {
|
||||
return cs::CopySource(source, status);
|
||||
}
|
||||
@@ -177,24 +195,20 @@ CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, void* data,
|
||||
void (*onChange)(void* data, const char* name, CS_Property property),
|
||||
void (*onChange)(void* data, CS_Property property),
|
||||
CS_Status* status) {
|
||||
return cs::CreateSourcePropertyCallback(
|
||||
source, name, type,
|
||||
[=](llvm::StringRef name, CS_Property property) {
|
||||
// avoid the copy if possible
|
||||
if (name[name.size()] == '\0') {
|
||||
onChange(data, name.data(), property);
|
||||
} else {
|
||||
llvm::SmallString<128> copy{name};
|
||||
onChange(data, copy.c_str(), property);
|
||||
}
|
||||
},
|
||||
status);
|
||||
[=](CS_Property property) { onChange(data, property); }, status);
|
||||
}
|
||||
|
||||
void CS_RemoveSourceProperty(CS_Source source, const char* name,
|
||||
void CS_RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status) {
|
||||
return cs::RemoveSourceProperty(source, property, status);
|
||||
}
|
||||
|
||||
void CS_RemoveSourcePropertyByName(CS_Source source, const char* name,
|
||||
CS_Status* status) {
|
||||
return cs::RemoveSourceProperty(source, name, status);
|
||||
}
|
||||
|
||||
@@ -386,4 +400,8 @@ void CS_FreeEnumPropertyChoices(char** choices, int count) {
|
||||
std::free(choices);
|
||||
}
|
||||
|
||||
void CS_FreeEnumeratedProperties(CS_Property* properties, int count) {
|
||||
std::free(properties);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -21,6 +21,15 @@ CS_PropertyType GetPropertyType(CS_Property property, CS_Status* status) {
|
||||
return CS_PROP_NONE; // TODO
|
||||
}
|
||||
|
||||
std::string GetPropertyName(CS_Property property, CS_Status* status) {
|
||||
return ""; // TODO
|
||||
}
|
||||
|
||||
void GetPropertyName(CS_Property property, llvm::SmallVectorImpl<char>& name,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
bool GetBooleanProperty(CS_Property property, CS_Status* status) {
|
||||
return false; // TODO
|
||||
}
|
||||
@@ -138,6 +147,12 @@ bool IsSourceConnected(CS_Source source, CS_Status* status) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void EnumerateSourceProperties(CS_Source source,
|
||||
llvm::SmallVectorImpl<CS_Property>& properties,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
CS_Source CopySource(CS_Source source, CS_Status* status) {
|
||||
return source; // TODO
|
||||
}
|
||||
@@ -179,11 +194,15 @@ CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type,
|
||||
std::function<void(llvm::StringRef name, CS_Property property)> onChange,
|
||||
CS_Status* status) {
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
void RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void RemoveSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
|
||||
@@ -9,9 +9,20 @@
|
||||
|
||||
using namespace cs;
|
||||
|
||||
std::vector<VideoProperty> VideoSource::EnumerateProperties() const {
|
||||
std::vector<VideoProperty> properties;
|
||||
llvm::SmallVector<CS_Property, 32> handles;
|
||||
CS_Status status = 0;
|
||||
EnumerateSourceProperties(m_handle, handles, &status);
|
||||
properties.reserve(handles.size());
|
||||
for (int handle : handles)
|
||||
properties.emplace_back(VideoProperty{handle});
|
||||
return properties;
|
||||
}
|
||||
|
||||
std::vector<VideoSource> VideoSource::EnumerateSources() {
|
||||
std::vector<VideoSource> sources;
|
||||
llvm::SmallVector<int, 16> handles;
|
||||
llvm::SmallVector<CS_Source, 16> handles;
|
||||
CS_Status status = 0;
|
||||
::cs::EnumerateSources(handles, &status);
|
||||
sources.reserve(handles.size());
|
||||
@@ -22,7 +33,7 @@ std::vector<VideoSource> VideoSource::EnumerateSources() {
|
||||
|
||||
std::vector<VideoSink> VideoSink::EnumerateSinks() {
|
||||
std::vector<VideoSink> sinks;
|
||||
llvm::SmallVector<int, 16> handles;
|
||||
llvm::SmallVector<CS_Sink, 16> handles;
|
||||
CS_Status status = 0;
|
||||
::cs::EnumerateSinks(handles, &status);
|
||||
sinks.reserve(handles.size());
|
||||
|
||||
Reference in New Issue
Block a user