utils/dvb: read/write the virtual channel number
authorMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 7 Jan 2012 10:56:40 +0000 (08:56 -0200)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 7 Jan 2012 13:12:17 +0000 (11:12 -0200)
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
utils/dvb/dvb-file.c
utils/dvb/dvb-file.h

index 055e2e1894e5ed1ba36c94e8ea2b39bd4acd7262..9b6cab3b4d8a47c8c1becdd2b08389a90bed3196 100644 (file)
@@ -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)
index d7357a016906de31a8ab1fbd4a58de20bd5c6ad0..29c93bd20a07bac223701aa83a2e3ba96c166f3c 100644 (file)
@@ -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;