From 34a63af3f11afd5d02fc5fdc0faf41afb9f2b2ed Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 14 Feb 2014 14:17:53 +0900 Subject: [PATCH] dvb-demux: add code for DVB section filter 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 --- lib/include/dvb-demux.h | 9 ++++++++- lib/libdvbv5/dvb-demux.c | 36 +++++++++++++++++++++++++++++++++++- lib/libdvbv5/dvb-scan.c | 13 +++---------- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/lib/include/dvb-demux.h b/lib/include/dvb-demux.h index 51d2176..fc3df0b 100644 --- a/lib/include/dvb-demux.h +++ b/lib/include/dvb-demux.h @@ -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); diff --git a/lib/libdvbv5/dvb-demux.c b/lib/libdvbv5/dvb-demux.c index e867c35..cfd075f 100644 --- a/lib/libdvbv5/dvb-demux.c +++ b/lib/libdvbv5/dvb-demux.c @@ -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; diff --git a/lib/libdvbv5/dvb-scan.c b/lib/libdvbv5/dvb-scan.c index 42e2c8c..69b175a 100644 --- a/lib/libdvbv5/dvb-scan.c +++ b/lib/libdvbv5/dvb-scan.c @@ -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); -- 2.7.4