Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
profile: improve profile selection for htsp
  • Loading branch information
perexg committed Jun 13, 2015
1 parent d1f9d8e commit c475cd0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/htsp_server.c
Expand Up @@ -2072,7 +2072,8 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
}
#endif

pro = profile_find_by_list(htsp->htsp_granted_access->aa_profiles, profile_id, "htsp");
pro = profile_find_by_list(htsp->htsp_granted_access->aa_profiles, profile_id,
"htsp", SUBSCRIPTION_PACKET | SUBSCRIPTION_HTSP);
profile_chain_init(&hs->hs_prch, pro, ch);
if (profile_chain_work(&hs->hs_prch, &hs->hs_input, timeshiftPeriod, 0)) {
tvhlog(LOG_ERR, "htsp", "unable to create profile chain '%s'", pro->pro_name);
Expand Down
35 changes: 30 additions & 5 deletions src/profile.c
Expand Up @@ -416,28 +416,47 @@ profile_find_by_name(const char *name, const char *alt)
return profile_find_by_name2(name, alt, 0);
}

/*
*
*/
static int
profile_verify(profile_t *pro, int sflags)
{
if (!pro)
return 0;
if (!pro->pro_enabled)
return 0;
if ((sflags & SUBSCRIPTION_HTSP) != 0 && !pro->pro_work)
return 0;
sflags &= pro->pro_sflags;
sflags &= SUBSCRIPTION_PACKET|SUBSCRIPTION_MPEGTS;
return sflags ? 1 : 0;
}

/*
*
*/
profile_t *
profile_find_by_list(htsmsg_t *uuids, const char *name, const char *alt)
profile_find_by_list
(htsmsg_t *uuids, const char *name, const char *alt, int sflags)
{
profile_t *pro, *res = NULL;
htsmsg_field_t *f;
const char *uuid, *uuid2;

pro = profile_find_by_uuid(name);
if (!pro)
pro = profile_find_by_name(name, alt);
uuid = pro ? idnode_uuid_as_str(&pro->pro_id) : "";
pro = profile_find_by_name(name, alt);
pro = NULL;
if (uuids) {
uuid = pro ? idnode_uuid_as_str(&pro->pro_id) : "";
HTSMSG_FOREACH(f, uuids) {
uuid2 = htsmsg_field_get_str(f) ?: "";
if (strcmp(uuid, uuid2) == 0)
if (strcmp(uuid, uuid2) == 0 && profile_verify(pro, sflags))
return pro;
if (!res) {
res = profile_find_by_uuid(uuid2);
if (!res->pro_enabled)
if (!profile_verify(res, sflags))
res = NULL;
}
}
Expand Down Expand Up @@ -955,6 +974,7 @@ static profile_t *
profile_htsp_builder(void)
{
profile_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_PACKET;
pro->pro_work = profile_htsp_work;
pro->pro_get_mc = profile_htsp_get_mc;
return pro;
Expand Down Expand Up @@ -1057,6 +1077,7 @@ static profile_t *
profile_mpegts_pass_builder(void)
{
profile_mpegts_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_MPEGTS;
pro->pro_reopen = profile_mpegts_pass_reopen;
pro->pro_open = profile_mpegts_pass_open;
pro->pro_get_mc = profile_mpegts_pass_get_mc;
Expand Down Expand Up @@ -1140,6 +1161,7 @@ static profile_t *
profile_matroska_builder(void)
{
profile_matroska_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_PACKET;
pro->pro_reopen = profile_matroska_reopen;
pro->pro_open = profile_matroska_open;
pro->pro_get_mc = profile_matroska_get_mc;
Expand Down Expand Up @@ -1211,6 +1233,7 @@ static profile_t *
profile_libav_mpegts_builder(void)
{
profile_libav_mpegts_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_PACKET;
pro->pro_reopen = profile_libav_mpegts_reopen;
pro->pro_open = profile_libav_mpegts_open;
pro->pro_get_mc = profile_libav_mpegts_get_mc;
Expand Down Expand Up @@ -1296,6 +1319,7 @@ static profile_t *
profile_libav_matroska_builder(void)
{
profile_libav_matroska_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_PACKET;
pro->pro_reopen = profile_libav_matroska_reopen;
pro->pro_open = profile_libav_matroska_open;
pro->pro_get_mc = profile_libav_matroska_get_mc;
Expand Down Expand Up @@ -1720,6 +1744,7 @@ static profile_t *
profile_transcode_builder(void)
{
profile_transcode_t *pro = calloc(1, sizeof(*pro));
pro->pro_sflags = SUBSCRIPTION_PACKET;
pro->pro_free = profile_transcode_free;
pro->pro_work = profile_transcode_work;
pro->pro_reopen = profile_transcode_reopen;
Expand Down
4 changes: 3 additions & 1 deletion src/profile.h
Expand Up @@ -120,6 +120,7 @@ typedef struct profile {
LIST_HEAD(,dvr_config) pro_dvr_configs;
LIST_HEAD(,access_entry) pro_accesses;

int pro_sflags;
int pro_enabled;
int pro_shield;
char *pro_name;
Expand Down Expand Up @@ -175,7 +176,8 @@ int profile_chain_weight(profile_chain_t *prch, int custom);
static inline profile_t *profile_find_by_uuid(const char *uuid)
{ return (profile_t*)idnode_find(uuid, &profile_class, NULL); }
profile_t *profile_find_by_name(const char *name, const char *alt);
profile_t *profile_find_by_list(htsmsg_t *uuids, const char *name, const char *alt);
profile_t *profile_find_by_list(htsmsg_t *uuids, const char *name,
const char *alt, int sflags);

htsmsg_t * profile_class_get_list(void *o);

Expand Down
1 change: 1 addition & 0 deletions src/subscriptions.h
Expand Up @@ -39,6 +39,7 @@ extern struct th_subscription_list subscriptions;
#define SUBSCRIPTION_IDLESCAN 0x2000 ///< for mux subscriptions
#define SUBSCRIPTION_USERSCAN 0x4000 ///< for mux subscriptions
#define SUBSCRIPTION_EPG 0x8000 ///< for mux subscriptions
#define SUBSCRIPTION_HTSP 0x10000

/* Some internal priorities */
#define SUBSCRIPTION_PRIO_KEEP 1 ///< Keep input rolling
Expand Down
6 changes: 4 additions & 2 deletions src/webui/webui.c
Expand Up @@ -772,7 +772,8 @@ http_stream_service(http_connection_t *hc, service_t *service, int weight)

if(!(pro = profile_find_by_list(hc->hc_access->aa_profiles,
http_arg_get(&hc->hc_req_args, "profile"),
"service")))
"service",
SUBSCRIPTION_PACKET | SUBSCRIPTION_MPEGTS)))
return HTTP_STATUS_NOT_ALLOWED;

if((tcp_id = http_stream_preop(hc)) == NULL)
Expand Down Expand Up @@ -909,7 +910,8 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight)

if(!(pro = profile_find_by_list(hc->hc_access->aa_profiles,
http_arg_get(&hc->hc_req_args, "profile"),
"channel")))
"channel",
SUBSCRIPTION_PACKET | SUBSCRIPTION_MPEGTS)))
return HTTP_STATUS_NOT_ALLOWED;

if((tcp_id = http_stream_preop(hc)) == NULL)
Expand Down

0 comments on commit c475cd0

Please sign in to comment.