diff --git a/mux.c b/mux.c index 0fc49016..d0a3abc6 100644 --- a/mux.c +++ b/mux.c @@ -64,8 +64,10 @@ muxer_play(th_muxer_t *tm, int64_t toffset) { th_subscription_t *s = tm->tm_subscription; - if(!tm->tm_linked) + if(!tm->tm_linked) { LIST_INSERT_HEAD(&s->ths_transport->tht_muxers, tm, tm_transport_link); + tm->tm_linked = 1; + } if(toffset == AV_NOPTS_VALUE) { /* continue from last playback */ @@ -197,7 +199,7 @@ muxer_deinit(th_muxer_t *tm, th_subscription_t *s) s->ths_muxer = NULL; if(tm->tm_linked) - LIST_INSERT_HEAD(&s->ths_transport->tht_muxers, tm, tm_transport_link); + LIST_REMOVE(tm, tm_transport_link); while((tms = LIST_FIRST(&tm->tm_streams)) != NULL) tms_destroy(tms); diff --git a/transports.c b/transports.c index d853012f..0a94c262 100644 --- a/transports.c +++ b/transports.c @@ -108,8 +108,10 @@ transport_stop(th_transport_t *t, int flush_subscriptions) st->st_buffer_ptr = 0; st->st_startcode = 0; - if(st->st_curpkt != NULL) + if(st->st_curpkt != NULL) { pkt_deref(st->st_curpkt); + st->st_curpkt = NULL; + } /* Clear PTS queue */ diff --git a/tsmux.c b/tsmux.c index 2ef07ce2..59543f85 100644 --- a/tsmux.c +++ b/tsmux.c @@ -696,9 +696,29 @@ ts_muxer_init(th_subscription_t *s, ts_mux_output_t *output, void ts_muxer_deinit(ts_muxer_t *ts, th_subscription_t *s) { - free(ts->ts_packet); - muxer_deinit(ts->ts_muxer, s); + th_muxstream_t *tms; + th_muxer_t *tm = s->ths_muxer; + th_muxpkt_t *f; + th_refpkt_t *o; + dtimer_disarm(&ts->ts_patpmt_timer); + + LIST_FOREACH(tms, &tm->tm_streams, tms_muxer_link0) { + dtimer_disarm(&tms->tms_mux_timer); + + /* Free mux packets */ + while((f = tmf_deq(&tms->tms_delivery_fifo)) != NULL) + free(f); + + /* Unreference lookahead queue */ + while((o = TAILQ_FIRST(&tms->tms_lookahead)) != NULL) { + pkt_deref(o->trp_pkt); + TAILQ_REMOVE(&tms->tms_lookahead, o, trp_link); + } + } + + free(ts->ts_packet); + muxer_deinit(tm, s); free(ts); }