diff mbox

[11/11] libdvbv5: fix PMT parser

Message ID 1395771601-3509-11-git-send-email-neolynx@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

André Roth March 25, 2014, 6:20 p.m. UTC
- 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(-)

Comments

Bjørn Mork March 25, 2014, 8:51 p.m. UTC | #1
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
--
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
André Roth March 25, 2014, 9:22 p.m. UTC | #2
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é
--
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
Bjørn Mork March 26, 2014, 6:38 a.m. UTC | #3
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
--
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
Mauro Carvalho Chehab March 26, 2014, 11:36 a.m. UTC | #4
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
diff mbox

Patch

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[] = {