BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
706 stars 284 forks source link

Multicast, improvements, bug fixes #64

Open RandDruid opened 4 years ago

RandDruid commented 4 years ago

bug fixes: 1) SDES packet header - padding flag must be "false". Fixed. 2) SDES chunk - text length should not include /0. Fixed. 3) SDES reports were sent to RTP port instead of RTCP. Fixed. 4) Since Socket.ReceiveAsync do not natively support cancellation, and receive task was waiting for complete of both RTP and RTCP receive, "normal" cancellation never took place. CloseRtspSessionAsync never called because sockets were closed due to CancelTimeout. As a result, TEARDOWN was never sent. I added WithCancellation task extension and now ReadAsync can be canceled immediately without wait for next incoming packet. I modified only UDP part, but extension can be used in other places too.

improvements: 1) "Receiver Report Goodbye" packet is sent on session close. 2) UDP sockets are bound to only one interface, which IP is retrieved from already connected RTSP session. This improves security in certain usage scenarios, especially with multicast.

new features: 1) UDP multicast support. New SETUP request asking for multicast. New socket extension for multicast groups. Implementation logic is similar to FFMPEG "forced multicast" or VLC --rtsp-mcast option.

todo: 1) so far tested on only one device - TRUEN HD encoder 2) Transport Protocol may be selected based on device capabilities (AUTO option?)

RandDruid commented 4 years ago

Test on different PC and two different video encoders. Found small problem with IPv6 addresses, but already fixed it in third commit. But in general works like a charm. In a dump below PC .244 opens and closes two sessions to .13 and .14. Encoders multicast to 224.10.0.0 and 239.127.0.14 respectively. RTP & H264 packets are hidden. dump_2streams