]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
profile: improve profile selection for htsp
authorJaroslav Kysela <perex@perex.cz>
Sat, 13 Jun 2015 07:46:14 +0000 (09:46 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 29 Sep 2015 06:25:57 +0000 (08:25 +0200)
src/htsp_server.c
src/profile.c
src/profile.h
src/subscriptions.h
src/webui/webui.c

index 94ba04d9ba146157348a8750637e19585f732be9..a0441db36c7599fdd4b4b1ccb3212c52c700e305 100644 (file)
@@ -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);
index 3170504684d1c5029fbea2a7e3b2f5d22aa4b352..4146c34d2493e49e3a95381c9f86cb2c9a6a66b6 100644 (file)
@@ -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;
index d2169be4ec34f3a7302348b41bdf60cd1fd0106a..c2c080ce52b1ebf96d266f9b94deb0fa609e424a 100644 (file)
@@ -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);
 
index 688585c3ce93163767c18ee8b3852b22d75f2c29..f6f85f7881c872dd5c6a6fdfa1fccc3690b7a076 100644 (file)
@@ -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
index 3475e7478aa8512a31dfb709c12919cb4c2edbeb..a6444151d6047d21a961d80ec56d41808c5f1e71 100644 (file)
@@ -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)