]> git.sesse.net Git - vlc/blob - modules/codec/xvmc/mpeg2.h
37470a93d31dd6145317572b704f7f07cbf45875
[vlc] / modules / codec / xvmc / mpeg2.h
1 /* $Id$
2  * mpeg2.h
3  * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5  *
6  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
7  * See http://libmpeg2.sourceforge.net/ for updates.
8  *
9  * mpeg2dec is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * mpeg2dec is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifndef MPEG2_H
25 #define MPEG2_H
26
27 #define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
28 #define MPEG2_RELEASE MPEG2_VERSION (0, 4, 0)   /* 0.4.0 */
29
30 #define SEQ_FLAG_MPEG2 1
31 #define SEQ_FLAG_CONSTRAINED_PARAMETERS 2
32 #define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4
33 #define SEQ_FLAG_LOW_DELAY 8
34 #define SEQ_FLAG_COLOUR_DESCRIPTION 16
35
36 #define SEQ_MASK_VIDEO_FORMAT 0xe0
37 #define SEQ_VIDEO_FORMAT_COMPONENT 0
38 #define SEQ_VIDEO_FORMAT_PAL 0x20
39 #define SEQ_VIDEO_FORMAT_NTSC 0x40
40 #define SEQ_VIDEO_FORMAT_SECAM 0x60
41 #define SEQ_VIDEO_FORMAT_MAC 0x80
42 #define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0
43
44 typedef struct mpeg2_sequence_s
45 {
46     unsigned int width, height;
47     unsigned int chroma_width, chroma_height;
48     unsigned int byte_rate;
49     unsigned int vbv_buffer_size;
50     uint32_t flags;
51
52     unsigned int picture_width, picture_height;
53     unsigned int display_width, display_height;
54     unsigned int pixel_width, pixel_height;
55     unsigned int frame_period;
56
57     uint8_t profile_level_id;
58     uint8_t colour_primaries;
59     uint8_t transfer_characteristics;
60     uint8_t matrix_coefficients;
61     int aspect_ratio_information;
62 } mpeg2_sequence_t;
63
64 #define GOP_FLAG_DROP_FRAME 1
65 #define GOP_FLAG_BROKEN_LINK 2
66 #define GOP_FLAG_CLOSED_GOP 4
67
68 typedef struct mpeg2_gop_s
69 {
70     uint8_t hours;
71     uint8_t minutes;
72     uint8_t seconds;
73     uint8_t pictures;
74     uint32_t flags;
75 } mpeg2_gop_t;
76
77 #define PIC_MASK_CODING_TYPE 7
78 #define PIC_FLAG_CODING_TYPE_I 1
79 #define PIC_FLAG_CODING_TYPE_P 2
80 #define PIC_FLAG_CODING_TYPE_B 3
81 #define PIC_FLAG_CODING_TYPE_D 4
82
83 #define PIC_FLAG_TOP_FIELD_FIRST 8
84 #define PIC_FLAG_PROGRESSIVE_FRAME 16
85 #define PIC_FLAG_COMPOSITE_DISPLAY 32
86 #define PIC_FLAG_SKIP 64
87 #define PIC_FLAG_TAGS 128
88 #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
89
90 typedef struct mpeg2_picture_s
91 {
92     unsigned int temporal_reference;
93     unsigned int nb_fields;
94     uint32_t tag, tag2;
95     uint32_t flags;
96     struct {
97         int x, y;
98     } display_offset[3];
99 } mpeg2_picture_t;
100
101 typedef struct mpeg2_fbuf_s
102 {
103     uint8_t * buf[3];
104     void * id;
105 } mpeg2_fbuf_t;
106
107 typedef struct mpeg2_info_s
108 {
109     const mpeg2_sequence_t * sequence;
110     const mpeg2_gop_t * gop;
111     const mpeg2_picture_t * current_picture;
112     const mpeg2_picture_t * current_picture_2nd;
113     const mpeg2_fbuf_t * current_fbuf;
114     const mpeg2_picture_t * display_picture;
115     const mpeg2_picture_t * display_picture_2nd;
116     const mpeg2_fbuf_t * display_fbuf;
117     const mpeg2_fbuf_t * discard_fbuf;
118     const uint8_t * user_data;
119     unsigned int user_data_len;
120 } mpeg2_info_t;
121
122 typedef struct mpeg2dec_s mpeg2dec_t;
123 typedef struct mpeg2_decoder_s mpeg2_decoder_t;
124
125 typedef enum
126 {
127     STATE_BUFFER = 0,
128     STATE_SEQUENCE = 1,
129     STATE_SEQUENCE_REPEATED = 2,
130     STATE_GOP = 3,
131     STATE_PICTURE = 4,
132     STATE_SLICE_1ST = 5,
133     STATE_PICTURE_2ND = 6,
134     STATE_SLICE = 7,
135     STATE_END = 8,
136     STATE_INVALID = 9,
137     STATE_INVALID_END = 10
138 } mpeg2_state_t;
139
140 typedef struct mpeg2_convert_init_s
141 {
142     unsigned int id_size;
143     unsigned int buf_size[3];
144     void (* start) (void * id, const mpeg2_fbuf_t * fbuf,
145                     const mpeg2_picture_t * picture, const mpeg2_gop_t * gop);
146     void (* copy) (void * id, uint8_t * const * src, unsigned int v_offset);
147 } mpeg2_convert_init_t;
148
149 typedef enum
150 {
151     MPEG2_CONVERT_SET = 0,
152     MPEG2_CONVERT_STRIDE = 1,
153     MPEG2_CONVERT_START = 2
154 } mpeg2_convert_stage_t;
155
156 typedef int mpeg2_convert_t (int stage, void * id,
157                              const mpeg2_sequence_t * sequence, int stride,
158                              uint32_t accel, void * arg,
159                              mpeg2_convert_init_t * result);
160 int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg);
161 int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride);
162 void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id);
163 void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf);
164
165 #define MPEG2_ACCEL_X86_MMX 1
166 #define MPEG2_ACCEL_X86_3DNOW 2
167 #define MPEG2_ACCEL_X86_MMXEXT 4
168 #define MPEG2_ACCEL_PPC_ALTIVEC 1
169 #define MPEG2_ACCEL_ALPHA 1
170 #define MPEG2_ACCEL_ALPHA_MVI 2
171 #define MPEG2_ACCEL_SPARC_VIS 1
172 #define MPEG2_ACCEL_SPARC_VIS2 2
173 #define MPEG2_ACCEL_DETECT 0x80000000
174
175 uint32_t mpeg2_accel (uint32_t accel);
176 mpeg2dec_t * mpeg2_init (void);
177 const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec);
178 void mpeg2_close (mpeg2dec_t * mpeg2dec);
179
180 void mpeg2_buffer (mpeg2dec_t * mpeg2dec, uint8_t * start, uint8_t * end);
181 int mpeg2_getpos (mpeg2dec_t * mpeg2dec);
182 mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec);
183
184 void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset);
185 void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip);
186 void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end);
187
188 void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2);
189
190 void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
191                       uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]);
192
193 typedef enum
194 {
195     MPEG2_ALLOC_MPEG2DEC = 0,
196     MPEG2_ALLOC_CHUNK = 1,
197     MPEG2_ALLOC_YUV = 2,
198     MPEG2_ALLOC_CONVERT_ID = 3,
199     MPEG2_ALLOC_CONVERTED = 4
200 } mpeg2_alloc_t;
201
202 void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason);
203 void mpeg2_free (void * buf);
204 void mpeg2_malloc_hooks (void * malloc (unsigned, mpeg2_alloc_t),
205                          int free (void *));
206
207 #endif /* MPEG2_H */