CameraServer: auto-increment startAutomaticCapture(). (#468)

Also add GetServer() functions so the automatically created VideoSink can
be retrieved by user code if desired.
This commit is contained in:
Peter Johnson
2017-01-20 01:07:37 -07:00
committed by GitHub
parent ff141ab1ff
commit e375b4a9ff
3 changed files with 83 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ import edu.wpi.cscore.VideoSource;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;
import edu.wpi.first.wpilibj.tables.ITable;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.regex.Matcher;
@@ -56,6 +57,7 @@ public class CameraServer {
return server;
}
private AtomicInteger m_defaultUsbDevice;
private String m_primarySourceName;
private final Hashtable<String, VideoSource> m_sources;
private final Hashtable<String, VideoSink> m_sinks;
@@ -330,6 +332,7 @@ public class CameraServer {
@SuppressWarnings({"JavadocMethod", "PMD.UnusedLocalVariable"})
private CameraServer() {
m_defaultUsbDevice = new AtomicInteger();
m_sources = new Hashtable<String, VideoSource>();
m_sinks = new Hashtable<String, VideoSink>();
m_tables = new Hashtable<Integer, ITable>();
@@ -513,11 +516,13 @@ public class CameraServer {
* If you also want to perform vision processing on the roboRIO, use
* getVideo() to get access to the camera images.
*
* <p>This overload calls {@link #startAutomaticCapture(int)} with device 0,
* creating a camera named "USB Camera 0".
* <p>The first time this overload is called, it calls
* {@link #startAutomaticCapture(int)} with device 0, creating a camera
* named "USB Camera 0". Subsequent calls increment the device number
* (e.g. 1, 2, etc).
*/
public UsbCamera startAutomaticCapture() {
return startAutomaticCapture(0);
return startAutomaticCapture(m_defaultUsbDevice.getAndIncrement());
}
/**
@@ -745,6 +750,32 @@ public class CameraServer {
}
}
/**
* Get server for the primary camera feed.
*
* <p>This is only valid to call after a camera feed has been added
* with startAutomaticCapture() or addServer().
*/
public VideoSink getServer() {
synchronized (this) {
if (m_primarySourceName == null) {
throw new VideoException("no camera available");
}
return getServer("serve_" + m_primarySourceName);
}
}
/**
* Gets a server by name.
*
* @param name Server name
*/
public VideoSink getServer(String name) {
synchronized (this) {
return m_sinks.get(name);
}
}
/**
* Adds an already created camera.
*