]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
more wizard tuner / network creation work
authorJaroslav Kysela <perex@perex.cz>
Mon, 18 Jan 2016 16:37:28 +0000 (17:37 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 19 Jan 2016 14:14:15 +0000 (15:14 +0100)
src/input.h
src/input/mpegts.h
src/input/mpegts/iptv/iptv.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/mpegts_network.c
src/input/mpegts/satip/satip_frontend.c
src/input/mpegts/satip/satip_private.h
src/input/mpegts/satip/satip_satconf.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c
src/wizard.c

index 0decc89cbc3bf8ebf217379e7419a6afc94bca58..6718f779330d5938fdaec3e15c7e0000a73fe2ef 100644 (file)
@@ -90,7 +90,7 @@ struct tvh_input {
   void (*ti_get_streams) (tvh_input_t *, tvh_input_stream_list_t*);
   void (*ti_clear_stats) (tvh_input_t *);
   struct htsmsg *(*ti_wizard_get) (tvh_input_t *, const char *);
-  void (*ti_wizard_set)  (tvh_input_t *, struct htsmsg *);
+  void (*ti_wizard_set)  (tvh_input_t *, struct htsmsg *, const char *);
 };
 
 /*
index fbe1668e0a50a4c1ed12bc08a906aa7271a72869..07e38ddd8ee178a815b581c1119576269f34568e 100644 (file)
@@ -803,6 +803,8 @@ void mpegts_network_register_builder
 void mpegts_network_unregister_builder
   ( const idclass_t *idc );
 
+mpegts_network_builder_t *mpegts_network_builder_find ( const char *clazz );
+
 mpegts_network_t *mpegts_network_build
   ( const char *clazz, htsmsg_t *conf );
                  
@@ -830,6 +832,10 @@ int mpegts_network_set_network_name ( mpegts_network_t *mn, const char *name );
 void mpegts_network_scan ( mpegts_network_t *mn );
 void mpegts_network_get_type_str( mpegts_network_t *mn, char *buf, size_t buflen );
 
+htsmsg_t * mpegts_network_wizard_get ( mpegts_input_t *mi, const idclass_t *idc,
+                                       mpegts_network_t *mn, const char *lang );
+void mpegts_network_wizard_create ( const char *clazz, htsmsg_t **nlist, const char *lang );
+
 mpegts_mux_t *mpegts_mux_create0
   ( mpegts_mux_t *mm, const idclass_t *class, const char *uuid,
     mpegts_network_t *mn, uint16_t onid, uint16_t tsid,
index 66fe4a593ce08dd123b7768553925feef0b4c95d..05882a8923034536857ed8607426e2a2a2f78b4c 100644 (file)
@@ -1001,6 +1001,37 @@ iptv_network_init ( void )
   htsmsg_destroy(c);
 }
 
+static mpegts_network_t *
+iptv_input_wizard_network ( iptv_input_t *lfe )
+{
+  return (mpegts_network_t *)LIST_FIRST(&lfe->mi_networks);
+}
+
+static htsmsg_t *
+iptv_input_wizard_get( tvh_input_t *ti, const char *lang )
+{
+  iptv_input_t *mi = (iptv_input_t*)ti;
+  mpegts_network_t *mn;
+  const idclass_t *idc;
+
+  mn = iptv_input_wizard_network(mi);
+  if (mn == NULL || (mn && mn->mn_wizard))
+    idc = &iptv_auto_network_class;
+  return mpegts_network_wizard_get((mpegts_input_t *)mi, idc, mn, lang);
+}
+
+static void
+iptv_input_wizard_set( tvh_input_t *ti, htsmsg_t *conf, const char *lang )
+{
+  iptv_input_t *mi = (iptv_input_t*)ti;
+  const char *ntype = htsmsg_get_str(conf, "mpegts_network_type");
+  mpegts_network_t *mn;
+
+  mn = iptv_input_wizard_network(mi);
+  if ((mn == NULL || mn->mn_wizard))
+    mpegts_network_wizard_create(ntype, NULL, lang);
+}
+
 void iptv_init ( void )
 {
   /* Register handlers */
@@ -1015,6 +1046,8 @@ void iptv_init ( void )
   /* Init Input */
   mpegts_input_create0((mpegts_input_t*)iptv_input,
                        &iptv_input_class, NULL, NULL);
+  iptv_input->ti_wizard_get     = iptv_input_wizard_get;
+  iptv_input->ti_wizard_set     = iptv_input_wizard_set;
   iptv_input->mi_warm_mux       = iptv_input_warm_mux;
   iptv_input->mi_start_mux      = iptv_input_start_mux;
   iptv_input->mi_stop_mux       = iptv_input_stop_mux;
index 4e8f4091f880f4754e2ffe5a696a7327f3c07259..ef0f90e9beebcd56a4bc72319d6a0f49a4a3c8e7 100644 (file)
@@ -1720,6 +1720,60 @@ linuxdvb_frontend_tune1
  * Creation/Config
  * *************************************************************************/
 
+static mpegts_network_t *
+linuxdvb_frontend_wizard_network ( linuxdvb_frontend_t *lfe )
+{
+  linuxdvb_satconf_ele_t *ele = NULL;
+
+  if (lfe->lfe_satconf) {
+    ele = TAILQ_FIRST(&lfe->lfe_satconf->ls_elements);
+    if (ele && ele->lse_networks && ele->lse_networks->is_count > 0)
+      return (mpegts_network_t *)ele->lse_networks->is_array[0];
+  }
+  return (mpegts_network_t *)LIST_FIRST(&lfe->mi_networks);
+}
+
+static htsmsg_t *
+linuxdvb_frontend_wizard_get( tvh_input_t *ti, const char *lang )
+{
+  linuxdvb_frontend_t *lfe = (linuxdvb_frontend_t*)ti;
+  mpegts_network_t *mn;
+  const idclass_t *idc = NULL;
+
+  mn = linuxdvb_frontend_wizard_network(lfe);
+  if ((lfe->lfe_master == 0 && mn == NULL) || (mn && mn->mn_wizard))
+    idc = dvb_network_class_by_fe_type(lfe->lfe_type);
+  return mpegts_network_wizard_get((mpegts_input_t *)lfe, idc, mn, lang);
+}
+
+static void
+linuxdvb_frontend_wizard_set( tvh_input_t *ti, htsmsg_t *conf, const char *lang )
+{
+  linuxdvb_frontend_t *lfe = (linuxdvb_frontend_t*)ti;
+  const char *ntype = htsmsg_get_str(conf, "mpegts_network_type");
+  mpegts_network_t *mn;
+
+  mn = linuxdvb_frontend_wizard_network(lfe);
+  if (ntype && (mn == NULL || mn->mn_wizard)) {
+    htsmsg_t *nlist;
+    mpegts_network_wizard_create(ntype, &nlist, lang);
+    if (lfe->lfe_satconf) {
+      htsmsg_t *conf = htsmsg_create_map();
+      htsmsg_add_msg(conf, "networks", nlist);
+      linuxdvb_satconf_create(lfe, NULL, NULL, conf);
+      mn = linuxdvb_frontend_wizard_network(lfe);
+      htsmsg_destroy(conf);
+    } else {
+      mpegts_input_set_networks((mpegts_input_t *)lfe, nlist);
+      htsmsg_destroy(nlist);
+    }
+    if (mn) {
+      mn->mn_wizard = 1;
+      mn->mn_config_save(mn);
+    }
+  }
+}
+
 linuxdvb_frontend_t *
 linuxdvb_frontend_create
   ( htsmsg_t *conf, linuxdvb_adapter_t *la, int number,
@@ -1815,6 +1869,8 @@ linuxdvb_frontend_create
   lfe->lfe_dvr_path = strdup(dvr_path);
 
   /* Input callbacks */
+  lfe->ti_wizard_get      = linuxdvb_frontend_wizard_get;
+  lfe->ti_wizard_set      = linuxdvb_frontend_wizard_set;
   lfe->mi_is_enabled      = linuxdvb_frontend_is_enabled;
   lfe->mi_start_mux       = linuxdvb_frontend_start_mux;
   lfe->mi_stop_mux        = linuxdvb_frontend_stop_mux;
index 35b8475b96ed1635f8d0e256d692cdaedcc70d10..6d22087e262ee980bdc412d4586245fc3ca6ab53 100644 (file)
@@ -469,6 +469,59 @@ mpegts_network_get_type_str( mpegts_network_t *mn, char *buf, size_t buflen )
   snprintf(buf, buflen, "%s", s);
 }
 
+/******************************************************************************
+ * Wizard
+ *****************************************************************************/
+
+htsmsg_t *
+mpegts_network_wizard_get
+  ( mpegts_input_t *mi, const idclass_t *idc,
+    mpegts_network_t *mn, const char *lang )
+{
+  htsmsg_t *m = htsmsg_create_map(), *l, *e;
+  char ubuf[UUID_HEX_SIZE], buf[256];
+
+  if (mi && idc) {
+    mi->mi_display_name(mi, buf, sizeof(buf));
+    htsmsg_add_str(m, "input_name", buf);
+    l = htsmsg_create_list();
+    e = htsmsg_create_map();
+    htsmsg_add_str(e, "key", idc->ic_class);
+    htsmsg_add_str(e, "val", idclass_get_caption(idc, lang));
+    htsmsg_add_msg(l, NULL, e);
+    htsmsg_add_msg(m, "mpegts_network_types", l);
+    if (mn)
+      htsmsg_add_str(m, "mpegts_network", idnode_uuid_as_str(&mn->mn_id, ubuf));
+  }
+  return m;
+}
+
+void
+mpegts_network_wizard_create
+  ( const char *clazz, htsmsg_t **nlist, const char *lang )
+{
+  char buf[256];
+  mpegts_network_t *mn;
+  mpegts_network_builder_t *mnb;
+  htsmsg_t *conf;
+
+  if (nlist)
+    *nlist = NULL;
+  mnb = mpegts_network_builder_find(clazz);
+  if (mnb == NULL)
+    return;
+
+  conf = htsmsg_create_map();
+  htsmsg_add_str(conf, "networkname", idclass_get_caption(mnb->idc, lang));
+  htsmsg_add_bool(conf, "wizard", 1);
+  mn = mnb->build(mnb->idc, conf);
+  htsmsg_destroy(conf);
+  if (mn && nlist) {
+    *nlist = htsmsg_create_list();
+    htsmsg_add_str(*nlist, NULL, idnode_uuid_as_str(&mn->mn_id, buf));
+  }
+}
+
 /******************************************************************************
  * Network classes/creation
  *****************************************************************************/
@@ -500,18 +553,29 @@ mpegts_network_unregister_builder
   }
 }
 
