Skip to contentSkip to conversation

libdvbv5: move table parsers to separate directory

PATCH New André Roth 1 participant 4 messages Apr 15, 2014 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 libdvbv5: move table parsers to separate directory

move the dvb table parsers from the descriptors/ directory to tables/ to have a nice and clear separation.

---
 lib/libdvbv5/Makefile.am                        | 42 ++++++++++++-------------
 lib/libdvbv5/{descriptors => tables}/atsc_eit.c |  0
 lib/libdvbv5/{descriptors => tables}/cat.c      |  0
 lib/libdvbv5/{descriptors => tables}/eit.c      |  0
 lib/libdvbv5/{descriptors => tables}/header.c   |  0
 lib/libdvbv5/{descriptors => tables}/mgt.c      |  0
 lib/libdvbv5/{descriptors => tables}/mpeg_es.c  |  0
 lib/libdvbv5/{descriptors => tables}/mpeg_pes.c |  0
 lib/libdvbv5/{descriptors => tables}/mpeg_ts.c  |  0
 lib/libdvbv5/{descriptors => tables}/nit.c      |  0
 lib/libdvbv5/{descriptors => tables}/pat.c      |  0
 lib/libdvbv5/{descriptors => tables}/pmt.c      |  0
 lib/libdvbv5/{descriptors => tables}/sdt.c      |  0
 lib/libdvbv5/{descriptors => tables}/vct.c      |  0
 14 files changed, 21 insertions(+), 21 deletions(-)
 rename lib/libdvbv5/{descriptors => tables}/atsc_eit.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/cat.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/eit.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/header.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/mgt.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/mpeg_es.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/mpeg_pes.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/mpeg_ts.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/nit.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/pat.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/pmt.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/sdt.c (100%)
 rename lib/libdvbv5/{descriptors => tables}/vct.c (100%)
lib/libdvbv5/Makefile.am +21 -21
index ce3f806..515adc3 100644
@@ -63,27 +63,30 @@ libdvbv5_la_SOURCES = \
 	parse_string.c	 \
 	dvb-demux.c	 \
 	dvb-fe.c	 \
-	dvb-log.c	\
-	dvb-file.c	\
-	dvb-v5-std.c	\
-	dvb-sat.c	\
-	dvb-scan.c	\
-	descriptors.c	\
-	descriptors/header.c		\
-	descriptors/pat.c		\
-	descriptors/pmt.c		\
-	descriptors/nit.c		\
-	descriptors/sdt.c		\
-	descriptors/vct.c		\
-	descriptors/mgt.c		\
-	descriptors/eit.c		\
-	descriptors/cat.c		\
-	descriptors/atsc_eit.c		\
+	dvb-log.c	 \
+	dvb-file.c	 \
+	dvb-v5-std.c	 \
+	dvb-sat.c	 \
+	dvb-scan.c	 \
+	descriptors.c	 \
+	tables/header.c		\
+	tables/pat.c		\
+	tables/pmt.c		\
+	tables/nit.c		\
+	tables/sdt.c		\
+	tables/vct.c		\
+	tables/mgt.c		\
+	tables/eit.c		\
+	tables/cat.c		\
+	tables/atsc_eit.c	\
+	tables/mpeg_ts.c	\
+	tables/mpeg_pes.c	\
+	tables/mpeg_es.c	\
 	descriptors/desc_language.c		\
 	descriptors/desc_network_name.c		\
 	descriptors/desc_cable_delivery.c	\
 	descriptors/desc_sat.c			\
-	descriptors/desc_terrestrial_delivery.c  \
+	descriptors/desc_terrestrial_delivery.c \
 	descriptors/desc_t2_delivery.c		\
 	descriptors/desc_service.c		\
 	descriptors/desc_frequency_list.c	\
@@ -99,10 +102,7 @@ libdvbv5_la_SOURCES = \
 	descriptors/desc_partial_reception.c	\
 	descriptors/desc_service_location.c	\
 	descriptors/desc_ca.c			\
-	descriptors/desc_ca_identifier.c	\
-	descriptors/mpeg_ts.c			\
-	descriptors/mpeg_pes.c			\
-	descriptors/mpeg_es.c
+	descriptors/desc_ca_identifier.c
 
 libdvbv5_la_CPPFLAGS = -I../.. $(ENFORCE_LIBDVBV5_STATIC)
 libdvbv5_la_LDFLAGS = $(LIBDVBV5_VERSION) $(ENFORCE_LIBDVBV5_STATIC) -lm
