tv icon indicating copy to clipboard operation
tv copied to clipboard

Start RTMP forwarding when RTMP source arrives

Open lastcanal opened this issue 1 year ago • 4 comments

This fixes a ~1 second delay in audio when multi-streaming, tested on Twitch.

It is possible that calling :multicast_algora may still result in a de-sync of audio and video while forwarding. Adding a field/flag to the user/channel would allow multicasting to "Algora" when the RTMP source arrives, instead of ad-hoc like it is now.

lastcanal avatar Dec 16 '24 18:12 lastcanal

Very nice!

I ran into an issue where some pipeline components crashed while the pipeline itself remained running. In this scenario, attempting to reconnect leads to [warning] No demand made for client /live/●●●●●●●●●●●, terminating connection. until the pipeline is manually terminated :thinking:

zcesur avatar Dec 17 '24 00:12 zcesur

It seems like starting RTMP forwarding in the same group as the source has messed up reconnecting...

I am getting this error now:

[error] GenServer #PID<0.2169.0> terminating
** (MatchError) no match of right hand side value: %{input: [{Membrane.Pad, :input, #Reference<0.740859990.2745171970.64194>}]}
    (membrane_mp4_plugin 0.35.2) lib/membrane_mp4/muxer/cmaf.ex:227: Membrane.MP4.Muxer.CMAF.handle_playing/2
    (membrane_core 1.0.1) lib/membrane/core/callback_handler.ex:139: Membrane.Core.CallbackHandler.exec_callback/4
    (membrane_core 1.0.1) lib/membrane/core/callback_handler.ex:69: Membrane.Core.CallbackHandler.exec_and_handle_callback/5
    (membrane_core 1.0.1) lib/membrane/core/element/lifecycle_controller.ex:84: Membrane.Core.Element.LifecycleController.handle_playing/1
    (membrane_core 1.0.1) lib/membrane/core/element.ex:249: Membrane.Core.Element.handle_info/2
    (stdlib 6.1) gen_server.erl:2345: :gen_server.try_handle_info/3
    (stdlib 6.1) gen_server.erl:2433: :gen_server.handle_msg/6
    (stdlib 6.1) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: {Membrane.Core.Message, :play, [], []}

lastcanal avatar Dec 17 '24 04:12 lastcanal

I don't think that's related to forwarding - been having this issue before this PR, even without any forwarding. Seems to be caused by a timeout when sending link messages between CMAF muxers and the sink. See #131

zcesur avatar Dec 17 '24 12:12 zcesur

I've rebased this against main and got rid of the delay when reconnecting. Denying incoming RTMP connections isn't very straight forward, or at least I couldn't figure out a way to do it without adding it to a pipeline, so I added Algora.Pipeline.AbortPipeline which accepts the RTMP connection before letting the pipeline terminate, which does an orderly shutdown of the RTMP connection. Might be worth looking into adding something to membrane_rtmp_plugin to make denying an incoming RTMP connections a bit easier.

lastcanal avatar Dec 18 '24 21:12 lastcanal