From: Mauro Carvalho Chehab Date: Thu, 14 Nov 2013 02:57:00 +0000 (-0200) Subject: libdvbv5: Add a parser for extension descriptors X-Git-Tag: v4l-utils-1.2.0~364 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b87fb6da9777a4dc6e6a2819692eee5d014c9a69;p=platform%2Fupstream%2Fv4l-utils.git libdvbv5: Add a parser for extension descriptors 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 --- diff --git a/lib/include/descriptors.h b/lib/include/descriptors.h index 166f415..da05091 100644 --- a/lib/include/descriptors.h +++ b/lib/include/descriptors.h @@ -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 index 0000000..1675886 --- /dev/null +++ b/lib/include/descriptors/desc_extension.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 - Mauro Carvalho Chehab + * + * 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 +#include /* 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 diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am index 250eebb..ca59a0d 100644 --- a/lib/libdvbv5/Makefile.am +++ b/lib/libdvbv5/Makefile.am @@ -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 \ diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c index f7dfb7e..2ad138b 100644 --- a/lib/libdvbv5/descriptors.c +++ b/lib/libdvbv5/descriptors.c @@ -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 index 0000000..403c254 --- /dev/null +++ b/lib/libdvbv5/descriptors/desc_extension.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2013 - Mauro Carvalho Chehab + * + * 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; +}