From 83004676891678de73e285a6a3c06e09c98a961f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sun, 6 Dec 2009 14:07:55 +0000 Subject: [PATCH] Add RTP support to IPTV input --- debian/changelog | 2 ++ src/iptv_input.c | 32 +++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 78fa06b6..d7b0c336 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ hts-tvheadend (2.7) hts; urgency=low * Added support for DVB subtitles. Currently only forwarded over HTSP + * Add support for reception of RTP encapsulated IPTV + hts-tvheadend (2.6) hts; urgency=low * Tvheadend's DVB service probe will now make the channel join tags based diff --git a/src/iptv_input.c b/src/iptv_input.c index 7debd095..da0eaa10 100644 --- a/src/iptv_input.c +++ b/src/iptv_input.c @@ -123,9 +123,9 @@ static void * iptv_thread(void *aux) { int nfds, fd, r, j; - uint8_t tsb[65536]; - th_transport_t *t; + uint8_t tsb[65536], *buf; struct epoll_event ev; + th_transport_t *t; while(1) { nfds = epoll_wait(iptv_epollfd, &ev, 1, -1); @@ -142,11 +142,29 @@ iptv_thread(void *aux) fd = ev.data.fd; r = read(fd, tsb, sizeof(tsb)); - // Add RTP support here - - if((r % 188) != 0) - continue; // We expect multiples of a TS packet - + if(r > 1 && tsb[0] == 0x47 && (r % 188) == 0) { + /* Looks like raw TS in UDP */ + buf = tsb; + } else { + /* Check for valid RTP packets */ + if(r < 12) + continue; + + if((tsb[0] & 0xc0) != 0x80) + continue; + + if((tsb[1] & 0x7f) != 33) + continue; + + int hlen = (tsb[0] & 0xf) * 4 + 12; + + if(r < hlen || (r - hlen) % 188 != 0) + continue; + + buf = tsb + hlen; + r -= hlen; + } + pthread_mutex_lock(&iptv_recvmutex); LIST_FOREACH(t, &iptv_active_transports, tht_active_link) {