• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This library is licensed under 2 different licenses and you
3  * can choose to use it under the terms of either one of them. The
4  * two licenses are the MPL 1.1 and the LGPL.
5  *
6  * MPL:
7  *
8  * The contents of this file are subject to the Mozilla Public License
9  * Version 1.1 (the "License"); you may not use this file except in
10  * compliance with the License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/.
12  *
13  * Software distributed under the License is distributed on an "AS IS"
14  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations
16  * under the License.
17  *
18  * LGPL:
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Library General Public
22  * License as published by the Free Software Foundation; either
23  * version 2 of the License, or (at your option) any later version.
24  *
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28  * Library General Public License for more details.
29  *
30  * You should have received a copy of the GNU Library General Public
31  * License along with this library; if not, write to the
32  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
33  * Boston, MA 02110-1301, USA.
34  *
35  * The Original Code is Fluendo MPEG Demuxer plugin.
36  *
37  * The Initial Developer of the Original Code is Fluendo, S.L.
38  * Portions created by Fluendo, S.L. are Copyright (C) 2005
39  * Fluendo, S.L. All Rights Reserved.
40  *
41  * Contributor(s): Wim Taymans <wim@fluendo.com>
42  */
43 
44 #ifndef __GST_MPEG_DEFS_H__
45 #define __GST_MPEG_DEFS_H__
46 
47 /*
48  * 1011 1100                program_stream_map
49  * 1011 1101                private_stream_1
50  * 1011 1110                padding_stream
51  * 1011 1111                private_stream_2
52  * 110x xxxx                ISO/IEC 13818-3 or ISO/IEC 11172-3 audio stream number x xxxx
53  * 1110 xxxx                ITU-T Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 11172-2 video stream number xxxx
54  * 1111 0000                ECM_stream
55  * 1111 0001                EMM_stream
56  * 1111 0010                ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A or ISO/IEC 13818-6_DSMCC_stream
57  * 1111 0011                ISO/IEC_13522_stream
58  * 1111 0100                ITU-T Rec. H.222.1 type A
59  * 1111 0101                ITU-T Rec. H.222.1 type B
60  * 1111 0110                ITU-T Rec. H.222.1 type C
61  * 1111 0111                ITU-T Rec. H.222.1 type D
62  * 1111 1000                ITU-T Rec. H.222.1 type E
63  * 1111 1001                ancillary_stream
64  * 1111 1010 E 1111 1110    reserved data stream
65  * 1111 1111                program_stream_directory
66  */
67 
68 #define ID_PS_END_CODE                          0x000001B9
69 #define ID_PS_PACK_START_CODE                   0x000001BA
70 #define ID_PS_SYSTEM_HEADER_START_CODE          0x000001BB
71 #define ID_PS_PROGRAM_STREAM_MAP                0x000001BC
72 #define ID_PRIVATE_STREAM_1                     0x000001BD
73 #define ID_PADDING_STREAM                       0x000001BE
74 #define ID_PRIVATE_STREAM_2                     0x000001BF
75 #define ID_ISO_IEC_MPEG12_AUDIO_STREAM_0        0x000001C0
76 #define ID_ISO_IEC_MPEG12_AUDIO_STREAM_32       0x000001DF
77 #define ID_ISO_IEC_MPEG12_VIDEO_STREAM_0        0x000001E0
78 #define ID_ISO_IEC_MPEG12_VIDEO_STREAM_16       0x000001EF
79 #define ID_ECM_STREAM                           0x000001F0
80 #define ID_EMM_STREAM                           0x000001F1
81 #define ID_DSMCC_STREAM                         0x000001F2
82 #define ID_ISO_IEC_13522_STREAM                 0x000001F3
83 #define ID_ITU_TREC_H222_TYPE_A_STREAM          0x000001F4
84 #define ID_ITU_TREC_H222_TYPE_B_STREAM          0x000001F5
85 #define ID_ITU_TREC_H222_TYPE_C_STREAM          0x000001F6
86 #define ID_ITU_TREC_H222_TYPE_D_STREAM          0x000001F7
87 #define ID_ITU_TREC_H222_TYPE_E_STREAM          0x000001F8
88 #define ID_ANCILLARY_STREAM                     0x000001F9
89 #define ID_RESERVED_STREAM_1                    0x000001FA
90 #define ID_RESERVED_STREAM_2                    0x000001FB
91 #define ID_EXTENDED_METADATA                    0x000001FC
92 #define ID_EXTENDED_STREAM_ID                   0x000001FD
93 #define ID_RESERVED_STREAM_3                    0x000001FE
94 #define ID_PROGRAM_STREAM_DIRECTORY             0x000001FF
95 
96 #define PACKET_VIDEO_START_CODE                 0x000001E0
97 #define PACKET_AUDIO_START_CODE                 0x000001C0
98 #define PICTURE_START_CODE                      0x00000100
99 #define USER_DATA_START_CODE                    0x000001B2
100 #define SEQUENCE_HEADER_CODE                    0x000001B3
101 #define SEQUENCE_ERROR_CODE                     0x000001B4
102 #define EXTENSION_START_CODE                    0x000001B5
103 #define SEQUENCE_END_CODE                       0x000001B7
104 #define GROUP_START_CODE                        0x000001B8
105 
106 #define AC3_SYNC_WORD                           0x0b770000
107 
108 #define MPEG_TS_SYNC_BYTE                       0x00000047
109 
110 #define PID_PROGRAM_ASSOCIATION_TABLE          0x0000
111 #define PID_CONDITIONAL_ACCESS_TABLE           0x0001
112 #define PID_RESERVED_FIRST                     0x0002
113 #define PID_RESERVED_LAST                      0x0010
114 #define PID_NULL_PACKET                        0x1FFF
115 
116 #define PID_TYPE_UNKNOWN                        0
117 #define PID_TYPE_RESERVED                       1
118 #define PID_TYPE_PROGRAM_ASSOCIATION            2
119 #define PID_TYPE_CONDITIONAL_ACCESS             3
120 #define PID_TYPE_PROGRAM_MAP                    4
121 #define PID_TYPE_ELEMENTARY                     5
122 #define PID_TYPE_NULL_PACKET                    6
123 #define PID_TYPE_PRIVATE_SECTION                7
124 
125 /* Stream type assignments
126  *
127  *   0x00    ITU-T | ISO/IEC Reserved
128  *   0x01    ISO/IEC 11172 Video
129  *   0x02    ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or
130  *           ISO/IEC 11172-2 constrained parameter video
131  *           stream
132  *   0x03    ISO/IEC 11172 Audio
133  *   0x04    ISO/IEC 13818-3 Audio
134  *   0x05    ITU-T Rec. H.222.0 | ISO/IEC 13818-1
135  *           private_sections
136  *   0x06    ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES
137  *           packets containing private data
138  *   0x07    ISO/IEC 13522 MHEG
139  *   0x08    ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A
140  *           DSM CC
141  *   0x09    ITU-T Rec. H.222.1
142  *   0x0A    ISO/IEC 13818-6 type A
143  *   0x0B    ISO/IEC 13818-6 type B
144  *   0x0C    ISO/IEC 13818-6 type C
145  *   0x0D    ISO/IEC 13818-6 type D
146  *   0x0E    ISO/IEC 13818-1 auxiliary
147  * 0x0F-0x7F ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
148  * 0x80-0xFF User Private
149  */
150 #define ST_RESERVED                     0x00
151 #define ST_VIDEO_MPEG1                  0x01
152 #define ST_VIDEO_MPEG2                  0x02
153 #define ST_AUDIO_MPEG1                  0x03
154 #define ST_AUDIO_MPEG2                  0x04
155 #define ST_PRIVATE_SECTIONS             0x05
156 #define ST_PRIVATE_DATA                 0x06
157 #define ST_MHEG                         0x07
158 #define ST_DSMCC                        0x08
159 #define ST_H222_1                       0x09
160 
161 /* later extensions */
162 #define ST_AUDIO_AAC_ADTS               0x0f
163 /* LATM/LOAS AAC syntax */
164 #define ST_AUDIO_AAC_LOAS               0x11
165 #define ST_VIDEO_MPEG4                  0x10
166 #define ST_VIDEO_H264                   0x1b
167 #define ST_VIDEO_H265                   0x24
168 
169 /* Un-official Dirac extension */
170 #define ST_VIDEO_DIRAC                  0xd1
171 
172 /* private stream types */
173 #define ST_PS_AUDIO_AC3                 0x81
174 #define ST_PS_AUDIO_DTS                 0x8a
175 #define ST_PS_AUDIO_LPCM                0x8b
176 #define ST_PS_DVD_SUBPICTURE            0xff
177 /* Blu-ray related */
178 #define ST_BD_AUDIO_LPCM                0x80
179 #define ST_BD_AUDIO_AC3                 0x81
180 #define ST_BD_AUDIO_DTS                 0x82
181 #define ST_BD_AUDIO_AC3_TRUE_HD         0x83
182 #define ST_BD_AUDIO_AC3_PLUS            0x84
183 #define ST_BD_AUDIO_DTS_HD              0x85
184 #define ST_BD_AUDIO_DTS_HD_MASTER_AUDIO 0x86
185 #define ST_BD_AUDIO_EAC3                0x87
186 #define ST_BD_PGS_SUBPICTURE            0x90
187 #define ST_BD_IGS                       0x91
188 #define ST_BD_SUBTITLE                  0x92
189 #define ST_BD_SECONDARY_AC3_PLUS        0xa1
190 #define ST_BD_SECONDARY_DTS_HD          0xa2
191 
192 /* defined for VC1 extension in RP227 */
193 #define ST_PRIVATE_EA                   0xea
194 
195 /* HDV AUX stream mapping
196  * 0xA0      ISO/IEC 61834-11
197  * 0xA1      ISO/IEC 61834-11
198  */
199 #define ST_HDV_AUX_A                    0xa0
200 #define ST_HDV_AUX_V                    0xa1
201 
202 /* Un-official time-code stream */
203 #define ST_PS_TIMECODE                  0xd2
204 
205 /* Internal stream types >= 0x100 */
206 #define ST_GST_AUDIO_RAWA52             0x181
207   /* Used when we don't yet know which stream type it will be in a PS stream */
208 #define ST_GST_VIDEO_MPEG1_OR_2         0x102
209 
210 #define CLOCK_BASE 9LL
211 #define CLOCK_FREQ (CLOCK_BASE * 10000)
212 
213 #define MPEGTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
214             GST_MSECOND/10, CLOCK_BASE))
215 #define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \
216             CLOCK_BASE, GST_MSECOND/10))
217 
218 #define MPEG_MUX_RATE_MULT      50
219 
220 /* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
221 #define READ_TS(data, target, lost_sync_label)          \
222     if ((*data & 0x01) != 0x01) goto lost_sync_label;   \
223     target  = ((guint64) (*data++ & 0x0E)) << 29;       \
224     target |= ((guint64) (*data++       )) << 22;       \
225     if ((*data & 0x01) != 0x01) goto lost_sync_label;   \
226     target |= ((guint64) (*data++ & 0xFE)) << 14;       \
227     target |= ((guint64) (*data++       )) << 7;        \
228     if ((*data & 0x01) != 0x01) goto lost_sync_label;   \
229     target |= ((guint64) (*data++ & 0xFE)) >> 1;
230 
231 /* some extra GstFlowReturn values used internally */
232 #define GST_FLOW_NEED_MORE_DATA   GST_FLOW_CUSTOM_SUCCESS
233 #define GST_FLOW_LOST_SYNC        GST_FLOW_CUSTOM_SUCCESS_1
234 
235 #endif /* __GST_MPEG_DEFS_H__ */
236