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