linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo
@ 2014-03-25 18:19 André Roth
  2014-03-25 18:19 ` [PATCH 02/11] libdvbv5: fix asprintf compile warnings André Roth
                   ` (8 more replies)
  0 siblings, 9 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

dvb_loginfo log support without setting output color.

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/dvb-log.h  |  3 +++
 lib/libdvbv5/dvb-log.c | 26 +++++++++++++-------------
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/lib/include/dvb-log.h b/lib/include/dvb-log.h
index a72adce..755167a 100644
--- a/lib/include/dvb-log.h
+++ b/lib/include/dvb-log.h
@@ -38,6 +38,9 @@ typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( fo
 #define dvb_logwarn(fmt, arg...) do {\
 	parms->logfunc(LOG_WARNING, fmt, ##arg); \
 } while (0)
+#define dvb_loginfo(fmt, arg...) do {\
+	parms->logfunc(LOG_NOTICE, fmt, ##arg); \
+} while (0)
 
 
 #define dvb_perror(msg) do {\
diff --git a/lib/libdvbv5/dvb-log.c b/lib/libdvbv5/dvb-log.c
index 87d92f2..8bb34ca 100644
--- a/lib/libdvbv5/dvb-log.c
+++ b/lib/libdvbv5/dvb-log.c
@@ -30,15 +30,15 @@ static const struct loglevel {
 	const char *color;
 	int fd;
 } loglevels[9] = {
-	{"EMERG   ", "\033[31m", STDERR_FILENO },
-	{"ALERT   ", "\033[31m", STDERR_FILENO },
-	{"CRITICAL", "\033[31m", STDERR_FILENO },
-	{"ERROR   ", "\033[31m", STDERR_FILENO },
-	{"WARNING ", "\033[33m", STDOUT_FILENO },
-	{"NOTICE  ", "\033[36m", STDOUT_FILENO },
-	{"INFO    ", "\033[36m", STDOUT_FILENO },
-	{"DEBUG   ", "\033[32m", STDOUT_FILENO },
-	{"",         "\033[0m",  STDOUT_FILENO },
+	{"EMERG    ", "\033[31m", STDERR_FILENO },
+	{"ALERT    ", "\033[31m", STDERR_FILENO },
+	{"CRITICAL ", "\033[31m", STDERR_FILENO },
+	{"ERROR    ", "\033[31m", STDERR_FILENO },
+	{"WARNING  ", "\033[33m", STDOUT_FILENO },
+	{"",          "\033[36m", STDOUT_FILENO }, /* NOTICE */
+	{"",          NULL,       STDOUT_FILENO }, /* INFO */
+	{"DEBUG    ", "\033[32m", STDOUT_FILENO },
+	{"",          "\033[0m",  STDOUT_FILENO }, /* reset*/
 };
 #define LOG_COLOROFF 8
 
@@ -49,14 +49,14 @@ void dvb_default_log(int level, const char *fmt, ...)
 	va_list ap;
 	va_start(ap, fmt);
 	FILE *out = stdout;
-	if(STDERR_FILENO == loglevels[level].fd)
+	if (STDERR_FILENO == loglevels[level].fd)
 		out = stderr;
-	if(isatty(loglevels[level].fd))
+	if (loglevels[level].color && isatty(loglevels[level].fd))
 		fputs(loglevels[level].color, out);
-	fprintf(out, "%s ", loglevels[level].name);
+	fprintf(out, "%s", loglevels[level].name);
 	vfprintf(out, fmt, ap);
 	fprintf(out, "\n");
-	if(isatty(loglevels[level].fd))
+	if(loglevels[level].color && isatty(loglevels[level].fd))
 		fputs(loglevels[LOG_COLOROFF].color, out);
 	va_end(ap);
 }
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 02/11] libdvbv5: fix asprintf compile warnings
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:19 ` [PATCH 03/11] libdvbv5: mpeg elementary stream parsers André Roth
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

- allow logging in dvb_vchannel
- get rid of compile warings about unused asprintf return value

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/libdvbv5/dvb-demux.c |  8 ++++++--
 lib/libdvbv5/dvb-fe.c    |  8 ++++++--
 lib/libdvbv5/dvb-file.c  | 31 +++++++++++++++++++++----------
 utils/dvb/dvbv5-zap.c    | 17 +++++++++++++----
 4 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/lib/libdvbv5/dvb-demux.c b/lib/libdvbv5/dvb-demux.c
index cfd075f..91636f5 100644
--- a/lib/libdvbv5/dvb-demux.c
+++ b/lib/libdvbv5/dvb-demux.c
@@ -43,9 +43,13 @@
 int dvb_dmx_open(int adapter, int demux)
 {
 	char* demux_name = NULL;
+	int fd_demux;
+	int r;
 
-	asprintf(&demux_name, "/dev/dvb/adapter%i/demux%i", adapter, demux );
-	int fd_demux = open( demux_name, O_RDWR | O_NONBLOCK );
+	r = asprintf(&demux_name, "/dev/dvb/adapter%i/demux%i", adapter, demux );
+	if (r < 0)
+		return -1;
+	fd_demux = open( demux_name, O_RDWR | O_NONBLOCK );
 	free(demux_name);
 	return fd_demux;
 }
diff --git a/lib/libdvbv5/dvb-fe.c b/lib/libdvbv5/dvb-fe.c
index 28e6354..4975ff9 100644
--- a/lib/libdvbv5/dvb-fe.c
+++ b/lib/libdvbv5/dvb-fe.c
@@ -52,12 +52,16 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int frontend, unsigned verbose,
 struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend, unsigned verbose,
 				    unsigned use_legacy_call, dvb_logfunc logfunc)
 {
-	int fd, i;
+	int fd, i, r;
 	char *fname;
 	struct dtv_properties dtv_prop;
 	struct dvb_v5_fe_parms *parms = NULL;
 
-	asprintf(&fname, "/dev/dvb/adapter%i/frontend%i", adapter, frontend);
+	r = asprintf(&fname, "/dev/dvb/adapter%i/frontend%i", adapter, frontend);
+	if (r < 0) {
+		logfunc(LOG_ERR, "asprintf error");
+		return NULL;
+	}
 	if (!fname) {
 		logfunc(LOG_ERR, "fname calloc: %s", strerror(errno));
 		return NULL;
diff --git a/lib/libdvbv5/dvb-file.c b/lib/libdvbv5/dvb-file.c
index e0cef34..3e0394e 100644
--- a/lib/libdvbv5/dvb-file.c
+++ b/lib/libdvbv5/dvb-file.c
@@ -807,7 +807,7 @@ int write_dvb_file(const char *fname, struct dvb_file *dvb_file)
 	return 0;
 };
 
-static char *dvb_vchannel(struct dvb_table_nit *nit, uint16_t service_id)
+static char *dvb_vchannel(struct dvb_v5_fe_parms *parms, struct dvb_table_nit *nit, uint16_t service_id)
 {
 	int i;
 	char *buf;
@@ -817,17 +817,18 @@ static char *dvb_vchannel(struct dvb_table_nit *nit, uint16_t service_id)
 
 for( struct dvb_desc_logical_channel *desc = (struct dvb_desc_logical_channel *) nit->descriptor; desc; desc = (struct dvb_desc_logical_channel *) desc->next ) \
 		if(desc->type == logical_channel_number_descriptor) {
-//	dvb_desc_find(struct dvb_desc_logical_channel, desc, nit, logical_channel_number_descriptor) {
+/* FIXME:  dvb_desc_find(struct dvb_desc_logical_channel, desc, nit, logical_channel_number_descriptor) ? */
 		struct dvb_desc_logical_channel *d = (void *)desc;
-
 		size_t len;
+		int r;
 
 		len = d->length / sizeof(d->lcn);
-
 		for (i = 0; i < len; i++) {
 			if (service_id == d->lcn[i].service_id) {
-				asprintf(&buf, "%d.%d",
+				r = asprintf(&buf, "%d.%d",
 					d->lcn[i].logical_channel_number, i);
+				if (r < 0)
+					dvb_perror("asprintf");
 				return buf;
 			}
 		}
@@ -836,13 +837,16 @@ for( struct dvb_desc_logical_channel *desc = (struct dvb_desc_logical_channel *)
 	dvb_desc_find(struct dvb_desc_ts_info, desc, nit, TS_Information_descriptior) {
 		const struct dvb_desc_ts_info *d = (const void *) desc;
 		const struct dvb_desc_ts_info_transmission_type *t;
+		int r;
 
 		t = &d->transmission_type;
 
 		for (i = 0; i < t->num_of_service; i++) {
 			if (d->service_id[i] == service_id) {
-				asprintf(&buf, "%d.%d",
+				r = asprintf(&buf, "%d.%d",
 					d->remote_control_key_id, i);
+				if (r < 0)
+					dvb_perror("asprintf");
 				return buf;
 			}
 		}
@@ -1062,13 +1066,16 @@ int store_dvb_channel(struct dvb_file **dvb_file,
 		atsc_vct_channel_foreach(d, dvb_scan_handler->vct) {
 			char *channel = NULL;
 			char *vchannel = NULL;
+			int r;
 
 			channel = calloc(1, strlen(d->short_name) + 1);
 			strcpy(channel, d->short_name);
 
-			asprintf(&vchannel, "%d.%d",
+			r = asprintf(&vchannel, "%d.%d",
 				d->major_channel_number,
 				d->minor_channel_number);
+			if (r < 0)
+				dvb_perror("asprintf");
 
 			if (parms->verbose)
 				dvb_log("Virtual channel %s, name = %s",
@@ -1095,6 +1102,7 @@ int store_dvb_channel(struct dvb_file **dvb_file,
 	dvb_sdt_service_foreach(service, dvb_scan_handler->sdt) {
 		char *channel = NULL;
 		char *vchannel = NULL;
+		int r;
 
 		dvb_desc_find(struct dvb_desc_service, desc, service, service_descriptor) {
 			if (desc->name) {
@@ -1107,12 +1115,15 @@ int store_dvb_channel(struct dvb_file **dvb_file,
 			break;
 		}
 
-		if (!channel)
-			asprintf(&channel, "#%d", service->service_id);
+		if (!channel) {
+			r = asprintf(&channel, "#%d", service->service_id);
+			if (r < 0)
+				dvb_perror("asprintf");
+		}
 
 		if (parms->verbose)
 			dvb_log("Storing as channel %s", channel);
-		vchannel = dvb_vchannel(dvb_scan_handler->nit, service->service_id);
+		vchannel = dvb_vchannel(parms, dvb_scan_handler->nit, service->service_id);
 
 		rc = get_program_and_store(parms, *dvb_file, dvb_scan_handler,
 					   service->service_id,
diff --git a/utils/dvb/dvbv5-zap.c b/utils/dvb/dvbv5-zap.c
index 5c3b74c..d4a4b98 100644
--- a/utils/dvb/dvbv5-zap.c
+++ b/utils/dvb/dvbv5-zap.c
@@ -692,6 +692,7 @@ int main(int argc, char **argv)
 	int audio_fd = -1, video_fd = -1;
 	int dvr_fd = -1, file_fd = -1;
 	int err = -1;
+	int r;
 	struct dvb_v5_fe_parms *parms = NULL;
 	const struct argp argp = {
 		.options = options,
@@ -732,11 +733,19 @@ int main(int argc, char **argv)
 		}
 	}
 
-	asprintf(&args.demux_dev,
+	r = asprintf(&args.demux_dev,
 		 "/dev/dvb/adapter%i/demux%i", args.adapter, args.demux);
+	if (r < 0) {
+		fprintf(stderr, "asprintf error\n");
+		return -1;
+	}
 
-	asprintf(&args.dvr_dev,
+	r = asprintf(&args.dvr_dev,
 		 "/dev/dvb/adapter%i/dvr%i", args.adapter, args.demux);
+	if (r < 0) {
+		fprintf(stderr, "asprintf error\n");
+		return -1;
+	}
 
 	if (args.silent < 2)
 		fprintf(stderr, "using demux '%s'\n", args.demux_dev);
@@ -744,11 +753,11 @@ int main(int argc, char **argv)
 	if (!args.confname) {
 		if (!homedir)
 			ERROR("$HOME not set");
-		asprintf(&args.confname, "%s/.tzap/%i/%s",
+		r = asprintf(&args.confname, "%s/.tzap/%i/%s",
 			 homedir, args.adapter, CHANNEL_FILE);
 		if (access(args.confname, R_OK)) {
 			free(args.confname);
-			asprintf(&args.confname, "%s/.tzap/%s",
+			r = asprintf(&args.confname, "%s/.tzap/%s",
 				homedir, CHANNEL_FILE);
 		}
 	}
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 03/11] libdvbv5: mpeg elementary stream parsers
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
  2014-03-25 18:19 ` [PATCH 02/11] libdvbv5: fix asprintf compile warnings André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:19 ` [PATCH 04/11] libdvbv5: fix EIT parsing André Roth
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

Implement parsers for mpeg TS, PES and ES

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/descriptors/mpeg_es.h   | 109 +++++++++++++++++++++++++++++
 lib/include/descriptors/mpeg_pes.h  | 111 +++++++++++++++++++++++++++++
 lib/include/descriptors/mpeg_ts.h   |  79 +++++++++++++++++++++
 lib/libdvbv5/descriptors/mpeg_es.c  |  76 ++++++++++++++++++++
 lib/libdvbv5/descriptors/mpeg_pes.c | 135 ++++++++++++++++++++++++++++++++++++
 lib/libdvbv5/descriptors/mpeg_ts.c  |  81 ++++++++++++++++++++++
 6 files changed, 591 insertions(+)
 create mode 100644 lib/include/descriptors/mpeg_es.h
 create mode 100644 lib/include/descriptors/mpeg_pes.h
 create mode 100644 lib/include/descriptors/mpeg_ts.h
 create mode 100644 lib/libdvbv5/descriptors/mpeg_es.c
 create mode 100644 lib/libdvbv5/descriptors/mpeg_pes.c
 create mode 100644 lib/libdvbv5/descriptors/mpeg_ts.c

diff --git a/lib/include/descriptors/mpeg_es.h b/lib/include/descriptors/mpeg_es.h
new file mode 100644
index 0000000..4c6a862
--- /dev/null
+++ b/lib/include/descriptors/mpeg_es.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#ifndef _MPEG_ES_H
+#define _MPEG_ES_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+#define DVB_MPEG_ES_PIC_START  0x00
+#define DVB_MPEG_ES_USER_DATA  0xb2
+#define DVB_MPEG_ES_SEQ_START  0xb3
+#define DVB_MPEG_ES_SEQ_EXT    0xb5
+#define DVB_MPEG_ES_GOP        0xb8
+#define DVB_MPEG_ES_SLICES     0x01 ... 0xaf
+
+struct dvb_mpeg_es_seq_start {
+	union {
+		uint32_t bitfield;
+		struct {
+			uint32_t  type:8;
+			uint32_t  sync:24;
+		} __attribute__((packed));
+	} __attribute__((packed));
+	union {
+		uint32_t bitfield2;
+		struct {
+			uint32_t framerate:4;
+			uint32_t aspect:4;
+			uint32_t height:12;
+			uint32_t width:12;
+		} __attribute__((packed));
+	};
+	union {
+		uint32_t bitfield3;
+		struct {
+			uint32_t qm_nonintra:1;
+			uint32_t qm_intra:1;
+			uint32_t constrained:1;
+			uint32_t vbv:10; // Size of video buffer verifier = 16*1024*vbv buf size
+			uint32_t one:1;
+			uint32_t bitrate:18;
+		} __attribute__((packed));
+	};
+} __attribute__((packed));
+
+struct dvb_mpeg_es_pic_start {
+	union {
+		uint32_t bitfield;
+		struct {
+			uint32_t  type:8;
+			uint32_t  sync:24;
+		} __attribute__((packed));
+	} __attribute__((packed));
+	union {
+		uint32_t bitfield2;
+		struct {
+			uint32_t dummy:3;
+			uint32_t vbv_delay:16;
+			uint32_t coding_type:3;
+			uint32_t temporal_ref:10;
+		} __attribute__((packed));
+	};
+} __attribute__((packed));
+
+enum dvb_mpeg_es_frame_t
+{
+	DVB_MPEG_ES_FRAME_UNKNOWN,
+	DVB_MPEG_ES_FRAME_I,
+	DVB_MPEG_ES_FRAME_P,
+	DVB_MPEG_ES_FRAME_B,
+	DVB_MPEG_ES_FRAME_D
+};
+extern const char *dvb_mpeg_es_frame_names[5];
+
+struct dvb_v5_fe_parms;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int  dvb_mpeg_es_seq_start_init (const uint8_t *buf, ssize_t buflen, struct dvb_mpeg_es_seq_start *seq_start);
+void dvb_mpeg_es_seq_start_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_es_seq_start *seq_start);
+
+int  dvb_mpeg_es_pic_start_init (const uint8_t *buf, ssize_t buflen, struct dvb_mpeg_es_pic_start *pic_start);
+void dvb_mpeg_es_pic_start_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_es_pic_start *pic_start);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/include/descriptors/mpeg_pes.h b/lib/include/descriptors/mpeg_pes.h
new file mode 100644
index 0000000..5889df7
--- /dev/null
+++ b/lib/include/descriptors/mpeg_pes.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#ifndef _MPEG_PES_H
+#define _MPEG_PES_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+#define DVB_MPEG_PES  0x00001
+#define DVB_MPEG_PES_VIDEO  0xe0 ... 0xef
+
+#define DVB_MPEG_STREAM_MAP       0xBC
+#define DVB_MPEG_STREAM_PADDING   0xBE
+#define DVB_MPEG_STREAM_PRIVATE_2 0x5F
+#define DVB_MPEG_STREAM_ECM       0x70
+#define DVB_MPEG_STREAM_EMM       0x71
+#define DVB_MPEG_STREAM_DIRECTORY 0xFF
+#define DVB_MPEG_STREAM_DSMCC     0x7A
+#define DVB_MPEG_STREAM_H222E     0xF8
+
+struct ts_t {
+	uint8_t  one:1;
+	uint8_t  bits30:3;
+	uint8_t  tag:4;
+
+	union {
+		uint16_t bitfield;
+		struct {
+			uint16_t  one1:1;
+			uint16_t  bits15:15;
+		} __attribute__((packed));
+	} __attribute__((packed));
+
+	union {
+		uint16_t bitfield2;
+		struct {
+			uint16_t  one2:1;
+			uint16_t  bits00:15;
+		} __attribute__((packed));
+	} __attribute__((packed));
+} __attribute__((packed));
+
+struct dvb_mpeg_pes_optional {
+	union {
+		uint16_t bitfield;
+		struct {
+			uint16_t PES_extension:1;
+			uint16_t PES_CRC:1;
+			uint16_t additional_copy_info:1;
+			uint16_t DSM_trick_mode:1;
+			uint16_t ES_rate:1;
+			uint16_t ESCR:1;
+			uint16_t PTS_DTS:2;
+			uint16_t original_or_copy:1;
+			uint16_t copyright:1;
+			uint16_t data_alignment_indicator:1;
+			uint16_t PES_priority:1;
+			uint16_t PES_scrambling_control:2;
+			uint16_t two:2;
+		} __attribute__((packed));
+	} __attribute__((packed));
+	uint8_t length;
+	uint64_t pts;
+	uint64_t dts;
+} __attribute__((packed));
+
+struct dvb_mpeg_pes {
+	union {
+		uint32_t bitfield;
+		struct {
+			uint32_t  stream_id:8;
+			uint32_t  sync:24;
+		} __attribute__((packed));
+	} __attribute__((packed));
+	uint16_t length;
+	struct dvb_mpeg_pes_optional optional[];
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ssize_t dvb_mpeg_pes_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table);
+void dvb_mpeg_pes_free(struct dvb_mpeg_pes *ts);
+void dvb_mpeg_pes_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_pes *ts);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/include/descriptors/mpeg_ts.h b/lib/include/descriptors/mpeg_ts.h
new file mode 100644
index 0000000..aca97aa
--- /dev/null
+++ b/lib/include/descriptors/mpeg_ts.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#ifndef _MPEG_TS_H
+#define _MPEG_TS_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+#define DVB_MPEG_TS  0x47
+#define DVB_MPEG_TS_PACKET_SIZE  188
+
+struct dvb_mpeg_ts_adaption {
+	uint8_t length;
+	struct {
+		uint8_t extension:1;
+		uint8_t private_data:1;
+		uint8_t splicing_point:1;
+		uint8_t OPCR:1;
+		uint8_t PCR:1;
+		uint8_t priority:1;
+		uint8_t random_access:1;
+		uint8_t discontinued:1;
+	} __attribute__((packed));
+	uint8_t data[];
+} __attribute__((packed));
+
+struct dvb_mpeg_ts {
+	uint8_t sync_byte; // DVB_MPEG_TS
+	union {
+		uint16_t bitfield;
+		struct {
+			uint16_t pid:13;
+			uint16_t priority:1;
+			uint16_t payload_start:1;
+			uint16_t tei:1;
+		} __attribute__((packed));
+	};
+	struct {
+		uint8_t continuity_counter:4;
+		uint8_t payload:1;
+		uint8_t adaptation_field:1;
+		uint8_t scrambling:2;
+	} __attribute__((packed));
+	struct dvb_mpeg_ts_adaption adaption[];
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ssize_t dvb_mpeg_ts_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+void dvb_mpeg_ts_free(struct dvb_mpeg_ts *ts);
+void dvb_mpeg_ts_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_ts *ts);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libdvbv5/descriptors/mpeg_es.c b/lib/libdvbv5/descriptors/mpeg_es.c
new file mode 100644
index 0000000..9fcb5ca
--- /dev/null
+++ b/lib/libdvbv5/descriptors/mpeg_es.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#include "descriptors/mpeg_es.h"
+#include "descriptors.h"
+#include "dvb-fe.h"
+
+int dvb_mpeg_es_seq_start_init(const uint8_t *buf, ssize_t buflen, struct dvb_mpeg_es_seq_start *seq_start)
+{
+	if(buflen < sizeof(struct dvb_mpeg_es_seq_start))
+		return -1;
+	memcpy(seq_start, buf, sizeof(struct dvb_mpeg_es_seq_start));
+	bswap32(seq_start->bitfield);
+	bswap32(seq_start->bitfield2);
+	bswap32(seq_start->bitfield3);
+	return 0;
+}
+
+void dvb_mpeg_es_seq_start_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_es_seq_start *seq_start)
+{
+	dvb_log("MPEG ES SEQ START");
+        dvb_log(" - width       %d", seq_start->width);
+        dvb_log(" - height      %d", seq_start->height);
+        dvb_log(" - aspect      %d", seq_start->aspect);
+        dvb_log(" - framerate   %d", seq_start->framerate);
+        dvb_log(" - bitrate     %d", seq_start->bitrate);
+        dvb_log(" - one         %d", seq_start->one);
+        dvb_log(" - vbv         %d", seq_start->vbv);
+        dvb_log(" - constrained %d", seq_start->constrained);
+        dvb_log(" - qm_intra    %d", seq_start->qm_intra);
+        dvb_log(" - qm_nonintra %d", seq_start->qm_nonintra);
+}
+
+const char *dvb_mpeg_es_frame_names[5] = {
+	"?",
+	"I",
+	"P",
+	"B",
+	"D"
+};
+
+int dvb_mpeg_es_pic_start_init(const uint8_t *buf, ssize_t buflen, struct dvb_mpeg_es_pic_start *pic_start)
+{
+	if(buflen < sizeof(struct dvb_mpeg_es_pic_start))
+		return -1;
+	memcpy(pic_start, buf, sizeof(struct dvb_mpeg_es_pic_start));
+	bswap32(pic_start->bitfield);
+	bswap32(pic_start->bitfield2);
+	return 0;
+}
+
+void dvb_mpeg_es_pic_start_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_es_pic_start *pic_start)
+{
+	dvb_log("MPEG ES PIC START");
+        dvb_log(" - temporal_ref %d", pic_start->temporal_ref);
+        dvb_log(" - coding_type  %d (%s-frame)", pic_start->coding_type, dvb_mpeg_es_frame_names[pic_start->coding_type]);
+        dvb_log(" - vbv_delay    %d", pic_start->vbv_delay);
+}
+
diff --git a/lib/libdvbv5/descriptors/mpeg_pes.c b/lib/libdvbv5/descriptors/mpeg_pes.c
new file mode 100644
index 0000000..f406004
--- /dev/null
+++ b/lib/libdvbv5/descriptors/mpeg_pes.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#include "descriptors/mpeg_pes.h"
+#include "descriptors.h"
+#include "dvb-fe.h"
+
+ssize_t dvb_mpeg_pes_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table)
+{
+	struct dvb_mpeg_pes *pes = (struct dvb_mpeg_pes *) table;
+	const uint8_t *p = buf;
+	ssize_t bytes_read = 0;
+
+	memcpy(table, p, sizeof(struct dvb_mpeg_pes));
+	p += sizeof(struct dvb_mpeg_pes);
+	bytes_read += sizeof(struct dvb_mpeg_pes);
+
+	bswap32(pes->bitfield);
+	bswap16(pes->length);
+
+	if (pes->sync != 0x000001) {
+		dvb_logerr("mpeg pes invalid, sync 0x%06x should be 0x000001", pes->sync);
+		return -1;
+	}
+
+	if (pes->stream_id == DVB_MPEG_STREAM_PADDING) {
+		dvb_logwarn("mpeg pes padding stream ignored");
+	} else if (pes->stream_id == DVB_MPEG_STREAM_MAP ||
+		   pes->stream_id == DVB_MPEG_STREAM_PRIVATE_2 ||
+		   pes->stream_id == DVB_MPEG_STREAM_ECM ||
+		   pes->stream_id == DVB_MPEG_STREAM_EMM ||
+		   pes->stream_id == DVB_MPEG_STREAM_DIRECTORY ||
+		   pes->stream_id == DVB_MPEG_STREAM_DSMCC ||
+		   pes->stream_id == DVB_MPEG_STREAM_H222E ) {
+		dvb_logerr("mpeg pes: unsupported stream type 0x%04x", pes->stream_id);
+		return -2;
+	} else {
+		memcpy(pes->optional, p, sizeof(struct dvb_mpeg_pes_optional) -
+					 sizeof(pes->optional->pts) -
+					 sizeof(pes->optional->dts));
+		p += sizeof(struct dvb_mpeg_pes_optional) -
+		     sizeof(pes->optional->pts) -
+		     sizeof(pes->optional->dts);
+		bswap16(pes->optional->bitfield);
+		pes->optional->pts = 0;
+		pes->optional->dts = 0;
+		if (pes->optional->PTS_DTS & 2) {
+			struct ts_t pts;
+			memcpy(&pts, p, sizeof(pts));
+			p += sizeof(pts);
+			bswap16(pts.bitfield);
+			bswap16(pts.bitfield2);
+			if (pts.one != 1 || pts.one1 != 1 || pts.one2 != 1)
+				dvb_logwarn("mpeg pes: invalid pts");
+			else {
+				pes->optional->pts |= (uint64_t) pts.bits00;
+				pes->optional->pts |= (uint64_t) pts.bits15 << 15;
+				pes->optional->pts |= (uint64_t) pts.bits30 << 30;
+			}
+		}
+		if (pes->optional->PTS_DTS & 1) {
+			struct ts_t dts;
+			memcpy(&dts, p, sizeof(dts));
+			p += sizeof(dts);
+			bswap16(dts.bitfield);
+			bswap16(dts.bitfield2);
+			pes->optional->dts |= (uint64_t) dts.bits00;
+			pes->optional->dts |= (uint64_t) dts.bits15 << 15;
+			pes->optional->dts |= (uint64_t) dts.bits30 << 30;
+		}
+		bytes_read += sizeof(struct dvb_mpeg_pes_optional);
+	}
+	return bytes_read;
+}
+
+void dvb_mpeg_pes_free(struct dvb_mpeg_pes *ts)
+{
+	free(ts);
+}
+
+void dvb_mpeg_pes_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_pes *pes)
+{
+	dvb_loginfo("MPEG PES");
+	dvb_loginfo(" - sync    0x%06x", pes->sync);
+	dvb_loginfo(" - stream_id 0x%04x", pes->stream_id);
+	dvb_loginfo(" - length      %d", pes->length);
+	if (pes->stream_id == DVB_MPEG_STREAM_PADDING) {
+	} else if (pes->stream_id == DVB_MPEG_STREAM_MAP ||
+		   pes->stream_id == DVB_MPEG_STREAM_PRIVATE_2 ||
+		   pes->stream_id == DVB_MPEG_STREAM_ECM ||
+		   pes->stream_id == DVB_MPEG_STREAM_EMM ||
+		   pes->stream_id == DVB_MPEG_STREAM_DIRECTORY ||
+		   pes->stream_id == DVB_MPEG_STREAM_DSMCC ||
+		   pes->stream_id == DVB_MPEG_STREAM_H222E ) {
+		dvb_log("  mpeg pes unsupported stream type %#04x", pes->stream_id);
+	} else {
+		dvb_loginfo("  mpeg pes optional");
+		dvb_loginfo("   - two                      %d", pes->optional->two);
+		dvb_loginfo("   - PES_scrambling_control   %d", pes->optional->PES_scrambling_control);
+		dvb_loginfo("   - PES_priority             %d", pes->optional->PES_priority);
+		dvb_loginfo("   - data_alignment_indicator %d", pes->optional->data_alignment_indicator);
+		dvb_loginfo("   - copyright                %d", pes->optional->copyright);
+		dvb_loginfo("   - original_or_copy         %d", pes->optional->original_or_copy);
+		dvb_loginfo("   - PTS_DTS                  %d", pes->optional->PTS_DTS);
+		dvb_loginfo("   - ESCR                     %d", pes->optional->ESCR);
+		dvb_loginfo("   - ES_rate                  %d", pes->optional->ES_rate);
+		dvb_loginfo("   - DSM_trick_mode           %d", pes->optional->DSM_trick_mode);
+		dvb_loginfo("   - additional_copy_info     %d", pes->optional->additional_copy_info);
+		dvb_loginfo("   - PES_CRC                  %d", pes->optional->PES_CRC);
+		dvb_loginfo("   - PES_extension            %d", pes->optional->PES_extension);
+		dvb_loginfo("   - length                   %d", pes->optional->length);
+		if (pes->optional->PTS_DTS & 2)
+			dvb_loginfo("   - pts                      %lx (%fs)", pes->optional->pts, (float) pes->optional->pts / 90000.0);
+		if (pes->optional->PTS_DTS & 1)
+			dvb_loginfo("   - dts                      %lx (%fs)", pes->optional->dts, (float) pes->optional->dts/ 90000.0);
+	}
+}
+
diff --git a/lib/libdvbv5/descriptors/mpeg_ts.c b/lib/libdvbv5/descriptors/mpeg_ts.c
new file mode 100644
index 0000000..497233d
--- /dev/null
+++ b/lib/libdvbv5/descriptors/mpeg_ts.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#include "descriptors/mpeg_ts.h"
+#include "descriptors.h"
+#include "dvb-fe.h"
+
+ssize_t dvb_mpeg_ts_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length)
+{
+	struct dvb_mpeg_ts *ts = (struct dvb_mpeg_ts *) table;
+	const uint8_t *p = buf;
+
+	if (buf[0] != DVB_MPEG_TS) {
+		dvb_logerr("mpeg ts invalid marker %#02x, sould be %#02x", buf[0], DVB_MPEG_TS);
+		*table_length = 0;
+		return -1;
+	}
+
+	memcpy(table, p, sizeof(struct dvb_mpeg_ts));
+	p += sizeof(struct dvb_mpeg_ts);
+
+	bswap16(ts->bitfield);
+
+	if (ts->adaptation_field) {
+		memcpy(ts->adaption, p, sizeof(struct dvb_mpeg_ts_adaption));
+		p += ts->adaption->length + 1;
+		/* FIXME: copy adaption->lenght bytes */
+	}
+
+	*table_length = p - buf;
+	return p - buf;
+}
+
+void dvb_mpeg_ts_free(struct dvb_mpeg_ts *ts)
+{
+	free(ts);
+}
+
+void dvb_mpeg_ts_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_ts *ts)
+{
+	dvb_loginfo("MPEG TS");
+	dvb_loginfo(" - sync byte       0x%02x", ts->sync_byte);
+	dvb_loginfo(" - tei                %d", ts->tei);
+	dvb_loginfo(" - payload_start      %d", ts->payload_start);
+	dvb_loginfo(" - priority           %d", ts->priority);
+	dvb_loginfo(" - pid           0x%04x", ts->pid);
+	dvb_loginfo(" - scrambling         %d", ts->scrambling);
+	dvb_loginfo(" - adaptation_field   %d", ts->adaptation_field);
+	dvb_loginfo(" - payload present    %d", ts->payload);
+	dvb_loginfo(" - continuity_counter %d", ts->continuity_counter);
+	if (ts->adaptation_field) {
+		dvb_loginfo(" Adaption Field");
+                dvb_loginfo("   - length         %d", ts->adaption->length);
+                dvb_loginfo("   - discontinued   %d", ts->adaption->discontinued);
+                dvb_loginfo("   - random_access  %d", ts->adaption->random_access);
+                dvb_loginfo("   - priority       %d", ts->adaption->priority);
+                dvb_loginfo("   - PCR            %d", ts->adaption->PCR);
+                dvb_loginfo("   - OPCR           %d", ts->adaption->OPCR);
+                dvb_loginfo("   - splicing_point %d", ts->adaption->splicing_point);
+                dvb_loginfo("   - private_data   %d", ts->adaption->private_data);
+                dvb_loginfo("   - extension      %d", ts->adaption->extension);
+	}
+}
+
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 04/11] libdvbv5: fix EIT parsing
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
  2014-03-25 18:19 ` [PATCH 02/11] libdvbv5: fix asprintf compile warnings André Roth
  2014-03-25 18:19 ` [PATCH 03/11] libdvbv5: mpeg elementary stream parsers André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:19 ` [PATCH 06/11] libdvbv5: remove header files from SOURCES in Makefile.am André Roth
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