-mpegts_network_t *
-mpegts_network_build
-  ( const char *clazz, htsmsg_t *conf )
+mpegts_network_builder_t *
+mpegts_network_builder_find
+  ( const char *clazz )
 {
   mpegts_network_builder_t *mnb;
   LIST_FOREACH(mnb, &mpegts_network_builders, link) {
     if (!strcmp(mnb->idc->ic_class, clazz))
-      return mnb->build(mnb->idc, conf);
+      return mnb;
   }
   return NULL;
 }
 
+mpegts_network_t *
+mpegts_network_build
+  ( const char *clazz, htsmsg_t *conf )
+{
+  mpegts_network_builder_t *mnb;
+  mnb = mpegts_network_builder_find(clazz);
+  if (mnb)
+    return mnb->build(mnb->idc, conf);
+  return NULL;
+}
+
 /******************************************************************************
  * Search
  *****************************************************************************/
index a725825d86c6268194b079aba25a27eb393fe878..fd7b86eb1fa203eb434091b0160c7320dcb1a668 100644 (file)
@@ -1762,52 +1762,44 @@ satip_frontend_default_positions ( satip_frontend_t *lfe )
   return sd->sd_info.srcs;
 }
 
+static mpegts_network_t *
+satip_frontend_wizard_network ( satip_frontend_t *lfe )
+{
+  satip_satconf_t *sfc;
+
+  sfc = TAILQ_FIRST(&lfe->sf_satconf);
+  if (sfc && sfc->sfc_networks)
+    if (sfc->sfc_networks->is_count > 0)
+      return (mpegts_network_t *)sfc->sfc_networks->is_array[0];
+  return NULL;
+}
+
 static htsmsg_t *
 satip_frontend_wizard_get( tvh_input_t *ti, const char *lang )
 {
   satip_frontend_t *lfe = (satip_frontend_t*)ti;
-  htsmsg_t *m = htsmsg_create_map(), *l, *e;
-  satip_satconf_t *sfc;
-  const idclass_t *idc;
-  char ubuf[UUID_HEX_SIZE], buf[256];
+  mpegts_network_t *mn;
+  const idclass_t *idc = NULL;
 
-  sfc = TAILQ_FIRST(&lfe->sf_satconf);
-  if (sfc == NULL || (sfc && sfc->sfc_wizard)) {
-    lfe->mi_display_name((mpegts_input_t*)lfe, buf, sizeof(buf));
-    htsmsg_add_str(m, "input_name", buf);
+  mn = satip_frontend_wizard_network(lfe);
+  if (lfe->sf_master == 0 && (mn == NULL || (mn && mn->mn_wizard)))
     idc = dvb_network_class_by_fe_type(lfe->sf_type);
-    if (idc) {
-      l = htsmsg_create_list();
-      e = htsmsg_create_map();
-      htsmsg_add_str(e, "key", idc->ic_class);
-      htsmsg_add_str(e, "val", idclass_get_caption(idc, lang));
-      htsmsg_add_msg(l, NULL, e);
-      htsmsg_add_msg(m, "mpegts_network_types", l);
-    }
-    if (sfc && sfc->sfc_wizard) {
-      lfe->mi_display_name((mpegts_input_t*)lfe, buf, sizeof(buf));
-      htsmsg_add_str(m, "input_name", buf);
-      htsmsg_add_str(m, "mpegts_network",
-                     idnode_uuid_as_str(sfc->sfc_networks->is_array[0], ubuf));
-    }
-  }
-  return m;
+  return mpegts_network_wizard_get((mpegts_input_t *)lfe, idc, mn, lang);
 }
 
 static void
