Browse Source

Add support for LCN.

Georgi Makedonski 10 years ago
parent
commit
e38fb3bd29
12 changed files with 309 additions and 48 deletions
  1. 1
    1
      Makefile
  2. 32
    5
      config.c
  3. 17
    6
      config.h
  4. 3
    1
      data.c
  5. 4
    1
      data.h
  6. 1
    1
      input.c
  7. 4
    1
      mptsd.c
  8. 22
    0
      mptsd_channels.conf
  9. 0
    6
      mptsd_nit.conf
  10. 50
    26
      output_psi.c
  11. 143
    0
      udp_server.c
  12. 32
    0
      udp_server.h

+ 1
- 1
Makefile View File

26
 	sleep.o network.o \
26
 	sleep.o network.o \
27
 	input.o \
27
 	input.o \
28
 	output_psi.o output_mix.o output_write.o \
28
 	output_psi.o output_mix.o output_write.o \
29
-	web_pages.o web_server.o \
29
+	web_pages.o web_server.o udp_server.o\
30
 	mptsd.o
30
 	mptsd.o
31
 
31
 
32
 PROGS = mptsd
32
 PROGS = mptsd

+ 32
- 5
config.c View File

110
 	// Parse channels file
110
 	// Parse channels file
111
 	conf->provider_name = ini_get_string_copy(ini, NULL, "Global:provider_name");
111
 	conf->provider_name = ini_get_string_copy(ini, NULL, "Global:provider_name");
112
 	conf->transport_stream_id = ini_get_int(ini, 0, "Global:transport_stream_id");
112
 	conf->transport_stream_id = ini_get_int(ini, 0, "Global:transport_stream_id");
113
+	conf->frequency = ini_get_string_copy(ini, NULL, "Global:frequency");
114
+	conf->modulation = ini_get_string_copy(ini, NULL, "Global:modulation");
115
+	conf->symbol_rate = ini_get_string_copy(ini, NULL, "Global:symbol_rate");
116
+
117
+//	conf->epg_source = ini_get_string(ini, NULL, "EPG:source");
118
+
119
+
120
+
113
 	for (i=1;i<32;i++) {
121
 	for (i=1;i<32;i++) {
114
 		CHANNEL *channel = NULL;
122
 		CHANNEL *channel = NULL;
115
 		int service_id = ini_get_int(ini, 0, "Channel%d:service_id", i);
123
 		int service_id = ini_get_int(ini, 0, "Channel%d:service_id", i);
117
 			continue;
125
 			continue;
118
 
126
 
119
 		int is_radio = ini_get_bool(ini, 0, "Channel%d:radio", i);
127
 		int is_radio = ini_get_bool(ini, 0, "Channel%d:radio", i);
128
+		int lcn = ini_get_int(ini, 0, "Channel%d:lcn", i);
129
+		int is_lcn_visible = ini_get_bool(ini, 0, "Channel%d:lcn_visible", i);
130
+
120
 
131
 
121
 		char *id = ini_get_string(ini, NULL, "Channel%d:id", i);
132
 		char *id = ini_get_string(ini, NULL, "Channel%d:id", i);
122
 		if (!id) {
133
 		if (!id) {
142
 				}
153
 				}
143
 				// Init channel
154
 				// Init channel
144
 				if (channel == NULL) {
155
 				if (channel == NULL) {
145
-					channel = channel_new(service_id, is_radio, id, name, source);
156
+					channel = channel_new(service_id, is_radio, id, name, source, lcn, is_lcn_visible);
146
 				} else {
157
 				} else {
147
 					chansrc_add(channel, source);
158
 					chansrc_add(channel, source);
148
 				}
159
 				}
222
 		if (r->cookie != cookie) {
233
 		if (r->cookie != cookie) {
223
 			proxy_log(r, "Remove");
234
 			proxy_log(r, "Remove");
224
 			/* Replace channel reference with real object and instruct free_restreamer to free it */
235
 			/* Replace channel reference with real object and instruct free_restreamer to free it */
225
-			r->channel = channel_new(r->channel->service_id, r->channel->radio, r->channel->id, r->channel->name, r->channel->source);
236
+			r->channel = channel_new(r->channel->service_id, r->channel->radio, r->channel->id, r->channel->name, r->channel->source, r->channel->lcn, r->channel->lcn_visible);
226
 			r->freechannel = 1;
237
 			r->freechannel = 1;
227
 			r->dienow = 1;
238
 			r->dienow = 1;
228
 		}
239
 		}
243
 		LOGf("CONFIG: Error loading global config (%s)\n", conf->global_conf);
254
 		LOGf("CONFIG: Error loading global config (%s)\n", conf->global_conf);
244
 		return 0;
255
 		return 0;
245
 	}
256
 	}
