libdvbv5: implement ATSC standard header
PATCH 1/3 libdvbv5: implement ATSC standard header
The ATSC standard header is slightly different from the one used in DVB. This implements the parser for it, and will be used by the VCT table for example.
--- lib/include/descriptors/atsc_header.h | 63 ++++++++++++++++++++++++++++++++++ lib/libdvbv5/descriptors/atsc_header.c | 47 +++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 lib/include/descriptors/atsc_header.h create mode 100644 lib/libdvbv5/descriptors/atsc_header.c
lib/include/descriptors/atsc_header.h new file +63 -0
@@ -0,0 +1,63 @@ +/* +* Copyright (c) 2013 - Andre Roth <[email protected]> +* +* 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 _ATSC_HEADER_H +#define _ATSC_HEADER_H + +#include <stdint.h> +#include <unistd.h> /* ssize_t */ + +#define ATSC_BASE_PID 0x1FFB + +struct atsc_table_header { +uint8_t table_id; +union { +uint16_t bitfield; +struct { +uint16_t section_length:12 ; +uint16_t one:2 ; +uint16_t priv:1 ; +uint16_t syntax:1 ; + } __attribute__((packed)); + }; +uint16_t id; +uint8_t current_next:1 ; +uint8_t version:5 ; +uint8_t one2:2 ; + +uint8_t section_id; +uint8_t last_section; +uint8_t protocol_version; +} __attribute__((packed)); + +struct dvb_v5_fe_parms ; + +#ifdef __cplusplus +extern "C" { +#endif + +int atsc_table_header_init (struct atsc_table_header *t); +void atsc_table_header_print (struct dvb_v5_fe_parms *parms,const struct atsc_table_header *t); + +#ifdef __cplusplus +} +#endif + +#endif
lib/libdvbv5/descriptors/atsc_header.c new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 2/3 libdvbv5: implement MGT table parser
The Master Guide Table is used in ATSC. Implementation according to specs A/65:2009
--- lib/include/descriptors/mgt.h | 79 +++++++++++++++++++++++ lib/libdvbv5/Makefile.am | 3 +- lib/libdvbv5/descriptors.c | 1 + lib/libdvbv5/descriptors/mgt.c | 140 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 lib/include/descriptors/mgt.h create mode 100644 lib/libdvbv5/descriptors/mgt.c
lib/include/descriptors/mgt.h new file +79 -0
@@ -0,0 +1,79 @@ +/* +* Copyright (c) 2013 - Andre Roth <[email protected]> +* +* 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 _MGT_H +#define _MGT_H + +#include <stdint.h> +#include <unistd.h> /* ssize_t */ + +#include "descriptors/atsc_header.h" +#include "descriptors.h" + +#define ATSC_TABLE_MGT 0xC7 + +struct atsc_table_mgt_table { +uint16_t type; +union { +uint16_t bitfield; +struct { +uint16_t pid:13 ; +uint16_t one:3 ; + } __attribute__((packed)); + } __attribute__((packed)); +uint8_t type_version:5 ; +uint8_t one2:3 ; +uint32_t size; +union { +uint16_t bitfield2; +struct { +uint16_t desc_length:12 ; +uint16_t one3:4 ; + } __attribute__((packed)); + } __attribute__((packed)); +struct dvb_desc *descriptor; +struct atsc_table_mgt_table *next; +} __attribute__((packed)); + +struct atsc_table_mgt { +struct atsc_table_header header; +uint16_t tables; +struct atsc_table_mgt_table *table; +struct dvb_desc *descriptor; +} __attribute__((packed)); + +#define atsc_mgt_table_foreach ( _tran, _mgt ) \ + for( struct atsc_table_mgt_table *_tran = _mgt->table; _tran; _tran = _tran->next ) \ + +struct dvb_v5_fe_parms ; + +#ifdef __cplusplus +extern "C" { +#endif + +void atsc_table_mgt_init (struct dvb_v5_fe_parms *parms,const uint8_t *buf,ssize_t buflen,uint8_t *table,ssize_t *table_length); +void atsc_table_mgt_free (struct atsc_table_mgt *mgt); +void atsc_table_mgt_print (struct dvb_v5_fe_parms *parms,struct atsc_table_mgt *mgt); + +#ifdef __cplusplus +} +#endif + +#endif
lib/libdvbv5/Makefile.am +2 -1
@@ -48,7 +48,8 @@ libdvbv5_la_SOURCES = \ descriptors/nit.c ../include/descriptors/nit.h \ descriptors/sdt.c ../include/descriptors/sdt.h \ descriptors/vct.c ../include/descriptors/vct.h \ - descriptors/eit.c ../include/descriptors/eit.h + descriptors/eit.c ../include/descriptors/eit.h \ + descriptors/mgt.c ../include/descriptors/mgt.h \ libdvbv5_la_CPPFLAGS = $(ENFORCE_LIBDVBV5_STATIC) libdvbv5_la_LDFLAGS = $(LIBDVBV5_VERSION) $(ENFORCE_LIBDVBV5_STATIC) -lm
lib/libdvbv5/descriptors.c +1 -0
@@ -36,6 +36,7 @@#include "descriptors/sdt.h" #include "descriptors/eit.h" #include "descriptors/vct.h" +#include "descriptors/mgt.h" #include "descriptors/desc_language.h" #include "descriptors/desc_network_name.h" #include "descriptors/desc_cable_delivery.h"
lib/libdvbv5/descriptors/mgt.c new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 3/3 libdvbv5: implement ATSC EIT
In reply to André RothATSC has a different EIT table then DVB. This implements the parser according to secifications defined in A/65:2009.
--- lib/include/descriptors/atsc_eit.h | 90 +++++++++++++++++++ lib/libdvbv5/Makefile.am | 4 +- lib/libdvbv5/descriptors.c | 1 + lib/libdvbv5/descriptors/atsc_eit.c | 170 ++++++++++++++++++++++++++++++++++++ 4 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 lib/include/descriptors/atsc_eit.h create mode 100644 lib/libdvbv5/descriptors/atsc_eit.c
lib/include/descriptors/atsc_eit.h new file +90 -0
@@ -0,0 +1,90 @@ +/* +* Copyright (c) 2013 - Andre Roth <[email protected]> +* +* 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 _ATSC_EIT_H +#define _ATSC_EIT_H + +#include <stdint.h> +#include <unistd.h> /* ssize_t */ +#include <time.h> + +#include "descriptors/atsc_header.h" +#include "descriptors.h" + +#define ATSC_TABLE_EIT 0xCB + +struct atsc_table_eit_event { +union { +uint16_t bitfield; +struct { +uint16_t event_id:14 ; +uint16_t one:2 ; + } __attribute__((packed)); + } __attribute__((packed)); +uint32_t start_time; +union { +uint32_t bitfield2; +struct { +uint32_t title_length:8 ; +uint32_t duration:20 ; +uint32_t etm:2 ; +uint32_t one2:2 ; + uint32_t :2; + } __attribute__((packed)); + } __attribute__((packed)); +struct dvb_desc *descriptor; +struct atsc_table_eit_event *next; +struct tm start; +uint16_t source_id; +} __attribute__((packed)); + +union atsc_table_eit_desc_length { +uint16_t bitfield; +struct { +uint16_t desc_length:12 ; +uint16_t reserved:4 ; + } __attribute__((packed)); +} __attribute__((packed)); + +struct atsc_table_eit { +struct atsc_table_header header; +uint8_t events; +struct atsc_table_eit_event *event; +} __attribute__((packed)); + +#define atsc_eit_event_foreach (_event, _eit) \ + for( struct atsc_table_eit_event *_event = _eit->event; _event; _event = _event->next ) \ + +struct dvb_v5_fe_parms ; + +#ifdef __cplusplus +extern "C" { +#endif + +void atsc_table_eit_init (struct dvb_v5_fe_parms *parms,const uint8_t *buf,ssize_t buflen,uint8_t *table,ssize_t *table_length); +void atsc_table_eit_free (struct atsc_table_eit *eit); +void atsc_table_eit_print (struct dvb_v5_fe_parms *parms,struct atsc_table_eit *eit); +void atsc_time (const uint32_t start_time,struct tm *tm); + +#ifdef __cplusplus +} +#endif + +#endif
lib/libdvbv5/Makefile.am +3 -1
@@ -48,8 +48,10 @@ libdvbv5_la_SOURCES = \ descriptors/nit.c ../include/descriptors/nit.h \ descriptors/sdt.c ../include/descriptors/sdt.h \ descriptors/vct.c ../include/descriptors/vct.h \ - descriptors/eit.c ../include/descriptors/eit.h \ + descriptors/atsc_header.c ../include/descriptors/atsc_header.h \ descriptors/mgt.c ../include/descriptors/mgt.h \ + descriptors/eit.c ../include/descriptors/eit.h \ + descriptors/atsc_eit.c ../include/descriptors/atsc_eit.h libdvbv5_la_CPPFLAGS = $(ENFORCE_LIBDVBV5_STATIC) libdvbv5_la_LDFLAGS = $(LIBDVBV5_VERSION) $(ENFORCE_LIBDVBV5_STATIC) -lm
lib/libdvbv5/descriptors.c +1 -0
@@ -37,6 +37,7 @@#include "descriptors/eit.h" #include "descriptors/vct.h" #include "descriptors/mgt.h" +#include "descriptors/atsc_eit.h" #include "descriptors/desc_language.h" #include "descriptors/desc_network_name.h" #include "descriptors/desc_cable_delivery.h"
lib/libdvbv5/descriptors/atsc_eit.c new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH 2/3] libdvbv5: implement MGT table parser
In reply to André RothHello André,
lib/include/descriptors/mgt.h line 43
Quoted 11 lines · André Roth
...
lib/include/descriptors/mgt.h new file +10
-0+union { +uint16_t bitfield; +struct { +uint16_t pid:13 ; +uint16_t one:3 ; + } __attribute__((packed)); + } __attribute__((packed)); + uint8_t type_version:5; + uint8_t one2:3; +uint32_t size;
Are you sure that this code handles the endianess correctly? Looking at netinet/in.h I'm under the impression that the order of the bitfield entries have to be swapped, too:
struct ip
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ip_hl:4; /* header length */
unsigned int ip_v:4; /* version */
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int ip_v:4; /* version */
unsigned int ip_hl:4; /* header length */
#endif
I also remember that you can also easily get the byte swapping wrongif entries cross byte borders (like a :13 one).
Maybe you could write some unit tests for your functions. The Debian build farm then will catch any errors.
Cheers,
Gregor