change semantics for transport stop so we dont leak memory

This commit is contained in:
Andreas Öman 2007-11-28 09:16:16 +00:00
parent 23b72c500d
commit 44e7245df2
6 changed files with 23 additions and 16 deletions

View file

@ -142,7 +142,6 @@ avgen_stop_feed(th_transport_t *t)
free(avg);
t->tht_status = TRANSPORT_IDLE;
transport_flush_subscribers(t);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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 */

1
v4l.c
View file

@ -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);