File: mpeg2structs.h

package info (click to toggle)
ivtv 0.8.2-2
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 2,128 kB
  • ctags: 5,173
  • sloc: ansic: 28,746; perl: 2,593; cpp: 1,946; sh: 1,521; makefile: 263
file content (249 lines) | stat: -rw-r--r-- 7,741 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
#
# MPEG2 data structures for MPEG2Parser class
#
# $Id: mpeg2structs.h,v 1.2 2003/11/01 08:35:37 knup Exp $
#
# Copyright (C) 2001-2003 Kees Cook
# kees@outflux.net, http://outflux.net/
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html
#
*/

#ifndef _MPEG2STRUCTS_H_
#define _MPEG2STRUCTS_H_

#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif

/*
   This problem with these damn compilers is that I can't
   specify an arbitrary bit layout structure.  It always
   grows to a different size.  If someone know how to portably
   control that problem let me know, and I can stop using bit masks
   to get at my data.  :)
*/

#define PICTURE_CODING_MASK		0x38
#define PICTURE_CODING_SHIFT		0x03
#define PICTURE_CODING_INTRA		0x01
#define PICTURE_CODING_PREDICTIVE	0x02
#define PICTURE_CODING_BIDIRECTIONAL	0x03

typedef struct {
	uint8_t start_code[4];
	uint8_t bits[2];
	/*  only stuff I want to get to is picture_coding_type
	   uint16_t temporal_reference:10;
	   uint8_t  picture_coding_type:3;
	 */
} picture_header;

#define GOP_FLAG_MASK	0x60
#define GOP_FLAG_CLOSED	0x40
#define GOP_FLAG_BROKEN	0x20

typedef struct {
	uint8_t start_code[4];
	uint8_t bits[4];
	/*
	   uint32_t time_code:25;
	   uint8_t  closed_gop:1;
	   uint8_t  broken_link:1;
	   uint8_t  unknown:5;
	 */
} group_of_pictures_header;

#define ES_TYPE_WEIRD   0
#define ES_TYPE_VIDEO   1
#define ES_TYPE_AUDIO   2

typedef struct {
	uint8_t start_code[3];
	uint8_t stream_id;
	uint8_t PES_packet_length[2];
} PES_packet_header_t;

typedef struct {
	uint8_t bits[2];
	/*
	   uint8_t         marker0:2; // 10
	   uint8_t         PES_scrambling_control:2;
	   uint8_t         PES_priority:1;
	   uint8_t         data_alignment_indicator:1;
	   uint8_t         copyright:1;
	   uint8_t         original_or_copy:1;

	   uint8_t         PTS_DTS_flags:2;
	   uint8_t         ESCR_flag:1;
	   uint8_t         ES_rate_flag:1;
	   uint8_t         DSM_trick_mode_flag:1;
	   uint8_t         additional_copy_info_flag:1;
	   uint8_t         PES_CRC_flag:1;
	   uint8_t         PES_extension_flag:1;
	 */
	uint8_t PES_header_data_length;
} PES_packet_internals_t;

typedef struct {
	uint8_t marker_bit:1;
	uint8_t data:7;
} PES_packet_additional_copy_info_t;

#define GET_BITS(byte,mask,shiftdown)	(((byte)&(mask))>>(shiftdown))

#define PPE_PES_private_data_flag(x)	GET_BITS(x,0x80,7)
#define PPE_pack_header_field_flag(x)	GET_BITS(x,0x40,6)
#define PPE_program_packet_sequence_counter_flag(x)	GET_BITS(x,0x20,5)
#define PPE_P_STD_buffer_flag(x)		GET_BITS(x,0x10,5)
#define PPE_PES_extension_flag_2(x)		GET_BITS(x,0x01,0)
typedef struct {
	uint8_t bits[1];
	/*
	   uint8_t         PES_private_data_flag:1;
	   uint8_t         pack_header_field_flag:1;
	   uint8_t         program_packet_sequence_counter_flag:1;
	   uint8_t         P_STD_buffer_flag:1;
	   uint8_t         reserved:3;
	   uint8_t         PES_extension_flag_2:1;
	 */
} PES_packet_extension_t;

typedef struct {
	uint8_t marker0:1;
	uint8_t program_packet_sequence_counter:7;

	uint8_t marker1:1;
	uint8_t MPEG1_MPEG2_identifier:1;
	uint8_t original_stuff_length:6;
} PES_packet_extension_program_packet_sequence_counter_t;

