diff --git a/README b/README index 2f01d3e..13ba973 100644 --- a/README +++ b/README @@ -89,6 +89,7 @@ Supported MPEG descriptors * Descriptor 0x22: FmxBufferSize descriptor * Descriptor 0x23: MultiplexBuffer descriptor * Descriptor 0x24: Content labeling descriptor + * Descriptor 0x25: Metadata pointer descriptor * Descriptor 0x27: Metadata STD descriptor * Descriptor 0x28: AVC video descriptor * Descriptor 0x2a: AVC timing and HRD descriptor diff --git a/TODO b/TODO index 7d42742..5264992 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ TODO items for biTStream. The items are not ordered by importance so if you like something just do it and send a patch. - Add support (parser, generator, example) for these MPEG descriptors: - - Descriptor 0x25 metadata_pointer_descriptor - Descriptor 0x26 metadata_descriptor - Descriptor 0x29 IPMP_descriptor (defined in ISO/IEC 13818-11, MPEG-2 IPMP) diff --git a/examples/dvb_gen_si.c b/examples/dvb_gen_si.c index 5eb19a4..6ff8866 100644 --- a/examples/dvb_gen_si.c +++ b/examples/dvb_gen_si.c @@ -446,6 +446,34 @@ static void build_desc24_3(uint8_t *desc) { desc24_set_length(desc); } +/* MPEG Descriptor 0x25: Metadata pointer descriptor */ +static void build_desc25(uint8_t *desc) { + desc25_init(desc); + + desc25_set_metadata_application_format(desc, 0xffff); + // Needs desc25_set_metadata_application_format(desc, 0xffff); + desc25_set_metadata_application_format_identifier(desc, 0x00112233); + + desc25_set_metadata_format(desc, 0xff); + // Needs desc25_set_metadata_format(desc, 0xff); + desc25_set_metadata_format_identifier(desc, 0xdeadbeaf); + + desc25_set_metadata_service_id(desc, 0x88); + + desc25_set_metadata_locator_record_flag(desc, true); + // Needs desc25_set_metadata_locator_record_flag(desc, true); + desc25_set_metadata_locator_record(desc, 3, (uint8_t *)"abc"); + + desc25_set_mpeg_carriage_flags(desc, 1); + // Needs desc25_set_mpeg_carriage_flags(desc, 0..2); + desc25_set_program_number(desc, 1000); + // Needs desc25_set_mpeg_carriage_flags(desc, 1); + desc25_set_ts_location(desc, 2000); + desc25_set_ts_id(desc, 3000); + + desc25_set_length(desc); +} + /* MPEG Descriptor 0x27: Metadata STD descriptor */ static void build_desc27(uint8_t *desc) { desc27_init(desc); @@ -2625,6 +2653,9 @@ static void generate_pmt(void) { desc = descs_get_desc(desc_loop, desc_counter++); build_desc24_3(desc); + desc = descs_get_desc(desc_loop, desc_counter++); + build_desc25(desc); + desc = descs_get_desc(desc_loop, desc_counter++); build_desc28(desc); diff --git a/examples/dvb_print_si.output.txt b/examples/dvb_print_si.output.txt index 43a0ecc..e975568 100644 --- a/examples/dvb_print_si.output.txt +++ b/examples/dvb_print_si.output.txt @@ -302,6 +302,7 @@ new PMT program=20000 version=1 pcrpid=110 - desc 24 content_labeling metadata_application_format=0xabcd metadata_application_format_identifier=0x00000000 content_reference_id_record_flag=0 content_reference_id_record_length=0 content_reference_id_record="" content_time_base_indicator=0 content_time_base_value="0" metadata_time_base_value="0" content_id=0 time_base_association_data_length=0 time_base_association_data="" - desc 24 content_labeling metadata_application_format=0xfff0 metadata_application_format_identifier=0x00000000 content_reference_id_record_flag=0 content_reference_id_record_length=0 content_reference_id_record="" content_time_base_indicator=3 content_time_base_value="0" metadata_time_base_value="0" content_id=0 time_base_association_data_length=3 time_base_association_data="414243" - desc 24 content_labeling metadata_application_format=0xffff metadata_application_format_identifier=0xaabbccdd content_reference_id_record_flag=1 content_reference_id_record_length=3 content_reference_id_record="616263" content_time_base_indicator=2 content_time_base_value="8337289456" metadata_time_base_value="8354132465" content_id=100 time_base_association_data_length=0 time_base_association_data="" + - desc 25 metadata_pointer_desc metadata_application_format=0xffff metadata_application_format_identifier=0x00112233 metadata_format=0xff metadata_format_identifier=0xdeadbeaf metadata_service_id=0x88 metadata_locator_record_flag=1 metadata_locator_record_length=3 metadata_locator_record="616263" mpeg_carriage_flags=1 program_number=1000 ts_location=2000 ts_id=3000 - desc 28 avc_video profile_idc=0x12 constraint_set0_flag=1 constraint_set1_flag=1 constraint_set2_flag=0 AVC_compatible_flags=0x0a level_idc=0x34 AVC_still_present=0 AVC_24_hour_picture_flag=0 - desc 2a avc_timing_and_hrd hrd_management_valid_flag=0 picture_and_timing_info_present=1 flag_90khz=0 N=12345678 K=34567890 num_units_in_tick=456789 fixed_frame_rate_flag=1 temporal_poc_flag=0 picture_to_display_conversion_flag=1 * ES pid=127 streamtype=0x0f streamtype_txt="13818-7 Audio with ADTS transport syntax" diff --git a/examples/dvb_print_si.output.xml b/examples/dvb_print_si.output.xml index 675cd38..c867417 100644 --- a/examples/dvb_print_si.output.xml +++ b/examples/dvb_print_si.output.xml @@ -544,6 +544,9 @@ + + + diff --git a/mpeg/psi/desc_25.h b/mpeg/psi/desc_25.h new file mode 100644 index 0000000..35be005 --- /dev/null +++ b/mpeg/psi/desc_25.h @@ -0,0 +1,324 @@ +/***************************************************************************** + * desc_25.h: ISO/IEC 13818-1 Descriptor 0x25 (Metadata pointer descriptor) + ***************************************************************************** + * Copyright (C) 2011 Unix Solutions Ltd. + * + * Authors: 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: + * - ISO/IEC 13818-1:2007(E) (MPEG-2 Systems) + */ + +#ifndef __BITSTREAM_MPEG_DESC_25_H__ +#define __BITSTREAM_MPEG_DESC_25_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/***************************************************************************** + * Descriptor 0x25 (Metadata pointer descriptor) + *****************************************************************************/ +#define DESC25_HEADER_SIZE (DESC_HEADER_SIZE + 5) + +static inline void desc25_init(uint8_t *p_desc) +{ + desc_set_tag(p_desc, 0x25); +} + +#define desc25_get_metadata_application_format desc24_get_metadata_application_format +#define desc25_set_metadata_application_format desc24_set_metadata_application_format +#define desc25_get_metadata_application_format_identifier desc24_get_metadata_application_format_identifier +#define desc25_set_metadata_application_format_identifier desc24_set_metadata_application_format_identifier + +#define __ofs1 \ + (4 + (desc25_get_metadata_application_format(p_desc) == 0xffff ? 4 : 0)) + +static inline uint8_t desc25_get_metadata_format(const uint8_t *p_desc) +{ + return p_desc[__ofs1]; +} + +static inline void desc25_set_metadata_format(uint8_t *p_desc, uint8_t i_format) +{ + p_desc[__ofs1] = i_format; +} + +static inline uint32_t desc25_get_metadata_format_identifier(const uint8_t *p_desc) +{ + if (desc25_get_metadata_format(p_desc) == 0xff) { + uint8_t ofs = __ofs1; + return (p_desc[ofs + 1] << 24) | (p_desc[ofs + 2] << 16) | (p_desc[ofs + 3] << 8) | p_desc[ofs + 4]; + } else { + return 0; + } +} + +static inline void desc25_set_metadata_format_identifier(uint8_t *p_desc, uint32_t i_identifier) +{ + if (desc25_get_metadata_format(p_desc) == 0xff) { + uint8_t ofs = __ofs1; + p_desc[ofs + 1] = (i_identifier >> 24) & 0xff; + p_desc[ofs + 2] = (i_identifier >> 16) & 0xff; + p_desc[ofs + 3] = (i_identifier >> 8) & 0xff; + p_desc[ofs + 4] = i_identifier & 0xff; + } +} + +#define __ofs2 \ + (__ofs1 + 1 + (desc25_get_metadata_format(p_desc) == 0xff ? 4 : 0)) + +static inline uint8_t desc25_get_metadata_service_id(const uint8_t *p_desc) +{ + return p_desc[__ofs2]; +} + +static inline void desc25_set_metadata_service_id(uint8_t *p_desc, uint8_t i_service_id) +{ + p_desc[__ofs2] = i_service_id; +} + +static inline bool desc25_get_metadata_locator_record_flag(const uint8_t *p_desc) +{ + return (p_desc[__ofs2 + 1] & 0x80) == 0x80; +} + +static inline void desc25_set_metadata_locator_record_flag(uint8_t *p_desc, bool b_flag) +{ + uint8_t ofs = __ofs2; + p_desc[ofs + 1] = (b_flag ? (p_desc[ofs + 1] | 0x80) : (p_desc[ofs + 1] &~ 0x80)) | 0x1f; +} + +static inline uint8_t desc25_get_mpeg_carriage_flags(const uint8_t *p_desc) +{ + return (p_desc[__ofs2 + 1] & 0x60) >> 5; +} + +static inline void desc25_set_mpeg_carriage_flags(uint8_t *p_desc, uint8_t i_flags) +{ + uint8_t ofs = __ofs2; + p_desc[ofs + 1] = ((p_desc[ofs + 1] & 0x80) | ((i_flags & 0x03) << 5)) | 0x1f; +} + + +static inline uint8_t desc25_get_metadata_locator_record_length(const uint8_t *p_desc) +{ + return desc25_get_metadata_locator_record_flag(p_desc) ? p_desc[__ofs2 + 2] : 0; +} + +static inline const uint8_t *desc25_get_metadata_locator_record_data(const uint8_t *p_desc) +{ + return desc25_get_metadata_locator_record_flag(p_desc) ? p_desc + __ofs2 + 3 : NULL; +} + +static inline const uint8_t *desc25_get_metadata_locator_record(const uint8_t *p_desc, uint8_t *i_length) +{ + *i_length = desc25_get_metadata_locator_record_length(p_desc); + return desc25_get_metadata_locator_record_data(p_desc); +} + +static inline void desc25_set_metadata_locator_record(uint8_t *p_desc, uint8_t i_length, uint8_t *p_data) +{ + if (desc25_get_metadata_locator_record_flag(p_desc)) { + uint8_t ofs = __ofs2; + p_desc[ofs + 2] = i_length; + memcpy(p_desc + ofs + 3, p_data, i_length); + } +} + + +#define __ofs3 \ + (__ofs2 + 1 + \ + (desc25_get_metadata_locator_record_flag(p_desc) \ + ? 1 + desc25_get_metadata_locator_record_length(p_desc) \ + : 0 \ + ) + 1 \ + ) + +static inline uint16_t desc25_get_program_number(const uint8_t *p_desc) +{ + uint8_t i_flags = desc25_get_mpeg_carriage_flags(p_desc); + if (i_flags == 0 || i_flags == 1 || i_flags == 2) { + uint8_t ofs = __ofs3; + return (p_desc[ofs + 0] << 8) | p_desc[ofs + 1]; + } else { + return 0; + } +} + +static inline void desc25_set_program_number(uint8_t *p_desc, uint16_t i_program) +{ + uint8_t i_flags = desc25_get_mpeg_carriage_flags(p_desc); + if (i_flags == 0 || i_flags == 1 || i_flags == 2) { + uint8_t ofs = __ofs3; + p_desc[ofs + 0] = (i_program >> 8) & 0xff; + p_desc[ofs + 1] = i_program & 0xff; + } +} + +static inline uint16_t desc25_get_ts_location(const uint8_t *p_desc) +{ + if (desc25_get_mpeg_carriage_flags(p_desc) == 1) { + uint8_t ofs = __ofs3; + return (p_desc[ofs + 2] << 8) | p_desc[ofs + 3]; + } else { + return 0; + } +} + +static inline void desc25_set_ts_location(uint8_t *p_desc, uint16_t i_ts_location) +{ + if (desc25_get_mpeg_carriage_flags(p_desc) == 1) { + uint8_t ofs = __ofs3; + p_desc[ofs + 2] = (i_ts_location >> 8) & 0xff; + p_desc[ofs + 3] = i_ts_location & 0xff; + } +} + +static inline uint16_t desc25_get_ts_id(const uint8_t *p_desc) +{ + if (desc25_get_mpeg_carriage_flags(p_desc) == 1) { + uint8_t ofs = __ofs3; + return (p_desc[ofs + 4] << 8) | p_desc[ofs + 5]; + } else { + return 0; + } +} + +static inline void desc25_set_ts_id(uint8_t *p_desc, uint16_t i_ts_id) +{ + if (desc25_get_mpeg_carriage_flags(p_desc) == 1) { + uint8_t ofs = __ofs3; + p_desc[ofs + 4] = (i_ts_id >> 8) & 0xff; + p_desc[ofs + 5] = i_ts_id & 0xff; + } +} + +#undef __ofs1 +#undef __ofs2 +#undef __ofs3 + +static inline int desc25_calc_length(const uint8_t *p_desc) +{ + int i_length = DESC25_HEADER_SIZE - DESC_HEADER_SIZE; + uint8_t i_flags = desc25_get_mpeg_carriage_flags(p_desc); + if (desc25_get_metadata_application_format(p_desc) == 0xffff) + i_length += 4; + if (desc25_get_metadata_format(p_desc) == 0xff) + i_length += 4; + if (desc25_get_metadata_locator_record_flag(p_desc)) + i_length += 1 + desc25_get_metadata_locator_record_length(p_desc); + if (i_flags == 0 || i_flags == 1 || i_flags == 2) + i_length += 2; + if (i_flags == 1) + i_length += 4; + return i_length; +} + +static inline bool desc25_validate(const uint8_t *p_desc) +{ + return desc25_calc_length(p_desc) <= desc_get_length(p_desc); +} + +static inline void desc25_set_length(uint8_t *p_desc) +{ + desc_set_length(p_desc, desc25_calc_length(p_desc)); +} + +static inline void desc25_print(const uint8_t *p_desc, f_print pf_print, + void *opaque, print_type_t i_print_type) +{ + uint8_t i, i_metadata_locator_record_length; + const uint8_t *p_metadata_locator_record = desc25_get_metadata_locator_record(p_desc, &i_metadata_locator_record_length); + char psz_metadata_locator_record[2 * 255 + 1]; + + for (i = 0; i < i_metadata_locator_record_length; i++) + sprintf(psz_metadata_locator_record + 2 * i, "%02x", p_metadata_locator_record[i]); + psz_metadata_locator_record[2 * i] = '\0'; + + switch (i_print_type) { + case PRINT_XML: + pf_print(opaque, + "", + desc25_get_metadata_application_format(p_desc), + desc25_get_metadata_application_format_identifier(p_desc), + desc25_get_metadata_format(p_desc), + desc25_get_metadata_format_identifier(p_desc), + desc25_get_metadata_service_id(p_desc), + desc25_get_metadata_locator_record_flag(p_desc), + desc25_get_metadata_locator_record_length(p_desc), + psz_metadata_locator_record, // desc25_get_metadata_locator_record_data(p_desc) + desc25_get_mpeg_carriage_flags(p_desc), + desc25_get_program_number(p_desc), + desc25_get_ts_location(p_desc), + desc25_get_ts_id(p_desc) + ); + break; + default: + pf_print(opaque, + " - desc 25 metadata_pointer_desc metadata_application_format=0x%04x" + " metadata_application_format_identifier=0x%08x" + " metadata_format=0x%02x" + " metadata_format_identifier=0x%08x" + " metadata_service_id=0x%02x" + " metadata_locator_record_flag=%u" + " metadata_locator_record_length=%u" + " metadata_locator_record=\"%s\"" + " mpeg_carriage_flags=%u" + " program_number=%u ts_location=%u ts_id=%u", + desc25_get_metadata_application_format(p_desc), + desc25_get_metadata_application_format_identifier(p_desc), + desc25_get_metadata_format(p_desc), + desc25_get_metadata_format_identifier(p_desc), + desc25_get_metadata_service_id(p_desc), + desc25_get_metadata_locator_record_flag(p_desc), + desc25_get_metadata_locator_record_length(p_desc), + psz_metadata_locator_record, // desc25_get_metadata_locator_record_data(p_desc) + desc25_get_mpeg_carriage_flags(p_desc), + desc25_get_program_number(p_desc), + desc25_get_ts_location(p_desc), + desc25_get_ts_id(p_desc) + ); + } +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mpeg/psi/descs_list.h b/mpeg/psi/descs_list.h index d6cbc7d..52cfefb 100644 --- a/mpeg/psi/descs_list.h +++ b/mpeg/psi/descs_list.h @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include diff --git a/mpeg/psi/descs_print.h b/mpeg/psi/descs_print.h index 9c98b39..d4f2439 100644 --- a/mpeg/psi/descs_print.h +++ b/mpeg/psi/descs_print.h @@ -127,6 +127,7 @@ static inline void descl_print(uint8_t *p_descl, uint16_t i_length, CASE_DESC(22) CASE_DESC(23) CASE_DESC(24) + CASE_DESC(25) CASE_DESC(27) CASE_DESC(28) CASE_DESC(2a)