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_DEFS_H__
23 #define __GST_MPEG_DEFS_H__
24 
25 /*
26  * 1011 1100                program_stream_map
27  * 1011 1101                private_stream_1
28  * 1011 1110                padding_stream
29  * 1011 1111                private_stream_2
30  * 110x xxxx                ISO/IEC 13818-3 or ISO/IEC 11172-3 audio stream number x xxxx
31  * 1110 xxxx                ITU-T Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 11172-2 video stream number xxxx
32  * 1111 0000                ECM_stream
33  * 1111 0001                EMM_stream
34  * 1111 0010                ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A or ISO/IEC 13818-6_DSMCC_stream
35  * 1111 0011                ISO/IEC_13522_stream
36  * 1111 0100                ITU-T Rec. H.222.1 type A
37  * 1111 0101                ITU-T Rec. H.222.1 type B
38  * 1111 0110                ITU-T Rec. H.222.1 type C
39  * 1111 0111                ITU-T Rec. H.222.1 type D
40  * 1111 1000                ITU-T Rec. H.222.1 type E
41  * 1111 1001                ancillary_stream
42  * 1111 1010 E 1111 1110    reserved data stream
43  * 1111 1111                program_stream_directory
44  */
45 
46 #define ID_PS_END_CODE                          0x000001B9
47 #define ID_PS_PACK_START_CODE                   0x000001BA
48 #define ID_PS_SYSTEM_HEADER_START_CODE          0x000001BB
49 #define ID_PS_PROGRAM_STREAM_MAP                0x000001BC
50 #define ID_PRIVATE_STREAM_1                     0x000001BD
51 #define ID_PADDING_STREAM                       0x000001BE
52 #define ID_PRIVATE_STREAM_2                     0x000001BF
53 #define ID_ISO_IEC_MPEG12_AUDIO_STREAM_0        0x000001C0
54 #define ID_ISO_IEC_MPEG12_AUDIO_STREAM_32       0x000001DF
55 #define ID_ISO_IEC_MPEG12_VIDEO_STREAM_0        0x000001E0
56 #define ID_ISO_IEC_MPEG12_VIDEO_STREAM_16       0x000001EF
57 #define ID_ECM_STREAM                           0x000001F0
58 #define ID_EMM_STREAM                           0x000001F1
59 #define ID_DSMCC_STREAM                         0x000001F2
60 #define ID_ISO_IEC_13522_STREAM                 0x000001F3
61 #define ID_ITU_TREC_H222_TYPE_A_STREAM          0x000001F4
62 #define ID_ITU_TREC_H222_TYPE_B_STREAM          0x000001F5
63 #define ID_ITU_TREC_H222_TYPE_C_STREAM          0x000001F6
64 #define ID_ITU_TREC_H222_TYPE_D_STREAM          0x000001F7
65 #define ID_ITU_TREC_H222_TYPE_E_STREAM          0x000001F8
66 #define ID_ANCILLARY_STREAM                     0x000001F9
67 #define ID_RESERVED_STREAM_1                    0x000001FA
68 #define ID_RESERVED_STREAM_2                    0x000001FB
69 #define ID_EXTENDED_METADATA                    0x000001FC
70 #define ID_EXTENDED_STREAM_ID                   0x000001FD
71 #define ID_RESERVED_STREAM_3                    0x000001FE
72 #define ID_PROGRAM_STREAM_DIRECTORY             0x000001FF
73 
74 #define PACKET_VIDEO_START_CODE                 0x000001E0
75 #define PACKET_AUDIO_START_CODE                 0x000001C0
76 #define PICTURE_START_CODE                      0x00000100
77 #define USER_DATA_START_CODE                    0x000001B2
78 #define SEQUENCE_HEADER_CODE                    0x000001B3
79 #define SEQUENCE_ERROR_CODE                     0x000001B4
80 #define EXTENSION_START_CODE                    0x000001B5
81 #define SEQUENCE_END_CODE                       0x000001B7
82 #define GROUP_START_CODE                        0x000001B8
83 
84 #define AC3_SYNC_WORD                           0x0b770000
85 
86 #define MPEG_TS_SYNC_BYTE                       0x00000047
87 
88 #define PID_PROGRAM_ASSOCIATION_TABLE          0x0000
89 #define PID_CONDITIONAL_ACCESS_TABLE           0x0001
90 #define PID_RESERVED_FIRST                     0x0002
91 #define PID_RESERVED_LAST                      0x0010
92 #define PID_NULL_PACKET                        0x1FFF
93 
94 #define PID_TYPE_UNKNOWN                        0
95 #define PID_TYPE_RESERVED                       1
96 #define PID_TYPE_PROGRAM_ASSOCIATION            2
97 #define PID_TYPE_CONDITIONAL_ACCESS             3
98 #define PID_TYPE_PROGRAM_MAP                    4
99 #define PID_TYPE_ELEMENTARY                     5
100 #define PID_TYPE_NULL_PACKET                    6
101 #define PID_TYPE_PRIVATE_SECTION                7
102 
103 /* Stream type assignments
104  *
105  *   0x00    ITU-T | ISO/IEC Reserved
106  *   0x01    ISO/IEC 11172 Video
107  *   0x02    ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or
108  *           ISO/IEC 11172-2 constrained parameter video
109  *           stream
110  *   0x03    ISO/IEC 11172 Audio
111  *   0x04    ISO/IEC 13818-3 Audio
112  *   0x05    ITU-T Rec. H.222.0 | ISO/IEC 13818-1
113  *           private_sections
114  *   0x06    ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES
115  *           packets containing private data
116  *   0x07    ISO/IEC 13522 MHEG
117  *   0x08    ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A
118  *           DSM CC
119  *   0x09    ITU-T Rec. H.222.1
120  *   0x0A    ISO/IEC 13818-6 type A
121  *   0x0B    ISO/IEC 13818-6 type B
122  *   0x0C    ISO/IEC 13818-6 type C
123  *   0x0D    ISO/IEC 13818-6 type D
124  *   0x0E    ISO/IEC 13818-1 auxiliary
125  * 0x0F-0x7F ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
126  * 0x80-0xFF User Private
127  */
128 #define ST_RESERVED                     0x00
129 #define ST_VIDEO_MPEG1                  0x01
130 #define ST_VIDEO_MPEG2                  0x02
131 #define ST_AUDIO_MPEG1                  0x03
132 #define ST_AUDIO_MPEG2                  0x04
133 #define ST_PRIVATE_SECTIONS             0x05
134 #define ST_PRIVATE_DATA                 0x06
135 #define ST_MHEG                         0x07
136 #define ST_DSMCC                        0x08
137 #define ST_H222_1                       0x09
138 
139 /* later extensions */
140 #define ST_AUDIO_AAC_ADTS               0x0f
141 /* LATM/LOAS AAC syntax */
142 #define ST_AUDIO_AAC_LOAS               0x11
143 #define ST_VIDEO_MPEG4                  0x10
144 #define ST_VIDEO_H264                   0x1b
145 
146 /* Un-official Dirac extension */
147 #define ST_VIDEO_DIRAC                  0xd1
148 
149 /* private stream types */
150 #define ST_PS_AUDIO_AC3                 0x81
151 #define ST_PS_AUDIO_DTS                 0x8a
152 #define ST_PS_AUDIO_LPCM                0x8b
153 #define ST_PS_DVD_SUBPICTURE            0xff
154 /* Blu-ray related */
155 #define ST_BD_AUDIO_LPCM                0x80
156 #define ST_BD_AUDIO_AC3                 0x81
157 #define ST_BD_AUDIO_DTS                 0x82
158 #define ST_BD_AUDIO_AC3_TRUE_HD         0x83
159 #define ST_BD_AUDIO_AC3_PLUS            0x84
160 #define ST_BD_AUDIO_DTS_HD              0x85
161 #define ST_BD_AUDIO_DTS_HD_MASTER_AUDIO 0x86
162 #define ST_BD_AUDIO_EAC3                0x87
163 #define ST_BD_PGS_SUBPICTURE            0x90
164 #define ST_BD_IGS                       0x91
165 #define ST_BD_SUBTITLE                  0x92
166 #define ST_BD_SECONDARY_AC3_PLUS        0xa1
167 #define ST_BD_SECONDARY_DTS_HD          0xa2
168 
169 /* defined for VC1 extension in RP227 */
170 #define ST_PRIVATE_EA                   0xea
171 
172 /* HDV AUX stream mapping
173  * 0xA0      ISO/IEC 61834-11
174  * 0xA1      ISO/IEC 61834-11
175  */
176 #define ST_HDV_AUX_A                    0xa0
177 #define ST_HDV_AUX_V                    0xa1
178 
179 /* Un-official time-code stream */
180 #define ST_PS_TIMECODE                  0xd2
181 
182 /* Internal stream types >= 0x100 */
183 #define ST_GST_AUDIO_RAWA52             0x181
184   /* Used when we don't yet know which stream type it will be in a PS stream */
185 #define ST_GST_VIDEO_MPEG1_OR_2         0x102
186 
187 #define CLOCK_BASE 9LL
188 #define CLOCK_FREQ (CLOCK_BASE * 10000)
189 
190 #define MPEGTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
191             GST_MSECOND/10, CLOCK_BASE))
192 #define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \
193             CLOCK_BASE, GST_MSECOND/10))
194 
195 #define MPEG_MUX_RATE_MULT      50
196 
197 /* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
198 #define READ_TS(data, target, lost_sync_label)          \
199     if ((*data & 0x01) != 0x01) goto lost_sync_label;   \
200     target  = ((guint64) (*data++ & 0x0E)) << 29;       \
201     target |= ((guint64) (*data++       )) << 22;       \
202     if ((*data & 0x01) != 0x01) goto lost_sync_label;   \
203     target |= ((guint64) (*data++ & 0xFE)) << 14;       \
204     target |= ((guint64) (*data++       )) << 7;        \
205     if ((*data & 0x01) != 0x01) goto lost_sync_label;   \
206     target |= ((guint64) (*data++ & 0xFE)) >> 1;
207 
208 /* some extra GstFlowReturn values used internally */
209 #define GST_FLOW_NEED_MORE_DATA   GST_FLOW_CUSTOM_SUCCESS
210 #define GST_FLOW_LOST_SYNC        GST_FLOW_CUSTOM_SUCCESS_1
211 
212 #endif /* __GST_MPEG_DEFS_H__ */
213