1 /* 2 * 3 * This library is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU Library General Public 5 * License as published by the Free Software Foundation; either 6 * version 2 of the License, or (at your option) any later version. 7 * 8 * This library is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * Library General Public License for more details. 12 * 13 * You should have received a copy of the GNU Library General Public 14 * License along with this library; if not, write to the 15 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 16 * Boston, MA 02110-1301, USA. 17 * 18 * The Original Code is Fluendo MPEG Demuxer plugin. 19 * 20 * The Initial Developer of the Original Code is Fluendo, S.L. 21 * Portions created by Fluendo, S.L. are Copyright (C) 2005 22 * Fluendo, S.L. All Rights Reserved. 23 * 24 * Contributor(s): Wim Taymans <wim@fluendo.com> 25 * 26 */ 27 28 #ifndef __GST_MPEG_DESC_H__ 29 #define __GST_MPEG_DESC_H__ 30 31 #include <glib.h> 32 33 34 /* Others */ 35 36 37 /* 0xFF is forbidden */ 38 39 /* common for all descriptors */ 40 #define DESC_TAG(desc) (desc[0]) 41 #define DESC_LENGTH(desc) (desc[1]) 42 43 /* video_stream_descriptor */ 44 #define DESC_VIDEO_STREAM_multiple_framerate_flag(desc) (((desc)[2] & 0x80) == 0x80) 45 #define DESC_VIDEO_STREAM_frame_rate_code(desc) (((desc)[2] & 0x38) >> 3) 46 #define DESC_VIDEO_STREAM_MPEG_1_only_flag(desc) (((desc)[2] & 0x04) == 0x04) 47 #define DESC_VIDEO_STREAM_constrained_parameter_flag(desc) (((desc)[2] & 0x02) == 0x02) 48 #define DESC_VIDEO_STREAM_still_picture_flag(desc) (((desc)[2] & 0x01) == 0x01) 49 /* if (MPEG_1_only_flag == 1) */ 50 #define DESC_VIDEO_STREAM_profile_and_level_indication(desc) ((desc)[3]) 51 #define DESC_VIDEO_STREAM_chroma_format(desc) (((desc)[4] & 0xc0) >> 6) 52 #define DESC_VIDEO_STREAM_frame_rate_extension_flag(desc) (((desc)[4] & 0x20) == 0x20) 53 54 /* audio_stream_descriptor */ 55 #define DESC_AUDIO_STREAM_free_format_flag(desc) (((desc)[2] & 0x80) == 0x80) 56 #define DESC_AUDIO_STREAM_ID(desc) (((desc)[2] & 0x40) == 0x40) 57 #define DESC_AUDIO_STREAM_layer(desc) (((desc)[2] & 0x30) >> 4) 58 #define DESC_AUDIO_STREAM_variable_rate_audio_indicator(desc) (((desc)[2] & 0x08) == 0x08) 59 60 /* hierarchy_descriptor */ 61 #define DESC_HIERARCHY_hierarchy_type(desc) (((desc)[2] & 0x0f)) 62 #define DESC_HIERARCHY_hierarchy_layer_index(desc) (((desc)[3] & 0x3f)) 63 #define DESC_HIERARCHY_hierarchy_embedded_layer_index(desc) (((desc)[4] & 0x3f)) 64 #define DESC_HIERARCHY_hierarchy_channel(desc) (((desc)[5] & 0x3f)) 65 66 /* registration_descriptor */ 67 #define DESC_REGISTRATION_format_identifier(desc) (GST_READ_UINT32_BE ((desc)+2)) 68 #define DESC_REGISTRATION_additional_ident_info_len(desc) ((desc)[1] - 4) 69 #define DESC_REGISTRATION_additional_ident_info(desc) (&(desc)[6]) 70 71 /* data_stream_alignment_descriptor */ 72 #define DESC_DATA_STREAM_ALIGNMENT_alignment_type(desc) ((desc)[2]) 73 74 /* target_background_grid_descriptor */ 75 #define DESC_TARGET_BACKGROUND_GRID_horizontal_size(desc) (GST_READ_UINT16_BE ((desc)+2) >> 2) 76 #define DESC_TARGET_BACKGROUND_GRID_vertical_size(desc) ((GST_READ_UINT32_BE ((desc)+2) & 0x0003fff0) >> 4) 77 #define DESC_TARGET_BACKGROUND_GRID_aspect_ratio_information(desc) ((desc)[5] & 0x0f) 78 79 /* video_window_descriptor */ 80 #define DESC_VIDEO_WINDOW_horizontal_offset(desc) (GST_READ_UINT16_BE ((desc)+2) >> 2) 81 #define DESC_VIDEO_WINDOW_vertical_offset(desc) ((GST_READ_UINT32_BE ((desc)+2) & 0x0003fff0) >> 4) 82 #define DESC_VIDEO_WINDOW_window_priority(desc) ((desc)[5] & 0x0f) 83 84 /* CA_descriptor */ 85 #define DESC_CA_system_ID(desc) (GST_READ_UINT16_BE ((desc)+2)) 86 #define DESC_CA_PID(desc) (GST_READ_UINT16_BE ((desc)+2) & 0x1fff) 87 88 /* ISO_639_language_descriptor */ 89 #define DESC_ISO_639_LANGUAGE_codes_n(desc) ((desc[1]) >> 2) 90 #define DESC_ISO_639_LANGUAGE_language_code_nth(desc,i) (&(desc[2 + (4*i)])) 91 #define DESC_ISO_639_LANGUAGE_audio_type_nth(desc,i) ((desc)[5 + (4*i)]) 92 93 /* system_clock_descriptor */ 94 #define DESC_SYSTEM_CLOCK_external_clock_reference_indicator(desc) (((desc)[2] & 0x80) == 0x80) 95 #define DESC_SYSTEM_CLOCK_clock_accuracy_integer(desc) ((desc)[2] & 0x3f) 96 #define DESC_SYSTEM_CLOCK_clock_accuracy_exponent(desc) (((desc)[3] & 0xe0) >> 5) 97 98 /* multiplex_buffer_utilization_descriptor */ 99 #define DESC_MULTIPLEX_BUFFER_UTILISATION_bound_valid_flag(desc) (((desc)[2] & 0x80) == 0x80) 100 #define DESC_MULTIPLEX_BUFFER_UTILISATION_LTW_offset_lower_bound(desc) (GST_READ_UINT16_BE ((desc)+2) & 0x7fff) 101 #define DESC_MULTIPLEX_BUFFER_UTILISATION_LTW_offset_upper_bound(desc) (GST_READ_UINT16_BE ((desc)+4) & 0x7fff) 102 103 /* copyright_descriptor */ 104 #define DESC_COPYRIGHT_copyright_identifier(desc) (GST_READ_UINT32_BE ((desc)+2)) 105 #define DESC_COPYRIGHT_additional_copyright_info_len(desc) ((desc)[1] - 4) 106 #define DESC_COPYRIGHT_additional_copyright_info(desc) (&(desc)[6]) 107 108 /* maximum_bitrate_descriptor */ 109 #define DESC_MAXIMUM_BITRAT_maximum_bitrate(desc) (((((guint32)desc[2]) & 0x3f) << 16) | \ 110 GST_READ_UINT16_BE ((desc)+3)) 111 112 /* private_data_indicator_descriptor */ 113 #define DESC_PRIVATE_DATA_INDICATOR_indicator(desc) (GST_READ_UINT32_BE(&desc[2])) 114 115 /* smoothing_buffer_descriptor */ 116 #define DESC_SMOOTHING_BUFFER_sb_leak_rate(desc) (((((guint32)desc[2]) & 0x3f) << 16) | \ 117 GST_READ_UINT16_BE ((desc)+3)) 118 #define DESC_SMOOTHING_BUFFER_sb_size(desc) (((((guint32)desc[5]) & 0x3f) << 16) | \ 119 GST_READ_UINT16_BE ((desc)+6)) 120 /* STD_descriptor */ 121 #define DESC_STD_leak_valid_flag(desc) (((desc)[2] & 0x01) == 0x01) 122 123 /* ibp_descriptor */ 124 #define DESC_IBP_closed_gop_flag(desc) (((desc)[2] & 0x80) == 0x80) 125 #define DESC_IBP_identical_gop_flag(desc) (((desc)[2] & 0x40) == 0x40) 126 #define DESC_IBP_max_gop_length(desc) (GST_READ_UINT16_BE ((desc)+6) & 0x3fff) 127 128 /* time_code descriptor */ 129 #define DESC_TIMECODE_video_pid(desc) (GST_READ_UINT16_BE ((desc) + 2) & 0x1fff) 130 131 /* Stream identifier descriptor */ 132 #define DESC_DVB_STREAM_IDENTIFIER_component_tag(desc) (desc[2]) 133 134 /* DVB Network Name descriptor */ 135 #define DESC_DVB_NETWORK_NAME_length(desc) (GST_READ_UINT8((desc)+1)) 136 #define DESC_DVB_NETWORK_NAME_text(desc) (desc+2) 137 138 /* DVB Service Descriptor */ 139 #define DESC_DVB_SERVICE_type(desc) (desc[2]) 140 #define DESC_DVB_SERVICE_provider_name_length(desc) (desc[3]) 141 #define DESC_DVB_SERVICE_provider_name_text(desc) (desc+4) 142 #define DESC_DVB_SERVICE_name_length(desc) (desc[4 + DESC_DVB_SERVICE_provider_name_length(desc)]) 143 #define DESC_DVB_SERVICE_name_text(desc) (desc + 5 + DESC_DVB_SERVICE_provider_name_length(desc)) 144 145 /* DVB Component Descriptor */ 146 #define DESC_DVB_COMPONENT_stream_content(desc) (desc[2] & 0x0F) 147 #define DESC_DVB_COMPONENT_type(desc) (desc[3]) 148 #define DESC_DVB_COMPONENT_tag(desc) (desc[4]) 149 #define DESC_DVB_COMPONENT_language(desc) (desc + 5) 150 151 /* DVB Bouquet Name Descriptor */ 152 #define DESC_DVB_BOUQUET_NAME_text(desc) (desc + 2) 153 154 /* DVB Short Event Descriptor */ 155 #define DESC_DVB_SHORT_EVENT_name_text(desc) (desc + 6) 156 #define DESC_DVB_SHORT_EVENT_name_length(desc) (desc[5]) 157 #define DESC_DVB_SHORT_EVENT_description_text(desc) (desc + 6 + DESC_DVB_SHORT_EVENT_name_length(desc) + 1) 158 #define DESC_DVB_SHORT_EVENT_description_length(desc) (desc[6 + DESC_DVB_SHORT_EVENT_name_length(desc)]) 159 160 /* DVB Extended Event Descriptor */ 161 #define DESC_DVB_EXTENDED_EVENT_descriptor_number(desc) ((desc[2] & 0xF0) >> 4) 162 #define DESC_DVB_EXTENDED_EVENT_last_descriptor_number(desc) (desc[2] & 0x0F) 163 #define DESC_DVB_EXTENDED_EVENT_iso639_language_code(desc) (desc + 3) 164 #define DESC_DVB_EXTENDED_EVENT_items_length(desc) (desc[6]) 165 #define DESC_DVB_EXTENDED_EVENT_items(desc) (desc + 7) 166 #define DESC_DVB_EXTENDED_EVENT_text_length(desc) (desc[7 + DESC_DVB_EXTENDED_EVENT_items_length(desc)]) 167 #define DESC_DVB_EXTENDED_EVENT_text(desc) (desc + 7 + DESC_DVB_EXTENDED_EVENT_items_length(desc) + 1) 168 169 /* DVB Satellite Delivery System Descriptor */ 170 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_frequency(desc) (desc + 2) 171 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_orbital_position(desc) (desc + 6) 172 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_west_east_flag(desc) ((desc[8] & 0x80) == 0x80) 173 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_polarization(desc) ((desc[8] >> 5) & 0x3) 174 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_modulation(desc) (desc[8] & 0x3) 175 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_symbol_rate(desc) (desc + 9) 176 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_fec_inner(desc) (desc[12] & 0x0F) 177 178 /* DVB Terrestrial Delivery System Descriptor */ 179 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_frequency(desc) (GST_READ_UINT32_BE((desc) + 2)) 180 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_bandwidth(desc) ((desc[6] >> 5) & 0x7) 181 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_constellation(desc) ((desc[7] >> 6) & 0x3) 182 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_hierarchy(desc) ((desc[7] >> 3) & 0x7) 183 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_code_rate_hp(desc) (desc[7] & 0x7) 184 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_code_rate_lp(desc) ((desc[8] >> 5) & 0x7) 185 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_guard_interval(desc) ((desc[8] >> 3) & 0x3) 186 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_transmission_mode(desc) ((desc[8] >> 1) & 0x3) 187 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_other_frequency(desc) ((desc[8] & 0x01) == 0x01) 188 189 /* DVB Cable Delivery System Descriptor */ 190 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_frequency(desc) (desc + 2) 191 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_fec_outer(desc) (desc[7] & 0x0F) 192 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_modulation(desc) (desc[8]) 193 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_symbol_rate(desc) (desc + 9) 194 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_fec_inner(desc) (desc[12] & 0x0F) 195 196 /* DVB Data Broadcast Descriptor */ 197 #define DESC_DVB_DATA_BROADCAST_data_broadcast_id(desc) (GST_READ_UINT16_BE((desc) + 2)) 198 #define DESC_DVB_DATA_BROADCAST_component_tag(desc) (desc[4]) 199 #define DESC_DVB_DATA_BROADCAST_selector_length(desc) (desc[5]) 200 #define DESC_DVB_DATA_BROADCAST_selector(desc) (desc + 6) 201 #define DESC_DVB_DATA_BROADCAST_iso639_language_code(desc) (desc + 6 + DESC_DVB_DATA_BROADCAST_selector_length(desc)) 202 #define DESC_DVB_DATA_BROADCAST_text_length(desc) (desc + 9 + DESC_DVB_DATA_BROADCAST_selector_length(desc)) 203 #define DESC_DVB_DATA_BROADCAST_text(desc) (desc + 10 + DESC_DVB_DATA_BROADCAST_selector_length(desc)) 204 205 /* DVB Data Broadcast Id Descriptor */ 206 #define DESC_DVB_DATA_BROADCAST_ID_data_broadcast_id(desc) (GST_READ_UINT16_BE((desc) + 2)) 207 #define DESC_DVB_DATA_BROADCAST_ID_id_selector_byte(desc) (desc + 4) 208 209 /* DVB Carousel Identifier Descriptor */ 210 #define DESC_DVB_CAROUSEL_IDENTIFIER_carousel_id(desc) (GST_READ_UINT32_BE((desc) + 2)) 211 212 /* AC3_audio_stream_descriptor */ 213 #define DESC_AC_AUDIO_STREAM_bsid(desc) ((desc)[2] & 0x1f) 214 215 /* FIXME : Move list of well know registration ids to an enum 216 * in the mpegts library. 217 * 218 * See http://www.smpte-ra.org/mpegreg/mpegreg.html for a full list 219 * */ 220 221 /* registration_descriptor format IDs */ 222 #define DRF_ID_HDMV 0x48444d56 223 #define DRF_ID_VC1 0x56432D31 /* defined in RP227 */ 224 #define DRF_ID_DTS1 0x44545331 225 #define DRF_ID_DTS2 0x44545332 226 #define DRF_ID_DTS3 0x44545333 227 #define DRF_ID_S302M 0x42535344 228 #define DRF_ID_TSHV 0x54534856 229 #define DRF_ID_AC3 0x41432d33 230 #define DRF_ID_GA94 0x47413934 231 #define DRF_ID_CUEI 0x43554549 232 #define DRF_ID_ETV1 0x45545631 233 #define DRF_ID_HEVC 0x48455643 234 #define DRF_ID_KLVA 0x4b4c5641 /* defined in RP217 */ 235 #define DRF_ID_OPUS 0x4f707573 236 #define DRF_ID_EAC3 0x45414333 /* defined in A/52 Annex G */ 237 #define DRF_ID_AC4 0x41432D34 /* defined in ETSI TS 103 190-2 Annex D */ 238 239 #endif /* __GST_MPEG_DESC_H__ */ 240