3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
7 * See http://libmpeg2.sourceforge.net/ for updates.
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.
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.
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
27 #include "mpeg2dec_config.h"
29 #define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
30 #define MPEG2_RELEASE MPEG2_VERSION (0, 4, 0) /* 0.4.0 */
32 #define SEQ_FLAG_MPEG2 1
33 #define SEQ_FLAG_CONSTRAINED_PARAMETERS 2
34 #define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4
35 #define SEQ_FLAG_LOW_DELAY 8
36 #define SEQ_FLAG_COLOUR_DESCRIPTION 16
38 #define SEQ_MASK_VIDEO_FORMAT 0xe0
39 #define SEQ_VIDEO_FORMAT_COMPONENT 0x00
40 #define SEQ_VIDEO_FORMAT_PAL 0x20
41 #define SEQ_VIDEO_FORMAT_NTSC 0x40
42 #define SEQ_VIDEO_FORMAT_SECAM 0x60
43 #define SEQ_VIDEO_FORMAT_MAC 0x80
44 #define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0
46 typedef struct mpeg2_sequence_s
48 unsigned int width
, height
;
49 unsigned int chroma_width
, chroma_height
;
50 unsigned int byte_rate
;
51 unsigned int vbv_buffer_size
;
54 unsigned int picture_width
, picture_height
;
55 unsigned int display_width
, display_height
;
56 unsigned int pixel_width
, pixel_height
;
57 unsigned int frame_period
;
59 uint8_t profile_level_id
;
60 uint8_t colour_primaries
;
61 uint8_t transfer_characteristics
;
62 uint8_t matrix_coefficients
;
65 #define GOP_FLAG_DROP_FRAME 1
66 #define GOP_FLAG_BROKEN_LINK 2
67 #define GOP_FLAG_CLOSED_GOP 4
69 typedef struct mpeg2_gop_s
78 #define PIC_MASK_CODING_TYPE 7
79 #define PIC_FLAG_CODING_TYPE_I 1
80 #define PIC_FLAG_CODING_TYPE_P 2
81 #define PIC_FLAG_CODING_TYPE_B 3
82 #define PIC_FLAG_CODING_TYPE_D 4
84 #define PIC_FLAG_TOP_FIELD_FIRST 8
85 #define PIC_FLAG_PROGRESSIVE_FRAME 16
86 #define PIC_FLAG_COMPOSITE_DISPLAY 32
87 #define PIC_FLAG_SKIP 64
88 #define PIC_FLAG_TAGS 128
89 #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
91 typedef struct mpeg2_picture_s
93 unsigned int temporal_reference
;
94 unsigned int nb_fields
;
103 typedef struct mpeg2_fbuf_s
105 uint8_t * buf
[MPEG2_COMPONENTS
];
109 typedef struct mpeg2_info_s
111 const mpeg2_sequence_t
* sequence
;
112 const mpeg2_gop_t
* gop
;
113 const mpeg2_picture_t
* current_picture
;
114 const mpeg2_picture_t
* current_picture_2nd
;
115 const mpeg2_fbuf_t
* current_fbuf
;
116 const mpeg2_picture_t
* display_picture
;
117 const mpeg2_picture_t
* display_picture_2nd
;
118 const mpeg2_fbuf_t
* display_fbuf
;
119 const mpeg2_fbuf_t
* discard_fbuf
;
120 const uint8_t * user_data
;
121 unsigned int user_data_len
;
124 typedef struct mpeg2dec_s mpeg2dec_t
;
125 typedef struct mpeg2_decoder_s mpeg2_decoder_t
;
131 STATE_SEQUENCE_REPEATED
= 2,
135 STATE_PICTURE_2ND
= 6,
139 STATE_INVALID_END
= 10
142 typedef struct mpeg2_convert_init_s
144 unsigned int id_size
;
145 unsigned int buf_size
[MPEG2_COMPONENTS
];
146 void (* start
)(void * id
, const mpeg2_fbuf_t
* fbuf
,
147 const mpeg2_picture_t
* picture
, const mpeg2_gop_t
* gop
);
148 void (* copy
)(void * id
, uint8_t * const * src
, unsigned int v_offset
);
149 } mpeg2_convert_init_t
;
153 MPEG2_CONVERT_SET
= 0,
154 MPEG2_CONVERT_STRIDE
= 1,
155 MPEG2_CONVERT_START
= 2
156 } mpeg2_convert_stage_t
;
158 typedef int mpeg2_convert_t (int stage
, void * id
,
159 const mpeg2_sequence_t
* sequence
, int stride
,
160 void * arg
, mpeg2_convert_init_t
* result
);
161 int mpeg2_convert (mpeg2dec_t
* mpeg2dec
, mpeg2_convert_t convert
, void * arg
);
162 int mpeg2_stride (mpeg2dec_t
* mpeg2dec
, int stride
);
163 void mpeg2_set_buf (mpeg2dec_t
* mpeg2dec
, uint8_t * buf
[MPEG2_COMPONENTS
],
165 void mpeg2_custom_fbuf (mpeg2dec_t
* mpeg2dec
, int custom_fbuf
);
167 mpeg2dec_t
* mpeg2_init (void);
168 const mpeg2_info_t
* mpeg2_info (mpeg2dec_t
* mpeg2dec
);
169 void mpeg2_close (mpeg2dec_t
* mpeg2dec
);
171 void mpeg2_buffer (mpeg2dec_t
* mpeg2dec
, uint8_t * start
, uint8_t * end
);
172 int mpeg2_getpos (mpeg2dec_t
* mpeg2dec
);
173 mpeg2_state_t
mpeg2_parse (mpeg2dec_t
* mpeg2dec
);
175 void mpeg2_reset (mpeg2dec_t
* mpeg2dec
, int full_reset
);
176 void mpeg2_skip (mpeg2dec_t
* mpeg2dec
, int skip
);
177 void mpeg2_slice_region (mpeg2dec_t
* mpeg2dec
, int start
, int end
);
179 void mpeg2_tag_picture (mpeg2dec_t
* mpeg2dec
, uint32_t tag
, uint32_t tag2
);
181 void mpeg2_init_fbuf (mpeg2_decoder_t
* decoder
,
182 uint8_t * current_fbuf
[MPEG2_COMPONENTS
],
183 uint8_t * forward_fbuf
[MPEG2_COMPONENTS
],
184 uint8_t * backward_fbuf
[MPEG2_COMPONENTS
]);
185 void mpeg2_slice (mpeg2_decoder_t
* decoder
, int code
, const uint8_t * buffer
);
189 MPEG2_ALLOC_MPEG2DEC
= 0,
190 MPEG2_ALLOC_CHUNK
= 1,
192 MPEG2_ALLOC_CONVERT_ID
= 3,
193 MPEG2_ALLOC_CONVERTED
= 4
196 void * mpeg2_malloc (unsigned size
, mpeg2_alloc_t reason
);
198 void mpeg2_free (void * buf
);
200 /* allocates a dedicated buffer and locks all previous allocation in place */
201 void * mpeg2_bufalloc(unsigned size
, mpeg2_alloc_t reason
);
202 /* clears all non-dedicated buffer space */
203 void mpeg2_mem_reset(void);
204 void mpeg2_alloc_init(unsigned char* buf
, int mallocsize
);