246
-	conf->network_id		= ini_get_int(ini, 0,    "Global:network_id");
257
+	conf->network_id				= ini_get_int(ini, 0,    "Global:network_id");
247
 	conf->timeouts.pat		= ini_get_int(ini, 100,  "Timeouts:pat");
258
 	conf->timeouts.pat		= ini_get_int(ini, 100,  "Timeouts:pat");
248
 	conf->timeouts.pmt		= ini_get_int(ini, 200,  "Timeouts:pmt");
259
 	conf->timeouts.pmt		= ini_get_int(ini, 200,  "Timeouts:pmt");
249
 	conf->timeouts.sdt		= ini_get_int(ini, 500,  "Timeouts:sdt");
260
 	conf->timeouts.sdt		= ini_get_int(ini, 500,  "Timeouts:sdt");
413
 	puts("Server settings:");
424
 	puts("Server settings:");
414
 	puts("\t-b addr\t\tLocal IP address to bind.   (default: 0.0.0.0)");
425
 	puts("\t-b addr\t\tLocal IP address to bind.   (default: 0.0.0.0)");
415
 	puts("\t-p port\t\tPort to listen.             (default: 0)");
426
 	puts("\t-p port\t\tPort to listen.             (default: 0)");
427
+	puts("UDP Server settings:");
428
+	puts("\t-s addr\t\tLocal IP address to bind.   (default: 0.0.0.0)");
429
+	puts("\t-u port\t\tPort to listen.             (default: 2000)");
430
+
416
 	puts("\t-d pidfile\tDaemonize with pidfile");
431
 	puts("\t-d pidfile\tDaemonize with pidfile");
417
 	puts("\t-l host\t\tSyslog host                 (default: disabled)");
432
 	puts("\t-l host\t\tSyslog host                 (default: disabled)");
418
 	puts("\t-L port\t\tSyslog port                 (default: 514)");
433
 	puts("\t-L port\t\tSyslog port                 (default: 514)");
454
 	conf->logport = 514;
469
 	conf->logport = 514;
455
 	conf->server_port = 0;
470
 	conf->server_port = 0;
456
 	conf->server_socket = -1;
471
 	conf->server_socket = -1;
472
+	conf->udp_server_port = 2000;
473
+	conf->udp_server_socket = -1;
457
 
474
 
