]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
profile: load pre-defined streaming profiles and codecs from config tree
authorJaroslav Kysela <perex@perex.cz>
Mon, 28 Aug 2017 18:43:39 +0000 (20:43 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 29 Aug 2017 06:42:38 +0000 (08:42 +0200)
data/conf/profiles [new file with mode: 0644]
data/conf/transcoder/codecs [new file with mode: 0644]
data/conf/transcoder/profiles [new file with mode: 0644]
src/profile.c
src/transcoding/codec/profile.c

diff --git a/data/conf/profiles b/data/conf/profiles
new file mode 100644 (file)
index 0000000..f57fd13
--- /dev/null
@@ -0,0 +1,18 @@
+[
+    {
+       "comment": "MPEG-TS Pass-thru",
+       "class": "profile-mpegts",
+       "name": "pass",
+       "default": 1
+    },
+    {,
+       "comment": "Matroska",
+       "class": "profile-matroska",
+       "name": "matroska"
+    },
+    {,
+       "comment": "HTSP Default Stream Settings",
+       "class": "profile-htsp",
+       "name": "htsp"
+    }
+]
diff --git a/data/conf/transcoder/codecs b/data/conf/transcoder/codecs
new file mode 100644 (file)
index 0000000..5ed0770
--- /dev/null
@@ -0,0 +1,24 @@
+[
+    {
+       "description": "WEBTV codec VP8",
+       "name": "webtv-vp8",
+       "codec_name": "libvpx",
+       "height": 384
+    },
+    {
+       "description": "WEBTV codec H264",
+       "name": "webtv-h264",
+       "codec_name": "libx264",
+       "height": 384
+    },
+    {
+       "description": "WEBTV codec Vorbis",
+       "name": "webtv-vorbis",
+       "codec_name": "vorbis"
+    },
+    {
+       "description": "WEBTV codec AAC",
+       "name": "webtv-aac",
+       "codec_name": "aac"
+    }
+]
diff --git a/data/conf/transcoder/profiles b/data/conf/transcoder/profiles
new file mode 100644 (file)
index 0000000..9e56dd4
--- /dev/null
@@ -0,0 +1,30 @@
+[
+    {
+       "comment": "WEBTV profile VP8/Vorbis/WEBM",
+       "name": "webtv-vp8-vorbis-webm",
+       "pro_vcodec": "webtv-vp8",
+       "pro_acodec": "webtv-vorbis",
+       "container": 6
+    },
+    {
+       "comment": "WEBTV profile H264/AAC/MPEG-TS",
+       "name": "webtv-h264-aac-mpegts",
+       "pro_vcodec": "webtv-h264",
+       "pro_acodec": "webtv-aac",
+       "container": 2
+    },
+    {
+       "comment": "WEBTV profile H264/AAC/Matroska",
+       "name": "webtv-h264-aac-matroska",
+       "pro_vcodec": "webtv-h264",
+       "pro_acodec": "webtv-aac",
+       "container": 1
+    },
+    {
+       "comment": "WEBTV profile H264/Vorbis/MP4",
+       "name": "webtv-h264-vorbis-mp4",
+       "pro_vcodec": "webtv-h264",
+       "pro_acodec": "webtv-vorbis",
+       "container": 9
+    }
+]
index 97f764d39560c6dc3486a9ecb7236a0c91bc07c0..e06aee1100dda0ee7366018a26f36212f043c044 100644 (file)
@@ -2456,123 +2456,53 @@ profile_init(void)
     htsmsg_destroy(c);
   }
 
