* [PATCH 1/3] libdvbv5: implement ATSC standard header
@ 2014-01-08 11:23 André Roth
2014-01-08 11:23 ` [PATCH 2/3] libdvbv5: implement MGT table parser André Roth
2014-01-08 11:23 ` [PATCH 3/3] libdvbv5: implement ATSC EIT André Roth
0 siblings, 2 replies; 4+ messages in thread
From: André Roth @ 2014-01-08 11:23 UTC (permalink / raw)
To: linux-media; +Cc: André Roth
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.
Signed-off-by: André Roth <neolynx@gmail.com>
---
| 63 ++++++++++++++++++++++++++++++++++
| 47 +++++++++++++++++++++++++
2 files changed, 110 insertions(+)
create mode 100644 lib/include/descriptors/atsc_header.h
create mode 100644 lib/libdvbv5/descriptors/atsc_header.c
--git a/lib/include/descriptors/atsc_header.h b/lib/include/descriptors/atsc_header.h
new file mode 100644
index 0000000..1e7148e
--- /dev/null
+++ b/lib/include/descriptors/atsc_header.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
+ *
+ */
+
+#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
--git a/lib/libdvbv5/descriptors/atsc_header.c b/lib/libdvbv5/descriptors/atsc_header.c
new file mode 100644
index 0000000..ed152ce
--- /dev/null
+++ b/lib/libdvbv5/descriptors/atsc_header.c
@@ -0,0 +1,47 @@
+/*
+ * 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/atsc_header.h"
+#include "descriptors.h"
+#include "dvb-fe.h"
+
+int atsc_table_header_init(struct atsc_table_header *t)
+{
+ bswap16(t->bitfield);
+ bswap16(t->id);
+ return 0;
+}
+
+void atsc_table_header_print(struct dvb_v5_fe_parms *parms, const struct atsc_table_header *t)
+{
+ dvb_log("| table_id %02x", t->table_id);
+ dvb_log("| section_length %d", t->section_length);
+ dvb_log("| syntax %d", t->syntax);
+ dvb_log("| priv %d", t->priv);
+ dvb_log("| one %d", t->one);
+ dvb_log("| id %d", t->id);
+ dvb_log("| one2 %d", t->one2);
+ dvb_log("| version %d", t->version);
+ dvb_log("| current_next %d", t->current_next);
+ dvb_log("| section_id %d", t->section_id);
+ dvb_log("| last_section %d", t->last_section);
+ dvb_log("| protocol_version %d", t->protocol_version);
+}
+
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] libdvbv5: implement MGT table parser
2014-01-08 11:23 [PATCH 1/3] libdvbv5: implement ATSC standard header André Roth
@ 2014-01-08 11:23 ` André Roth
2014-01-09 19:39 ` Gregor Jasny
2014-01-08 11:23 ` [PATCH 3/3] libdvbv5: implement ATSC EIT André Roth
1 sibling, 1 reply; 4+ messages in thread
From: André Roth @ 2014-01-08 11:23 UTC (permalink / raw)
To: linux-media; +Cc: André Roth
The Master Guide Table is used in ATSC. Implementation
according to specs A/65:2009
Signed-off-by: André Roth <neolynx@gmail.com>
---
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
diff --git a/lib/include/descriptors/mgt.h b/lib/include/descriptors/mgt.h
new file mode 100644
index 0000000..9c583b4
--- /dev/null
+++ b/lib/include/descriptors/mgt.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 _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
diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index 2ad5902..44f68d4 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -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
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index d0887f4..7385027 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -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"
diff --git a/lib/libdvbv5/descriptors/mgt.c b/lib/libdvbv5/descriptors/mgt.c
new file mode 100644
index 0000000..7279982
--- /dev/null
+++ b/lib/libdvbv5/descriptors/mgt.c
@@ -0,0 +1,140 @@
+/*
+ * 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/mgt.h"
+#include "dvb-fe.h"
+
+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)
+{
+ const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */
+ struct atsc_table_mgt *mgt = (struct atsc_table_mgt *) table;
+ struct dvb_desc **head_desc;
+ struct atsc_table_mgt_table **head;
+ int i = 0;
+ struct atsc_table_mgt_table *last = NULL;
+ size_t size = offsetof(struct atsc_table_mgt, table);
+
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+
+ if (*table_length > 0) {
+ /* find end of curent lists */
+ head_desc = &mgt->descriptor;
+ while (*head_desc != NULL)
+ head_desc = &(*head_desc)->next;
+ head = &mgt->table;
+ while (*head != NULL)
+ head = &(*head)->next;
+
+ /* FIXME: read current mgt->tables for loop below */
+ } else {
+ memcpy(table, p, size);
+ *table_length = sizeof(struct atsc_table_mgt);
+
+ bswap16(mgt->tables);
+
+ mgt->descriptor = NULL;
+ mgt->table = NULL;
+ head_desc = &mgt->descriptor;
+ head = &mgt->table;
+ }
+ p += size;
+
+ while (i++ < mgt->tables && p < endbuf) {
+ struct atsc_table_mgt_table *table;
+
+ size = offsetof(struct atsc_table_mgt_table, descriptor);
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+ table = (struct atsc_table_mgt_table *) malloc(sizeof(struct atsc_table_mgt_table));
+ memcpy(table, p, size);
+ p += size;
+
+ bswap16(table->type);
+ bswap16(table->bitfield);
+ bswap16(table->bitfield2);
+ bswap32(table->size);
+ table->descriptor = NULL;
+ table->next = NULL;
+
+ if(!*head)
+ *head = table;
+ if(last)
+ last->next = table;
+
+ /* get the descriptors for each table */
+ size = table->desc_length;
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+ dvb_parse_descriptors(parms, p, size, &table->descriptor);
+
+ p += size;
+ last = table;
+ }
+ /* TODO: parse MGT descriptors here into head_desc */
+}
+
+void atsc_table_mgt_free(struct atsc_table_mgt *mgt)
+{
+ struct atsc_table_mgt_table *table = mgt->table;
+
+ dvb_free_descriptors((struct dvb_desc **) &mgt->descriptor);
+ while(table) {
+ struct atsc_table_mgt_table *tmp = table;
+
+ dvb_free_descriptors((struct dvb_desc **) &table->descriptor);
+ table = table->next;
+ free(tmp);
+ }
+ free(mgt);
+}
+
+void atsc_table_mgt_print(struct dvb_v5_fe_parms *parms, struct atsc_table_mgt *mgt)
+{
+ const struct atsc_table_mgt_table *table = mgt->table;
+ uint16_t tables = 0;
+
+ dvb_log("MGT");
+ atsc_table_header_print(parms, &mgt->header);
+ dvb_log("| tables %d", mgt->tables);
+ while(table) {
+ dvb_log("|- type %04x %d", table->type, table->pid);
+ dvb_log("| one %d", table->one);
+ dvb_log("| one2 %d", table->one2);
+ dvb_log("| type version %d", table->type_version);
+ dvb_log("| size %d", table->size);
+ dvb_log("| one3 %d", table->one3);
+ dvb_log("| desc_length %d", table->desc_length);
+ dvb_print_descriptors(parms, table->descriptor);
+ table = table->next;
+ tables++;
+ }
+ dvb_log("|_ %d tables", tables);
+}
+
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] libdvbv5: implement ATSC EIT
2014-01-08 11:23 [PATCH 1/3] libdvbv5: implement ATSC standard header André Roth
2014-01-08 11:23 ` [PATCH 2/3] libdvbv5: implement MGT table parser André Roth
@ 2014-01-08 11:23 ` André Roth
1 sibling, 0 replies; 4+ messages in thread
From: André Roth @ 2014-01-08 11:23 UTC (permalink / raw)
To: linux-media; +Cc: André Roth
ATSC has a different EIT table then DVB. This implements
the parser according to secifications defined in A/65:2009.
Signed-off-by: André Roth <neolynx@gmail.com>
---
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
diff --git a/lib/include/descriptors/atsc_eit.h b/lib/include/descriptors/atsc_eit.h
new file mode 100644
index 0000000..3bc5df6
--- /dev/null
+++ b/lib/include/descriptors/atsc_eit.h
@@ -0,0 +1,90 @@
+/*
+ * 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 _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
diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index 44f68d4..c6d2a42 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -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
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index 7385027..aeace36 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -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"
diff --git a/lib/libdvbv5/descriptors/atsc_eit.c b/lib/libdvbv5/descriptors/atsc_eit.c
new file mode 100644
index 0000000..f8afc76
--- /dev/null
+++ b/lib/libdvbv5/descriptors/atsc_eit.c
@@ -0,0 +1,170 @@
+/*
+ * 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/atsc_eit.h"
+#include "dvb-fe.h"
+
+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)
+{
+ const uint8_t *p = buf, *endbuf = buf + buflen - 4; /* minus CRC */;
+ struct atsc_table_eit *eit = (struct atsc_table_eit *) table;
+ struct atsc_table_eit_event **head;
+ int i = 0;
+ struct atsc_table_eit_event *last = NULL;
+ size_t size = offsetof(struct atsc_table_eit, event);
+
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+
+ if (*table_length > 0) {
+ memcpy(eit, p, size);
+
+ /* find end of curent list */
+ head = &eit->event;
+ while (*head != NULL)
+ head = &(*head)->next;
+ } else {
+ memcpy(eit, p, size);
+ *table_length = sizeof(struct atsc_table_eit);
+
+ eit->event = NULL;
+ head = &eit->event;
+ }
+ p += size;
+
+ while (i++ < eit->events && p < endbuf) {
+ struct atsc_table_eit_event *event;
+ union atsc_table_eit_desc_length dl;
+
+ size = offsetof(struct atsc_table_eit_event, descriptor);
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+ event = (struct atsc_table_eit_event *) malloc(sizeof(struct atsc_table_eit_event));
+ memcpy(event, p, size);
+ p += size;
+
+ bswap16(event->bitfield);
+ bswap32(event->start_time);
+ bswap32(event->bitfield2);
+ event->descriptor = NULL;
+ event->next = NULL;
+ atsc_time(event->start_time, &event->start);
+ event->source_id = eit->header.id;
+
+ size = event->title_length - 1;
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+ /* TODO: parse title */
+ p += size;
+
+ if(!*head)
+ *head = event;
+ if(last)
+ last->next = event;
+
+ /* get the descriptors for each program */
+ size = sizeof(union atsc_table_eit_desc_length);
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+ memcpy(&dl, p, size);
+ p += size;
+ bswap16(dl.bitfield);
+
+ size = dl.desc_length;
+ if (p + size > endbuf) {
+ dvb_logerr("%s: short read %zd/%zd bytes", __func__,
+ size, endbuf - p);
+ return;
+ }
+ dvb_parse_descriptors(parms, p, size, &event->descriptor);
+
+ p += size;
+ last = event;
+ }
+}
+
+void atsc_table_eit_free(struct atsc_table_eit *eit)
+{
+ struct atsc_table_eit_event *event = eit->event;
+
+ while (event) {
+ struct atsc_table_eit_event *tmp = event;
+
+ dvb_free_descriptors((struct dvb_desc **) &event->descriptor);
+ event = event->next;
+ free(tmp);
+ }
+ free(eit);
+}
+
+void atsc_table_eit_print(struct dvb_v5_fe_parms *parms, struct atsc_table_eit *eit)
+{
+ dvb_log("EIT");
+ atsc_table_header_print(parms, &eit->header);
+ const struct atsc_table_eit_event *event = eit->event;
+ uint16_t events = 0;
+
+ while (event) {
+ char start[255];
+
+ strftime(start, sizeof(start), "%F %T", &event->start);
+ dvb_log("|- event %7d", event->event_id);
+ dvb_log("| Source %d", event->source_id);
+ dvb_log("| Starttime %d", event->start_time);
+ dvb_log("| Start %s UTC", start);
+ dvb_log("| Duration %dh %dm %ds", event->duration / 3600, (event->duration % 3600) / 60, event->duration % 60);
+ dvb_log("| ETM %d", event->etm);
+ dvb_log("| title length %d", event->title_length);
+ dvb_print_descriptors(parms, event->descriptor);
+ event = event->next;
+ events++;
+ }
+ dvb_log("|_ %d events", events);
+}
+
+void atsc_time(const uint32_t start_time, struct tm *tm)
+{
+ tm->tm_sec = 0;
+ tm->tm_min = 0;
+ tm->tm_hour = 0;
+ tm->tm_mday = 6;
+ tm->tm_mon = 0;
+ tm->tm_year = 80;
+ tm->tm_isdst = -1;
+ tm->tm_wday = 0;
+ tm->tm_yday = 0;
+ mktime(tm);
+ tm->tm_sec += start_time;
+ mktime(tm);
+}
+
+
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/3] libdvbv5: implement MGT table parser
2014-01-08 11:23 ` [PATCH 2/3] libdvbv5: implement MGT table parser André Roth
@ 2014-01-09 19:39 ` Gregor Jasny
0 siblings, 0 replies; 4+ messages in thread
From: Gregor Jasny @ 2014-01-09 19:39 UTC (permalink / raw)
To: André Roth, linux-media
Hello André,
On 08/01/14 12:23, André Roth wrote:
> ...
> + 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-09 19:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-08 11:23 [PATCH 1/3] libdvbv5: implement ATSC standard header André Roth
2014-01-08 11:23 ` [PATCH 2/3] libdvbv5: implement MGT table parser André Roth
2014-01-09 19:39 ` Gregor Jasny
2014-01-08 11:23 ` [PATCH 3/3] libdvbv5: implement ATSC EIT André Roth
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).