Browse Source

Add init() functions in addition to alloc_init() functions.

Georgi Chorbadzhiyski 8 years ago
parent
commit
968352d1ec
6 changed files with 55 additions and 13 deletions
  1. 11 3
      eit_desc.c
  2. 10 3
      nit_desc.c
  3. 10 3
      pat_desc.c
  4. 10 3
      sdt_desc.c
  5. 8 0
      tdt_desc.c
  6. 6 1
      tsfuncs.h

+ 11 - 3
eit_desc.c View File

@@ -22,9 +22,7 @@ static void ts_eit_regenerate_packet_data(struct ts_eit *eit) {
22 22
 	free(ts_packets);
23 23
 }
24 24
 
25
-struct ts_eit *ts_eit_alloc_init(uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t table_id, uint8_t sec_number, uint8_t last_sec_number) {
26
-	struct ts_eit *eit = ts_eit_alloc();
27
-
25
+struct ts_eit *ts_eit_init(struct ts_eit *eit, uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t table_id, uint8_t sec_number, uint8_t last_sec_number) {
28 26
 	eit->ts_header.pid            = 0x12;
29 27
 	eit->ts_header.pusi           = 1;
30 28
 	eit->ts_header.payload_field  = 1;
@@ -48,6 +46,8 @@ struct ts_eit *ts_eit_alloc_init(uint16_t service_id, uint16_t transport_stream_
48 46
 	eit->segment_last_section_number = 0;						// 8 bits
49 47
 	eit->last_table_id               = table_id;				// 8 bits
50 48
 
49
+	eit->streams_num = 0;
50
+
51 51
 	eit->initialized = 1;
52 52
 
53 53
 	ts_eit_regenerate_packet_data(eit);
@@ -55,6 +55,14 @@ struct ts_eit *ts_eit_alloc_init(uint16_t service_id, uint16_t transport_stream_
55 55
 	return eit;
56 56
 }
57 57
 
58
+struct ts_eit *ts_eit_alloc_init(uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t table_id, uint8_t sec_number, uint8_t last_sec_number) {
59
+	struct ts_eit *eit = ts_eit_alloc();
60
+	if (!eit)
61
+		return NULL;
62
+
63
+	return ts_eit_init(eit, service_id, transport_stream_id, org_network_id, table_id, sec_number, last_sec_number);
64
+}
65
+
58 66
 struct ts_eit *ts_eit_alloc_init_pf(uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t sec_number, uint8_t last_sec_number) {
59 67
 	return ts_eit_alloc_init(service_id, transport_stream_id, org_network_id, 0x4e, sec_number, last_sec_number);
60 68
 }

+ 10 - 3
nit_desc.c View File

@@ -22,9 +22,7 @@ static void ts_nit_regenerate_packet_data(struct ts_nit *nit) {
22 22
 	free(ts_packets);
23 23
 }
24 24
 
25
-struct ts_nit *ts_nit_alloc_init(uint16_t network_id) {
26
-	struct ts_nit *nit = ts_nit_alloc();
27
-
25
+struct ts_nit *ts_nit_init(struct ts_nit *nit, uint16_t network_id) {
28 26
 	nit->ts_header.pid            = 0x10;
29 27
 	nit->ts_header.pusi           = 1;
30 28
 	nit->ts_header.payload_field  = 1;
@@ -45,6 +43,8 @@ struct ts_nit *ts_nit_alloc_init(uint16_t network_id) {
45 43
 	nit->reserved2           = 0xf;
46 44
 	nit->ts_loop_size        = 0;		// 16 bits
47 45
 
46
+	nit->streams_num = 0;
47
+
48 48
 	nit->initialized = 1;
49 49
 
50 50
 	ts_nit_regenerate_packet_data(nit);
@@ -52,6 +52,13 @@ struct ts_nit *ts_nit_alloc_init(uint16_t network_id) {
52 52
 	return nit;
53 53
 }
54 54
 
55
+struct ts_nit *ts_nit_alloc_init(uint16_t network_id) {
56
+	struct ts_nit *nit = ts_nit_alloc();
57
+	if (!nit)
58
+		return NULL;
59
+	return ts_nit_init(nit, network_id);
60
+}
61
+
55 62
 int ts_nit_add_network_name_descriptor(struct ts_nit *nit, char *network_name) {
56 63
 	if (!network_name || strlen(network_name) > 255)
57 64
 		return 0;

+ 10 - 3
pat_desc.c View File

@@ -22,9 +22,7 @@ static void ts_pat_regenerate_packet_data(struct ts_pat *pat) {
22 22
 	free(ts_packets);
23 23
 }
24 24
 
25
-struct ts_pat *ts_pat_alloc_init(uint16_t transport_stream_id) {
26
-	struct ts_pat *pat = ts_pat_alloc();
27
-
25
+struct ts_pat *ts_pat_init(struct ts_pat *pat, uint16_t transport_stream_id) {
28 26
 	pat->ts_header.pid            = 0x00;
29 27
 	pat->ts_header.pusi           = 1;
30 28
 	pat->ts_header.payload_field  = 1;
@@ -41,6 +39,8 @@ struct ts_pat *ts_pat_alloc_init(uint16_t transport_stream_id) {
41 39
 
42 40
 	pat->section_header->ts_id_number             = transport_stream_id;
43 41
 
42
+	pat->programs_num = 0;
43
+
44 44
 	pat->initialized = 1;
45 45
 
46 46
 	ts_pat_regenerate_packet_data(pat);
@@ -48,6 +48,13 @@ struct ts_pat *ts_pat_alloc_init(uint16_t transport_stream_id) {
48 48
 	return pat;
49 49
 }
50 50
 
51
+struct ts_pat *ts_pat_alloc_init(uint16_t transport_stream_id) {
52
+	struct ts_pat *pat = ts_pat_alloc();
53
+	if (!pat)
54
+		return NULL;
55
+	return ts_pat_init(pat, transport_stream_id);
56
+}
57
+
51 58
 int ts_pat_add_program(struct ts_pat *pat, uint16_t program, uint16_t pat_pid) {
52 59
 	int i;
53 60
 	if (pat->programs_max == pat->programs_num)

+ 10 - 3
sdt_desc.c View File

@@ -22,9 +22,7 @@ static void ts_sdt_regenerate_packet_data(struct ts_sdt *sdt) {
22 22
 	free(ts_packets);
23 23
 }
24 24
 
25
-struct ts_sdt *ts_sdt_alloc_init(uint16_t org_network_id, uint16_t transport_stream_id) {
26
-	struct ts_sdt *sdt = ts_sdt_alloc();
27
-
25
+struct ts_sdt *ts_sdt_init(struct ts_sdt *sdt, uint16_t org_network_id, uint16_t transport_stream_id) {
28 26
 	sdt->ts_header.pid            = 0x11;
29 27
 	sdt->ts_header.pusi           = 1;
30 28
 	sdt->ts_header.payload_field  = 1;
@@ -43,6 +41,8 @@ struct ts_sdt *ts_sdt_alloc_init(uint16_t org_network_id, uint16_t transport_str
43 41
 	sdt->original_network_id = org_network_id;	// 16 bits
44 42
 	sdt->reserved            = 0xff;			// 8 bits
45 43
 
44
+	sdt->streams_num = 0;
45
+
46 46
 	sdt->initialized = 1;
47 47
 
48 48
 	ts_sdt_regenerate_packet_data(sdt);
@@ -50,6 +50,13 @@ struct ts_sdt *ts_sdt_alloc_init(uint16_t org_network_id, uint16_t transport_str
50 50
 	return sdt;
51 51
 }
52 52
 
53
+struct ts_sdt *ts_sdt_alloc_init(uint16_t org_network_id, uint16_t transport_stream_id) {
54
+	struct ts_sdt *sdt = ts_sdt_alloc();
55
+	if (!sdt)
56
+		return NULL;
57
+	return ts_sdt_init(sdt, org_network_id, transport_stream_id);
58
+}
59
+
53 60
 static int ts_sdt_add_stream(struct ts_sdt *sdt, uint16_t service_id, uint8_t *desc, uint8_t desc_size) {
54 61
 	if (sdt->streams_num == sdt->streams_max - 1 || desc_size == 0) {
55 62
 		FREE(desc);

+ 8 - 0
tdt_desc.c View File

@@ -51,6 +51,14 @@ static struct ts_tdt *ts_tdt_init_empty(struct ts_tdt *tdt, time_t ts, int tot)
51 51
 	return tdt;
52 52
 }
53 53
 
54
+struct ts_tdt *ts_tdt_init(struct ts_tdt *tdt, time_t ts) {
55
+	return ts_tdt_init_empty(tdt, ts, 0);
56
+}
57
+
58
+struct ts_tdt *ts_tot_init(struct ts_tdt *tot, time_t ts) {
59
+	return ts_tdt_init_empty(tot, ts, 1);
60
+}
61
+
54 62
 struct ts_tdt *ts_tdt_alloc_init(time_t ts) {
55 63
 	return ts_tdt_init_empty(ts_tdt_alloc(), ts, 0);
56 64
 }

+ 6 - 1
tsfuncs.h View File

@@ -137,6 +137,7 @@ void						ts_section_data_gen_ts_packets	(struct ts_header *ts_header, uint8_t *
137 137
 
138 138
 // PAT
139 139
 struct ts_pat *	ts_pat_alloc		(void);
140
+struct ts_pat * ts_pat_init			(struct ts_pat *pat, uint16_t transport_stream_id);
140 141
 struct ts_pat * ts_pat_alloc_init	(uint16_t transport_stream_id);
141 142
 struct ts_pat *	ts_pat_push_packet	(struct ts_pat *pat, uint8_t *ts_packet);
142 143
 void            ts_pat_clear		(struct ts_pat *pat);
@@ -177,7 +178,6 @@ int				ts_get_ecm_info_by_pid	(struct ts_pmt *pmt, uint16_t *caid, uint16_t ca_p
177 178
 
178 179
 // PMT
179 180
 struct ts_pmt *	ts_pmt_alloc		(void);
180
-struct ts_pmt * ts_pmt_alloc_init	(uint16_t org_network_id, uint16_t transport_stream_id);
181 181
 struct ts_pmt *	ts_pmt_push_packet	(struct ts_pmt *pmt, uint8_t *ts_packet);
182 182
 void            ts_pmt_clear		(struct ts_pmt *pmt);
183 183
 void            ts_pmt_free			(struct ts_pmt **pmt);
@@ -192,6 +192,7 @@ int				ts_pmt_is_same		(struct ts_pmt *pmt1, struct ts_pmt *pmt2);
192 192
 
193 193
 // NIT
194 194
 struct ts_nit * ts_nit_alloc		(void);
195
+struct ts_nit * ts_nit_init			(struct ts_nit *nit, uint16_t network_id);
195 196
 struct ts_nit * ts_nit_alloc_init	(uint16_t network_id);
196 197
 struct ts_nit *	ts_nit_push_packet	(struct ts_nit *nit, uint8_t *ts_packet);
197 198
 void			ts_nit_clear		(struct ts_nit *nit);
@@ -210,6 +211,7 @@ int				ts_nit_is_same		(struct ts_nit *nit1, struct ts_nit *nit2);
210 211
 
211 212
 // SDT
212 213
 struct ts_sdt *	ts_sdt_alloc		(void);
214
+struct ts_sdt * ts_sdt_init			(struct ts_sdt *sdt, uint16_t org_network_id, uint16_t transport_stream_id);
213 215
 struct ts_sdt * ts_sdt_alloc_init	(uint16_t org_network_id, uint16_t transport_stream_id);
214 216
 struct ts_sdt *	ts_sdt_push_packet	(struct ts_sdt *sdt, uint8_t *ts_packet);
215 217
 void            ts_sdt_clear		(struct ts_sdt *sdt);
@@ -225,6 +227,7 @@ int				ts_sdt_is_same		(struct ts_sdt *sdt1, struct ts_sdt *sdt2);
225 227
 
226 228
 // EIT
227 229
 struct ts_eit * ts_eit_alloc				(void);
230
+struct ts_eit *	ts_eit_init					(struct ts_eit *eit, uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t table_id, uint8_t sec_number, uint8_t last_sec_number);
228 231
 struct ts_eit *	ts_eit_alloc_init			(uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t table_id, uint8_t sec_number, uint8_t last_sec_number);
229 232
 struct ts_eit *	ts_eit_alloc_init_pf		(uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t sec_number, uint8_t last_sec_number);	// Shortcut using table_id 0x4e
230 233
 struct ts_eit *	ts_eit_alloc_init_schedule	(uint16_t service_id, uint16_t transport_stream_id, uint16_t org_network_id, uint8_t sec_number, uint8_t last_sec_number);	// Shortcut using table_id 0x50
@@ -247,6 +250,8 @@ int				ts_eit_is_same		(struct ts_eit *eit1, struct ts_eit *eit2);
247 250
 
248 251
 // TDT
249 252
 struct ts_tdt *	ts_tdt_alloc(void);
253
+struct ts_tdt *	ts_tdt_init			(struct ts_tdt *tdt, time_t ts);
254
+struct ts_tdt *	ts_tot_init			(struct ts_tdt *tot, time_t ts);
250 255
 struct ts_tdt *	ts_tdt_alloc_init	(time_t ts);
251 256
 struct ts_tdt *	ts_tot_alloc_init	(time_t ts);
252 257
 void			ts_tdt_clear		(struct ts_tdt *tdt);