-  name = "pass";
-  pro = profile_find_by_name2(name, NULL, 1);
-  if (pro == NULL || strcmp(profile_get_name(pro), name)) {
-    htsmsg_t *conf;
-
-    conf = htsmsg_create_map();
-    htsmsg_add_str (conf, "class", "profile-mpegts");
-    htsmsg_add_bool(conf, "enabled", 1);
-    htsmsg_add_bool(conf, "default", 1);
-    htsmsg_add_str (conf, "name", name);
-    htsmsg_add_str (conf, "comment", _("MPEG-TS Pass-thru"));
-    htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_NORMAL);
-    htsmsg_add_bool(conf, "rewrite_pmt", 1);
-    htsmsg_add_bool(conf, "rewrite_pat", 1);
-    htsmsg_add_bool(conf, "rewrite_sdt", 1);
-    htsmsg_add_bool(conf, "rewrite_eit", 1);
-    htsmsg_add_bool(conf, "shield", 1);
-    (void)profile_create(NULL, conf, 1);
-    htsmsg_destroy(conf);
-  }
-
-  name = "matroska";
-  pro = profile_find_by_name2(name, NULL, 1);
-  if (pro == NULL || strcmp(profile_get_name(pro), name)) {
-    htsmsg_t *conf;
-
-    conf = htsmsg_create_map();
-    htsmsg_add_str (conf, "class", "profile-matroska");
-    htsmsg_add_bool(conf, "enabled", 1);
-    htsmsg_add_str (conf, "name", name);
-    htsmsg_add_str (conf, "comment", _("Matroska"));
-    htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_NORMAL);
-    htsmsg_add_bool(conf, "shield", 1);
-    (void)profile_create(NULL, conf, 1);
-    htsmsg_destroy(conf);
-  }
-
-  name = "htsp";
-  pro = profile_find_by_name2(name, NULL, 1);
-  if (pro == NULL || strcmp(profile_get_name(pro), name)) {
-    htsmsg_t *conf;
-
-    conf = htsmsg_create_map();
-    htsmsg_add_str (conf, "class", "profile-htsp");
-    htsmsg_add_bool(conf, "enabled", 1);
-    htsmsg_add_str (conf, "name", name);
-    htsmsg_add_str (conf, "comment", _("HTSP Default Stream Settings"));
-    htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_IMPORTANT);
-    htsmsg_add_bool(conf, "shield", 1);
-    (void)profile_create(NULL, conf, 1);
-    htsmsg_destroy(conf);
+  if ((c = hts_settings_load("profiles")) != NULL) {
+    HTSMSG_FOREACH(f, c) {
+      if (!(e = htsmsg_field_get_map(f)))
+        continue;
+      if ((name = htsmsg_get_str(e, "name")) == NULL)
+        continue;
+      pro = profile_find_by_name2(name, NULL, 1);
+      if (pro == NULL || strcmp(profile_get_name(pro), name)) {
+        if (!htsmsg_field_find(e, "enabled"))
+          htsmsg_add_bool(e, "enabled", 1);
+        if (!htsmsg_field_find(e, "priority"))
+          htsmsg_add_s32(e, "priority", PROFILE_SPRIO_NORMAL);
+        if (!htsmsg_field_find(e, "shield"))
+          htsmsg_add_bool(e, "shield", 1);
+        (void)profile_create(NULL, e, 1);
+      }
+    }
+    htsmsg_destroy(c);
   }
 
