From: Jaroslav Kysela Date: Fri, 13 Nov 2015 07:32:21 +0000 (+0100) Subject: IPTV: add file:// scheme support (incomplete) X-Git-Tag: v4.2.1~1559 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0206a144b0496af0847a5740967604863f75e60;p=thirdparty%2Ftvheadend.git IPTV: add file:// scheme support (incomplete) --- diff --git a/Makefile b/Makefile index f90166faf..7a21799cc 100644 --- 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) diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index 61237dca7..23f1dc401 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -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 index 000000000..e7cfffda7 --- /dev/null +++ b/src/input/mpegts/iptv/iptv_file.c @@ -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 . + */ + +#include "tvheadend.h" +#include "iptv_private.h" +#include "spawn.h" + +#include +#include +#include +#include + +/* + * 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)); +} diff --git a/src/input/mpegts/iptv/iptv_mux.c b/src/input/mpegts/iptv/iptv_mux.c index 91011671e..c13892ad8 100644 --- a/src/input/mpegts/iptv/iptv_mux.c +++ b/src/input/mpegts/iptv/iptv_mux.c @@ -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 * diff --git a/src/input/mpegts/iptv/iptv_private.h b/src/input/mpegts/iptv/iptv_private.h index 0343e04a8..3b127e09f 100644 --- a/src/input/mpegts/iptv/iptv_private.h +++ b/src/input/mpegts/iptv/iptv_private.h @@ -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) );