WPILibC++ 2023.4.3
cs::VideoSource Class Reference

A source for video that provides a sequence of frames. More...

#include <cscore_oo.h>

Inheritance diagram for cs::VideoSource:
cs::ImageSource cs::VideoCamera cs::HttpCamera cs::UsbCamera cs::AxisCamera

Public Types

enum  Kind { kUnknown = CS_SOURCE_UNKNOWN , kUsb = CS_SOURCE_USB , kHttp = CS_SOURCE_HTTP , kCv = CS_SOURCE_CV }
 
enum  ConnectionStrategy { kConnectionAutoManage = CS_CONNECTION_AUTO_MANAGE , kConnectionKeepOpen = CS_CONNECTION_KEEP_OPEN , kConnectionForceClose = CS_CONNECTION_FORCE_CLOSE }
 Connection strategy. More...
 

Public Member Functions

 VideoSource () noexcept=default
 
 VideoSource (const VideoSource &source)
 
 VideoSource (VideoSource &&other) noexcept
 
VideoSourceoperator= (VideoSource other) noexcept
 
 ~VideoSource ()
 
 operator bool () const
 
int GetHandle () const
 
bool operator== (const VideoSource &other) const
 
Kind GetKind () const
 Get the kind of the source. More...
 
std::string GetName () const
 Get the name of the source. More...
 
std::string GetDescription () const
 Get the source description. More...
 
uint64_t GetLastFrameTime () const
 Get the last time a frame was captured. More...
 
void SetConnectionStrategy (ConnectionStrategy strategy)
 Sets the connection strategy. More...
 
bool IsConnected () const
 Is the source currently connected to whatever is providing the images? More...
 
bool IsEnabled () const
 Gets source enable status. More...
 
VideoProperty GetProperty (std::string_view name)
 Get a property. More...
 
std::vector< VideoPropertyEnumerateProperties () const
 Enumerate all properties of this source. More...
 
VideoMode GetVideoMode () const
 Get the current video mode. More...
 
bool SetVideoMode (const VideoMode &mode)
 Set the video mode. More...
 
bool SetVideoMode (VideoMode::PixelFormat pixelFormat, int width, int height, int fps)
 Set the video mode. More...
 
bool SetPixelFormat (VideoMode::PixelFormat pixelFormat)
 Set the pixel format. More...
 
bool SetResolution (int width, int height)
 Set the resolution. More...
 
bool SetFPS (int fps)
 Set the frames per second (FPS). More...
 
bool SetConfigJson (std::string_view config)
 Set video mode and properties from a JSON configuration string. More...
 
bool SetConfigJson (const wpi::json &config)
 Set video mode and properties from a JSON configuration object. More...
 
std::string GetConfigJson () const
 Get a JSON configuration string. More...
 
wpi::json GetConfigJsonObject () const
 Get a JSON configuration object. More...
 
double GetActualFPS () const
 Get the actual FPS. More...
 
double GetActualDataRate () const
 Get the data rate (in bytes per second). More...
 
std::vector< VideoModeEnumerateVideoModes () const
 Enumerate all known video modes for this source. More...
 
CS_Status GetLastStatus () const
 
std::vector< VideoSinkEnumerateSinks ()
 Enumerate all sinks connected to this source. More...
 

Static Public Member Functions

static std::vector< VideoSourceEnumerateSources ()
 Enumerate all existing sources. More...
 

Protected Member Functions

 VideoSource (CS_Source handle)
 

Protected Attributes

CS_Status m_status = 0
 
CS_Source m_handle {0}
 

Friends

class VideoEvent
 
class VideoSink
 
void swap (VideoSource &first, VideoSource &second) noexcept
 

Detailed Description

A source for video that provides a sequence of frames.

Member Enumeration Documentation

◆ ConnectionStrategy

Connection strategy.

Used for SetConnectionStrategy().

Enumerator
kConnectionAutoManage 

Automatically connect or disconnect based on whether any sinks are connected to this source.

This is the default behavior.

kConnectionKeepOpen 

Try to keep the connection open regardless of whether any sinks are connected.

kConnectionForceClose 

Never open the connection.

If this is set when the connection is open, close the connection.

◆ Kind

Enumerator
kUnknown 
kUsb 
kHttp 
kCv 

Constructor & Destructor Documentation

◆ VideoSource() [1/4]

cs::VideoSource::VideoSource ( )
defaultnoexcept

◆ VideoSource() [2/4]

cs::VideoSource::VideoSource ( const VideoSource source)
inline

◆ VideoSource() [3/4]

cs::VideoSource::VideoSource ( VideoSource &&  other)
inlinenoexcept

◆ ~VideoSource()

cs::VideoSource::~VideoSource ( )
inline

◆ VideoSource() [4/4]

cs::VideoSource::VideoSource ( CS_Source  handle)
inlineexplicitprotected

Member Function Documentation

◆ EnumerateProperties()

std::vector< VideoProperty > cs::VideoSource::EnumerateProperties ( ) const

Enumerate all properties of this source.

◆ EnumerateSinks()

std::vector< VideoSink > cs::VideoSource::EnumerateSinks ( )

Enumerate all sinks connected to this source.

