Create VideoCamera base class and move camera settings functions to it.

This makes them available for both UsbCamera and HttpCamera / AxisCamera.

To avoid virtual functions in the public-facing interface, move the
implementation of the camera settings functions to the core library.
This commit is contained in:
Peter Johnson
2017-01-01 14:24:13 -08:00
parent 23135d7a5a
commit 7ddbf20108
19 changed files with 581 additions and 186 deletions

View File

@@ -25,13 +25,13 @@ public class AxisCamera extends HttpCamera {
/// @param name Source name (arbitrary unique identifier)
/// @param host Camera host IP or DNS name (e.g. "10.x.y.11")
public AxisCamera(String name, String host) {
super(name, hostToUrl(host), CameraKind.kAxis);
super(name, hostToUrl(host), HttpCameraKind.kAxis);
}
/// Create a source for an Axis IP camera.
/// @param name Source name (arbitrary unique identifier)
/// @param hosts Array of Camera host IPs/DNS names
public AxisCamera(String name, String[] hosts) {
super(name, hostToUrl(hosts), CameraKind.kAxis);
super(name, hostToUrl(hosts), HttpCameraKind.kAxis);
}
}

View File

@@ -128,6 +128,18 @@ public class CameraServerJNI {
public static native int copySource(int source);
public static native void releaseSource(int source);
//
// Camera Source Common Property Fuctions
//
public static native void setCameraBrightness(int source, int brightness);
public static native int getCameraBrightness(int source);
public static native void setCameraWhiteBalanceAuto(int source);
public static native void setCameraWhiteBalanceHoldCurrent(int source);
public static native void setCameraWhiteBalanceManual(int source, int value);
public static native void setCameraExposureAuto(int source);
public static native void setCameraExposureHoldCurrent(int source);
public static native void setCameraExposureManual(int source, int value);
//
// UsbCamera Source Functions
//

View File

@@ -8,12 +8,12 @@
package edu.wpi.cscore;
/// A source that represents a MJPEG-over-HTTP (IP) camera.
public class HttpCamera extends VideoSource {
public enum CameraKind {
public class HttpCamera extends VideoCamera {
public enum HttpCameraKind {
kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
private int value;
private CameraKind(int value) {
private HttpCameraKind(int value) {
this.value = value;
}
@@ -22,12 +22,12 @@ public class HttpCamera extends VideoSource {
}
}
public static CameraKind getCameraKindFromInt(int kind) {
public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
switch (kind) {
case 1: return CameraKind.kMJPGStreamer;
case 2: return CameraKind.kCSCore;
case 3: return CameraKind.kAxis;
default: return CameraKind.kUnknown;
case 1: return HttpCameraKind.kMJPGStreamer;
case 2: return HttpCameraKind.kCSCore;
case 3: return HttpCameraKind.kAxis;
default: return HttpCameraKind.kUnknown;
}
}
@@ -35,14 +35,14 @@ public class HttpCamera extends VideoSource {
/// @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, CameraKind.kUnknown.getValue()));
super(CameraServerJNI.createHttpCamera(name, url, HttpCameraKind.kUnknown.getValue()));
}
/// 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")
/// @param kind Camera kind (e.g. kAxis)
public HttpCamera(String name, String url, CameraKind kind) {
public HttpCamera(String name, String url, HttpCameraKind kind) {
super(CameraServerJNI.createHttpCamera(name, url, kind.getValue()));
}
@@ -50,22 +50,22 @@ public class HttpCamera extends VideoSource {
/// @param name Source name (arbitrary unique identifier)
/// @param urls Array of Camera URLs
public HttpCamera(String name, String[] urls) {
super(CameraServerJNI.createHttpCameraMulti(name, urls, CameraKind.kUnknown.getValue()));
super(CameraServerJNI.createHttpCameraMulti(name, urls, HttpCameraKind.kUnknown.getValue()));
}
/// Create a source for a MJPEG-over-HTTP (IP) camera.
/// @param name Source name (arbitrary unique identifier)
/// @param urls Array of Camera URLs
/// @param kind Camera kind (e.g. kAxis)
public HttpCamera(String name, String[] urls, CameraKind kind) {
public HttpCamera(String name, String[] urls, HttpCameraKind kind) {
super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
}
/// Get the kind of HTTP camera.
/// Autodetection can result in returning a different value than the camera
/// was created with.
public CameraKind getCameraKind() {
return getCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
public HttpCameraKind getHttpCameraKind() {
return getHttpCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
}
/// Change the URLs used to connect to the camera.

View File

@@ -8,28 +8,7 @@
package edu.wpi.cscore;
/// A source that represents a USB camera.
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";
private static final String kPropExValue = "exposure_absolute";
private static final String kPropBrValue = "brightness";
public class WhiteBalance {
public static final int kFixedIndoor = 3000;
public static final int kFixedOutdoor1 = 4000;
public static final int kFixedOutdoor2 = 5000;
public static final int kFixedFluorescent1 = 5100;
public static final int kFixedFlourescent2 = 5200;
}
// Cached to avoid duplicate string lookups
private VideoProperty m_wbAuto;
private VideoProperty m_wbValue;
private VideoProperty m_exAuto;
private VideoProperty m_exValue;
private VideoProperty m_brValue;
public class UsbCamera extends VideoCamera {
/// 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)
@@ -54,66 +33,4 @@ public class UsbCamera extends VideoSource {
public String getPath() {
return CameraServerJNI.getUsbCameraPath(m_handle);
}
/// Set the brightness, as a percentage (0-100).
public synchronized void setBrightness(int brightness) {
if (brightness > 100) {
brightness = 100;
} else if (brightness < 0) {
brightness = 0;
}
if (m_brValue == null) m_brValue = getProperty(kPropBrValue);
m_brValue.set(brightness);
}
/// Get the brightness, as a percentage (0-100).
public synchronized int getBrightness() {
if (m_brValue == null) m_brValue = getProperty(kPropBrValue);
return m_brValue.get();
}
/// Set the white balance to auto.
public synchronized void setWhiteBalanceAuto() {
if (m_wbAuto == null) m_wbAuto = getProperty(kPropWbAuto);
m_wbAuto.set(1); // auto
}
/// Set the white balance to hold current.
public synchronized void setWhiteBalanceHoldCurrent() {
if (m_wbAuto == null) m_wbAuto = getProperty(kPropWbAuto);
m_wbAuto.set(0); // manual
}
/// Set the white balance to manual, with specified color temperature.
public synchronized void setWhiteBalanceManual(int value) {
if (m_wbAuto == null) m_wbAuto = getProperty(kPropWbAuto);
m_wbAuto.set(0); // manual
if (m_wbValue == null) m_wbValue = getProperty(kPropWbValue);
m_wbValue.set(value);
}
/// Set the exposure to auto aperature.
public synchronized void setExposureAuto() {
if (m_exAuto == null) m_exAuto = getProperty(kPropExAuto);
m_exAuto.set(0); // auto; yes, this is opposite of white balance.
}
/// Set the exposure to hold current.
public synchronized void setExposureHoldCurrent() {
if (m_exAuto == null) m_exAuto = getProperty(kPropExAuto);
m_exAuto.set(1); // manual
}
/// Set the exposure to manual, as a percentage (0-100).
public synchronized void setExposureManual(int value) {
if (m_exAuto == null) m_exAuto = getProperty(kPropExAuto);
m_exAuto.set(1); // manual
if (value > 100) {
value = 100;
} else if (value < 0) {
value = 0;
}
if (m_exValue == null) m_exValue = getProperty(kPropExValue);
m_exValue.set(value);
}
}

View File

@@ -0,0 +1,63 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/// A source that represents a video camera.
public class VideoCamera extends VideoSource {
public class WhiteBalance {
public static final int kFixedIndoor = 3000;
public static final int kFixedOutdoor1 = 4000;
public static final int kFixedOutdoor2 = 5000;
public static final int kFixedFluorescent1 = 5100;
public static final int kFixedFlourescent2 = 5200;
}
protected VideoCamera(int handle) {
super(handle);
}
/// Set the brightness, as a percentage (0-100).
public synchronized void setBrightness(int brightness) {
CameraServerJNI.setCameraBrightness(m_handle, brightness);
}
/// Get the brightness, as a percentage (0-100).
public synchronized int getBrightness() {
return CameraServerJNI.getCameraBrightness(m_handle);
}
/// Set the white balance to auto.
public synchronized void setWhiteBalanceAuto() {
CameraServerJNI.setCameraWhiteBalanceAuto(m_handle);
}
/// Set the white balance to hold current.
public synchronized void setWhiteBalanceHoldCurrent() {
CameraServerJNI.setCameraWhiteBalanceHoldCurrent(m_handle);
}
/// Set the white balance to manual, with specified color temperature.
public synchronized void setWhiteBalanceManual(int value) {
CameraServerJNI.setCameraWhiteBalanceManual(m_handle, value);
}
/// Set the exposure to auto aperture.
public synchronized void setExposureAuto() {
CameraServerJNI.setCameraExposureAuto(m_handle);
}
/// Set the exposure to hold current.
public synchronized void setExposureHoldCurrent() {
CameraServerJNI.setCameraExposureHoldCurrent(m_handle);
}
/// Set the exposure to manual, as a percentage (0-100).
public synchronized void setExposureManual(int value) {
CameraServerJNI.setCameraExposureManual(m_handle, value);
}
}