1 /* 2 * The contents of this file are subject to the Mozilla Public License 3 * Version 1.1 (the "License"); you may not use this file except in 4 * compliance with the License. You may obtain a copy of the License at 5 * http://www.mozilla.org/MPL/. 6 * 7 * Software distributed under the License is distributed on an "AS IS" 8 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 9 * License for the specific language governing rights and limitations 10 * under the License. 11 * 12 * The Original Code is Fluendo MPEG Demuxer plugin. 13 * 14 * The Initial Developer of the Original Code is Fluendo, S.L. 15 * Portions created by Fluendo, S.L. are Copyright (C) 2005 16 * Fluendo, S.L. All Rights Reserved. 17 * 18 * Contributor(s): Wim Taymans <wim@fluendo.com> 19 * Jan Schmidt <thaytan@noraisin.net> 20 */ 21 22 #ifndef __GST_MPEG_DESC_H__ 23 #define __GST_MPEG_DESC_H__ 24 25 #include <glib.h> 26 /* 27 * descriptor_tag TS PS Identification 28 * 0 n/a n/a Reserved 29 * 1 n/a n/a Reserved 30 * 2 X X video_stream_descriptor 31 * 3 X X audio_stream_descriptor 32 * 4 X X hierarchy_descriptor 33 * 5 X X registration_descriptor 34 * 6 X X data_stream_alignment_descriptor 35 * 7 X X target_background_grid_descriptor 36 * 8 X X video_window_descriptor 37 * 9 X X CA_descriptor 38 * 10 X X ISO_639_language_descriptor 39 * 11 X X system_clock_descriptor 40 * 12 X X multiplex_buffer_utilization_descriptor 41 * 13 X X copyright_descriptor 42 * 14 X maximum bitrate descriptor 43 * 15 X X private data indicator descriptor 44 * 16 X X smoothing buffer descriptor 45 * 17 X STD_descriptor 46 * 18 X X IBP descriptor 47 * 19-63 n/a n/a ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved 48 * 64-255 n/a n/a User Private 49 */ 50 #define DESC_VIDEO_STREAM 2 51 #define DESC_AUDIO_STREAM 3 52 #define DESC_HIERARCHY 4 53 #define DESC_REGISTRATION 5 54 #define DESC_DATA_STREAM_ALIGNMENT 6 55 #define DESC_TARGET_BACKGROUND_GRID 7 56 #define DESC_VIDEO_WINDOW 8 57 #define DESC_CA 9 58 #define DESC_ISO_639_LANGUAGE 10 59 #define DESC_SYSTEM_CLOCK 11 60 #define DESC_MULTIPLEX_BUFFER_UTILISATION 12 61 #define DESC_COPYRIGHT 13 62 #define DESC_MAXIMUM_BITRATE 14 63 #define DESC_PRIVATE_DATA_INDICATOR 15 64 #define DESC_SMOOTHING_BUFFER 16 65 #define DESC_STD 17 66 #define DESC_IBP 18 67 68 #define DESC_DIRAC_TC_PRIVATE 0xAC 69 70 /* DVB tags */ 71 #define DESC_DVB_NETWORK_NAME 0x40 72 #define DESC_DVB_SERVICE_LIST 0x41 73 #define DESC_DVB_STUFFING 0x42 74 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM 0x43 75 #define DESC_DVB_CABLE_DELIVERY_SYSTEM 0x44 76 #define DESC_DVB_VBI_DATA 0x45 77 #define DESC_DVB_VBI_TELETEXT 0x46 78 #define DESC_DVB_BOUQUET_NAME 0x47 79 #define DESC_DVB_SERVICE 0x48 80 #define DESC_DVB_COUNTRY_AVAILABILITY 0x49 81 #define DESC_DVB_LINKAGE 0x4A 82 #define DESC_DVB_NVOD_REFERENCE 0x4B 83 #define DESC_DVB_TIME_SHIFTED_SERVICE 0x4C 84 #define DESC_DVB_SHORT_EVENT 0x4D 85 #define DESC_DVB_EXTENDED_EVENT 0x4E 86 #define DESC_DVB_TIME_SHIFTED_EVENT 0x4F 87 #define DESC_DVB_COMPONENT 0x50 88 #define DESC_DVB_MOSAIC 0x51 89 #define DESC_DVB_STREAM_IDENTIFIER 0x52 90 #define DESC_DVB_CA_IDENTIFIER 0x53 91 #define DESC_DVB_CONTENT 0x54 92 #define DESC_DVB_PARENTAL_RATING 0x55 93 #define DESC_DVB_TELETEXT 0x56 94 #define DESC_DVB_TELEPHONE 0x57 95 #define DESC_DVB_LOCAL_TIME_OFFSET 0x58 96 #define DESC_DVB_SUBTITLING 0x59 97 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM 0x5A 98 #define DESC_DVB_MULTILINGUAL_NETWORK_NAME 0x5B 99 #define DESC_DVB_MULTILINGUAL_BOUQUET_NAME 0x5C 100 #define DESC_DVB_MULTILINGUAL_SERVICE_NAME 0x5D 101 #define DESC_DVB_MULTILINGUAL_COMPONENT 0x5E 102 #define DESC_DVB_PRIVATE_DATA 0x5F 103 #define DESC_DVB_SERVICE_MOVE 0x60 104 #define DESC_DVB_SHORT_SMOOTHING_BUFFER 0x61 105 #define DESC_DVB_FREQUENCY_LIST 0x62 106 #define DESC_DVB_PARTIAL_TRANSPORT_STREAM 0x63 107 #define DESC_DVB_DATA_BROADCAST 0x64 108 #define DESC_DVB_SCRAMBLING 0x65 109 #define DESC_DVB_DATA_BROADCAST_ID 0x66 110 #define DESC_DVB_TRANSPORT_STREAM 0x67 111 #define DESC_DVB_DSNG 0x68 112 #define DESC_DVB_PDC 0x69 113 #define DESC_DVB_AC3 0x6A 114 #define DESC_DVB_ANCILLARY_DATA 0x6B 115 #define DESC_DVB_CELL_LIST 0x6C 116 #define DESC_DVB_CELL_FREQUENCY_LINK 0x6D 117 #define DESC_DVB_ANNOUNCEMENT_SUPPORT 0x6E 118 #define DESC_DVB_APPLICATION_SIGNALLING 0x6F 119 #define DESC_DVB_ADAPTATION_FIELD_DATA 0x70 120 #define DESC_DVB_SERVICE_IDENTIFIER 0x71 121 #define DESC_DVB_SERVICE_AVAILABILITY 0x72 122 #define DESC_DVB_DEFAULT_AUTHORITY 0x73 123 #define DESC_DVB_RELATED_CONTENT 0x74 124 #define DESC_DVB_TVA_ID 0x75 125 #define DESC_DVB_CONTENT_IDENTIFIER 0x76 126 #define DESC_DVB_TIMESLICE_FEC_IDENTIFIER 0x77 127 #define DESC_DVB_ECM_REPETITION_RATE 0x78 128 #define DESC_DVB_S2_SATELLITE_DELIVERY_SYSTEM 0x79 129 #define DESC_DVB_ENHANCED_AC3 0x7A 130 #define DESC_DVB_DTS 0x7B 131 #define DESC_DVB_AAC 0x7C 132 /* 0x7D and 0x7E are reserved for future use */ 133 #define DESC_DVB_EXTENSION 0x7F 134 /* 0x80 - 0xFE are user defined */ 135 /* 0xFF is forbidden */ 136 137 /* common for all descriptors */ 138 #define DESC_TAG(desc) (desc[0]) 139 #define DESC_LENGTH(desc) (desc[1]) 140 141 /* video_stream_descriptor */ 142 #define DESC_VIDEO_STREAM_multiple_framerate_flag(desc) (((desc)[2] & 0x80) == 0x80) 143 #define DESC_VIDEO_STREAM_frame_rate_code(desc) (((desc)[2] & 0x38) >> 3) 144 #define DESC_VIDEO_STREAM_MPEG_1_only_flag(desc) (((desc)[2] & 0x04) == 0x04) 145 #define DESC_VIDEO_STREAM_constrained_parameter_flag(desc) (((desc)[2] & 0x02) == 0x02) 146 #define DESC_VIDEO_STREAM_still_picture_flag(desc) (((desc)[2] & 0x01) == 0x01) 147 /* if (MPEG_1_only_flag == 1) */ 148 #define DESC_VIDEO_STREAM_profile_and_level_indication(desc) ((desc)[3]) 149 #define DESC_VIDEO_STREAM_chroma_format(desc) (((desc)[4] & 0xc0) >> 6) 150 #define DESC_VIDEO_STREAM_frame_rate_extension_flag(desc) (((desc)[4] & 0x20) == 0x20) 151 152 /* audio_stream_descriptor */ 153 #define DESC_AUDIO_STREAM_free_format_flag(desc) (((desc)[2] & 0x80) == 0x80) 154 #define DESC_AUDIO_STREAM_ID(desc) (((desc)[2] & 0x40) == 0x40) 155 #define DESC_AUDIO_STREAM_layer(desc) (((desc)[2] & 0x30) >> 4) 156 #define DESC_AUDIO_STREAM_variable_rate_audio_indicator(desc) (((desc)[2] & 0x08) == 0x08) 157 158 /* hierarchy_descriptor */ 159 #define DESC_HIERARCHY_hierarchy_type(desc) (((desc)[2] & 0x0f)) 160 #define DESC_HIERARCHY_hierarchy_layer_index(desc) (((desc)[3] & 0x3f)) 161 #define DESC_HIERARCHY_hierarchy_embedded_layer_index(desc) (((desc)[4] & 0x3f)) 162 #define DESC_HIERARCHY_hierarchy_channel(desc) (((desc)[5] & 0x3f)) 163 164 /* registration_descriptor */ 165 #define DESC_REGISTRATION_format_identifier(desc) (GST_READ_UINT32_BE ((desc)+2)) 166 #define DESC_REGISTRATION_additional_ident_info_len(desc) ((desc)[1] - 4) 167 #define DESC_REGISTRATION_additional_ident_info(desc) (&(desc)[6]) 168 169 /* data_stream_alignment_descriptor */ 170 #define DESC_DATA_STREAM_ALIGNMENT_alignment_type(desc) ((desc)[2]) 171 172 /* target_background_grid_descriptor */ 173 #define DESC_TARGET_BACKGROUND_GRID_horizontal_size(desc) (GST_READ_UINT16_BE ((desc)+2) >> 2) 174 #define DESC_TARGET_BACKGROUND_GRID_vertical_size(desc) ((GST_READ_UINT32_BE ((desc)+2) & 0x0003fff0) >> 4) 175 #define DESC_TARGET_BACKGROUND_GRID_aspect_ratio_information(desc) ((desc)[5] & 0x0f) 176 177 /* video_window_descriptor */ 178 #define DESC_VIDEO_WINDOW_horizontal_offset(desc) (GST_READ_UINT16_BE ((desc)+2) >> 2) 179 #define DESC_VIDEO_WINDOW_vertical_offset(desc) ((GST_READ_UINT32_BE ((desc)+2) & 0x0003fff0) >> 4) 180 #define DESC_VIDEO_WINDOW_window_priority(desc) ((desc)[5] & 0x0f) 181 182 /* CA_descriptor */ 183 #define DESC_CA_system_ID(desc) (GST_READ_UINT16_BE ((desc)+2)) 184 #define DESC_CA_PID(desc) (GST_READ_UINT16_BE ((desc)+2) & 0x1fff) 185 186 /* ISO_639_language_descriptor */ 187 #define DESC_ISO_639_LANGUAGE_codes_n(desc) ((desc[1]) >> 2) 188 #define DESC_ISO_639_LANGUAGE_language_code_nth(desc,i) (&(desc[2 + (4*i)])) 189 #define DESC_ISO_639_LANGUAGE_audio_type_nth(desc,i) ((desc)[5 + (4*i)]) 190 191 /* system_clock_descriptor */ 192 #define DESC_SYSTEM_CLOCK_external_clock_reference_indicator(desc) (((desc)[2] & 0x80) == 0x80) 193 #define DESC_SYSTEM_CLOCK_clock_accuracy_integer(desc) ((desc)[2] & 0x3f) 194 #define DESC_SYSTEM_CLOCK_clock_accuracy_exponent(desc) (((desc)[3] & 0xe0) >> 5) 195 196 /* multiplex_buffer_utilization_descriptor */ 197 #define DESC_MULTIPLEX_BUFFER_UTILISATION_bound_valid_flag(desc) (((desc)[2] & 0x80) == 0x80) 198 #define DESC_MULTIPLEX_BUFFER_UTILISATION_LTW_offset_lower_bound(desc) (GST_READ_UINT16_BE ((desc)+2) & 0x7fff) 199 #define DESC_MULTIPLEX_BUFFER_UTILISATION_LTW_offset_upper_bound(desc) (GST_READ_UINT16_BE ((desc)+4) & 0x7fff) 200 201 /* copyright_descriptor */ 202 #define DESC_COPYRIGHT_copyright_identifier(desc) (GST_READ_UINT32_BE ((desc)+2)) 203 #define DESC_COPYRIGHT_additional_copyright_info_len(desc) ((desc)[1] - 4) 204 #define DESC_COPYRIGHT_additional_copyright_info(desc) (&(desc)[6]) 205 206 /* maximum_bitrate_descriptor */ 207 #define DESC_MAXIMUM_BITRAT_maximum_bitrate(desc) (((((guint32)desc[2]) & 0x3f) << 16) | \ 208 GST_READ_UINT16_BE ((desc)+3)) 209 210 /* private_data_indicator_descriptor */ 211 #define DESC_PRIVATE_DATA_INDICATOR_indicator(desc) (GST_READ_UINT32_BE(&desc[2])) 212 213 /* smoothing_buffer_descriptor */ 214 #define DESC_SMOOTHING_BUFFER_sb_leak_rate(desc) (((((guint32)desc[2]) & 0x3f) << 16) | \ 215 GST_READ_UINT16_BE ((desc)+3)) 216 #define DESC_SMOOTHING_BUFFER_sb_size(desc) (((((guint32)desc[5]) & 0x3f) << 16) | \ 217 GST_READ_UINT16_BE ((desc)+6)) 218 /* STD_descriptor */ 219 #define DESC_STD_leak_valid_flag(desc) (((desc)[2] & 0x01) == 0x01) 220 221 /* ibp_descriptor */ 222 #define DESC_IBP_closed_gop_flag(desc) (((desc)[2] & 0x80) == 0x80) 223 #define DESC_IBP_identical_gop_flag(desc) (((desc)[2] & 0x40) == 0x40) 224 #define DESC_IBP_max_gop_length(desc) (GST_READ_UINT16_BE ((desc)+6) & 0x3fff) 225 226 /* time_code descriptor */ 227 #define DESC_TIMECODE_video_pid(desc) (GST_READ_UINT16_BE ((desc) + 2) & 0x1fff) 228 229 /* Stream identifier descriptor */ 230 #define DESC_DVB_STREAM_IDENTIFIER_component_tag(desc) (desc[2]) 231 232 /* DVB Network Name descriptor */ 233 #define DESC_DVB_NETWORK_NAME_length(desc) (GST_READ_UINT8((desc)+1)) 234 #define DESC_DVB_NETWORK_NAME_text(desc) (desc+2) 235 236 typedef struct { 237 guint n_desc; 238 guint8 data_length; 239 guint8 *data; 240 } GstMPEGDescriptor; 241 242 GstMPEGDescriptor* gst_mpeg_descriptor_parse (guint8 *data, guint size); 243 void gst_mpeg_descriptor_free (GstMPEGDescriptor *desc); 244 245 guint gst_mpeg_descriptor_n_desc (GstMPEGDescriptor *desc); 246 guint8* gst_mpeg_descriptor_find (GstMPEGDescriptor *desc, gint tag); 247 guint8* gst_mpeg_descriptor_nth (GstMPEGDescriptor *desc, guint i); 248 249 #endif /* __GST_MPEG_DESC_H__ */ 250