-//#if ENABLE_LIBAV
-#if 0
-  name = "webtv-vp8-vorbis-webm";
-  pro = profile_find_by_name2(name, NULL, 1);
-  if (pro == NULL || strcmp(profile_get_name(pro), name)) {
-    htsmsg_t *conf;
-
-    conf = htsmsg_create_map();
-    htsmsg_add_str (conf, "class", "profile-transcode");
-    htsmsg_add_bool(conf, "enabled", 1);
-    htsmsg_add_str (conf, "name", name);
-    htsmsg_add_str (conf, "comment", _("WEBTV profile VP8/Vorbis/WEBM"));
-    htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_NORMAL);
-    htsmsg_add_s32 (conf, "container", MC_WEBM);
-    htsmsg_add_u32 (conf, "resolution", 384);
-    htsmsg_add_u32 (conf, "channels", 2);
-    htsmsg_add_str (conf, "vcodec", "libvpx");
-    htsmsg_add_str (conf, "vcodec_preset", "faster");
-    htsmsg_add_str (conf, "acodec", "libvorbis");
-    htsmsg_add_bool(conf, "shield", 1);
-    (void)profile_create(NULL, conf, 1);
-    htsmsg_destroy(conf);
-  }
-  name = "webtv-h264-aac-mpegts";
-  pro = profile_find_by_name2(name, NULL, 1);
-  if (pro == NULL || strcmp(profile_get_name(pro), name)) {
-    htsmsg_t *conf;
-
-    conf = htsmsg_create_map();
-    htsmsg_add_str (conf, "class", "profile-transcode");
-    htsmsg_add_bool(conf, "enabled", 1);
-    htsmsg_add_str (conf, "name", name);
-    htsmsg_add_str (conf, "comment", _("WEBTV profile H264/AAC/MPEG-TS"));
-    htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_NORMAL);
-    htsmsg_add_s32 (conf, "container", MC_MPEGTS);
-    htsmsg_add_u32 (conf, "resolution", 384);
-    htsmsg_add_u32 (conf, "channels", 2);
-    htsmsg_add_str (conf, "vcodec", "libx264");
-    htsmsg_add_str (conf, "vcodec_preset", "faster");
-    htsmsg_add_str (conf, "acodec", "aac");
-    htsmsg_add_bool(conf, "shield", 1);
-    (void)profile_create(NULL, conf, 1);
-    htsmsg_destroy(conf);
-  }
-  name = "webtv-h264-aac-matroska";
-  pro = profile_find_by_name2(name, NULL, 1);
-  if (pro == NULL || strcmp(profile_get_name(pro), name)) {
-    htsmsg_t *conf;
-
-    conf = htsmsg_create_map();
-    htsmsg_add_str (conf, "class", "profile-transcode");
-    htsmsg_add_bool(conf, "enabled", 1);
-    htsmsg_add_str (conf, "name", name);
-    htsmsg_add_str (conf, "comment", _("WEBTV profile H264/AAC/Matroska"));
-    htsmsg_add_s32 (conf, "priority", PROFILE_SPRIO_NORMAL);
-    htsmsg_add_s32 (conf, "container", MC_MATROSKA);
-    htsmsg_add_u32 (conf, "resolution", 384);
-    htsmsg_add_u32 (conf, "channels", 2);
-    htsmsg_add_str (conf, "vcodec", "libx264");
-    htsmsg_add_str (conf, "vcodec_preset", "faster");
-    htsmsg_add_str (conf, "acodec", "aac");
-    htsmsg_add_bool(conf, "shield", 1);
-    (void)profile_create(NULL, conf, 1);
-    htsmsg_destroy(conf);
+#if ENABLE_LIBAV
+  if ((c = hts_settings_load("transcoder/profiles")) != NULL) {
+    HTSMSG_FOREACH(f, c) {
+      if (!(e = htsmsg_field_get_map(f)))
+        continue;
+      if ((name = htsmsg_get_str(e, "name")) == NULL)
+        continue;
+      pro = profile_find_by_name2(name, NULL, 1);
+      if (pro == NULL || strcmp(profile_get_name(pro), name)) {
+transcoder_create:
+        htsmsg_add_str(e, "class", "profile-transcode");
+        if (!htsmsg_field_find(e, "enabled"))
+          htsmsg_add_bool(e, "enabled", 1);
+        if (!htsmsg_field_find(e, "priority"))
+          htsmsg_add_s32(e, "priority", PROFILE_SPRIO_NORMAL);
+        if (!htsmsg_field_find(e, "shield"))
+          htsmsg_add_bool(e, "shield", 1);
+        (void)profile_create(NULL, e, 1);
+      } else if (pro && idnode_is_instance(&pro->pro_id, &profile_transcode_class)) {
+        profile_transcode_t *prot = (profile_transcode_t *)pro;
+        if (prot->pro_vcodec == NULL || prot->pro_vcodec[0] == '\0') {
+          profile_delete(pro, 1);
+          goto transcoder_create;
+        }
+      }
+    }
+    htsmsg_destroy(c);
   }
 #endif
 
index 26047595cde5c2b9d1549a722e1cf4fd0a2af80a..da277c1f4c978be78ffcb15da8112447ea41cdf7 100644 (file)
@@ -65,6 +65,25 @@ tvh_codec_profile_load(htsmsg_field_t *config)
 }
 
 
+static void
+tvh_codec_profile_create2(htsmsg_field_t *config)
+{
+    htsmsg_t *conf = NULL;
+    const char *name = NULL;
+
+    if ((conf = htsmsg_field_get_map(config)) != NULL) {
+        name = htsmsg_get_str(conf, "name");
+        if (name == NULL)
+            return;
+        if (tvh_codec_profile_find(name))
+            return;
+        if (tvh_codec_profile_create(conf, NULL, 0))
+          tvherror(LS_CODEC, "unable to create codec profile from config tree: '%s'",
+                   (name = htsmsg_get_str(conf, "name")) ? name : "<unknown>");
+    }
+}
+
+
 static int
 tvh_codec_profile_setup(TVHCodecProfile *self, tvh_ssc_t *ssc)
 {
@@ -323,7 +342,12 @@ tvh_codec_profiles_load()
             tvh_codec_profile_load(config);
         }
         htsmsg_destroy(settings);
-        settings = NULL;
+    }
+    if ((settings = hts_settings_load("transcoder/codecs"))) {
+        HTSMSG_FOREACH(config, settings) {
+            tvh_codec_profile_create2(config);
+        }
+        htsmsg_destroy(settings);
     }
 }