the dvb_table_eit_event now contains the service_id,
indicating where the events belong to.

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/descriptors/eit.h  |  3 ++-
 lib/libdvbv5/descriptors/eit.c | 35 ++++++++++++++++++++++++++---------
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/lib/include/descriptors/eit.h b/lib/include/descriptors/eit.h
index 9a1a637..e0ecee3 100644
--- a/lib/include/descriptors/eit.h
+++ b/lib/include/descriptors/eit.h
@@ -40,7 +40,7 @@
 struct dvb_table_eit_event {
 	uint16_t event_id;
 	union {
-		uint16_t bitfield;
+		uint16_t bitfield1; /* first 2 bytes are MJD, they need to be bswapped */
 		uint8_t dvbstart[5];
 	} __attribute__((packed));
 	uint8_t dvbduration[3];
@@ -56,6 +56,7 @@ struct dvb_table_eit_event {
 	struct dvb_table_eit_event *next;
 	struct tm start;
 	uint32_t duration;
+	uint16_t service_id;
 } __attribute__((packed));
 
 struct dvb_table_eit {
diff --git a/lib/libdvbv5/descriptors/eit.c b/lib/libdvbv5/descriptors/eit.c
index 64a8897..123dc91 100644
--- a/lib/libdvbv5/descriptors/eit.c
+++ b/lib/libdvbv5/descriptors/eit.c
@@ -29,6 +29,11 @@ void dvb_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize
 	struct dvb_table_eit_event **head;
 
 	if (*table_length > 0) {
+		memcpy(eit, p, sizeof(struct dvb_table_eit) - sizeof(eit->event));
+
+		bswap16(eit->transport_id);
+		bswap16(eit->network_id);
+
 		/* find end of curent list */
 		head = &eit->event;
 		while (*head != NULL)
@@ -48,18 +53,30 @@ void dvb_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize
 	struct dvb_table_eit_event *last = NULL;
 	while ((uint8_t *) p < buf + buflen - 4) {
 		struct dvb_table_eit_event *event = (struct dvb_table_eit_event *) malloc(sizeof(struct dvb_table_eit_event));
-		memcpy(event, p, sizeof(struct dvb_table_eit_event) - sizeof(event->descriptor) - sizeof(event->next) - sizeof(event->start) - sizeof(event->duration));
-		p += sizeof(struct dvb_table_eit_event) - sizeof(event->descriptor) - sizeof(event->next) - sizeof(event->start) - sizeof(event->duration);
+		memcpy(event, p, sizeof(struct dvb_table_eit_event) -
+				 sizeof(event->descriptor) -
+				 sizeof(event->next) -
+				 sizeof(event->start) -
+				 sizeof(event->duration) -
+				 sizeof(event->service_id));
+		p += sizeof(struct dvb_table_eit_event) -
+		     sizeof(event->descriptor) -
+		     sizeof(event->next) -
+		     sizeof(event->start) -
+		     sizeof(event->duration) -
+		     sizeof(event->service_id);
 
 		bswap16(event->event_id);
-		bswap16(event->bitfield);
+		bswap16(event->bitfield1);
 		bswap16(event->bitfield2);
 		event->descriptor = NULL;
 		event->next = NULL;
 		dvb_time(event->dvbstart, &event->start);
-		event->duration = bcd(event->dvbduration[0]) * 3600 +
-				  bcd(event->dvbduration[1]) * 60 +
-				  bcd(event->dvbduration[2]);
+		event->duration = bcd((uint32_t) event->dvbduration[0]) * 3600 +
+				  bcd((uint32_t) event->dvbduration[1]) * 60 +
+				  bcd((uint32_t) event->dvbduration[2]);
+
+		event->service_id = eit->header.id;
 
 		if(!*head)
 			*head = event;
@@ -102,6 +119,7 @@ void dvb_table_eit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_eit *ei
 		char start[255];
 		strftime(start, sizeof(start), "%F %T", &event->start);
 		dvb_log("|- %7d", event->event_id);
+		dvb_log("|   Service               %d", event->service_id);
 		dvb_log("|   Start                 %s UTC", start);
 		dvb_log("|   Duration              %dh %dm %ds", event->duration / 3600, (event->duration % 3600) / 60, event->duration % 60);
 		dvb_log("|   free CA mode          %d", event->free_CA_mode);
@@ -137,9 +155,8 @@ void dvb_time(const uint8_t data[5], struct tm *tm)
   tm->tm_mday  = day;
   tm->tm_mon   = month - 1;
   tm->tm_year  = year;
-  tm->tm_isdst = -1;
-  tm->tm_wday  = 0;
-  tm->tm_yday  = 0;
+  tm->tm_isdst = 1; /* dst in effect, do not adjust */
+  mktime( tm );
 }
 
 
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 06/11] libdvbv5: remove header files from SOURCES in Makefile.am
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
                   ` (2 preceding siblings ...)
  2014-03-25 18:19 ` [PATCH 04/11] libdvbv5: fix EIT parsing André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:19 ` [PATCH 07/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private André Roth
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

The header files are not needed in the Makefile.am since
automake finds the dependencies automatically. This is not
needed for installing header files either.

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/libdvbv5/Makefile.am | 87 ++++++++++++++++++++++++------------------------
 1 file changed, 43 insertions(+), 44 deletions(-)

diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index ddf9ea1..8f89531 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -52,52 +52,51 @@ noinst_LTLIBRARIES = libdvbv5.la
 endif
 
 libdvbv5_la_SOURCES = \
-	crc32.c crc32.h \
-	../include/dvb-frontend.h \
+	crc32.c \
 	dvb-legacy-channel-format.c \
 	dvb-zap-format.c \
-	dvb-v5.c	dvb-v5.h \
-	parse_string.c	parse_string.h \
-	dvb-demux.c	../include/dvb-demux.h \
-	dvb-fe.c	../include/dvb-fe.h \
-	dvb-log.c	../include/dvb-log.h \
-	dvb-file.c	../include/dvb-file.h \
-	dvb-v5-std.c	../include/dvb-v5-std.h \
-	dvb-sat.c	../include/dvb-sat.h \
-	dvb-scan.c	../include/dvb-scan.h \
-	descriptors.c	../include/descriptors.h \
-	descriptors/header.c		../include/libdvbv5/header.h \
-	descriptors/atsc_header.c	../include/libdvbv5/atsc_header.h \
-	descriptors/pat.c		../include/libdvbv5/pat.h \
-	descriptors/pmt.c		../include/libdvbv5/pmt.h \
-	descriptors/nit.c		../include/libdvbv5/nit.h \
-	descriptors/sdt.c		../include/libdvbv5/sdt.h \
-	descriptors/vct.c		../include/libdvbv5/vct.h \
-	descriptors/mgt.c		../include/libdvbv5/mgt.h \
-	descriptors/eit.c		../include/libdvbv5/eit.h \
-	descriptors/atsc_eit.c		../include/libdvbv5/atsc_eit.h \
-	descriptors/desc_language.c		../include/libdvbv5/desc_language.h \
-	descriptors/desc_network_name.c		../include/libdvbv5/desc_network_name.h \
-	descriptors/desc_cable_delivery.c	../include/libdvbv5/desc_cable_delivery.h \
-	descriptors/desc_sat.c			../include/libdvbv5/desc_sat.h \
-	descriptors/desc_terrestrial_delivery.c  ../include/libdvbv5/desc_terrestrial_delivery.h \
-	descriptors/desc_t2_delivery.c		../include/libdvbv5/desc_t2_delivery.h \
-	descriptors/desc_service.c		../include/libdvbv5/desc_service.h \
-	descriptors/desc_frequency_list.c	../include/libdvbv5/desc_frequency_list.h \
-	descriptors/desc_service_list.c		../include/libdvbv5/desc_service_list.h \
-	descriptors/desc_event_short.c		../include/libdvbv5/desc_event_short.h \
-	descriptors/desc_event_extended.c	../include/libdvbv5/desc_event_extended.h \
-	descriptors/desc_atsc_service_location.c ../include/libdvbv5/desc_atsc_service_location.h \
-	descriptors/desc_hierarchy.c		../include/libdvbv5/desc_hierarchy.h \
-	descriptors/desc_extension.c		../include/libdvbv5/desc_extension.h \
-	descriptors/desc_isdbt_delivery.c	../include/libdvbv5/desc_isdbt_delivery.h \
-	descriptors/desc_logical_channel.c	../include/libdvbv5/desc_logical_channel.h \
-	descriptors/desc_ts_info.c		../include/libdvbv5/desc_ts_info.h \
-	descriptors/desc_partial_reception.c	../include/libdvbv5/desc_partial_reception.h \
-	descriptors/desc_service_location.c	../include/libdvbv5/desc_service_location.h \
-	descriptors/mpeg_ts.c		../include/libdvbv5/mpeg_ts.h \
-	descriptors/mpeg_pes.c		../include/libdvbv5/mpeg_pes.h \
-	descriptors/mpeg_es.c		../include/libdvbv5/mpeg_es.h
+	dvb-v5.c	 \
+	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/atsc_header.c	\
+	descriptors/pat.c		\
+	descriptors/pmt.c		\
+	descriptors/nit.c		\
+	descriptors/sdt.c		\
+	descriptors/vct.c		\
+	descriptors/mgt.c		\
+	descriptors/eit.c		\
+	descriptors/atsc_eit.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_t2_delivery.c		\
+	descriptors/desc_service.c		\
+	descriptors/desc_frequency_list.c	\
+	descriptors/desc_service_list.c		\
+	descriptors/desc_event_short.c		\
+	descriptors/desc_event_extended.c	\
+	descriptors/desc_atsc_service_location.c \
+	descriptors/desc_hierarchy.c		\
+	descriptors/desc_extension.c		\
+	descriptors/desc_isdbt_delivery.c	\
+	descriptors/desc_logical_channel.c	\
+	descriptors/desc_ts_info.c		\
+	descriptors/desc_partial_reception.c	\
+	descriptors/desc_service_location.c	\
+	descriptors/mpeg_ts.c		\
+	descriptors/mpeg_pes.c		\
+	descriptors/mpeg_es.c
 
 libdvbv5_la_CPPFLAGS = -I../.. $(ENFORCE_LIBDVBV5_STATIC)
 libdvbv5_la_LDFLAGS = $(LIBDVBV5_VERSION) $(ENFORCE_LIBDVBV5_STATIC) -lm
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 07/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
                   ` (3 preceding siblings ...)
  2014-03-25 18:19 ` [PATCH 06/11] libdvbv5: remove header files from SOURCES in Makefile.am André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:19 ` [PATCH 08/11] libdvbv5: add attribute packed to structs and unions André Roth
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

- set list pointer to NULL in case of an error
- improve size checking
- dvb_desc_init is used only internal, remove from header

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/libdvbv5/descriptors.h |  2 --
 lib/libdvbv5/descriptors.c         | 44 ++++++++++++++++++--------------------
 2 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/lib/include/libdvbv5/descriptors.h b/lib/include/libdvbv5/descriptors.h
index b482fa0..f4d9288 100644
--- a/lib/include/libdvbv5/descriptors.h
+++ b/lib/include/libdvbv5/descriptors.h
@@ -78,8 +78,6 @@ void dvb_desc_default_print  (struct dvb_v5_fe_parms *parms, const struct dvb_de
 	for( _struct *_desc = (_struct *) _tbl->descriptor; _desc; _desc = (_struct *) _desc->next ) \
 		if(_desc->type == _type) \
 
-ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc);
-
 uint32_t bcd(uint32_t bcd);
 
 void hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned char *buf, int len);
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index 91cc4a6..e611876 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -56,12 +56,11 @@
 #include <libdvbv5/desc_partial_reception.h>
 #include <libdvbv5/desc_extension.h>
 
-ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc)
+static void dvb_desc_init(uint8_t type, uint8_t length, struct dvb_desc *desc)
 {
-	desc->type   = buf[0];
-	desc->length = buf[1];
+	desc->type   = type;
+	desc->length = length;
 	desc->next   = NULL;
-	return 2;
 }
 
 void dvb_desc_default_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