lib/libdvbv5/tables/atsc_eit.c renamed from lib/libdvbv5/descriptors/atsc_eit.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/atsc_eit.c
rename to lib/libdvbv5/tables/atsc_eit.c
lib/libdvbv5/tables/cat.c renamed from lib/libdvbv5/descriptors/cat.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/cat.c
rename to lib/libdvbv5/tables/cat.c
lib/libdvbv5/tables/eit.c renamed from lib/libdvbv5/descriptors/eit.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/eit.c
rename to lib/libdvbv5/tables/eit.c
lib/libdvbv5/tables/header.c renamed from lib/libdvbv5/descriptors/header.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/header.c
rename to lib/libdvbv5/tables/header.c
lib/libdvbv5/tables/mgt.c renamed from lib/libdvbv5/descriptors/mgt.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/mgt.c
rename to lib/libdvbv5/tables/mgt.c
lib/libdvbv5/tables/mpeg_es.c renamed from lib/libdvbv5/descriptors/mpeg_es.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/mpeg_es.c
rename to lib/libdvbv5/tables/mpeg_es.c
lib/libdvbv5/tables/mpeg_pes.c renamed from lib/libdvbv5/descriptors/mpeg_pes.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/mpeg_pes.c
rename to lib/libdvbv5/tables/mpeg_pes.c
lib/libdvbv5/tables/mpeg_ts.c renamed from lib/libdvbv5/descriptors/mpeg_ts.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/mpeg_ts.c
rename to lib/libdvbv5/tables/mpeg_ts.c
lib/libdvbv5/tables/nit.c renamed from lib/libdvbv5/descriptors/nit.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/nit.c
rename to lib/libdvbv5/tables/nit.c
lib/libdvbv5/tables/pat.c renamed from lib/libdvbv5/descriptors/pat.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/pat.c
rename to lib/libdvbv5/tables/pat.c
lib/libdvbv5/tables/pmt.c renamed from lib/libdvbv5/descriptors/pmt.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/pmt.c
rename to lib/libdvbv5/tables/pmt.c
lib/libdvbv5/tables/sdt.c renamed from lib/libdvbv5/descriptors/sdt.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/sdt.c
rename to lib/libdvbv5/tables/sdt.c
lib/libdvbv5/tables/vct.c renamed from lib/libdvbv5/descriptors/vct.c +0 -0
similarity index 100%
rename from lib/libdvbv5/descriptors/vct.c
rename to lib/libdvbv5/tables/vct.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/4 libdvbv5: cleanup parser API

- fix initialization of dvb_table_initializers
- check return value of dvb_desc_parse
- allocate table inside the parser
- remove unneeded table_length argument

---
 lib/include/libdvbv5/atsc_eit.h    |  2 +-
 lib/include/libdvbv5/cat.h         |  2 +-
 lib/include/libdvbv5/descriptors.h | 18 ++---------
 lib/include/libdvbv5/eit.h         |  2 +-
 lib/include/libdvbv5/mgt.h         |  2 +-
 lib/include/libdvbv5/nit.h         |  2 +-
 lib/include/libdvbv5/pat.h         |  2 +-
 lib/include/libdvbv5/pmt.h         |  2 +-
 lib/include/libdvbv5/sdt.h         |  2 +-
 lib/include/libdvbv5/vct.h         |  2 +-
 lib/libdvbv5/descriptors.c         |  5 ++--
 lib/libdvbv5/dvb-scan.c            | 27 ++++-------------
 lib/libdvbv5/tables/atsc_eit.c     | 44 ++++++++++++++-------------
 lib/libdvbv5/tables/cat.c          | 28 +++++++++--------
 lib/libdvbv5/tables/eit.c          | 42 +++++++++++++-------------
 lib/libdvbv5/tables/mgt.c          | 54 ++++++++++++++++-----------------
 lib/libdvbv5/tables/nit.c          | 61 +++++++++++++++++---------------------
 lib/libdvbv5/tables/pat.c          | 31 ++++++++++---------
 lib/libdvbv5/tables/pmt.c          | 52 +++++++++++++++-----------------
 lib/libdvbv5/tables/sdt.c          | 36 +++++++++++-----------
 lib/libdvbv5/tables/vct.c          | 47 ++++++++++++++++-------------
 21 files changed, 219 insertions(+), 244 deletions(-)
