SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
333 stars 105 forks source link

support for tcp transmission #118

Closed nivhsay closed 1 year ago

nivhsay commented 1 year ago

Fixes #111

SamuelScheit commented 1 year ago

Thank you very much for your contribution 👍 Whats the purpose of keeping UDP, when its not working properly in some situations? I think we should remove UDP altogether and only use tcp sockets

nivhsay commented 1 year ago

We could yes. But I wouldn't say UDP does not work. It works and supposedly should be lower latency; the transmission should be starting faster with UDP but I did not do any benchmarking.

UDP worked in most of my user cases. But sometimes when there were high CPU loads, then it would have those broken frames. The high CPU load is probably just because of the MediaRecorder not being able to use GPU in my docker container.

I had to have it work reliably, so I made a patch to always use TCP on my setup.

Maybe having a lower latency startup might be of value to someone?

SamuelScheit commented 1 year ago

yeah thats right, I'll do a benchmark and see how they compare 👍

SamuelScheit commented 1 year ago

In average the TCP method took 1.544 seconds to get the first packet (measured after getStream was called). In comparison the UDP method took 1.494 seconds. The variation between the measures where fairly high +-200ms, so there isn't a real latency difference between UDP and TCP when starting the stream. The latency bottleneck is the chrome tab capturer and the media recorder, which we don't have control over. So I think we should switch to TCP only, as it makes the transmission more reliable and does not impose any measurable latency. I'll edit the PR 👍 #119

SamuelScheit commented 1 year ago

published in the latest version 3.0.5

nivhsay commented 1 year ago

Great