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

Diff of /xvidcore/src/xvid.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.33.2.20

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