@@ -42,6 +42,7 @@ public static CameraServer Instance
42
42
}
43
43
}
44
44
45
+ private int m_defaultUsbDevice ;
45
46
private string m_primarySourceName ;
46
47
private Dictionary < string , VideoSource > m_sources ;
47
48
private Dictionary < string , VideoSink > m_sinks ;
@@ -346,6 +347,7 @@ private static void PutSourcePropertyValue(ITable table, VideoEvent evnt, bool i
346
347
347
348
private CameraServer ( )
348
349
{
350
+ m_defaultUsbDevice = 0 ;
349
351
m_lockObject = new object ( ) ;
350
352
m_sources = new Dictionary < string , VideoSource > ( ) ;
351
353
m_sinks = new Dictionary < string , VideoSink > ( ) ;
@@ -542,14 +544,16 @@ private CameraServer()
542
544
/// <see cref="GetVideo()"/> to get access to the camera images
543
545
///
544
546
/// <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).
547
550
/// </para>
548
551
/// </remarks>
549
552
/// <returns>The <see cref="UsbCamera"/> object that was created to stream from</returns>
550
553
public UsbCamera StartAutomaticCapture ( )
551
554
{
552
- return StartAutomaticCapture ( 0 ) ;
555
+ // returns new value, so subtract 1 to get old value
556
+ return StartAutomaticCapture ( Interlocked . Increment ( ref m_defaultUsbDevice ) - 1 ) ;
553
557
}
554
558
555
559
/// <summary>
@@ -836,6 +840,41 @@ public void RemoveServer(string name)
836
840
}
837
841
}
838
842
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
+
839
878
/// <summary>
840
879
/// Adds an already created camera.
841
880
/// </summary>
0 commit comments