libdvbv5: Better handle program data
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 17 Nov 2013 11:13:35 +0000 (09:13 -0200)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Wed, 27 Nov 2013 11:24:40 +0000 (09:24 -0200)
Program data tables (pmt) are associated with the program
inside the pat table.

Keep that association, in order to make life easier for scanning
programs that may need it.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/include/dvb-scan-table-handler.h
lib/libdvbv5/dvb-scan-table-handler.c
lib/libdvbv5/dvb-scan.c

index 745d7d7..81ced1f 100644 (file)
@@ -147,6 +147,10 @@ struct sdt_table {
        unsigned service_table_len;
 };
 
+struct dvb_v5_descriptors_program {
+       struct dvb_table_pat_program *program;
+       struct dvb_table_pmt *pmt;
+};
 struct dvb_v5_descriptors {
        int verbose;
        uint32_t delivery_system;
@@ -164,11 +168,11 @@ struct dvb_v5_descriptors {
 
        struct dvb_table_pat *pat;
        struct dvb_table_vct *vct;
-       struct dvb_table_pmt **pmt;
+       struct dvb_v5_descriptors_program *program;
        struct dvb_table_nit *nit;
        struct dvb_table_sdt *sdt;
 
-       unsigned num_pmt;
+       unsigned num_program;
 };
 
 struct dvb_v5_descriptors *dvb_scan_alloc_handler_table(uint32_t delivery_system,
index 2dabee9..f45a1ca 100644 (file)
@@ -121,9 +121,11 @@ void dvb_scan_free_handler_table(struct dvb_v5_descriptors *dvb_scan_handler)
                dvb_table_nit_free(dvb_scan_handler->nit);
        if (dvb_scan_handler->sdt)
                dvb_table_sdt_free(dvb_scan_handler->sdt);
-       if (dvb_scan_handler->pmt) {
-               for (i = 0; i < dvb_scan_handler->num_pmt; i++)
-                       dvb_table_pmt_free(dvb_scan_handler->pmt[i]);
+       if (dvb_scan_handler->program) {
+               for (i = 0; i < dvb_scan_handler->num_program; i++)
+                       if (dvb_scan_handler->program[i].pmt)
+                               dvb_table_pmt_free(dvb_scan_handler->program[i].pmt);
+               free(dvb_scan_handler->program);
        }
 
        free(dvb_scan_handler);
index ff153b0..e3d74a9 100644 (file)
@@ -307,32 +307,39 @@ struct dvb_v5_descriptors *dvb_get_ts_tables(struct dvb_v5_fe_parms *parms,
 
        /* PMT tables */
 
-       dvb_scan_handler->pmt = NULL;
+       dvb_scan_handler->program = calloc(dvb_scan_handler->pat->programs,
+                                          sizeof(*dvb_scan_handler->program));
 
        dvb_pat_program_foreach(program, dvb_scan_handler->pat) {
-               uint16_t pn = program->service_id;
-               /* Skip PAT, CAT, reserved and NULL packets */
-               if (!pn)
+               dvb_scan_handler->program->program = program;
+
+               if (!program->service_id) {
+                       dvb_log("Program ID %d has service ID 0. discarding",
+                               program->pid);
+                       num_pmt++;
                        continue;
+               }
 
-               dvb_scan_handler->pmt = realloc(dvb_scan_handler->pmt,
-                                               sizeof(*dvb_scan_handler->pmt) * (num_pmt + 1));
+               dvb_scan_handler->program[num_pmt].pmt = calloc(1, sizeof(*dvb_scan_handler->program[num_pmt].pmt));
 
                dvb_log("Program ID %d", program->pid);
                rc = dvb_read_section(parms, dmx_fd,
                                      DVB_TABLE_PMT, program->pid,
-                                     (uint8_t **)&dvb_scan_handler->pmt[num_pmt],
+                                     (uint8_t **)&dvb_scan_handler->program[num_pmt].pmt,
                                      pat_pmt_time * timeout_multiply);
-               if (rc < 0)
-                       fprintf(stderr, "error while reading the PMT table for service 0x%04x\n",
-                                       pn);
-               else {
+               if (rc < 0) {
+                       fprintf(stderr,
+                               "error while reading the PMT table for service 0x%04x\n",
+                               program->service_id);
+                       free(dvb_scan_handler->program->pmt);
+                       dvb_scan_handler->program->pmt = NULL;
+               } else {
                        if (verbose)
-                               dvb_table_pmt_print(parms, dvb_scan_handler->pmt[num_pmt]);
-
-                       num_pmt++;
+                               dvb_table_pmt_print(parms, dvb_scan_handler->program[num_pmt].pmt);
                }
+               num_pmt++;
        }
+       dvb_scan_handler->num_program = num_pmt;
 
        /* NIT table */
        rc = dvb_read_section(parms, dmx_fd,