[cvs] / xvidcore / src / xvid.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/xvid.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.47 - (view) (download)

1 : edgomez 1.16 /*****************************************************************************
2 : edgomez 1.17 *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Native API implementation -
5 :     *
6 : edgomez 1.41 * 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 1.17 * (at your option) any later version.
10 :     *
11 :     * This program is distributed in the hope that it will be useful,
12 : edgomez 1.41 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
13 : edgomez 1.17 * 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 1.41 * along with this program ; if not, write to the Free Software
18 : edgomez 1.17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 :     *
20 : Isibaar 1.47 * $Id: xvid.c,v 1.46 2003/06/09 17:07:10 Isibaar Exp $
21 : edgomez 1.36 *
22 : edgomez 1.17 ****************************************************************************/
23 : chenm001 1.29
24 : edgomez 1.41 #include <stdio.h>
25 :     #include <stdlib.h>
26 :     #include <string.h>
27 :     #include <time.h>
28 :    
29 : Isibaar 1.1 #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 1.41 #include "image/reduced.h"
38 : Isibaar 1.1 #include "utils/mem_transfer.h"
39 : edgomez 1.41 #include "utils/mbfunctions.h"
40 : Isibaar 1.1 #include "quant/quant_h263.h"
41 :     #include "quant/quant_mpeg4.h"
42 : ia64p 1.30 #include "motion/motion.h"
43 : Isibaar 1.1 #include "motion/sad.h"
44 :     #include "utils/emms.h"
45 :     #include "utils/timer.h"
46 : Isibaar 1.9 #include "bitstream/mbcoding.h"
47 : Isibaar 1.1
48 : edgomez 1.41 #if defined(ARCH_IS_IA32)
49 : suxen_drol 1.31
50 : edgomez 1.41 #if defined(_MSC_VER)
51 :     # include <windows.h>
52 : suxen_drol 1.31 #else
53 : edgomez 1.41 # include <signal.h>
54 :     # include <setjmp.h>
55 : suxen_drol 1.31
56 : edgomez 1.41 static jmp_buf mark;
57 : suxen_drol 1.31
58 : edgomez 1.41 static void
59 :     sigill_handler(int signal)
60 :     {
61 :     longjmp(mark, 1);
62 :     }
63 : suxen_drol 1.31 #endif
64 :    
65 :    
66 :     /*
67 : edgomez 1.43 * 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 1.31
76 :     int
77 :     sigill_check(void (*func)())
78 :     {
79 : edgomez 1.41 #if defined(_MSC_VER)
80 : suxen_drol 1.31 _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 1.41
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 1.16 /*****************************************************************************
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 1.41
155 :     static
156 :     int xvid_init_init(XVID_INIT_PARAM * init_param)
157 : Isibaar 1.1 {
158 :     int cpu_flags;
159 :    
160 : suxen_drol 1.21 /* 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 1.31 /* Do we have to force CPU features ? */
167 :     if ((init_param->cpu_flags & XVID_CPU_FORCE)) {
168 : suxen_drol 1.21
169 : Isibaar 1.1 cpu_flags = init_param->cpu_flags;
170 : suxen_drol 1.31
171 : edgomez 1.16 } else {
172 : Isibaar 1.1
173 : edgomez 1.41 cpu_flags = detect_cpu_flags();
174 : suxen_drol 1.31 }
175 :    
176 :     if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
177 :     {
178 : Isibaar 1.1 init_param->cpu_flags = cpu_flags;
179 : suxen_drol 1.31 return XVID_ERR_OK;
180 : Isibaar 1.1 }
181 : suxen_drol 1.31
182 :     init_param->cpu_flags = cpu_flags;
183 :    
184 : Isibaar 1.1
185 : edgomez 1.16 /* Initialize the function pointers */
186 : Isibaar 1.1 idct_int32_init();
187 : Isibaar 1.9 init_vlc_tables();
188 :    
189 : edgomez 1.16 /* Fixed Point Forward/Inverse DCT transformations */
190 : Isibaar 1.1 fdct = fdct_int32;
191 :     idct = idct_int32;
192 :    
193 : edgomez 1.16 /* Only needed on PPC Altivec archs */
194 : canard 1.10 sadInit = 0;
195 : edgomez 1.15
196 : edgomez 1.16 /* Restore FPU context : emms_c is a nop functions */
197 : Isibaar 1.1 emms = emms_c;
198 :    
199 : edgomez 1.16 /* Quantization functions */
200 :     quant_intra = quant_intra_c;
201 : Isibaar 1.1 dequant_intra = dequant_intra_c;
202 : edgomez 1.16 quant_inter = quant_inter_c;
203 : Isibaar 1.1 dequant_inter = dequant_inter_c;
204 :    
205 : edgomez 1.16 quant4_intra = quant4_intra_c;
206 : Isibaar 1.1 dequant4_intra = dequant4_intra_c;
207 : edgomez 1.16 quant4_inter = quant4_inter_c;
208 : Isibaar 1.1 dequant4_inter = dequant4_inter_c;
209 :    
210 : edgomez 1.16 /* Block transfer related functions */
211 : Isibaar 1.1 transfer_8to16copy = transfer_8to16copy_c;
212 :     transfer_16to8copy = transfer_16to8copy_c;
213 : edgomez 1.16 transfer_8to16sub = transfer_8to16sub_c;
214 : edgomez 1.41 transfer_8to16subro = transfer_8to16subro_c;
215 : suxen_drol 1.11 transfer_8to16sub2 = transfer_8to16sub2_c;
216 : edgomez 1.16 transfer_16to8add = transfer_16to8add_c;
217 :     transfer8x8_copy = transfer8x8_copy_c;
218 : Isibaar 1.1
219 : edgomez 1.41 /* Interlacing functions */
220 :     MBFieldTest = MBFieldTest_c;
221 :    
222 : edgomez 1.16 /* Image interpolation related functions */
223 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;
224 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;
225 : Isibaar 1.1 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;
226 :    
227 : edgomez 1.41 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 1.16 /* Initialize internal colorspace transformation tables */
250 : Isibaar 1.1 colorspace_init();
251 :    
252 : edgomez 1.16 /* All colorspace transformation functions User Format->YV12 */
253 : edgomez 1.41 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 :    
263 :     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 : Isibaar 1.1
273 : edgomez 1.16 /* All colorspace transformation functions YV12->User format */
274 : edgomez 1.41 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 1.1
292 : edgomez 1.16 /* Functions used in motion estimation algorithms */
293 : Isibaar 1.1 calc_cbp = calc_cbp_c;
294 : edgomez 1.16 sad16 = sad16_c;
295 : suxen_drol 1.33 sad8 = sad8_c;
296 : edgomez 1.16 sad16bi = sad16bi_c;
297 : suxen_drol 1.33 sad8bi = sad8bi_c;
298 : edgomez 1.16 dev16 = dev16_c;
299 : edgomez 1.41 sad16v = sad16v_c;
300 : suxen_drol 1.33
301 : edgomez 1.43 /* Halfpel8_Refine = Halfpel8_Refine_c; */
302 : Isibaar 1.1
303 : edgomez 1.41 #if defined(ARCH_IS_IA32)
304 :    
305 :     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 : edgomez 1.16
321 :     /* Forward and Inverse Discrete Cosine Transformation functions */
322 : Isibaar 1.1 fdct = fdct_mmx;
323 : Isibaar 1.47 idct = idct_mmx;
324 : Isibaar 1.1
325 : edgomez 1.16 /* Quantization related functions */
326 :     quant_intra = quant_intra_mmx;
327 : Isibaar 1.1 dequant_intra = dequant_intra_mmx;
328 : edgomez 1.16 quant_inter = quant_inter_mmx;
329 : Isibaar 1.1 dequant_inter = dequant_inter_mmx;
330 :    
331 : edgomez 1.16 quant4_intra = quant4_intra_mmx;
332 : Isibaar 1.1 dequant4_intra = dequant4_intra_mmx;
333 : edgomez 1.16 quant4_inter = quant4_inter_mmx;
334 : Isibaar 1.1 dequant4_inter = dequant4_inter_mmx;
335 :    
336 : edgomez 1.16 /* Block related functions */
337 : Isibaar 1.1 transfer_8to16copy = transfer_8to16copy_mmx;
338 :     transfer_16to8copy = transfer_16to8copy_mmx;
339 : edgomez 1.16 transfer_8to16sub = transfer_8to16sub_mmx;
340 : edgomez 1.41 transfer_8to16subro = transfer_8to16subro_mmx;
341 : edgomez 1.22 transfer_8to16sub2 = transfer_8to16sub2_mmx;
342 : edgomez 1.16 transfer_16to8add = transfer_16to8add_mmx;
343 :     transfer8x8_copy = transfer8x8_copy_mmx;
344 : edgomez 1.22
345 : edgomez 1.41 /* Interlacing Functions */
346 :     MBFieldTest = MBFieldTest_mmx;
347 : edgomez 1.16
348 :     /* Image Interpolation related functions */
349 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;
350 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;
351 : Isibaar 1.1 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;
352 :    
353 : edgomez 1.41 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 1.16 yuyv_to_yv12 = yuyv_to_yv12_mmx;
371 :     uyvy_to_yv12 = uyvy_to_yv12_mmx;
372 : Isibaar 1.1
373 : edgomez 1.41 /* 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 1.16 yv12_to_yuyv = yv12_to_yuyv_mmx;
377 :     yv12_to_uyvy = yv12_to_uyvy_mmx;
378 : edgomez 1.41
379 :     yv12_to_yuyvi = yv12_to_yuyvi_mmx;
380 :     yv12_to_uyvyi = yv12_to_uyvyi_mmx;
381 : Isibaar 1.1
382 : edgomez 1.16 /* Motion estimation related functions */
383 : Isibaar 1.1 calc_cbp = calc_cbp_mmx;
384 : edgomez 1.16 sad16 = sad16_mmx;
385 :     sad8 = sad8_mmx;
386 : suxen_drol 1.33 sad16bi = sad16bi_mmx;
387 :     sad8bi = sad8bi_mmx;
388 : edgomez 1.16 dev16 = dev16_mmx;
389 : edgomez 1.41 sad16v = sad16v_mmx;
390 : Isibaar 1.1 }
391 :    
392 : suxen_drol 1.33 /* these 3dnow functions are faster than mmx, but slower than xmm. */
393 : edgomez 1.41 if ((cpu_flags & XVID_CPU_3DNOW)) {
394 :    
395 :     emms = emms_3dn;
396 : suxen_drol 1.33
397 :     /* ME functions */
398 :     sad16bi = sad16bi_3dn;
399 :     sad8bi = sad8bi_3dn;
400 : edgomez 1.41
401 :     yuyv_to_yv12 = yuyv_to_yv12_3dn;
402 :     uyvy_to_yv12 = uyvy_to_yv12_3dn;
403 : suxen_drol 1.33 }
404 :    
405 :    
406 : edgomez 1.41 if ((cpu_flags & XVID_CPU_MMXEXT)) {
407 : edgomez 1.16
408 :     /* Inverse DCT */
409 : Isibaar 1.47 idct = idct_xmm;
410 : edgomez 1.16
411 :     /* Interpolation */
412 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;
413 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;
414 : h 1.3 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;
415 : Isibaar 1.25
416 : edgomez 1.41 /* 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 1.29 /* Quantization */
421 : edgomez 1.41 quant4_intra = quant4_intra_xmm;
422 :     quant4_inter = quant4_inter_xmm;
423 :    
424 : chenm001 1.29 dequant_intra = dequant_intra_xmm;
425 :     dequant_inter = dequant_inter_xmm;
426 :    
427 : edgomez 1.19 /* Buffer transfer */
428 :     transfer_8to16sub2 = transfer_8to16sub2_xmm;
429 : edgomez 1.16
430 :     /* Colorspace transformation */
431 : edgomez 1.41 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 1.1
435 : edgomez 1.16 /* ME functions */
436 : Isibaar 1.1 sad16 = sad16_xmm;
437 : suxen_drol 1.33 sad8 = sad8_xmm;
438 : chenm001 1.29 sad16bi = sad16bi_xmm;
439 : suxen_drol 1.33 sad8bi = sad8bi_xmm;
440 : Isibaar 1.1 dev16 = dev16_xmm;
441 : edgomez 1.41 sad16v = sad16v_xmm;
442 : Isibaar 1.1 }
443 :    
444 : edgomez 1.41 if ((cpu_flags & XVID_CPU_3DNOW)) {
445 : edgomez 1.16
446 :     /* Interpolation */
447 : Isibaar 1.1 interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
448 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
449 : h 1.4 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
450 : Isibaar 1.1 }
451 :    
452 : edgomez 1.41 if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
453 :    
454 :     /* Inverse DCT */
455 : Isibaar 1.47 idct = idct_3dne;
456 : edgomez 1.41
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 : edgomez 1.16
491 : Isibaar 1.47 #if defined(EXPERIMENTAL_SSE2_CODE) /* many people reported crashes with SSE2 */
492 :     /* better deactivate it completely and fix everything */
493 :     /* in dev-api-4 */
494 : chenm001 1.29 calc_cbp = calc_cbp_sse2;
495 :    
496 : edgomez 1.16 /* Quantization */
497 :     quant_intra = quant_intra_sse2;
498 : Isibaar 1.14 dequant_intra = dequant_intra_sse2;
499 : edgomez 1.16 quant_inter = quant_inter_sse2;
500 : Isibaar 1.14 dequant_inter = dequant_inter_sse2;
501 : h 1.13
502 : edgomez 1.41 /* ME; slower than xmm */
503 : edgomez 1.16 sad16 = sad16_sse2;
504 :     dev16 = dev16_sse2;
505 : edgomez 1.41 #endif
506 : edgomez 1.16 /* Forward and Inverse DCT */
507 : Isibaar 1.46 /* idct = idct_sse2;
508 :     /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */
509 : h 1.12 }
510 : Isibaar 1.1 #endif
511 : Isibaar 1.18
512 : edgomez 1.41 #if defined(ARCH_IS_IA64)
513 : edgomez 1.43 if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */
514 : Isibaar 1.18 idct_ia64_init();
515 :     fdct = fdct_ia64;
516 : edgomez 1.43 idct = idct_ia64; /*not yet working, crashes */
517 : Isibaar 1.18 interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
518 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
519 :     interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
520 :     sad16 = sad16_ia64;
521 :     sad16bi = sad16bi_ia64;
522 :     sad8 = sad8_ia64;
523 :     dev16 = dev16_ia64;
524 : edgomez 1.43 /* Halfpel8_Refine = Halfpel8_Refine_ia64; */
525 : Isibaar 1.18 quant_intra = quant_intra_ia64;
526 :     dequant_intra = dequant_intra_ia64;
527 :     quant_inter = quant_inter_ia64;
528 :     dequant_inter = dequant_inter_ia64;
529 :     transfer_8to16copy = transfer_8to16copy_ia64;
530 :     transfer_16to8copy = transfer_16to8copy_ia64;
531 :     transfer_8to16sub = transfer_8to16sub_ia64;
532 :     transfer_8to16sub2 = transfer_8to16sub2_ia64;
533 :     transfer_16to8add = transfer_16to8add_ia64;
534 :     transfer8x8_copy = transfer8x8_copy_ia64;
535 : edgomez 1.43 DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines.");
536 : Isibaar 1.18 }
537 :     #endif
538 : edgomez 1.16
539 : edgomez 1.41 #if defined(ARCH_IS_PPC)
540 :     if ((cpu_flags & XVID_CPU_ASM))
541 :     {
542 :     calc_cbp = calc_cbp_ppc;
543 :     }
544 :    
545 :     if ((cpu_flags & XVID_CPU_ALTIVEC))
546 :     {
547 :     calc_cbp = calc_cbp_altivec;
548 :     fdct = fdct_altivec;
549 :     idct = idct_altivec;
550 :     sadInit = sadInit_altivec;
551 :     sad16 = sad16_altivec;
552 :     sad8 = sad8_altivec;
553 :     dev16 = dev16_altivec;
554 :     }
555 : canard 1.6 #endif
556 : edgomez 1.41
557 :     return XVID_ERR_OK;
558 :     }
559 :    
560 :    
561 :    
562 :     static int
563 :     xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
564 :     {
565 : edgomez 1.43 /*
566 :     const int flip1 =
567 :     (convert->input.colorspace & XVID_CSP_VFLIP) ^
568 :     (convert->output.colorspace & XVID_CSP_VFLIP);
569 :     */
570 : edgomez 1.41 const int width = convert->width;
571 :     const int height = convert->height;
572 :     const int width2 = convert->width/2;
573 :     const int height2 = convert->height/2;
574 :     IMAGE img;
575 :    
576 :     switch (convert->input.colorspace & ~XVID_CSP_VFLIP)
577 :     {
578 :     case XVID_CSP_YV12 :
579 :     img.y = convert->input.y;
580 :     img.v = (uint8_t*)convert->input.y + width*height;
581 :     img.u = (uint8_t*)convert->input.y + width*height + width2*height2;
582 :     image_output(&img, width, height, width,
583 :     convert->output.y, convert->output.y_stride,
584 :     convert->output.colorspace, convert->interlacing);
585 :     break;
586 :    
587 :     default :
588 :     return XVID_ERR_FORMAT;
589 :     }
590 :    
591 :    
592 :     emms();
593 :     return XVID_ERR_OK;
594 :     }
595 :    
596 :    
597 :    
598 :     void fill8(uint8_t * block, int size, int value)
599 :     {
600 :     int i;
601 :     for (i = 0; i < size; i++)
602 :     block[i] = value;
603 :     }
604 :    
605 :     void fill16(int16_t * block, int size, int value)
606 :     {
607 :     int i;
608 :     for (i = 0; i < size; i++)
609 :     block[i] = value;
610 :     }
611 :    
612 :     #define RANDOM(min,max) min + (rand() % (max-min))
613 :    
614 :     void random8(uint8_t * block, int size, int min, int max)
615 :     {
616 :     int i;
617 :     for (i = 0; i < size; i++)
618 :     block[i] = RANDOM(min,max);
619 :     }
620 :    
621 :     void random16(int16_t * block, int size, int min, int max)
622 :     {
623 :     int i;
624 :     for (i = 0; i < size; i++)
625 :     block[i] = RANDOM(min,max);
626 :     }
627 :    
628 :     int compare16(const int16_t * blockA, const int16_t * blockB, int size)
629 :     {
630 :     int i;
631 :     for (i = 0; i < size; i++)
632 :     if (blockA[i] != blockB[i])
633 :     return 1;
634 :    
635 :     return 0;
636 :     }
637 :    
638 :     int diff16(const int16_t * blockA, const int16_t * blockB, int size)
639 :     {
640 :     int i, diff = 0;
641 :     for (i = 0; i < size; i++)
642 :     diff += ABS(blockA[i]-blockB[i]);
643 :     return diff;
644 :     }
645 :    
646 :    
647 :     #define XVID_TEST_RANDOM 0x00000001 /* random input data */
648 :     #define XVID_TEST_VERBOSE 0x00000002 /* verbose error output */
649 :    
650 :    
651 :     #define TEST_FORWARD 0x00000001 /* intra */
652 :     #define TEST_FDCT (TEST_FORWARD)
653 :     #define TEST_IDCT (0)
654 :    
655 : suxen_drol 1.42 static int test_transform(void * funcA, void * funcB, const char * nameB,
656 : edgomez 1.41 int test, int flags)
657 :     {
658 :     int i;
659 :     int64_t timeSTART;
660 :     int64_t timeA = 0;
661 :     int64_t timeB = 0;
662 :     DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
663 :     DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
664 :     int min, max;
665 :     int count = 0;
666 :    
667 :     int tmp;
668 :     int min_error = 0x10000*64;
669 :     int max_error = 0;
670 :    
671 :    
672 :     if ((test & TEST_FORWARD)) /* forward */
673 :     {
674 :     min = -256;
675 :     max = 255;
676 :     }else{ /* inverse */
677 :     min = -2048;
678 :     max = 2047;
679 :     }
680 :    
681 :     for (i = 0; i < 64*64; i++)
682 :     {
683 :     if ((flags & XVID_TEST_RANDOM))
684 :     {
685 :     random16(arrayA, 64, min, max);
686 :     }else{
687 :     fill16(arrayA, 64, i);
688 :     }
689 :     memcpy(arrayB, arrayA, 64*sizeof(int16_t));
690 :    
691 :     if ((test & TEST_FORWARD))
692 :     {
693 :     timeSTART = read_counter();
694 :     ((fdctFunc*)funcA)(arrayA);
695 :     timeA += read_counter() - timeSTART;
696 :    
697 :     timeSTART = read_counter();
698 :     ((fdctFunc*)funcB)(arrayB);
699 :     timeB += read_counter() - timeSTART;
700 :     }
701 :     else
702 :     {
703 :     timeSTART = read_counter();
704 :     ((idctFunc*)funcA)(arrayA);
705 :     timeA += read_counter() - timeSTART;
706 :    
707 :     timeSTART = read_counter();
708 :     ((idctFunc*)funcB)(arrayB);
709 :     timeB += read_counter() - timeSTART;
710 :     }
711 :    
712 :     tmp = diff16(arrayA, arrayB, 64) / 64;
713 :     if (tmp > max_error)
714 :     max_error = tmp;
715 :     if (tmp < min_error)
716 :     min_error = tmp;
717 :    
718 :     count++;
719 :     }
720 :    
721 :     /* print the "average difference" of best/worst transforms */
722 :     printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error);
723 :    
724 :     return 0;
725 :     }
726 :    
727 :    
728 :     #define TEST_QUANT 0x00000001 /* forward quantization */
729 :     #define TEST_INTRA 0x00000002 /* intra */
730 :     #define TEST_QUANT_INTRA (TEST_QUANT|TEST_INTRA)
731 :     #define TEST_QUANT_INTER (TEST_QUANT)
732 :     #define TEST_DEQUANT_INTRA (TEST_INTRA)
733 :     #define TEST_DEQUANT_INTER (0)
734 :    
735 : suxen_drol 1.42 static int test_quant(void * funcA, void * funcB, const char * nameB,
736 : edgomez 1.41 int test, int flags)
737 :     {
738 :     int q,i;
739 :     int64_t timeSTART;
740 :     int64_t timeA = 0;
741 :     int64_t timeB = 0;
742 : edgomez 1.43 int retA = 0, retB = 0;
743 : edgomez 1.41 DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
744 :     DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
745 :     DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
746 :     int min, max;
747 :     int count = 0;
748 :     int errors = 0;
749 :    
750 :     if ((test & TEST_QUANT)) /* quant */
751 :     {
752 :     min = -2048;
753 :     max = 2047;
754 :     }else{ /* dequant */
755 :     min = -256;
756 :     max = 255;
757 :     }
758 :    
759 :     for (q = 1; q <= 31; q++) /* quantizer */
760 :     {
761 :     for (i = min; i < max; i++) /* input coeff */
762 :     {
763 :     if ((flags & XVID_TEST_RANDOM))
764 :     {
765 :     random16(arrayX, 64, min, max);
766 :     }else{
767 :     fill16(arrayX, 64, i);
768 :     }
769 :    
770 :     if ((test & TEST_INTRA)) /* intra */
771 :     {
772 :     timeSTART = read_counter();
773 :     ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
774 :     timeA += read_counter() - timeSTART;
775 :    
776 :     timeSTART = read_counter();
777 :     ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
778 :     timeB += read_counter() - timeSTART;
779 :     }
780 :     else /* inter */
781 :     {
782 :     timeSTART = read_counter();
783 :     retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q);
784 :     timeA += read_counter() - timeSTART;
785 :    
786 :     timeSTART = read_counter();
787 :     retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q);
788 :     timeB += read_counter() - timeSTART;
789 :     }
790 :    
791 :     /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
792 :     if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) ||
793 :     compare16(arrayA, arrayB, 64))
794 :     {
795 :     errors++;
796 :     if ((flags & XVID_TEST_VERBOSE))
797 :     printf("%s error: q=%i, i=%i\n", nameB, q, i);
798 :     }
799 :    
800 :     count++;
801 :     }
802 :     }
803 :    
804 :     printf("%s:\t%i", nameB, (int)(timeB / count));
805 :     if (errors>0)
806 :     printf("\t(%i errors out of %i)", errors, count);
807 :     printf("\n");
808 :    
809 :     return 0;
810 :     }
811 :    
812 :    
813 :    
814 :     int xvid_init_test(int flags)
815 :     {
816 : edgomez 1.45 #if defined(ARCH_IS_IA32)
817 :     int cpu_flags;
818 :     #endif
819 : edgomez 1.41
820 : edgomez 1.44 printf("XviD tests\n\n");
821 : edgomez 1.41
822 : edgomez 1.44 #if defined(ARCH_IS_IA32)
823 : edgomez 1.41 cpu_flags = detect_cpu_flags();
824 : edgomez 1.44 #endif
825 :    
826 : edgomez 1.41 idct_int32_init();
827 : edgomez 1.44 emms();
828 : edgomez 1.45
829 :     srand(time(0));
830 : edgomez 1.41
831 : edgomez 1.44 /* fDCT test */
832 : edgomez 1.41 printf("--- fdct ---\n");
833 :     test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
834 : edgomez 1.44
835 :     #if defined(ARCH_IS_IA32)
836 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
837 :     test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
838 :     if (cpu_flags & XVID_CPU_SSE2)
839 :     test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
840 : edgomez 1.44 #endif
841 : edgomez 1.41
842 : edgomez 1.44 /* iDCT test */
843 : edgomez 1.41 printf("\n--- idct ---\n");
844 :     test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
845 : edgomez 1.44
846 :     #if defined(ARCH_IS_IA32)
847 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
848 :     test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
849 :     if (cpu_flags & XVID_CPU_MMXEXT)
850 :     test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags);
851 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
852 :     test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
853 :     if (cpu_flags & XVID_CPU_SSE2)
854 :     test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
855 : edgomez 1.44 #endif
856 : edgomez 1.41
857 : edgomez 1.44 /* Intra quantization test */
858 : edgomez 1.41 printf("\n--- quant intra ---\n");
859 :     test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
860 : edgomez 1.44
861 :     #if defined(ARCH_IS_IA32)
862 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
863 :     test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
864 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
865 :     test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
866 :     if (cpu_flags & XVID_CPU_SSE2)
867 :     test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
868 : edgomez 1.44 #endif
869 : edgomez 1.41
870 : edgomez 1.44 /* Inter quantization test */
871 : edgomez 1.41 printf("\n--- quant inter ---\n");
872 :     test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
873 : edgomez 1.44
874 :     #if defined(ARCH_IS_IA32)
875 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
876 :     test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
877 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
878 :     test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);
879 :     if (cpu_flags & XVID_CPU_SSE2)
880 :     test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);
881 : edgomez 1.44 #endif
882 : edgomez 1.41
883 : edgomez 1.44 /* Intra dequantization test */
884 : edgomez 1.41 printf("\n--- dequant intra ---\n");
885 :     test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
886 : edgomez 1.44
887 :     #if defined(ARCH_IS_IA32)
888 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
889 :     test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
890 :     if (cpu_flags & XVID_CPU_MMXEXT)
891 :     test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags);
892 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
893 :     test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
894 :     if (cpu_flags & XVID_CPU_SSE2)
895 :     test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);
896 : edgomez 1.44 #endif
897 : edgomez 1.41
898 : edgomez 1.44 /* Inter dequantization test */
899 : edgomez 1.41 printf("\n--- dequant inter ---\n");
900 :     test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
901 : edgomez 1.44
902 :     #if defined(ARCH_IS_IA32)
903 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
904 :     test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
905 :     if (cpu_flags & XVID_CPU_MMXEXT)
906 :     test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags);
907 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
908 :     test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
909 :     if (cpu_flags & XVID_CPU_SSE2)
910 :     test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
911 : edgomez 1.44 #endif
912 : edgomez 1.41
913 : edgomez 1.44 /* Intra quantization test */
914 :     printf("\n--- quant4 intra ---\n");
915 : edgomez 1.41 test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
916 : edgomez 1.44
917 :     #if defined(ARCH_IS_IA32)
918 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
919 :     test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
920 :     if (cpu_flags & XVID_CPU_MMXEXT)
921 :     test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
922 : edgomez 1.44 #endif
923 : edgomez 1.41
924 : edgomez 1.44 /* Inter quantization test */
925 :     printf("\n--- quant4 inter ---\n");
926 : edgomez 1.41 test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
927 : edgomez 1.44
928 :     #if defined(ARCH_IS_IA32)
929 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
930 :     test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
931 :     if (cpu_flags & XVID_CPU_MMXEXT)
932 :     test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
933 : edgomez 1.44 #endif
934 : edgomez 1.41
935 : edgomez 1.44 /* Intra dequantization test */
936 :     printf("\n--- dequant4 intra ---\n");
937 : edgomez 1.41 test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
938 : edgomez 1.44
939 :     #if defined(ARCH_IS_IA32)
940 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
941 :     test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
942 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
943 :     test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
944 : edgomez 1.44 #endif
945 : edgomez 1.41
946 : edgomez 1.44 /* Inter dequantization test */
947 :     printf("\n--- dequant4 inter ---\n");
948 : edgomez 1.41 test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
949 : edgomez 1.44
950 :     #if defined(ARCH_IS_IA32)
951 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
952 :     test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
953 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
954 :     test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
955 : edgomez 1.44 #endif
956 : edgomez 1.41
957 : edgomez 1.44 emms();
958 : Isibaar 1.1
959 :     return XVID_ERR_OK;
960 :     }
961 :    
962 : edgomez 1.41
963 :     int
964 :     xvid_init(void *handle,
965 :     int opt,
966 :     void *param1,
967 :     void *param2)
968 :     {
969 :     switch(opt)
970 :     {
971 :     case XVID_INIT_INIT :
972 :     return xvid_init_init((XVID_INIT_PARAM*)param1);
973 :    
974 :     case XVID_INIT_CONVERT :
975 :     return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
976 :    
977 :     case XVID_INIT_TEST :
978 : edgomez 1.44 {
979 :     ptr_t flags = (ptr_t)param1;
980 :     return xvid_init_test((int)flags);
981 :     }
982 : edgomez 1.41 default :
983 :     return XVID_ERR_FAIL;
984 :     }
985 :     }
986 :    
987 : edgomez 1.16 /*****************************************************************************
988 :     * XviD Native decoder entry point
989 :     *
990 :     * This function is just a wrapper to all the option cases.
991 :     *
992 :     * Returned values : XVID_ERR_FAIL when opt is invalid
993 :     * else returns the wrapped function result
994 :     *
995 :     ****************************************************************************/
996 :    
997 : edgomez 1.15 int
998 :     xvid_decore(void *handle,
999 :     int opt,
1000 :     void *param1,
1001 :     void *param2)
1002 : Isibaar 1.1 {
1003 : edgomez 1.15 switch (opt) {
1004 :     case XVID_DEC_DECODE:
1005 : edgomez 1.41 return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2);
1006 : edgomez 1.15
1007 :     case XVID_DEC_CREATE:
1008 : chenm001 1.29 return decoder_create((XVID_DEC_PARAM *) param1);
1009 : edgomez 1.15
1010 :     case XVID_DEC_DESTROY:
1011 :     return decoder_destroy((DECODER *) handle);
1012 : Isibaar 1.1
1013 :     default:
1014 : edgomez 1.15 return XVID_ERR_FAIL;
1015 :     }
1016 : Isibaar 1.1 }
1017 :    
1018 : edgomez 1.16
1019 :     /*****************************************************************************
1020 :     * XviD Native encoder entry point
1021 :     *
1022 :     * This function is just a wrapper to all the option cases.
1023 :     *
1024 :     * Returned values : XVID_ERR_FAIL when opt is invalid
1025 :     * else returns the wrapped function result
1026 :     *
1027 :     ****************************************************************************/
1028 : Isibaar 1.1
1029 : edgomez 1.15 int
1030 :     xvid_encore(void *handle,
1031 :     int opt,
1032 :     void *param1,
1033 :     void *param2)
1034 : Isibaar 1.1 {
1035 : edgomez 1.15 switch (opt) {
1036 :     case XVID_ENC_ENCODE:
1037 : edgomez 1.41
1038 :     if (((Encoder *) handle)->mbParam.max_bframes >= 0)
1039 : edgomez 1.44 return encoder_encode_bframes((Encoder *) handle,
1040 :     (XVID_ENC_FRAME *) param1,
1041 :     (XVID_ENC_STATS *) param2);
1042 : edgomez 1.41 else
1043 : edgomez 1.44 return encoder_encode((Encoder *) handle,
1044 :     (XVID_ENC_FRAME *) param1,
1045 :     (XVID_ENC_STATS *) param2);
1046 : edgomez 1.15
1047 :     case XVID_ENC_CREATE:
1048 :     return encoder_create((XVID_ENC_PARAM *) param1);
1049 :    
1050 :     case XVID_ENC_DESTROY:
1051 :     return encoder_destroy((Encoder *) handle);
1052 : Isibaar 1.1
1053 :     default:
1054 : edgomez 1.15 return XVID_ERR_FAIL;
1055 :     }
1056 : Isibaar 1.1 }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4