lib/include/libdvbv5/atsc_eit.h +1 -1
index 93d9304..5116a3d 100644
@@ -77,7 +77,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t atsc_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_eit *eit, ssize_t *table_length);
+ssize_t atsc_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_eit **table);
 void atsc_table_eit_free(struct atsc_table_eit *eit);
 void atsc_table_eit_print(struct dvb_v5_fe_parms *parms, struct atsc_table_eit *eit);
 void atsc_time(const uint32_t start_time, struct tm *tm);
lib/include/libdvbv5/cat.h +1 -1
index df1e417..134e3e5 100644
@@ -40,7 +40,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_cat *cat, ssize_t *table_length);
+ssize_t dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_cat **table);
 void dvb_table_cat_free(struct dvb_table_cat *cat);
 void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat *t);
 
lib/include/libdvbv5/descriptors.h +2 -16
index 8b38977..66197f6 100644
@@ -36,14 +36,9 @@
 
 struct dvb_v5_fe_parms;
 
-typedef void (*dvb_table_init_func)(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, void *table, ssize_t *table_length);
+typedef void (*dvb_table_init_func)(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, void **table);
 
-struct dvb_table_init {
-	dvb_table_init_func init;
-	ssize_t size;
-};
-
-extern const struct dvb_table_init dvb_table_initializers[];
+extern const dvb_table_init_func dvb_table_initializers[256];
 extern char *default_charset;
 extern char *output_charset;
 
@@ -106,15 +101,6 @@ struct dvb_descriptor {
 
 extern const struct dvb_descriptor dvb_descriptors[];
 
-enum dvb_tables {
-	PAT,
-	PMT,
-	NIT,
-	SDT,
-	TVCT,
-	CVCT,
-};
-
 enum descriptors {
 	/* ISO/IEC 13818-1 */
 	video_stream_descriptor				= 0x02,
lib/include/libdvbv5/eit.h +1 -1
index c959537..97fbf36 100644
@@ -78,7 +78,7 @@ extern const char *dvb_eit_running_status_name[8];
 extern "C" {
 #endif
 
-ssize_t dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_eit *eit, ssize_t *table_length);
+ssize_t dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_eit **table);
 void dvb_table_eit_free(struct dvb_table_eit *eit);
 void dvb_table_eit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_eit *eit);
 void dvb_time(const uint8_t data[5], struct tm *tm);
lib/include/libdvbv5/mgt.h +1 -1
index d67ad33..eb4403e 100644
@@ -67,7 +67,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t atsc_table_mgt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_mgt *mgt, ssize_t *table_length);
+ssize_t atsc_table_mgt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_mgt **table);
 void atsc_table_mgt_free(struct atsc_table_mgt *mgt);
 void atsc_table_mgt_print(struct dvb_v5_fe_parms *parms, struct atsc_table_mgt *mgt);
 
lib/include/libdvbv5/nit.h +1 -1
index fdea7a7..63ffcd5 100644
@@ -85,7 +85,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_nit *nit, ssize_t *table_length);
+ssize_t dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_nit **table);
 void dvb_table_nit_free(struct dvb_table_nit *nit);
 void dvb_table_nit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_nit *nit);
 
lib/include/libdvbv5/pat.h +1 -1
index eb4aeef..a2180d5 100644
@@ -57,7 +57,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t dvb_table_pat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pat *pat, ssize_t *table_length);
+ssize_t dvb_table_pat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pat **table);
 void dvb_table_pat_free(struct dvb_table_pat *pat);
 void dvb_table_pat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_pat *t);
 
lib/include/libdvbv5/pmt.h +1 -1
index 432a458..150b45a 100644
@@ -112,7 +112,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t *table_length);
+ssize_t dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_pmt **table);
 void dvb_table_pmt_free(struct dvb_table_pmt *pmt);
 void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms, const struct dvb_table_pmt *pmt);
 
lib/include/libdvbv5/sdt.h +1 -1
index 9684fbc..8455080 100644
@@ -64,7 +64,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t dvb_table_sdt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_sdt *sdt, ssize_t *table_lengh);
+ssize_t dvb_table_sdt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct dvb_table_sdt **table);
 void dvb_table_sdt_free(struct dvb_table_sdt *sdt);
 void dvb_table_sdt_print(struct dvb_v5_fe_parms *parms, struct dvb_table_sdt *sdt);
 
