Skip to content

More accurate next player selection and preventing endless restarts when a specific player is selected - #4960

Open
IgorA100 wants to merge 20 commits into
ZoneMinder:masterfrom
IgorA100:patch-865636
Open

More accurate next player selection and preventing endless restarts when a specific player is selected#4960
IgorA100 wants to merge 20 commits into
ZoneMinder:masterfrom
IgorA100:patch-865636

Conversation

@IgorA100

@IgorA100 IgorA100 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor
  • When broadcasting a stream in an unsupported RTSP2Web format (for example, H265), select the next player
  • We'll now keep track of playback errors when a specific player is selected. After two consecutive errors, we'll stop trying to restart the player and notify the user. After playback successfully starts, we'll clear the error counter.
  • More accurate player switching for mode=Auto and mode=go2rtc and more comprehensive error handling.
  • Added getCountStreamErrors() and resetCountStreamErrors() methods.
  • On the Montage page, run hls.js without parsing RTSP2WebType == "HLS" because we use automatic player switching, and even if we don't use the HLS type by default, the player may switch to HLS when using RTSP2Web.
  • Added waitingWebrtcPlayback to video-stream.js to detect the start of RTC playback. If we receive a 'webrtc/candidate' candidate, the next step is to start playback. We wait 3 seconds, and if the video hasn't loaded, we log the error and switch to another player.
  • Error logging in video-stream.js occurs via errorHandling() and allows us to display a text message in the video display block. - Before logging errors, we change monitorStream.player to a specific go2rtc_webrtc or go2rtc_mse player, since we don't have just "go2rtc" in the list of players to switch to.
  • We'll simplify getting monitorStream: instead of looking for the parent liveStream and getting its ID, we'll directly request getMonitorStream(stringToNumber(this.id))
  • Go2RTC errors now generate the onErrorGo2RTC event.
  • Added the ability to display text information (typically used to inform about errors) in the block where the stream is displayed. The class for the block is ".info-text"
  • We no longer need the changes made in 8b9546d
  • this.started = false; In this.stop() in MonitorStream.js we will move it higher in the code so that when stopping, the correct state of the stream is already set. No, we'll leave everything as is in this PR, otherwise some things will break. However, in the future, we'll need to analyze the move of this.started = false; further up in the code in more detail.

@IgorA100 IgorA100 changed the title When broadcasting a stream in an unsupported RTSP2Web format (for example, H265), select the next player More accurate next player selection and preventing endless restarts when a specific player is selected Jul 5, 2026
IgorA100 added a commit to IgorA100/zoneminder that referenced this pull request Jul 6, 2026
…b in HLS mode, stop playback and restart. Yes, for now, it will restart in an infinite loop if a specific player is selected in the browser. However, this will be changed in the next PR ZoneMinder#4960.

- Execute this.updateStreamInfo('', '') only after playback starts, not after MEDIA_ATTACHED, since that will cause a delay. There may be more errors later (for example, an unsupported audio codec, an m3u8 manifest error, or other errors.)
- Execute this.updateStreamInfo('', 'Error') and log errors only if the error is fatal.
- Moved this.streamErrorRegistration() lower in the code.
IgorA100 and others added 5 commits July 6, 2026 18:00
…re comprehensive error handling.

- Added getCountStreamErrors() and resetCountStreamErrors() methods.
- On the Montage page, run hls.js without parsing RTSP2WebType == "HLS" because we use automatic player switching, and even if we don't use the HLS type by default, the player may switch to HLS when using RTSP2Web.
- Added waitingWebrtcPlayback to video-stream.js to detect the start of RTC playback. If we receive a 'webrtc/candidate' candidate, the next step is to start playback. We wait 3 seconds, and if the video hasn't loaded, we log the error and switch to another player.
- Error logging in video-stream.js occurs via errorHandling() and allows us to display a text message in the video display block. - Before logging errors, we change monitorStream.player to a specific go2rtc_webrtc or go2rtc_mse player, since we don't have just "go2rtc" in the list of players to switch to.
- We'll simplify getting monitorStream: instead of looking for the parent liveStream and getting its ID, we'll directly request getMonitorStream(stringToNumber(this.id))
- Go2RTC errors now generate the onErrorGo2RTC event.
- Added the ability to display text information (typically used to inform about errors) in the block where the stream is displayed. The class for the block is ".info-text"
- We no longer need the changes made in ZoneMinder@8b9546d
- this.started = false; In this.stop() in MonitorStream.js we will move it higher in the code so that when stopping, the correct state of the stream is already set.
@IgorA100

IgorA100 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@connortechnology
Please, if possible, have Copilot review this PR.

@IgorA100
IgorA100 marked this pull request as ready for review July 7, 2026 16:24
IgorA100 added a commit to IgorA100/zoneminder that referenced this pull request Jul 9, 2026
…tch page.

- Some players may take a long time to start playing a stream (several seconds) and if a short cycle is selected (5 or 10 seconds), then half of the time or more the stream is in standby mode and viewing may occur within 1-5 seconds instead of the planned 5 or 10 seconds. Now the player will play the stream for the time specified in the cycle parameters
- If a specific player is selected on the page, then in case of repeated errors it will switch to the next monitor. In the "Auto" mode, theoretically we should always get to the ZMS player.
- This change will only work if approved by PR ZoneMinder#4960
@IgorA100

Copy link
Copy Markdown
Contributor Author

Isaac, is there anything I should redo or do you not have time to check this PR?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves stream playback robustness in the classic web UI by enhancing automatic player switching and adding safeguards to prevent endless restart loops when a specific player is selected (especially around Go2RTC/RTSP2Web edge cases like unsupported codecs).

Changes:

  • Adds consecutive playback-error counting with a stop-after-N-attempts behavior and reset hooks on successful playback.
  • Improves player switching logic (Auto vs pinned selections) and expands error handling/reporting (including UI text overlays).
  • Adjusts Montage behavior to allow automatic switching to HLS when RTSP2Web is enabled (and adds WebRTC “start detection” timeout handling).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
web/skins/classic/views/montage.php Load HLS support whenever RTSP2Web is enabled to support auto-switching scenarios.
web/skins/classic/js/skin.js Adds Go2RTC error event handling/fallback and improves track-based logic for switching players when video is missing.
web/skins/classic/css/base/skin.css Adds .info-text styling for in-stream informational/error text overlays.
web/js/video-stream.js Enhances Go2RTC event/error handling and integrates error counting reset + WebRTC startup timeout logic.
web/js/MonitorStream.js Introduces error-count limiting, player selection tweaks, info-text support, and updated RTSP2Web MSE error handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web/js/video-stream.js
Comment thread web/js/video-stream.js
Comment thread web/js/MonitorStream.js
Comment thread web/js/MonitorStream.js
Comment thread web/js/MonitorStream.js
Comment thread web/skins/classic/js/skin.js
Comment thread web/skins/classic/js/skin.js
@IgorA100

Copy link
Copy Markdown
Contributor Author

I'll come back to this PR a bit later, as I'm currently busy fixing the KeyframeOnly decoding mode.

@IgorA100
IgorA100 marked this pull request as draft July 18, 2026 19:29
@IgorA100
IgorA100 marked this pull request as ready for review July 23, 2026 17:51
@IgorA100

Copy link
Copy Markdown
Contributor Author

I made the necessary adjustments and left comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants