From 009354c4e455b77c42da0bf7c47860d3f5952bf4 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sat, 7 Jan 2012 08:56:40 -0200 Subject: [PATCH] utils/dvb: read/write the virtual channel number Signed-off-by: Mauro Carvalho Chehab --- utils/dvb/dvb-file.c | 37 +++++++++++++++++++++++++++++++++++++ utils/dvb/dvb-file.h | 1 + 2 files changed, 38 insertions(+) diff --git a/utils/dvb/dvb-file.c b/utils/dvb/dvb-file.c index 055e2e1..9b6cab3 100644 --- a/utils/dvb/dvb-file.c +++ b/utils/dvb/dvb-file.c @@ -247,6 +247,12 @@ static int fill_entry(struct dvb_entry *entry, char *key, char *value) return 0; } + if (!strcasecmp(key, "VCHANNEL")) { + entry->vchannel = strdup(value); + return 0; + } + + if (!strcasecmp(key, "VIDEO_PID")) is_video = 1; else if (!strcasecmp(key, "AUDIO_PID")) @@ -404,6 +410,8 @@ int write_dvb_file(const char *fname, struct dvb_file *dvb_file) for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { if (entry->channel) { fprintf(fp, "[%s]\n", entry->channel); + if (entry->vchannel) + fprintf(fp, "\tVCHANNEL = %s\n", entry->vchannel); fprintf(fp, "\tSERVICE_ID = %d\n", entry->service_id); fprintf(fp, "\tVIDEO_PID ="); @@ -450,6 +458,33 @@ int write_dvb_file(const char *fname, struct dvb_file *dvb_file) return 0; }; +static char *vchannel(struct dvb_descriptors *dvb_desc, + struct service_table *service_table) +{ + struct lcn_table *lcn = dvb_desc->nit_table.lcn; + int i; + char *buf; + + if (!lcn) { + if (!dvb_desc->nit_table.virtual_channel) + return NULL; + + asprintf(&buf, "%d", dvb_desc->nit_table.virtual_channel); + return buf; + } + + for (i = 0; i < dvb_desc->nit_table.lcn_len; i++) { + if (lcn[i].service_id == service_table->service_id) { + asprintf(&buf, "%d.%d", + dvb_desc->nit_table.virtual_channel, + lcn[i].lcn); + return buf; + } + } + asprintf(&buf, "%d", dvb_desc->nit_table.virtual_channel); + return buf; +} + int store_dvb_channel(struct dvb_file **dvb_file, struct dvb_v5_fe_parms *parms, struct dvb_descriptors *dvb_desc, @@ -492,6 +527,8 @@ int store_dvb_channel(struct dvb_file **dvb_file, strcpy(entry->channel, service_table->service_name); entry->service_id = service_table->service_id; + entry->vchannel = vchannel(dvb_desc, service_table); + for (j = 0; j < pat_table->pid_table_len; j++) { pid_table = &pat_table->pid_table[j]; if (service_table->service_id == pid_table->program_number) diff --git a/utils/dvb/dvb-file.h b/utils/dvb/dvb-file.h index d7357a0..29c93bd 100644 --- a/utils/dvb/dvb-file.h +++ b/utils/dvb/dvb-file.h @@ -67,6 +67,7 @@ struct parse_struct { #define DTV_AUDIO_PID (DTV_MAX_COMMAND + 202) #define DTV_SERVICE_ID (DTV_MAX_COMMAND + 203) #define DTV_CH_NAME (DTV_MAX_COMMAND + 204) +#define DTV_VCHANNEL (DTV_MAX_COMMAND + 205) struct dvb_descriptors; -- 2.7.4