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