WebRTC icon indicating copy to clipboard operation
WebRTC copied to clipboard

Background Camera streams pause after some amount of time

Open Bad-Magic opened this issue 1 year ago • 7 comments

WebRTC v3.1.0 HA 2023.4.1 Frontend 20230406.1

I have 5 Ubiquiti cameras connecting over rtsp & configured in MSE only mode in chrome on an ipad. The streams open without any issue, but after a few minutes the streams pause and start buffering content. Eventually, they turn black and are disconnected. No interaction at all with the ipad during this time - it's a camera + calendar display.

Nothing obvious in the logs with default settings in HA.

Assuming these are buffering - the desired outcome would be for these cameras to flush their buffer and stay in real time no matter what.

Happy to pull logs or other info. Please let me know how I can help debug.

Bad-Magic avatar Apr 08 '23 22:04 Bad-Magic

I've been able to reproduce a similar appearing issue on chrome for mac by repeatedly swapping tabs and triggering video-rtc.connectedCallback(). Grabbing the video object into temp1, it appears that the video player is being set to a time outside the buffer. Manually setting temp1.currentTime = temp1.seekable.end(0) resumes playing.

image

Interesting notes as I continue to debug: This is only happening on cards with background: true configured.

Bad-Magic avatar Apr 16 '23 16:04 Bad-Magic

Tentatively, removing background: true from the cards resolves this. My dashboard has been running for about an hour without any issues. Will let it run overnight.

Assuming this holds true, the issue is likely that the stream eventually slips outside of the content in the buffer and then hangs.

The return statement here prevents the call to this.connectedCallback(); which contains code to jump to the front of the buffer. https://github.com/AlexxIT/WebRTC/blob/master/custom_components/webrtc/www/video-rtc.js#L240

Bad-Magic avatar Apr 16 '23 18:04 Bad-Magic

Continuing to see issues on my HA dashboard after 30-90 minutes. Still unable to reproduce without background: true by switching tabs. Going to leave a long running stream running on my laptop to see if I can get it to reproduce and debug.

Bad-Magic avatar Apr 16 '23 19:04 Bad-Magic

I've added a handler to the video.onpause, and verified that the video on my ipad seems to be being caused by something calling pause() on the video objects randomly.

Current SWAG is the video is underflowing and safari is pausing similar to - https://stackoverflow.com/questions/74461792/mediasource-api-safari-pauses-video-on-buffer-underflow

Applying an infinite duration resolved the issue on safari for desktop (the video is flagged as a livestream and never pauses). Unfortunately, this doesn't resolve the issue on safari for iPad.

Bad-Magic avatar Apr 16 '23 23:04 Bad-Magic

I've added a handler to the video.onpause, and verified that the video on my ipad seems to be being caused by something calling pause() on the video objects randomly.

Current SWAG is the video is underflowing and safari is pausing similar to - https://stackoverflow.com/questions/74461792/mediasource-api-safari-pauses-video-on-buffer-underflow

Applying an infinite duration resolved the issue on safari for desktop (the video is flagged as a livestream and never pauses). Unfortunately, this doesn't resolve the issue on safari for iPad.

Hi what is it I add to get this working. Thanks

direx1 avatar Apr 26 '23 10:04 direx1

There is a known problem, MSE can crash if the RTSP stream is "broken"

AlexxIT avatar Apr 26 '23 13:04 AlexxIT

In this case, the RTSP stream isn't broken. The pause event comes in (presumably because the buffer is empty on the browser side), but it then immediately starts to buffer content. Hitting play returns the card to playback without any issue.

Currently, it seems like adding the infinite duration resolves the issue on safari for desktop and ipad (my prior report was incorrect - I assume I had a locally cached JS file which meant it wasn't actually running the new code) which is good enough for me. My initial thought would be to add a config entry real_time to the card config with a default to false.

I still do see periodic stream errors, but they seem unrelated. I'll do some more debugging on this and file another bug if I can figure out enough info to reproduce.

Bad-Magic avatar Apr 26 '23 16:04 Bad-Magic