Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
htsp: add delayed unsubscription in response to HTSP request
The reason for this is there isn't a command for "changing" channel, this may
be changed in the future. So to simulate it the subscription weight is change
to a minimum level and then a new one can be created, thus reducing the need
to stop the tuner (especially for in mux zaps).
  • Loading branch information
adamsutton committed Oct 12, 2013
1 parent 93de822 commit 2c61205
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/htsp_server.c
Expand Up @@ -160,6 +160,8 @@ typedef struct htsp_connection {

uint8_t htsp_challenge[32];

gtimer_t htsp_timer;

} htsp_connection_t;


Expand Down Expand Up @@ -201,6 +203,7 @@ streaming_target_t *hs_transcoder;
uint32_t hs_filtered_streams[16]; // one bit per stream

int hs_first;
int hs_unsubscribe;

} htsp_subscription_t;

Expand Down Expand Up @@ -1415,7 +1418,8 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
if(normts)
st = hs->hs_tsfix = tsfix_create(st);

tvhdebug("htsp", "%s - subscribe to %s\n", htsp->htsp_logname, ch->ch_name ?: "");
tvhdebug("htsp", "%s - subscribe to %s", htsp->htsp_logname,
channel_get_name(ch));
hs->hs_s = subscription_create_from_channel(ch, weight,
htsp->htsp_logname,
st, 0,
Expand All @@ -1425,6 +1429,19 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
return NULL;
}

static void
htsp_unsubscribe_timer ( void *p )
{
htsp_connection_t *htsp = p;
htsp_subscription_t *s, *n;

for (s = LIST_FIRST(&htsp->htsp_subscriptions); s != NULL; s = n) {
n = LIST_NEXT(s, hs_link);
if (s->hs_unsubscribe)
htsp_subscription_destroy(htsp, s);
}
}

/**
* Request unsubscription for a channel
*/
Expand All @@ -1450,7 +1467,10 @@ htsp_method_unsubscribe(htsp_connection_t *htsp, htsmsg_t *in)
if(s == NULL)
return NULL; /* Subscription did not exist, but we don't really care */

htsp_subscription_destroy(htsp, s);
s->hs_unsubscribe = 1;
subscription_change_weight(s->hs_s, 10); // fake unsubscribe (Note: don't set to 0 else other
// background tasks could steal the tuner)
gtimer_arm(&htsp->htsp_timer, htsp_unsubscribe_timer, htsp, 2);
return NULL;
}

Expand Down Expand Up @@ -2102,6 +2122,8 @@ htsp_serve(int fd, void *opaque, struct sockaddr_storage *source,

pthread_mutex_lock(&global_lock);

gtimer_disarm(&htsp.htsp_timer);

/* Beware! Closing subscriptions will invoke a lot of callbacks
down in the streaming code. So we do this as early as possible
to avoid any weird lockups */
Expand Down

0 comments on commit 2c61205

Please sign in to comment.