@@ -94,17 +93,27 @@ char *default_charset = "iso-8859-1";
 char *output_charset = "utf-8";
 
 void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
-			   uint16_t section_length, struct dvb_desc **head_desc)
+			   uint16_t buflen, struct dvb_desc **head_desc)
 {
-	const uint8_t *ptr = buf;
+	const uint8_t *ptr = buf, *endbuf = buf + buflen;
 	struct dvb_desc *current = NULL;
 	struct dvb_desc *last = NULL;
 
-	while (ptr + 2 < buf + section_length) {
-		unsigned desc_type = ptr[0];
-		int desc_len  = ptr[1];
+	*head_desc = NULL;
+
+	while (ptr + 2 <= endbuf ) {
+		uint8_t desc_type = ptr[0];
+		uint8_t desc_len  = ptr[1];
 		size_t size;
 
+		ptr += 2; /* skip type and length */
+
+		if (ptr + desc_len > endbuf) {
+			dvb_logerr("short read of %zd/%d bytes parsing descriptor %#02x",
+				   endbuf - ptr, desc_len, desc_type);
+			return;
+		}
+
 		switch (parms->verbose) {
 		case 0:
 		case 1:
@@ -120,12 +129,6 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 			hexdump(parms, "content: ", ptr + 2, desc_len);
 		}
 
-		if (desc_len > section_length - 2) {
-			dvb_logwarn("descriptor type 0x%02x is too big",
-				   desc_type);
-			return;
-		}
-
 		dvb_desc_init_func init = dvb_descriptors[desc_type].init;
 		if (!init) {
 			init = dvb_desc_default_init;
@@ -134,21 +137,16 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 			size = dvb_descriptors[desc_type].size;
 		}
 		if (!size) {
-			dvb_logwarn("descriptor type 0x%02x has no size defined", desc_type);
-			size = 4096;
-		}
-		if (ptr + 2 >=  buf + section_length) {
-			dvb_logwarn("descriptor type 0x%02x is truncated: desc len %d, section len %zd",
-				   desc_type, desc_len, section_length - (ptr - buf));
+			dvb_logerr("descriptor type 0x%02x has no size defined", desc_type);
 			return;
 		}
 
-		current = calloc(1, size);
+		current = malloc(size);
 		if (!current) {
 			dvb_perror("Out of memory");
 			return;
 		}
-		ptr += dvb_desc_init(ptr, current); /* the standard header was read */
+		dvb_desc_init(desc_type, desc_len, current); /* initialize the standard header */
 		init(parms, ptr, current);
 		if (!*head_desc)
 			*head_desc = current;
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 08/11] libdvbv5: add attribute packed to structs and unions
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
                   ` (4 preceding siblings ...)
  2014-03-25 18:19 ` [PATCH 07/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:19 ` [PATCH 09/11] libdvbv5: add parser for CAT André Roth
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

__attribute__((packed)) is needed for nested structs and
unions to get the correct size.

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/libdvbv5/atsc_header.h                |  2 +-
 lib/include/libdvbv5/desc_atsc_service_location.h |  4 ++--
 lib/include/libdvbv5/desc_cable_delivery.h        |  8 ++++----
 lib/include/libdvbv5/desc_event_extended.h        |  4 ++--
 lib/include/libdvbv5/desc_frequency_list.h        |  4 ++--
 lib/include/libdvbv5/desc_isdbt_delivery.h        |  4 ++--
 lib/include/libdvbv5/desc_logical_channel.h       |  4 ++--
 lib/include/libdvbv5/desc_sat.h                   |  4 ++--
 lib/include/libdvbv5/desc_t2_delivery.h           |  4 ++--
 lib/include/libdvbv5/header.h                     |  4 ++--
 lib/include/libdvbv5/mpeg_es.h                    |  6 +++---
 lib/include/libdvbv5/mpeg_ts.h                    |  2 +-
 lib/include/libdvbv5/nit.h                        |  4 ++--
 lib/include/libdvbv5/pat.h                        |  2 +-
 lib/include/libdvbv5/pmt.h                        | 16 ++++++++--------
 lib/include/libdvbv5/sdt.h                        |  2 +-
 lib/include/libdvbv5/vct.h                        |  4 ++--
 17 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/lib/include/libdvbv5/atsc_header.h b/lib/include/libdvbv5/atsc_header.h
index 1e7148e..9685b37 100644
--- a/lib/include/libdvbv5/atsc_header.h
+++ b/lib/include/libdvbv5/atsc_header.h
@@ -36,7 +36,7 @@ struct atsc_table_header {
 			uint16_t priv:1;
 			uint16_t syntax:1;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	uint16_t id;
 	uint8_t  current_next:1;
 	uint8_t  version:5;
diff --git a/lib/include/libdvbv5/desc_atsc_service_location.h b/lib/include/libdvbv5/desc_atsc_service_location.h
index 47113f2..1ff2341 100644
--- a/lib/include/libdvbv5/desc_atsc_service_location.h
+++ b/lib/include/libdvbv5/desc_atsc_service_location.h
@@ -32,7 +32,7 @@ struct atsc_desc_service_location_elementary {
 			uint16_t elementary_pid:13;
 			uint16_t reserved:3;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	char ISO_639_language_code[3];
 } __attribute__((packed));
 
@@ -49,7 +49,7 @@ struct atsc_desc_service_location {
 			uint16_t pcr_pid:13;
 			uint16_t reserved:3;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 
 	uint8_t number_elements;
 } __attribute__((packed));
diff --git a/lib/include/libdvbv5/desc_cable_delivery.h b/lib/include/libdvbv5/desc_cable_delivery.h
index b4aa037..7abe920 100644
--- a/lib/include/libdvbv5/desc_cable_delivery.h
+++ b/lib/include/libdvbv5/desc_cable_delivery.h
@@ -37,16 +37,16 @@ struct dvb_desc_cable_delivery {
 		struct {
 			uint16_t fec_outer:4;
 			uint16_t reserved_future_use:12;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 	uint8_t modulation;
 	union {
 		uint32_t bitfield2;
 		struct {
 			uint32_t fec_inner:4;
 			uint32_t symbol_rate:28;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
diff --git a/lib/include/libdvbv5/desc_event_extended.h b/lib/include/libdvbv5/desc_event_extended.h
index 306c2ab..286f91d 100644
--- a/lib/include/libdvbv5/desc_event_extended.h
+++ b/lib/include/libdvbv5/desc_event_extended.h
@@ -34,9 +34,9 @@ struct dvb_desc_event_extended {
 		struct {
 			uint8_t last_id:4;
 			uint8_t id:4;
-		};
+		} __attribute__((packed));
 		uint8_t ids;
-	};
+	} __attribute__((packed));
 
 	unsigned char language[4];
 	char *text;
diff --git a/lib/include/libdvbv5/desc_frequency_list.h b/lib/include/libdvbv5/desc_frequency_list.h
index 26d078a..a138e56 100644
--- a/lib/include/libdvbv5/desc_frequency_list.h
+++ b/lib/include/libdvbv5/desc_frequency_list.h
@@ -38,8 +38,8 @@ struct dvb_desc_frequency_list {
 		struct {
 			uint8_t freq_type:2;
 			uint8_t reserved:6;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
diff --git a/lib/include/libdvbv5/desc_isdbt_delivery.h b/lib/include/libdvbv5/desc_isdbt_delivery.h
index 4df30df..5bac178 100644
--- a/lib/include/libdvbv5/desc_isdbt_delivery.h
+++ b/lib/include/libdvbv5/desc_isdbt_delivery.h
@@ -38,8 +38,8 @@ struct isdbt_desc_terrestrial_delivery_system {
 			uint16_t transmission_mode:2;
 			uint16_t guard_interval:2;
 			uint16_t area_code:6;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
diff --git a/lib/include/libdvbv5/desc_logical_channel.h b/lib/include/libdvbv5/desc_logical_channel.h
index ce1206c..bbccb81 100644
--- a/lib/include/libdvbv5/desc_logical_channel.h
+++ b/lib/include/libdvbv5/desc_logical_channel.h
@@ -36,8 +36,8 @@ struct dvb_desc_logical_channel_number {
 			uint16_t logical_channel_number:10;
 			uint16_t reserved:5;
 			uint16_t visible_service_flag:1;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_desc_logical_channel {
diff --git a/lib/include/libdvbv5/desc_sat.h b/lib/include/libdvbv5/desc_sat.h
index d28841b..cf6393f 100644
--- a/lib/include/libdvbv5/desc_sat.h
+++ b/lib/include/libdvbv5/desc_sat.h
@@ -42,8 +42,8 @@ struct dvb_desc_sat {
 		struct {
 			uint32_t fec:4;
 			uint32_t symbol_rate:28;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
diff --git a/lib/include/libdvbv5/desc_t2_delivery.h b/lib/include/libdvbv5/desc_t2_delivery.h
index a36f6c1..a51f897 100644
--- a/lib/include/libdvbv5/desc_t2_delivery.h
+++ b/lib/include/libdvbv5/desc_t2_delivery.h
@@ -43,8 +43,8 @@ struct dvb_desc_t2_delivery {
 			uint16_t reserved:2;
 			uint16_t bandwidth:3;
 			uint16_t SISO_MISO:2;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 
 	uint32_t *centre_frequency;
 	uint8_t frequency_loop_length;
diff --git a/lib/include/libdvbv5/header.h b/lib/include/libdvbv5/header.h
index 8ba93b0..67b7694 100644
--- a/lib/include/libdvbv5/header.h
+++ b/lib/include/libdvbv5/header.h
@@ -36,7 +36,7 @@ struct dvb_ts_packet_header {
 			uint16_t payload_unit_start_indicator:1;
 			uint16_t transport_error_indicator:1;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	uint8_t continuity_counter:4;
 	uint8_t adaptation_field_control:2;
 	uint8_t transport_scrambling_control:2;
@@ -56,7 +56,7 @@ struct dvb_table_header {
 			uint8_t  zero2:1;
 			uint8_t  syntax:1;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	uint16_t id;			/* TS ID */
 	uint8_t  current_next:1;
 	uint8_t  version:5;
diff --git a/lib/include/libdvbv5/mpeg_es.h b/lib/include/libdvbv5/mpeg_es.h
index 4c6a862..4f1786e 100644
--- a/lib/include/libdvbv5/mpeg_es.h
+++ b/lib/include/libdvbv5/mpeg_es.h
@@ -47,7 +47,7 @@ struct dvb_mpeg_es_seq_start {
 			uint32_t height:12;
 			uint32_t width:12;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	union {
 		uint32_t bitfield3;
 		struct {
@@ -58,7 +58,7 @@ struct dvb_mpeg_es_seq_start {
 			uint32_t one:1;
 			uint32_t bitrate:18;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_mpeg_es_pic_start {
@@ -77,7 +77,7 @@ struct dvb_mpeg_es_pic_start {
 			uint32_t coding_type:3;
 			uint32_t temporal_ref:10;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 } __attribute__((packed));
 
 enum dvb_mpeg_es_frame_t
diff --git a/lib/include/libdvbv5/mpeg_ts.h b/lib/include/libdvbv5/mpeg_ts.h
index aca97aa..3eab029 100644
--- a/lib/include/libdvbv5/mpeg_ts.h
+++ b/lib/include/libdvbv5/mpeg_ts.h
@@ -52,7 +52,7 @@ struct dvb_mpeg_ts {
 			uint16_t payload_start:1;
 			uint16_t tei:1;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	struct {
 		uint8_t continuity_counter:4;
 		uint8_t payload:1;
diff --git a/lib/include/libdvbv5/nit.h b/lib/include/libdvbv5/nit.h
index a2c4950..af57931 100644
--- a/lib/include/libdvbv5/nit.h
+++ b/lib/include/libdvbv5/nit.h
@@ -49,7 +49,7 @@ struct dvb_table_nit_transport {
 			uint16_t section_length:12;
 			uint16_t reserved:4;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	struct dvb_desc *descriptor;
 	struct dvb_table_nit_transport *next;
 } __attribute__((packed));
@@ -62,7 +62,7 @@ struct dvb_table_nit {
 			uint16_t desc_length:12;
 			uint16_t reserved:4;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	struct dvb_desc *descriptor;
 	struct dvb_table_nit_transport *transport;
 } __attribute__((packed));
diff --git a/lib/include/libdvbv5/pat.h b/lib/include/libdvbv5/pat.h
index a3f9b30..4c1fd4d 100644
--- a/lib/include/libdvbv5/pat.h
+++ b/lib/include/libdvbv5/pat.h
@@ -38,7 +38,7 @@ struct dvb_table_pat_program {
 			uint16_t pid:13;
 			uint8_t  reserved:3;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	struct dvb_table_pat_program *next;
 } __attribute__((packed));
 
diff --git a/lib/include/libdvbv5/pmt.h b/lib/include/libdvbv5/pmt.h
index 59debf0..07b77ce 100644
--- a/lib/include/libdvbv5/pmt.h
+++ b/lib/include/libdvbv5/pmt.h
@@ -64,16 +64,16 @@ struct dvb_table_pmt_stream {
 		struct {
 			uint16_t elementary_pid:13;
 			uint16_t reserved:3;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 	union {
 		uint16_t bitfield2;
 		struct {
 			uint16_t section_length:10;
 			uint16_t zero:2;
 			uint16_t reserved2:4;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 	struct dvb_desc *descriptor;
 	struct dvb_table_pmt_stream *next;
 } __attribute__((packed));
@@ -85,8 +85,8 @@ struct dvb_table_pmt {
 		struct {
 			uint16_t pcr_pid:13;
 			uint16_t reserved2:3;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 
 	union {
 		uint16_t bitfield2;
@@ -94,8 +94,8 @@ struct dvb_table_pmt {
 			uint16_t prog_length:10;
 			uint16_t zero3:2;
 			uint16_t reserved3:4;
-		};
-	};
+		} __attribute__((packed));
+	} __attribute__((packed));
 	struct dvb_table_pmt_stream *stream;
 } __attribute__((packed));
 
diff --git a/lib/include/libdvbv5/sdt.h b/lib/include/libdvbv5/sdt.h
index 3d5b1d7..2b3e8e0 100644
--- a/lib/include/libdvbv5/sdt.h
+++ b/lib/include/libdvbv5/sdt.h
@@ -44,7 +44,7 @@ struct dvb_table_sdt_service {
 			uint16_t free_CA_mode:1;
 			uint16_t running_status:3;
 		} __attribute__((packed));
-	};
+	} __attribute__((packed));
 	struct dvb_desc *descriptor;
 	struct dvb_table_sdt_service *next;
 } __attribute__((packed));
diff --git a/lib/include/libdvbv5/vct.h b/lib/include/libdvbv5/vct.h
index 8044af1..fd7b845 100644
--- a/lib/include/libdvbv5/vct.h
+++ b/lib/include/libdvbv5/vct.h
@@ -103,8 +103,8 @@ union atsc_table_vct_descriptor_length {
 	struct {
 		uint16_t descriptor_length:10;
 		uint16_t reserved:6;
-	};
-};
+	} __attribute__((packed));
+} __attribute__((packed));
 
 #define atsc_vct_channel_foreach(_channel, _vct) \
 	for (struct atsc_table_vct_channel *_channel = _vct->channel; _channel; _channel = _channel->next) \
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 09/11] libdvbv5: add parser for CAT
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
                   ` (5 preceding siblings ...)
  2014-03-25 18:19 ` [PATCH 08/11] libdvbv5: add attribute packed to structs and unions André Roth
@ 2014-03-25 18:19 ` André Roth
  2014-03-25 18:20 ` [PATCH 10/11] libdvbv5: add parser for ca and ca_identifier descriptors André Roth
  2014-03-25 18:20 ` [PATCH 11/11] libdvbv5: fix PMT parser André Roth
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:19 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/libdvbv5/cat.h     | 51 ++++++++++++++++++++++++++++++
 lib/libdvbv5/Makefile.am       |  2 ++
 lib/libdvbv5/descriptors.c     |  2 ++
 lib/libdvbv5/descriptors/cat.c | 72 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 127 insertions(+)
 create mode 100644 lib/include/libdvbv5/cat.h
 create mode 100644 lib/libdvbv5/descriptors/cat.c

diff --git a/lib/include/libdvbv5/cat.h b/lib/include/libdvbv5/cat.h
new file mode 100644
index 0000000..4c442a8
--- /dev/null
+++ b/lib/include/libdvbv5/cat.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#ifndef _CAT_H
+#define _CAT_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+#include <libdvbv5/header.h>
+
+#define DVB_TABLE_CAT      0x01
+#define DVB_TABLE_CAT_PID  0x0001
+
+struct dvb_table_cat {
+	struct dvb_table_header header;
+	struct dvb_desc *descriptor;
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index 8f89531..0abe42d 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -39,6 +39,7 @@ otherinclude_HEADERS = \
 	../include/libdvbv5/atsc_header.h \
 	../include/libdvbv5/mgt.h \
 	../include/libdvbv5/eit.h \
+	../include/libdvbv5/cat.h \
 	../include/libdvbv5/atsc_eit.h \
 	../include/libdvbv5/desc_service_location.h \
 	../include/libdvbv5/mpeg_ts.h \
@@ -74,6 +75,7 @@ libdvbv5_la_SOURCES = \
 	descriptors/vct.c		\
 	descriptors/mgt.c		\
 	descriptors/eit.c		\
+	descriptors/cat.c		\
 	descriptors/atsc_eit.c		\
 	descriptors/desc_language.c		\
 	descriptors/desc_network_name.c		\
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index e611876..ba83d41 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -31,6 +31,7 @@
 #include <libdvbv5/dvb-log.h>
 
 #include <libdvbv5/pat.h>
+#include <libdvbv5/cat.h>
 #include <libdvbv5/pmt.h>
 #include <libdvbv5/nit.h>
 #include <libdvbv5/sdt.h>
@@ -78,6 +79,7 @@ void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc
 
 const struct dvb_table_init dvb_table_initializers[] = {
 	[DVB_TABLE_PAT]          = { dvb_table_pat_init, sizeof(struct dvb_table_pat) },
+	[DVB_TABLE_CAT]          = { dvb_table_cat_init, sizeof(struct dvb_table_cat) },
 	[DVB_TABLE_PMT]          = { dvb_table_pmt_init, sizeof(struct dvb_table_pmt) },
 	[DVB_TABLE_NIT]          = { dvb_table_nit_init, sizeof(struct dvb_table_nit) },
 	[DVB_TABLE_SDT]          = { dvb_table_sdt_init, sizeof(struct dvb_table_sdt) },
diff --git a/lib/libdvbv5/descriptors/cat.c b/lib/libdvbv5/descriptors/cat.c
new file mode 100644
index 0000000..4069923
--- /dev/null
+++ b/lib/libdvbv5/descriptors/cat.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#include <libdvbv5/cat.h>
+#include <libdvbv5/descriptors.h>
+#include <libdvbv5/dvb-fe.h>
+
+void dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
+			ssize_t buflen, uint8_t *table, ssize_t *table_length)
+{
+	struct dvb_table_cat *cat = (void *)table;
+	struct dvb_desc **head_desc = &cat->descriptor;
+	const uint8_t *p = buf, *endbuf = buf + buflen - 4;
+	size_t size;
+
+	if (buf[0] != DVB_TABLE_CAT) {
+		dvb_logerr("%s: invalid marker 0x%02x, sould be 0x%02x", __func__, buf[0], DVB_TABLE_CAT);
+		*table_length = 0;
+		return;
+	}
+
+	if (*table_length > 0) {
+		/* find end of current lists */
+		while (*head_desc != NULL)
+			head_desc = &(*head_desc)->next;
+	}
+
+	size = offsetof(struct dvb_table_cat, descriptor);
+	if (p + size > endbuf) {
+		dvb_logerr("CAT table was truncated while filling dvb_table_cat. Need %zu bytes, but has only %zu.",
+			   size, buflen);
+		return;
+	}
+
+	memcpy(table, p, size);
+	p += size;
+	*table_length = sizeof(struct dvb_table_cat);
+
+	size = endbuf - p;
+	dvb_parse_descriptors(parms, p, size, head_desc);
+}
+
+void dvb_table_cat_free(struct dvb_table_cat *cat)
+{
+	dvb_free_descriptors((struct dvb_desc **) &cat->descriptor);
+	free(cat);
+}
+
+void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat *cat)
+{
+	dvb_log("cat");
+	dvb_table_header_print(parms, &cat->header);
+	dvb_print_descriptors(parms, cat->descriptor);
+}
+
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 10/11] libdvbv5: add parser for ca and ca_identifier descriptors
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
                   ` (6 preceding siblings ...)
  2014-03-25 18:19 ` [PATCH 09/11] libdvbv5: add parser for CAT André Roth
@ 2014-03-25 18:20 ` André Roth
  2014-03-25 18:20 ` [PATCH 11/11] libdvbv5: fix PMT parser André Roth
  8 siblings, 0 replies; 14+ messages in thread
From: André Roth @ 2014-03-25 18:20 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/libdvbv5/desc_ca.h                | 63 ++++++++++++++++++++++++++
 lib/include/libdvbv5/desc_ca_identifier.h     | 55 +++++++++++++++++++++++
 lib/libdvbv5/Makefile.am                      | 10 +++--
 lib/libdvbv5/descriptors.c                    | 18 ++++----
 lib/libdvbv5/descriptors/desc_ca.c            | 64 +++++++++++++++++++++++++++
 lib/libdvbv5/descriptors/desc_ca_identifier.c | 58 ++++++++++++++++++++++++
 6 files changed, 257 insertions(+), 11 deletions(-)
 create mode 100644 lib/include/libdvbv5/desc_ca.h
 create mode 100644 lib/include/libdvbv5/desc_ca_identifier.h
 create mode 100644 lib/libdvbv5/descriptors/desc_ca.c
 create mode 100644 lib/libdvbv5/descriptors/desc_ca_identifier.c

diff --git a/lib/include/libdvbv5/desc_ca.h b/lib/include/libdvbv5/desc_ca.h
new file mode 100644
index 0000000..12f4ff3
--- /dev/null
+++ b/lib/include/libdvbv5/desc_ca.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Described at ETSI EN 300 468 V1.11.1 (2010-04)
+ */
+
+#ifndef _CA_H
+#define _CA_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+struct dvb_desc_ca {
+	uint8_t type;
+	uint8_t length;
+	struct dvb_desc *next;
+
+	uint16_t ca_id;
+	union {
+		uint16_t bitfield1;
+		struct {
+			uint16_t ca_pid:13;
+			uint16_t reserved:3;
+		} __attribute__((packed));
+	} __attribute__((packed));
+
+	uint8_t *privdata;
+	uint8_t privdata_len;
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#define dvb_desc_ca_field_first ca_id
+#define dvb_desc_ca_field_last  privdata
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void dvb_desc_ca_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc);
+void dvb_desc_ca_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc);
+void dvb_desc_ca_free (struct dvb_desc *desc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/include/libdvbv5/desc_ca_identifier.h b/lib/include/libdvbv5/desc_ca_identifier.h
new file mode 100644
index 0000000..18df191
--- /dev/null
+++ b/lib/include/libdvbv5/desc_ca_identifier.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Described at ETSI EN 300 468 V1.11.1 (2010-04)
+ */
+
+#ifndef _CA_IDENTIFIER_H
+#define _CA_IDENTIFIER_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+struct dvb_desc_ca_identifier {
+	uint8_t type;
+	uint8_t length;
+	struct dvb_desc *next;
+
+	uint8_t caid_count;
+	uint16_t *caids;
+
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#define dvb_desc_ca_identifier_field_first ca_id
+#define dvb_desc_ca_identifier_field_last  privdata
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void dvb_desc_ca_identifier_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc);
+void dvb_desc_ca_identifier_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc);
+void dvb_desc_ca_identifier_free (struct dvb_desc *desc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index 0abe42d..667a1af 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -33,6 +33,9 @@ otherinclude_HEADERS = \
 	../include/libdvbv5/desc_logical_channel.h \
 	../include/libdvbv5/desc_ts_info.h \
 	../include/libdvbv5/desc_partial_reception.h \
+	../include/libdvbv5/desc_service_location.h \
+	../include/libdvbv5/desc_ca.h \
+	../include/libdvbv5/desc_ca_identifier.h \
 	../include/libdvbv5/nit.h \
 	../include/libdvbv5/sdt.h \
 	../include/libdvbv5/vct.h \
@@ -41,7 +44,6 @@ otherinclude_HEADERS = \
 	../include/libdvbv5/eit.h \
 	../include/libdvbv5/cat.h \
 	../include/libdvbv5/atsc_eit.h \
-	../include/libdvbv5/desc_service_location.h \
 	../include/libdvbv5/mpeg_ts.h \
 	../include/libdvbv5/mpeg_pes.h \
 	../include/libdvbv5/mpeg_es.h
@@ -96,8 +98,10 @@ libdvbv5_la_SOURCES = \
 	descriptors/desc_ts_info.c		\
 	descriptors/desc_partial_reception.c	\
 	descriptors/desc_service_location.c	\
-	descriptors/mpeg_ts.c		\
-	descriptors/mpeg_pes.c		\
+	descriptors/desc_ca.c			\
+	descriptors/desc_ca_identifier.c	\
+	descriptors/mpeg_ts.c			\
+	descriptors/mpeg_pes.c			\
 	descriptors/mpeg_es.c
 
 libdvbv5_la_CPPFLAGS = -I../.. $(ENFORCE_LIBDVBV5_STATIC)
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index ba83d41..418576c 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -55,6 +55,8 @@
 #include <libdvbv5/desc_ts_info.h>
 #include <libdvbv5/desc_logical_channel.h>
 #include <libdvbv5/desc_partial_reception.h>
+#include <libdvbv5/desc_ca.h>
+#include <libdvbv5/desc_ca_identifier.h>
 #include <libdvbv5/desc_extension.h>
 
 static void dvb_desc_init(uint8_t type, uint8_t length, struct dvb_desc *desc)
@@ -242,10 +244,10 @@ const struct dvb_descriptor dvb_descriptors[] = {
 	},
 	[conditional_access_descriptor] = {
 		.name  = "conditional_access_descriptor",
-		.init  = NULL,
-		.print = NULL,
-		.free  = NULL,
-		.size  = 0,
+		.init  = dvb_desc_ca_init,
+		.print = dvb_desc_ca_print,
+		.free  = dvb_desc_ca_free,
+		.size  = sizeof(struct dvb_desc_ca),
 	},
 	[iso639_language_descriptor] = {
 		.name  = "iso639_language_descriptor",
@@ -571,10 +573,10 @@ const struct dvb_descriptor dvb_descriptors[] = {
 	},
 	[CA_identifier_descriptor] = {
 		.name  = "CA_identifier_descriptor",
-		.init  = NULL,
-		.print = NULL,
-		.free  = NULL,
-		.size  = 0,
+		.init  = dvb_desc_ca_identifier_init,
+		.print = dvb_desc_ca_identifier_print,
+		.free  = dvb_desc_ca_identifier_free,
+		.size  = sizeof(struct dvb_desc_ca_identifier),
 	},
 	[content_descriptor] = {
 		.name  = "content_descriptor",
diff --git a/lib/libdvbv5/descriptors/desc_ca.c b/lib/libdvbv5/descriptors/desc_ca.c
new file mode 100644
index 0000000..6b48175
--- /dev/null
+++ b/lib/libdvbv5/descriptors/desc_ca.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Described at ETSI EN 300 468 V1.11.1 (2010-04)
+ */
+
+#include <libdvbv5/desc_ca.h>
+#include <libdvbv5/descriptors.h>
+#include <libdvbv5/dvb-fe.h>
+
+void dvb_desc_ca_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
+{
+	size_t size = offsetof(struct dvb_desc_ca, dvb_desc_ca_field_last) - offsetof(struct dvb_desc_ca, dvb_desc_ca_field_first);
+	struct dvb_desc_ca *d = (struct dvb_desc_ca *) desc;
+
+	memcpy(((uint8_t *) d ) + sizeof(struct dvb_desc), buf, size);
+	bswap16(d->ca_id);
+	bswap16(d->bitfield1);
+
+	if (d->length > size) {
+		size = d->length - size;
+		d->privdata = malloc(size);
+		d->privdata_len = size;
+		memcpy(d->privdata, buf + 4, size);
+	} else {
+		d->privdata = NULL;
+		d->privdata_len = 0;
+	}
+	/*hexdump(parms, "desc ca ", buf, desc->length);*/
+	/*dvb_desc_ca_print(parms, desc);*/
+}
+
+void dvb_desc_ca_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc)
+{
+	const struct dvb_desc_ca *d = (const struct dvb_desc_ca *) desc;
+	dvb_log("|           ca_id             %04x", d->ca_id);
+	dvb_log("|           ca_pid            %04x", d->ca_pid);
+	dvb_log("|           privdata length   %d", d->privdata_len);
+	if (d->privdata)
+		hexdump(parms, "|           privdata          ", d->privdata, d->privdata_len);
+}
+
+void dvb_desc_ca_free(struct dvb_desc *desc)
+{
+	struct dvb_desc_ca *d = (struct dvb_desc_ca *) desc;
+	if (d->privdata)
+		free(d->privdata);
+}
+
diff --git a/lib/libdvbv5/descriptors/desc_ca_identifier.c b/lib/libdvbv5/descriptors/desc_ca_identifier.c
new file mode 100644
index 0000000..4740a01
--- /dev/null
+++ b/lib/libdvbv5/descriptors/desc_ca_identifier.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Described at ETSI EN 300 468 V1.11.1 (2010-04)
+ */
+
+#include <libdvbv5/desc_ca_identifier.h>
+#include <libdvbv5/descriptors.h>
+#include <libdvbv5/dvb-fe.h>
+
+void dvb_desc_ca_identifier_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
+{
+	struct dvb_desc_ca_identifier *d = (struct dvb_desc_ca_identifier *) desc;
+	int i;
+
+	d->caid_count = d->length >> 1; /* FIXME: warn if odd */
+	d->caids = malloc(d->length);
+	if (!d->caids) {
+		dvb_logerr("dvb_desc_ca_identifier_init: out of memory");
+		return;
+	}
+	for (i = 0; i < d->caid_count; i++) {
+		d->caids[i] = ((uint16_t *) buf)[i];
+		bswap16(d->caids[i]);
+	}
+}
+
+void dvb_desc_ca_identifier_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc)
+{
+	const struct dvb_desc_ca_identifier *d = (const struct dvb_desc_ca_identifier *) desc;
+	int i;
+
+	for (i = 0; i < d->caid_count; i++)
+		dvb_log("|           caid %d            %04x", i, d->caids[i]);
+}
+
+void dvb_desc_ca_identifier_free(struct dvb_desc *desc)
+{
+	struct dvb_desc_ca_identifier *d = (struct dvb_desc_ca_identifier *) desc;
+	if (d->caids)
+		free(d->caids);
+}
+
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 11/11] libdvbv5: fix PMT parser
  2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
                   ` (7 preceding siblings ...)
  2014-03-25 18:20 ` [PATCH 10/11] libdvbv5: add parser for ca and ca_identifier descriptors André Roth