-satip_frontend_wizard_set( tvh_input_t *ti, htsmsg_t *conf )
+satip_frontend_wizard_set( tvh_input_t *ti, htsmsg_t *conf, const char *lang )
 {
   satip_frontend_t *lfe = (satip_frontend_t*)ti;
-  const char *uuid = htsmsg_get_str(conf, "mpegts_network_type");
-  satip_satconf_t *sfc;
+  const char *ntype = htsmsg_get_str(conf, "mpegts_network_type");
+  mpegts_network_t *mn;
 
-  sfc = TAILQ_FIRST(&lfe->sf_satconf);
-  if (uuid && (sfc == NULL || sfc->sfc_wizard)) {
+  mn = satip_frontend_wizard_network(lfe);
+  if (ntype && lfe->sf_master == 0 && (mn == NULL || mn->mn_wizard)) {
     htsmsg_t *conf = htsmsg_create_map();
-    htsmsg_t *nlist = htsmsg_create_list();
-    htsmsg_add_str(nlist, NULL, uuid);
+    htsmsg_t *nlist;
+    mpegts_network_wizard_create(ntype, &nlist, lang);
     htsmsg_add_msg(conf, "networks", nlist);
-    htsmsg_add_bool(conf, "wizard", 1);
     satip_satconf_create(lfe, conf, satip_frontend_default_positions(lfe));
     htsmsg_destroy(conf);
   }
index e0a349479c79db06d83500d2548f0db03a8815ee..21fd4a4404364877337284abaa9b649ae7a83d95 100644 (file)
@@ -177,7 +177,6 @@ struct satip_satconf
   /*
    * Config
    */
-  int                        sfc_wizard;
   int                        sfc_enabled;
   int                        sfc_position;
   int                        sfc_priority;
index e60f7e102631f2a7b85e0ce6bf231e185ed64420..35254c09ec2b9b52fabe6f6935cd995747683358 100644 (file)
@@ -183,13 +183,6 @@ const idclass_t satip_satconf_class =
   .ic_get_title  = satip_satconf_class_get_title,
   .ic_save       = satip_satconf_class_save,
   .ic_properties = (const property_t[]) {
-    {
-      .type     = PT_BOOL,
-      .id       = "wizard",
-      .name     = N_("Wizard"),
-      .off      = offsetof(satip_satconf_t, sfc_wizard),
-      .opts     = PO_NOUI,
-    },
     {
       .type     = PT_BOOL,
       .id       = "enabled",
index f3aff35c05908ffb3d3bb3da88ca0a3b7abf934b..3b5d10755ee1eff32b0a2f90dc027f66cf24fa30 100644 (file)
@@ -593,6 +593,42 @@ const idclass_t tvhdhomerun_frontend_atsc_c_class =
   }
 };
 
+static mpegts_network_t *
+tvhdhomerun_frontend_wizard_network ( tvhdhomerun_frontend_t *hfe )
+{
+  return (mpegts_network_t *)LIST_FIRST(&hfe->mi_networks);
+}
+
+static htsmsg_t *
+tvhdhomerun_frontend_wizard_get( tvh_input_t *ti, const char *lang )
+{
+  tvhdhomerun_frontend_t *hfe = (tvhdhomerun_frontend_t*)ti;
+  mpegts_network_t *mn;
+  const idclass_t *idc = NULL;
+
+  mn = tvhdhomerun_frontend_wizard_network(hfe);
+  if (mn == NULL || (mn && mn->mn_wizard))
+    idc = dvb_network_class_by_fe_type(hfe->hf_type);
+  return mpegts_network_wizard_get((mpegts_input_t *)hfe, idc, mn, lang);
+}
+
+static void
+tvhdhomerun_frontend_wizard_set( tvh_input_t *ti, htsmsg_t *conf, const char *lang )
+{
+  tvhdhomerun_frontend_t *hfe = (tvhdhomerun_frontend_t*)ti;
+  const char *ntype = htsmsg_get_str(conf, "mpegts_network_type");
+  mpegts_network_t *mn;
+
+  mn = tvhdhomerun_frontend_wizard_network(hfe);
+  if (ntype && (mn == NULL || mn->mn_wizard)) {
+    htsmsg_t *nlist = htsmsg_create_list();
+    mpegts_network_wizard_create(ntype, &nlist, lang);
+    htsmsg_add_str(nlist, NULL, ntype);
+    mpegts_input_set_networks((mpegts_input_t *)hfe, nlist);
+    htsmsg_destroy(nlist);
+  }
+}
+
 void
 tvhdhomerun_frontend_delete ( tvhdhomerun_frontend_t *hfe )
 {
@@ -677,6 +713,8 @@ tvhdhomerun_frontend_create(tvhdhomerun_device_t *hd, struct hdhomerun_discover_
   }
 
   /* Input callbacks */
+  hfe->ti_wizard_get     = tvhdhomerun_frontend_wizard_get;
+  hfe->ti_wizard_set     = tvhdhomerun_frontend_wizard_set;
   hfe->mi_is_enabled     = tvhdhomerun_frontend_is_enabled;
   hfe->mi_start_mux      = tvhdhomerun_frontend_start_mux;
   hfe->mi_stop_mux       = tvhdhomerun_frontend_stop_mux;
index ef693ca9df072cb93f461a86714fb58545932543..4529aced378a123972ae8f7423bab98c8c3d07a0 100644 (file)
@@ -482,6 +482,7 @@ wizard_page_t *wizard_login(const char *lang)
 #define WIZARD_NETWORKS 6
 
 typedef struct wizard_network {
+  char lang        [64];
   property_t props [WIZARD_NETWORKS * 3 + 10];
   char tuner       [WIZARD_NETWORKS][64];
   char tunerid     [WIZARD_NETWORKS][UUID_HEX_SIZE];
@@ -519,7 +520,7 @@ static void network_save(idnode_t *in)
       continue;
     m = htsmsg_create_map();
     htsmsg_add_str(m, "mpegts_network_type", w->network_type[idx]);
-    ti->ti_wizard_set(ti, m);
+    ti->ti_wizard_set(ti, m, w->lang[0] ? w->lang : NULL);
     htsmsg_destroy(m);
   }
   for (mn = LIST_FIRST(&mpegts_network_all); mn != NULL; mn = mn_next) {
@@ -646,6 +647,7 @@ wizard_page_t *wizard_network(const char *lang)
   ic->ic_properties = w->props;
   ic->ic_save = network_save;
   page->free = network_free;
+  snprintf(w->lang, sizeof(w->lang), "%s", lang ?: "");
 
   for (idx = 0; idx < ARRAY_SIZE(props); idx++)
     w->props[idx] = props[idx];