lib/include/libdvbv5/vct.h +1 -1
index 10ac301..383c5b1 100644
@@ -114,7 +114,7 @@ struct dvb_v5_fe_parms;
 extern "C" {
 #endif
 
-ssize_t atsc_table_vct_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_vct *vct, ssize_t *table_length);
+ssize_t atsc_table_vct_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_vct **table);
 void atsc_table_vct_free(struct atsc_table_vct *vct);
 void atsc_table_vct_print(struct dvb_v5_fe_parms *parms, struct atsc_table_vct *vct);
 
lib/libdvbv5/descriptors.c +3 -2
index c2b0293..bfbf529 100644
@@ -79,9 +79,10 @@ static void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, const struct d
 	hexdump(parms, "|           ", desc->data, desc->length);
 }
 
-#define TABLE_INIT( _x ) { (dvb_table_init_func) _x##_init, sizeof(struct _x) }
+#define TABLE_INIT(_x) (dvb_table_init_func) _x##_init
 
-const struct dvb_table_init dvb_table_initializers[] = {
+const dvb_table_init_func dvb_table_initializers[256] = {
+	[0 ... 255]              = NULL,
 	[DVB_TABLE_PAT]          = TABLE_INIT(dvb_table_pat),
 	[DVB_TABLE_CAT]          = TABLE_INIT(dvb_table_cat),
 	[DVB_TABLE_PMT]          = TABLE_INIT(dvb_table_pmt),
lib/libdvbv5/dvb-scan.c +5 -22
index 68c0551..5cd38f8 100644
@@ -129,7 +129,6 @@ struct dvb_table_filter_priv {
 	unsigned long is_read_bits[BITS_TO_LONGS(256)];
 
 	/* section gaps and multiple ts_id handling */
-	ssize_t table_length;
 	int first_ts_id;
 	int first_section;
 	int done;
@@ -141,7 +140,8 @@ static int dvb_parse_section_alloc(struct dvb_v5_fe_parms *parms,
 	struct dvb_table_filter_priv *priv;
 
 	if (!sect->table) {
-		dvb_logerr("table memory pointer not filled");
+		dvb_logerr("%s: table memory pointer not filled",
+				__func__);
 		return -4;
 	}
 	*sect->table = NULL;
@@ -173,7 +173,6 @@ static int dvb_parse_section(struct dvb_v5_fe_parms *parms,
 	struct dvb_table_header *h;
 	struct dvb_table_filter_priv *priv;
 
-	uint8_t *tbl = NULL;
 	unsigned char tid;
 
 	h = (struct dvb_table_header *)buf;
@@ -222,27 +221,13 @@ static int dvb_parse_section(struct dvb_v5_fe_parms *parms,
 	if (!sect->allow_section_gaps && sect->ts_id != -1)
 		set_bit(h->section_id, priv->is_read_bits);
 
-	tbl = *sect->table;
-	if (!tbl) {
-		if (!dvb_table_initializers[tid].size) {
-			dvb_logerr("%s: no table size for table %d",
-					__func__, tid);
-			return -1;
-		}
-
-		tbl = calloc(dvb_table_initializers[tid].size, 1);
-	}
-
-	if (dvb_table_initializers[tid].init)
-		dvb_table_initializers[tid].init(parms, buf, buf_length,
-						 tbl, &priv->table_length);
+	if (dvb_table_initializers[tid])
+		dvb_table_initializers[tid](parms, buf, buf_length,
+						 sect->table);
 	else
 		dvb_logerr("%s: no initializer for table %d",
 			   __func__, tid);
 
-	/* Store the table */
-	*sect->table = tbl;
-
 	if (!sect->allow_section_gaps && sect->ts_id != -1 &&
 			is_all_bits_set(priv->last_section, priv->is_read_bits))
 		priv->done = 1;
@@ -262,8 +247,6 @@ int dvb_read_sections(struct dvb_v5_fe_parms *parms, int dmx_fd,
 	uint8_t *buf = NULL;
 	uint8_t mask = 0xff;
 
-	/* FIXME: verify if all requested tables are known */
-
 	ret = dvb_parse_section_alloc(parms, sect);
 	if (ret < 0)
 		return ret;
lib/libdvbv5/tables/atsc_eit.c +24 -20

94 lines not on this page · raw message

lib/libdvbv5/tables/cat.c +16 -12
index 5acc88e..394eb3c 100644
@@ -23,9 +23,10 @@
 #include <libdvbv5/dvb-fe.h>
 
 ssize_t dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
-		ssize_t buflen, struct dvb_table_cat *cat, ssize_t *table_length)
+		ssize_t buflen, struct dvb_table_cat **table)
 {
 	const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+	struct dvb_table_cat *cat;
 	struct dvb_desc **head_desc;
 	size_t size;
 
@@ -42,23 +43,27 @@ ssize_t dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		return -2;
 	}
 
-	if (*table_length > 0) {
-		/* find end of current lists */
-		head_desc = &cat->descriptor;
-		while (*head_desc != NULL)
-			head_desc = &(*head_desc)->next;
-	} else {
-		head_desc = &cat->descriptor;
+	if (!*table) {
+		*table = calloc(sizeof(struct dvb_table_cat), 1);
+		if (!*table) {
+			dvb_logerr("%s: out of memory", __func__);
+			return -3;
+		}
 	}
-
+	cat = *table;
 	memcpy(cat, p, size);
 	p += size;
 
+	/* find end of current lists */
+	head_desc = &cat->descriptor;
+	while (*head_desc != NULL)
+		head_desc = &(*head_desc)->next;
+
 	size = cat->header.section_length + 3 - 4; /* plus header, minus CRC */
 	if (buf + size > endbuf) {
 		dvb_logerr("%s: short read %zd/%zd bytes", __func__,
 			   endbuf - buf, size);
-		return -3;
+		return -4;
 	}
 	endbuf = buf + size;
 
@@ -67,7 +72,7 @@ ssize_t dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		uint16_t desc_length = endbuf - p;
 		if (dvb_desc_parse(parms, p, desc_length,
 				      head_desc) != 0) {
-			return -4;
+			return -5;
 		}
 		p += desc_length;
 	}
@@ -76,7 +81,6 @@ ssize_t dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		dvb_logwarn("%s: %zu spurious bytes at the end",
 			   __func__, endbuf - p);
 
-	*table_length = p - buf;
 	return p - buf;
 }
 
lib/libdvbv5/tables/eit.c +20 -22

77 lines not on this page · raw message

lib/libdvbv5/tables/mgt.c +27 -27

94 lines not on this page · raw message

lib/libdvbv5/tables/nit.c +28 -33

106 lines not on this page · raw message

lib/libdvbv5/tables/pat.c +17 -14
index 1a79bca..544bac4 100644
@@ -24,9 +24,10 @@
 #include <libdvbv5/dvb-fe.h>
 
 ssize_t dvb_table_pat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
-			ssize_t buflen, struct dvb_table_pat *pat, ssize_t *table_length)
+			ssize_t buflen, struct dvb_table_pat **table)
 {
 	const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+	struct dvb_table_pat *pat;
 	struct dvb_table_pat_program **head;
 	size_t size;
 
@@ -43,18 +44,21 @@ ssize_t dvb_table_pat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		return -2;
 	}
 
-	if (*table_length > 0) {
-		/* find end of current list */
-		head = &pat->program;
-		while (*head != NULL)
-			head = &(*head)->next;
-	} else {
-		memcpy(pat, buf, size);
-		p += size;
-		pat->programs = 0;
-		pat->program = NULL;
-		head = &pat->program;
+	if (!*table) {
+		*table = calloc(sizeof(struct dvb_table_pat), 1);
+		if (!*table) {
+			dvb_logerr("%s: out of memory", __func__);
+			return -3;
+		}
 	}
+	pat = *table;
+	memcpy(pat, buf, size);
+	p += size;
+
+	/* find end of current list */
+	head = &pat->program;
+	while (*head != NULL)
+		head = &(*head)->next;
 
 	size = offsetof(struct dvb_table_pat_program, next);
 	while (p + size <= endbuf) {
@@ -63,7 +67,7 @@ ssize_t dvb_table_pat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		prog = malloc(sizeof(struct dvb_table_pat_program));
 		if (!prog) {
 			dvb_logerr("%s: out of memory", __func__);
-			return -3;
+			return -4;
 		}
 
 		memcpy(prog, p, size);
@@ -86,7 +90,6 @@ ssize_t dvb_table_pat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 	if (endbuf - p)
 		dvb_logwarn("%s: %zu spurious bytes at the end",
 			   __func__, endbuf - p);
-	*table_length = p - buf;
 	return p - buf;
 }
 
lib/libdvbv5/tables/pmt.c +24 -28

97 lines not on this page · raw message

lib/libdvbv5/tables/sdt.c +18 -18
index 561ec66..a64726f 100644
@@ -24,9 +24,10 @@
 #include <libdvbv5/dvb-fe.h>
 
 ssize_t dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
-			ssize_t buflen, struct dvb_table_sdt *sdt, ssize_t *table_length)
+			ssize_t buflen, struct dvb_table_sdt **table)
 {
 	const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+	struct dvb_table_sdt *sdt;
 	struct dvb_table_sdt_service **head;
 	size_t size;
 
@@ -43,28 +44,28 @@ ssize_t dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		return -2;
 	}
 
-	if (*table_length > 0) {
-		memcpy(sdt, p, size);
-		bswap16(sdt->network_id);
-
-		/* find end of curent list */
-		head = &sdt->service;
-		while (*head != NULL)
-			head = &(*head)->next;
-	} else {
-		memcpy(sdt, p, size);
-		bswap16(sdt->network_id);
-
-		sdt->service = NULL;
-		head = &sdt->service;
+	if (!*table) {
+		*table = calloc(sizeof(struct dvb_table_sdt), 1);
+		if (!*table) {
+			dvb_logerr("%s: out of memory", __func__);
+			return -3;
+		}
 	}
+	sdt = *table;
+	memcpy(sdt, p, size);
 	p += size;
+	bswap16(sdt->network_id);
+
+	/* find end of curent list */
+	head = &sdt->service;
+	while (*head != NULL)
+		head = &(*head)->next;
 
 	size = sdt->header.section_length + 3 - 4; /* plus header, minus CRC */
 	if (buf + size > endbuf) {
 		dvb_logerr("%s: short read %zd/%zd bytes", __func__,
 			   endbuf - buf, size);
-		return -3;
+		return -4;
 	}
 	endbuf = buf + size;
 
@@ -99,7 +100,7 @@ ssize_t dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 			}
 			if (dvb_desc_parse(parms, p, desc_length,
 					      &service->descriptor) != 0) {
-				return -4;
+				return -6;
 			}
 			p += desc_length;
 		}