@ 2014-03-25 18:20 ` André Roth
  2014-03-25 20:51   ` Bjørn Mork
  8 siblings, 1 reply; 14+ messages in thread
From: André Roth @ 2014-03-25 18:20 UTC (permalink / raw)
  To: LMML; +Cc: André Roth

- check for correct table ID
- parse all descriptos
- improve table printing

Signed-off-by: André Roth <neolynx@gmail.com>
---
 lib/include/libdvbv5/pmt.h     | 10 ++++--
 lib/libdvbv5/descriptors/pmt.c | 80 ++++++++++++++++++++++++++++--------------
 2 files changed, 61 insertions(+), 29 deletions(-)

diff --git a/lib/include/libdvbv5/pmt.h b/lib/include/libdvbv5/pmt.h
index 07b77ce..e6273f0 100644
--- a/lib/include/libdvbv5/pmt.h
+++ b/lib/include/libdvbv5/pmt.h
@@ -27,7 +27,7 @@
 
 #include <libdvbv5/header.h>
 
-#define DVB_TABLE_PMT      2
+#define DVB_TABLE_PMT      0x02
 
 enum dvb_streams {
 	stream_reserved0	= 0x00, // ITU-T | ISO/IEC Reserved
@@ -69,7 +69,7 @@ struct dvb_table_pmt_stream {
 	union {
 		uint16_t bitfield2;
 		struct {
-			uint16_t section_length:10;
+			uint16_t desc_length:10;
 			uint16_t zero:2;
 			uint16_t reserved2:4;
 		} __attribute__((packed));
@@ -91,14 +91,18 @@ struct dvb_table_pmt {
 	union {
 		uint16_t bitfield2;
 		struct {
-			uint16_t prog_length:10;
+			uint16_t desc_length:10;
 			uint16_t zero3:2;
 			uint16_t reserved3:4;
 		} __attribute__((packed));
 	} __attribute__((packed));
+	struct dvb_desc *descriptor;
 	struct dvb_table_pmt_stream *stream;
 } __attribute__((packed));
 
+#define dvb_pmt_field_first header
+#define dvb_pmt_field_last descriptor
+
 #define dvb_pmt_stream_foreach(_stream, _pmt) \
   for (struct dvb_table_pmt_stream *_stream = _pmt->stream; _stream; _stream = _stream->next) \
 
diff --git a/lib/libdvbv5/descriptors/pmt.c b/lib/libdvbv5/descriptors/pmt.c
index 32ee7e4..adedf5a 100644
--- a/lib/libdvbv5/descriptors/pmt.c
+++ b/lib/libdvbv5/descriptors/pmt.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
- * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
+ * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -33,27 +32,43 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 	struct dvb_table_pmt_stream **head = &pmt->stream;
 	size_t size;
 
+	if (buf[0] != DVB_TABLE_PMT) {
+		dvb_logerr("%s: invalid marker 0x%02x, sould be 0x%02x", __func__, buf[0], DVB_TABLE_PMT);
+		*table_length = 0;
+		return;
+	}
+
 	if (*table_length > 0) {
 		/* find end of current list */
 		while (*head != NULL)
 			head = &(*head)->next;
 	} else {
-		size = offsetof(struct dvb_table_pmt, stream);
+		size = offsetof(struct dvb_table_pmt, dvb_pmt_field_last);
 		if (p + size > endbuf) {
-			dvb_logerr("PMT table was truncated. Need %zu bytes, but has only %zu.",
-				size, buflen);
+			dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+				   size, endbuf - p);
 			return;
 		}
-		memcpy(table, p, size);
+		memcpy(pmt, p, size);
 		p += size;
-		*table_length = sizeof(struct dvb_table_pmt);
 
 		bswap16(pmt->bitfield);
 		bswap16(pmt->bitfield2);
+		pmt->descriptor = NULL;
 		pmt->stream = NULL;
 
-		/* skip prog section */
-		p += pmt->prog_length;
+		/* parse the descriptors */
+		if (pmt->desc_length > 0 ) {
+			size = pmt->desc_length;
+			if (p + size > endbuf) {
+				dvb_logwarn("%s: decsriptors short read %zd/%zd bytes", __func__,
+					   size, endbuf - p);
+				size = endbuf - p;
+			}
+			dvb_parse_descriptors(parms, p, size,
+					      &pmt->descriptor);
+			p += size;
+		}
 	}
 
 	/* get the stream entries */
@@ -74,15 +89,25 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
 		*head = stream;
 		head = &(*head)->next;
 
-		/* get the descriptors for each program */
-		dvb_parse_descriptors(parms, p, stream->section_length,
-				      &stream->descriptor);
-
-		p += stream->section_length;
+		/* parse the descriptors */
+		if (stream->desc_length > 0) {
+			size = stream->desc_length;
+			if (p + size > endbuf) {
+				dvb_logwarn("%s: decsriptors short read %zd/%zd bytes", __func__,
+					   size, endbuf - p);
+				size = endbuf - p;
+			}
+			dvb_parse_descriptors(parms, p, size,
+					      &stream->descriptor);
+
+			p += size;
+		}
 	}
-	if (endbuf - p)
-		dvb_logerr("PAT table has %zu spurious bytes at the end.",
-			   endbuf - p);
+	if (p < endbuf)
+		dvb_logwarn("%s: %zu spurious bytes at the end",
+			   __func__, endbuf - p);
+
+	*table_length = p - buf;
 }
 
 void dvb_table_pmt_free(struct dvb_table_pmt *pmt)
