44using Microsoft . Extensions . Configuration ;
55using SharpRTSPServer ;
66using System ;
7+ using System . Buffers ;
78using System . Collections . Generic ;
89using System . Diagnostics ;
910using System . IO ;
@@ -87,7 +88,7 @@ void Reader_OnReadPacketEvent(object context, IPacket packet)
8788 {
8889 var ipHeader = ParseIPHeader ( packet ) ;
8990
90- if ( ipHeader . Protocol == 6 ) // TCP - RTSP
91+ if ( ipHeader . Protocol == 6 ) // TCP - RTSP
9192 {
9293 var tcpHeader = ParseTCPHeader ( packet , 4 + ipHeader . HeaderLength ) ;
9394 Debug . WriteLine ( $ "Source: { ipHeader . SourceIP } :{ tcpHeader . SourcePort } , Dest: { ipHeader . DestintationIP } :{ tcpHeader . DestinationPort } , Ver: { ipHeader . Version } ") ;
@@ -113,7 +114,7 @@ void ParseData(byte[] data, object header, uint seconds, uint microseconds)
113114
114115 if ( udp != null && data . Length > 1 ) // TODO
115116 {
116- if ( data [ 0 ] == 0x80 && data [ 1 ] != 0xc8 ) // 0xc8 sender report -> ignore rtcp
117+ if ( data [ 0 ] == 0x80 && data [ 1 ] != 0xc8 ) // 0xc8 sender report -> ignore rtcp
117118 {
118119 long messageTime = seconds * 1000 + ( microseconds / 1000 ) ;
119120 long realTime = ( uint ) _stopwatch . ElapsedMilliseconds ;
@@ -132,9 +133,9 @@ void ParseData(byte[] data, object header, uint seconds, uint microseconds)
132133 {
133134 Thread . Sleep ( sleep ) ;
134135 }
135- videoTrack ? . FeedInRawSamples ( RTPPacketUtil . ReadTS ( data ) , new List < byte [ ] > { data } ) ;
136+ videoTrack ? . FeedInRawSamples ( RTPPacketUtil . ReadTS ( data ) , new ReadOnlySequence < byte > ( data ) ) ;
136137 }
137- else if ( rtspProtocolParser . Ports . Count > 1 && rtspProtocolParser . Ports [ 1 ] . Contains ( udp . SourcePort ) && rtspProtocolParser . Ports [ 1 ] . Contains ( udp . DestinationPort ) )
138+ else if ( rtspProtocolParser . Ports . Count > 1 && rtspProtocolParser . Ports [ 1 ] . Contains ( udp . SourcePort ) && rtspProtocolParser . Ports [ 1 ] . Contains ( udp . DestinationPort ) )
138139 {
139140 if ( lastAudioMessageTime == - 1 )
140141 lastAudioMessageTime = messageTime ;
@@ -149,7 +150,7 @@ void ParseData(byte[] data, object header, uint seconds, uint microseconds)
149150 Thread . Sleep ( sleep ) ;
150151 }
151152
152- audioTrack ? . FeedInRawSamples ( RTPPacketUtil . ReadTS ( data ) , new List < byte [ ] > { data } ) ;
153+ audioTrack ? . FeedInRawSamples ( RTPPacketUtil . ReadTS ( data ) , new ReadOnlySequence < byte > ( data ) ) ;
153154 }
154155 }
155156 }
@@ -305,19 +306,19 @@ public bool Parse(string rtsp)
305306 {
306307 int . TryParse ( line . Substring ( CONTENT_LENGTH . Length ) . Trim ( ) , out contentLength ) ;
307308 }
308- else if ( line . StartsWith ( TRANSPORT ) ) // SETUP response
309+ else if ( line . StartsWith ( TRANSPORT ) ) // SETUP response
309310 {
310311 int [ ] clientPorts = null ;
311312 int [ ] serverPorts = null ;
312313 string [ ] split = line . Substring ( TRANSPORT . Length ) . Trim ( ) . Split ( ';' ) ;
313- foreach ( var s in split )
314+ foreach ( var s in split )
314315 {
315316 string str = s . Trim ( ) ;
316- if ( str . StartsWith ( CLIENT_PORT ) )
317+ if ( str . StartsWith ( CLIENT_PORT ) )
317318 {
318319 clientPorts = str . Substring ( CLIENT_PORT . Length ) . Split ( '-' ) . Select ( int . Parse ) . ToArray ( ) ;
319320 }
320- else if ( str . StartsWith ( SERVER_PORT ) )
321+ else if ( str . StartsWith ( SERVER_PORT ) )
321322 {
322323 serverPorts = str . Substring ( SERVER_PORT . Length ) . Split ( '-' ) . Select ( int . Parse ) . ToArray ( ) ;
323324 }
@@ -337,7 +338,7 @@ public bool Parse(string rtsp)
337338 if ( ms . Position == ms . Length && contentLength > ( ms . Length - ms . Position ) )
338339 {
339340 return true ;
340- }
341+ }
341342 }
342343 }
343344 }
@@ -364,7 +365,7 @@ public UDPHeader(ushort sourcePort, ushort destinationPort, ushort length, ushor
364365
365366public class TCPHeader
366367{
367- public TCPHeader ( ushort sourcePort , ushort destinationPort , uint sequenceNumber , uint acknowledgementNumber , int tcpHeaderLength , int flags , ushort window , ushort checksum , ushort urgentPointer )
368+ public TCPHeader ( ushort sourcePort , ushort destinationPort , uint sequenceNumber , uint acknowledgementNumber , int tcpHeaderLength , int flags , ushort window , ushort checksum , ushort urgentPointer )
368369 {
369370 SourcePort = sourcePort ;
370371 DestinationPort = destinationPort ;
@@ -391,18 +392,18 @@ public TCPHeader(ushort sourcePort, ushort destinationPort, uint sequenceNumber,
391392public class IPHeader
392393{
393394 public IPHeader (
394- int family ,
395- int version ,
395+ int family ,
396+ int version ,
396397 int headerLength ,
397- byte differentiatedServicesField ,
398- ushort totalLength ,
399- ushort identification ,
400- byte flags ,
401- ushort fragmentOffset ,
402- byte ttl ,
403- byte protocol ,
404- ushort headerCheckSum ,
405- IPAddress sourceIP ,
398+ byte differentiatedServicesField ,
399+ ushort totalLength ,
400+ ushort identification ,
401+ byte flags ,
402+ ushort fragmentOffset ,
403+ byte ttl ,
404+ byte protocol ,
405+ ushort headerCheckSum ,
406+ IPAddress sourceIP ,
406407 IPAddress destintationIP )
407408 {
408409 Family = family ;
0 commit comments