@@ -109,7 +110,6 @@ ssize_t dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		dvb_logwarn("%s: %zu spurious bytes at the end",
 			   __func__, endbuf - p);
 
-	*table_length = p - buf;
 	return p - buf;
 }
 
lib/libdvbv5/tables/vct.c +26 -21

90 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH 3/4 libdvbv5: short API description

In reply to André Roth
---
 lib/include/libdvbv5/dvb-scan.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/include/libdvbv5/dvb-scan.h +26 -0
index f0af9d7..8f0e553 100644
@@ -76,6 +76,32 @@ struct dvb_table_filter {
 
 void dvb_table_filter_free(struct dvb_table_filter *sect);
 
+/* Read DVB table sections
+ *
+ * The following functions can be used to read DVB table sections by
+ * specifying a table ID and a program ID. Optionally a transport
+ * stream ID can be specified as well. The function will read on the
+ * specified demux and return when reading is done or an error has
+ * occurred. If table is not NULL after the call, it has to be freed
+ * with the apropriate free table function (even if an error has
+ * occurred).
+ *
+ * Returns 0 on success or a negative error code.
+ *
+ * Example usage:
+ *
+ * struct dvb_table_pat *pat;
+ * int r = dvb_read_section( parms, dmx_fd, DVB_TABLE_PAT, DVB_TABLE_PAT_PID, (void **) &pat, 5 );
+ * if (r < 0)
+ *	dvb_logerr("error reading PAT table");
+ * else {
+ *	// do something with pat
+ * }
+ * if (pat)
+ *	dvb_table_pat_free( pat );
+ *
+ */
+
 int dvb_read_section(struct dvb_v5_fe_parms *parms, int dmx_fd, unsigned char tid, uint16_t pid, void **table,
 		unsigned timeout);
 
Signature · 1 line
1.9.1
#3 lore raw

PATCH 4/4 libdvbv5: build dynamic libdvbv5 by default

In reply to André Roth

- renamed ./configure option --enable-libdvbv5 to --disable-libdvbv5
- thus libdvbv5 will be build shared by default
- cleanups in configure.ac

---
 configure.ac | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
configure.ac +12 -12
index 4080d1e..474c681 100644
@@ -216,10 +216,10 @@ AC_DEFINE_DIR([IR_KEYTABLE_USER_DIR], [keytableuserdir], [ir-keytable user defin
 # options
 
 AC_ARG_ENABLE(libdvbv5,
-  AS_HELP_STRING([--enable-libdvbv5], [enable experimental dynamic libdvbv5 compilation]),
+  AS_HELP_STRING([--disable-libdvbv5], [disable experimental dynamic libdvbv5 compilation]),
   [case "${enableval}" in
      yes | no ) ;;
-     *) AC_MSG_ERROR(bad value ${enableval} for --enable-libdvbv5) ;;
+     *) AC_MSG_ERROR(bad value ${enableval} for --disable-libdvbv5) ;;
    esac]
 )
 
