]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
IPTV: add file:// scheme support (incomplete)
authorJaroslav Kysela <perex@perex.cz>
Fri, 13 Nov 2015 07:32:21 +0000 (08:32 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 13 Nov 2015 07:33:46 +0000 (08:33 +0100)
Makefile
src/input/mpegts/iptv/iptv.c
src/input/mpegts/iptv/iptv_file.c [new file with mode: 0644]
src/input/mpegts/iptv/iptv_mux.c
src/input/mpegts/iptv/iptv_private.h

index f90166fafa64bc7bc7e626de12056a2042665f54..7a21799cc51c52bba79c7da3ad4cb0cdc5e669ac 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -381,6 +381,7 @@ SRCS-IPTV = \
         src/input/mpegts/iptv/iptv_rtsp.c \
         src/input/mpegts/iptv/iptv_rtcp.c \
         src/input/mpegts/iptv/iptv_pipe.c \
+        src/input/mpegts/iptv/iptv_file.c \
        src/input/mpegts/iptv/iptv_auto.c
 SRCS-${CONFIG_IPTV} += $(SRCS-IPTV)
 I18N-C += $(SRCS-IPTV)
index 61237dca7336dd48eaa8e2c180bad8f140a6d1de..23f1dc4015b39a2389f40dcb0bd7b38efe8a1004 100644 (file)
@@ -251,7 +251,9 @@ static const char *
 iptv_sub_url_encode(iptv_mux_t *im, const char *s, char *tmp, size_t tmplen)
 {
   char *p;
-  if (im->mm_iptv_url && !strncmp(im->mm_iptv_url, "pipe://", 7))
+  if (im->mm_iptv_url &&
+      (!strncmp(im->mm_iptv_url, "pipe://", 7) ||
+       !strncmp(im->mm_iptv_url, "file://", 7)))
     return s;
   p = url_encode(s);
   strncpy(tmp, p, tmplen-1);
@@ -319,6 +321,10 @@ iptv_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi )
 
     scheme = "pipe";
 
+  } else if (raw && !strncmp(raw, "file://", 7)) {
+
+    scheme = "file";
+
   } else {
 
     if (urlparse(raw ?: "", &url)) {
@@ -875,6 +881,7 @@ void iptv_init ( void )
   iptv_udp_init();
   iptv_rtsp_init();
   iptv_pipe_init();
+  iptv_file_init();
 
   iptv_input = calloc(1, sizeof(iptv_input_t));
 
diff --git a/src/input/mpegts/iptv/iptv_file.c b/src/input/mpegts/iptv/iptv_file.c
new file mode 100644 (file)
index 0000000..e7cfffd
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *  IPTV - file handler
+ *
+ *  Copyright (C) 2015 Jaroslav Kysela
+ *
+ *  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/>.
+ */
+
+#include "tvheadend.h"
+#include "iptv_private.h"
+#include "spawn.h"
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <assert.h>
+
+/*
+ * Connect UDP/RTP
+ */
+static int
+iptv_file_start ( iptv_mux_t *im, const char *raw, const url_t *url )
+{
+  int fd = tvh_open(raw + 7, O_RDONLY | O_DIRECT, 0);
+
+  if (fd < 0) {
+    tvherror("iptv", "unable to open file '%s'", raw + 7);
+    return -1;
+  }
+
+  im->mm_iptv_fd = fd;
+
+  iptv_input_mux_started(im);
+  return 0;
+}
+
+static void
+iptv_file_stop
+  ( iptv_mux_t *im )
+{
+  int rd = im->mm_iptv_fd;
+  if (rd > 0)
+    close(rd);
+  im->mm_iptv_fd = -1;
+}
+
+static ssize_t
+iptv_file_read ( iptv_mux_t *im )
+{
+  int r, fd = im->mm_iptv_fd;
+  ssize_t res = 0;
+
+  while (fd > 0) {
+    sbuf_alloc(&im->mm_iptv_buffer, 32*1024);
+    r = sbuf_read(&im->mm_iptv_buffer, fd);
+    if (r == 0) {
+      close(fd);
+      im->mm_iptv_fd = -1;
+      break;
+    }
+    if (r < 0) {
+      if (errno == EAGAIN)
+        break;
+      if (ERRNO_AGAIN(errno))
+        continue;
+    }
+    res += r;
+  }
+
+  return res;
+}
+
+/*
+ * Initialise pipe handler
+ */
+
+void
+iptv_file_init ( void )
+{
+  static iptv_handler_t ih[] = {
+    {
+      .scheme = "file",
+      .start  = iptv_file_start,
+      .stop   = iptv_file_stop,
+      .read   = iptv_file_read,
+    },
+  };
+  iptv_handler_register(ih, ARRAY_SIZE(ih));
+}
index 91011671e39c235b32373aa67783283e158c39f7..c13892ad802f7f8e06a8a836c057c650064a9b03 100644 (file)
@@ -94,7 +94,7 @@ static int
 iptv_mux_url_set ( void *p, const void *v )
 {
   iptv_mux_t *im = p;
-  return iptv_url_set(&im->mm_iptv_url, &im->mm_iptv_url_sane, v, 0, 1);
+  return iptv_url_set(&im->mm_iptv_url, &im->mm_iptv_url_sane, v, 1, 1);
 }
 
 static htsmsg_t *
index 0343e04a8d011d87d53a796ec389554fa7512134..3b127e09ff23d04b1f78d5b4bef36d7f06cc6a7c 100644 (file)
@@ -178,6 +178,7 @@ void iptv_http_init    ( void );
 void iptv_udp_init     ( void );
 void iptv_rtsp_init    ( void );
 void iptv_pipe_init    ( void );
+void iptv_file_init    ( void );
 
 ssize_t iptv_rtp_read ( iptv_mux_t *im, udp_multirecv_t *um,
                         void (*pkt_cb)(iptv_mux_t *im, uint8_t *buf, int len) );