@@ -94,29 +119,32 @@ void dvb_table_pmt_free(struct dvb_table_pmt *pmt)
 		stream = stream->next;
 		free(tmp);
 	}
+	dvb_free_descriptors((struct dvb_desc **) &pmt->descriptor);
 	free(pmt);
 }
 
 void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms, const struct dvb_table_pmt *pmt)
 {
-	dvb_log("PMT");
+	dvb_loginfo("PMT");
 	dvb_table_header_print(parms, &pmt->header);
-	dvb_log("|- pcr_pid       %d", pmt->pcr_pid);
-	dvb_log("|  reserved2     %d", pmt->reserved2);
-	dvb_log("|  prog length   %d", pmt->prog_length);
-	dvb_log("|  zero3         %d", pmt->zero3);
-	dvb_log("|  reserved3     %d", pmt->reserved3);
-	dvb_log("|\\  pid     type");
+	dvb_loginfo("|- pcr_pid          %04x", pmt->pcr_pid);
+	dvb_loginfo("|  reserved2           %d", pmt->reserved2);
+	dvb_loginfo("|  descriptor length   %d", pmt->desc_length);
+	dvb_loginfo("|  zero3               %d", pmt->zero3);
+	dvb_loginfo("|  reserved3          %d", pmt->reserved3);
+	dvb_print_descriptors(parms, pmt->descriptor);
+	dvb_loginfo("|\\");
 	const struct dvb_table_pmt_stream *stream = pmt->stream;
 	uint16_t streams = 0;
 	while(stream) {
-		dvb_log("|- %5d   %s (%d)", stream->elementary_pid,
+		dvb_loginfo("|- stream 0x%04x: %s (%x)", stream->elementary_pid,
 				pmt_stream_name[stream->type], stream->type);
+		dvb_loginfo("|    descriptor length   %d", stream->desc_length);
 		dvb_print_descriptors(parms, stream->descriptor);
 		stream = stream->next;
 		streams++;
 	}
-	dvb_log("|_  %d streams", streams);
+	dvb_loginfo("|_  %d streams", streams);
 }
 
 const char *pmt_stream_name[] = {
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 11/11] libdvbv5: fix PMT parser
  2014-03-25 18:20 ` [PATCH 11/11] libdvbv5: fix PMT parser André Roth
@ 2014-03-25 20:51   ` Bjørn Mork
  2014-03-25 21:22     ` André Roth
  0 siblings, 1 reply; 14+ messages in thread
From: Bjørn Mork @ 2014-03-25 20:51 UTC (permalink / raw)
  To: André Roth; +Cc: LMML

André Roth <neolynx@gmail.com> writes:

> --- a/lib/libdvbv5/descriptors/pmt.c
> +++ b/lib/libdvbv5/descriptors/pmt.c
> @@ -1,6 +1,5 @@
>  /*
> - * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
> - * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
> + * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
>   *
>   * This program is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU General Public License

This copyright change looked strange to me.  Accidental deletion?


Bjørn

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 11/11] libdvbv5: fix PMT parser
  2014-03-25 20:51   ` Bjørn Mork
@ 2014-03-25 21:22     ` André Roth
  2014-03-26  6:38       ` Bjørn Mork
  0 siblings, 1 reply; 14+ messages in thread
From: André Roth @ 2014-03-25 21:22 UTC (permalink / raw)
  To: Bjørn Mork; +Cc: LMML, Mauro Carvalho Chehab

On Tue, 25 Mar 2014 21:51:49 +0100
Bjørn Mork <bjorn@mork.no> wrote:

> > - * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
> > - * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
> > + * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
> >   *
> >   * This program is free software; you can redistribute it and/or
> >   * modify it under the terms of the GNU General Public License
> 
> This copyright change looked strange to me.  Accidental deletion?

Hi Bjørn,

thanks for pointing this out.
originally I was adding mauro to my dvb files as the "owner" of dvb in
v4l. mauro then stated on some files that this was not his code and as
the PMT is originally my code, I corrected this here.

@mauro: please correct me if I'm wrong...

I'm a bit confused about the copyright year and author. Is this still
needed in the age of git ? What is the policy for them ?

regards,
 andré

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 11/11] libdvbv5: fix PMT parser
  2014-03-25 21:22     ` André Roth
@ 2014-03-26  6:38       ` Bjørn Mork
  2014-03-26 11:36         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 14+ messages in thread
