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

Increased default UDP receive buffer size #59

Closed RandDruid closed 4 years ago

RandDruid commented 4 years ago

To make video more fluid on HD channel (8 Mbit/s).

BogdanovKirill commented 4 years ago

Hello !

Could you also test TCP. Should we increase it to 128 Kb in that case ?

RandDruid commented 4 years ago

It's strange, but TCP works fine with 64k. On UDP 64k causes short interruptions ~0.5 sec every several seconds.

BogdanovKirill commented 4 years ago

Is it possible to check on another hardware (different machine or may be network card) ?

RandDruid commented 4 years ago

Yes, I will check it on my laptop tomorrow.

RandDruid commented 4 years ago

I checked this issue on my laptop. Sometimes it works fine with default 64k UDP buffer, but I saw several short stops over 5 minutes interval. With 128k buffer video never stops. My hypothesis is that short stops are connected to I Frames. I checked with Wireshark, in my case size of I Frame is ~74 kbytes. May be parts of this frame (singular udp packets) are lost if socket buffer is not big enough. And it never happens with TCP because it smart enough to re-transmit if needed. I didn't analyze complete call chain in player, but finally frame copied to WritableBitmap in GUI thread. And if GUI thread is locked for longer then 40 ms (inter-frame delay for 25 fps) something may go wrong. If you hesitant to always spend extra 64k, I can implement it like an option and bring to upper API levels. For example to ConnectionParameters.

BogdanovKirill commented 4 years ago

Thank you for your deep research. I don't see any problem to increase buffer by 64k. Just trying to figure out how much this buffer should be increased. We could start from additional 64k and may be increase the whole buffer size up to 512k or even more in future.