1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* native api |
* - Native API implementation - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* This program is an implementation of a part of one or more MPEG-4 |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
24 |
* |
* |
25 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
27 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
* |
* |
29 |
*************************************************************************/ |
****************************************************************************/ |
30 |
|
|
31 |
/************************************************************************** |
/***************************************************************************** |
32 |
* |
* |
33 |
* History: |
* History |
34 |
* |
* |
35 |
* 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
* - 23.06.2002 added XVID_CPU_CHKONLY |
36 |
* 22.12.2001 API change: added xvid_init() - Isibaar |
* - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
37 |
* 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* - 22.12.2001 API change: added xvid_init() - Isibaar |
38 |
|
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
39 |
* |
* |
40 |
*************************************************************************/ |
* $Id$ |
41 |
|
* |
42 |
|
****************************************************************************/ |
43 |
|
|
44 |
#include "xvid.h" |
#include "xvid.h" |
45 |
#include "decoder.h" |
#include "decoder.h" |
50 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
51 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
52 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
53 |
|
#include "utils/mbfunctions.h" |
54 |
#include "quant/quant_h263.h" |
#include "quant/quant_h263.h" |
55 |
#include "quant/quant_mpeg4.h" |
#include "quant/quant_mpeg4.h" |
56 |
|
#include "motion/motion.h" |
57 |
#include "motion/sad.h" |
#include "motion/sad.h" |
58 |
#include "utils/emms.h" |
#include "utils/emms.h" |
59 |
#include "utils/timer.h" |
#include "utils/timer.h" |
60 |
|
#include "bitstream/mbcoding.h" |
61 |
|
|
62 |
|
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
63 |
|
|
64 |
|
#ifdef WIN32 |
65 |
|
#include <windows.h> |
66 |
|
#else |
67 |
|
#include <signal.h> |
68 |
|
#include <setjmp.h> |
69 |
|
#endif |
70 |
|
|
71 |
|
|
72 |
|
#ifndef WIN32 |
73 |
|
|
74 |
|
static jmp_buf mark; |
75 |
|
|
76 |
int xvid_init(void *handle, int opt, void *param1, void *param2) |
static void |
77 |
|
sigill_handler(int signal) |
78 |
|
{ |
79 |
|
longjmp(mark, 1); |
80 |
|
} |
81 |
|
#endif |
82 |
|
|
83 |
|
|
84 |
|
/* |
85 |
|
calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
86 |
|
return values: |
87 |
|
-1 : could not determine |
88 |
|
0 : SIGILL was *not* signalled |
89 |
|
1 : SIGILL was signalled |
90 |
|
*/ |
91 |
|
|
92 |
|
int |
93 |
|
sigill_check(void (*func)()) |
94 |
|
{ |
95 |
|
#ifdef WIN32 |
96 |
|
_try { |
97 |
|
func(); |
98 |
|
} |
99 |
|
_except(EXCEPTION_EXECUTE_HANDLER) { |
100 |
|
|
101 |
|
if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION) |
102 |
|
return 1; |
103 |
|
} |
104 |
|
return 0; |
105 |
|
#else |
106 |
|
void * old_handler; |
107 |
|
int jmpret; |
108 |
|
|
109 |
|
|
110 |
|
old_handler = signal(SIGILL, sigill_handler); |
111 |
|
if (old_handler == SIG_ERR) |
112 |
|
{ |
113 |
|
return -1; |
114 |
|
} |
115 |
|
|
116 |
|
jmpret = setjmp(mark); |
117 |
|
if (jmpret == 0) |
118 |
|
{ |
119 |
|
func(); |
120 |
|
} |
121 |
|
|
122 |
|
signal(SIGILL, old_handler); |
123 |
|
|
124 |
|
return jmpret; |
125 |
|
#endif |
126 |
|
} |
127 |
|
#endif |
128 |
|
|
129 |
|
/***************************************************************************** |
130 |
|
* XviD Init Entry point |
131 |
|
* |
132 |
|
* Well this function initialize all internal function pointers according |
133 |
|
* to the CPU features forced by the library client or autodetected (depending |
134 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
135 |
|
* image colorspace transformation tables. |
136 |
|
* |
137 |
|
* Returned value : XVID_ERR_OK |
138 |
|
* + API_VERSION in the input XVID_INIT_PARAM structure |
139 |
|
* + core build " " " " " |
140 |
|
* |
141 |
|
****************************************************************************/ |
142 |
|
|
143 |
|
|
144 |
|
static |
145 |
|
int xvid_init_init(XVID_INIT_PARAM * init_param) |
146 |
{ |
{ |
147 |
int cpu_flags; |
int cpu_flags; |
|
XVID_INIT_PARAM *init_param; |
|
148 |
|
|
149 |
init_param = (XVID_INIT_PARAM *) param1; |
/* Inform the client the API version */ |
150 |
|
init_param->api_version = API_VERSION; |
151 |
|
|
152 |
|
/* Inform the client the core build - unused because we're still alpha */ |
153 |
|
init_param->core_build = 1000; |
154 |
|
|
155 |
|
/* Do we have to force CPU features ? */ |
156 |
|
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
157 |
|
|
|
// force specific cpu settings? |
|
|
if((init_param->cpu_flags & XVID_CPU_FORCE) > 0) |
|
158 |
cpu_flags = init_param->cpu_flags; |
cpu_flags = init_param->cpu_flags; |
|
else { |
|
159 |
|
|
160 |
#ifdef ARCH_X86 |
} else { |
161 |
|
|
162 |
cpu_flags = check_cpu_features(); |
cpu_flags = check_cpu_features(); |
163 |
#else |
|
164 |
cpu_flags = 0; |
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
165 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
166 |
|
cpu_flags &= ~XVID_CPU_SSE; |
167 |
|
|
168 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
169 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
170 |
#endif |
#endif |
171 |
|
} |
172 |
|
|
173 |
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
174 |
|
{ |
175 |
init_param->cpu_flags = cpu_flags; |
init_param->cpu_flags = cpu_flags; |
176 |
|
return XVID_ERR_OK; |
177 |
} |
} |
178 |
|
|
179 |
// initialize the function pointers |
init_param->cpu_flags = cpu_flags; |
180 |
|
|
181 |
|
|
182 |
|
/* Initialize the function pointers */ |
183 |
idct_int32_init(); |
idct_int32_init(); |
184 |
|
init_vlc_tables(); |
185 |
|
|
186 |
|
/* Fixed Point Forward/Inverse DCT transformations */ |
187 |
fdct = fdct_int32; |
fdct = fdct_int32; |
188 |
idct = idct_int32; |
idct = idct_int32; |
189 |
|
|
190 |
|
/* Only needed on PPC Altivec archs */ |
191 |
|
sadInit = 0; |
192 |
|
|
193 |
|
/* Restore FPU context : emms_c is a nop functions */ |
194 |
emms = emms_c; |
emms = emms_c; |
195 |
|
|
196 |
|
/* Quantization functions */ |
197 |
quant_intra = quant_intra_c; |
quant_intra = quant_intra_c; |
198 |
dequant_intra = dequant_intra_c; |
dequant_intra = dequant_intra_c; |
199 |
quant_inter = quant_inter_c; |
quant_inter = quant_inter_c; |
204 |
quant4_inter = quant4_inter_c; |
quant4_inter = quant4_inter_c; |
205 |
dequant4_inter = dequant4_inter_c; |
dequant4_inter = dequant4_inter_c; |
206 |
|
|
207 |
|
/* Block transfer related functions */ |
208 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
209 |
transfer_16to8copy = transfer_16to8copy_c; |
transfer_16to8copy = transfer_16to8copy_c; |
210 |
transfer_8to16sub = transfer_8to16sub_c; |
transfer_8to16sub = transfer_8to16sub_c; |
211 |
|
transfer_8to16sub2 = transfer_8to16sub2_c; |
212 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
213 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
214 |
|
|
215 |
|
/* Interlacing functions */ |
216 |
|
MBFieldTest = MBFieldTest_c; |
217 |
|
|
218 |
|
/* Image interpolation related functions */ |
219 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
220 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
221 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
222 |
|
|
223 |
|
interpolate16x16_lowpass_h = interpolate16x16_lowpass_h_c; |
224 |
|
interpolate16x16_lowpass_v = interpolate16x16_lowpass_v_c; |
225 |
|
interpolate16x16_lowpass_hv = interpolate16x16_lowpass_hv_c; |
226 |
|
|
227 |
|
interpolate8x8_lowpass_h = interpolate8x8_lowpass_h_c; |
228 |
|
interpolate8x8_lowpass_v = interpolate8x8_lowpass_v_c; |
229 |
|
interpolate8x8_lowpass_hv = interpolate8x8_lowpass_hv_c; |
230 |
|
|
231 |
|
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_c; |
232 |
|
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_c; |
233 |
|
|
234 |
|
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
235 |
|
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
236 |
|
|
237 |
|
/* Initialize internal colorspace transformation tables */ |
238 |
colorspace_init(); |
colorspace_init(); |
239 |
|
|
240 |
|
/* All colorspace transformation functions User Format->YV12 */ |
241 |
|
yv12_to_yv12 = yv12_to_yv12_c; |
242 |
rgb555_to_yv12 = rgb555_to_yv12_c; |
rgb555_to_yv12 = rgb555_to_yv12_c; |
243 |
rgb565_to_yv12 = rgb565_to_yv12_c; |
rgb565_to_yv12 = rgb565_to_yv12_c; |
244 |
rgb24_to_yv12 = rgb24_to_yv12_c; |
bgr_to_yv12 = bgr_to_yv12_c; |
245 |
rgb32_to_yv12 = rgb32_to_yv12_c; |
bgra_to_yv12 = bgra_to_yv12_c; |
246 |
yuv_to_yv12 = yuv_to_yv12_c; |
abgr_to_yv12 = abgr_to_yv12_c; |
247 |
|
rgba_to_yv12 = rgba_to_yv12_c; |
248 |
yuyv_to_yv12 = yuyv_to_yv12_c; |
yuyv_to_yv12 = yuyv_to_yv12_c; |
249 |
uyvy_to_yv12 = uyvy_to_yv12_c; |
uyvy_to_yv12 = uyvy_to_yv12_c; |
250 |
|
|
251 |
|
rgb555i_to_yv12 = rgb555i_to_yv12_c; |
252 |
|
rgb565i_to_yv12 = rgb565i_to_yv12_c; |
253 |
|
bgri_to_yv12 = bgri_to_yv12_c; |
254 |
|
bgrai_to_yv12 = bgrai_to_yv12_c; |
255 |
|
abgri_to_yv12 = abgri_to_yv12_c; |
256 |
|
rgbai_to_yv12 = rgbai_to_yv12_c; |
257 |
|
yuyvi_to_yv12 = yuyvi_to_yv12_c; |
258 |
|
uyvyi_to_yv12 = uyvyi_to_yv12_c; |
259 |
|
|
260 |
|
|
261 |
|
/* All colorspace transformation functions YV12->User format */ |
262 |
yv12_to_rgb555 = yv12_to_rgb555_c; |
yv12_to_rgb555 = yv12_to_rgb555_c; |
263 |
yv12_to_rgb565 = yv12_to_rgb565_c; |
yv12_to_rgb565 = yv12_to_rgb565_c; |
264 |
yv12_to_rgb24 = yv12_to_rgb24_c; |
yv12_to_bgr = yv12_to_bgr_c; |
265 |
yv12_to_rgb32 = yv12_to_rgb32_c; |
yv12_to_bgra = yv12_to_bgra_c; |
266 |
yv12_to_yuv = yv12_to_yuv_c; |
yv12_to_abgr = yv12_to_abgr_c; |
267 |
|
yv12_to_rgba = yv12_to_rgba_c; |
268 |
yv12_to_yuyv = yv12_to_yuyv_c; |
yv12_to_yuyv = yv12_to_yuyv_c; |
269 |
yv12_to_uyvy = yv12_to_uyvy_c; |
yv12_to_uyvy = yv12_to_uyvy_c; |
270 |
|
|
271 |
|
yv12_to_rgb555i = yv12_to_rgb555i_c; |
272 |
|
yv12_to_rgb565i = yv12_to_rgb565i_c; |
273 |
|
yv12_to_bgri = yv12_to_bgri_c; |
274 |
|
yv12_to_bgrai = yv12_to_bgrai_c; |
275 |
|
yv12_to_abgri = yv12_to_abgri_c; |
276 |
|
yv12_to_rgbai = yv12_to_rgbai_c; |
277 |
|
yv12_to_yuyvi = yv12_to_yuyvi_c; |
278 |
|
yv12_to_uyvyi = yv12_to_uyvyi_c; |
279 |
|
|
280 |
|
/* Functions used in motion estimation algorithms */ |
281 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
282 |
sad16 = sad16_c; |
sad16 = sad16_c; |
283 |
sad8 = sad8_c; |
sad8 = sad8_c; |
284 |
|
sad16bi = sad16bi_c; |
285 |
|
sad8bi = sad8bi_c; |
286 |
dev16 = dev16_c; |
dev16 = dev16_c; |
287 |
|
sad16v = sad16v_c; |
288 |
|
|
289 |
|
// Halfpel8_Refine = Halfpel8_Refine_c; |
290 |
|
|
291 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
292 |
|
|
293 |
|
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
294 |
|
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
295 |
|
(cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2)) |
296 |
|
{ |
297 |
|
/* Restore FPU context : emms_c is a nop functions */ |
298 |
|
emms = emms_mmx; |
299 |
|
} |
300 |
|
|
301 |
if((cpu_flags & XVID_CPU_MMX) > 0) { |
if((cpu_flags & XVID_CPU_MMX) > 0) { |
302 |
|
|
303 |
|
/* Forward and Inverse Discrete Cosine Transformation functions */ |
304 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
305 |
idct = idct_mmx; |
idct = idct_mmx; |
306 |
|
|
307 |
emms = emms_mmx; |
/* Quantization related functions */ |
|
|
|
308 |
quant_intra = quant_intra_mmx; |
quant_intra = quant_intra_mmx; |
309 |
dequant_intra = dequant_intra_mmx; |
dequant_intra = dequant_intra_mmx; |
310 |
quant_inter = quant_inter_mmx; |
quant_inter = quant_inter_mmx; |
315 |
quant4_inter = quant4_inter_mmx; |
quant4_inter = quant4_inter_mmx; |
316 |
dequant4_inter = dequant4_inter_mmx; |
dequant4_inter = dequant4_inter_mmx; |
317 |
|
|
318 |
|
/* Block related functions */ |
319 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
320 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
321 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
322 |
|
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
323 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
324 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
325 |
|
|
326 |
|
/* Interlacing Functions */ |
327 |
|
MBFieldTest = MBFieldTest_mmx; |
328 |
|
|
329 |
|
/* Image Interpolation related functions */ |
330 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
331 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
332 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
333 |
|
|
334 |
rgb24_to_yv12 = rgb24_to_yv12_mmx; |
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_mmx; |
335 |
rgb32_to_yv12 = rgb32_to_yv12_mmx; |
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_mmx; |
336 |
yuv_to_yv12 = yuv_to_yv12_mmx; |
|
337 |
|
interpolate8x8_avg2 = interpolate8x8_avg2_mmx; |
338 |
|
interpolate8x8_avg4 = interpolate8x8_avg4_mmx; |
339 |
|
|
340 |
|
/* image input xxx_to_yv12 related functions */ |
341 |
|
yv12_to_yv12 = yv12_to_yv12_mmx; |
342 |
|
bgr_to_yv12 = bgr_to_yv12_mmx; |
343 |
|
bgra_to_yv12 = bgra_to_yv12_mmx; |
344 |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
345 |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
346 |
|
|
347 |
yv12_to_rgb24 = yv12_to_rgb24_mmx; |
/* image output yv12_to_xxx related functions */ |
348 |
yv12_to_rgb32 = yv12_to_rgb32_mmx; |
yv12_to_bgr = yv12_to_bgr_mmx; |
349 |
|
yv12_to_bgra = yv12_to_bgra_mmx; |
350 |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
351 |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
352 |
|
|
353 |
|
yv12_to_yuyvi = yv12_to_yuyvi_mmx; |
354 |
|
yv12_to_uyvyi = yv12_to_uyvyi_mmx; |
355 |
|
|
356 |
|
/* Motion estimation related functions */ |
357 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
358 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
359 |
sad8 = sad8_mmx; |
sad8 = sad8_mmx; |
360 |
|
sad16bi = sad16bi_mmx; |
361 |
|
sad8bi = sad8bi_mmx; |
362 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
363 |
|
sad16v = sad16v_mmx; |
364 |
|
|
365 |
|
} |
366 |
|
|
367 |
|
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
368 |
|
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
369 |
|
|
370 |
|
/* ME functions */ |
371 |
|
sad16bi = sad16bi_3dn; |
372 |
|
sad8bi = sad8bi_3dn; |
373 |
|
|
374 |
|
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
375 |
|
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
376 |
} |
} |
377 |
|
|
378 |
|
|
379 |
if((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
380 |
|
|
381 |
|
/* Inverse DCT */ |
382 |
idct = idct_xmm; |
idct = idct_xmm; |
383 |
|
|
384 |
|
/* Interpolation */ |
385 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
386 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
387 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
|
yuv_to_yv12 = yuv_to_yv12_xmm; |
|
388 |
|
|
389 |
|
/* Quantization */ |
390 |
|
dequant_intra = dequant_intra_xmm; |
391 |
|
dequant_inter = dequant_inter_xmm; |
392 |
|
|
393 |
|
/* Buffer transfer */ |
394 |
|
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
395 |
|
|
396 |
|
/* Colorspace transformation */ |
397 |
|
yv12_to_yv12 = yv12_to_yv12_xmm; |
398 |
|
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
399 |
|
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
400 |
|
|
401 |
|
/* ME functions */ |
402 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
403 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
404 |
|
sad16bi = sad16bi_xmm; |
405 |
|
sad8bi = sad8bi_xmm; |
406 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
407 |
|
sad16v = sad16v_xmm; |
408 |
} |
} |
409 |
|
|
410 |
if((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if((cpu_flags & XVID_CPU_3DNOW) > 0) { |
411 |
|
|
412 |
|
/* Interpolation */ |
413 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
414 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; |
415 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
416 |
} |
} |
417 |
|
|
418 |
|
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
419 |
|
#ifdef EXPERIMENTAL_SSE2_CODE |
420 |
|
|
421 |
|
calc_cbp = calc_cbp_sse2; |
422 |
|
|
423 |
|
/* Quantization */ |
424 |
|
quant_intra = quant_intra_sse2; |
425 |
|
dequant_intra = dequant_intra_sse2; |
426 |
|
quant_inter = quant_inter_sse2; |
427 |
|
dequant_inter = dequant_inter_sse2; |
428 |
|
|
429 |
|
/* ME */ |
430 |
|
sad16 = sad16_sse2; |
431 |
|
dev16 = dev16_sse2; |
432 |
|
|
433 |
|
/* Forward and Inverse DCT */ |
434 |
|
idct = idct_sse2; |
435 |
|
fdct = fdct_sse2; |
436 |
|
#endif |
437 |
|
} |
438 |
|
|
439 |
|
#endif |
440 |
|
|
441 |
|
#ifdef ARCH_IA64 |
442 |
|
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
443 |
|
idct_ia64_init(); |
444 |
|
fdct = fdct_ia64; |
445 |
|
idct = idct_ia64; //not yet working, crashes |
446 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
447 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
448 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
449 |
|
sad16 = sad16_ia64; |
450 |
|
sad16bi = sad16bi_ia64; |
451 |
|
sad8 = sad8_ia64; |
452 |
|
dev16 = dev16_ia64; |
453 |
|
// Halfpel8_Refine = Halfpel8_Refine_ia64; |
454 |
|
quant_intra = quant_intra_ia64; |
455 |
|
dequant_intra = dequant_intra_ia64; |
456 |
|
quant_inter = quant_inter_ia64; |
457 |
|
dequant_inter = dequant_inter_ia64; |
458 |
|
transfer_8to16copy = transfer_8to16copy_ia64; |
459 |
|
transfer_16to8copy = transfer_16to8copy_ia64; |
460 |
|
transfer_8to16sub = transfer_8to16sub_ia64; |
461 |
|
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
462 |
|
transfer_16to8add = transfer_16to8add_ia64; |
463 |
|
transfer8x8_copy = transfer8x8_copy_ia64; |
464 |
|
DEBUG("Using IA-64 assembler routines.\n"); |
465 |
|
} |
466 |
#endif |
#endif |
467 |
|
|
468 |
#ifdef ARCH_PPC |
#ifdef ARCH_PPC |
469 |
#ifdef ARCH_PPC_ALTIVEC |
#ifdef ARCH_PPC_ALTIVEC |
470 |
calc_cbp = calc_cbp_altivec; |
calc_cbp = calc_cbp_altivec; |
471 |
|
fdct = fdct_altivec; |
472 |
|
idct = idct_altivec; |
473 |
|
sadInit = sadInit_altivec; |
474 |
|
sad16 = sad16_altivec; |
475 |
|
sad8 = sad8_altivec; |
476 |
|
dev16 = dev16_altivec; |
477 |
#else |
#else |
478 |
calc_cbp = calc_cbp_ppc; |
calc_cbp = calc_cbp_ppc; |
479 |
#endif |
#endif |
480 |
#endif |
#endif |
481 |
|
|
482 |
// API version |
return XVID_ERR_OK; |
483 |
init_param->api_version = API_VERSION; |
} |
484 |
|
|
|
// something clever has to be done for this |
|
|
init_param->core_build = 1000; |
|
485 |
|
|
486 |
|
|
487 |
|
static int |
488 |
|
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
489 |
|
{ |
490 |
|
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
491 |
|
const int width = convert->width; |
492 |
|
const int height = convert->height; |
493 |
|
const int width2 = convert->width/2; |
494 |
|
const int height2 = convert->height/2; |
495 |
|
IMAGE img; |
496 |
|
|
497 |
|
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
498 |
|
{ |
499 |
|
case XVID_CSP_YV12 : |
500 |
|
img.y = convert->input.y; |
501 |
|
img.v = (uint8_t*)convert->input.y + width*height; |
502 |
|
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
503 |
|
image_output(&img, width, height, width, |
504 |
|
convert->output.y, convert->output.y_stride, |
505 |
|
convert->output.colorspace, convert->interlacing); |
506 |
|
break; |
507 |
|
|
508 |
|
default : |
509 |
|
return XVID_ERR_FORMAT; |
510 |
|
} |
511 |
|
|
512 |
|
|
513 |
|
emms(); |
514 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
515 |
} |
} |
516 |
|
|
517 |
int xvid_decore(void * handle, int opt, void * param1, void * param2) |
|
518 |
|
int |
519 |
|
xvid_init(void *handle, |
520 |
|
int opt, |
521 |
|
void *param1, |
522 |
|
void *param2) |
523 |
{ |
{ |
524 |
switch (opt) |
switch (opt) |
525 |
{ |
{ |
526 |
|
case XVID_INIT_INIT : |
527 |
|
return xvid_init_init((XVID_INIT_PARAM*)param1); |
528 |
|
|
529 |
|
case XVID_INIT_CONVERT : |
530 |
|
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
531 |
|
|
532 |
|
default : |
533 |
|
return XVID_ERR_FAIL; |
534 |
|
} |
535 |
|
} |
536 |
|
|
537 |
|
/***************************************************************************** |
538 |
|
* XviD Native decoder entry point |
539 |
|
* |
540 |
|
* This function is just a wrapper to all the option cases. |
541 |
|
* |
542 |
|
* Returned values : XVID_ERR_FAIL when opt is invalid |
543 |
|
* else returns the wrapped function result |
544 |
|
* |
545 |
|
****************************************************************************/ |
546 |
|
|
547 |
|
int |
548 |
|
xvid_decore(void *handle, |
549 |
|
int opt, |
550 |
|
void *param1, |
551 |
|
void *param2) |
552 |
|
{ |
553 |
|
switch (opt) { |
554 |
case XVID_DEC_DECODE : |
case XVID_DEC_DECODE : |
555 |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
556 |
|
|
557 |
case XVID_DEC_CREATE : |
case XVID_DEC_CREATE : |
558 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((XVID_DEC_PARAM *) param1); |
566 |
} |
} |
567 |
|
|
568 |
|
|
569 |
int xvid_encore(void * handle, int opt, void * param1, void * param2) |
/***************************************************************************** |
570 |
{ |
* XviD Native encoder entry point |
571 |
switch (opt) |
* |
572 |
|
* This function is just a wrapper to all the option cases. |
573 |
|
* |
574 |
|
* Returned values : XVID_ERR_FAIL when opt is invalid |
575 |
|
* else returns the wrapped function result |
576 |
|
* |
577 |
|
****************************************************************************/ |
578 |
|
|
579 |
|
int |
580 |
|
xvid_encore(void *handle, |
581 |
|
int opt, |
582 |
|
void *param1, |
583 |
|
void *param2) |
584 |
{ |
{ |
585 |
|
switch (opt) { |
586 |
case XVID_ENC_ENCODE : |
case XVID_ENC_ENCODE : |
587 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, (XVID_ENC_STATS *) param2); |
|
588 |
|
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
589 |
|
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
590 |
|
(XVID_ENC_STATS *) param2); |
591 |
|
else |
592 |
|
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
593 |
|
(XVID_ENC_STATS *) param2); |
594 |
|
|
595 |
case XVID_ENC_CREATE : |
case XVID_ENC_CREATE : |
596 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return encoder_create((XVID_ENC_PARAM *) param1); |