diff --git a/src/input/mpegts/mpegts_input.c b/src/input/mpegts/mpegts_input.c index a72916ca..4073c946 100644 --- a/src/input/mpegts/mpegts_input.c +++ b/src/input/mpegts/mpegts_input.c @@ -181,7 +181,10 @@ mpegts_input_table_thread ( void *aux ) int mpegts_input_is_free ( mpegts_input_t *mi ) { - return LIST_FIRST(&mi->mi_mux_active) == NULL; + int r; + r = (LIST_FIRST(&mi->mi_mux_active) == NULL); + printf("mpegts_input_is_free(%p) = %d\n", mi, r); + return r; } int diff --git a/src/input/mpegts/mpegts_mux.c b/src/input/mpegts/mpegts_mux.c index a88ef74c..a5d3a4bd 100644 --- a/src/input/mpegts/mpegts_mux.c +++ b/src/input/mpegts/mpegts_mux.c @@ -31,14 +31,6 @@ const idclass_t mpegts_mux_instance_class = } }; -#if 0 -static int -mpegts_mux_instance_weight ( mpegts_mux_instance_t *mmi ) -{ - return 0; -} -#endif - mpegts_mux_instance_t * mpegts_mux_instance_create0 ( size_t alloc, const char *uuid, mpegts_input_t *mi, mpegts_mux_t *mm ) @@ -122,9 +114,10 @@ mpegts_mux_start ( mpegts_mux_t *mm, const char *reason, int weight ) while (1) { /* Find free input */ + printf("checking for free input\n"); LIST_FOREACH(mmi, &mm->mm_instances, mmi_mux_link) if (!mmi->mmi_tune_failed && - !mmi->mmi_input->mi_is_free(mmi->mmi_input)); + !mmi->mmi_input->mi_is_free(mmi->mmi_input)) break; printf("free input ?= %p\n", mmi); diff --git a/src/input/mpegts/tsfile/tsfile_input.c b/src/input/mpegts/tsfile/tsfile_input.c index d58f1af8..7f7ecdc1 100644 --- a/src/input/mpegts/tsfile/tsfile_input.c +++ b/src/input/mpegts/tsfile/tsfile_input.c @@ -48,17 +48,14 @@ tsfile_input_thread ( void *aux ) printf("waiting for lock..\n"); pthread_mutex_lock(&global_lock); printf("got lock\n"); -#if 0 -printf("cur mux = %p\n", mi->mi_mux_current); - if (mi->mi_mux_current) { - mmi = (tsfile_mux_instance_t*)mi->mi_mux_current; - fd = tvh_open(mmi->mmi_tsfile_path, O_RDONLY | O_NONBLOCK, 0); - if (fd == -1) { + + if ((mmi = LIST_FIRST(&mi->mi_mux_active))) { + tsfile_mux_instance_t *tmi = (tsfile_mux_instance_t*)mmi; + fd = tvh_open(tmi->mmi_tsfile_path, O_RDONLY | O_NONBLOCK, 0); + if (fd == -1) tvhlog(LOG_ERR, "tsfile", "open(%s) failed %d (%s)", - mmi->mmi_tsfile_path, errno, strerror(errno)); - } + tmi->mmi_tsfile_path, errno, strerror(errno)); } -#endif pthread_mutex_unlock(&global_lock); if (fd == -1) return NULL; printf("file opened = %d\n", fd); @@ -144,6 +141,8 @@ static void tsfile_input_stop_mux ( mpegts_input_t *mi ) { int err; + mpegts_mux_instance_t *mmi = LIST_FIRST(&mi->mi_mux_active); + assert(mmi != NULL); /* Stop thread */ if (mi->mi_thread_pipe.rd != -1) { @@ -155,10 +154,8 @@ tsfile_input_stop_mux ( mpegts_input_t *mi ) tvhtrace("tsfile", "adapter %d stopped thread", mi->mi_instance); } -#if 0 - mi->mi_mux_current->mmi_mux->mm_active = NULL; - mi->mi_mux_current = NULL; -#endif + mmi->mmi_mux->mm_active = NULL; + LIST_REMOVE(mmi, mmi_active_link); } static int @@ -171,6 +168,7 @@ tsfile_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *t ) /* Already tuned */ assert(mmi->mmi_mux->mm_active == NULL); + assert(LIST_FIRST(&mi->mi_mux_active) == NULL); /* Check file is accessible */ if (lstat(mmi->mmi_tsfile_path, &st)) { @@ -191,7 +189,8 @@ tsfile_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *t ) } /* Current */ - //mi->mi_mux_current = mmi->mmi_mux->mm_active = t; + mmi->mmi_mux->mm_active = t; + LIST_INSERT_HEAD(&mi->mi_mux_active, t, mmi_active_link); /* Install table handlers */ mpegts_table_add(mm, 0x0, 0xff, psi_pat_callback, NULL, "pat",