1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* native api |
* - Native API implementation - |
|
* |
|
|
* This program is an implementation of a part of one or more MPEG-4 |
|
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
5 |
* |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
* |
|
|
*************************************************************************/ |
|
|
|
|
|
/************************************************************************** |
|
|
* |
|
|
* History: |
|
19 |
* |
* |
20 |
* 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
* $Id: xvid.c,v 1.45.2.2 2003-03-26 11:01:03 suxen_drol Exp $ |
|
* 22.12.2001 API change: added xvid_init() - Isibaar |
|
|
* 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
21 |
* |
* |
22 |
*************************************************************************/ |
****************************************************************************/ |
23 |
|
|
24 |
|
#include <stdio.h> |
25 |
|
#include <stdlib.h> |
26 |
|
#include <string.h> |
27 |
|
#include <time.h> |
28 |
|
|
29 |
#include "xvid.h" |
#include "xvid.h" |
30 |
#include "decoder.h" |
#include "decoder.h" |
34 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
35 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
36 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
37 |
|
#include "image/reduced.h" |
38 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
39 |
|
#include "utils/mbfunctions.h" |
40 |
#include "quant/quant_h263.h" |
#include "quant/quant_h263.h" |
41 |
#include "quant/quant_mpeg4.h" |
#include "quant/quant_mpeg4.h" |
42 |
|
#include "motion/motion.h" |
43 |
#include "motion/sad.h" |
#include "motion/sad.h" |
44 |
#include "utils/emms.h" |
#include "utils/emms.h" |
45 |
#include "utils/timer.h" |
#include "utils/timer.h" |
46 |
|
#include "bitstream/mbcoding.h" |
47 |
|
|
48 |
|
#if defined(ARCH_IS_IA32) |
49 |
|
|
50 |
|
#if defined(_MSC_VER) |
51 |
|
# include <windows.h> |
52 |
|
#else |
53 |
|
# include <signal.h> |
54 |
|
# include <setjmp.h> |
55 |
|
|
56 |
|
static jmp_buf mark; |
57 |
|
|
58 |
int xvid_init(void *handle, int opt, void *param1, void *param2) |
static void |
59 |
|
sigill_handler(int signal) |
60 |
{ |
{ |
61 |
int cpu_flags; |
longjmp(mark, 1); |
62 |
XVID_INIT_PARAM *init_param; |
} |
63 |
|
#endif |
64 |
|
|
65 |
|
|
66 |
init_param = (XVID_INIT_PARAM *) param1; |
/* |
67 |
|
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
68 |
|
* signalled |
69 |
|
* |
70 |
|
* Return values: |
71 |
|
* -1 : could not determine |
72 |
|
* 0 : SIGILL was *not* signalled |
73 |
|
* 1 : SIGILL was signalled |
74 |
|
*/ |
75 |
|
|
76 |
// force specific cpu settings? |
int |
77 |
if((init_param->cpu_flags & XVID_CPU_FORCE) > 0) |
sigill_check(void (*func)()) |
78 |
cpu_flags = init_param->cpu_flags; |
{ |
79 |
else { |
#if defined(_MSC_VER) |
80 |
|
_try { |
81 |
|
func(); |
82 |
|
} |
83 |
|
_except(EXCEPTION_EXECUTE_HANDLER) { |
84 |
|
|
85 |
#ifdef ARCH_X86 |
if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION) |
86 |
cpu_flags = check_cpu_features(); |
return 1; |
87 |
|
} |
88 |
|
return 0; |
89 |
#else |
#else |
90 |
cpu_flags = 0; |
void * old_handler; |
91 |
|
int jmpret; |
92 |
|
|
93 |
|
|
94 |
|
old_handler = signal(SIGILL, sigill_handler); |
95 |
|
if (old_handler == SIG_ERR) |
96 |
|
{ |
97 |
|
return -1; |
98 |
|
} |
99 |
|
|
100 |
|
jmpret = setjmp(mark); |
101 |
|
if (jmpret == 0) |
102 |
|
{ |
103 |
|
func(); |
104 |
|
} |
105 |
|
|
106 |
|
signal(SIGILL, old_handler); |
107 |
|
|
108 |
|
return jmpret; |
109 |
#endif |
#endif |
|
init_param->cpu_flags = cpu_flags; |
|
110 |
} |
} |
111 |
|
#endif |
112 |
|
|
113 |
|
|
114 |
|
/* detect cpu flags */ |
115 |
|
static unsigned int |
116 |
|
detect_cpu_flags() |
117 |
|
{ |
118 |
|
/* enable native assembly optimizations by default */ |
119 |
|
unsigned int cpu_flags = XVID_CPU_ASM; |
120 |
|
|
121 |
|
#if defined(ARCH_IS_IA32) |
122 |
|
cpu_flags |= check_cpu_features(); |
123 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
124 |
|
cpu_flags &= ~XVID_CPU_SSE; |
125 |
|
|
126 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
127 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
128 |
|
#endif |
129 |
|
|
130 |
// initialize the function pointers |
#if defined(ARCH_IS_PPC) |
131 |
|
#if defined(ARCH_IS_PPC_ALTIVEC) |
132 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
133 |
|
#endif |
134 |
|
#endif |
135 |
|
|
136 |
|
return cpu_flags; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
/***************************************************************************** |
141 |
|
* XviD Init Entry point |
142 |
|
* |
143 |
|
* Well this function initialize all internal function pointers according |
144 |
|
* to the CPU features forced by the library client or autodetected (depending |
145 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
146 |
|
* image colorspace transformation tables. |
147 |
|
* |
148 |
|
* Returned value : XVID_ERR_OK |
149 |
|
* + API_VERSION in the input XVID_INIT_PARAM structure |
150 |
|
* + core build " " " " " |
151 |
|
* |
152 |
|
****************************************************************************/ |
153 |
|
|
154 |
|
|
155 |
|
static |
156 |
|
int xvid_gbl_init(xvid_gbl_init_t * init) |
157 |
|
{ |
158 |
|
unsigned int cpu_flags; |
159 |
|
|
160 |
|
if (XVID_MAJOR(init->version) != 1) /* v1.x.x */ |
161 |
|
return XVID_ERR_VERSION; |
162 |
|
|
163 |
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
164 |
|
|
165 |
|
/* Initialize the function pointers */ |
166 |
idct_int32_init(); |
idct_int32_init(); |
167 |
|
init_vlc_tables(); |
168 |
|
|
169 |
|
/* Fixed Point Forward/Inverse DCT transformations */ |
170 |
fdct = fdct_int32; |
fdct = fdct_int32; |
171 |
idct = idct_int32; |
idct = idct_int32; |
172 |
|
|
173 |
|
/* Only needed on PPC Altivec archs */ |
174 |
|
sadInit = 0; |
175 |
|
|
176 |
|
/* Restore FPU context : emms_c is a nop functions */ |
177 |
emms = emms_c; |
emms = emms_c; |
178 |
|
|
179 |
|
/* Quantization functions */ |
180 |
quant_intra = quant_intra_c; |
quant_intra = quant_intra_c; |
181 |
dequant_intra = dequant_intra_c; |
dequant_intra = dequant_intra_c; |
182 |
quant_inter = quant_inter_c; |
quant_inter = quant_inter_c; |
187 |
quant4_inter = quant4_inter_c; |
quant4_inter = quant4_inter_c; |
188 |
dequant4_inter = dequant4_inter_c; |
dequant4_inter = dequant4_inter_c; |
189 |
|
|
190 |
|
/* Block transfer related functions */ |
191 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
192 |
transfer_16to8copy = transfer_16to8copy_c; |
transfer_16to8copy = transfer_16to8copy_c; |
193 |
transfer_8to16sub = transfer_8to16sub_c; |
transfer_8to16sub = transfer_8to16sub_c; |
194 |
|
transfer_8to16subro = transfer_8to16subro_c; |
195 |
|
transfer_8to16sub2 = transfer_8to16sub2_c; |
196 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
197 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
198 |
|
|
199 |
|
/* Interlacing functions */ |
200 |
|
MBFieldTest = MBFieldTest_c; |
201 |
|
|
202 |
|
/* Image interpolation related functions */ |
203 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
204 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
205 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
206 |
|
|
207 |
|
interpolate16x16_lowpass_h = interpolate16x16_lowpass_h_c; |
208 |
|
interpolate16x16_lowpass_v = interpolate16x16_lowpass_v_c; |
209 |
|
interpolate16x16_lowpass_hv = interpolate16x16_lowpass_hv_c; |
210 |
|
|
211 |
|
interpolate8x8_lowpass_h = interpolate8x8_lowpass_h_c; |
212 |
|
interpolate8x8_lowpass_v = interpolate8x8_lowpass_v_c; |
213 |
|
interpolate8x8_lowpass_hv = interpolate8x8_lowpass_hv_c; |
214 |
|
|
215 |
|
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_c; |
216 |
|
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_c; |
217 |
|
|
218 |
|
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
219 |
|
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
220 |
|
|
221 |
|
/* reduced resoltuion */ |
222 |
|
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
223 |
|
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
224 |
|
vfilter_31 = xvid_VFilter_31_C; |
225 |
|
hfilter_31 = xvid_HFilter_31_C; |
226 |
|
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
227 |
|
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
228 |
|
|
229 |
|
/* Initialize internal colorspace transformation tables */ |
230 |
colorspace_init(); |
colorspace_init(); |
231 |
|
|
232 |
|
/* All colorspace transformation functions User Format->YV12 */ |
233 |
|
yv12_to_yv12 = yv12_to_yv12_c; |
234 |
rgb555_to_yv12 = rgb555_to_yv12_c; |
rgb555_to_yv12 = rgb555_to_yv12_c; |
235 |
rgb565_to_yv12 = rgb565_to_yv12_c; |
rgb565_to_yv12 = rgb565_to_yv12_c; |
236 |
rgb24_to_yv12 = rgb24_to_yv12_c; |
bgr_to_yv12 = bgr_to_yv12_c; |
237 |
rgb32_to_yv12 = rgb32_to_yv12_c; |
bgra_to_yv12 = bgra_to_yv12_c; |
238 |
yuv_to_yv12 = yuv_to_yv12_c; |
abgr_to_yv12 = abgr_to_yv12_c; |
239 |
|
rgba_to_yv12 = rgba_to_yv12_c; |
240 |
yuyv_to_yv12 = yuyv_to_yv12_c; |
yuyv_to_yv12 = yuyv_to_yv12_c; |
241 |
uyvy_to_yv12 = uyvy_to_yv12_c; |
uyvy_to_yv12 = uyvy_to_yv12_c; |
242 |
|
|
243 |
|
rgb555i_to_yv12 = rgb555i_to_yv12_c; |
244 |
|
rgb565i_to_yv12 = rgb565i_to_yv12_c; |
245 |
|
bgri_to_yv12 = bgri_to_yv12_c; |
246 |
|
bgrai_to_yv12 = bgrai_to_yv12_c; |
247 |
|
abgri_to_yv12 = abgri_to_yv12_c; |
248 |
|
rgbai_to_yv12 = rgbai_to_yv12_c; |
249 |
|
yuyvi_to_yv12 = yuyvi_to_yv12_c; |
250 |
|
uyvyi_to_yv12 = uyvyi_to_yv12_c; |
251 |
|
|
252 |
|
|
253 |
|
/* All colorspace transformation functions YV12->User format */ |
254 |
yv12_to_rgb555 = yv12_to_rgb555_c; |
yv12_to_rgb555 = yv12_to_rgb555_c; |
255 |
yv12_to_rgb565 = yv12_to_rgb565_c; |
yv12_to_rgb565 = yv12_to_rgb565_c; |
256 |
yv12_to_rgb24 = yv12_to_rgb24_c; |
yv12_to_bgr = yv12_to_bgr_c; |
257 |
yv12_to_rgb32 = yv12_to_rgb32_c; |
yv12_to_bgra = yv12_to_bgra_c; |
258 |
yv12_to_yuv = yv12_to_yuv_c; |
yv12_to_abgr = yv12_to_abgr_c; |
259 |
|
yv12_to_rgba = yv12_to_rgba_c; |
260 |
yv12_to_yuyv = yv12_to_yuyv_c; |
yv12_to_yuyv = yv12_to_yuyv_c; |
261 |
yv12_to_uyvy = yv12_to_uyvy_c; |
yv12_to_uyvy = yv12_to_uyvy_c; |
262 |
|
|
263 |
|
yv12_to_rgb555i = yv12_to_rgb555i_c; |
264 |
|
yv12_to_rgb565i = yv12_to_rgb565i_c; |
265 |
|
yv12_to_bgri = yv12_to_bgri_c; |
266 |
|
yv12_to_bgrai = yv12_to_bgrai_c; |
267 |
|
yv12_to_abgri = yv12_to_abgri_c; |
268 |
|
yv12_to_rgbai = yv12_to_rgbai_c; |
269 |
|
yv12_to_yuyvi = yv12_to_yuyvi_c; |
270 |
|
yv12_to_uyvyi = yv12_to_uyvyi_c; |
271 |
|
|
272 |
|
/* Functions used in motion estimation algorithms */ |
273 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
274 |
sad16 = sad16_c; |
sad16 = sad16_c; |
275 |
sad8 = sad8_c; |
sad8 = sad8_c; |
276 |
|
sad16bi = sad16bi_c; |
277 |
|
sad8bi = sad8bi_c; |
278 |
dev16 = dev16_c; |
dev16 = dev16_c; |
279 |
|
sad16v = sad16v_c; |
280 |
|
|
281 |
#ifdef ARCH_X86 |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
282 |
if((cpu_flags & XVID_CPU_MMX) > 0) { |
|
283 |
fdct = fdct_mmx; |
#if defined(ARCH_IS_IA32) |
|
idct = idct_mmx; |
|
284 |
|
|
285 |
|
if ((cpu_flags & XVID_CPU_ASM)) |
286 |
|
{ |
287 |
|
vfilter_31 = xvid_VFilter_31_x86; |
288 |
|
hfilter_31 = xvid_HFilter_31_x86; |
289 |
|
} |
290 |
|
|
291 |
|
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
292 |
|
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
293 |
|
(cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2)) |
294 |
|
{ |
295 |
|
/* Restore FPU context : emms_c is a nop functions */ |
296 |
emms = emms_mmx; |
emms = emms_mmx; |
297 |
|
} |
298 |
|
|
299 |
|
if ((cpu_flags & XVID_CPU_MMX)) { |
300 |
|
|
301 |
|
/* Forward and Inverse Discrete Cosine Transformation functions */ |
302 |
|
fdct = fdct_mmx; |
303 |
|
idct = idct_mmx; |
304 |
|
|
305 |
|
/* Quantization related functions */ |
306 |
quant_intra = quant_intra_mmx; |
quant_intra = quant_intra_mmx; |
307 |
dequant_intra = dequant_intra_mmx; |
dequant_intra = dequant_intra_mmx; |
308 |
quant_inter = quant_inter_mmx; |
quant_inter = quant_inter_mmx; |
313 |
quant4_inter = quant4_inter_mmx; |
quant4_inter = quant4_inter_mmx; |
314 |
dequant4_inter = dequant4_inter_mmx; |
dequant4_inter = dequant4_inter_mmx; |
315 |
|
|
316 |
|
/* Block related functions */ |
317 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
318 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
319 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
320 |
|
transfer_8to16subro = transfer_8to16subro_mmx; |
321 |
|
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
322 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
323 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
324 |
|
|
325 |
|
/* Interlacing Functions */ |
326 |
|
MBFieldTest = MBFieldTest_mmx; |
327 |
|
|
328 |
|
/* Image Interpolation related functions */ |
329 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
330 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
331 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
332 |
|
|
333 |
rgb24_to_yv12 = rgb24_to_yv12_mmx; |
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_mmx; |
334 |
rgb32_to_yv12 = rgb32_to_yv12_mmx; |
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_mmx; |
335 |
yuv_to_yv12 = yuv_to_yv12_mmx; |
|
336 |
|
interpolate8x8_avg2 = interpolate8x8_avg2_mmx; |
337 |
|
interpolate8x8_avg4 = interpolate8x8_avg4_mmx; |
338 |
|
|
339 |
|
/* reduced resolution */ |
340 |
|
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_mmx; |
341 |
|
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_mmx; |
342 |
|
hfilter_31 = xvid_HFilter_31_mmx; |
343 |
|
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_mmx; |
344 |
|
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_mmx; |
345 |
|
|
346 |
|
/* image input xxx_to_yv12 related functions */ |
347 |
|
yv12_to_yv12 = yv12_to_yv12_mmx; |
348 |
|
bgr_to_yv12 = bgr_to_yv12_mmx; |
349 |
|
bgra_to_yv12 = bgra_to_yv12_mmx; |
350 |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
351 |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
352 |
|
|
353 |
yv12_to_rgb24 = yv12_to_rgb24_mmx; |
/* image output yv12_to_xxx related functions */ |
354 |
yv12_to_rgb32 = yv12_to_rgb32_mmx; |
yv12_to_bgr = yv12_to_bgr_mmx; |
355 |
|
yv12_to_bgra = yv12_to_bgra_mmx; |
356 |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
357 |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
358 |
|
|
359 |
|
yv12_to_yuyvi = yv12_to_yuyvi_mmx; |
360 |
|
yv12_to_uyvyi = yv12_to_uyvyi_mmx; |
361 |
|
|
362 |
|
/* Motion estimation related functions */ |
363 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
364 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
365 |
sad8 = sad8_mmx; |
sad8 = sad8_mmx; |
366 |
|
sad16bi = sad16bi_mmx; |
367 |
|
sad8bi = sad8bi_mmx; |
368 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
369 |
|
sad16v = sad16v_mmx; |
370 |
|
} |
371 |
|
|
372 |
|
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
373 |
|
if ((cpu_flags & XVID_CPU_3DNOW)) { |
374 |
|
|
375 |
|
emms = emms_3dn; |
376 |
|
|
377 |
|
/* ME functions */ |
378 |
|
sad16bi = sad16bi_3dn; |
379 |
|
sad8bi = sad8bi_3dn; |
380 |
|
|
381 |
|
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
382 |
|
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
383 |
} |
} |
384 |
|
|
385 |
if((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
|
386 |
|
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
387 |
|
|
388 |
|
/* Inverse DCT */ |
389 |
idct = idct_xmm; |
idct = idct_xmm; |
390 |
|
|
391 |
|
/* Interpolation */ |
392 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
393 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
394 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
|
yuv_to_yv12 = yuv_to_yv12_xmm; |
|
395 |
|
|
396 |
|
/* reduced resolution */ |
397 |
|
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_xmm; |
398 |
|
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
399 |
|
|
400 |
|
/* Quantization */ |
401 |
|
quant4_intra = quant4_intra_xmm; |
402 |
|
quant4_inter = quant4_inter_xmm; |
403 |
|
|
404 |
|
dequant_intra = dequant_intra_xmm; |
405 |
|
dequant_inter = dequant_inter_xmm; |
406 |
|
|
407 |
|
/* Buffer transfer */ |
408 |
|
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
409 |
|
|
410 |
|
/* Colorspace transformation */ |
411 |
|
yv12_to_yv12 = yv12_to_yv12_xmm; |
412 |
|
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
413 |
|
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
414 |
|
|
415 |
|
/* ME functions */ |
416 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
417 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
418 |
|
sad16bi = sad16bi_xmm; |
419 |
|
sad8bi = sad8bi_xmm; |
420 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
421 |
|
sad16v = sad16v_xmm; |
422 |
} |
} |
423 |
|
|
424 |
if((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
425 |
|
|
426 |
|
/* Interpolation */ |
427 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
428 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; |
429 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
430 |
} |
} |
431 |
|
|
432 |
|
if ((cpu_flags & XVID_CPU_3DNOWEXT)) { |
433 |
|
|
434 |
|
/* Inverse DCT */ |
435 |
|
idct = idct_3dne; |
436 |
|
|
437 |
|
/* Buffer transfer */ |
438 |
|
transfer_8to16copy = transfer_8to16copy_3dne; |
439 |
|
transfer_16to8copy = transfer_16to8copy_3dne; |
440 |
|
transfer_8to16sub = transfer_8to16sub_3dne; |
441 |
|
transfer_8to16subro = transfer_8to16subro_3dne; |
442 |
|
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
443 |
|
transfer_16to8add = transfer_16to8add_3dne; |
444 |
|
transfer8x8_copy = transfer8x8_copy_3dne; |
445 |
|
|
446 |
|
/* Quantization */ |
447 |
|
dequant4_intra = dequant4_intra_3dne; |
448 |
|
dequant4_inter = dequant4_inter_3dne; |
449 |
|
quant_intra = quant_intra_3dne; |
450 |
|
quant_inter = quant_inter_3dne; |
451 |
|
dequant_intra = dequant_intra_3dne; |
452 |
|
dequant_inter = dequant_inter_3dne; |
453 |
|
|
454 |
|
/* ME functions */ |
455 |
|
calc_cbp = calc_cbp_3dne; |
456 |
|
sad16 = sad16_3dne; |
457 |
|
sad8 = sad8_3dne; |
458 |
|
sad16bi = sad16bi_3dne; |
459 |
|
sad8bi = sad8bi_3dne; |
460 |
|
dev16 = dev16_3dne; |
461 |
|
|
462 |
|
/* Interpolation */ |
463 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dne; |
464 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dne; |
465 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
|
if ((cpu_flags & XVID_CPU_SSE2)) { |
470 |
|
|
471 |
|
calc_cbp = calc_cbp_sse2; |
472 |
|
|
473 |
|
/* Quantization */ |
474 |
|
quant_intra = quant_intra_sse2; |
475 |
|
dequant_intra = dequant_intra_sse2; |
476 |
|
quant_inter = quant_inter_sse2; |
477 |
|
dequant_inter = dequant_inter_sse2; |
478 |
|
|
479 |
|
#if defined(EXPERIMENTAL_SSE2_CODE) |
480 |
|
/* ME; slower than xmm */ |
481 |
|
sad16 = sad16_sse2; |
482 |
|
dev16 = dev16_sse2; |
483 |
|
#endif |
484 |
|
/* Forward and Inverse DCT */ |
485 |
|
idct = idct_sse2; |
486 |
|
fdct = fdct_sse2; |
487 |
|
} |
488 |
|
#endif |
489 |
|
|
490 |
|
#if defined(ARCH_IS_IA64) |
491 |
|
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
492 |
|
idct_ia64_init(); |
493 |
|
fdct = fdct_ia64; |
494 |
|
idct = idct_ia64; /*not yet working, crashes */ |
495 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
496 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
497 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
498 |
|
sad16 = sad16_ia64; |
499 |
|
sad16bi = sad16bi_ia64; |
500 |
|
sad8 = sad8_ia64; |
501 |
|
dev16 = dev16_ia64; |
502 |
|
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
503 |
|
quant_intra = quant_intra_ia64; |
504 |
|
dequant_intra = dequant_intra_ia64; |
505 |
|
quant_inter = quant_inter_ia64; |
506 |
|
dequant_inter = dequant_inter_ia64; |
507 |
|
transfer_8to16copy = transfer_8to16copy_ia64; |
508 |
|
transfer_16to8copy = transfer_16to8copy_ia64; |
509 |
|
transfer_8to16sub = transfer_8to16sub_ia64; |
510 |
|
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
511 |
|
transfer_16to8add = transfer_16to8add_ia64; |
512 |
|
transfer8x8_copy = transfer8x8_copy_ia64; |
513 |
|
DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines."); |
514 |
|
} |
515 |
#endif |
#endif |
516 |
#ifdef ARCH_PPC |
|
517 |
|
#if defined(ARCH_IS_PPC) |
518 |
|
if ((cpu_flags & XVID_CPU_ASM)) |
519 |
|
{ |
520 |
calc_cbp = calc_cbp_ppc; |
calc_cbp = calc_cbp_ppc; |
521 |
|
} |
522 |
|
|
523 |
|
if ((cpu_flags & XVID_CPU_ALTIVEC)) |
524 |
|
{ |
525 |
|
calc_cbp = calc_cbp_altivec; |
526 |
|
fdct = fdct_altivec; |
527 |
|
idct = idct_altivec; |
528 |
|
sadInit = sadInit_altivec; |
529 |
|
sad16 = sad16_altivec; |
530 |
|
sad8 = sad8_altivec; |
531 |
|
dev16 = dev16_altivec; |
532 |
|
} |
533 |
|
#endif |
534 |
|
|
535 |
|
return 0; |
536 |
|
} |
537 |
|
|
538 |
|
|
539 |
|
static int |
540 |
|
xvid_gbl_info(xvid_gbl_info_t * info) |
541 |
|
{ |
542 |
|
if (XVID_MAJOR(info->version) != 1) /* v1.x.x */ |
543 |
|
return XVID_ERR_VERSION; |
544 |
|
|
545 |
|
info->actual_version = XVID_VERSION; |
546 |
|
info->build = "dev-api-4"; |
547 |
|
info->cpu_flags = detect_cpu_flags(); |
548 |
|
|
549 |
|
#if defined(_SMP) && defined(WIN32) |
550 |
|
info->num_threads = pthread_num_processors_np();; |
551 |
|
#else |
552 |
|
info->num_threads = 0; |
553 |
|
#endif |
554 |
|
|
555 |
|
return 0; |
556 |
|
} |
557 |
|
|
558 |
|
|
559 |
|
static int |
560 |
|
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
561 |
|
{ |
562 |
|
int width; |
563 |
|
int height; |
564 |
|
int width2; |
565 |
|
int height2; |
566 |
|
IMAGE img; |
567 |
|
|
568 |
|
if (XVID_MAJOR(convert->version) != 1) /* v1.x.x */ |
569 |
|
return XVID_ERR_VERSION; |
570 |
|
|
571 |
|
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
572 |
|
width = convert->width; |
573 |
|
height = convert->height; |
574 |
|
width2 = convert->width/2; |
575 |
|
height2 = convert->height/2; |
576 |
|
|
577 |
|
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
578 |
|
{ |
579 |
|
case XVID_CSP_YV12 : |
580 |
|
img.y = convert->input.plane[0]; |
581 |
|
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
582 |
|
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; |
583 |
|
image_output(&img, width, height, width, |
584 |
|
(uint8_t**)convert->output.plane, convert->output.stride, |
585 |
|
convert->output.csp, convert->interlacing); |
586 |
|
break; |
587 |
|
|
588 |
|
default : |
589 |
|
return XVID_ERR_FORMAT; |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
|
emms(); |
594 |
|
return 0; |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
|
|
599 |
|
void fill8(uint8_t * block, int size, int value) |
600 |
|
{ |
601 |
|
int i; |
602 |
|
for (i = 0; i < size; i++) |
603 |
|
block[i] = value; |
604 |
|
} |
605 |
|
|
606 |
|
void fill16(int16_t * block, int size, int value) |
607 |
|
{ |
608 |
|
int i; |
609 |
|
for (i = 0; i < size; i++) |
610 |
|
block[i] = value; |
611 |
|
} |
612 |
|
|
613 |
|
#define RANDOM(min,max) min + (rand() % (max-min)) |
614 |
|
|
615 |
|
void random8(uint8_t * block, int size, int min, int max) |
616 |
|
{ |
617 |
|
int i; |
618 |
|
for (i = 0; i < size; i++) |
619 |
|
block[i] = RANDOM(min,max); |
620 |
|
} |
621 |
|
|
622 |
|
void random16(int16_t * block, int size, int min, int max) |
623 |
|
{ |
624 |
|
int i; |
625 |
|
for (i = 0; i < size; i++) |
626 |
|
block[i] = RANDOM(min,max); |
627 |
|
} |
628 |
|
|
629 |
|
int compare16(const int16_t * blockA, const int16_t * blockB, int size) |
630 |
|
{ |
631 |
|
int i; |
632 |
|
for (i = 0; i < size; i++) |
633 |
|
if (blockA[i] != blockB[i]) |
634 |
|
return 1; |
635 |
|
|
636 |
|
return 0; |
637 |
|
} |
638 |
|
|
639 |
|
int diff16(const int16_t * blockA, const int16_t * blockB, int size) |
640 |
|
{ |
641 |
|
int i, diff = 0; |
642 |
|
for (i = 0; i < size; i++) |
643 |
|
diff += ABS(blockA[i]-blockB[i]); |
644 |
|
return diff; |
645 |
|
} |
646 |
|
|
647 |
|
|
648 |
|
#define XVID_TEST_RANDOM 0x00000001 /* random input data */ |
649 |
|
#define XVID_TEST_VERBOSE 0x00000002 /* verbose error output */ |
650 |
|
|
651 |
|
|
652 |
|
#define TEST_FORWARD 0x00000001 /* intra */ |
653 |
|
#define TEST_FDCT (TEST_FORWARD) |
654 |
|
#define TEST_IDCT (0) |
655 |
|
|
656 |
|
static int test_transform(void * funcA, void * funcB, const char * nameB, |
657 |
|
int test, int flags) |
658 |
|
{ |
659 |
|
int i; |
660 |
|
int64_t timeSTART; |
661 |
|
int64_t timeA = 0; |
662 |
|
int64_t timeB = 0; |
663 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
664 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
665 |
|
int min, max; |
666 |
|
int count = 0; |
667 |
|
|
668 |
|
int tmp; |
669 |
|
int min_error = 0x10000*64; |
670 |
|
int max_error = 0; |
671 |
|
|
672 |
|
|
673 |
|
if ((test & TEST_FORWARD)) /* forward */ |
674 |
|
{ |
675 |
|
min = -256; |
676 |
|
max = 255; |
677 |
|
}else{ /* inverse */ |
678 |
|
min = -2048; |
679 |
|
max = 2047; |
680 |
|
} |
681 |
|
|
682 |
|
for (i = 0; i < 64*64; i++) |
683 |
|
{ |
684 |
|
if ((flags & XVID_TEST_RANDOM)) |
685 |
|
{ |
686 |
|
random16(arrayA, 64, min, max); |
687 |
|
}else{ |
688 |
|
fill16(arrayA, 64, i); |
689 |
|
} |
690 |
|
memcpy(arrayB, arrayA, 64*sizeof(int16_t)); |
691 |
|
|
692 |
|
if ((test & TEST_FORWARD)) |
693 |
|
{ |
694 |
|
timeSTART = read_counter(); |
695 |
|
((fdctFunc*)funcA)(arrayA); |
696 |
|
timeA += read_counter() - timeSTART; |
697 |
|
|
698 |
|
timeSTART = read_counter(); |
699 |
|
((fdctFunc*)funcB)(arrayB); |
700 |
|
timeB += read_counter() - timeSTART; |
701 |
|
} |
702 |
|
else |
703 |
|
{ |
704 |
|
timeSTART = read_counter(); |
705 |
|
((idctFunc*)funcA)(arrayA); |
706 |
|
timeA += read_counter() - timeSTART; |
707 |
|
|
708 |
|
timeSTART = read_counter(); |
709 |
|
((idctFunc*)funcB)(arrayB); |
710 |
|
timeB += read_counter() - timeSTART; |
711 |
|
} |
712 |
|
|
713 |
|
tmp = diff16(arrayA, arrayB, 64) / 64; |
714 |
|
if (tmp > max_error) |
715 |
|
max_error = tmp; |
716 |
|
if (tmp < min_error) |
717 |
|
min_error = tmp; |
718 |
|
|
719 |
|
count++; |
720 |
|
} |
721 |
|
|
722 |
|
/* print the "average difference" of best/worst transforms */ |
723 |
|
printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error); |
724 |
|
|
725 |
|
return 0; |
726 |
|
} |
727 |
|
|
728 |
|
|
729 |
|
#define TEST_QUANT 0x00000001 /* forward quantization */ |
730 |
|
#define TEST_INTRA 0x00000002 /* intra */ |
731 |
|
#define TEST_QUANT_INTRA (TEST_QUANT|TEST_INTRA) |
732 |
|
#define TEST_QUANT_INTER (TEST_QUANT) |
733 |
|
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
734 |
|
#define TEST_DEQUANT_INTER (0) |
735 |
|
|
736 |
|
static int test_quant(void * funcA, void * funcB, const char * nameB, |
737 |
|
int test, int flags) |
738 |
|
{ |
739 |
|
int q,i; |
740 |
|
int64_t timeSTART; |
741 |
|
int64_t timeA = 0; |
742 |
|
int64_t timeB = 0; |
743 |
|
int retA = 0, retB = 0; |
744 |
|
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
745 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
746 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
747 |
|
int min, max; |
748 |
|
int count = 0; |
749 |
|
int errors = 0; |
750 |
|
|
751 |
|
if ((test & TEST_QUANT)) /* quant */ |
752 |
|
{ |
753 |
|
min = -2048; |
754 |
|
max = 2047; |
755 |
|
}else{ /* dequant */ |
756 |
|
min = -256; |
757 |
|
max = 255; |
758 |
|
} |
759 |
|
|
760 |
|
for (q = 1; q <= 31; q++) /* quantizer */ |
761 |
|
{ |
762 |
|
for (i = min; i < max; i++) /* input coeff */ |
763 |
|
{ |
764 |
|
if ((flags & XVID_TEST_RANDOM)) |
765 |
|
{ |
766 |
|
random16(arrayX, 64, min, max); |
767 |
|
}else{ |
768 |
|
fill16(arrayX, 64, i); |
769 |
|
} |
770 |
|
|
771 |
|
if ((test & TEST_INTRA)) /* intra */ |
772 |
|
{ |
773 |
|
timeSTART = read_counter(); |
774 |
|
((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q); |
775 |
|
timeA += read_counter() - timeSTART; |
776 |
|
|
777 |
|
timeSTART = read_counter(); |
778 |
|
((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q); |
779 |
|
timeB += read_counter() - timeSTART; |
780 |
|
} |
781 |
|
else /* inter */ |
782 |
|
{ |
783 |
|
timeSTART = read_counter(); |
784 |
|
retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q); |
785 |
|
timeA += read_counter() - timeSTART; |
786 |
|
|
787 |
|
timeSTART = read_counter(); |
788 |
|
retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q); |
789 |
|
timeB += read_counter() - timeSTART; |
790 |
|
} |
791 |
|
|
792 |
|
/* compare return value from quant_inter, and compare (de)quantiz'd arrays */ |
793 |
|
if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) || |
794 |
|
compare16(arrayA, arrayB, 64)) |
795 |
|
{ |
796 |
|
errors++; |
797 |
|
if ((flags & XVID_TEST_VERBOSE)) |
798 |
|
printf("%s error: q=%i, i=%i\n", nameB, q, i); |
799 |
|
} |
800 |
|
|
801 |
|
count++; |
802 |
|
} |
803 |
|
} |
804 |
|
|
805 |
|
printf("%s:\t%i", nameB, (int)(timeB / count)); |
806 |
|
if (errors>0) |
807 |
|
printf("\t(%i errors out of %i)", errors, count); |
808 |
|
printf("\n"); |
809 |
|
|
810 |
|
return 0; |
811 |
|
} |
812 |
|
|
813 |
|
|
814 |
|
|
815 |
|
int xvid_init_test(int flags) |
816 |
|
{ |
817 |
|
#if defined(ARCH_IS_IA32) |
818 |
|
int cpu_flags; |
819 |
|
#endif |
820 |
|
|
821 |
|
printf("XviD tests\n\n"); |
822 |
|
|
823 |
|
#if defined(ARCH_IS_IA32) |
824 |
|
cpu_flags = detect_cpu_flags(); |
825 |
|
#endif |
826 |
|
|
827 |
|
idct_int32_init(); |
828 |
|
emms(); |
829 |
|
|
830 |
|
srand(time(0)); |
831 |
|
|
832 |
|
/* fDCT test */ |
833 |
|
printf("--- fdct ---\n"); |
834 |
|
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
835 |
|
|
836 |
|
#if defined(ARCH_IS_IA32) |
837 |
|
if (cpu_flags & XVID_CPU_MMX) |
838 |
|
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
839 |
|
if (cpu_flags & XVID_CPU_SSE2) |
840 |
|
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
841 |
|
#endif |
842 |
|
|
843 |
|
/* iDCT test */ |
844 |
|
printf("\n--- idct ---\n"); |
845 |
|
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
846 |
|
|
847 |
|
#if defined(ARCH_IS_IA32) |
848 |
|
if (cpu_flags & XVID_CPU_MMX) |
849 |
|
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
850 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
851 |
|
test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags); |
852 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
853 |
|
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
854 |
|
if (cpu_flags & XVID_CPU_SSE2) |
855 |
|
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
856 |
|
#endif |
857 |
|
|
858 |
|
/* Intra quantization test */ |
859 |
|
printf("\n--- quant intra ---\n"); |
860 |
|
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
861 |
|
|
862 |
|
#if defined(ARCH_IS_IA32) |
863 |
|
if (cpu_flags & XVID_CPU_MMX) |
864 |
|
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
865 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
866 |
|
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
867 |
|
if (cpu_flags & XVID_CPU_SSE2) |
868 |
|
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
869 |
|
#endif |
870 |
|
|
871 |
|
/* Inter quantization test */ |
872 |
|
printf("\n--- quant inter ---\n"); |
873 |
|
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
874 |
|
|
875 |
|
#if defined(ARCH_IS_IA32) |
876 |
|
if (cpu_flags & XVID_CPU_MMX) |
877 |
|
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
878 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
879 |
|
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
880 |
|
if (cpu_flags & XVID_CPU_SSE2) |
881 |
|
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
882 |
|
#endif |
883 |
|
|
884 |
|
/* Intra dequantization test */ |
885 |
|
printf("\n--- dequant intra ---\n"); |
886 |
|
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
887 |
|
|
888 |
|
#if defined(ARCH_IS_IA32) |
889 |
|
if (cpu_flags & XVID_CPU_MMX) |
890 |
|
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
891 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
892 |
|
test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags); |
893 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
894 |
|
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
895 |
|
if (cpu_flags & XVID_CPU_SSE2) |
896 |
|
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
897 |
|
#endif |
898 |
|
|
899 |
|
/* Inter dequantization test */ |
900 |
|
printf("\n--- dequant inter ---\n"); |
901 |
|
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
902 |
|
|
903 |
|
#if defined(ARCH_IS_IA32) |
904 |
|
if (cpu_flags & XVID_CPU_MMX) |
905 |
|
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
906 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
907 |
|
test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags); |
908 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
909 |
|
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
910 |
|
if (cpu_flags & XVID_CPU_SSE2) |
911 |
|
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
912 |
|
#endif |
913 |
|
|
914 |
|
/* Intra quantization test */ |
915 |
|
printf("\n--- quant4 intra ---\n"); |
916 |
|
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
917 |
|
|
918 |
|
#if defined(ARCH_IS_IA32) |
919 |
|
if (cpu_flags & XVID_CPU_MMX) |
920 |
|
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
921 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
922 |
|
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
923 |
#endif |
#endif |
924 |
|
|
925 |
// API version |
/* Inter quantization test */ |
926 |
init_param->api_version = API_VERSION; |
printf("\n--- quant4 inter ---\n"); |
927 |
|
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
928 |
|
|
929 |
|
#if defined(ARCH_IS_IA32) |
930 |
|
if (cpu_flags & XVID_CPU_MMX) |
931 |
|
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
932 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
933 |
|
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
934 |
|
#endif |
935 |
|
|
936 |
// something clever has to be done for this |
/* Intra dequantization test */ |
937 |
init_param->core_build = 1000; |
printf("\n--- dequant4 intra ---\n"); |
938 |
|
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
939 |
|
|
940 |
|
#if defined(ARCH_IS_IA32) |
941 |
|
if (cpu_flags & XVID_CPU_MMX) |
942 |
|
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
943 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
944 |
|
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
945 |
|
#endif |
946 |
|
|
947 |
return XVID_ERR_OK; |
/* Inter dequantization test */ |
948 |
|
printf("\n--- dequant4 inter ---\n"); |
949 |
|
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
950 |
|
|
951 |
|
#if defined(ARCH_IS_IA32) |
952 |
|
if (cpu_flags & XVID_CPU_MMX) |
953 |
|
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
954 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
955 |
|
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
956 |
|
#endif |
957 |
|
|
958 |
|
emms(); |
959 |
|
|
960 |
|
return 0; |
961 |
} |
} |
962 |
|
|
963 |
int xvid_decore(void * handle, int opt, void * param1, void * param2) |
|
964 |
|
/***************************************************************************** |
965 |
|
* XviD Global Entry point |
966 |
|
* |
967 |
|
* Well this function initialize all internal function pointers according |
968 |
|
* to the CPU features forced by the library client or autodetected (depending |
969 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
970 |
|
* image colorspace transformation tables. |
971 |
|
* |
972 |
|
****************************************************************************/ |
973 |
|
|
974 |
|
|
975 |
|
int |
976 |
|
xvid_global(void *handle, |
977 |
|
int opt, |
978 |
|
void *param1, |
979 |
|
void *param2) |
980 |
{ |
{ |
981 |
switch (opt) |
switch (opt) |
982 |
{ |
{ |
983 |
case XVID_DEC_DECODE : |
case XVID_GBL_INIT : |
984 |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
985 |
|
|
986 |
|
case XVID_GBL_INFO : |
987 |
|
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
988 |
|
|
989 |
|
case XVID_GBL_CONVERT : |
990 |
|
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
991 |
|
|
992 |
|
case XVID_GBL_TEST : |
993 |
|
{ |
994 |
|
ptr_t flags = (ptr_t)param1; |
995 |
|
return xvid_init_test((int)flags); |
996 |
|
} |
997 |
|
default : |
998 |
|
return XVID_ERR_FAIL; |
999 |
|
} |
1000 |
|
} |
1001 |
|
|
1002 |
|
/***************************************************************************** |
1003 |
|
* XviD Native decoder entry point |
1004 |
|
* |
1005 |
|
* This function is just a wrapper to all the option cases. |
1006 |
|
* |
1007 |
|
* Returned values : XVID_ERR_FAIL when opt is invalid |
1008 |
|
* else returns the wrapped function result |
1009 |
|
* |
1010 |
|
****************************************************************************/ |
1011 |
|
|
1012 |
|
int |
1013 |
|
xvid_decore(void *handle, |
1014 |
|
int opt, |
1015 |
|
void *param1, |
1016 |
|
void *param2) |
1017 |
|
{ |
1018 |
|
switch (opt) { |
1019 |
case XVID_DEC_CREATE : |
case XVID_DEC_CREATE : |
1020 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((xvid_dec_create_t *) param1); |
1021 |
|
|
1022 |
case XVID_DEC_DESTROY : |
case XVID_DEC_DESTROY : |
1023 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1024 |
|
|
1025 |
|
case XVID_DEC_DECODE: |
1026 |
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
1027 |
|
|
1028 |
default: |
default: |
1029 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1030 |
} |
} |
1031 |
} |
} |
1032 |
|
|
1033 |
|
|
1034 |
int xvid_encore(void * handle, int opt, void * param1, void * param2) |
/***************************************************************************** |
1035 |
{ |
* XviD Native encoder entry point |
1036 |
switch (opt) |
* |
1037 |
|
* This function is just a wrapper to all the option cases. |
1038 |
|
* |
1039 |
|
* Returned values : XVID_ERR_FAIL when opt is invalid |
1040 |
|
* else returns the wrapped function result |
1041 |
|
* |
1042 |
|
****************************************************************************/ |
1043 |
|
|
1044 |
|
int |
1045 |
|
xvid_encore(void *handle, |
1046 |
|
int opt, |
1047 |
|
void *param1, |
1048 |
|
void *param2) |
1049 |
{ |
{ |
1050 |
|
switch (opt) { |
1051 |
case XVID_ENC_ENCODE : |
case XVID_ENC_ENCODE : |
1052 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, (XVID_ENC_STATS *) param2); |
|
1053 |
|
return enc_encode((Encoder *) handle, |
1054 |
|
(xvid_enc_frame_t *) param1, |
1055 |
|
(xvid_enc_stats_t *) param2); |
1056 |
|
|
1057 |
case XVID_ENC_CREATE : |
case XVID_ENC_CREATE : |
1058 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return enc_create((xvid_enc_create_t *) param1); |
1059 |
|
|
1060 |
case XVID_ENC_DESTROY : |
case XVID_ENC_DESTROY : |
1061 |
return encoder_destroy((Encoder *) handle); |
return enc_destroy((Encoder *) handle); |
1062 |
|
|
1063 |
default: |
default: |
1064 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |