From 6acd4b60a30b19cb206b8203f42b394fe9facebc Mon Sep 17 00:00:00 2001 From: Glenn-1990 Date: Tue, 3 Mar 2015 15:20:43 +0100 Subject: [PATCH] auto create mux --- data/conf/fastscan | 42 +++++++++++++ src/input/mpegts/dvb_psi.c | 2 +- src/input/mpegts/fastscan.c | 30 +++++++--- src/input/mpegts/fastscan.h | 2 +- src/input/mpegts/mpegts_network_scan.c | 83 ++++++++++++++++++++++---- 5 files changed, 136 insertions(+), 23 deletions(-) diff --git a/data/conf/fastscan b/data/conf/fastscan index 84065f04..599ce86e 100644 --- a/data/conf/fastscan +++ b/data/conf/fastscan @@ -3,84 +3,126 @@ "name": "Canal Digitaal Astra1", "position": 192, "frequency": 12515000, + "symbolrate" : 22000000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 900 }, { "name": "TV Vlaanderen Astra1", "position": 192, "frequency": 12515000, + "symbolrate" : 22000000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 910 }, { "name": "TéléSAT Astra1", "position": 192, "frequency": 12515000, + "symbolrate" : 22000000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 920 }, { "name": "Mobistar NL Astra1", "position": 192, "frequency": 12515000, + "symbolrate" : 22000000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 930 }, { "name": "Mobistar FR Astra1", "position": 192, "frequency": 12515000, + "symbolrate" : 22000000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 940 }, { "name": "AustriaSat Astra1", "position": 192, "frequency": 12515000, + "symbolrate" : 22000000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 950 }, { "name": "Canal Digitaal Astra3", "position": 235, "frequency": 12187000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs2", "pid": 900 }, { "name": "TV Vlaanderen Astra3", "position": 235, "frequency": 12187000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs2", "pid": 910 }, { "name": "TéléSAT Astra3", "position": 235, "frequency": 12187000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs2", "pid": 920 }, { "name": "Mobistar NL Astra3", "position": 235, "frequency": 12187000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs2", "pid": 930 }, { "name": "Mobistar FR Astra3", "position": 235, "frequency": 12187000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs2", "pid": 940 }, { "name": "AustriaSat Astra3", "position": 235, "frequency": 12187000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs2", "pid": 950 }, { "name": "Skylink: Czech Republic", "position": 235, "frequency": 12070000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 30 }, { "name": "Skylink: Slovak Republic", "position": 235, "frequency": 12070000, + "symbolrate" : 27500000, + "polarisation" : "H", + "delsys" : "dvbs", "pid": 31 } ] diff --git a/src/input/mpegts/dvb_psi.c b/src/input/mpegts/dvb_psi.c index f6150c4f..e8dabf7d 100644 --- a/src/input/mpegts/dvb_psi.c +++ b/src/input/mpegts/dvb_psi.c @@ -2623,7 +2623,7 @@ psi_tables_dvb ( mpegts_mux_t *mm ) dvb_mux_conf_t *mc = &((dvb_mux_t *)mm)->lm_tuning; if (mc->dmc_fe_type == DVB_TYPE_S) dvb_fastscan_each(mm, mc->u.dmc_fe_qpsk.orbital_pos, - mc->dmc_fe_freq, psi_tables_dvb_fastscan); + mc->dmc_fe_freq, mc->u.dmc_fe_qpsk.polarisation, psi_tables_dvb_fastscan); } #endif } diff --git a/src/input/mpegts/fastscan.c b/src/input/mpegts/fastscan.c index 7fd1cac6..14b3ba64 100644 --- a/src/input/mpegts/fastscan.c +++ b/src/input/mpegts/fastscan.c @@ -37,8 +37,11 @@ typedef struct dvb_fastscan { LIST_HEAD(,dvb_fastscan_item) items; - int position; - uint32_t frequency; + int position; + dvb_fe_delivery_system_t delsys; + dvb_polarisation_t polarisation; + uint32_t frequency; + uint32_t symbolRate; } dvb_fastscan_t; static RB_HEAD(,dvb_fastscan) fastscan_rb; @@ -51,13 +54,13 @@ _fs_cmp(const void *a, const void *b) if (r == 0) { r = ((dvb_fastscan_t *)a)->frequency - ((dvb_fastscan_t *)b)->frequency; if (abs(r) < 2000) - return 0; + return (((dvb_fastscan_t *)a)->polarisation - ((dvb_fastscan_t *)b)->polarisation); } return r; } void -dvb_fastscan_each(void *aux, int position, uint32_t frequency, +dvb_fastscan_each(void *aux, int position, uint32_t frequency, dvb_polarisation_t polarisation, void (*job)(void *aux, bouquet_t *bq, const char *name, int pid)) { @@ -69,13 +72,14 @@ dvb_fastscan_each(void *aux, int position, uint32_t frequency, SKEL_ALLOC(fastscan_rb_skel); fastscan_rb_skel->position = position; fastscan_rb_skel->frequency = frequency; + fastscan_rb_skel->polarisation = polarisation; fs = RB_FIND(&fastscan_rb, fastscan_rb_skel, link, _fs_cmp); if (!fs) return; LIST_FOREACH(fsi, &fs->items, ilink) { dvb_sat_position_to_str(fs->position, buf, sizeof(buf)); - snprintf(url, sizeof(url), "dvb-fastscan://dvbs,%s,%u,%d", - buf, fs->frequency, fsi->pid); + snprintf(url, sizeof(url), "dvb-fastscan://%s,%s,%u,%s,%u,%d", dvb_delsys2str(fastscan_rb_skel->delsys), + buf, fs->frequency, dvb_pol2str(fs->polarisation), fs->symbolRate, fsi->pid); bq = bouquet_find_by_source(NULL, url, 0); if (bq == NULL || !bq->bq_enabled) continue; @@ -90,7 +94,7 @@ dvb_fastscan_create(htsmsg_t *e) dvb_fastscan_t *fs; dvb_fastscan_item_t *fsi; bouquet_t *bq; - const char *name; + const char *name, *polarisation, *delsys; int pid; char url[64], buf[16]; @@ -103,10 +107,18 @@ dvb_fastscan_create(htsmsg_t *e) goto fail; if ((name = htsmsg_get_str(e, "name")) == NULL) goto fail; + if (htsmsg_get_u32(e, "symbolrate", &fastscan_rb_skel->symbolRate)) + goto fail; + if ((delsys = htsmsg_get_str(e, "delsys")) == NULL) + goto fail; + if ((polarisation = htsmsg_get_str(e, "polarisation")) == NULL) + goto fail; + fastscan_rb_skel->polarisation = dvb_str2pol(polarisation); + fastscan_rb_skel->delsys = dvb_str2delsys(delsys); dvb_sat_position_to_str(fastscan_rb_skel->position, buf, sizeof(buf)); - snprintf(url, sizeof(url), "dvb-fastscan://dvbs,%s,%u,%d", - buf, fastscan_rb_skel->frequency, pid); + snprintf(url, sizeof(url), "dvb-fastscan://%s,%s,%u,%s,%u,%d", dvb_delsys2str(fastscan_rb_skel->delsys), + buf, fastscan_rb_skel->frequency, dvb_pol2str(fastscan_rb_skel->polarisation), fastscan_rb_skel->symbolRate, pid); bq = bouquet_find_by_source(name, url, 1); if (bq == NULL) goto fail; diff --git a/src/input/mpegts/fastscan.h b/src/input/mpegts/fastscan.h index 85eb2aa5..ca577420 100644 --- a/src/input/mpegts/fastscan.h +++ b/src/input/mpegts/fastscan.h @@ -24,7 +24,7 @@ struct bouquet; void -dvb_fastscan_each(void *aux, int position, uint32_t frequency, +dvb_fastscan_each(void *aux, int position, uint32_t frequency, dvb_polarisation_t polarisation, void (*job)(void *aux, struct bouquet *, const char *name, int pid)); diff --git a/src/input/mpegts/mpegts_network_scan.c b/src/input/mpegts/mpegts_network_scan.c index e4d86f63..711e350b 100644 --- a/src/input/mpegts/mpegts_network_scan.c +++ b/src/input/mpegts/mpegts_network_scan.c @@ -321,18 +321,7 @@ tsid_lookup: if (!extra) return; freq = strtod(extra, NULL) * 1000; - goto freq; - } - if ((l = startswith(src, "dvb-fastscan://dvbs,")) > 0) { - uint32_t pid; - src += l; - if ((satpos = dvb_sat_position_from_str(src)) == INT_MAX) - return; - while (*src && *src != ',') - src++; - if (sscanf(src, ",%u,%u", &freq, &pid) != 2) - return; -freq: + LIST_FOREACH(mn, &mpegts_network_all, mn_global_link) LIST_FOREACH(mm, &mn->mn_muxes, mm_network_link) if (idnode_is_instance(&mm->mm_id, &dvb_mux_dvbs_class) && @@ -341,6 +330,76 @@ freq: mpegts_mux_scan_state_set(mm, MM_SCAN_STATE_PEND); return; } + if ((l = startswith(src, "dvb-fastscan://")) > 0) { + uint32_t pid, symbol, dvbs2; + char pol[2]; + pol[1] = '\0'; + src += l; + + if ((l = startswith(src, "DVBS2,")) > 0) + dvbs2 = 1; + else if ((l = startswith(src, "DVBS,")) > 0) + dvbs2 = 0; + else + return; + src += l; + + if ((satpos = dvb_sat_position_from_str(src)) == INT_MAX) + return; + while (*src && *src != ',') + src++; + if (sscanf(src, ",%u,%c,%u,%u", &freq, &pol[0], &symbol, &pid) != 4) + return; + + // search for fastscan mux + LIST_FOREACH(mn, &mpegts_network_all, mn_global_link) + LIST_FOREACH(mm, &mn->mn_muxes, mm_network_link) + if (idnode_is_instance(&mm->mm_id, &dvb_mux_dvbs_class) && + abs(((dvb_mux_t *)mm)->lm_tuning.dmc_fe_freq - freq) < 2000 && + ((dvb_mux_t *)mm)->lm_tuning.u.dmc_fe_qpsk.polarisation == dvb_str2pol(pol) && + ((dvb_mux_t *)mm)->lm_tuning.u.dmc_fe_qpsk.orbital_pos == satpos) + { + char buf[256]; + mpegts_mux_nice_name(mm, buf, sizeof(buf)); + tvhinfo("mpegts", "fastscan mux found '%s', set scan state 'PENDING'", buf); + mpegts_mux_scan_state_set(mm, MM_SCAN_STATE_PEND); + return; + } + tvhinfo("mpegts", "fastscan mux not found, position:%i, frequency:%i, polarisation:%c", satpos, freq, pol[0]); + + // fastscan mux not found, try to add it automatically + LIST_FOREACH(mn, &mpegts_network_all, mn_global_link) + if (mn->mn_satpos != INT_MAX && mn->mn_satpos == satpos) + { + dvb_mux_conf_t *mux; + mpegts_mux_t *mm = NULL; + + mux = malloc(sizeof(dvb_mux_conf_t)); + dvb_mux_conf_init(mux, dvbs2 ? DVB_SYS_DVBS2 : DVB_SYS_DVBS); + mux->dmc_fe_freq = freq; + mux->u.dmc_fe_qpsk.symbol_rate = symbol; + mux->u.dmc_fe_qpsk.polarisation = dvb_str2pol(pol); + mux->u.dmc_fe_qpsk.orbital_pos = satpos; + mux->u.dmc_fe_qpsk.fec_inner = DVB_FEC_AUTO; + mux->dmc_fe_modulation = DVB_MOD_AUTO; + mux->dmc_fe_rolloff = DVB_ROLLOFF_AUTO; + mux->dmc_fe_pls_code = 1; + + mm = (mpegts_mux_t*)dvb_mux_create0((dvb_network_t*)mn, + MPEGTS_ONID_NONE, + MPEGTS_TSID_NONE, + mux, NULL, NULL); + if (mm) + { + mm->mm_config_save(mm); + char buf[256]; + mn->mn_display_name(mn, buf, sizeof(buf)); + tvhinfo("mpegts", "fastscan mux add to network '%s'", buf); + } + free(mux); + } + return; + } #endif }