458
-	while ((j = getopt(argc, argv, "i:b:p:g:c:n:e:d:t:o:O:P:l:L:B:m:qDHhWE")) != -1) {
475
+	while ((j = getopt(argc, argv, "i:b:p:s:u:g:c:n:e:d:t:o:O:P:l:L:B:m:qDHhWE")) != -1) {
459
 		switch (j) {
476
 		switch (j) {
460
 			case 'i':
477
 			case 'i':
461
 				conf->ident = strdup(optarg);
478
 				conf->ident = strdup(optarg);
473
 			case 'p':
490
 			case 'p':
474
 				conf->server_port = atoi(optarg);
491
 				conf->server_port = atoi(optarg);
475
 				break;
492
 				break;
493
+			case 's':
494
+				conf->udp_server_addr = strdup(optarg);
495
+				break;
496
+			case 'u':
497
+				conf->udp_server_port = atoi(optarg);
498
+				break;
476
 			case 'd':
499
 			case 'd':
477
 				conf->pidfile = strdup(optarg);
500
 				conf->pidfile = strdup(optarg);
478
 				break;
501
 				break;
582
 	if (conf->server_port)
605
 	if (conf->server_port)
583
 		init_server_socket(conf->server_addr, conf->server_port, &conf->server, &conf->server_socket);
606
 		init_server_socket(conf->server_addr, conf->server_port, &conf->server, &conf->server_socket);
584
 
607
 
608
+//	if (conf->udp_server_port)
609
+//		init_server_socket_udp(conf->server_addr, conf->udp_server_port, &conf->server, &conf->udp_server_socket);
610
+
585
 	if (!conf->quiet) {
611
 	if (!conf->quiet) {
586
 		printf("Configuration:\n");
612
 		printf("Configuration:\n");
587
 		printf("\tServer ident      : %s\n", conf->ident);
613
 		printf("\tServer ident      : %s\n", conf->ident);
632
 	if (!config_load_channels(conf))
658
 	if (!config_load_channels(conf))
633
 		goto ERR;
659
 		goto ERR;
634
 
660
 
635
-	config_load_epg(conf);
661
+	if (!config_load_epg(conf))
662
+		LOGf("CONFIG: Run without EIT (%s)\n", conf->epg_conf);
636
 
663
 
637
 	return;
664
 	return;
638
 
665
 

+ 17
- 6
config.h View File

35
 	char			*loghost;
35
 	char			*loghost;
36
 	int				logport;
36
 	int				logport;
37
 
37
 
38
-	struct sockaddr_in	server;
39
-	char				*server_addr;
40
-	int					server_port;
41
-	int					server_socket;
42
-	pthread_t			server_thread;
38
+	struct sockaddr_in		server;
39
+	char			*server_addr;
40
+	int				server_port;
41
+	int				server_socket;
42
+	pthread_t		server_thread;
43
+
44
+	struct sockaddr_in		udp_server;
45
+	char			*udp_server_addr;
46
+	int				udp_server_port;
47
+	int				udp_server_socket;
48
+	pthread_t		udp_server_thread;
43
 
49
 
44
 	int				multicast_ttl;
50
 	int				multicast_ttl;
51
+
45
 	struct in_addr	output_intf;
52
 	struct in_addr	output_intf;
46
 
53
 
47
 	char			*global_conf;
54
 	char			*global_conf;
61
 
68
 
62
 	uint16_t		network_id;			// For NIT && SDT
69
 	uint16_t		network_id;			// For NIT && SDT
63
 	uint16_t		transport_stream_id;// For NIT
70
 	uint16_t		transport_stream_id;// For NIT
71
+	char			*frequency;			// For NIT
72
+	char			*modulation;		// For NIT
73
+	char			*symbol_rate;		// For NIT
74
+
64
 	char 			*network_name;		// For NIT
75
 	char 			*network_name;		// For NIT
65
 	char 			*provider_name;		// For SDT
76
 	char 			*provider_name;		// For SDT
66
 
77
 
94
 void		config_load		(CONFIG *conf, int argc, char **argv);
105
 void		config_load		(CONFIG *conf, int argc, char **argv);
95
 
106
 
96
 int			config_load_global		(CONFIG *conf);
107
 int			config_load_global		(CONFIG *conf);
97
-int			config_load_channels	(CONFIG *conf);
108
+int			config_load_channels		(CONFIG *conf);
98
 int			config_load_nit			(CONFIG *conf);
109
 int			config_load_nit			(CONFIG *conf);
99
 int			config_load_epg			(CONFIG *conf);
110
 int			config_load_epg			(CONFIG *conf);
100
 
111
 

+ 3
- 1
data.c View File

121
 
121
 
122
 
122
 
123
 
123
 
124
-CHANNEL *channel_new(int service_id, int is_radio, char *id, char *name, char *source) {
124
+CHANNEL *channel_new(int service_id, int is_radio, char *id, char *name, char *source, int lcn, int is_lcn_visible) {
125
 	CHANNEL *c = calloc(1, sizeof(CHANNEL));
125
 	CHANNEL *c = calloc(1, sizeof(CHANNEL));
126
 	c->service_id = service_id;
126
 	c->service_id = service_id;
127
 	c->radio = is_radio;
127
 	c->radio = is_radio;
128
+	c->lcn = lcn;
129
+	c->lcn_visible = is_lcn_visible;
128
 	c->base_pid = service_id * 32; // The first pid is saved for PMT
130
 	c->base_pid = service_id * 32; // The first pid is saved for PMT
129
 	c->pmt_pid = c->base_pid; // The first pid is saved for PMT
131
 	c->pmt_pid = c->base_pid; // The first pid is saved for PMT
130
 	c->id = strdup(id);
132
 	c->id = strdup(id);

+ 4
- 1
data.h View File

63
 	int			service_id;
63
 	int			service_id;
64
 	int			pmt_pid;
64
 	int			pmt_pid;
65
 	int			radio;
65
 	int			radio;
66
+	int			lcn;
67
+	int			lcn_visible;
66
 	char *		id;
68
 	char *		id;
67
 	char *		name;
69
 	char *		name;
68
 	/* Sources */
70
 	/* Sources */
219
 void		epg_free		(EPG_ENTRY **e);
221
 void		epg_free		(EPG_ENTRY **e);
220
 int			epg_changed		(EPG_ENTRY *a, EPG_ENTRY *b);
222
 int			epg_changed		(EPG_ENTRY *a, EPG_ENTRY *b);
221
 
223
 
222
-CHANNEL *	channel_new		(int service_id, int is_radio, char *id, char *name, char *source);
224
+CHANNEL *	channel_new		(int service_id, int is_radio, char *id, char *name, char *source, int lcn, int is_lcn_visible);
223
 void		channel_free	(CHANNEL **c);
225
 void		channel_free	(CHANNEL **c);
224
 void		channel_free_epg(CHANNEL *c);
226
 void		channel_free_epg(CHANNEL *c);
225
 
227
 
246
 NIT *		nit_new			(uint16_t ts_id, char *freq, char *modulation, char *symbol_rate);
248
 NIT *		nit_new			(uint16_t ts_id, char *freq, char *modulation, char *symbol_rate);
247
 void		nit_free		(NIT **nit);
249
 void		nit_free		(NIT **nit);
248
 
250
 
251
+
249
 void		proxy_log		(INPUT *r, char *msg);
252
 void		proxy_log		(INPUT *r, char *msg);
250
 void		proxy_close		(LIST *inputs, INPUT **input);
253
 void		proxy_close		(LIST *inputs, INPUT **input);
251
 
254
 

+ 1
- 1
input.c View File

404
 				pid = ts_packet_get_pid(ts_packet);
404
 				pid = ts_packet_get_pid(ts_packet);
405
 				// Kill incomming NIT, SDT, EIT, RST, TDT/TOT
405
 				// Kill incomming NIT, SDT, EIT, RST, TDT/TOT
406
 				if (pid == s->nit_pid || pid == 0x10 || pid == 0x11 || pid == 0x12 || pid == 0x13 || pid == 0x14 || pid == 0x1fff) {
406
 				if (pid == s->nit_pid || pid == 0x10 || pid == 0x11 || pid == 0x12 || pid == 0x13 || pid == 0x14 || pid == 0x1fff) {
407
-					// LOGf("INPUT: %-10s: Remove PID %03x\n", r->channel->id, pid);
407
+				//	 LOGf("INPUT: %-10s: Remove PID %03x\n", r->channel->id, pid);
408
 					continue;
408
 					continue;
409
 				}
409
 				}
410
 
410
 

+ 4
- 1
mptsd.c View File

31
 #include "input.h"
31
 #include "input.h"
32
 #include "output.h"
32
 #include "output.h"
33
 #include "web_server.h"
33
 #include "web_server.h"
34
+#include "udp_server.h"
34
 
35
 
35
 #define PROGRAM_NAME "ux-mptsd"
36
 #define PROGRAM_NAME "ux-mptsd"
36
 
37
 
64
 			INPUT *nr = input_new(c->name, c);
65
 			INPUT *nr = input_new(c->name, c);
65
 			if (nr) {
66
 			if (nr) {
66
 				list_add(conf->inputs, nr);
67
 				list_add(conf->inputs, nr);
67
-//				LOGf("SPAWN : %s thread.\n", c->name);
68
+				LOGf("SPAWN : %s thread.\n", c->name);
68
 				if (pthread_create(&nr->thread, NULL, &input_stream, nr) == 0) {
69
 				if (pthread_create(&nr->thread, NULL, &input_stream, nr) == 0) {
69
 					spawned++;
70
 					spawned++;
70
 					pthread_detach(nr->thread);
71
 					pthread_detach(nr->thread);
156
 
157
 
157
 	daemonize(config->pidfile);
158
 	daemonize(config->pidfile);
158
 	web_server_start(config);
159
 	web_server_start(config);
160
+	udp_server_start(config);
159
 	log_init(config->logident, config->syslog_active, config->pidfile == NULL, config->loghost, config->logport);
161
 	log_init(config->logident, config->syslog_active, config->pidfile == NULL, config->loghost, config->logport);
160
 	init_signals(config);
162
 	init_signals(config);
161
 
163
 
169
 
171
 
170
 	kill_threads(config);
172
 	kill_threads(config);
171
 	web_server_stop(config);
173
 	web_server_stop(config);
174
+	udp_server_stop(config);
172
 
175
 
173
 	LOGf("SHUTDOWN: Signal %d | %s %s (%s)\n", rcvsig, server_sig, server_ver, config->ident);
176
 	LOGf("SHUTDOWN: Signal %d | %s %s (%s)\n", rcvsig, server_sig, server_ver, config->ident);
174
 	config_free(&config);
177
 	config_free(&config);

+ 22
- 0
mptsd_channels.conf View File

1
 [Global]
1
 [Global]
2
 provider_name = Unix Solutions
2
 provider_name = Unix Solutions
3
 transport_stream_id = 1
3
 transport_stream_id = 1
4
+frequency           = 0658,0000
5
+modulation          = 64-QAM
6
+symbol_rate         = 006,8750
7
+
4
 
8
 
5
 [Channel1]
9
 [Channel1]
6
 service_id	= 1
10
 service_id	= 1
12
 #source4		= udp://239.0.0.1:5000/
16
 #source4		= udp://239.0.0.1:5000/
13
 #source5        = rtp://239.78.78.2:5000/
17
 #source5        = rtp://239.78.78.2:5000/
14
 #worktime	= 14:18-14:19
18
 #worktime	= 14:18-14:19
19
+lcn		= 2
20
+lcn_visible	= yes
15
 
21
 
16
 [Channel2]
22
 [Channel2]
17
 service_id	= 2
23
 service_id	= 2
18
 id			= kanal1
24
 id			= kanal1
19
 name		= "Kanal 1"
25
 name		= "Kanal 1"
20
 source		= http://signal-server/stb/kanal1.mpg
26
 source		= http://signal-server/stb/kanal1.mpg
27
+lcn		= 2
28
+lcn_visible	= yes
21
 
29
 
22
 [Channel3]
30
 [Channel3]
23
 service_id	= 3
31
 service_id	= 3
24
 id			= novatv
32
 id			= novatv
25
 name		= "Nova"
33
 name		= "Nova"
26
 source1		= http://signal-server/stb/novatv.mpg
34
 source1		= http://signal-server/stb/novatv.mpg
35
+lcn		= 3
36
+lcn_visible	= yes
27
 
37
 
28
 [Channel4]
38
 [Channel4]
29
 service_id	= 4
39
 service_id	= 4
30
 id			= tv2
40
 id			= tv2
31
 name		= "TV 2"
41
 name		= "TV 2"
32
 source1		= http://signal-server/stb/tv2.mpg
42
 source1		= http://signal-server/stb/tv2.mpg
43
+lcn		= 7
44
+lcn_visible	= no
33
 
45
 
34
 [Channel5]
46
 [Channel5]
35
 service_id	= 5
47
 service_id	= 5
36
 id			= ngc
48
 id			= ngc
37
 name		= "NatGeo"
49
 name		= "NatGeo"
38
 source1		= http://signal-server/stb/ngc.mpg
50
 source1		= http://signal-server/stb/ngc.mpg
51
+lcn		= 72
52
+lcn_visible	= yes
39
 
53
 
40
 [Channel6]
54
 [Channel6]
41
 service_id	= 6
55
 service_id	= 6
42
 id			= tv1
56
 id			= tv1
43
 name		= "TV 1"
57
 name		= "TV 1"
44
 source1		= http://signal-server/stb/tv1.mpg
58
 source1		= http://signal-server/stb/tv1.mpg
59
+lcn		= 25
60
+lcn_visible	= yes
45
 
61
 
46
 [Channel7]
62
 [Channel7]
47
 service_id	= 7
63
 service_id	= 7
48
 id			= planetahit
64
 id			= planetahit
49
 name		= "Planeta HIT"
65
 name		= "Planeta HIT"
50
 source1		= http://signal-server/stb/planetahit.mpg
66
 source1		= http://signal-server/stb/planetahit.mpg
67
+lcn		= 33
68
+lcn_visible	= no
51
 
69
 
52
 [Channel8]
70
 [Channel8]
53
 service_id	= 8
71
 service_id	= 8
55
 name		= "Radio Fresh"
73
 name		= "Radio Fresh"
56
 radio		= yes
74
 radio		= yes
57
 source		= http://signal-server/stb/fresh.mpg
75
 source		= http://signal-server/stb/fresh.mpg
76
+lcn		= 201
77
+lcn_visible	= no
58
 
78
 
59
 [Channel9]
79
 [Channel9]
60
 service_id	= 9
80
 service_id	= 9
62
 name		= "BG Radio"
82
 name		= "BG Radio"
63
 radio		= yes
83
 radio		= yes
64
 source1		= http://signal-server/stb/bgradio.mpg
84
 source1		= http://signal-server/stb/bgradio.mpg
85
+lcn		= 202
86
+lcn_visible	= yes

+ 0
- 6
mptsd_nit.conf View File

1
 [Global]
1
 [Global]
2
 network_name = "Unixsol DVB-C network"
2
 network_name = "Unixsol DVB-C network"
3
 
3
 
4
-[Transponder1]
5
-transport_stream_id = 1
6
-frequency           = 0658,0000
7
-modulation          = 64-QAM
8
-symbol_rate         = 006,8750
9
-
10
 [Transponder2]
4
 [Transponder2]
11
 transport_stream_id = 2
5
 transport_stream_id = 2
12
 frequency           = 0666,0000
6
 frequency           = 0666,0000

+ 50
- 26
output_psi.c View File

29
 
29
 
30
 static void output_psi_init_pat(CONFIG *conf, OUTPUT *o) {
30
 static void output_psi_init_pat(CONFIG *conf, OUTPUT *o) {
31
 	LNODE *lc, *lctmp;
31
 	LNODE *lc, *lctmp;
32
+
32
 	o->pat = ts_pat_alloc_init(conf->transport_stream_id);
33
 	o->pat = ts_pat_alloc_init(conf->transport_stream_id);
33
 	list_lock(conf->channels);
34
 	list_lock(conf->channels);
34
 	list_for_each(conf->channels, lc, lctmp) {
35
 	list_for_each(conf->channels, lc, lctmp) {
44
 
45
 
45
 	ts_nit_add_network_name_descriptor(nit, conf->network_name);
46
 	ts_nit_add_network_name_descriptor(nit, conf->network_name);
46
 
47
 
48
+	int num;
49
+	LNODE *lc, *lctmp;
50
+
51
+	uint32_t *svc_services = malloc(conf->channels->items * sizeof(uint32_t));
52
+	uint32_t *lcn_services = malloc(conf->channels->items * sizeof(uint32_t));
53
+
54
+	num = 0;
55
+
56
+	list_lock(conf->channels);
57
+
58
+	list_for_each(conf->channels, lc, lctmp) {
59
+			CHANNEL *c = lc->data;
60
+			uint32_t srv = 0;
61
+			srv  = (c->service_id &~ 0x00ff) << 24;
62
+			srv |= (c->service_id &~ 0xff00) << 16;
63
+			srv |= (c->lcn_visible ? 0x01 : 0x00 &~ 0xf0 ) << 15;
64
+			srv |= (0X00 &~ 0xf0 ) << 14;
65
+			srv |= (c->lcn &~ 0xc0ff);
66
+			srv |= (c->lcn &~ 0xff00);
67
+			lcn_services[num++] = srv;
68
+	}
69
+
70
+	list_unlock(conf->channels);
71
+
72
+	num = 0;
73
+
74
+	list_lock(conf->channels);
75
+    list_for_each(conf->channels, lc, lctmp) {
76
+             CHANNEL *c = lc->data;
77
+             uint32_t srv = 0;
78
+             srv  = (c->service_id &~ 0x00ff) << 16;
79
+             srv |= (c->service_id &~ 0xff00) << 8;
80
+             srv |= c->radio ? 0x02 : 0x01;
81
+             svc_services[num++] = srv;
82
+    }
83
+
84
+	list_unlock(conf->channels);
85
+
86
+    NIT *ts_ndata = nit_new(conf->transport_stream_id, conf->frequency, conf->modulation, conf->symbol_rate);
87
+
88
+	ts_nit_add_stream_descriptors(nit, ts_ndata->ts_id, conf->network_id, ts_ndata->_freq, ts_ndata->_modulation, ts_ndata->_symbol_rate, lcn_services, svc_services, num);
89
+
47
 	if (conf->nit->items < 64) {
90
 	if (conf->nit->items < 64) {
48
-		int num;
49
-		LNODE *lc, *lctmp;
50
-		uint32_t *freqs = malloc(conf->nit->items * sizeof(uint32_t));
51
-		uint32_t *services = malloc(conf->channels->items * sizeof(uint32_t));
52
-		num = 0;
53
 		list_lock(conf->nit);
91
 		list_lock(conf->nit);
54
-		list_for_each(conf->nit, lc, lctmp) {
55
-			NIT *ndata = lc->data;
56
-			freqs[num++] = ndata->_freq;
57
-		}
58
-		ts_nit_add_frequency_list_descriptor_cable(nit, conf->transport_stream_id, conf->network_id, freqs, num);
59
-		list_for_each(conf->nit, lc, lctmp) {
92
+			list_for_each(conf->nit, lc, lctmp) {
60
 			NIT *ndata = lc->data;
93
 			NIT *ndata = lc->data;
61
 			ts_nit_add_cable_delivery_descriptor(nit, ndata->ts_id, conf->network_id, ndata->_freq, ndata->_modulation, ndata->_symbol_rate);
94
 			ts_nit_add_cable_delivery_descriptor(nit, ndata->ts_id, conf->network_id, ndata->_freq, ndata->_modulation, ndata->_symbol_rate);
62
 		}
95
 		}
96
+
63
 		list_unlock(conf->nit);
97
 		list_unlock(conf->nit);
64
-		num = 0;
65
-		list_lock(conf->channels);
66
-		list_for_each(conf->channels, lc, lctmp) {
67
-			CHANNEL *c = lc->data;
68
-			uint32_t srv = 0;
69
-			srv  = (c->service_id &~ 0x00ff) << 16;
70
-			srv |= (c->service_id &~ 0xff00) << 8;
71
-			srv |= c->radio ? 0x02 : 0x01;
72
-			services[num++] = srv;
73
-		}
74
-		list_unlock(conf->channels);
75
-		ts_nit_add_service_list_descriptor(nit, conf->transport_stream_id, conf->network_id, services, num);
76
-		free(freqs);
77
-		free(services);
98
+
99
+		free(lcn_services);
100
+		free(svc_services);
101
+
78
 	} else {
102
 	} else {
79
 		LOG("CONF  : Too much items in the NIT, maximum is 64! NIT not generated.\n");
103
 		LOG("CONF  : Too much items in the NIT, maximum is 64! NIT not generated.\n");
80
 	}
104
 	}
192
 		o->pid_eit_cont += eit->section_header->num_packets;
216
 		o->pid_eit_cont += eit->section_header->num_packets;
193
 		cbuf_fill(o->psibuf, eit->section_header->packet_data, eit->section_header->num_packets * TS_PACKET_SIZE);
217
 		cbuf_fill(o->psibuf, eit->section_header->packet_data, eit->section_header->num_packets * TS_PACKET_SIZE);
194
 	}
218
 	}
195
-//	ts_eit_dump(eit);
219
+	ts_eit_dump(eit);
196
 }
220
 }
197
 
221
 
198
 static void output_add_eit(CONFIG *conf, OUTPUT *o) {
222
 static void output_add_eit(CONFIG *conf, OUTPUT *o) {

+ 143
- 0
udp_server.c View File

1
+/*
2
+ * mptsd internal web server
3
+ * Copyright (C) 2010-2011 Unix Solutions Ltd.
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License version 2
7
+ * as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
+ * GNU General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17
+ */
18
+#include <stdlib.h>
19
+#include <regex.h>
20
+#include <errno.h>
21
+#include <string.h>
22
+#include <signal.h>
23
+#include <arpa/inet.h>
24
+#include <netinet/in.h>
25
+
26
+#include "libfuncs/libfuncs.h"
27
+
28
+#include "libfuncs/io.h"
29
+#include "libfuncs/log.h"
30
+
31
+#include "libtsfuncs/tsfuncs.h"
32
+
33
+#include "data.h"
34
+#include "config.h"
35
+#include "network.h"
36
+
37
+#include "udp_server.h"
38
+
39
+extern int keep_going;
40
+
41
+#define NEXT_CLIENT { FREE(path); FREE(buf); pthread_exit(0); }
42
+#define SHUTDOWN_CLIENT { FREE(path); FREE(buf); shutdown_fd(&clientsock); pthread_exit(0); }
43
+#define BUFSIZE 1316
44
+
45
+void *udp_server_thread(void *data) {
46
+	CONFIG *conf = data;
47
+
48
+	struct sockaddr_in client;					/* remote address */
49
+	socklen_t clientlen = sizeof(client);		/* length of addresses */
50
+	int clientsock; 							/* #bytes received */
51
+	char buf[FRAME_PACKET_SIZE];				/* receive buffer */
52
+
53
+	while (keep_going) {
54
+
55
+
56
+		clientsock = recvfrom(conf->udp_server_socket,(char*)buf, FRAME_PACKET_SIZE, 0, (struct sockaddr *)&client, &clientlen);
57
+
58
+		if (clientsock < 0) {
59
+			if (conf->udp_server_socket > -1)	// The server_socket is closed on exit, so do not report errors
60
+				LOGf("ERROR : Failed to accept client fd: %i err: %s\n", clientsock, strerror(errno));
61
+			if (errno==EMFILE || errno==ENFILE)
62
+				break;
63
+		} else {
64
+
65
+		//	LOGf("received %d bytes from %s with port %d \n", clientsock, inet_ntoa(client.sin_addr), ntohs( client.sin_port ) );
66
+
67
+		// TODO  Process buffer and add to output_mix
68
+
69
+		}
70
+
71
+	}
72
+
73
+	pthread_exit(0);
74
+
75
+
76
+}
77
+
78
+void udp_server_start(CONFIG *conf) {
79
+	if (conf->udp_server_port)
80
+		udp_server_init(conf->udp_server_addr, conf->udp_server_port, &conf->udp_server, &conf->udp_server_socket);
81
+
82
+	if (conf->udp_server_socket > -1) {
83
+		LOG("UDP_SERVER: Started \n");
84
+		pthread_create(&conf->udp_server_thread, NULL, &udp_server_thread, conf);
85
+		}
86
+}
87
+
88
+void udp_server_stop(CONFIG *conf) {
89
+	if (conf->udp_server_socket > -1) {
90
+		shutdown_fd(&conf->udp_server_socket);
91
+		pthread_join(conf->udp_server_thread, NULL);
92
+	}
93
+}
94
+
95
+
96
+void udp_server_init(char *bind_addr, int bind_port, struct sockaddr_in *server, int *server_socket) {
97
+
98
+	LOG("UDP_SERVER: Init.\n");
99
+
100
+	char *binded;
101
+
102
+	struct hostent *host_ptr;
103
+	*server_socket = socket(PF_INET, SOCK_DGRAM, 0);
104
+
105
+	if (*server_socket == -1) {
106
+		perror("socket(server_socket)");
107
+		exit(1);
108
+	}
109
+
110
+	int j = 1;
111
+	if (setsockopt(*server_socket, SOL_SOCKET, SO_REUSEADDR,(const char *) &j, sizeof(j))<0) {
112
+		perror("setsockopt(SO_REUSEADDR)");
113
+		exit(1);
114
+	}
115
+
116
+	memset(server, 0, sizeof(struct sockaddr_in));
117
+	if (!bind_addr) {
118
+		binded = "*";
119
+		server->sin_addr.s_addr = htonl(INADDR_ANY);
120
+	} else {
121
+		host_ptr = gethostbyname(bind_addr);
122
+		if (!host_ptr) {
123
+			fprintf(stderr,"Error can't resolve bind address: %s\n", bind_addr);
124
+			exit(1);
125
+		}
126
+		memcpy(&server->sin_addr, host_ptr->h_addr, sizeof(server->sin_addr));
127
+		binded = inet_ntoa(server->sin_addr);
128
+	}
129
+
130
+	/* Bind to server socket */
131
+	LOGf ("UDP_SERVER: Bind to : %s:%i\n", binded, bind_port);
132
+
133
+	server->sin_family = AF_INET;
134
+	server->sin_port   = htons(bind_port);
135
+
136
+	if (bind(*server_socket, (struct sockaddr *)server, sizeof(struct sockaddr_in)) < 0) {
137
+		perror("bind(server_socket)");
138
+		exit(1);
139
+	}
140
+
141
+	LOG("UDP_SERVER: UDP server Initialized.\n");
142
+
143
+}

+ 32
- 0
udp_server.h View File

1
+/*
2
+ * mptsd internal web server header file
3
+ * Copyright (C) 2010-2011 Unix Solutions Ltd.
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License version 2
7
+ * as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
+ * GNU General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17
+ */
18
+#ifndef UDP_SERVER_H
19
+#define UDP_SERVER_H
20
+
21
+#include "config.h"
22
+
23
+void udp_server_start(CONFIG *conf);
24
+void udp_server_init(char *bind_addr, int bind_port, struct sockaddr_in *server, int *server_socket);
25
+void udp_server_stop(CONFIG *conf);
26
+
27
+
28
+
29
+
30
+
31
+
32
+#endif

Loading…
Cancel
Save