Returns
Vector of sinks.

◆ EnumerateSources()

static std::vector< VideoSource > cs::VideoSource::EnumerateSources ( )
static

Enumerate all existing sources.

Returns
Vector of sources.

◆ EnumerateVideoModes()

std::vector< VideoMode > cs::VideoSource::EnumerateVideoModes ( ) const
inline

Enumerate all known video modes for this source.

◆ GetActualDataRate()

double cs::VideoSource::GetActualDataRate ( ) const
inline

Get the data rate (in bytes per second).

SetTelemetryPeriod() must be called for this to be valid.

Returns
Data rate averaged over the telemetry period.

◆ GetActualFPS()

double cs::VideoSource::GetActualFPS ( ) const
inline

Get the actual FPS.

SetTelemetryPeriod() must be called for this to be valid.

Returns
Actual FPS averaged over the telemetry period.

◆ GetConfigJson()

std::string cs::VideoSource::GetConfigJson ( ) const
inline

Get a JSON configuration string.

Returns
JSON configuration string

◆ GetConfigJsonObject()

wpi::json cs::VideoSource::GetConfigJsonObject ( ) const

Get a JSON configuration object.

Returns
JSON configuration object

◆ GetDescription()

std::string cs::VideoSource::GetDescription ( ) const
inline

Get the source description.

This is source-kind specific.

◆ GetHandle()

int cs::VideoSource::GetHandle ( ) const
inline

◆ GetKind()

VideoSource::Kind cs::VideoSource::GetKind ( ) const
inline

Get the kind of the source.

◆ GetLastFrameTime()

uint64_t cs::VideoSource::GetLastFrameTime ( ) const
inline

Get the last time a frame was captured.

This uses the same time base as wpi::Now().

Returns
Time in 1 us increments.

◆ GetLastStatus()

CS_Status cs::VideoSource::GetLastStatus ( ) const
inline

◆ GetName()

std::string cs::VideoSource::GetName ( ) const
inline

Get the name of the source.

The name is an arbitrary identifier provided when the source is created, and should be unique.

◆ GetProperty()

VideoProperty cs::VideoSource::GetProperty ( std::string_view  name)
inline

Get a property.

Parameters
nameProperty name
Returns
Property contents (of kind Property::kNone if no property with the given name exists)

◆ GetVideoMode()

VideoMode cs::VideoSource::GetVideoMode ( ) const
inline

Get the current video mode.

◆ IsConnected()

bool cs::VideoSource::IsConnected ( ) const
inline

Is the source currently connected to whatever is providing the images?

◆ IsEnabled()

bool cs::VideoSource::IsEnabled ( ) const
inline

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.

◆ operator bool()

cs::VideoSource::operator bool ( ) const
inlineexplicit

◆ operator=()

VideoSource & cs::VideoSource::operator= ( VideoSource  other)
inlinenoexcept

◆ operator==()

bool cs::VideoSource::operator== ( const VideoSource other) const
inline

◆ SetConfigJson() [1/2]

bool cs::VideoSource::SetConfigJson ( const wpi::json config)
inline

Set video mode and properties from a JSON configuration object.

Parameters
configconfiguration
Returns
True if set successfully

◆ SetConfigJson() [2/2]

bool cs::VideoSource::SetConfigJson ( std::string_view  config)
inline

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
configconfiguration
Returns
True if set successfully

◆ SetConnectionStrategy()

void cs::VideoSource::SetConnectionStrategy ( ConnectionStrategy  strategy)
inline

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
strategyconnection strategy (auto, keep open, or force close)

◆ SetFPS()

bool cs::VideoSource::SetFPS ( int  fps)
inline

Set the frames per second (FPS).

Parameters
fpsdesired FPS
Returns
True if set successfully

◆ SetPixelFormat()

bool cs::VideoSource::SetPixelFormat ( VideoMode::PixelFormat  pixelFormat)
inline

Set the pixel format.

Parameters
pixelFormatdesired pixel format
Returns
True if set successfully

◆ SetResolution()

bool cs::VideoSource::SetResolution ( int  width,
int  height 
)
inline

Set the resolution.

Parameters
widthdesired width
heightdesired height
Returns
True if set successfully

◆ SetVideoMode() [1/2]

bool cs::VideoSource::SetVideoMode ( const VideoMode mode)
inline

Set the video mode.

Parameters
modeVideo mode

◆ SetVideoMode() [2/2]

bool cs::VideoSource::SetVideoMode ( VideoMode::PixelFormat  pixelFormat,
int  width,
int  height,
int  fps 
)
inline

Set the video mode.

Parameters
pixelFormatdesired pixel format
widthdesired width
heightdesired height
fpsdesired FPS
Returns
True if set successfully

Friends And Related Function Documentation

◆ swap

void swap ( VideoSource first,
VideoSource second 
)
friend

◆ VideoEvent

friend class VideoEvent
friend

◆ VideoSink

friend class VideoSink
friend

Member Data Documentation

◆ m_handle

CS_Source cs::VideoSource::m_handle {0}
protected

◆ m_status

CS_Status cs::VideoSource::m_status = 0
mutableprotected

The documentation for this class was generated from the following files: