1
|
1 #include <inttypes.h>
|
|
2 /*
|
|
3 * mpeg2_internal.h
|
|
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 *
|
|
8 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * mpeg2dec is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22
|
|
23 // hack mode - temporary
|
|
24 // 0 = decode B pictures in a small slice buffer, display slice per slice
|
|
25 // 1 = decode in a frame buffer, display slice per slice
|
|
26 // 2 = decode in a frame buffer, display whole frames
|
|
27 #define HACK_MODE 0
|
|
28
|
|
29 // macroblock modes
|
|
30 #define MACROBLOCK_INTRA 1
|
|
31 #define MACROBLOCK_PATTERN 2
|
|
32 #define MACROBLOCK_MOTION_BACKWARD 4
|
|
33 #define MACROBLOCK_MOTION_FORWARD 8
|
|
34 #define MACROBLOCK_QUANT 16
|
|
35 #define DCT_TYPE_INTERLACED 32
|
|
36 // motion_type
|
|
37 #define MOTION_TYPE_MASK (3*64)
|
|
38 #define MOTION_TYPE_BASE 64
|
|
39 #define MC_FIELD (1*64)
|
|
40 #define MC_FRAME (2*64)
|
|
41 #define MC_16X8 (2*64)
|
|
42 #define MC_DMV (3*64)
|
|
43
|
|
44 //picture structure
|
|
45 #define TOP_FIELD 1
|
|
46 #define BOTTOM_FIELD 2
|
|
47 #define FRAME_PICTURE 3
|
|
48
|
|
49 //picture coding type
|
|
50 #define I_TYPE 1
|
|
51 #define P_TYPE 2
|
|
52 #define B_TYPE 3
|
|
53 #define D_TYPE 4
|
|
54
|
|
55 //The picture struct contains all of the top level state
|
|
56 //information (ie everything except slice and macroblock
|
|
57 //state)
|
|
58 typedef struct picture_s {
|
|
59 //-- sequence header stuff --
|
|
60 uint8_t intra_quantizer_matrix [64];
|
|
61 uint8_t non_intra_quantizer_matrix [64];
|
|
62
|
|
63 //The width and height of the picture snapped to macroblock units
|
|
64 int coded_picture_width;
|
|
65 int coded_picture_height;
|
|
66
|
|
67 //-- picture header stuff --
|
|
68
|
|
69 //what type of picture this is (I,P,or B) D from MPEG-1 isn't supported
|
|
70 int picture_coding_type;
|
|
71
|
|
72 //-- picture coding extension stuff --
|
|
73
|
|
74 //quantization factor for motion vectors
|
|
75 int f_code[2][2];
|
|
76 //quantization factor for intra dc coefficients
|
|
77 int intra_dc_precision;
|
|
78 //top/bottom/both fields
|
|
79 int picture_structure;
|
|
80 //bool to indicate all predictions are frame based
|
|
81 int frame_pred_frame_dct;
|
|
82 //bool to indicate whether intra blocks have motion vectors
|
|
83 // (for concealment)
|
|
84 int concealment_motion_vectors;
|
|
85 //bit to indicate which quantization table to use
|
|
86 int q_scale_type;
|
|
87 //bool to use different vlc tables
|
|
88 int intra_vlc_format;
|
|
89
|
|
90 //last macroblock in the picture
|
|
91 int last_mba;
|
|
92 //width of picture in macroblocks
|
|
93 int mb_width;
|
|
94
|
|
95 //stuff derived from bitstream
|
|
96
|
|
97 //pointer to the zigzag scan we're supposed to be using
|
|
98 uint8_t * scan;
|
|
99
|
|
100 //Pointer to the current planar frame buffer (Y,Cr,CB)
|
|
101 uint8_t * current_frame[3];
|
|
102 //storage for reference frames plus a b-frame
|
|
103 uint8_t * forward_reference_frame[3];
|
|
104 uint8_t * backward_reference_frame[3];
|
|
105 uint8_t * throwaway_frame[3];
|
|
106 uint8_t * pp_frame[3]; // postprocess
|
|
107 //uint8_t * throwaway_frame;
|
|
108
|
|
109 int pp_options; // postprocess
|
|
110
|
|
111 int second_field;
|
|
112
|
|
113 // MPEG1 - testing
|
|
114 uint8_t mpeg1;
|
|
115
|
|
116 //these things are not needed by the decoder
|
|
117 //NOTICE : this is a temporary interface, we will build a better one later.
|
|
118 int aspect_ratio_information;
|
|
119 int frame_rate_code;
|
|
120 int progressive_sequence;
|
|
121 int top_field_first; // this one is actually used for DMV MC
|
|
122 int repeat_first_field;
|
|
123 int progressive_frame;
|
|
124 // added by A'rpi/ESP-team:
|
|
125 int repeat_count;
|
|
126 int bitrate;
|
|
127 int frame_rate;
|
|
128 int display_picture_width;
|
|
129 int display_picture_height;
|
|
130 } picture_t;
|
|
131
|
|
132 typedef struct motion_s {
|
|
133 uint8_t * ref[2][3];
|
|
134 int pmv[2][2];
|
|
135 int f_code[2];
|
|
136 } motion_t;
|
|
137
|
|
138 // state that is carried from one macroblock to the next inside of a same slice
|
|
139 typedef struct slice_s {
|
|
140 // bit parsing stuff
|
|
141 uint32_t bitstream_buf; // current 32 bit working set of buffer
|
|
142 int bitstream_bits; // used bits in working set
|
|
143 uint8_t * bitstream_ptr; // buffer with stream data
|
|
144
|
|
145 //Motion vectors
|
|
146 //The f_ and b_ correspond to the forward and backward motion
|
|
147 //predictors
|
|
148 motion_t b_motion;
|
|
149 motion_t f_motion;
|
|
150
|
|
151 // predictor for DC coefficients in intra blocks
|
|
152 int16_t dc_dct_pred[3];
|
|
153
|
|
154 uint16_t quantizer_scale; // remove
|
|
155 } slice_t;
|
|
156
|
|
157 typedef struct mpeg2_config_s {
|
|
158 //Bit flags that enable various things
|
|
159 uint32_t flags;
|
|
160 } mpeg2_config_t;
|
|
161
|
|
162 //The only global variable,
|
|
163 //the config struct
|
|
164 extern mpeg2_config_t config;
|
|
165
|
|
166
|
|
167
|
|
168 // slice.c
|
|
169 void header_state_init (picture_t * picture);
|
|
170 int header_process_picture_header (picture_t * picture, uint8_t * buffer);
|
|
171 int header_process_sequence_header (picture_t * picture, uint8_t * buffer);
|
|
172 int header_process_extension (picture_t * picture, uint8_t * buffer);
|
|
173
|
|
174 // idct.c
|
|
175 void idct_init (void);
|
|
176
|
|
177 // idct_mlib.c
|
|
178 void idct_block_copy_mlib (int16_t * block, uint8_t * dest, int stride);
|
|
179 void idct_block_add_mlib (int16_t * block, uint8_t * dest, int stride);
|
|
180
|
|
181 // idct_mmx.c
|
|
182 void idct_block_copy_mmxext (int16_t *block, uint8_t * dest, int stride);
|
|
183 void idct_block_add_mmxext (int16_t *block, uint8_t * dest, int stride);
|
|
184 void idct_block_copy_mmx (int16_t *block, uint8_t * dest, int stride);
|
|
185 void idct_block_add_mmx (int16_t *block, uint8_t * dest, int stride);
|
|
186 void idct_mmx_init (void);
|
|
187
|
|
188 // motion_comp.c
|
|
189 void motion_comp_init (void);
|
|
190
|
|
191 typedef struct mc_functions_s
|
|
192 {
|
|
193 void (* put [8]) (uint8_t *dst, uint8_t *, int32_t, int32_t);
|
|
194 void (* avg [8]) (uint8_t *dst, uint8_t *, int32_t, int32_t);
|
|
195 } mc_functions_t;
|
|
196
|
|
197 #define MOTION_COMP_EXTERN(x) mc_functions_t mc_functions_##x = \
|
|
198 { \
|
|
199 {MC_put_16_##x, MC_put_x16_##x, MC_put_y16_##x, MC_put_xy16_##x, \
|
|
200 MC_put_8_##x, MC_put_x8_##x, MC_put_y8_##x, MC_put_xy8_##x}, \
|
|
201 {MC_avg_16_##x, MC_avg_x16_##x, MC_avg_y16_##x, MC_avg_xy16_##x, \
|
|
202 MC_avg_8_##x, MC_avg_x8_##x, MC_avg_y8_##x, MC_avg_xy8_##x} \
|
|
203 };
|
|
204
|
|
205 extern mc_functions_t mc_functions_c;
|
|
206 extern mc_functions_t mc_functions_mmx;
|
|
207 extern mc_functions_t mc_functions_mmxext;
|
|
208 extern mc_functions_t mc_functions_3dnow;
|
|
209 extern mc_functions_t mc_functions_mlib;
|
|
210
|
|
211 // slice.c
|
|
212 int slice_process (picture_t *picture, uint8_t code, uint8_t * buffer);
|
|
213
|
|
214 // stats.c
|
|
215 void stats_header (uint8_t code, uint8_t * buffer);
|
|
216
|
|
217 #define MBC 45
|
|
218 #define MBR 36
|
|
219 extern int quant_store[MBR+1][MBC+1]; // [Review]
|
|
220
|