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.
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.
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.
18 * The Original Code is Fluendo MPEG Demuxer plugin.
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.
24 * Contributor(s): Wim Taymans <wim@fluendo.com>
27 #ifndef __GST_MPEG_DEFS_H__
28 #define __GST_MPEG_DEFS_H__
31 * 1011 1100 program_stream_map
32 * 1011 1101 private_stream_1
33 * 1011 1110 padding_stream
34 * 1011 1111 private_stream_2
35 * 110x xxxx ISO/IEC 13818-3 or ISO/IEC 11172-3 audio stream number x xxxx
36 * 1110 xxxx ITU-T Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 11172-2 video stream number xxxx
37 * 1111 0000 ECM_stream
38 * 1111 0001 EMM_stream
39 * 1111 0010 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A or ISO/IEC 13818-6_DSMCC_stream
40 * 1111 0011 ISO/IEC_13522_stream
41 * 1111 0100 ITU-T Rec. H.222.1 type A
42 * 1111 0101 ITU-T Rec. H.222.1 type B
43 * 1111 0110 ITU-T Rec. H.222.1 type C
44 * 1111 0111 ITU-T Rec. H.222.1 type D
45 * 1111 1000 ITU-T Rec. H.222.1 type E
46 * 1111 1001 ancillary_stream
47 * 1111 1010 ISO/IEC 14496-1_SL-packetized_stream
48 * 1111 1011 ISO/IEC 14496-1_FlexMux_stream
49 * 1111 1100 metadata stream
50 * 1111 1101 extended_stream_id
51 * 1111 1110 reserved data stream
52 * 1111 1111 program_stream_directory
55 #define ID_PS_END_CODE 0x000001B9
56 #define ID_PS_PACK_START_CODE 0x000001BA
57 #define ID_PS_SYSTEM_HEADER_START_CODE 0x000001BB
58 #define ID_PS_PROGRAM_STREAM_MAP 0x000001BC
59 #define ID_PRIVATE_STREAM_1 0x000001BD
60 #define ID_PADDING_STREAM 0x000001BE
61 #define ID_PRIVATE_STREAM_2 0x000001BF
62 #define ID_ISO_IEC_MPEG12_AUDIO_STREAM_0 0x000001C0
63 #define ID_ISO_IEC_MPEG12_AUDIO_STREAM_32 0x000001DF
64 #define ID_ISO_IEC_MPEG12_VIDEO_STREAM_0 0x000001E0
65 #define ID_ISO_IEC_MPEG12_VIDEO_STREAM_16 0x000001EF
66 #define ID_ECM_STREAM 0x000001F0
67 #define ID_EMM_STREAM 0x000001F1
68 #define ID_DSMCC_STREAM 0x000001F2
69 #define ID_ISO_IEC_13522_STREAM 0x000001F3
70 #define ID_ITU_TREC_H222_TYPE_A_STREAM 0x000001F4
71 #define ID_ITU_TREC_H222_TYPE_B_STREAM 0x000001F5
72 #define ID_ITU_TREC_H222_TYPE_C_STREAM 0x000001F6
73 #define ID_ITU_TREC_H222_TYPE_D_STREAM 0x000001F7
74 #define ID_ITU_TREC_H222_TYPE_E_STREAM 0x000001F8
75 #define ID_ANCILLARY_STREAM 0x000001F9
76 #define ID_14496_1_SL_PACKETIZED_STREAM 0x000001FA
77 #define ID_14496_1_SL_FLEXMUX_STREAM 0x000001FB
78 #define ID_METADATA_STREAM 0x000001FC
79 #define ID_EXTENDED_STREAM_ID 0x000001FD
80 #define ID_RESERVED_STREAM_3 0x000001FE
81 #define ID_PROGRAM_STREAM_DIRECTORY 0x000001FF
83 #define PACKET_VIDEO_START_CODE 0x000001E0
84 #define PACKET_AUDIO_START_CODE 0x000001C0
85 #define PICTURE_START_CODE 0x00000100
86 #define USER_DATA_START_CODE 0x000001B2
87 #define SEQUENCE_HEADER_CODE 0x000001B3
88 #define SEQUENCE_ERROR_CODE 0x000001B4
89 #define EXTENSION_START_CODE 0x000001B5
90 #define SEQUENCE_END_CODE 0x000001B7
91 #define GROUP_START_CODE 0x000001B8
93 #define AC3_SYNC_WORD 0x0b770000
95 #define MPEG_TS_SYNC_BYTE 0x00000047
97 #define PID_PROGRAM_ASSOCIATION_TABLE 0x0000
98 #define PID_CONDITIONAL_ACCESS_TABLE 0x0001
99 #define PID_RESERVED_FIRST 0x0002
100 #define PID_RESERVED_LAST 0x0010
101 #define PID_NULL_PACKET 0x1FFF
103 #define PID_TYPE_UNKNOWN 0
104 #define PID_TYPE_RESERVED 1
105 #define PID_TYPE_PROGRAM_ASSOCIATION 2
106 #define PID_TYPE_CONDITIONAL_ACCESS 3
107 #define PID_TYPE_PROGRAM_MAP 4
108 #define PID_TYPE_ELEMENTARY 5
109 #define PID_TYPE_NULL_PACKET 6
110 #define PID_TYPE_PRIVATE_SECTION 7
112 /* Stream type assignments
114 * 0x00 ITU-T | ISO/IEC Reserved
115 * 0x01 ISO/IEC 11172 Video
116 * 0x02 ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or
117 * ISO/IEC 11172-2 constrained parameter video
119 * 0x03 ISO/IEC 11172 Audio
120 * 0x04 ISO/IEC 13818-3 Audio
121 * 0x05 ITU-T Rec. H.222.0 | ISO/IEC 13818-1
123 * 0x06 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES
124 * packets containing private data
125 * 0x07 ISO/IEC 13522 MHEG
126 * 0x08 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A
128 * 0x09 ITU-T Rec. H.222.1
129 * 0x0A ISO/IEC 13818-6 type A
130 * 0x0B ISO/IEC 13818-6 type B
131 * 0x0C ISO/IEC 13818-6 type C
132 * 0x0D ISO/IEC 13818-6 type D
133 * 0x0E ISO/IEC 13818-1 auxiliary
134 * 0x0F-0x7F ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
135 * 0x80-0xFF User Private
137 #define ST_RESERVED 0x00
138 #define ST_VIDEO_MPEG1 0x01
139 #define ST_VIDEO_MPEG2 0x02
140 #define ST_AUDIO_MPEG1 0x03
141 #define ST_AUDIO_MPEG2 0x04
142 #define ST_PRIVATE_SECTIONS 0x05
143 #define ST_PRIVATE_DATA 0x06
145 #define ST_DSMCC 0x08
146 #define ST_H222_1 0x09
148 #define ST_DSMCC_A 0x0a
149 #define ST_DSMCC_B 0x0b
150 #define ST_DSMCC_C 0x0c
151 #define ST_DSMCC_D 0x0d
153 /* later extensions */
154 #define ST_AUDIO_AAC_ADTS 0x0f
155 #define ST_VIDEO_MPEG4 0x10
156 #define ST_AUDIO_AAC_LATM 0x11
157 #define ST_VIDEO_H264 0x1b
159 /* Un-official Dirac extension */
160 #define ST_VIDEO_DIRAC 0xd1
162 /* private stream types */
163 #define ST_PS_AUDIO_AC3 0x81
164 #define ST_PS_AUDIO_DTS 0x8a
165 #define ST_PS_AUDIO_LPCM 0x8b
166 #define ST_PS_DVD_SUBPICTURE 0xff
167 /* Blu-ray related */
168 #define ST_BD_AUDIO_LPCM 0x80
169 #define ST_BD_AUDIO_AC3 0x81
170 #define ST_BD_AUDIO_DTS 0x82
171 #define ST_BD_AUDIO_AC3_TRUE_HD 0x83
172 #define ST_BD_AUDIO_AC3_PLUS 0x84
173 #define ST_BD_AUDIO_DTS_HD 0x85
174 #define ST_BD_AUDIO_DTS_HD_MASTER_AUDIO 0x86
175 #define ST_BD_AUDIO_EAC3 0x87
176 #define ST_BD_PGS_SUBPICTURE 0x90
177 #define ST_BD_IGS 0x91
178 #define ST_BD_SUBTITLE 0x92
179 #define ST_BD_SECONDARY_AC3_PLUS 0xa1
180 #define ST_BD_SECONDARY_DTS_HD 0xa2
182 /* defined for VC1 extension in RP227 */
183 #define ST_PRIVATE_EA 0xea
185 /* HDV AUX stream mapping
186 * 0xA0 ISO/IEC 61834-11
187 * 0xA1 ISO/IEC 61834-11
189 #define ST_HDV_AUX_A 0xa0
190 #define ST_HDV_AUX_V 0xa1
192 /* Un-official time-code stream */
193 #define ST_PS_TIMECODE 0xd2
195 /* Internal stream types >= 0x100 */
196 #define ST_GST_AUDIO_RAWA52 0x181
197 /* Used when we don't yet know which stream type it will be in a PS stream */
198 #define ST_GST_VIDEO_MPEG1_OR_2 0x102
202 /* ITU H.222.0 / IEC 13818-1 */
203 #define TABLE_ID_PROGRAM_ASSOCIATION 0x00
204 #define TABLE_ID_CONDITIONAL_ACCESS 0x01
205 #define TABLE_ID_TS_PROGRAM_MAP 0x02
206 #define TABLE_ID_TS_DESCRIPTION 0x03
207 #define TABLE_ID_14496_SCENE_DESCRIPTION 0x04
208 #define TABLE_ID_14496_OBJET_DESCRIPTOR 0x05
209 #define TABLE_ID_METADATA 0x06
210 #define TABLE_ID_IPMP_CONTROL_INFORMATION 0x07
211 /* IEC 13818-6 (DSM-CC) */
212 #define TABLE_ID_DSM_CC_MULTIPROTO_ENCAPSULATED_DATA 0x3A
213 #define TABLE_ID_DSM_CC_U_N_MESSAGES 0x3B
214 #define TABLE_ID_DSM_CC_DOWNLOAD_DATA_MESSAGES 0x3C
215 #define TABLE_ID_DSM_CC_STREAM_DESCRIPTORS 0x3D
216 #define TABLE_ID_DSM_CC_PRIVATE_DATA 0x3E
217 #define TABLE_ID_DSM_CC_ADDRESSABLE_SECTIONS 0x3F
218 /* EN 300 468 (DVB) v 1.12.1 */
219 #define TABLE_ID_NETWORK_INFORMATION_ACTUAL_NETWORK 0x40
220 #define TABLE_ID_NETWORK_INFORMATION_OTHER_NETWORK 0x41
221 #define TABLE_ID_SERVICE_DESCRIPTION_ACTUAL_TS 0x42
222 #define TABLE_ID_SERVICE_DESCRIPTION_OTHER_TS 0x46
223 #define TABLE_ID_BOUQUET_ASSOCIATION 0x4A
224 #define TABLE_ID_EVENT_INFORMATION_ACTUAL_TS_PRESENT 0x4E
225 #define TABLE_ID_EVENT_INFORMATION_OTHER_TS_PRESENT 0x4F
226 #define TABLE_ID_EVENT_INFORMATION_ACTUAL_TS_SCHEDULE_1 0x50 /* First */
227 #define TABLE_ID_EVENT_INFORMATION_ACTUAL_TS_SCHEDULE_N 0x5F /* Last */
228 #define TABLE_ID_EVENT_INFORMATION_OTHER_TS_SCHEDULE_1 0x60 /* First */
229 #define TABLE_ID_EVENT_INFORMATION_OTHER_TS_SCHEDULE_N 0x6F /* Last */
230 #define TABLE_ID_TIME_DATE 0x70
231 #define TABLE_ID_RUNNING_STATUS 0x71
232 #define TABLE_ID_STUFFING 0x72
233 #define TABLE_ID_TIME_OFFSET 0x73
234 /* TS 102 812 (MHP v1.1.3) */
235 #define TABLE_ID_APPLICATION_INFORMATION_TABLE 0x74
236 /* TS 102 323 (DVB TV Anytime v1.5.1) */
237 #define TABLE_ID_CONTAINER 0x75
238 #define TABLE_ID_RELATED_CONTENT 0x76
239 #define TABLE_ID_CONTENT_IDENTIFIER 0x77
240 /* EN 301 192 (DVB specification for data broadcasting) */
241 #define TABLE_ID_MPE_FEC 0x78
242 /* TS 102 323 (DVB TV Anytime v1.5.1) */
243 #define TABLE_ID_RESOLUTION_NOTIFICATION 0x79
244 /* TS 102 772 (DVB-SH Multi-Protocol Encapsulation) */
245 #define TABLE_ID_MPE_IFEC 0x7A
246 /* EN 300 468 (DVB) v 1.12.1 */
247 #define TABLE_ID_DISCONTINUITY_INFORMATION 0x7E
248 #define TABLE_ID_SELECTION_INFORMATION 0x7F
249 /* ETR 289 (DVB Support for use of scrambling and CA) */
250 #define TABLE_ID_CA_MESSAGE_ECM_0 0x80
251 #define TABLE_ID_CA_MESSAGE_ECM_1 0x81
252 #define TABLE_ID_CA_MESSAGE_SYSTEM_PRIVATE_1 0x82 /* First */
253 #define TABLE_ID_CA_MESSAGE_SYSTEM_PRIVATE_N 0x8F /* Last */
255 /* EN 301 790 (DVB interaction channel for satellite distribution channels) */
256 #define TABLE_ID_SCT 0xA0
257 #define TABLE_ID_FCT 0xA1
258 #define TABLE_ID_TCT 0xA2
259 #define TABLE_ID_SPT 0xA3
260 #define TABLE_ID_CMT 0xA4
261 #define TABLE_ID_TBTP 0xA5
262 #define TABLE_ID_PCR_PACKET_PAYLOAD 0xA6
263 #define TABLE_ID_TRANSMISSION_MODE_SUPPORT_PAYLOAD 0xAA
264 #define TABLE_ID_TIM 0xB0
265 #define TABLE_ID_LL_FEC_PARITY_DATA_TABLE 0xB1
269 #define TABLE_ID_UNSET 0xFF
272 #define CLOCK_BASE 9LL
273 #define CLOCK_FREQ (CLOCK_BASE * 10000)
275 #define PCRTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
276 GST_MSECOND/10, 300 * CLOCK_BASE))
277 #define MPEGTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
278 GST_MSECOND/10, CLOCK_BASE))
279 #define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \
280 CLOCK_BASE, GST_MSECOND/10))
281 #define GSTTIME_TO_PCRTIME(time) (gst_util_uint64_scale ((time), \
282 300 * CLOCK_BASE, GST_MSECOND/10))
284 #define MPEG_MUX_RATE_MULT 50
286 /* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
287 #define READ_TS(data, target, lost_sync_label) \
288 if ((*data & 0x01) != 0x01) goto lost_sync_label; \
289 target = ((guint64) (*data++ & 0x0E)) << 29; \
290 target |= ((guint64) (*data++ )) << 22; \
291 if ((*data & 0x01) != 0x01) goto lost_sync_label; \
292 target |= ((guint64) (*data++ & 0xFE)) << 14; \
293 target |= ((guint64) (*data++ )) << 7; \
294 if ((*data & 0x01) != 0x01) goto lost_sync_label; \
295 target |= ((guint64) (*data++ & 0xFE)) >> 1;
297 /* some extra GstFlowReturn values used internally */
298 #define GST_FLOW_NEED_MORE_DATA GST_FLOW_CUSTOM_SUCCESS
299 #define GST_FLOW_LOST_SYNC GST_FLOW_CUSTOM_SUCCESS_1
301 #endif /* __GST_MPEG_DEFS_H__ */