From: Bjørn Mork @ 2014-03-26  6:38 UTC (permalink / raw)
  To: André Roth; +Cc: LMML, Mauro Carvalho Chehab

André Roth <neolynx@gmail.com> writes:

> On Tue, 25 Mar 2014 21:51:49 +0100
> Bjørn Mork <bjorn@mork.no> wrote:
>
>> > - * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
>> > - * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
>> > + * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
>> >   *
>> >   * This program is free software; you can redistribute it and/or
>> >   * modify it under the terms of the GNU General Public License
>> 
>> This copyright change looked strange to me.  Accidental deletion?
>
> Hi Bjørn,
>
> thanks for pointing this out.
> originally I was adding mauro to my dvb files as the "owner" of dvb in
> v4l. mauro then stated on some files that this was not his code and as
> the PMT is originally my code, I corrected this here.
>
> @mauro: please correct me if I'm wrong...

Correcting the copyright is of course fine, but I think it would be good
to document that in the patch description so people like me don't end up
asking unnecessary questions :-)

> I'm a bit confused about the copyright year and author. Is this still
> needed in the age of git ? What is the policy for them ?

IANAL.  But looking at this from a practical point of view, I believe
that this info is useful whether it is required or not.  Reading the
copyright owner(s) out of a git log can be a lot of work, and it isn't
necessariliy correct either - your copyright can be assigned to
e.g. your employer or to the FSF.  It's also difficult to judge who of
many contributors have made changes big enough to make them copyright
owners.  Some changes can be small in code size but still major, while
other changes can touch almost every line but still only be a minor
editorial fixup.

