Browse Source

Add RTP input support.

Georgi Chorbadzhiyski 7 years ago
parent
commit
f642e2963e
5 changed files with 24 additions and 5 deletions
  1. 2 2
      README
  2. 5 0
      data.c
  3. 5 0
      data.h
  4. 11 3
      input.c
  5. 1 0
      mptsd_channels.conf

+ 2 - 2
README View File

@@ -1,7 +1,7 @@
1 1
 mptsd
2 2
 =====
3
-mptsd receives mpegts streams from udp/multicast or http and combines them
4
-into one multiple program stream that is suitable for outputing to DVB-C
3
+mptsd receives mpegts streams from multicast (udp/rtp) or http and combines
4
+them into one multiple program stream that is suitable for outputing to DVB-C
5 5
 modulator. It is tested with Dektec DTE-3114 Quad QAM Modulator and it
6 6
 is used in production in couple of small DVB-C networks.
7 7
 

+ 5 - 0
data.c View File

@@ -43,6 +43,10 @@ channel_source get_sproto(char *url) {
43 43
 	return strncmp(url, "http", 4)==0 ? tcp_sock : udp_sock;
44 44
 }
45 45
 
46
+int is_rtp(char *url) {
47
+	return strncmp(url, "rtp", 3) == 0;
48
+}
49
+
46 50
 CHANSRC *chansrc_init(char *url) {
47 51
 	if (!url)
48 52
 		return NULL;
@@ -65,6 +69,7 @@ CHANSRC *chansrc_init(char *url) {
65 69
 		src->host  = strdup(host);
66 70
 		src->port  = iport ? iport : 80;
67 71
 		src->path  = strdup(path);
72
+		src->rtp   = strcmp(proto, "rtp") == 0;
68 73
 		FREE(data);
69 74
 		regfree(&re);
70 75
 		return src;

+ 5 - 0
data.h View File

@@ -27,6 +27,8 @@
27 27
 /* 7 * 188 */
28 28
 #define FRAME_PACKET_SIZE 1316
29 29
 
30
+#define RTP_HEADER_SIZE 12
31
+
30 32
 #include "libfuncs/libfuncs.h"
31 33
 
32 34
 #include "libtsfuncs/tsdata.h"
@@ -41,6 +43,7 @@ typedef struct {
41 43
 	char *host;
42 44
 	char *path;
43 45
 	unsigned int port;
46
+	unsigned int rtp;
44 47
 } CHANSRC;
45 48
 
46 49
 #define MAX_CHANNEL_SOURCES 8
@@ -221,6 +224,8 @@ void		channel_free	(CHANNEL **c);
221 224
 void		channel_free_epg(CHANNEL *c);
222 225
 
223 226
 channel_source get_sproto(char *url);
227
+int is_rtp(char *url);
228
+
224 229
 CHANSRC *	chansrc_init	(char *url);
225 230
 void		chansrc_free	(CHANSRC **url);
226 231
 void		chansrc_add		(CHANNEL *c, char *src);

+ 11 - 3
input.c View File

@@ -305,7 +305,8 @@ int in_worktime(int start, int end) {
305 305
 void * input_stream(void *self) {
306 306
 	INPUT *r = self;
307 307
 	INPUT_STREAM *s = &r->stream;
308
-	char buf[FRAME_PACKET_SIZE];
308
+	char buffer[RTP_HEADER_SIZE + FRAME_PACKET_SIZE];
309
+	char *buf = buffer + RTP_HEADER_SIZE;
309 310
 
310 311
 	signal(SIGPIPE, SIG_IGN);
311 312
 
@@ -335,8 +336,9 @@ void * input_stream(void *self) {
335 336
 			goto RECONNECT;
336 337
 
337 338
 		channel_source sproto = get_sproto(r->channel->source);
339
+		int rtp = is_rtp(r->channel->source);
338 340
 
339
-		if (mpeg_sync(r, sproto) != 0) {
341
+		if (!rtp && mpeg_sync(r, sproto) != 0) {
340 342
 			proxy_log(r, "Can't sync input MPEG TS");
341 343
 			sleep(2);
342 344
 			goto RECONNECT;
@@ -363,7 +365,13 @@ void * input_stream(void *self) {
363 365
 			if (sproto == tcp_sock) {
364 366
 				readen = fdread_ex(r->sock, buf, FRAME_PACKET_SIZE, TCP_READ_TIMEOUT, TCP_READ_RETRIES, 1);
365 367
 			} else {
366
-				readen = fdread_ex(r->sock, buf, FRAME_PACKET_SIZE, UDP_READ_TIMEOUT, UDP_READ_RETRIES, 0);
368
+				if (!rtp) {
369
+					readen = fdread_ex(r->sock, buf, FRAME_PACKET_SIZE, UDP_READ_TIMEOUT, UDP_READ_RETRIES, 0);
370
+				} else {
371
+					readen = fdread_ex(r->sock, buffer, FRAME_PACKET_SIZE + RTP_HEADER_SIZE, UDP_READ_TIMEOUT, UDP_READ_RETRIES, 0);
372
+					if (readen > RTP_HEADER_SIZE)
373
+						readen -= RTP_HEADER_SIZE;
374
+				}
367 375
 			}
368 376
 
369 377
 			if (readen < 0)

+ 1 - 0
mptsd_channels.conf View File

@@ -10,6 +10,7 @@ source1		= http://signal-server/stb/btv.mpg
10 10
 #source2		= http://signal-server2/stb/btv.mpg
11 11
 #source3		= http://signal-server3/stb/btv.mpg
12 12
 #source4		= udp://239.0.0.1:5000/
13
+#source5        = rtp://239.78.78.2:5000/
13 14
 #worktime	= 14:18-14:19
14 15
 
15 16
 [Channel2]