Browse Source

Add support for ts_privsec

Georgi Chorbadzhiyski 9 years ago
parent
commit
3a92b6face
4 changed files with 79 additions and 1 deletions
  1. 2
    1
      Makefile
  2. 6
    0
      tsdata.h
  3. 7
    0
      tsfuncs.h
  4. 64
    0
      tsfuncs_privsec.c

+ 2
- 1
Makefile View File

@@ -16,7 +16,8 @@ OBJS = log.o tsfuncs.o tsfuncs_crc.o tsfuncs_misc.o tsfuncs_time.o \
16 16
 	tsfuncs_eit.o tsfuncs_eit_desc.o \
17 17
 	tsfuncs_tdt.o tsfuncs_tdt_desc.o \
18 18
 	tsfuncs_pes.o tsfuncs_pes_data.o \
19
-	tsfuncs_pes_es.o
19
+	tsfuncs_pes_es.o \
20
+	tsfuncs_privsec.o
20 21
 PROG = libts.a
21 22
 
22 23
 tstest_OBJS = tstest.o libts.a

+ 6
- 0
tsdata.h View File

@@ -245,6 +245,12 @@ struct ts_tdt {
245 245
 	uint8_t		initialized;
246 246
 };
247 247
 
248
+struct ts_privsec {
249
+	struct ts_header			ts_header;
250
+	struct ts_section_header	*section_header;
251
+	uint8_t						initialized;
252
+};
253
+
248 254
 // PMT stream types
249 255
 enum ts_stream_type {
250 256
 	STREAM_TYPE_MPEG1_VIDEO			= 0x01, // MPEG-1 video

+ 7
- 0
tsfuncs.h View File

@@ -197,6 +197,13 @@ void			ts_tdt_set_time		(struct ts_tdt *tdt, time_t ts);
197 197
 void			ts_tot_set_localtime_offset			(struct ts_tdt *tdt, time_t now, time_t change_time, uint8_t polarity, uint16_t ofs, uint16_t ofs_next);
198 198
 void			ts_tot_set_localtime_offset_sofia	(struct ts_tdt *tdt, time_t now);
199 199
 
200
+// Private section
201
+struct ts_privsec *	ts_privsec_alloc();
202
+void				ts_privsec_free			(struct ts_privsec **pprivsec);
203
+
204
+struct ts_privsec *	ts_privsec_push_packet	(struct ts_privsec *privsec, uint8_t *ts_packet);
205
+void				ts_privsec_dump			(struct ts_privsec *privsec);
206
+
200 207
 // Time
201 208
 uint32_t		ts_time_encode_bcd	(int duration_sec);
202 209
 void			ts_time_decode_bcd	(int duration_bcd, int *duration_sec, int *hour, int *min, int *sec);

+ 64
- 0
tsfuncs_privsec.c View File

@@ -0,0 +1,64 @@
1
+#include <stdio.h>
2
+#include <unistd.h>
3
+#include <netdb.h>
4
+#include <stdlib.h>
5
+#include <string.h>
6
+#include <time.h>
7
+
8
+#include "tsfuncs.h"
9
+
10
+struct ts_privsec *ts_privsec_alloc() {
11
+	struct ts_privsec *privsec = calloc(1, sizeof(struct ts_privsec));
12
+	privsec->section_header	= ts_section_data_alloc();
13
+	return privsec;
14
+}
15
+
16
+void ts_privsec_free(struct ts_privsec **pprivsec) {
17
+	struct ts_privsec *privsec = *pprivsec;
18
+	if (privsec) {
19
+		ts_section_data_free(&privsec->section_header);
20
+		FREE(*pprivsec);
21
+	}
22
+}
23
+
24
+struct ts_privsec *ts_privsec_push_packet(struct ts_privsec *privsec, uint8_t *ts_packet) {
25
+	struct ts_header ts_header;
26
+	memset(&ts_header, 0, sizeof(struct ts_header));
27
+
28
+	if (ts_packet_header_parse(ts_packet, &ts_header)) {
29
+		if (!privsec->ts_header.pusi)
30
+			privsec->ts_header = ts_header;
31
+	}
32
+
33
+	if (ts_header.pusi) {
34
+		struct ts_section_header section_header;
35
+		memset(&section_header, 0, sizeof(struct ts_section_header));
36
+
37
+		uint8_t *section_data = ts_section_header_parse(ts_packet, &privsec->ts_header, &section_header);
38
+		if (!section_data) {
39
+			memset(&privsec->ts_header, 0, sizeof(struct ts_header));
40
+			goto OUT;
41
+		}
42
+
43
+		// Set correct section_header
44
+		ts_section_header_parse(ts_packet, &privsec->ts_header, privsec->section_header);
45
+	}
46
+
47
+	if (!privsec->initialized) {
48
+		ts_section_add_packet(privsec->section_header, &ts_header, ts_packet);
49
+		if (privsec->section_header->initialized) {
50
+			privsec->initialized = 1;
51
+		}
52
+	}
53
+
54
+OUT:
55
+	return privsec;
56
+}
57
+
58
+void ts_privsec_dump(struct ts_privsec *privsec) {
59
+	struct ts_section_header *sec = privsec->section_header;
60
+	ts_section_dump(sec);
61
+	char *data = ts_hex_dump(sec->data, sec->data_len, 16);
62
+	ts_LOGf("  * Section data:\n%s\n", data);
63
+	FREE(data);
64
+}

Loading…
Cancel
Save