@@ -42,6 +42,7 @@ public static CameraServer Instance
4242 }
4343 }
4444
45+ private int m_defaultUsbDevice ;
4546 private string m_primarySourceName ;
4647 private Dictionary < string , VideoSource > m_sources ;
4748 private Dictionary < string , VideoSink > m_sinks ;
@@ -346,6 +347,7 @@ private static void PutSourcePropertyValue(ITable table, VideoEvent evnt, bool i
346347
347348 private CameraServer ( )
348349 {
350+ m_defaultUsbDevice = 0 ;
349351 m_lockObject = new object ( ) ;
350352 m_sources = new Dictionary < string , VideoSource > ( ) ;
351353 m_sinks = new Dictionary < string , VideoSink > ( ) ;
@@ -542,14 +544,16 @@ private CameraServer()
542544 /// <see cref="GetVideo()"/> to get access to the camera images
543545 ///
544546 /// <para>
545- /// This overload calls <see cref="StartAutomaticCapture(int)"/> with device 0,
546- /// creating a camera named "USB Camera 0"
547+ /// The first time this overload is called, it calls <see cref="StartAutomaticCapture(int)"/>
548+ /// with device 0, creating a camera named "USB Camera 0". Subsequent calls increment the device
549+ /// number (e.g. 1, 2, etc).
547550 /// </para>
548551 /// </remarks>
549552 /// <returns>The <see cref="UsbCamera"/> object that was created to stream from</returns>
550553 public UsbCamera StartAutomaticCapture ( )
551554 {
552- return StartAutomaticCapture ( 0 ) ;
555+ // returns new value, so subtract 1 to get old value
556+ return StartAutomaticCapture ( Interlocked . Increment ( ref m_defaultUsbDevice ) - 1 ) ;
553557 }
554558
555559 /// <summary>
@@ -836,6 +840,41 @@ public void RemoveServer(string name)
836840 }
837841 }
838842
843+ /// <summary>
844+ /// Get server for the primary camera feed.
845+ /// </summary>
846+ /// <remarks>
847+ /// This is only valid to call after a camera feed has been added with
848+ /// <see cref="StartAutomaticCapture()"/> or <see cref="AddServer(string)"/>.
849+ /// </remarks>
850+ /// <returns>VideoSink for the primary camera feed.</returns>
851+ public VideoSink GetServer ( )
852+ {
853+ lock ( m_lockObject )
854+ {
855+ if ( m_primarySourceName == null )
856+ {
857+ throw new VideoException ( "no camera available" ) ;
858+ }
859+ return GetServer ( $ "serve_{ m_primarySourceName } ") ;
860+ }
861+ }
862+
863+ /// <summary>
864+ /// Gets a server by name
865+ /// </summary>
866+ /// <param name="name">Server name</param>
867+ /// <returns>VideoSink if it exists, otherwise null</returns>
868+ public VideoSink GetServer ( string name )
869+ {
870+ lock ( m_lockObject )
871+ {
872+ VideoSink sink ;
873+ m_sinks . TryGetValue ( name , out sink ) ;
874+ return sink ;
875+ }
876+ }
877+
839878 /// <summary>
840879 /// Adds an already created camera.
841880 /// </summary>
0 commit comments