]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
dvb: Move out PID specific stuff from dvb_service.c
authorAndreas Öman <andreas@lonelycoder.com>
Fri, 19 Oct 2012 08:53:22 +0000 (10:53 +0200)
committerAndreas Öman <andreas@lonelycoder.com>
Thu, 25 Oct 2012 11:06:05 +0000 (13:06 +0200)
Makefile
src/dvb/dvb.h
src/dvb/dvb_adapter.c
src/dvb/dvb_input_filtered.c [new file with mode: 0644]
src/dvb/dvb_service.c

index 59b2506545406c5e7f67b3d9eea455d6f69b0241..b795333976db67cbb1408fde60d9f54ab10121bb 100644 (file)
--- 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
index c5d93d0ca58e012822c101044611d028bf03fe5b..7a71bf9cf42f9c626193a3757481faa87240be3d 100644 (file)
@@ -24,6 +24,8 @@
 #include <pthread.h>
 #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
  */
index e4973be33eb17c7c275a81cbb915508359381faf..83e2d4d0caa043e7f75ffb5a2c98fdd8ea5c8ee7 100644 (file)
@@ -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 (file)
index 0000000..59d934f
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * DVB input using hardware filters
+ */
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/dvb/frontend.h>
+#include <linux/dvb/dmx.h>
+
+#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;
+}
+
index 9ea91b0f007ac2a2c1e811c126f99370edcf2ec8..32877f8e91433642a8244f23fb764998e2831654 100644 (file)
 #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);
 }