algora-io / tv

Open source Twitch for developers
https://algora.tv
GNU Affero General Public License v3.0
867 stars 48 forks source link

Implement stream resumption feature for handling disconnections #73

Open zcesur opened 2 weeks ago

zcesur commented 2 weeks ago

Livestreams sometimes get interrupted due to network issues, OBS crash, server crash, streamer taking a break etc. When the user makes a new RTMP connection, our current pipeline initializes a new livestream on a new URL along with a new HLS playlist.

We should introduce a reconnection window (e.g. 1 hour) where we reconnect the user to their latest livestream.

To do that, we likely need to modify Membrane.HTTPAdaptiveStream.SinkBin to accept an existing playlist and initialize its state with that.

In addition we might need to add a discontinuity event/marker (EXT-X-DISCONTINUITY tag) at the end of the playlist so that the video player can play everything properly (as commonly used for mid-roll ads)

The player should seamlessly transition to the new segment without the user having to refresh the page.

zcesur commented 2 weeks ago

/bounty 400

algora-pbc[bot] commented 2 weeks ago

💎 $400 bounty • Algora

Steps to solve:

  1. Start working: Comment /attempt #73 with your implementation plan
  2. Submit work: Create a pull request including /claim #73 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

❗ Important guidelines:

Thank you for contributing to algora-io/tv!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @Raushankumar-prog Aug 29, 2024, 8:23:09 PM WIP
Raushankumar-prog commented 2 weeks ago

/attempt #73

deepakdinesh1123 commented 2 weeks ago

@zcesur I setup algora on my local to work on this but when I try to livestream the stream gets cancelled as it cannot create a thumbnail and a new stream gets started, I think this is occurring due to running it on a mac M1 as rambo only supports x86_64 and requires rust compiler to use other architectures ( I have it installed but still running into error) just wanted to ask if you are using a mac arm based machine and how you have set it up

Edit:

I was able to set it up, let me know if you want me to add a section on how to setup in docs, could you please let me know what should be the value of the EVENT_SINK_URL

zcesur commented 2 weeks ago

Ooh interesting, yeah that'd be great to have in docs!

Re: EVENT_SINK_URL just leave it empty, filling out these env variables should be enough for almost all features

deepakdinesh1123 commented 2 weeks ago

@zcesur I keep getting this error whenever I try to stream

[error] <0.860.0>/ Error occured in Membrane Pipeline:
%ArgumentError{message: "scheme is required for url: "}
    (finch 0.18.0) lib/finch/request.ex:135: Finch.Request.parse_url/1
    (finch 0.18.0) lib/finch/request.ex:103: Finch.Request.build/5
    (algora 0.1.0) lib/algora/library.ex:325: Algora.Library.toggle_streamer_live/2
    (algora 0.1.0) lib/algora/pipeline.ex:77: Algora.Pipeline.handle_child_notification/4
    (membrane_core 1.1.0) lib/membrane/core/callback_handler.ex:139: Membrane.Core.CallbackHandler.exec_callback/4
    (membrane_core 1.1.0) lib/membrane/core/callback_handler.ex:69: Membrane.Core.CallbackHandler.exec_and_handle_callback/5
    (membrane_core 1.1.0) lib/membrane/core/pipeline.ex:119: Membrane.Core.Pipeline.do_handle_info/2
    (membrane_core 1.1.0) lib/membrane/core/pipeline.ex:93: Membrane.Core.Pipeline.handle_info/2
    (stdlib 5.2.3) gen_server.erl:1095: :gen_server.try_handle_info/3
    (stdlib 5.2.3) gen_server.erl:1183: :gen_server.handle_msg/6
    (stdlib 5.2.3) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

and in the stream I am seeing this error image

zcesur commented 2 weeks ago

Just pushed a fix to main, can you try again? We were missing the sink_url != "" check

deepakdinesh1123 commented 1 week ago

@zcesur it is working now thank you very much