@@ -227,7 +227,7 @@ AC_ARG_ENABLE(libv4l,
   AS_HELP_STRING([--disable-libv4l], [disable dynamic libv4l compilation]),
   [case "${enableval}" in
      yes | no ) ;;
-     *) AC_MSG_ERROR(bad value ${enableval} for --enable-libv4l) ;;
+     *) AC_MSG_ERROR(bad value ${enableval} for --disable-libv4l) ;;
    esac]
 )
 
@@ -235,7 +235,7 @@ AC_ARG_ENABLE(v4l-utils,
   AS_HELP_STRING([--disable-v4l-utils], [disable v4l-utils compilation]),
   [case "${enableval}" in
      yes | no ) ;;
-     *) AC_MSG_ERROR(bad value ${enableval} for --enable-v4l-utils) ;;
+     *) AC_MSG_ERROR(bad value ${enableval} for --disable-v4l-utils) ;;
    esac]
 )
 
@@ -247,17 +247,17 @@ AC_ARG_ENABLE(qv4l2,
    esac]
 )
 
-AM_CONDITIONAL([WITH_LIBDVBV5], [test x$enable_libdvbv5 = xyes])
-AM_CONDITIONAL([WITH_LIBV4L], [test x$enable_libv4l != xno])
-AM_CONDITIONAL([WITH_V4LUTILS], [test x$enable_v4l_utils != "xno"])
-AM_CONDITIONAL([WITH_QV4L2], [test ${qt_pkgconfig} = true -a x$enable_qv4l2 != xno])
-AM_CONDITIONAL([WITH_V4L_PLUGINS], [test x$enable_libv4l != xno -a x$enable_shared != xno])
+AM_CONDITIONAL([WITH_LIBDVBV5],     [test x$enable_libdvbv5  != xno])
+AM_CONDITIONAL([WITH_LIBV4L],       [test x$enable_libv4l    != xno])
+AM_CONDITIONAL([WITH_V4LUTILS],	    [test x$enable_v4l_utils != xno])
+AM_CONDITIONAL([WITH_QV4L2],	    [test ${qt_pkgconfig}  = true -a x$enable_qv4l2 != xno])
+AM_CONDITIONAL([WITH_V4L_PLUGINS],  [test x$enable_libv4l != xno -a x$enable_shared != xno])
 AM_CONDITIONAL([WITH_V4L_WRAPPERS], [test x$enable_libv4l != xno -a x$enable_shared != xno])
-AM_CONDITIONAL([WITH_QTGL], [test ${qt_pkgconfig_gl} = true])
+AM_CONDITIONAL([WITH_QTGL],	    [test ${qt_pkgconfig_gl} = true])
 
 # append -static to libtool compile and link command to enforce static libs
-AS_IF([test x$enable_libdvbv5 != xyes], [AC_SUBST([ENFORCE_LIBDVBV5_STATIC], ["-static"])])
-AS_IF([test x$enable_libv4l = xno], [AC_SUBST([ENFORCE_LIBV4L_STATIC], ["-static"])])
+AS_IF([test x$enable_libdvbv5 = xno], [AC_SUBST([ENFORCE_LIBDVBV5_STATIC], ["-static"])])
+AS_IF([test x$enable_libv4l = xno],   [AC_SUBST([ENFORCE_LIBV4L_STATIC],   ["-static"])])
 
 # misc
 
Signature · 1 line
1.9.1