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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 273 - (hide annotations) (download)
Fri Nov 12 01:10:22 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 6518 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4013 local: v0.9.7.197-latest) in ./trunk
1 william 31 /*
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 william 62 #pragma once
26 william 31
27 william 62 #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 william 273 #define StoreDestIdx(idx) case idx: _mm_store_ps(&destxmm[idx-1][0], zeroreg)
41 william 62
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 william 31 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 william 62 u8 Y[16][16]; //0
112     u8 Cb[8][8]; //1
113     u8 Cr[8][8]; //2
114 william 31 };
115    
116     struct macroblock_16{
117 william 62 s16 Y[16][16]; //0
118     s16 Cb[8][8]; //1
119     s16 Cr[8][8]; //2
120 william 31 };
121    
122     struct macroblock_rgb32{
123     struct {
124 william 62 u8 r, g, b, a;
125 william 31 } c[16][16];
126     };
127    
128 william 62 struct rgb16_t{
129     u16 r:5, g:5, b:5, a:1;
130 william 31 };
131    
132     struct macroblock_rgb16{
133 william 62 rgb16_t c[16][16];
134 william 31 };
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 william 62 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 william 191 uint ipu0_data; // amount of data in the output macroblock (in QWC)
152 william 62 uint ipu0_idx;
153    
154 william 273 int quantizer_scale;
155 william 31
156     /* now non-slice-specific information */
157    
158     /* picture header stuff */
159    
160     /* what type of picture this is (I, P, B, D) */
161     int coding_type;
162    
163     /* picture coding extension stuff */
164    
165 william 62 /* predictor for DC coefficients in intra blocks */
166     s16 dc_dct_pred[3];
167    
168 william 31 /* quantization factor for intra dc coefficients */
169     int intra_dc_precision;
170     /* top/bottom/both fields */
171     int picture_structure;
172     /* bool to indicate all predictions are frame based */
173     int frame_pred_frame_dct;
174     /* bool to indicate whether intra blocks have motion vectors */
175     /* (for concealment) */
176     int concealment_motion_vectors;
177     /* bit to indicate which quantization table to use */
178     int q_scale_type;
179     /* bool to use different vlc tables */
180     int intra_vlc_format;
181     /* used for DMV MC */
182     int top_field_first;
183     // Pseudo Sign Offset
184     int sgn;
185     // Dither Enable
186     int dte;
187     // Output Format
188     int ofm;
189     // Macroblock type
190     int macroblock_modes;
191     // DC Reset
192     int dcr;
193     // Coded block pattern
194     int coded_block_pattern;
195    
196     /* stuff derived from bitstream */
197    
198 william 62 /* the zigzag scan we're supposed to be using, true for alt, false for normal */
199     bool scantype;
200 william 31
201     int mpeg1;
202 william 62
203     template< typename T >
204     void SetOutputTo( T& obj )
205     {
206     uint mb_offset = ((uptr)&obj - (uptr)&mb8);
207     pxAssume( (mb_offset & 15) == 0 );
208     ipu0_idx = mb_offset / 16;
209     ipu0_data = sizeof(obj)/16;
210     }
211    
212     u128* GetIpuDataPtr()
213     {
214     return ((u128*)&mb8) + ipu0_idx;
215     }
216    
217     void AdvanceIpuDataBy(uint amt)
218     {
219 william 273 pxAssumeMsg(ipu0_data>=amt, "IPU FIFO Overflow on advance!" );
220 william 62 ipu0_idx += amt;
221     ipu0_data -= amt;
222     }
223 william 31 };
224    
225 william 62 struct mpeg2_scan_pack
226     {
227     u8 norm[64];
228     u8 alt[64];
229 william 31
230 william 62 mpeg2_scan_pack();
231     };
232    
233 william 191 extern int bitstream_init ();
234     extern u32 UBITS(uint bits);
235     extern s32 SBITS(uint bits);
236    
237 william 62 extern void mpeg2_idct_copy(s16 * block, u8* dest, int stride);
238     extern void mpeg2_idct_add(int last, s16 * block, s16* dest, int stride);
239    
240     extern bool mpeg2sliceIDEC();
241     extern bool mpeg2_slice();
242     extern int get_macroblock_address_increment();
243     extern int get_macroblock_modes();
244 william 31
245 william 62 extern int get_motion_delta(const int f_code);
246     extern int get_dmv();
247 william 31
248 william 62 extern void ipu_csc(macroblock_8& mb8, macroblock_rgb32& rgb32, int sgn);
249     extern void ipu_dither(const macroblock_rgb32& rgb32, macroblock_rgb16& rgb16, int dte);
250     extern void ipu_vq(macroblock_rgb16& rgb16, u8* indx4);
251 william 31
252 william 62 extern int slice (u8 * buffer);
253 william 31
254     #ifdef _MSC_VER
255 william 191 #define BigEndian(in) _byteswap_ulong(in)
256 william 31 #else
257 william 191 #define BigEndian(in) __builtin_bswap32(in) // or we could use the asm function bswap...
258 william 31 #endif
259    
260 william 62 #ifdef _MSC_VER
261 william 191 #define BigEndian64(in) _byteswap_uint64(in)
262 william 62 #else
263 william 191 #define BigEndian64(in) __builtin_bswap64(in) // or we could use the asm function bswap...
264 william 62 #endif
265    
266     extern __aligned16 const mpeg2_scan_pack mpeg2_scan;
267     extern const int non_linear_quantizer_scale[];
268    
269     // The IPU can only do one task at once and never uses other buffers so all mpeg state variables
270     // are made available to mpeg/vlc modules as globals here:
271    
272     extern __aligned16 tIPU_BP g_BP;
273     extern __aligned16 decoder_t decoder;
274    

  ViewVC Help
Powered by ViewVC 1.1.22