diff --git a/README b/README index 16152e5..3153904 100644 --- a/README +++ b/README @@ -126,6 +126,7 @@ Supported DVB descriptors * Descriptor 0x5a: Terrestrial delivery system descriptor * Descriptor 0x5b: Multilingual network name descriptor * Descriptor 0x5c: Multilingual bouquet name descriptor + * Descriptor 0x5d: Multilingual service name descriptor * Descriptor 0x5f: Private data specifier descriptor * Descriptor 0x6a: AC-3 descriptor [p] diff --git a/TODO b/TODO index c59c3c2..55f330e 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,6 @@ so if you like something just do it and send a patch. - Descriptor 0x6a: AC-3 descriptor - Add support (parser, generator, example) for these DVB descriptors: - - Descriptor 0x5d: multilingual_service_name_descriptor - Descriptor 0x5e: multilingual_component_descriptor - Descriptor 0x60: service_move_descriptor - Descriptor 0x61: short_smoothing_buffer_descriptor diff --git a/dvb/si/desc_5d.h b/dvb/si/desc_5d.h new file mode 100644 index 0000000..aa1431c --- /dev/null +++ b/dvb/si/desc_5d.h @@ -0,0 +1,170 @@ +/***************************************************************************** + * desc_5d.h: ETSI EN 300 468 Descriptor 0x5d: Multilingual service name + ***************************************************************************** + * Copyright (C) 2009-2010 VideoLAN + * + * Authors: Christophe Massiot + * Georgi Chorbadzhiyski + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *****************************************************************************/ + +/* + * Normative references: + * - ETSI EN 300 468 V1.11.1 (2010-04) (SI in DVB systems) + */ + +#ifndef __BITSTREAM_DVB_DESC_5D_H__ +#define __BITSTREAM_DVB_DESC_5D_H__ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/***************************************************************************** + * Descriptor 0x5d: Multilingual service name + *****************************************************************************/ +#define DESC5D_HEADER_SIZE DESC_HEADER_SIZE +#define DESC5D_DATA_SIZE 5 + +static inline void desc5d_init(uint8_t *p_desc) +{ + desc_set_tag(p_desc, 0x5d); +} + +#define desc5dn_set_code desc0an_set_code +#define desc5dn_get_code desc0an_get_code + +static inline uint8_t desc5dn_get_provider_name_length(const uint8_t *p_desc_n) +{ + return p_desc_n[3]; +} + +static inline const uint8_t *desc5dn_get_provider_name(const uint8_t *p_desc_n, uint8_t *pi_length) +{ + *pi_length = desc5dn_get_provider_name_length(p_desc_n); + return p_desc_n + 4; +} + +static inline void desc5dn_set_provider_name(uint8_t *p_desc_n, const uint8_t *p_network_name, uint8_t i_length) +{ + p_desc_n[3] = i_length; + memcpy(p_desc_n + 4, p_network_name, i_length); +} + +static inline uint8_t desc5dn_get_service_name_length(const uint8_t *p_desc_n) +{ + return p_desc_n[4 + desc5dn_get_provider_name_length(p_desc_n)]; +} + +static inline const uint8_t *desc5dn_get_service_name(const uint8_t *p_desc_n, uint8_t *pi_length) +{ + *pi_length = desc5dn_get_service_name_length(p_desc_n); + return p_desc_n + 5 + desc5dn_get_provider_name_length(p_desc_n); +} + +static inline void desc5dn_set_service_name(uint8_t *p_desc_n, const uint8_t *p_network_name, uint8_t i_length) +{ + p_desc_n[4 + desc5dn_get_provider_name_length(p_desc_n)] = i_length; + memcpy(p_desc_n + 5 + desc5dn_get_provider_name_length(p_desc_n), + p_network_name, i_length); +} + +static inline uint8_t *desc5d_get_data(const uint8_t *p_desc, uint8_t n) +{ + const uint8_t *p_desc_n = p_desc + DESC5D_HEADER_SIZE; + uint8_t i_desc_size = desc_get_length(p_desc); + + while (n) { + if (p_desc_n + DESC5D_DATA_SIZE - p_desc > i_desc_size) + return NULL; + p_desc_n += DESC5D_DATA_SIZE + + desc5dn_get_provider_name_length(p_desc_n) + + desc5dn_get_service_name_length(p_desc_n); + n--; + } + if (p_desc_n - p_desc > i_desc_size) + return NULL; + return (uint8_t *)p_desc_n; +} + +static inline bool desc5d_validate(const uint8_t *p_desc) +{ + const uint8_t *p_desc_n = p_desc + DESC5D_HEADER_SIZE; + int i_desc_size = desc_get_length(p_desc); + while (i_desc_size > 0) + { + uint8_t i_data_sz = DESC5D_DATA_SIZE + + desc5dn_get_provider_name_length(p_desc_n) + + desc5dn_get_service_name_length(p_desc_n); + i_desc_size -= i_data_sz; + p_desc_n += i_data_sz; + } + return i_desc_size == 0; +} + +static inline void desc5d_print(const uint8_t *p_desc, + f_print pf_print, void *print_opaque, + f_iconv pf_iconv, void *iconv_opaque, + print_type_t i_print_type) +{ + const uint8_t *p_desc_n; + uint8_t j = 0; + + while ((p_desc_n = desc5d_get_data(p_desc, j++)) != NULL) { + uint8_t i_provider_name_length, i_service_name_length; + const uint8_t *p_provider_name = desc5dn_get_provider_name(p_desc_n, &i_provider_name_length); + const uint8_t *p_service_name = desc5dn_get_service_name(p_desc_n, &i_service_name_length); + char *psz_provider_name = dvb_string_get(p_provider_name, i_provider_name_length, pf_iconv, iconv_opaque); + char *psz_service_name = dvb_string_get(p_service_name, i_service_name_length, pf_iconv, iconv_opaque); + switch (i_print_type) { + case PRINT_XML: + psz_provider_name = dvb_string_xml_escape(psz_provider_name); + pf_print(print_opaque, + "", + desc5dn_get_code(p_desc_n), + psz_provider_name, + psz_service_name + ); + break; + default: + pf_print(print_opaque, + " - desc 5d multilingual_service_name code=\"%3.3s\" provider=\"%s\" service=\"%s\"", + desc5dn_get_code(p_desc_n), + psz_provider_name, + psz_service_name + ); + } + free(psz_provider_name); + free(psz_service_name); + } +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dvb/si/descs_list.h b/dvb/si/descs_list.h index f4d699a..3965b95 100644 --- a/dvb/si/descs_list.h +++ b/dvb/si/descs_list.h @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/examples/dvb_gen_si.c b/examples/dvb_gen_si.c index 4124405..9b48e08 100644 --- a/examples/dvb_gen_si.c +++ b/examples/dvb_gen_si.c @@ -937,7 +937,36 @@ static void build_desc5c(uint8_t *desc) { desc_set_length(desc, data_n - desc - DESC_HEADER_SIZE); } -/* --- Descriptor 0x5d: multilingual_service_name_descriptor */ +/* DVB Descriptor 0x5d: Multilingual service name descriptor */ +static void build_desc5d(uint8_t *desc) { + char *provider_name = "M Provider"; + char *service_name = "M Service"; + uint8_t k = 0; + uint8_t *data_n; + + desc5d_init(desc); + desc_set_length(desc, 255); + + data_n = desc5d_get_data(desc, k++); + desc5dn_set_code(data_n, (uint8_t *)"eng"); + desc5dn_set_provider_name(data_n, (uint8_t *)provider_name, strlen(provider_name)); + desc5dn_set_service_name(data_n, (uint8_t *)service_name, strlen(service_name)); + + data_n = desc5d_get_data(desc, k++); + desc5dn_set_code(data_n, (uint8_t *)"fre"); + desc5dn_set_provider_name(data_n, (uint8_t *)provider_name, strlen(provider_name)); + desc5dn_set_service_name(data_n, (uint8_t *)service_name, strlen(service_name)); + + data_n = desc5d_get_data(desc, k++); + desc5dn_set_code(data_n, (uint8_t *)"bul"); + desc5dn_set_provider_name(data_n, (uint8_t *)provider_name, strlen(provider_name)); + desc5dn_set_service_name(data_n, (uint8_t *)service_name, strlen(service_name)); + + + data_n = desc5d_get_data(desc, k); + desc_set_length(desc, data_n - desc - DESC_HEADER_SIZE); +} + /* --- Descriptor 0x5e: multilingual_component_descriptor */ /* DVB Descriptor 0x5f: Private data specifier descriptor */ static void build_desc5f(uint8_t *desc) { @@ -1465,6 +1494,9 @@ static void generate_sdt(void) { desc = descs_get_desc(desc_loop, desc_counter++); build_desc57(desc); + desc = descs_get_desc(desc_loop, desc_counter++); + build_desc5d(desc); + desc = descs_get_desc(desc_loop, desc_counter++); build_desc5f(desc); diff --git a/examples/dvb_print_si.output.txt b/examples/dvb_print_si.output.txt index 7abc51c..2f6fdac 100644 --- a/examples/dvb_print_si.output.txt +++ b/examples/dvb_print_si.output.txt @@ -88,6 +88,9 @@ new SDT actual tsid=10000 version=1 onid=40000 - elementary_cell cell_id=7 - elementary_cell cell_id=8 - desc 57 telephone foreign_availability=1 connection_type=3 country_prefix=+ international_area_code=359 operator_code=2 national_area_code= core_number=9868620 phone=+35929868620 + - desc 5d multilingual_service_name code="eng" provider="M Provider" service="M Service" + - desc 5d multilingual_service_name code="fre" provider="M Provider" service="M Service" + - desc 5d multilingual_service_name code="bul" provider="M Provider" service="M Service" - desc 5f private_data specifier=0xaabbccdd * service sid=20100 eit_schedule running=1 - desc 48 service type=0x1 provider="Test Provider Name" service="Test Service Name" diff --git a/examples/dvb_print_si.output.xml b/examples/dvb_print_si.output.xml index 3bf1139..9ad0d5f 100644 --- a/examples/dvb_print_si.output.xml +++ b/examples/dvb_print_si.output.xml @@ -140,6 +140,11 @@ + + + + + diff --git a/mpeg/psi/descs_print.h b/mpeg/psi/descs_print.h index 41aeb0f..32fe4d8 100644 --- a/mpeg/psi/descs_print.h +++ b/mpeg/psi/descs_print.h @@ -158,6 +158,7 @@ static inline void descl_print(uint8_t *p_descl, uint16_t i_length, CASE_DESC(5a) CASE_DESC_ICONV(5b) CASE_DESC_ICONV(5c) + CASE_DESC_ICONV(5d) CASE_DESC(6a) #undef CASE_DESC