And why is it useful who owns a copyright and when the copyrighted work
was produced? If relicensing your code ever becomes a question, then we
need to know who to contact.  You might think that relicensing isn't
going to happen.  But there are real world examples where code has ended
up beeing linked to libraries with a GPL conflicting license, and
therefore needed an exception. The classical example is linking with
openssl.

And the year is useful because copyright expires some years (depending
on country of origin, but typical 50) after the authors death.  You
write code that will live forever, right? :-)


Bjørn

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 11/11] libdvbv5: fix PMT parser
  2014-03-26  6:38       ` Bjørn Mork
@ 2014-03-26 11:36         ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 14+ messages in thread
From: Mauro Carvalho Chehab @ 2014-03-26 11:36 UTC (permalink / raw)
  To: Bjørn Mork; +Cc: André Roth, LMML

Em Wed, 26 Mar 2014 07:38:15 +0100
Bjørn Mork <bjorn@mork.no> escreveu:

> André Roth <neolynx@gmail.com> writes:
> 
> > On Tue, 25 Mar 2014 21:51:49 +0100
> > Bjørn Mork <bjorn@mork.no> wrote:
> >
> >> > - * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
> >> > - * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
> >> > + * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
> >> >   *
> >> >   * This program is free software; you can redistribute it and/or
> >> >   * modify it under the terms of the GNU General Public License
> >> 
> >> This copyright change looked strange to me.  Accidental deletion?
> >
> > Hi Bjørn,
> >
> > thanks for pointing this out.
> > originally I was adding mauro to my dvb files as the "owner" of dvb in
> > v4l. mauro then stated on some files that this was not his code and as
> > the PMT is originally my code, I corrected this here.
> >
> > @mauro: please correct me if I'm wrong...
> 
> Correcting the copyright is of course fine, but I think it would be good
> to document that in the patch description so people like me don't end up
> asking unnecessary questions :-)

Yeah, a proper documentation always help.

Btw, what we generally do here is to extend the copyright timestamp,
instead of just replacing, like:

Copyright (c) 2012-2014 

> 
> > I'm a bit confused about the copyright year and author. Is this still
> > needed in the age of git ? What is the policy for them ?
> 
> IANAL.  But looking at this from a practical point of view, I believe
> that this info is useful whether it is required or not.  Reading the
> copyright owner(s) out of a git log can be a lot of work, and it isn't
> necessariliy correct either - your copyright can be assigned to
> e.g. your employer or to the FSF.  It's also difficult to judge who of
> many contributors have made changes big enough to make them copyright
> owners.  Some changes can be small in code size but still major, while
> other changes can touch almost every line but still only be a minor
> editorial fixup.

The copyright laws were written to cover all sorts of intelectual
work, and were written originally to cover music, painting, literature
work. There are actually two kinds of copyrights: moral rights and
economic rights. 

The GPL license (and all other sorts of licensing) deals with the
economic rights. A copyright line, however, can, IMO, serve for both
purposes: to tell the authorship and to identify who owns the
economic rights and who is licensing them under GPL.

If you develop something under your work contract, your employer likely
has property rights. 

Yet, you still owns the moral rights[1]. On most Countries, it is
not even possible to transfer them to someone else.

[1] http://en.wikipedia.org/wiki/Moral_rights

That warrants that a book written by, let's say, Julio Verne, will
always be copyrighted by him, no matter if he (or his family)
sold the economic rights, or if his books are already in public
domain or not.

> And why is it useful who owns a copyright and when the copyrighted work
> was produced? If relicensing your code ever becomes a question, then we
> need to know who to contact.  You might think that relicensing isn't
> going to happen.  But there are real world examples where code has ended
> up beeing linked to libraries with a GPL conflicting license, and
> therefore needed an exception. The classical example is linking with
> openssl.
> 
> And the year is useful because copyright expires some years (depending
> on country of origin, but typical 50) after the authors death.  You
> write code that will live forever, right? :-)

Yeah, the property rights expires. 

The moral rights, however, never expire: if someone uses part of the
Illiad (written around the 8th Century BC by Homero) on his work, he 
can't claim any rights on it, because that part of the text will forever
belong to Homero.

> 
> 
> Bjørn
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


-- 

Regards,
Mauro

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-03-26 11:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-25 18:19 [PATCH 01/11] libdvbv5: support info info log via dvb_loginfo André Roth
2014-03-25 18:19 ` [PATCH 02/11] libdvbv5: fix asprintf compile warnings André Roth
2014-03-25 18:19 ` [PATCH 03/11] libdvbv5: mpeg elementary stream parsers André Roth
2014-03-25 18:19 ` [PATCH 04/11] libdvbv5: fix EIT parsing André Roth
2014-03-25 18:19 ` [PATCH 06/11] libdvbv5: remove header files from SOURCES in Makefile.am André Roth
2014-03-25 18:19 ` [PATCH 07/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private André Roth
2014-03-25 18:19 ` [PATCH 08/11] libdvbv5: add attribute packed to structs and unions André Roth
2014-03-25 18:19 ` [PATCH 09/11] libdvbv5: add parser for CAT André Roth
2014-03-25 18:20 ` [PATCH 10/11] libdvbv5: add parser for ca and ca_identifier descriptors André Roth
2014-03-25 18:20 ` [PATCH 11/11] libdvbv5: fix PMT parser André Roth
2014-03-25 20:51   ` Bjørn Mork
2014-03-25 21:22     ` André Roth
2014-03-26  6:38       ` Bjørn Mork
2014-03-26 11:36         ` Mauro Carvalho Chehab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).