@@ -40,8 +40,20 @@ public class RTSPClient : IDisposable
4040
4141 public bool AutoPlay { get ; set ; } = true ;
4242
43- public enum RTP_TRANSPORT { UDP , TCP , MULTICAST } ;
44- public enum MEDIA_REQUEST { VIDEO_ONLY , AUDIO_ONLY , VIDEO_AND_AUDIO } ;
43+ public enum RTP_TRANSPORT
44+ {
45+ UDP ,
46+ TCP ,
47+ MULTICAST
48+ } ;
49+
50+ public enum MEDIA_REQUEST
51+ {
52+ VIDEO_ONLY ,
53+ AUDIO_ONLY ,
54+ VIDEO_AND_AUDIO
55+ } ;
56+
4557 private enum RTSP_STATUS { WaitingToConnect , Connecting , ConnectFailed , Connected } ;
4658
4759 private IRtspTransport _rtspSocket ; // RTSP connection
@@ -54,7 +66,7 @@ private enum RTSP_STATUS { WaitingToConnect, Connecting, ConnectFailed, Connecte
5466 private IRtpTransport _videoRtpTransport ;
5567 private IRtpTransport _audioRtpTransport ;
5668
57- private Uri _uri ; // RTSP URI (username & password will be stripped out
69+ private Uri _uri ; // RTSP URI (username & password will be stripped out)
5870 private string _session = "" ; // RTSP Session
5971 private Authentication _authentication ;
6072 private NetworkCredential _credentials = new NetworkCredential ( ) ;
@@ -99,15 +111,31 @@ private enum RTSP_STATUS { WaitingToConnect, Connecting, ConnectFailed, Connecte
99111 /// </summary>
100112 public uint AudioSSRC { get ; set ; } = ( uint ) _rand . Next ( 20000 , 29999 ) ;
101113
114+ /// <summary>
115+ /// Default ctor.
116+ /// </summary>
102117 public RTSPClient ( ) : this ( new CustomLoggerFactory ( ) )
103118 { }
104119
120+ /// <summary>
121+ /// Ctor.
122+ /// </summary>
123+ /// <param name="loggerFactory">Logger factory <see cref="ILoggerFactory"/>.</param>
105124 public RTSPClient ( ILoggerFactory loggerFactory )
106125 {
107126 _logger = loggerFactory . CreateLogger < RTSPClient > ( ) ;
108127 _loggerFactory = loggerFactory ;
109128 }
110129
130+ /// <summary>
131+ /// Connect.
132+ /// </summary>
133+ /// <param name="url">URL to connect to.</param>
134+ /// <param name="rtpTransport">Type of the RTP transport <see cref="RTP_TRANSPORT"/>.</param>
135+ /// <param name="username">User name.</param>
136+ /// <param name="password">Password.</param>
137+ /// <param name="mediaRequest">Media request type <see cref="MEDIA_REQUEST>."/></param>
138+ /// <param name="playbackSession">Playback session.</param>
111139 public void Connect ( string url , RTP_TRANSPORT rtpTransport , string username = null , string password = null , MEDIA_REQUEST mediaRequest = MEDIA_REQUEST . VIDEO_AND_AUDIO , bool playbackSession = false )
112140 {
113141 RtspUtils . RegisterUri ( ) ;
@@ -125,8 +153,7 @@ public void Connect(string url, RTP_TRANSPORT rtpTransport, string username = nu
125153 if ( _uri . UserInfo . Length > 0 )
126154 {
127155 _credentials = new NetworkCredential ( _uri . UserInfo . Split ( ':' ) [ 0 ] , _uri . UserInfo . Split ( ':' ) [ 1 ] ) ;
128- _uri = new Uri ( _uri . GetComponents ( UriComponents . AbsoluteUri & ~ UriComponents . UserInfo ,
129- UriFormat . UriEscaped ) ) ;
156+ _uri = new Uri ( _uri . GetComponents ( UriComponents . AbsoluteUri & ~ UriComponents . UserInfo , UriFormat . UriEscaped ) ) ;
130157 }
131158 else
132159 {
@@ -225,7 +252,10 @@ public void Connect(string url, RTP_TRANSPORT rtpTransport, string username = nu
225252 _rtspClient . SendMessage ( options_message ) ;
226253 }
227254
228- // return true if this connection failed, or if it connected but is no longer connected.
255+ /// <summary>
256+ /// Returns true if this connection failed, or if it connected but is no longer connected.
257+ /// </summary>
258+ /// <returns></returns>
229259 public bool StreamingFinished ( )
230260 {
231261 switch ( _rtspSocketStatus )
@@ -239,6 +269,10 @@ public bool StreamingFinished()
239269 }
240270 }
241271
272+ /// <summary>
273+ /// Pause.
274+ /// </summary>
275+ /// <exception cref="InvalidOperationException"></exception>
242276 public void Pause ( )
243277 {
244278 if ( _rtspSocket == null || _uri == null )
@@ -254,6 +288,10 @@ public void Pause()
254288 _rtspClient ? . SendMessage ( pause_message ) ;
255289 }
256290
291+ /// <summary>
292+ /// Play.
293+ /// </summary>
294+ /// <exception cref="InvalidOperationException"></exception>
257295 public void Play ( )
258296 {
259297 if ( _rtspSocket == null || _uri == null )
@@ -323,6 +361,9 @@ public void Play(DateTime seekTimeFrom, DateTime seekTimeTo, double speed = 1.0)
323361 _rtspClient ? . SendMessage ( playMessage ) ;
324362 }
325363
364+ /// <summary>
365+ /// Stop.
366+ /// </summary>
326367 public void Stop ( )
327368 {
328369 // Send TEARDOWN
@@ -345,8 +386,25 @@ public void Stop()
345386 _rtspClient ? . Stop ( ) ;
346387 }
347388
348- // A Video RTP packet has been received.
349- public void VideoRtpDataReceived ( object sender , RtspDataEventArgs e )
389+ /// <summary>
390+ /// Send RTCP in the video channel.
391+ /// </summary>
392+ /// <param name="rtcp">RTCP message bytes.</param>
393+ public void SendVideoRTCP ( byte [ ] rtcp )
394+ {
395+ _videoRtpTransport . WriteToControlPort ( rtcp ) ;
396+ }
397+
398+ /// <summary>
399+ /// Send RTCP in the audio channel.
400+ /// </summary>
401+ /// <param name="rtcp">RTCP message bytes.</param>
402+ public void SendAudioRTCP ( byte [ ] rtcp )
403+ {
404+ _audioRtpTransport . WriteToControlPort ( rtcp ) ;
405+ }
406+
407+ private void VideoRtpDataReceived ( object sender , RtspDataEventArgs e )
350408 {
351409 if ( e . Data . Data . IsEmpty )
352410 return ;
@@ -385,7 +443,7 @@ public void VideoRtpDataReceived(object sender, RtspDataEventArgs e)
385443 }
386444 }
387445
388- public void AudioRtpDataReceived ( object sender , RtspDataEventArgs e )
446+ private void AudioRtpDataReceived ( object sender , RtspDataEventArgs e )
389447 {
390448 if ( e . Data . Data . IsEmpty )
391449 return ;
@@ -411,7 +469,7 @@ public void AudioRtpDataReceived(object sender, RtspDataEventArgs e)
411469
412470 if ( _audioPayloadProcessor == null )
413471 {
414- _logger . LogWarning ( "No parser for RTP payload {audioPayload}" , _audioPayload ) ;
472+ _logger . LogWarning ( "No parser for audio RTP payload {audioPayload}" , _audioPayload ) ;
415473 return ;
416474 }
417475
@@ -425,12 +483,12 @@ public void AudioRtpDataReceived(object sender, RtspDataEventArgs e)
425483 }
426484 }
427485
428- public void VideoRtcpControlDataReceived ( object sender , RtspDataEventArgs e )
486+ private void VideoRtcpControlDataReceived ( object sender , RtspDataEventArgs e )
429487 {
430488 if ( e . Data . Data . IsEmpty )
431489 return ;
432490
433- _logger . LogDebug ( "Received a RTCP message" ) ;
491+ _logger . LogDebug ( "Received video RTCP message" ) ;
434492
435493 using ( var data = e . Data )
436494 {
@@ -447,12 +505,12 @@ public void VideoRtcpControlDataReceived(object sender, RtspDataEventArgs e)
447505 }
448506 }
449507
450- public void AudioRtcpControlDataReceived ( object sender , RtspDataEventArgs e )
508+ private void AudioRtcpControlDataReceived ( object sender , RtspDataEventArgs e )
451509 {
452510 if ( e . Data . Data . IsEmpty )
453511 return ;
454512
455- _logger . LogDebug ( "Received a RTCP message" ) ;
513+ _logger . LogDebug ( "Received audio RTCP message" ) ;
456514
457515 using ( var data = e . Data )
458516 {
@@ -559,12 +617,12 @@ private List<byte[]> ParseRTCPAndGenerateReponse(RtspData data, uint ssrc)
559617 return reports ;
560618 }
561619
562- // RTSP Messages are OPTIONS, DESCRIBE, SETUP, PLAY etc
563620 private void RtspMessageReceived ( object sender , RtspChunkEventArgs e )
564621 {
565622 if ( ! ( e . Message is RtspResponse message ) )
566623 return ;
567624
625+ // RTSP Messages are OPTIONS, DESCRIBE, SETUP, PLAY etc
568626 _logger . LogDebug ( "Received RTSP response to message {originalRequest}" , message . OriginalRequest ) ;
569627
570628 // If message has a 401 - Unauthorized Error, then we re-send the message with Authorization
@@ -780,7 +838,7 @@ private void HandleDescribeResponse(RtspResponse message)
780838 }
781839
782840 // Process each 'Media' Attribute in the SDP (each sub-stream)
783- // to look for first supported video substream
841+ // to look for first supported video substream
784842 if ( _clientWantsVideo )
785843 {
786844 foreach ( Media media in sdp_data . Medias . Where ( m => m . MediaType == Media . MediaTypes . video ) )
@@ -1116,15 +1174,7 @@ private void SendKeepAlive(object sender, System.Timers.ElapsedEventArgs e)
11161174 _rtspClient ? . SendMessage ( keepAliveMessage ) ;
11171175 }
11181176
1119- public void SendVideoRTCP ( byte [ ] rtcp )
1120- {
1121- _videoRtpTransport . WriteToControlPort ( rtcp ) ;
1122- }
1123-
1124- public void SendAudioRTCP ( byte [ ] rtcp )
1125- {
1126- _audioRtpTransport . WriteToControlPort ( rtcp ) ;
1127- }
1177+ #region IDisposable
11281178
11291179 protected virtual void Dispose ( bool disposing )
11301180 {
@@ -1142,11 +1192,14 @@ protected virtual void Dispose(bool disposing)
11421192 _disposedValue = true ;
11431193 }
11441194 }
1195+
11451196 public void Dispose ( )
11461197 {
11471198 Dispose ( disposing : true ) ;
11481199 GC . SuppressFinalize ( this ) ;
11491200 }
1201+
1202+ #endregion // IDisposable
11501203 }
11511204
11521205 public class NewStreamEventArgs : EventArgs
0 commit comments