diff --git a/src/input/mpegts/mpegts_mux.c b/src/input/mpegts/mpegts_mux.c index c776b86e..06c88f92 100644 --- a/src/input/mpegts/mpegts_mux.c +++ b/src/input/mpegts/mpegts_mux.c @@ -374,7 +374,11 @@ mpegts_mux_start if (!tune) { tvhdebug("mpegts", "%s - no free input (fail=%d)", buf, fail); - return havefree ? SM_CODE_TUNING_FAILED : SM_CODE_NO_FREE_ADAPTER; + LIST_FOREACH(mmi, &mm->mm_instances, mmi_mux_link) + if (!mmi->mmi_tune_failed) + return havefree ? SM_CODE_NO_VALID_ADAPTER : SM_CODE_NO_FREE_ADAPTER; + tvhdebug("mpegts", "%s - tuning failed", buf); + return SM_CODE_TUNING_FAILED; } return 0; diff --git a/src/input/mpegts/mpegts_network.c b/src/input/mpegts/mpegts_network.c index 9d6a3615..9b1905a7 100644 --- a/src/input/mpegts/mpegts_network.c +++ b/src/input/mpegts/mpegts_network.c @@ -238,10 +238,14 @@ mpegts_network_initial_scan(void *aux) { int r; mpegts_network_t *mn = aux; - mpegts_mux_t *mm; + mpegts_mux_t *mm, *mark = NULL; tvhtrace("mpegts", "setup initial scan for %p", mn); while((mm = TAILQ_FIRST(&mn->mn_initial_scan_pending_queue)) != NULL) { + + /* Stop */ + if (mm == mark) break; + assert(mm->mm_initial_scan_status == MM_SCAN_PENDING); r = mpegts_mux_subscribe(mm, "initscan", 1); @@ -255,8 +259,21 @@ mpegts_network_initial_scan(void *aux) continue; } - /* Remove */ TAILQ_REMOVE(&mn->mn_initial_scan_pending_queue, mm, mm_initial_scan_link); + + /* Available tuners can't be used + * Note: this is subtly different it does not imply there are no free + * tuners, just that none of the free ones can service this mux. + * therefore we move this to the back of the queue and see if we + * can find one we can tune + */ + if (r == SM_CODE_NO_VALID_ADAPTER) { + if (!mark) mark = mm; + TAILQ_INSERT_TAIL(&mn->mn_initial_scan_pending_queue, mm, mm_initial_scan_link); + continue; + } + + /* Remove */ mpegts_mux_initial_scan_fail(mm); } gtimer_arm(&mn->mn_initial_scan_timer, mpegts_network_initial_scan, mn, 10); diff --git a/src/tvheadend.h b/src/tvheadend.h index 6c062c9c..e7d0a226 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -371,6 +371,7 @@ typedef enum { #define SM_CODE_BAD_SIGNAL 205 #define SM_CODE_NO_SOURCE 206 #define SM_CODE_NO_SERVICE 207 +#define SM_CODE_NO_VALID_ADAPTER 308 #define SM_CODE_ABORTED 300