Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV: add file:// scheme support (incomplete)
  • Loading branch information
perexg committed Nov 13, 2015
1 parent 5192186 commit c0206a1
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/input/mpegts/iptv/iptv.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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));

Expand Down
100 changes: 100 additions & 0 deletions 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 <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));
}
2 changes: 1 addition & 1 deletion src/input/mpegts/iptv/iptv_mux.c
Expand Up @@ -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 *
Expand Down
1 change: 1 addition & 0 deletions src/input/mpegts/iptv/iptv_private.h
Expand Up @@ -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) );
Expand Down

0 comments on commit c0206a1

Please sign in to comment.