diff options
author | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2020-09-12 07:58:08 +0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2020-09-12 09:07:56 +0200 |
commit | d070107d6267f617bb7331d84507701c8e2d673c (patch) | |
tree | dccfa71be7488f25d90a426cdccfb7f9653f1b28 | |
parent | c3bff22b2cdd9027a28421553d8a19a9df37ebaf (diff) |
libdvbv5: add support for the registration descriptor
Such descriptor works like a fourcc descriptor: it specifies
the format of an Elementary Stream. It is needed in order
to identify SMPTE s302m audio streams.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r-- | doxygen_libdvbv5.cfg | 1 | ||||
-rw-r--r-- | lib/include/libdvbv5/desc_registration_id.h | 109 | ||||
-rw-r--r-- | lib/libdvbv5/Makefile.am | 2 | ||||
-rw-r--r-- | lib/libdvbv5/descriptors.c | 9 | ||||
-rw-r--r-- | lib/libdvbv5/descriptors/desc_registration_id.c | 71 |
5 files changed, 188 insertions, 4 deletions
diff --git a/doxygen_libdvbv5.cfg b/doxygen_libdvbv5.cfg index f9462d2a..b25301a0 100644 --- a/doxygen_libdvbv5.cfg +++ b/doxygen_libdvbv5.cfg @@ -776,6 +776,7 @@ INPUT = $(SRCDIR)/doc/libdvbv5-index.doc \ $(SRCDIR)/lib/include/libdvbv5/desc_event_extended.h \ $(SRCDIR)/lib/include/libdvbv5/desc_event_short.h \ $(SRCDIR)/lib/include/libdvbv5/desc_extension.h \ + $(SRCDIR)/lib/include/libdvbv5/desc_descriptor_id.h \ $(SRCDIR)/lib/include/libdvbv5/desc_frequency_list.h \ $(SRCDIR)/lib/include/libdvbv5/desc_hierarchy.h \ $(SRCDIR)/lib/include/libdvbv5/desc_isdbt_delivery.h \ diff --git a/lib/include/libdvbv5/desc_registration_id.h b/lib/include/libdvbv5/desc_registration_id.h new file mode 100644 index 00000000..20905533 --- /dev/null +++ b/lib/include/libdvbv5/desc_registration_id.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020 - Mauro Carvalho Chehab + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 _DESC_REGISTRATION_ID_H +#define _DESC_REGISTRATION_ID_H + +#include <libdvbv5/descriptors.h> +/** + * @file desc_registration_id.h + * @ingroup descriptors + * @brief Provides the descriptors for the registration descriptor. + * This descriptor provides the format information for an + * Elementary Stream. + * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) + * @author Mauro Carvalho Chehab + * + * @par Relevant specs + * The descriptor described herein is defined at: + * - ISO/IEC 13818-1 + * + * @par Bug Report + * Please submit bug reports and patches to linux-media@vger.kernel.org + */ + +/** + * @struct dvb_desc_registration + * @ingroup descriptors + * @brief Struct containing the frequency list descriptor + * + * @param type descriptor tag + * @param length descriptor length + * @param format_identifier 32-bit value obtained from ISO/IEC JTC 1/SC 29 + * which describes the format of the ES + * The length of the vector is given by: + * length - 4. + */ +struct dvb_desc_registration { + uint8_t type; + uint8_t length; + struct dvb_desc *next; + + uint32_t format_identifier; + uint8_t *additional_identification_info; +} __attribute__((packed)); + +struct dvb_v5_fe_parms; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initializes and parses the registration descriptor + * @ingroup descriptors + * + * @param parms struct dvb_v5_fe_parms pointer to the opened device + * @param buf buffer containing the descriptor's raw data + * @param desc pointer to struct dvb_desc to be allocated and filled + * + * This function initializes and makes sure that all fields will follow the CPU + * endianness. Due to that, the content of the buffer may change. + * + * Currently, no memory is allocated internally. + * + * @return On success, it returns the size of the allocated struct. + * A negative value indicates an error. + */ +int dvb_desc_registration_init(struct dvb_v5_fe_parms *parms, + const uint8_t *buf, struct dvb_desc *desc); + +/** + * @brief Prints the content of the registration descriptor + * @ingroup descriptors + * + * @param parms struct dvb_v5_fe_parms pointer to the opened device + * @param desc pointer to struct dvb_desc + */ +void dvb_desc_registration_print(struct dvb_v5_fe_parms *parms, + const struct dvb_desc *desc); + +/** + * @brief Frees all data allocated by the registration descriptor + * @ingroup descriptors + * + * @param desc pointer to struct dvb_desc to be freed + */ +void dvb_desc_registration_free(struct dvb_desc *desc); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am index 09c261be..683ae3fb 100644 --- a/lib/libdvbv5/Makefile.am +++ b/lib/libdvbv5/Makefile.am @@ -27,6 +27,7 @@ otherinclude_HEADERS = \ ../include/libdvbv5/desc_t2_delivery.h \ ../include/libdvbv5/desc_service.h \ ../include/libdvbv5/desc_frequency_list.h \ + ../include/libdvbv5/desc_registration_id.h \ ../include/libdvbv5/desc_event_short.h \ ../include/libdvbv5/desc_event_extended.h \ ../include/libdvbv5/desc_atsc_service_location.h \ @@ -99,6 +100,7 @@ libdvbv5_la_SOURCES = \ descriptors/desc_terrestrial_delivery.c \ descriptors/desc_t2_delivery.c \ descriptors/desc_service.c \ + descriptors/desc_registration_id.c \ descriptors/desc_frequency_list.c \ descriptors/desc_event_short.c \ descriptors/desc_event_extended.c \ diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c index 0683dc1b..5a580f95 100644 --- a/lib/libdvbv5/descriptors.c +++ b/lib/libdvbv5/descriptors.c @@ -45,6 +45,7 @@ #include <libdvbv5/desc_isdbt_delivery.h> #include <libdvbv5/desc_service.h> #include <libdvbv5/desc_frequency_list.h> +#include <libdvbv5/desc_registration_id.h> #include <libdvbv5/desc_event_short.h> #include <libdvbv5/desc_event_extended.h> #include <libdvbv5/desc_atsc_service_location.h> @@ -261,10 +262,10 @@ const struct dvb_descriptor dvb_descriptors[] = { }, [registration_descriptor] = { .name = "registration_descriptor", - .init = NULL, - .print = NULL, - .free = NULL, - .size = 0, + .init = dvb_desc_registration_init, + .print = dvb_desc_registration_print, + .free = dvb_desc_registration_free, + .size = sizeof(struct dvb_desc_registration), }, [ds_alignment_descriptor] = { .name = "ds_alignment_descriptor", diff --git a/lib/libdvbv5/descriptors/desc_registration_id.c b/lib/libdvbv5/descriptors/desc_registration_id.c new file mode 100644 index 00000000..f9b3f843 --- /dev/null +++ b/lib/libdvbv5/descriptors/desc_registration_id.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020 - Mauro Carvalho Chehab + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 <libdvbv5/desc_registration_id.h> +#include <libdvbv5/dvb-fe.h> + +#if __GNUC__ >= 9 +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" +#endif + +int dvb_desc_registration_init(struct dvb_v5_fe_parms *parms, + const uint8_t *buf, struct dvb_desc *desc) +{ + struct dvb_desc_registration *d = (struct dvb_desc_registration *) desc; + size_t size = sizeof(d->format_identifier); + + if (desc->length < size) { + dvb_logerr("dvb_desc_registration_init short read %d/%zd bytes", desc->length, size); + return -1; + } + + memcpy(&d->format_identifier, buf, size); + bswap32(d->format_identifier); + + if (desc->length <= size) + return 0; + + d->additional_identification_info = malloc(desc->length - size); + memcpy(desc->data, buf + size, desc->length - size); + + return 0; +} + +void dvb_desc_registration_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc) +{ + const struct dvb_desc_registration *d = (const struct dvb_desc_registration *) desc; + int i = 0; + + dvb_loginfo("| format_identifier : %08x", d->format_identifier); + + if (!d->additional_identification_info) + return; + + for (i = 0; i < d->length - 4; i++) { + dvb_loginfo("| aditional_id_info[%d] : %02x", + i, d->additional_identification_info[i]); + } +} + +void dvb_desc_registration_free(struct dvb_desc *desc) +{ + const struct dvb_desc_registration *d = (const void *) desc; + + free(d->additional_identification_info); +} |