From: Jaroslav Kysela Date: Mon, 28 Aug 2017 18:43:39 +0000 (+0200) Subject: profile: load pre-defined streaming profiles and codecs from config tree X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=654b9605a6480d66a73ad3d076e6cb266bbd7678;p=thirdparty%2Ftvheadend.git profile: load pre-defined streaming profiles and codecs from config tree --- diff --git a/data/conf/profiles b/data/conf/profiles new file mode 100644 index 000000000..f57fd137a --- /dev/null +++ b/data/conf/profiles @@ -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 index 000000000..5ed0770c9 --- /dev/null +++ b/data/conf/transcoder/codecs @@ -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 index 000000000..9e56dd4c4 --- /dev/null +++ b/data/conf/transcoder/profiles @@ -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 + } +] diff --git a/src/profile.c b/src/profile.c index 97f764d39..e06aee110 100644 --- a/src/profile.c +++ b/src/profile.c @@ -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 diff --git a/src/transcoding/codec/profile.c b/src/transcoding/codec/profile.c index 26047595c..da277c1f4 100644 --- a/src/transcoding/codec/profile.c +++ b/src/transcoding/codec/profile.c @@ -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 : ""); + } +} + + 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); } }