Package edu.wpi.first.cscore
Class VideoSource
java.lang.Object
edu.wpi.first.cscore.VideoSource
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ImageSource,VideoCamera
public class VideoSource extends Object implements AutoCloseable
A source for video that provides a sequence of frames. Each frame may consist of multiple images
(e.g. from a stereo or depth camera); these are called channels.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVideoSource.ConnectionStrategyConnection strategy.static classVideoSource.Kind -
Field Summary
Fields Modifier and Type Field Description protected intm_handle -
Constructor Summary
Constructors Modifier Constructor Description protectedVideoSource(int handle) -
Method Summary
Modifier and Type Method Description voidclose()VideoProperty[]enumerateProperties()Enumerate all properties of this source.VideoSink[]enumerateSinks()Enumerate all sinks connected to this source.static VideoSource[]enumerateSources()Enumerate all existing sources.VideoMode[]enumerateVideoModes()Enumerate all known video modes for this source.booleanequals(Object other)doublegetActualDataRate()Get the data rate (in bytes per second).doublegetActualFPS()Get the actual FPS.StringgetConfigJson()Get a JSON configuration string.StringgetDescription()Get the source description.intgetHandle()VideoSource.KindgetKind()Get the kind of the source.static VideoSource.KindgetKindFromInt(int kind)Convert from the numerical representation of kind to an enum type.longgetLastFrameTime()Get the last time a frame was captured.StringgetName()Get the name of the source.VideoPropertygetProperty(String name)Get a property.VideoModegetVideoMode()Get the current video mode.inthashCode()booleanisConnected()Returns true if the source currently connected to whatever is providing the images.booleanisEnabled()Gets source enable status.booleanisValid()booleansetConfigJson(String config)Set video mode and properties from a JSON configuration string.voidsetConnectionStrategy(VideoSource.ConnectionStrategy strategy)Sets the connection strategy.booleansetFPS(int fps)Set the frames per second (FPS).booleansetPixelFormat(VideoMode.PixelFormat pixelFormat)Set the pixel format.booleansetResolution(int width, int height)Set the resolution.booleansetVideoMode(VideoMode mode)Set the video mode.booleansetVideoMode(VideoMode.PixelFormat pixelFormat, int width, int height, int fps)Set the video mode.
-
Field Details
-
Constructor Details
-
Method Details
-
getKindFromInt
Convert from the numerical representation of kind to an enum type.- Parameters:
kind- The numerical representation of kind- Returns:
- The kind
-
close
- Specified by:
closein interfaceAutoCloseable
-
isValid
-
getHandle
-
equals
-
hashCode
-
getKind
Get the kind of the source.- Returns:
- The kind of the source.
-
getName
Get the name of the source. The name is an arbitrary identifier provided when the source is created, and should be unique.- Returns:
- The name of the source.
-
getDescription
Get the source description. This is source-kind specific.- Returns:
- The source description.
-
getLastFrameTime
Get the last time a frame was captured.- Returns:
- Time in 1 us increments.
-
setConnectionStrategy
Sets the connection strategy. By default, the source will automatically connect or disconnect based on whether any sinks are connected.This function is non-blocking; look for either a connection open or close event or call
isConnected()to determine the connection state.- Parameters:
strategy- connection strategy (auto, keep open, or force close)
-
isConnected
Returns true if the source currently connected to whatever is providing the images.- Returns:
- True if the source currently connected to whatever is providing the images.
-
isEnabled
Gets source enable status. This is determined with a combination of connection strategy and the number of sinks connected.- Returns:
- True if enabled, false otherwise.
-
getProperty
Get a property.- Parameters:
name- Property name- Returns:
- Property contents (of kind Property::kNone if no property with the given name exists)
-
enumerateProperties
Enumerate all properties of this source.- Returns:
- Array of video properties.
-
getVideoMode
Get the current video mode.- Returns:
- The current video mode.
-
setVideoMode
Set the video mode.- Parameters:
mode- Video mode- Returns:
- True if set successfully.
-
setVideoMode
Set the video mode.- Parameters:
pixelFormat- desired pixel formatwidth- desired widthheight- desired heightfps- desired FPS- Returns:
- True if set successfully
-
setPixelFormat
Set the pixel format.- Parameters:
pixelFormat- desired pixel format- Returns:
- True if set successfully
-
setResolution
Set the resolution.- Parameters:
width- desired widthheight- desired height- Returns:
- True if set successfully
-
setFPS
Set the frames per second (FPS).- Parameters:
fps- desired FPS- Returns:
- True if set successfully
-
setConfigJson
Set video mode and properties from a JSON configuration string.The format of the JSON input is:
{ "pixel format": "MJPEG", "YUYV", etc "width": video mode width "height": video mode height "fps": video mode fps "brightness": percentage brightness "white balance": "auto", "hold", or value "exposure": "auto", "hold", or value "properties": [ { "name": property name "value": property value } ] }- Parameters:
config- configuration- Returns:
- True if set successfully
-
getConfigJson
Get a JSON configuration string.- Returns:
- JSON configuration string
-
getActualFPS
Get the actual FPS.CameraServerJNI#setTelemetryPeriod() must be called for this to be valid (throws VisionException if telemetry is not enabled).
- Returns:
- Actual FPS averaged over the telemetry period.
-
getActualDataRate
Get the data rate (in bytes per second).CameraServerJNI#setTelemetryPeriod() must be called for this to be valid (throws VisionException if telemetry is not enabled).
- Returns:
- Data rate averaged over the telemetry period.
-
enumerateVideoModes
Enumerate all known video modes for this source.- Returns:
- Vector of video modes.
-
enumerateSinks
Enumerate all sinks connected to this source.- Returns:
- Vector of sinks.
-
enumerateSources
Enumerate all existing sources.- Returns:
- Vector of sources.
-