dvb-demux: add code for DVB section filter
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Fri, 14 Feb 2014 05:17:53 +0000 (14:17 +0900)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Sat, 15 Feb 2014 18:48:48 +0000 (03:48 +0900)
Instead of hardcoding its call inside dvb-scan, add a function
to set a section filter at the proper place (dmx-demux.c).

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

index 51d2176..fc3df0b 100644 (file)
@@ -39,7 +39,14 @@ int dvb_dmx_open(int adapter, int demux);
 void dvb_dmx_close(int dmx_fd);
 void dvb_dmx_stop(int dmx_fd);
 
-int dvb_set_pesfilter(int dmxfd, int pid, dmx_pes_type_t type, dmx_output_t output, int buffersize);
+int dvb_set_pesfilter(int dmxfd, int pid, dmx_pes_type_t type,
+                     dmx_output_t output, int buffersize);
+
+int dvb_set_section_filter(int dmxfd, int pid, unsigned filtsize,
+                          unsigned char *filter,
+                          unsigned char *mask,
+                          unsigned char *mode,
+                          unsigned int flags);
 
 int get_pmt_pid(const char *dmxdev, int sid);
 
index e867c35..cfd075f 100644 (file)
@@ -61,7 +61,8 @@ void dvb_dmx_stop(int dmx_fd)
        (void) ioctl(dmx_fd, DMX_STOP);
 }
 
-int dvb_set_pesfilter(int dmxfd, int pid, dmx_pes_type_t type, dmx_output_t output, int buffersize)
+int dvb_set_pesfilter(int dmxfd, int pid, dmx_pes_type_t type,
+                     dmx_output_t output, int buffersize)
 {
        struct dmx_pes_filter_params pesfilter;
 
@@ -87,6 +88,39 @@ int dvb_set_pesfilter(int dmxfd, int pid, dmx_pes_type_t type, dmx_output_t outp
        return 0;
 }
 
+int dvb_set_section_filter(int dmxfd, int pid, unsigned filtsize,
+                          unsigned char *filter,
+                          unsigned char *mask,
+                          unsigned char *mode,
+                          unsigned int flags)
+{
+       struct dmx_sct_filter_params sctfilter;
+
+       if (filtsize > DMX_FILTER_SIZE)
+               filtsize = DMX_FILTER_SIZE;
+
+       memset(&sctfilter, 0, sizeof(sctfilter));
+
+       sctfilter.pid = pid;
+
+       if (filter)
+               memcpy(sctfilter.filter.filter, filter, filtsize);
+       if (mask)
+               memcpy(sctfilter.filter.mask, mask, filtsize);
+       if (mode)
+               memcpy(sctfilter.filter.mode, mode, filtsize);
+
+       sctfilter.flags = flags;
+
+       if (ioctl(dmxfd, DMX_SET_FILTER, &sctfilter) == -1) {
+               fprintf(stderr, "DMX_SET_FILTER failed (PID = 0x%04x): %d %m\n",
+                       pid, errno);
+               return -1;
+       }
+
+       return 0;
+}
+
 int get_pmt_pid(const char *dmxdev, int sid)
 {
        int patfd, count;
index 42e2c8c..69b175a 100644 (file)
@@ -98,6 +98,7 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd,
        uint8_t *buf = NULL;
        uint8_t *tbl = NULL;
        ssize_t table_length = 0;
+       uint8_t mask = 0xff;
 
        /* variables for section handling */
        int start_id = -1;
@@ -105,7 +106,6 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd,
        int first_section = -1;
        int last_section = -1;
        int sections = 0;
-       struct dmx_sct_filter_params f;
        struct dvb_table_header *h;
 
        if (!table)
@@ -114,16 +114,9 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd,
 
        // FIXME: verify known table
 
-       memset(&f, 0, sizeof(f));
-       f.pid = pid;
-       f.filter.filter[0] = tid;
-       f.filter.mask[0] = 0xff;
-       f.timeout = 0;
-       f.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
-       if (ioctl(dmx_fd, DMX_SET_FILTER, &f) == -1) {
-               dvb_perror("dvb_read_section: ioctl DMX_SET_FILTER failed");
+       if (dvb_set_section_filter(dmx_fd, pid, 1, &tid, &mask, NULL,
+                                  DMX_IMMEDIATE_START | DMX_CHECK_CRC))
                return -1;
-       }
 
        if (parms->verbose)
                dvb_log("Parsing table ID %d, program ID %d", tid, pid);