From 0bc631332af5750cd38218131570640a1065bc9d Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 9 Jan 2012 11:09:54 -0200 Subject: [PATCH] utils/dvb: Allow filling the scan file with NIT network information Instead of just keeping the same parameters (generally auto-detection ones) for each service, allows overriding it with the detected data at the NIT tables. Also, add two options at dvbv5-scan to enable this feature, and to enable calling get_frontend() inside the drivers, from where other detected stuff may be read. Signed-off-by: Mauro Carvalho Chehab --- utils/dvb/dvb-file.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++- utils/dvb/dvb-file.h | 6 ++- utils/dvb/dvbv5-scan.c | 19 +++++++-- 3 files changed, 124 insertions(+), 6 deletions(-) diff --git a/utils/dvb/dvb-file.c b/utils/dvb/dvb-file.c index a0e1c79..b5ead20 100644 --- a/utils/dvb/dvb-file.c +++ b/utils/dvb/dvb-file.c @@ -514,10 +514,110 @@ char *dvb_vchannel(struct dvb_descriptors *dvb_desc, return buf; } +static int store_entry_prop(struct dvb_entry *entry, + uint32_t cmd, uint32_t value) +{ + int i; + + for (i = 0; i < entry->n_props; i++) { + if (cmd == entry->props[i].cmd) + break; + } + if (i == entry->n_props) { + if (i == DTV_MAX_COMMAND) { + fprintf(stderr, "Can't add property %s\n", + dvb_v5_name[cmd]); + return -1; + } + entry->n_props++; + } + + entry->props[i].u.data = value; + + return 0; +} + +static void handle_std_specific_parms(struct dvb_entry *entry, + struct dvb_descriptors *dvb_desc) +{ + struct nit_table *nit_table = &dvb_desc->nit_table; + int i; + + /* + * If found, parses the NIT tables for the delivery systems + * with the information provided on it. For some delivery systems, + * there are some missing stuff. + */ + switch (nit_table->delivery_system) { + case SYS_ISDBT: + store_entry_prop(entry, DTV_GUARD_INTERVAL, + nit_table->guard_interval); + store_entry_prop(entry, DTV_TRANSMISSION_MODE, + nit_table->transmission_mode); + asprintf(&entry->location, "area %d", nit_table->area_code); + for (i = 0; i < nit_table->partial_reception_len; i++) { + int par, sid = entry->service_id; + par = (sid == nit_table->partial_reception[i]) ? + 1 : 0; + store_entry_prop(entry, DTV_ISDBT_PARTIAL_RECEPTION, + par); + break; + } + break; + case SYS_DVBS2: + store_entry_prop(entry, DTV_ROLLOFF, + nit_table->rolloff); + /* fall through */ + case SYS_DVBS: + entry->location = strdup(nit_table->orbit); + store_entry_prop(entry, DTV_FREQUENCY, + nit_table->frequency[0]); + store_entry_prop(entry, DTV_MODULATION, + nit_table->modulation); + entry->pol = nit_table->pol; + store_entry_prop(entry, DTV_DELIVERY_SYSTEM, + nit_table->delivery_system); + store_entry_prop(entry, DTV_SYMBOL_RATE, + nit_table->symbol_rate); + store_entry_prop(entry, DTV_INNER_FEC, + nit_table->fec_inner); + break; + case SYS_DVBC_ANNEX_A: + entry->location = strdup(nit_table->network_name); + store_entry_prop(entry, DTV_FREQUENCY, + nit_table->frequency[0]); + store_entry_prop(entry, DTV_MODULATION, + nit_table->modulation); + store_entry_prop(entry, DTV_SYMBOL_RATE, + nit_table->symbol_rate); + store_entry_prop(entry, DTV_INNER_FEC, + nit_table->fec_inner); + break; + case SYS_DVBT: + entry->location = strdup(nit_table->network_name); + store_entry_prop(entry, DTV_FREQUENCY, + nit_table->frequency[0]); + store_entry_prop(entry, DTV_MODULATION, + nit_table->modulation); + store_entry_prop(entry, DTV_BANDWIDTH_HZ, + nit_table->bandwidth); + store_entry_prop(entry, DTV_CODE_RATE_HP, + nit_table->code_rate_hp); + store_entry_prop(entry, DTV_CODE_RATE_LP, + nit_table->code_rate_lp); + store_entry_prop(entry, DTV_GUARD_INTERVAL, + nit_table->guard_interval); + store_entry_prop(entry, DTV_TRANSMISSION_MODE, + nit_table->transmission_mode); + store_entry_prop(entry, DTV_HIERARCHY, + nit_table->hierarchy); + } +} + int store_dvb_channel(struct dvb_file **dvb_file, struct dvb_v5_fe_parms *parms, struct dvb_descriptors *dvb_desc, - int get_detected) + int get_detected, int get_nit) { struct dvb_entry *entry; int i, j; @@ -595,6 +695,9 @@ int store_dvb_channel(struct dvb_file **dvb_file, entry->props[j].u.data = parms->dvb_prop[j].u.data; } entry->n_props = parms->n_props; + + if (get_nit) + handle_std_specific_parms(entry, dvb_desc); } return 0; diff --git a/utils/dvb/dvb-file.h b/utils/dvb/dvb-file.h index 30cc354..0791288 100644 --- a/utils/dvb/dvb-file.h +++ b/utils/dvb/dvb-file.h @@ -29,6 +29,8 @@ struct dvb_entry { char *channel; char *vchannel; + char *location; + enum polarization pol; int sat_number; unsigned diseqc_wait; @@ -79,6 +81,8 @@ static inline void dvb_file_free(struct dvb_file *dvb_file) free (entry->channel); if (entry->vchannel) free (entry->vchannel); + if (entry->location) + free (entry->location); if (entry->video_pid) free (entry->video_pid); if (entry->audio_pid) @@ -112,4 +116,4 @@ char *dvb_vchannel(struct dvb_descriptors *dvb_desc, int store_dvb_channel(struct dvb_file **dvb_file, struct dvb_v5_fe_parms *parms, struct dvb_descriptors *dvb_desc, - int get_detected); + int get_detected, int get_nit); diff --git a/utils/dvb/dvbv5-scan.c b/utils/dvb/dvbv5-scan.c index dab17b6..b51a2c5 100644 --- a/utils/dvb/dvbv5-scan.c +++ b/utils/dvb/dvbv5-scan.c @@ -102,7 +102,8 @@ static int check_frontend(struct dvb_v5_fe_parms *parms, int timeout) } static int run_scan(const char *fname, int format, - struct dvb_v5_fe_parms *parms) + struct dvb_v5_fe_parms *parms, + int get_detected, int get_nit) { struct dvb_file *dvb_file = NULL, *dvb_file_new = NULL; struct dvb_entry *entry; @@ -229,7 +230,8 @@ static int run_scan(const char *fname, int format, printf("\n"); } - store_dvb_channel(&dvb_file_new, parms, dvb_desc, 0); + store_dvb_channel(&dvb_file_new, parms, dvb_desc, + get_detected, get_nit); free_dvb_ts_tables(dvb_desc); } @@ -253,6 +255,8 @@ static char *usage = " -l LNBf : type of LNBf to use. 'help' lists the available ones\n" " -S number : satellite number. If not specified, disable DISEqC\n" " -W number : adds aditional wait time for DISEqC command completion\n" + " -N : use data from NIT table on the output file\n" + " -G : use data from get_frontend on the output file\n" " -v : be (very) verbose\n" " -o file : output filename (use -o - for stdout)\n" " -O : uses old channel format\n" @@ -263,12 +267,13 @@ int main(int argc, char **argv) { char *confname = NULL, *lnb_name = NULL; int adapter = 0, frontend = 0, demux = 0; + int get_detected = 0, get_nit = 0; int lnb = -1, sat_number = -1; unsigned diseqc_wait = 0; int opt, format = 0; struct dvb_v5_fe_parms *parms; - while ((opt = getopt(argc, argv, "H?ha:f:d:vzOl:S:W:")) != -1) { + while ((opt = getopt(argc, argv, "H?ha:f:d:vzOl:S:W:NG")) != -1) { switch (opt) { case 'a': adapter = strtoul(optarg, NULL, 0); @@ -294,6 +299,12 @@ int main(int argc, char **argv) case 'W': diseqc_wait = strtoul(optarg, NULL, 0); break; + case 'N': + get_nit++; + break; + case 'D': + get_detected++; + break; case 'v': verbose++; break; @@ -341,7 +352,7 @@ int main(int argc, char **argv) parms->sat_number = sat_number % 3; parms->diseqc_wait = diseqc_wait; - if (run_scan(confname, format, parms)) + if (run_scan(confname, format, parms, get_detected, get_nit)) return -1; dvb_fe_close(parms); -- 2.7.4