From f85a8fc4aa711d5608c2ef78e23f6594185457ad Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 16 Apr 2014 22:33:02 +0200 Subject: [PATCH] SAT>IP: Add the possibility to override tuner type (DVB-T <-> DVB-C) --- src/idnode.c | 1 + src/input/mpegts/satip/satip.c | 25 +++++++- src/input/mpegts/satip/satip_frontend.c | 83 +++++++++++++++++++++++-- src/input/mpegts/satip/satip_private.h | 13 ++-- 4 files changed, 109 insertions(+), 13 deletions(-) diff --git a/src/idnode.c b/src/idnode.c index f068dba9..13ba418c 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -587,6 +587,7 @@ idnode_filter_clear else free(ele->u.s); } + free(ele->key); free(ele); } } diff --git a/src/input/mpegts/satip/satip.c b/src/input/mpegts/satip/satip.c index fd4b1dd5..0e3f3272 100644 --- a/src/input/mpegts/satip/satip.c +++ b/src/input/mpegts/satip/satip.c @@ -28,6 +28,8 @@ #include #include +static void satip_device_discovery_start( void ); + /* * SAT-IP client */ @@ -404,6 +406,8 @@ satip_device_destroy( satip_device_t *sd ) lock_assert(&global_lock); + gtimer_disarm(&sd->sd_destroy_timer); + while ((lfe = TAILQ_FIRST(&sd->sd_frontends)) != NULL) satip_frontend_delete(lfe); @@ -431,6 +435,19 @@ satip_device_destroy( satip_device_t *sd ) free(sd); } +static void +satip_device_destroy_cb( void *aux ) +{ + satip_device_destroy((satip_device_t *)aux); + satip_device_discovery_start(); +} + +void +satip_device_destroy_later( satip_device_t *sd, int after ) +{ + gtimer_arm_ms(&sd->sd_destroy_timer, satip_device_destroy_cb, sd, after); +} + /* * Discovery job */ @@ -795,6 +812,12 @@ ST: urn:ses-com:device:SatIPServer:1\r\n\ #undef MSG } +static void +satip_device_discovery_start( void ) +{ + gtimer_arm(&satip_discovery_timer, satip_discovery_timer_cb, NULL, 1); +} + /* * Initialization */ @@ -802,7 +825,7 @@ ST: urn:ses-com:device:SatIPServer:1\r\n\ void satip_init ( void ) { TAILQ_INIT(&satip_discoveries); - gtimer_arm(&satip_discovery_timer, satip_discovery_timer_cb, NULL, 1); + satip_device_discovery_start(); } void satip_done ( void ) diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index aa4dc3fd..80ebee2e 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -92,6 +92,39 @@ satip_frontend_class_save ( idnode_t *in ) satip_device_save(la); } +static int +satip_frontend_set_new_type + ( satip_frontend_t *lfe, const char *type ) +{ + free(lfe->sf_type_override); + lfe->sf_type_override = strdup(type); + satip_device_destroy_later(lfe->sf_device, 100); + return 1; +} + +static int +satip_frontend_class_override_set( void *obj, const void * p ) +{ + satip_frontend_t *lfe = obj; + const char *s = p; + + if (lfe->sf_type_override == NULL) { + if (strlen(p) > 0) + return satip_frontend_set_new_type(lfe, s); + } else if (strcmp(lfe->sf_type_override, s)) + return satip_frontend_set_new_type(lfe, s); + return 0; +} + +static htsmsg_t * +satip_frontend_class_override_enum( void * p ) +{ + htsmsg_t *m = htsmsg_create_list(); + htsmsg_add_str(m, NULL, "DVB-T"); + htsmsg_add_str(m, NULL, "DVB-C"); + return m; +} + const idclass_t satip_frontend_class = { .ic_super = &mpegts_input_class, @@ -128,6 +161,14 @@ const idclass_t satip_frontend_dvbt_class = .ic_class = "satip_frontend_dvbt", .ic_caption = "SAT>IP DVB-T Frontend", .ic_properties = (const property_t[]){ + { + .type = PT_STR, + .id = "fe_override", + .name = "Network Type", + .set = satip_frontend_class_override_set, + .list = satip_frontend_class_override_enum, + .off = offsetof(satip_frontend_t, sf_type_override), + }, {} } }; @@ -189,6 +230,14 @@ const idclass_t satip_frontend_dvbc_class = .ic_class = "satip_frontend_dvbc", .ic_caption = "SAT>IP DVB-C Frontend", .ic_properties = (const property_t[]){ + { + .type = PT_STR, + .id = "fe_override", + .name = "Network Type", + .set = satip_frontend_class_override_set, + .list = satip_frontend_class_override_enum, + .off = offsetof(satip_frontend_t, sf_type_override), + }, {} } }; @@ -1087,10 +1136,23 @@ satip_frontend_create ( htsmsg_t *conf, satip_device_t *sd, dvb_fe_type_t type, int t2, int num ) { const idclass_t *idc; - const char *uuid = NULL; + const char *uuid = NULL, *override = NULL; char id[12], lname[256]; satip_frontend_t *lfe; + int i; + /* Override type */ + snprintf(id, sizeof(id), "override #%d", num); + if (conf && type != DVB_TYPE_S) { + override = htsmsg_get_str(conf, id); + if (override) { + i = dvb_str2type(override); + if ((i == DVB_TYPE_T || i == DVB_TYPE_C || DVB_TYPE_S) && i != type) + type = i; + else + override = NULL; + } + } /* Internal config ID */ snprintf(id, sizeof(id), "%s #%d", dvb_type2str(type), num); if (conf) @@ -1114,9 +1176,11 @@ satip_frontend_create // correct "fe_type" we cannot set the network (which is done // in mpegts_input_create()). So we must set early. lfe = calloc(1, sizeof(satip_frontend_t)); + lfe->sf_device = sd; lfe->sf_number = num; lfe->sf_type = type; lfe->sf_type_t2 = t2; + lfe->sf_type_override = override ? strdup(override) : NULL; TAILQ_INIT(&lfe->sf_satconf); pthread_mutex_init(&lfe->sf_dvr_lock, NULL); lfe = (satip_frontend_t*)mpegts_input_create0((mpegts_input_t*)lfe, idc, uuid, conf); @@ -1132,9 +1196,13 @@ satip_frontend_create lfe->mi_get_grace = satip_frontend_get_grace; /* Default name */ - if (!lfe->mi_name) { - snprintf(lname, sizeof(lname), "SAT>IP %s Tuner %s #%i", - dvb_type2str(type), sd->sd_info.addr, num); + if (!lfe->mi_name || + (strncmp(lfe->mi_name, "SAT>IP ", 7) == 0 && + strstr(lfe->mi_name, " Tuner ") && + strstr(lfe->mi_name, " #"))) { + snprintf(lname, sizeof(lname), "SAT>IP %s Tuner #%i (%s)", + dvb_type2str(type), num, sd->sd_info.addr); + free(lfe->mi_name); lfe->mi_name = strdup(lname); } @@ -1169,10 +1237,15 @@ satip_frontend_save ( satip_frontend_t *lfe, htsmsg_t *fe ) satip_satconf_save(lfe, m); if (lfe->ti_id.in_class == &satip_frontend_dvbs_class) htsmsg_delete_field(m, "networks"); + htsmsg_delete_field(m, "fe_override"); /* Add to list */ snprintf(id, sizeof(id), "%s #%d", dvb_type2str(lfe->sf_type), lfe->sf_number); htsmsg_add_msg(fe, id, m); + if (lfe->sf_type_override) { + snprintf(id, sizeof(id), "override #%d", lfe->sf_number); + htsmsg_add_str(fe, id, lfe->sf_type_override); + } } void @@ -1194,6 +1267,8 @@ satip_frontend_delete ( satip_frontend_t *lfe ) /* Delete satconf */ satip_satconf_destroy(lfe); + free(lfe->sf_type_override); + /* Finish */ mpegts_input_delete((mpegts_input_t*)lfe, 0); } diff --git a/src/input/mpegts/satip/satip_private.h b/src/input/mpegts/satip/satip_private.h index 7b096b52..5e35f985 100644 --- a/src/input/mpegts/satip/satip_private.h +++ b/src/input/mpegts/satip/satip_private.h @@ -58,6 +58,8 @@ struct satip_device { tvh_hardware_t; + gtimer_t sd_destroy_timer; + /* * Adapter info */ @@ -76,14 +78,6 @@ struct satip_device int sd_pids_len; int sd_pids_deladd; int sd_sig_scale; - - int sd_rtsp_running; - pthread_t sd_rtsp_tid; - pthread_mutex_t sd_rtsp_lock; - pthread_cond_t sd_rtsp_cond; - TAILQ_HEAD(,satip_rtsp_request) sd_rtsp_queue; - time_t sd_rtsp_ping; - gtimer_t sd_rtsp_shutdown; }; struct satip_frontend @@ -102,6 +96,7 @@ struct satip_frontend int sf_number; dvb_fe_type_t sf_type; int sf_type_t2; + char *sf_type_override; int sf_udp_rtp_port; int sf_fullmux; @@ -171,6 +166,8 @@ void satip_device_save ( satip_device_t *sd ); void satip_device_destroy ( satip_device_t *sd ); +void satip_device_destroy_later( satip_device_t *sd, int after_ms ); + satip_frontend_t * satip_frontend_create ( htsmsg_t *conf, satip_device_t *sd, dvb_fe_type_t type, int t2, int num );