From: Jaroslav Kysela Date: Sat, 13 Jun 2015 07:46:14 +0000 (+0200) Subject: profile: improve profile selection for htsp X-Git-Tag: v4.0.7~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5e9c79a5763f46aa6b85396edcf5803a36e43be;p=thirdparty%2Ftvheadend.git profile: improve profile selection for htsp --- diff --git a/src/htsp_server.c b/src/htsp_server.c index 94ba04d9b..a0441db36 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -2020,7 +2020,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); diff --git a/src/profile.c b/src/profile.c index 317050468..4146c34d2 100644 --- a/src/profile.c +++ b/src/profile.c @@ -396,11 +396,29 @@ 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; @@ -408,16 +426,17 @@ profile_find_by_list(htsmsg_t *uuids, const char *name, const char *alt) 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; } } @@ -935,6 +954,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; @@ -1037,6 +1057,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; @@ -1120,6 +1141,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; @@ -1191,6 +1213,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; @@ -1276,6 +1299,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; @@ -1700,6 +1724,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; diff --git a/src/profile.h b/src/profile.h index d2169be4e..c2c080ce5 100644 --- a/src/profile.h +++ b/src/profile.h @@ -114,6 +114,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; @@ -168,7 +169,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); diff --git a/src/subscriptions.h b/src/subscriptions.h index 688585c3c..f6f85f788 100644 --- a/src/subscriptions.h +++ b/src/subscriptions.h @@ -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 diff --git a/src/webui/webui.c b/src/webui/webui.c index 3475e7478..a6444151d 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -788,7 +788,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) @@ -925,7 +926,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)