Use channel tag instead of subscription id to avoid weird race

conditions
This commit is contained in:
Andreas Öman 2008-07-08 20:05:15 +00:00
parent 3bf1f26c8d
commit f3305cf6f0
3 changed files with 14 additions and 19 deletions

18
htsp.c
View file

@ -149,15 +149,15 @@ htsp_subscribe(rpc_session_t *ses, htsmsg_t *in, void *opaque)
{
htsp_t *htsp = opaque;
channel_t *ch;
const char *txt;
th_subscription_t *s;
htsmsg_t *r;
uint32_t tag;
if((txt = htsmsg_get_str(in, "channel")) == NULL)
return rpc_error(ses, "missing argument: channel");
if(htsmsg_get_u32(in, "channelTag", &tag))
return rpc_error(ses, "missing argument: channelTag");
if((ch = channel_find(txt, 0, NULL)) == NULL)
if((ch = channel_by_tag(tag)) == NULL)
return rpc_error(ses, "Channel not found");
LIST_FOREACH(s, &htsp->htsp_subscriptions, ths_subscriber_link) {
@ -168,14 +168,10 @@ htsp_subscribe(rpc_session_t *ses, htsmsg_t *in, void *opaque)
}
tag = tag_get();
r = htsmsg_create();
htsmsg_add_u32(r, "seq", ses->rs_seq);
htsmsg_add_u32(r, "id", tag);
htsp_send_msg(htsp, r, 0);
htsp_muxer_subscribe(htsp, ch, 200, tag);
htsp_muxer_subscribe(htsp, ch, 200);
return NULL;
}
@ -190,8 +186,8 @@ htsp_unsubscribe(rpc_session_t *ses, htsmsg_t *in, void *opaque)
htsp_t *htsp = opaque;
uint32_t id;
if(htsmsg_get_u32(in, "id", &id))
return rpc_error(ses, "missing argument: id");
if(htsmsg_get_u32(in, "channelTag", &id))
return rpc_error(ses, "missing argument: channelTag");
htsp_muxer_unsubscribe(htsp, id);

View file

@ -51,7 +51,7 @@ htsp_packet_input(void *opaque, th_muxstream_t *tms, th_pkt_t *pkt)
*/
htsmsg_add_str(m, "method", "muxpkt");
htsmsg_add_u32(m, "id", s->ths_u32);
htsmsg_add_u32(m, "channelTag", s->ths_channel->ch_tag);
htsmsg_add_u64(m, "stream", tms->tms_index);
htsmsg_add_u64(m, "dts", pkt->pkt_dts);
@ -89,7 +89,7 @@ htsp_subscription_callback(struct th_subscription *s,
m = htsmsg_create();
htsmsg_add_str(m, "method", "subscription_start");
htsmsg_add_u32(m, "id", s->ths_u32);
htsmsg_add_u32(m, "channelTag", s->ths_channel->ch_tag);
LIST_FOREACH(tms, &tm->tm_streams, tms_muxer_link0) {
tms->tms_index = index++;
@ -113,7 +113,7 @@ htsp_subscription_callback(struct th_subscription *s,
if(htsp->htsp_zombie == 0) {
m = htsmsg_create();
htsmsg_add_str(m, "method", "subscription_stop");
htsmsg_add_u32(m, "id", s->ths_u32);
htsmsg_add_u32(m, "channelTag", s->ths_channel->ch_tag);
htsmsg_add_str(m, "reason", "unknown");
htsp_send_msg(htsp, m, 0);
@ -129,12 +129,12 @@ htsp_subscription_callback(struct th_subscription *s,
*
*/
void
htsp_muxer_subscribe(htsp_t *htsp, channel_t *ch, int weight, uint32_t tag)
htsp_muxer_subscribe(htsp_t *htsp, channel_t *ch, int weight)
{
th_subscription_t *s;
s = subscription_create(ch, weight, "HTSP", htsp_subscription_callback, htsp,
tag);
0);
LIST_INSERT_HEAD(&htsp->htsp_subscriptions, s, ths_subscriber_link);
}
@ -159,7 +159,7 @@ htsp_muxer_unsubscribe(htsp_t *htsp, uint32_t id)
th_subscription_t *s;
LIST_FOREACH(s, &htsp->htsp_subscriptions, ths_subscriber_link) {
if(s->ths_u32 == id)
if(s->ths_channel->ch_tag == id)
break;
}

View file

@ -19,8 +19,7 @@
#ifndef HTSP_MUXER_H_
#define HTSP_MUXER_H_
void htsp_muxer_subscribe(htsp_t *htsp, channel_t *ch,
int weight, uint32_t tag);
void htsp_muxer_subscribe(htsp_t *htsp, channel_t *ch, int weight);
void htsp_muxer_unsubscribe(htsp_t *htsp, uint32_t id);