From 09a2c71abb01db8735437f233b8a54a0bb4939fc Mon Sep 17 00:00:00 2001 From: Michael Marley Date: Sat, 11 Dec 2021 21:01:08 -0500 Subject: [PATCH] iptv: Fix stream limit starting a new input on a running mux In iptv.c:iptv_input_is_free(), if all the conf arguments are 0 (when called from input_is_enabled()), return null if the mux associated with the input is already running. If the mux is already running, starting a new input on it isn't going to create a new input stream or break any bandwidth limit. This fixes an issue where starting a new channel/input on a mux that is already active when the maximum number of input streams are in use would result in failure. This function is rather dense and appears to perform multiple different functions depending on who called it, so I had a hard time understanding exactly what is going on. Therefore, I made this patch in a way to be sure that it wouldn't affect how it works in other cases than input_is_enabled(). If there is a better way to do this, please do tell me. --- src/input/mpegts/iptv/iptv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index 07b5266f1..8334de205 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -137,7 +137,7 @@ static mpegts_mux_instance_t * iptv_input_is_free ( mpegts_input_t *mi, mpegts_mux_t *mm, iptv_is_free_t *conf, int weight, int *lweight ) { - int h = 0, l = 0, w, rw = INT_MAX; + int h = 0, l = 0, mux_running = 0, w, rw = INT_MAX; mpegts_mux_instance_t *mmi, *rmmi = NULL; iptv_input_t *mi2; iptv_network_t *in = (iptv_network_t *)mm->mm_network; @@ -148,6 +148,7 @@ iptv_input_is_free ( mpegts_input_t *mi, mpegts_mux_t *mm, tvh_mutex_lock(&mi2->mi_output_lock); LIST_FOREACH(mmi, &mi2->mi_mux_active, mmi_active_link) if (mmi->mmi_mux->mm_network == (mpegts_network_t *)in) { + mux_running = mux_running || mmi->mmi_mux == mm; w = mpegts_mux_instance_weight(mmi); if (w < rw && (!conf->active || mmi->mmi_mux != mm)) { rmmi = mmi; @@ -158,6 +159,10 @@ iptv_input_is_free ( mpegts_input_t *mi, mpegts_mux_t *mm, tvh_mutex_unlock(&mi2->mi_output_lock); } + /* If we are checking if an input is free, return null if the mux's input is already running */ + if (!conf->active && !conf->weight && !conf->warm && mux_running) + return NULL; + tvhtrace(LS_IPTV_SUB, "is free[%p]: h = %d, l = %d, rw = %d", mm, h, l, rw); if (lweight) -- 2.47.2