#define PES_TYPE_picture_start		0x00
// slice start: 0x01 - 0xAF
// reserved: 0xB0 - 0xB1
#define PES_TYPE_user_data_start	0xB2
#define PES_TYPE_sequence_header	0xB3
#define PES_TYPE_sequence_error		0xB4
#define PES_TYPE_extension_start	0xB5
// reserved: 0xB6
#define PES_TYPE_sequence_end		0xB7
#define PES_TYPE_group_start		0xB8
#define PES_TYPE_program_end		0xB9
#define PES_TYPE_pack_start		0xBA
#define PES_TYPE_system_header		0xBB
#define PES_TYPE_program_stream_map     0xBC	/* PES simple */
#define PES_TYPE_private_stream_1       0xBD	/* PES complex */
#define PES_TYPE_padding_stream         0xBE	/* PES simple */
#define PES_TYPE_private_stream_2       0xBF	/* PES simple */
#define PES_TYPE_ECM_stream             0xF0	/* PES simple */
#define PES_TYPE_EMM_stream             0xF1	/* PES simple */
#define PES_TYPE_DSMCC_stream           0xF2	/* PES simple */
#define PES_TYPE_ISO_13522              0xF3	/* PES complex */
#define PES_TYPE_H2221A                 0xF4	/* PES complex */
#define PES_TYPE_H2221B                 0xF5	/* PES complex */
#define PES_TYPE_H2221C                 0xF6	/* PES complex */
#define PES_TYPE_H2221D                 0xF7	/* PES complex */
#define PES_TYPE_H2221E                 0xF8	/* PES simple */
#define PES_TYPE_ancillary_stream       0xF9	/* PES complex */
// reserved: 0xFA - 0xFE                        /* PES complex */
#define PES_TYPE_program_stream_directory       0xFF	/* PES simple */

#define PES_TYPE_audio                  0xC0	/* PES complex */
#define PES_TYPE_MASK_audio             0xE0

#define PES_TYPE_video                  0xE0	/* PES complex */
#define PES_TYPE_MASK_video             0xF0

//                            xxxxx     xxxxx
// subtitles: 0x20..0x3F   00100000..00111111
#define DVD_AUDIO_TYPE_sub              0x20
#define DVD_AUDIO_TYPE_MASK_sub         0xE0
//                            xxxxx     xxxxx
// AC3:       0x80..0x9F   10000000..10011111
#define DVD_AUDIO_TYPE_ac3              0x80
#define DVD_AUDIO_TYPE_MASK_ac3         0xE0
//                            xxxxx     xxxxx 
// PCM:       0xA0..0xBF   10100000..10111111
#define DVD_AUDIO_TYPE_pcm              0xA0
#define DVD_AUDIO_TYPE_MASK_pcm         0xE0

typedef struct {
	uint8_t start_code[4];
	uint16_t header_length;

	uint8_t bits[6];
	/*
	   uint32_t        marker0:1; // 1
	   uint32_t        rate_bound:22;
	   uint32_t        marker1:1; // 1
	   uint32_t        audio_bound:6;
	   uint32_t        fixed_flag:1;
	   uint32_t        CSPS_flag:1;

	   uint8_t         system_audio_lock_flag:1;
	   uint8_t         system_video_lock_flag:1;
	   uint8_t         marker2:1; // 1
	   uint8_t         video_bound:5;

	   uint8_t         packet_rate_restriction_flag:1;
	   uint8_t         reserved:7;
	 */

} system_header_t;

typedef struct {
	uint8_t stream_id;
	// 1011 1000: P_STD map to all audio streams
	// 1011 1001: P_STD map to all video streams
	// otherwise, must be >= 1011 1100
	//
	uint8_t bits[2];
	/*
	   uint16_t        marker0:2; // 11
	   uint16_t        P_STD_buffer_bound_scale:1;
	   uint16_t        P_STD_buffer_size_bound:13;
	 */
} stream_id_t;

typedef struct {
	uint8_t start_code[4];
	/*
	   uint32_t        marker0:2; // 01
	   uint32_t        system_clock_reference_base_hi:3;
	   uint32_t        marker1:1; // 1
	   uint32_t        system_clock_reference_base_mid:15;
	   uint32_t        marker2:1; // 1
	   uint32_t        system_clock_reference_base_low:15;
	   uint16_t        marker3:1; // 1
	   uint16_t        system_clock_reference_extension:9;
	   uint16_t        marker4:1; // 1
	   uint32_t        program_mux_rate:22;
	   uint32_t        marker5:1; // 1
	   uint32_t        marker6:1; // 1
	   uint8_t reserved:5;
	   uint8_t pack_stuffing_length:3;
	 */
	uint8_t bits[10];
} pack_header_t;

#endif				//  _MPEG2STRUCTS_H_

/* vi:set ai ts=4 sw=4 expandtab: */