From 65a8fa5f282cca73489e43b516d30e0c178a55c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Fri, 19 Oct 2012 10:53:22 +0200 Subject: [PATCH] dvb: Move out PID specific stuff from dvb_service.c --- Makefile | 1 + src/dvb/dvb.h | 8 +++ src/dvb/dvb_adapter.c | 2 + src/dvb/dvb_input_filtered.c | 115 +++++++++++++++++++++++++++++++++++ src/dvb/dvb_service.c | 61 ++----------------- 5 files changed, 130 insertions(+), 57 deletions(-) create mode 100644 src/dvb/dvb_input_filtered.c diff --git a/Makefile b/Makefile index 59b25065..b7953339 100644 --- a/Makefile +++ b/Makefile @@ -155,6 +155,7 @@ SRCS-${CONFIG_LINUXDVB} += \ src/dvb/dvb_service.c \ src/dvb/dvb_preconf.c \ src/dvb/dvb_satconf.c \ + src/dvb/dvb_input_filtered.c \ src/webui/extjs_dvb.c \ # V4L diff --git a/src/dvb/dvb.h b/src/dvb/dvb.h index c5d93d0c..7a71bf9c 100644 --- a/src/dvb/dvb.h +++ b/src/dvb/dvb.h @@ -24,6 +24,8 @@ #include #include "htsmsg.h" +struct service; + #define DVB_VER_INT(maj,min) (((maj) << 16) + (min)) #define DVB_VER_ATLEAST(maj, min) \ @@ -231,6 +233,9 @@ typedef struct th_dvb_adapter { uint32_t tda_extrapriority; // extra priority for choosing the best adapter/service + void (*tda_open_service)(struct th_dvb_adapter *tda, struct service *s); + void (*tda_close_service)(struct th_dvb_adapter *tda, struct service *s); + } th_dvb_adapter_t; /** @@ -336,6 +341,9 @@ void dvb_adapter_set_extrapriority(th_dvb_adapter_t *tda, int extrapriority); void dvb_adapter_poweroff(th_dvb_adapter_t *tda); +void dvb_input_filtered_setup(th_dvb_adapter_t *tda); + + /** * DVB Multiplex */ diff --git a/src/dvb/dvb_adapter.c b/src/dvb/dvb_adapter.c index e4973be3..83e2d4d0 100644 --- a/src/dvb/dvb_adapter.c +++ b/src/dvb/dvb_adapter.c @@ -68,6 +68,8 @@ tda_alloc(void) tda->tda_allpids_dmx_fd = -1; tda->tda_dump_fd = -1; + dvb_input_filtered_setup(tda); + return tda; } diff --git a/src/dvb/dvb_input_filtered.c b/src/dvb/dvb_input_filtered.c new file mode 100644 index 00000000..59d934f8 --- /dev/null +++ b/src/dvb/dvb_input_filtered.c @@ -0,0 +1,115 @@ +/* + * TV Input - Linux DVB interface + * Copyright (C) 2012 Andreas Ă–man + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * DVB input using hardware filters + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "tvheadend.h" +#include "dvb.h" +#include "service.h" + +/** + * Install filters for a service + * + * global_lock must be held + */ +static void +open_service(th_dvb_adapter_t *tda, service_t *s) +{ + struct dmx_pes_filter_params dmx_param; + int fd; + elementary_stream_t *st; + + TAILQ_FOREACH(st, &s->s_components, es_link) { + if(st->es_pid >= 0x2000) + continue; + + if(st->es_demuxer_fd != -1) + continue; + + fd = tvh_open(tda->tda_demux_path, O_RDWR, 0); + st->es_cc_valid = 0; + + if(fd == -1) { + st->es_demuxer_fd = -1; + tvhlog(LOG_ERR, "dvb", + "\"%s\" unable to open demuxer \"%s\" for pid %d -- %s", + s->s_identifier, tda->tda_demux_path, + st->es_pid, strerror(errno)); + continue; + } + + memset(&dmx_param, 0, sizeof(dmx_param)); + dmx_param.pid = st->es_pid; + dmx_param.input = DMX_IN_FRONTEND; + dmx_param.output = DMX_OUT_TS_TAP; + dmx_param.pes_type = DMX_PES_OTHER; + dmx_param.flags = DMX_IMMEDIATE_START; + + if(ioctl(fd, DMX_SET_PES_FILTER, &dmx_param)) { + tvhlog(LOG_ERR, "dvb", + "\"%s\" unable to configure demuxer \"%s\" for pid %d -- %s", + s->s_identifier, tda->tda_demux_path, + st->es_pid, strerror(errno)); + close(fd); + fd = -1; + } + + st->es_demuxer_fd = fd; + } +} + + +/** + * Remove filters for a service + * + * global_lock must be held + */ +static void +close_service(th_dvb_adapter_t *tda, service_t *s) +{ + elementary_stream_t *es; + + TAILQ_FOREACH(es, &s->s_components, es_link) { + if(es->es_demuxer_fd != -1) { + close(es->es_demuxer_fd); + es->es_demuxer_fd = -1; + } + } +} + + + + + +void +dvb_input_filtered_setup(th_dvb_adapter_t *tda) +{ + tda->tda_open_service = open_service; + tda->tda_close_service = close_service; +} + diff --git a/src/dvb/dvb_service.c b/src/dvb/dvb_service.c index 9ea91b0f..32877f8e 100644 --- a/src/dvb/dvb_service.c +++ b/src/dvb/dvb_service.c @@ -44,54 +44,6 @@ #include "dvb_support.h" #include "notify.h" -/** - * - */ -static void -dvb_service_open_demuxers(th_dvb_adapter_t *tda, service_t *t) -{ - struct dmx_pes_filter_params dmx_param; - int fd; - elementary_stream_t *st; - - TAILQ_FOREACH(st, &t->s_components, es_link) { - if(st->es_pid >= 0x2000) - continue; - - if(st->es_demuxer_fd != -1) - continue; - - fd = tvh_open(tda->tda_demux_path, O_RDWR, 0); - st->es_cc_valid = 0; - - if(fd == -1) { - st->es_demuxer_fd = -1; - tvhlog(LOG_ERR, "dvb", - "\"%s\" unable to open demuxer \"%s\" for pid %d -- %s", - t->s_identifier, tda->tda_demux_path, - st->es_pid, strerror(errno)); - continue; - } - - memset(&dmx_param, 0, sizeof(dmx_param)); - dmx_param.pid = st->es_pid; - dmx_param.input = DMX_IN_FRONTEND; - dmx_param.output = DMX_OUT_TS_TAP; - dmx_param.pes_type = DMX_PES_OTHER; - dmx_param.flags = DMX_IMMEDIATE_START; - - if(ioctl(fd, DMX_SET_PES_FILTER, &dmx_param)) { - tvhlog(LOG_ERR, "dvb", - "\"%s\" unable to configure demuxer \"%s\" for pid %d -- %s", - t->s_identifier, tda->tda_demux_path, - st->es_pid, strerror(errno)); - close(fd); - fd = -1; - } - - st->es_demuxer_fd = fd; - } -} @@ -140,7 +92,7 @@ dvb_service_start(service_t *t, unsigned int weight, int force_start) pthread_mutex_unlock(&tda->tda_delivery_mutex); if(!r) - dvb_service_open_demuxers(tda, t); + tda->tda_open_service(tda, t); dvb_table_add_pmt(t->s_dvb_mux_instance, t->s_pmt_pid); @@ -155,7 +107,6 @@ static void dvb_service_stop(service_t *t) { th_dvb_adapter_t *tda = t->s_dvb_mux_instance->tdmi_adapter; - elementary_stream_t *st; lock_assert(&global_lock); @@ -163,12 +114,8 @@ dvb_service_stop(service_t *t) LIST_REMOVE(t, s_active_link); pthread_mutex_unlock(&tda->tda_delivery_mutex); - TAILQ_FOREACH(st, &t->s_components, es_link) { - if(st->es_demuxer_fd != -1) { - close(st->es_demuxer_fd); - st->es_demuxer_fd = -1; - } - } + tda->tda_close_service(tda, t); + t->s_status = SERVICE_IDLE; } @@ -182,7 +129,7 @@ dvb_service_refresh(service_t *t) th_dvb_adapter_t *tda = t->s_dvb_mux_instance->tdmi_adapter; lock_assert(&global_lock); - dvb_service_open_demuxers(tda, t); + tda->tda_open_service(tda, t); }