diff --git a/src/htsp.c b/src/htsp.c index 849a1a68..bcb34829 100644 --- a/src/htsp.c +++ b/src/htsp.c @@ -739,7 +739,7 @@ htsp_method_getSysTime(htsp_connection_t *htsp, htsmsg_t *in) static htsmsg_t * htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in) { - uint32_t chid, sid; + uint32_t chid, sid, weight; channel_t *ch; htsp_subscription_t *hs; @@ -752,6 +752,7 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in) if((ch = channel_find_by_identifier(chid)) == NULL) return htsp_error("Requested channel does not exist"); + weight = htsmsg_get_u32_or_default(in, "weight", 150); /* * We send the reply now to avoid the user getting the 'subscriptionStart' @@ -770,7 +771,8 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in) LIST_INSERT_HEAD(&htsp->htsp_subscriptions, hs, hs_link); streaming_target_init(&hs->hs_input, htsp_streaming_input, hs, 0); - hs->hs_s = subscription_create_from_channel(ch, 150, htsp->htsp_logname, + hs->hs_s = subscription_create_from_channel(ch, weight, + htsp->htsp_logname, &hs->hs_input, 0); return NULL; } @@ -806,6 +808,34 @@ htsp_method_unsubscribe(htsp_connection_t *htsp, htsmsg_t *in) } +/** + * Change weight for a subscription + */ +static htsmsg_t * +htsp_method_change_weight(htsp_connection_t *htsp, htsmsg_t *in) +{ + htsp_subscription_t *hs; + uint32_t sid, weight; + + if(htsmsg_get_u32(in, "subscriptionId", &sid)) + return htsp_error("Missing argument 'subscriptionId'"); + + weight = htsmsg_get_u32_or_default(in, "weight", 150); + + LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link) + if(hs->hs_sid == sid) + break; + + if(hs == NULL) + return htsp_error("Requested subscription does not exist"); + + htsp_reply(htsp, in, htsmsg_create_map()); + + subscription_change_weight(hs->hs_s, weight); + return NULL; +} + + /** * Try to authenticate */ @@ -888,6 +918,7 @@ struct { { "getSysTime", htsp_method_getSysTime, ACCESS_STREAMING}, { "subscribe", htsp_method_subscribe, ACCESS_STREAMING}, { "unsubscribe", htsp_method_unsubscribe, ACCESS_STREAMING}, + { "subscriptionChangeWeight", htsp_method_change_weight, ACCESS_STREAMING}, { "addDvrEntry", htsp_method_addDvrEntry, ACCESS_RECORDER}, { "deleteDvrEntry", htsp_method_deleteDvrEntry, ACCESS_RECORDER}, { "epgQuery", htsp_method_epgQuery, ACCESS_STREAMING}, diff --git a/src/subscriptions.c b/src/subscriptions.c index 7b0a11b7..7dabc537 100644 --- a/src/subscriptions.c +++ b/src/subscriptions.c @@ -394,6 +394,24 @@ subscription_create_from_transport(th_transport_t *t, const char *name, } +/** + * + */ +void +subscription_change_weight(th_subscription_t *s, int weight) +{ + if(s->ths_weight == weight) + return; + + LIST_REMOVE(s, ths_global_link); + + s->ths_weight = weight; + LIST_INSERT_SORTED(&subscriptions, s, ths_global_link, subscription_sort); + + subscription_reschedule(); +} + + /** * */ diff --git a/src/subscriptions.h b/src/subscriptions.h index ca7b9059..65f147a3 100644 --- a/src/subscriptions.h +++ b/src/subscriptions.h @@ -79,6 +79,8 @@ th_subscription_t *subscription_create_from_transport(th_transport_t *t, streaming_target_t *st, int flags); +void subscription_change_weight(th_subscription_t *s, int weight); + void subscription_stop(th_subscription_t *s); void subscription_unlink_transport(th_subscription_t *s, int reason);