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