Java: Add VideoProperty implementation.

This commit is contained in:
Peter Johnson
2016-08-26 08:50:58 -07:00
parent 97f1f1c9c4
commit 2f99f81aa6
4 changed files with 122 additions and 8 deletions

View File

@@ -48,7 +48,10 @@ public class CvSource extends VideoSource {
/// @param name Property name
/// @param type Property type
/// @return Property
//public VideoProperty createProperty(String name, VideoProperty.Type type);
public VideoProperty createProperty(String name, VideoProperty.Type type) {
return new VideoProperty(
CameraServerJNI.createSourceProperty(m_handle, name, type.getValue()));
}
/// Create a property with a change callback.
/// @param name Property name
@@ -62,9 +65,9 @@ public class CvSource extends VideoSource {
/// Remove a property.
/// @param name Property name
//public void removeProperty(VdeoProperty property) {
// CameraServerJNI.removeSourceProperty(m_handle, property.m_handle);
//}
public void removeProperty(VideoProperty property) {
CameraServerJNI.removeSourceProperty(m_handle, property.m_handle);
}
/// Remove a property.
/// @param name Property name

View File

@@ -0,0 +1,102 @@
package edu.wpi.cameraserver;
public class VideoProperty {
public enum Type {
kNone(0), kBoolean(1), kDouble(2), kString(3), kEnum(4);
private int value;
private Type(int value) {
this.value = value;
}
public int getValue() {
return value;
}
};
private static final Type[] m_typeValues = Type.values();
public String getName() {
return CameraServerJNI.getPropertyName(m_handle);
}
public Type type() {
return m_type;
}
public boolean isValid() {
return m_type != Type.kNone;
}
// Type checkers
public boolean isBoolean() {
return m_type == Type.kBoolean;
}
public boolean isDouble() {
return m_type == Type.kDouble;
}
public boolean isString() {
return m_type == Type.kString;
}
public boolean isEnum() {
return m_type == Type.kEnum;
}
// Boolean-specific functions
public boolean getBoolean() {
return CameraServerJNI.getBooleanProperty(m_handle);
}
public void setBoolean(boolean value) {
CameraServerJNI.setBooleanProperty(m_handle, value);
}
// Double-specific functions
public double getDouble() {
return CameraServerJNI.getDoubleProperty(m_handle);
}
public void setDouble(double value) {
CameraServerJNI.setDoubleProperty(m_handle, value);
}
public double getMin() {
return CameraServerJNI.getDoublePropertyMin(m_handle);
}
public double getMax() {
return CameraServerJNI.getDoublePropertyMax(m_handle);
}
// String-specific functions
public String getString() {
return CameraServerJNI.getStringProperty(m_handle);
}
public void setString(String value) {
CameraServerJNI.setStringProperty(m_handle, value);
}
// Enum-specific functions
public int getEnum() {
return CameraServerJNI.getEnumProperty(m_handle);
}
public void setEnum(int value) {
CameraServerJNI.setEnumProperty(m_handle, value);
}
public String[] getChoices() {
return CameraServerJNI.getEnumPropertyChoices(m_handle);
}
VideoProperty(int handle) {
m_handle = handle;
m_type = m_typeValues[CameraServerJNI.getPropertyType(handle)];
}
int m_handle;
private Type m_type;
}

View File

@@ -50,8 +50,8 @@ public class VideoSink {
/// @param name Property name
/// @return Property (type Property::kNone if no property with
/// the given name exists or no source connected)
//public VideoProperty getSourceProperty(String name) {
//}
public VideoProperty getSourceProperty(String name) {
return new VideoProperty(CameraServerJNI.getSourceProperty(m_handle, name)); }
/// Enumerate all existing sinks.
/// @return Vector of sinks.

View File

@@ -49,10 +49,19 @@ public class VideoSource {
/// @param name Property name
/// @return Property contents (of type Property::kNone if no property with
/// the given name exists)
//public VideoProperty getProperty(String name);
public VideoProperty getProperty(String name) {
return new VideoProperty(CameraServerJNI.getSourceProperty(m_handle, name));
}
/// Enumerate all properties of this source.
//public VideoProperty[] enumerateProperties();
public VideoProperty[] enumerateProperties() {
int[] handles = CameraServerJNI.enumerateSourceProperties(m_handle);
VideoProperty[] rv = new VideoProperty[handles.length];
for (int i=0; i<handles.length; i++) {
rv[i] = new VideoProperty(handles[i]);
}
return rv;
}
/// Enumerate all existing sources.
/// @return Vector of sources.