/[pcsx2_0.9.7]/trunk/pcsx2/IPU/mpeg2lib/Mpeg.h
ViewVC logotype

Contents of /trunk/pcsx2/IPU/mpeg2lib/Mpeg.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 191 - (show annotations) (download)
Mon Sep 20 05:35:51 2010 UTC (10 years ago) by william
File MIME type: text/plain
File size: 6817 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.3795 local: v0.9.7.186-latest) in ./trunk
1 /*
2 * Mpeg.h
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 * Modified by Florin for PCSX2 emu
6 *
7 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
8 * See http://libmpeg2.sourceforge.net/ for updates.
9 *
10 * mpeg2dec is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * mpeg2dec is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25 #pragma once
26
27 #include <xmmintrin.h>
28
29 template< typename T >
30 __noinline void memzero_sse_a( T& dest )
31 {
32 #define MZFqwc (sizeof(dest)/16)
33
34 C_ASSERT( (sizeof(dest) & 0xf) == 0 );
35
36 __m128 zeroreg = _mm_setzero_ps();
37
38 float (*destxmm)[4] = (float(*)[4])&dest;
39
40 #define StoreDestIdx(idx) case idx: _mm_store_ps(&destxmm[idx][0], zeroreg)
41
42 switch( MZFqwc & 0x07 )
43 {
44 StoreDestIdx(0x07);
45 StoreDestIdx(0x06);
46 StoreDestIdx(0x05);
47 StoreDestIdx(0x04);
48 StoreDestIdx(0x03);
49 StoreDestIdx(0x02);
50 StoreDestIdx(0x01);
51 }
52
53 destxmm += (MZFqwc & 0x07);
54 for( uint i=0; i<MZFqwc / 8; ++i, destxmm+=8 )
55 {
56 _mm_store_ps(&destxmm[0][0], zeroreg);
57 _mm_store_ps(&destxmm[1][0], zeroreg);
58 _mm_store_ps(&destxmm[2][0], zeroreg);
59 _mm_store_ps(&destxmm[3][0], zeroreg);
60 _mm_store_ps(&destxmm[4][0], zeroreg);
61 _mm_store_ps(&destxmm[5][0], zeroreg);
62 _mm_store_ps(&destxmm[6][0], zeroreg);
63 _mm_store_ps(&destxmm[7][0], zeroreg);
64 }
65
66 #undef MZFqwc
67 };
68
69 // the IPU is fixed to 16 byte strides (128-bit / QWC resolution):
70 static const uint decoder_stride = 16;
71
72 enum macroblock_modes
73 {
74 MACROBLOCK_INTRA = 1,
75 MACROBLOCK_PATTERN = 2,
76 MACROBLOCK_MOTION_BACKWARD = 4,
77 MACROBLOCK_MOTION_FORWARD = 8,
78 MACROBLOCK_QUANT = 16,
79 DCT_TYPE_INTERLACED = 32
80 };
81
82 enum motion_type
83 {
84 MOTION_TYPE_SHIFT = 6,
85 MOTION_TYPE_MASK = (3*64),
86 MOTION_TYPE_BASE = 64,
87 MC_FIELD = (1*64),
88 MC_FRAME = (2*64),
89 MC_16X8 = (2*64),
90 MC_DMV = (3*64)
91 };
92
93 /* picture structure */
94 enum picture_structure
95 {
96 TOP_FIELD = 1,
97 BOTTOM_FIELD = 2,
98 FRAME_PICTURE = 3
99 };
100
101 /* picture coding type */
102 enum picture_coding_type
103 {
104 I_TYPE =1,
105 P_TYPE = 2,
106 B_TYPE = 3,
107 D_TYPE = 4
108 };
109
110 struct macroblock_8{
111 u8 Y[16][16]; //0
112 u8 Cb[8][8]; //1
113 u8 Cr[8][8]; //2
114 };
115
116 struct macroblock_16{
117 s16 Y[16][16]; //0
118 s16 Cb[8][8]; //1
119 s16 Cr[8][8]; //2
120 };
121
122 struct macroblock_rgb32{
123 struct {
124 u8 r, g, b, a;
125 } c[16][16];
126 };
127
128 struct rgb16_t{
129 u16 r:5, g:5, b:5, a:1;
130 };
131
132 struct macroblock_rgb16{
133 rgb16_t c[16][16];
134 };
135
136 struct decoder_t {
137 /* first, state that carries information from one macroblock to the */
138 /* next inside a slice, and is never used outside of mpeg2_slice() */
139
140 /* DCT coefficients - should be kept aligned ! */
141 s16 DCTblock[64];
142
143 u8 niq[64]; //non-intraquant matrix (sequence header)
144 u8 iq[64]; //intraquant matrix (sequence header)
145
146 macroblock_8 mb8;
147 macroblock_16 mb16;
148 macroblock_rgb32 rgb32;
149 macroblock_rgb16 rgb16;
150
151 uint ipu0_data; // amount of data in the output macroblock (in QWC)
152 uint ipu0_idx;
153
154 /* bit parsing stuff */
155 //u32 bitstream_buf; /* current 32 bit working set */
156 //int bitstream_bits; /* used bits in working set */
157
158 int quantizer_scale; /* remove */
159 int dmv_offset; /* remove */
160
161 /* now non-slice-specific information */
162
163 /* picture header stuff */
164
165 /* what type of picture this is (I, P, B, D) */
166 int coding_type;
167
168 /* picture coding extension stuff */
169
170 /* predictor for DC coefficients in intra blocks */
171 s16 dc_dct_pred[3];
172
173 /* quantization factor for intra dc coefficients */
174 int intra_dc_precision;
175 /* top/bottom/both fields */
176 int picture_structure;
177 /* bool to indicate all predictions are frame based */
178 int frame_pred_frame_dct;
179 /* bool to indicate whether intra blocks have motion vectors */
180 /* (for concealment) */
181 int concealment_motion_vectors;
182 /* bit to indicate which quantization table to use */
183 int q_scale_type;
184 /* bool to use different vlc tables */
185 int intra_vlc_format;
186 /* used for DMV MC */
187 int top_field_first;
188 // Pseudo Sign Offset
189 int sgn;
190 // Dither Enable
191 int dte;
192 // Output Format
193 int ofm;
194 // Macroblock count
195 int mbc;
196 // Macroblock type
197 int macroblock_modes;
198 // DC Reset
199 int dcr;
200 // Coded block pattern
201 int coded_block_pattern;
202
203 /* stuff derived from bitstream */
204
205 /* the zigzag scan we're supposed to be using, true for alt, false for normal */
206 bool scantype;
207
208 int second_field;
209
210 int mpeg1;
211
212 template< typename T >
213 void SetOutputTo( T& obj )
214 {
215 uint mb_offset = ((uptr)&obj - (uptr)&mb8);
216 pxAssume( (mb_offset & 15) == 0 );
217 ipu0_idx = mb_offset / 16;
218 ipu0_data = sizeof(obj)/16;
219 }
220
221 u128* GetIpuDataPtr()
222 {
223 return ((u128*)&mb8) + ipu0_idx;
224 }
225
226 void AdvanceIpuDataBy(uint amt)
227 {
228 pxAssumeDev(ipu0_data>=amt, "IPU FIFO Overflow on advance!" );
229 ipu0_idx += amt;
230 ipu0_data -= amt;
231 }
232
233 __fi bool ReadIpuData(u128* out);
234 };
235
236 struct mpeg2_scan_pack
237 {
238 u8 norm[64];
239 u8 alt[64];
240
241 mpeg2_scan_pack();
242 };
243
244 extern int bitstream_init ();
245 extern u32 UBITS(uint bits);
246 extern s32 SBITS(uint bits);
247
248 extern void mpeg2_idct_copy(s16 * block, u8* dest, int stride);
249 extern void mpeg2_idct_add(int last, s16 * block, s16* dest, int stride);
250
251 #define IDEC 0
252 #define BDEC 1
253
254 extern bool mpeg2sliceIDEC();
255 extern bool mpeg2_slice();
256 extern int get_macroblock_address_increment();
257 extern int get_macroblock_modes();
258
259 extern int get_motion_delta(const int f_code);
260 extern int get_dmv();
261
262 extern void ipu_csc(macroblock_8& mb8, macroblock_rgb32& rgb32, int sgn);
263 extern void ipu_dither(const macroblock_rgb32& rgb32, macroblock_rgb16& rgb16, int dte);
264 extern void ipu_vq(macroblock_rgb16& rgb16, u8* indx4);
265
266 extern int slice (u8 * buffer);
267
268 #ifdef _MSC_VER
269 #define BigEndian(in) _byteswap_ulong(in)
270 #else
271 #define BigEndian(in) __builtin_bswap32(in) // or we could use the asm function bswap...
272 #endif
273
274 #ifdef _MSC_VER
275 #define BigEndian64(in) _byteswap_uint64(in)
276 #else
277 #define BigEndian64(in) __builtin_bswap64(in) // or we could use the asm function bswap...
278 #endif
279
280 extern __aligned16 const mpeg2_scan_pack mpeg2_scan;
281 extern const int non_linear_quantizer_scale[];
282
283 // The IPU can only do one task at once and never uses other buffers so all mpeg state variables
284 // are made available to mpeg/vlc modules as globals here:
285
286 extern __aligned16 tIPU_BP g_BP;
287 extern __aligned16 decoder_t decoder;
288

  ViewVC Help
Powered by ViewVC 1.1.22