libdvbv5: Add a parser for extension descriptors
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Thu, 14 Nov 2013 02:57:00 +0000 (00:57 -0200)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Wed, 27 Nov 2013 11:24:16 +0000 (09:24 -0200)
There are some descriptors that are extensions, e. g. they
use a new descriptor range.

Add support for them, as the DVB-T2 table is one of such
extensions.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/include/descriptors.h
lib/include/descriptors/desc_extension.h [new file with mode: 0644]
lib/libdvbv5/Makefile.am
lib/libdvbv5/descriptors.c
lib/libdvbv5/descriptors/desc_extension.c [new file with mode: 0644]

index 166f415..da05091 100644 (file)
@@ -283,7 +283,7 @@ enum descriptors {
        atsc_genre_descriptor                           = 0xab,
 };
 
-
+/* Parser implemented on desc_extension.c */
 enum extension_descriptors {
        image_icon_descriptor                           = 0x00,
        cpcm_delivery_signalling_descriptor             = 0x01,
@@ -299,5 +299,4 @@ enum extension_descriptors {
        service_relocated_descriptor                    = 0x0b,
 };
 
-
 #endif
diff --git a/lib/include/descriptors/desc_extension.h b/lib/include/descriptors/desc_extension.h
new file mode 100644 (file)
index 0000000..1675886
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 - Mauro Carvalho Chehab <m.chehab@samsung.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 _EXTENSION_DESC_H
+#define _EXTENSION_DESC_H
+
+#include <stdint.h>
+#include <unistd.h> /* ssize_t */
+
+struct dvb_extension_descriptor {
+       uint8_t type;
+       uint8_t length;
+       struct dvb_desc *next;
+
+       struct dvb_desc *descriptor;
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void extension_descriptor_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 250eebb..ca59a0d 100644 (file)
@@ -40,6 +40,7 @@ libdvbv5_la_SOURCES = \
   descriptors/desc_event_extended.c  ../include/descriptors/desc_event_extended.h \
   descriptors/desc_atsc_service_location.c ../include/descriptors/desc_atsc_service_location.h \
   descriptors/desc_hierarchy.c  ../include/descriptors/desc_hierarchy.h \
+  descriptors/desc_extension.c  ../include/descriptors/desc_extension.h \
   descriptors/nit.c  ../include/descriptors/nit.h \
   descriptors/sdt.c  ../include/descriptors/sdt.h \
   descriptors/vct.c  ../include/descriptors/vct.h \
index f7dfb7e..2ad138b 100644 (file)
@@ -48,6 +48,7 @@
 #include "descriptors/desc_event_extended.h"
 #include "descriptors/desc_atsc_service_location.h"
 #include "descriptors/desc_hierarchy.h"
+#include "descriptors/desc_extension.h"
 
 ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc)
 {
@@ -239,7 +240,7 @@ const struct dvb_descriptor dvb_descriptors[] = {
        [AAC_descriptor] = { "AAC_descriptor", NULL, NULL, NULL, 0 },
        [XAIT_location_descriptor] = { "XAIT_location_descriptor", NULL, NULL, NULL, 0 },
        [FTA_content_management_descriptor] = { "FTA_content_management_descriptor", NULL, NULL, NULL, 0 },
-       [extension_descriptor] = { "extension_descriptor", NULL, NULL, NULL, 0 },
+       [extension_descriptor] = { "extension_descriptor", extension_descriptor_init, NULL, NULL, sizeof(struct dvb_extension_descriptor) },
 
        [CUE_identifier_descriptor] = { "CUE_identifier_descriptor", NULL, NULL, NULL, 0 },
 
diff --git a/lib/libdvbv5/descriptors/desc_extension.c b/lib/libdvbv5/descriptors/desc_extension.c
new file mode 100644 (file)
index 0000000..403c254
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2013 - Mauro Carvalho Chehab <m.chehab@samsung.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.h"
+#include "descriptors/desc_extension.h"
+#include "dvb-fe.h"
+
+const struct dvb_descriptor dvb_ext_descriptors[] = {
+       [image_icon_descriptor] = { "image_icon_descriptor", NULL, NULL, NULL, 0 },
+       [cpcm_delivery_signalling_descriptor] = { "cpcm_delivery_signalling_descriptor", NULL, NULL, NULL, 0 },
+       [CP_descriptor] = { "CP_descriptor", NULL, NULL, NULL, 0 },
+       [CP_identifier_descriptor] = { "CP_identifier_descriptor", NULL, NULL, NULL, 0 },
+       [T2_delivery_system_descriptor] = { "T2_delivery_system_descriptor", NULL, NULL, NULL, 0 },
+       [SH_delivery_system_descriptor] = { "SH_delivery_system_descriptor", NULL, NULL, NULL, 0 },
+       [supplementary_audio_descriptor] = { "supplementary_audio_descriptor", NULL, NULL, NULL, 0 },
+       [network_change_notify_descriptor] = { "network_change_notify_descriptor", NULL, NULL, NULL, 0 },
+       [message_descriptor] = { "message_descriptor", NULL, NULL, NULL, 0 },
+       [target_region_descriptor] = { "target_region_descriptor", NULL, NULL, NULL, 0 },
+       [target_region_name_descriptor] = { "target_region_name_descriptor", NULL, NULL, NULL, 0 },
+       [service_relocated_descriptor] = { "service_relocated_descriptor", NULL, NULL, NULL, 0 },
+};
+
+void dvb_parse_ext_descriptors(struct dvb_v5_fe_parms *parms,
+                              const uint8_t *buf, uint16_t section_length,
+                              struct dvb_desc **head_desc)
+{
+       const uint8_t *ptr = buf;
+       struct dvb_desc *current = NULL;
+       struct dvb_desc *last = NULL;
+       while (ptr < buf + section_length) {
+               int desc_type = ptr[0];
+               int desc_len  = ptr[1];
+               size_t size;
+               dvb_desc_init_func init = dvb_ext_descriptors[desc_type].init;
+               if (!init) {
+                       init = dvb_desc_default_init;
+                       size = sizeof(struct dvb_desc) + desc_len;
+               } else {
+                       size = dvb_descriptors[desc_type].size;
+               }
+               if (!size) {
+                       dvb_logerr("descriptor type %d has no size defined", current->type);
+                       size = 4096;
+               }
+               current = (struct dvb_desc *) malloc(size);
+               ptr += dvb_desc_init(ptr, current); /* the standard header was read */
+               init(parms, ptr, current);
+               if (!*head_desc)
+                       *head_desc = current;
+               if (last)
+                       last->next = current;
+               last = current;
+               ptr += current->length;     /* standard descriptor header plus descriptor length */
+       }
+}
+
+void extension_descriptor_init(struct dvb_v5_fe_parms *parms,
+                                    const uint8_t *buf, struct dvb_desc *desc)
+{
+       struct dvb_extension_descriptor *ext = (struct dvb_extension_descriptor *)desc;
+       unsigned char *p = (unsigned char *)buf;
+       size_t len;
+
+       len = sizeof(*ext) - offsetof(struct dvb_extension_descriptor, descriptor);
+       memcpy(&ext->descriptor, p, len);
+       p += len;
+
+       struct dvb_desc **head_desc = &ext->descriptor;
+       dvb_parse_ext_descriptors(parms, p, ext->length,
+                               head_desc);
+       p += ext->length;
+}