Eyevinn / srt-whep

SRT to WHEP (WebRTC)
Apache License 2.0
80 stars 10 forks source link

Need to handle connect and disconnects in listener mode #28

Closed birme closed 1 year ago

birme commented 1 year ago

When running in listener mode it needs to handle connect and disconnects from SRT client (in caller mode)

Wkkkkk commented 1 year ago

Commit (https://github.com/Eyevinn/srt-whep/commit/81fb1195d591e795cc92ad783fb33842ce189bb4) tried to handle disconnects from SRT clients. When we are in listener mode and the client (caller) disconnects, we reset the pipeline so another client could connect.

Changes are:

  1. Stop the pipeline when an EOS or error message occurs
  2. Reset and rerun the pipeline in case of EOS
  3. Stop the program in other cases (errors, or ctrl-c)

Problems:

  1. Webrtc bins could enter a half-closed state when being reset. This would stop the pipeline from being reset.
Wkkkkk commented 1 year ago

Possible solutions are:

Wkkkkk commented 1 year ago

Some updates on this issue:

  1. SRT clients (caller) can connect/disconnect freely when there exist no viewers. The pipeline will reset itself and rerun once seeing EOS.
  2. When there are viewers (connection to the WebRTC Player) and the SRT client disconnects, the EOS message will be forwarded until the end of the pipeline (whipsink in our case). Therefore, whipsinks need to listen to EOS and terminate all WebRTC sessions before we can reset the pipeline. This will be addressed in a patch soon.
  3. If a viewer chooses to stop playing, a DELETE request will be received and the pipeline will remove the corresponding branch. Then there is no problem if now the SRT client disconnects too. However, closing a browser tab will not post a DELETE request and the corresponding WebRTCBin still runs. We need to handle this as stated in issue #38.
birme commented 1 year ago

It will be difficult from the player side to send a DELETE when the browser tab is closed. We should have a mechanism that removes viewer resources that are idle. What if all viewer resources are removed when the SRT input is lost?

Wkkkkk commented 1 year ago

Some updates on this issue:

  1. SRT clients (caller) can connect/disconnect freely now. The pipeline will reset itself and rerun once seeing EOS. This means: 1.1 It is possible to switch the SRT input stream at run time. 1.2 If there are running webrtc sessions, viewers will see a frozen stream. It is recommended that they refresh the tab before reconnect (otherwise, auto-reconnection will happen together with the connection and mess it up).
  2. Viewers from browser can connect/disconnect as they wish too. 2.1. If there exists no SRT input stream yet, an error will be returned so no stream will be played out. 2.2 If the viewer disconnects (hits the button) a running session, the corresponding resource will be released. 2.3 If the viewer close/refresh the tab without disconnecting first, the corresponding resource will NOT be released. However, when the SRT client disconnects (i.e., SRT input is lost), all resources (busy or idle) will be cleaned up.
Wkkkkk commented 1 year ago

Right now all viewer resources are removed when the SRT input is lost.

A better approach is to monitor 'consumer-added/removed' signal from webrtcbin but it seems not to work as expected. Will keep investigating on that.