diff --git a/avgen.c b/avgen.c index 94910e5d..b64df320 100644 --- a/avgen.c +++ b/avgen.c @@ -142,7 +142,6 @@ avgen_stop_feed(th_transport_t *t) free(avg); t->tht_status = TRANSPORT_IDLE; - transport_flush_subscribers(t); } diff --git a/dvb_dvr.c b/dvb_dvr.c index edf4dca8..dd52c972 100644 --- a/dvb_dvr.c +++ b/dvb_dvr.c @@ -109,7 +109,7 @@ dvb_adapter_clean(th_dvb_adapter_t *tda) th_transport_t *t; while((t = LIST_FIRST(&tda->tda_transports)) != NULL) - dvb_stop_feed(t); + transport_stop(t, 1); } @@ -129,7 +129,6 @@ dvb_stop_feed(th_transport_t *t) st->st_demuxer_fd = -1; } t->tht_status = TRANSPORT_IDLE; - transport_flush_subscribers(t); } diff --git a/subscriptions.c b/subscriptions.c index 8c88e319..fe558014 100644 --- a/subscriptions.c +++ b/subscriptions.c @@ -102,7 +102,7 @@ subscription_unsubscribe(th_subscription_t *s) if(t != NULL) { subscription_stop(s); - transport_purge(t); + transport_stop(t, 0); } free(s->ths_title); diff --git a/transports.c b/transports.c index 20cdbee5..623724c5 100644 --- a/transports.c +++ b/transports.c @@ -58,13 +58,19 @@ static dtimer_t transport_monitor_timer; void -transport_purge(th_transport_t *t) +transport_stop(th_transport_t *t, int flush_subscriptions) { + th_subscription_t *s; th_stream_t *st; th_pkt_t *pkt; - if(LIST_FIRST(&t->tht_subscriptions)) - return; + if(flush_subscriptions) { + while((s = LIST_FIRST(&t->tht_subscriptions)) != NULL) + subscription_stop(s); + } else { + if(LIST_FIRST(&t->tht_subscriptions)) + return; + } t->tht_stop_feed(t); @@ -83,6 +89,9 @@ transport_purge(th_transport_t *t) if(st->st_ctx != NULL) avcodec_close(st->st_ctx); + st->st_parser = NULL; + st->st_ctx = NULL; + /* Clear reassembly buffer */ free(st->st_buffer); @@ -136,6 +145,11 @@ transport_start(th_transport_t *t, unsigned int weight) AVCodec *c; enum CodecID id; + assert(t->tht_status != TRANSPORT_RUNNING); + + if(t->tht_start_feed(t, weight, TRANSPORT_RUNNING)) + return -1; + t->tht_monitor_suspend = 10; t->tht_dts_start = AV_NOPTS_VALUE; @@ -155,8 +169,8 @@ transport_start(th_transport_t *t, unsigned int weight) default: id = CODEC_ID_NONE; break; } - st->st_ctx = NULL; - st->st_parser = NULL; + assert(st->st_ctx == NULL); + assert(st->st_parser == NULL); if(id != CODEC_ID_NONE) { c = avcodec_find_decoder(id); @@ -167,8 +181,7 @@ transport_start(th_transport_t *t, unsigned int weight) } } } - - return t->tht_start_feed(t, weight, TRANSPORT_RUNNING); + return 0; } diff --git a/transports.h b/transports.h index 7a2bb999..f4f29e0c 100644 --- a/transports.h +++ b/transports.h @@ -23,7 +23,7 @@ unsigned int transport_compute_weight(struct th_transport_list *head); -void transport_flush_subscribers(th_transport_t *t); +void transport_stop(th_transport_t *t, int flush_subscriptions); void transport_monitor_init(th_transport_t *t); @@ -33,10 +33,7 @@ void transport_link(th_transport_t *t, th_channel_t *ch); th_transport_t *transport_find(th_channel_t *ch, unsigned int weight); -void transport_purge(th_transport_t *t); - th_stream_t *transport_add_stream(th_transport_t *t, int pid, tv_streamtype_t type); - #endif /* TRANSPORTS_H */ diff --git a/v4l.c b/v4l.c index 0c272619..d7bd2676 100644 --- a/v4l.c +++ b/v4l.c @@ -200,7 +200,6 @@ v4l_stop_feed(th_transport_t *t) LIST_REMOVE(t, tht_adapter_link); t->tht_status = TRANSPORT_IDLE; - transport_flush_subscribers(t); if(LIST_FIRST(&tva->tva_transports) == NULL) v4l_stop(tva);