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/.
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
12 * The Original Code is Fluendo MPEG Demuxer plugin.
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.
18 * Contributor(s): Wim Taymans <wim@fluendo.com>
20 * Alternatively, the contents of this file may be used under the terms of
21 * the GNU Lesser General Public License Version 2 or later (the "LGPL"),
22 * in which case the provisions of the LGPL are applicable instead
23 * of those above. If you wish to allow use of your version of this file only
24 * under the terms of the LGPL, and not to allow others to
25 * use your version of this file under the terms of the MPL, indicate your
26 * decision by deleting the provisions above and replace them with the notice
27 * and other provisions required by the LGPL. If you do not delete
28 * the provisions above, a recipient may use your version of this file under
29 * the terms of the MPL or the LGPL.
32 #ifndef __GST_MPEG_DESC_H__
33 #define __GST_MPEG_DESC_H__
37 * descriptor_tag TS PS Identification
40 * 2 X X video_stream_descriptor
41 * 3 X X audio_stream_descriptor
42 * 4 X X hierarchy_descriptor
43 * 5 X X registration_descriptor
44 * 6 X X data_stream_alignment_descriptor
45 * 7 X X target_background_grid_descriptor
46 * 8 X X video_window_descriptor
48 * 10 X X ISO_639_language_descriptor
49 * 11 X X system_clock_descriptor
50 * 12 X X multiplex_buffer_utilization_descriptor
51 * 13 X X copyright_descriptor
52 * 14 X maximum bitrate descriptor
53 * 15 X X private data indicator descriptor
54 * 16 X X smoothing buffer descriptor
56 * 18 X X IBP descriptor
57 * 19-63 n/a n/a ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
58 * 64-255 n/a n/a User Private
60 #define DESC_VIDEO_STREAM 2
61 #define DESC_AUDIO_STREAM 3
62 #define DESC_HIERARCHY 4
63 #define DESC_REGISTRATION 5
64 #define DESC_DATA_STREAM_ALIGNMENT 6
65 #define DESC_TARGET_BACKGROUND_GRID 7
66 #define DESC_VIDEO_WINDOW 8
68 #define DESC_ISO_639_LANGUAGE 10
69 #define DESC_SYSTEM_CLOCK 11
70 #define DESC_MULTIPLEX_BUFFER_UTILISATION 12
71 #define DESC_COPYRIGHT 13
72 #define DESC_MAXIMUM_BITRATE 14
73 #define DESC_PRIVATE_DATA_INDICATOR 15
74 #define DESC_SMOOTHING_BUFFER 16
78 #define DESC_DIRAC_TC_PRIVATE 0xAC
81 #define DESC_DVB_CAROUSEL_IDENTIFIER 0x13
82 #define DESC_DVB_NETWORK_NAME 0x40
83 #define DESC_DVB_SERVICE_LIST 0x41
84 #define DESC_DVB_STUFFING 0x42
85 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM 0x43
86 #define DESC_DVB_CABLE_DELIVERY_SYSTEM 0x44
87 #define DESC_DVB_VBI_DATA 0x45
88 #define DESC_DVB_VBI_TELETEXT 0x46
89 #define DESC_DVB_BOUQUET_NAME 0x47
90 #define DESC_DVB_SERVICE 0x48
91 #define DESC_DVB_COUNTRY_AVAILABILITY 0x49
92 #define DESC_DVB_LINKAGE 0x4A
93 #define DESC_DVB_NVOD_REFERENCE 0x4B
94 #define DESC_DVB_TIME_SHIFTED_SERVICE 0x4C
95 #define DESC_DVB_SHORT_EVENT 0x4D
96 #define DESC_DVB_EXTENDED_EVENT 0x4E
97 #define DESC_DVB_TIME_SHIFTED_EVENT 0x4F
98 #define DESC_DVB_COMPONENT 0x50
99 #define DESC_DVB_MOSAIC 0x51
100 #define DESC_DVB_STREAM_IDENTIFIER 0x52
101 #define DESC_DVB_CA_IDENTIFIER 0x53
102 #define DESC_DVB_CONTENT 0x54
103 #define DESC_DVB_PARENTAL_RATING 0x55
104 #define DESC_DVB_TELETEXT 0x56
105 #define DESC_DVB_TELEPHONE 0x57
106 #define DESC_DVB_LOCAL_TIME_OFFSET 0x58
107 #define DESC_DVB_SUBTITLING 0x59
108 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM 0x5A
109 #define DESC_DVB_MULTILINGUAL_NETWORK_NAME 0x5B
110 #define DESC_DVB_MULTILINGUAL_BOUQUET_NAME 0x5C
111 #define DESC_DVB_MULTILINGUAL_SERVICE_NAME 0x5D
112 #define DESC_DVB_MULTILINGUAL_COMPONENT 0x5E
113 #define DESC_DVB_PRIVATE_DATA 0x5F
114 #define DESC_DVB_SERVICE_MOVE 0x60
115 #define DESC_DVB_SHORT_SMOOTHING_BUFFER 0x61
116 #define DESC_DVB_FREQUENCY_LIST 0x62
117 #define DESC_DVB_PARTIAL_TRANSPORT_STREAM 0x63
118 #define DESC_DVB_DATA_BROADCAST 0x64
119 #define DESC_DVB_SCRAMBLING 0x65
120 #define DESC_DVB_DATA_BROADCAST_ID 0x66
121 #define DESC_DVB_TRANSPORT_STREAM 0x67
122 #define DESC_DVB_DSNG 0x68
123 #define DESC_DVB_PDC 0x69
124 #define DESC_DVB_AC3 0x6A
125 #define DESC_DVB_ANCILLARY_DATA 0x6B
126 #define DESC_DVB_CELL_LIST 0x6C
127 #define DESC_DVB_CELL_FREQUENCY_LINK 0x6D
128 #define DESC_DVB_ANNOUNCEMENT_SUPPORT 0x6E
129 #define DESC_DVB_APPLICATION_SIGNALLING 0x6F
130 #define DESC_DVB_ADAPTATION_FIELD_DATA 0x70
131 #define DESC_DVB_SERVICE_IDENTIFIER 0x71
132 #define DESC_DVB_SERVICE_AVAILABILITY 0x72
133 #define DESC_DVB_DEFAULT_AUTHORITY 0x73
134 #define DESC_DVB_RELATED_CONTENT 0x74
135 #define DESC_DVB_TVA_ID 0x75
136 #define DESC_DVB_CONTENT_IDENTIFIER 0x76
137 #define DESC_DVB_TIMESLICE_FEC_IDENTIFIER 0x77
138 #define DESC_DVB_ECM_REPETITION_RATE 0x78
139 #define DESC_DVB_S2_SATELLITE_DELIVERY_SYSTEM 0x79
140 #define DESC_DVB_ENHANCED_AC3 0x7A
141 #define DESC_DVB_DTS 0x7B
142 #define DESC_DVB_AAC 0x7C
143 /* 0x7D and 0x7E are reserved for future use */
144 #define DESC_DVB_EXTENSION 0x7F
145 /* 0x80 - 0xFE are user defined */
146 #define DESC_DTG_LOGICAL_CHANNEL 0x83 /* from DTG D-Book */
147 /* 0xFF is forbidden */
149 /* common for all descriptors */
150 #define DESC_TAG(desc) (desc[0])
151 #define DESC_LENGTH(desc) (desc[1])
153 /* video_stream_descriptor */
154 #define DESC_VIDEO_STREAM_multiple_framerate_flag(desc) (((desc)[2] & 0x80) == 0x80)
155 #define DESC_VIDEO_STREAM_frame_rate_code(desc) (((desc)[2] & 0x38) >> 3)
156 #define DESC_VIDEO_STREAM_MPEG_1_only_flag(desc) (((desc)[2] & 0x04) == 0x04)
157 #define DESC_VIDEO_STREAM_constrained_parameter_flag(desc) (((desc)[2] & 0x02) == 0x02)
158 #define DESC_VIDEO_STREAM_still_picture_flag(desc) (((desc)[2] & 0x01) == 0x01)
159 /* if (MPEG_1_only_flag == 1) */
160 #define DESC_VIDEO_STREAM_profile_and_level_indication(desc) ((desc)[3])
161 #define DESC_VIDEO_STREAM_chroma_format(desc) (((desc)[4] & 0xc0) >> 6)
162 #define DESC_VIDEO_STREAM_frame_rate_extension_flag(desc) (((desc)[4] & 0x20) == 0x20)
164 /* audio_stream_descriptor */
165 #define DESC_AUDIO_STREAM_free_format_flag(desc) (((desc)[2] & 0x80) == 0x80)
166 #define DESC_AUDIO_STREAM_ID(desc) (((desc)[2] & 0x40) == 0x40)
167 #define DESC_AUDIO_STREAM_layer(desc) (((desc)[2] & 0x30) >> 4)
168 #define DESC_AUDIO_STREAM_variable_rate_audio_indicator(desc) (((desc)[2] & 0x08) == 0x08)
170 /* hierarchy_descriptor */
171 #define DESC_HIERARCHY_hierarchy_type(desc) (((desc)[2] & 0x0f))
172 #define DESC_HIERARCHY_hierarchy_layer_index(desc) (((desc)[3] & 0x3f))
173 #define DESC_HIERARCHY_hierarchy_embedded_layer_index(desc) (((desc)[4] & 0x3f))
174 #define DESC_HIERARCHY_hierarchy_channel(desc) (((desc)[5] & 0x3f))
176 /* registration_descriptor */
177 #define DESC_REGISTRATION_format_identifier(desc) (GST_READ_UINT32_BE ((desc)+2))
178 #define DESC_REGISTRATION_additional_ident_info_len(desc) ((desc)[1] - 4)
179 #define DESC_REGISTRATION_additional_ident_info(desc) (&(desc)[6])
181 /* data_stream_alignment_descriptor */
182 #define DESC_DATA_STREAM_ALIGNMENT_alignment_type(desc) ((desc)[2])
184 /* target_background_grid_descriptor */
185 #define DESC_TARGET_BACKGROUND_GRID_horizontal_size(desc) (GST_READ_UINT16_BE ((desc)+2) >> 2)
186 #define DESC_TARGET_BACKGROUND_GRID_vertical_size(desc) ((GST_READ_UINT32_BE ((desc)+2) & 0x0003fff0) >> 4)
187 #define DESC_TARGET_BACKGROUND_GRID_aspect_ratio_information(desc) ((desc)[5] & 0x0f)
189 /* video_window_descriptor */
190 #define DESC_VIDEO_WINDOW_horizontal_offset(desc) (GST_READ_UINT16_BE ((desc)+2) >> 2)
191 #define DESC_VIDEO_WINDOW_vertical_offset(desc) ((GST_READ_UINT32_BE ((desc)+2) & 0x0003fff0) >> 4)
192 #define DESC_VIDEO_WINDOW_window_priority(desc) ((desc)[5] & 0x0f)
195 #define DESC_CA_system_ID(desc) (GST_READ_UINT16_BE ((desc)+2))
196 #define DESC_CA_PID(desc) (GST_READ_UINT16_BE ((desc)+2) & 0x1fff)
198 /* ISO_639_language_descriptor */
199 #define DESC_ISO_639_LANGUAGE_codes_n(desc) ((desc[1]) >> 2)
200 #define DESC_ISO_639_LANGUAGE_language_code_nth(desc,i) (&(desc[2 + (4*i)]))
201 #define DESC_ISO_639_LANGUAGE_audio_type_nth(desc,i) ((desc)[5 + (4*i)])
203 /* system_clock_descriptor */
204 #define DESC_SYSTEM_CLOCK_external_clock_reference_indicator(desc) (((desc)[2] & 0x80) == 0x80)
205 #define DESC_SYSTEM_CLOCK_clock_accuracy_integer(desc) ((desc)[2] & 0x3f)
206 #define DESC_SYSTEM_CLOCK_clock_accuracy_exponent(desc) (((desc)[3] & 0xe0) >> 5)
208 /* multiplex_buffer_utilization_descriptor */
209 #define DESC_MULTIPLEX_BUFFER_UTILISATION_bound_valid_flag(desc) (((desc)[2] & 0x80) == 0x80)
210 #define DESC_MULTIPLEX_BUFFER_UTILISATION_LTW_offset_lower_bound(desc) (GST_READ_UINT16_BE ((desc)+2) & 0x7fff)
211 #define DESC_MULTIPLEX_BUFFER_UTILISATION_LTW_offset_upper_bound(desc) (GST_READ_UINT16_BE ((desc)+4) & 0x7fff)
213 /* copyright_descriptor */
214 #define DESC_COPYRIGHT_copyright_identifier(desc) (GST_READ_UINT32_BE ((desc)+2))
215 #define DESC_COPYRIGHT_additional_copyright_info_len(desc) ((desc)[1] - 4)
216 #define DESC_COPYRIGHT_additional_copyright_info(desc) (&(desc)[6])
218 /* maximum_bitrate_descriptor */
219 #define DESC_MAXIMUM_BITRAT_maximum_bitrate(desc) (((((guint32)desc[2]) & 0x3f) << 16) | \
220 GST_READ_UINT16_BE ((desc)+3))
222 /* private_data_indicator_descriptor */
223 #define DESC_PRIVATE_DATA_INDICATOR_indicator(desc) (GST_READ_UINT32_BE(&desc[2]))
225 /* smoothing_buffer_descriptor */
226 #define DESC_SMOOTHING_BUFFER_sb_leak_rate(desc) (((((guint32)desc[2]) & 0x3f) << 16) | \
227 GST_READ_UINT16_BE ((desc)+3))
228 #define DESC_SMOOTHING_BUFFER_sb_size(desc) (((((guint32)desc[5]) & 0x3f) << 16) | \
229 GST_READ_UINT16_BE ((desc)+6))
231 #define DESC_STD_leak_valid_flag(desc) (((desc)[2] & 0x01) == 0x01)
234 #define DESC_IBP_closed_gop_flag(desc) (((desc)[2] & 0x80) == 0x80)
235 #define DESC_IBP_identical_gop_flag(desc) (((desc)[2] & 0x40) == 0x40)
236 #define DESC_IBP_max_gop_length(desc) (GST_READ_UINT16_BE ((desc)+6) & 0x3fff)
238 /* time_code descriptor */
239 #define DESC_TIMECODE_video_pid(desc) (GST_READ_UINT16_BE ((desc) + 2) & 0x1fff)
241 /* Stream identifier descriptor */
242 #define DESC_DVB_STREAM_IDENTIFIER_component_tag(desc) (desc[2])
244 /* DVB Network Name descriptor */
245 #define DESC_DVB_NETWORK_NAME_length(desc) (GST_READ_UINT8((desc)+1))
246 #define DESC_DVB_NETWORK_NAME_text(desc) (desc+2)
248 /* DVB Service Descriptor */
249 #define DESC_DVB_SERVICE_type(desc) (desc[2])
250 #define DESC_DVB_SERVICE_provider_name_length(desc) (desc[3])
251 #define DESC_DVB_SERVICE_provider_name_text(desc) (desc+4)
252 #define DESC_DVB_SERVICE_name_length(desc) (desc[4 + DESC_DVB_SERVICE_provider_name_length(desc)])
253 #define DESC_DVB_SERVICE_name_text(desc) (desc + 5 + DESC_DVB_SERVICE_provider_name_length(desc))
255 /* DVB Component Descriptor */
256 #define DESC_DVB_COMPONENT_stream_content(desc) (desc[2] & 0x0F)
257 #define DESC_DVB_COMPONENT_type(desc) (desc[3])
258 #define DESC_DVB_COMPONENT_tag(desc) (desc[4])
259 #define DESC_DVB_COMPONENT_language(desc) (desc + 5)
261 /* DVB Bouquet Name Descriptor */
262 #define DESC_DVB_BOUQUET_NAME_text(desc) (desc + 2)
264 /* DVB Short Event Descriptor */
265 #define DESC_DVB_SHORT_EVENT_name_text(desc) (desc + 6)
266 #define DESC_DVB_SHORT_EVENT_name_length(desc) (desc[5])
267 #define DESC_DVB_SHORT_EVENT_description_text(desc) (desc + 6 + DESC_DVB_SHORT_EVENT_name_length(desc) + 1)
268 #define DESC_DVB_SHORT_EVENT_description_length(desc) (desc[6 + DESC_DVB_SHORT_EVENT_name_length(desc)])
270 /* DVB Extended Event Descriptor */
271 #define DESC_DVB_EXTENDED_EVENT_descriptor_number(desc) ((desc[2] & 0xF0) >> 4)
272 #define DESC_DVB_EXTENDED_EVENT_last_descriptor_number(desc) (desc[2] & 0x0F)
273 #define DESC_DVB_EXTENDED_EVENT_iso639_language_code(desc) (desc + 3)
274 #define DESC_DVB_EXTENDED_EVENT_items_length(desc) (desc[6])
275 #define DESC_DVB_EXTENDED_EVENT_items(desc) (desc + 7)
276 #define DESC_DVB_EXTENDED_EVENT_text_length(desc) (desc[7 + DESC_DVB_EXTENDED_EVENT_items_length(desc)])
277 #define DESC_DVB_EXTENDED_EVENT_text(desc) (desc + 7 + DESC_DVB_EXTENDED_EVENT_items_length(desc) + 1)
279 /* DVB Satellite Delivery System Descriptor */
280 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_frequency(desc) (desc + 2)
281 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_orbital_position(desc) (desc + 6)
282 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_west_east_flag(desc) ((desc[8] & 0x80) == 0x80)
283 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_polarization(desc) ((desc[8] >> 5) & 0x3)
284 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_modulation(desc) (desc[8] & 0x1F)
285 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_symbol_rate(desc) (desc + 9)
286 #define DESC_DVB_SATELLITE_DELIVERY_SYSTEM_fec_inner(desc) (desc[12] & 0x0F)
288 /* DVB Terrestrial Delivery System Descriptor */
289 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_frequency(desc) (GST_READ_UINT32_BE((desc) + 2))
290 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_bandwidth(desc) ((desc[6] >> 5) & 0x7)
291 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_constellation(desc) ((desc[7] >> 6) & 0x3)
292 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_hierarchy(desc) ((desc[7] >> 3) & 0x7)
293 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_code_rate_hp(desc) (desc[7] & 0x7)
294 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_code_rate_lp(desc) ((desc[8] >> 5) & 0x7)
295 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_guard_interval(desc) ((desc[8] >> 3) & 0x3)
296 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_transmission_mode(desc) ((desc[8] >> 1) & 0x3)
297 #define DESC_DVB_TERRESTRIAL_DELIVERY_SYSTEM_other_frequency(desc) ((desc[8] & 0x01) == 0x01)
299 /* DVB Cable Delivery System Descriptor */
300 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_frequency(desc) (desc + 2)
301 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_fec_outer(desc) (desc[7] & 0x0F)
302 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_modulation(desc) (desc[8])
303 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_symbol_rate(desc) (desc + 9)
304 #define DESC_DVB_CABLE_DELIVERY_SYSTEM_fec_inner(desc) (desc[12] & 0x0F)
306 /* DVB Data Broadcast Descriptor */
307 #define DESC_DVB_DATA_BROADCAST_data_broadcast_id(desc) (GST_READ_UINT16_BE((desc) + 2))
308 #define DESC_DVB_DATA_BROADCAST_component_tag(desc) (desc[4])
309 #define DESC_DVB_DATA_BROADCAST_selector_length(desc) (desc[5])
310 #define DESC_DVB_DATA_BROADCAST_selector(desc) (desc + 6)
311 #define DESC_DVB_DATA_BROADCAST_iso639_language_code(desc) (desc + 6 + DESC_DVB_DATA_BROADCAST_selector_length(desc))
312 #define DESC_DVB_DATA_BROADCAST_text_length(desc) (desc + 9 + DESC_DVB_DATA_BROADCAST_selector_length(desc))
313 #define DESC_DVB_DATA_BROADCAST_text(desc) (desc + 10 + DESC_DVB_DATA_BROADCAST_selector_length(desc))
315 /* DVB Data Broadcast Id Descriptor */
316 #define DESC_DVB_DATA_BROADCAST_ID_data_broadcast_id(desc) (GST_READ_UINT16_BE((desc) + 2))
317 #define DESC_DVB_DATA_BROADCAST_ID_id_selector_byte(desc) (desc + 4)
319 /* DVB Carousel Identifier Descriptor */
320 #define DESC_DVB_CAROUSEL_IDENTIFIER_carousel_id(desc) (GST_READ_UINT32_BE((desc) + 2))
322 /* registration_descriptor format IDs */
323 #define DRF_ID_HDMV 0x48444d56
324 #define DRF_ID_VC1 0x56432D31 /* defined in RP227 */
332 void gst_mpegtsdesc_init_debug (void);
333 GstMPEGDescriptor* gst_mpeg_descriptor_parse (guint8 *data, guint size);
334 void gst_mpeg_descriptor_free (GstMPEGDescriptor *desc);
336 guint gst_mpeg_descriptor_n_desc (GstMPEGDescriptor *desc);
337 guint8* gst_mpeg_descriptor_find (GstMPEGDescriptor *desc, gint tag);
338 GArray* gst_mpeg_descriptor_find_all (GstMPEGDescriptor * desc, gint tag);
340 guint8* gst_mpeg_descriptor_nth (GstMPEGDescriptor *desc, guint i);
342 #endif /* __GST_MPEG_DESC_H__ */