[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.33.2.21, Fri Jan 3 16:25:14 2003 UTC revision 1.45.2.7, Mon Jun 9 19:42:08 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Native API implementation  -   *  - Native API implementation  -
5   *   *
6   *  This program is an implementation of a part of one or more MPEG-4   *  Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
7   *   *
8   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
9   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 26  Line 19 
19   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
  ****************************************************************************/  
   
 /*****************************************************************************  
  *  
  *  History  
  *  
  *      - 23.06.2002    added XVID_CPU_CHKONLY  
  *  - 17.03.2002        Added interpolate8x8_halfpel_hv_xmm  
  *  - 22.12.2001  API change: added xvid_init() - Isibaar  
  *  - 16.12.2001        inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>  
  *  
22   *  $Id$   *  $Id$
23   *   *
24   ****************************************************************************/   ****************************************************************************/
# Line 65  Line 47 
47  #include "utils/timer.h"  #include "utils/timer.h"
48  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
49    
50  #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)  #if defined(_DEBUG)
51    unsigned int xvid_debug = 0; /* xvid debug mask */
52    #endif
53    
54    #if defined(ARCH_IS_IA32)
55    
56  #ifdef WIN32  #if defined(_MSC_VER)
57  #include <windows.h>  #include <windows.h>
58  #else  #else
59  #include <signal.h>  #include <signal.h>
60  #include <setjmp.h>  #include <setjmp.h>
 #endif  
   
   
 #ifndef WIN32  
61    
62  static jmp_buf mark;  static jmp_buf mark;
63    
# Line 88  Line 70 
70    
71    
72  /*  /*
73  calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled   * Calls the funcptr, and returns whether SIGILL (illegal instruction) was
74  return values:   * signalled
75  -1 : could not determine   *
76  0  : SIGILL was *not* signalled   * Return values:
77  1  : SIGILL was signalled   *  -1 : could not determine
78     *   0 : SIGILL was *not* signalled
79     *   1 : SIGILL was signalled
80  */  */
81    
82  int  int
83  sigill_check(void (*func)())  sigill_check(void (*func)())
84  {  {
85  #ifdef WIN32  #if defined(_MSC_VER)
86          _try {          _try {
87                  func();                  func();
88          }          }
# Line 132  Line 116 
116  }  }
117  #endif  #endif
118    
119    
120    /* detect cpu flags  */
121    static unsigned int
122    detect_cpu_flags()
123    {
124            /* enable native assembly optimizations by default */
125            unsigned int cpu_flags = XVID_CPU_ASM;
126    
127    #if defined(ARCH_IS_IA32)
128            cpu_flags |= check_cpu_features();
129            if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))
130                    cpu_flags &= ~XVID_CPU_SSE;
131    
132            if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))
133                    cpu_flags &= ~XVID_CPU_SSE2;
134    #endif
135    
136    #if defined(ARCH_IS_PPC)
137    #if defined(ARCH_IS_PPC_ALTIVEC)
138            cpu_flags |= XVID_CPU_ALTIVEC;
139    #endif
140    #endif
141    
142            return cpu_flags;
143    }
144    
145    
146  /*****************************************************************************  /*****************************************************************************
147   * XviD Init Entry point   * XviD Init Entry point
148   *   *
# Line 148  Line 159 
159    
160    
161  static  static
162  int xvid_init_init(XVID_INIT_PARAM * init_param)  int xvid_gbl_init(xvid_gbl_init_t * init)
163  {  {
164          int cpu_flags;          unsigned int cpu_flags;
   
         /* Inform the client the API version */  
         init_param->api_version = API_VERSION;  
165    
166          /* Inform the client the core build - unused because we're still alpha */          if (XVID_MAJOR(init->version) != 1) /* v1.x.x */
167          init_param->core_build = 1000;                  return XVID_ERR_VERSION;
   
         /* Do we have to force CPU features  ? */  
         if ((init_param->cpu_flags & XVID_CPU_FORCE)) {  
   
                 cpu_flags = init_param->cpu_flags;  
   
         } else {  
   
                 cpu_flags = check_cpu_features();  
   
 #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)  
                 if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))  
                         cpu_flags &= ~XVID_CPU_SSE;  
   
                 if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))  
                         cpu_flags &= ~XVID_CPU_SSE2;  
 #endif  
         }  
   
         if ((init_param->cpu_flags & XVID_CPU_CHKONLY))  
         {  
                 init_param->cpu_flags = cpu_flags;  
                 return XVID_ERR_OK;  
         }  
   
         init_param->cpu_flags = cpu_flags;  
168    
169            cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags();
170    
171          /* Initialize the function pointers */          /* Initialize the function pointers */
172          idct_int32_init();          idct_int32_init();
# Line 214  Line 197 
197          transfer_8to16copy = transfer_8to16copy_c;          transfer_8to16copy = transfer_8to16copy_c;
198          transfer_16to8copy = transfer_16to8copy_c;          transfer_16to8copy = transfer_16to8copy_c;
199          transfer_8to16sub  = transfer_8to16sub_c;          transfer_8to16sub  = transfer_8to16sub_c;
200            transfer_8to16subro  = transfer_8to16subro_c;
201          transfer_8to16sub2 = transfer_8to16sub2_c;          transfer_8to16sub2 = transfer_8to16sub2_c;
202          transfer_16to8add  = transfer_16to8add_c;          transfer_16to8add  = transfer_16to8add_c;
203          transfer8x8_copy   = transfer8x8_copy_c;          transfer8x8_copy   = transfer8x8_copy_c;
# Line 241  Line 225 
225          interpolate8x8_avg4 = interpolate8x8_avg4_c;          interpolate8x8_avg4 = interpolate8x8_avg4_c;
226    
227          /* reduced resoltuion */          /* reduced resoltuion */
   
228          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;
229          add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;          add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;
 #ifdef ARCH_X86  
         vfilter_31 = xvid_VFilter_31_x86;  
         hfilter_31 = xvid_HFilter_31_x86;  
 #else  
230          vfilter_31 = xvid_VFilter_31_C;          vfilter_31 = xvid_VFilter_31_C;
231          hfilter_31 = xvid_HFilter_31_C;          hfilter_31 = xvid_HFilter_31_C;
 #endif  
232          filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;          filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;
233          filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;          filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;
234    
# Line 306  Line 284 
284          dev16    = dev16_c;          dev16    = dev16_c;
285          sad16v   = sad16v_c;          sad16v   = sad16v_c;
286    
287  //      Halfpel8_Refine = Halfpel8_Refine_c;  /*      Halfpel8_Refine = Halfpel8_Refine_c; */
288    
289    #if defined(ARCH_IS_IA32)
290    
291  #ifdef ARCH_X86          if ((cpu_flags & XVID_CPU_ASM)) {
292                    vfilter_31 = xvid_VFilter_31_x86;
293                    hfilter_31 = xvid_HFilter_31_x86;
294            }
295    
296          if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||          if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||
297                  (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||                  (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||
# Line 318  Line 301 
301                  emms = emms_mmx;                  emms = emms_mmx;
302          }          }
303    
304          if ((cpu_flags & XVID_CPU_MMX) > 0) {          if ((cpu_flags & XVID_CPU_MMX)) {
305    
306                  /* Forward and Inverse Discrete Cosine Transformation functions */                  /* Forward and Inverse Discrete Cosine Transformation functions */
307                  fdct = fdct_mmx;                  fdct = fdct_mmx;
308                  idct = idct_mmx;                  idct = simple_idct_mmx;
309    
310                  /* Quantization related functions */                  /* Quantization related functions */
311                  quant_intra   = quant_intra_mmx;                  quant_intra   = quant_intra_mmx;
# Line 339  Line 322 
322                  transfer_8to16copy = transfer_8to16copy_mmx;                  transfer_8to16copy = transfer_8to16copy_mmx;
323                  transfer_16to8copy = transfer_16to8copy_mmx;                  transfer_16to8copy = transfer_16to8copy_mmx;
324                  transfer_8to16sub  = transfer_8to16sub_mmx;                  transfer_8to16sub  = transfer_8to16sub_mmx;
325                    transfer_8to16subro  = transfer_8to16subro_mmx;
326                  transfer_8to16sub2 = transfer_8to16sub2_mmx;                  transfer_8to16sub2 = transfer_8to16sub2_mmx;
327                  transfer_16to8add  = transfer_16to8add_mmx;                  transfer_16to8add  = transfer_16to8add_mmx;
328                  transfer8x8_copy   = transfer8x8_copy_mmx;                  transfer8x8_copy   = transfer8x8_copy_mmx;
# Line 388  Line 372 
372                  sad8bi  = sad8bi_mmx;                  sad8bi  = sad8bi_mmx;
373                  dev16    = dev16_mmx;                  dev16    = dev16_mmx;
374                  sad16v   = sad16v_mmx;                  sad16v   = sad16v_mmx;
   
375          }          }
376    
377          /* these 3dnow functions are faster than mmx, but slower than xmm. */          /* these 3dnow functions are faster than mmx, but slower than xmm. */
378          if ((cpu_flags & XVID_CPU_3DNOW) > 0) {          if ((cpu_flags & XVID_CPU_3DNOW)) {
379    
380                    emms = emms_3dn;
381    
382                  /* ME functions */                  /* ME functions */
383                  sad16bi = sad16bi_3dn;                  sad16bi = sad16bi_3dn;
# Line 403  Line 388 
388          }          }
389    
390    
391          if ((cpu_flags & XVID_CPU_MMXEXT) > 0) {          if ((cpu_flags & XVID_CPU_MMXEXT)) {
392    
393                  /* Inverse DCT */                  /* Inverse DCT */
394    #if 0 /* We don't use  Walken idct anymore! */
395                  idct = idct_xmm;                  idct = idct_xmm;
396    #endif
397    
398                  /* Interpolation */                  /* Interpolation */
399                  interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_xmm;                  interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_xmm;
# Line 441  Line 428 
428                  sad16v   = sad16v_xmm;                  sad16v   = sad16v_xmm;
429          }          }
430    
431          if ((cpu_flags & XVID_CPU_3DNOW) > 0) {          if ((cpu_flags & XVID_CPU_3DNOW)) {
432    
433                  /* Interpolation */                  /* Interpolation */
434                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
# Line 449  Line 436 
436                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
437          }          }
438    
439          if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) {          if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
440    
441                  /* Inverse DCT */                  /* Inverse DCT */
442    #if 0 /* We don't use  Walken idct anymore! */
443                  idct =  idct_3dne;                  idct =  idct_3dne;
444    #endif
445    
446                  /* Buffer transfer */                  /* Buffer transfer */
447                  transfer_8to16copy =  transfer_8to16copy_3dne;                  transfer_8to16copy =  transfer_8to16copy_3dne;
448                  transfer_16to8copy = transfer_16to8copy_3dne;                  transfer_16to8copy = transfer_16to8copy_3dne;
449                  transfer_8to16sub =  transfer_8to16sub_3dne;                  transfer_8to16sub =  transfer_8to16sub_3dne;
450                    transfer_8to16subro =  transfer_8to16subro_3dne;
451                  transfer_8to16sub2 =  transfer_8to16sub2_3dne;                  transfer_8to16sub2 =  transfer_8to16sub2_3dne;
452                  transfer_16to8add = transfer_16to8add_3dne;                  transfer_16to8add = transfer_16to8add_3dne;
453                  transfer8x8_copy = transfer8x8_copy_3dne;                  transfer8x8_copy = transfer8x8_copy_3dne;
# Line 485  Line 475 
475          }          }
476    
477    
478          if ((cpu_flags & XVID_CPU_SSE2) > 0) {          if ((cpu_flags & XVID_CPU_SSE2)) {
 #ifdef EXPERIMENTAL_SSE2_CODE  
479    
480                  calc_cbp = calc_cbp_sse2;                  calc_cbp = calc_cbp_sse2;
481    
# Line 496  Line 485 
485                  quant_inter   = quant_inter_sse2;                  quant_inter   = quant_inter_sse2;
486                  dequant_inter = dequant_inter_sse2;                  dequant_inter = dequant_inter_sse2;
487    
488                  /* ME */  #if defined(EXPERIMENTAL_SSE2_CODE)
489                    /* ME; slower than xmm */
490                  sad16    = sad16_sse2;                  sad16    = sad16_sse2;
491                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
492    #endif
493                  /* Forward and Inverse DCT */                  /* Forward and Inverse DCT */
494    #if 0 /* Both function are known to be unprecise, better keep them deactivated */
495                  idct  = idct_sse2;                  idct  = idct_sse2;
496                  fdct = fdct_sse2;                  fdct = fdct_sse2;
497  #endif  #endif
498          }          }
   
499  #endif  #endif
500    
501  #ifdef ARCH_IA64  #if defined(ARCH_IS_IA64)
502          if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines?          if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */
503            idct_ia64_init();            idct_ia64_init();
504            fdct = fdct_ia64;            fdct = fdct_ia64;
505            idct = idct_ia64;   //not yet working, crashes            idct = idct_ia64;   /*not yet working, crashes */
506            interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;            interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
507            interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;            interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
508            interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;            interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
# Line 520  Line 510 
510            sad16bi = sad16bi_ia64;            sad16bi = sad16bi_ia64;
511            sad8 = sad8_ia64;            sad8 = sad8_ia64;
512            dev16 = dev16_ia64;            dev16 = dev16_ia64;
513  //        Halfpel8_Refine = Halfpel8_Refine_ia64;  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */
514            quant_intra = quant_intra_ia64;            quant_intra = quant_intra_ia64;
515            dequant_intra = dequant_intra_ia64;            dequant_intra = dequant_intra_ia64;
516            quant_inter = quant_inter_ia64;            quant_inter = quant_inter_ia64;
# Line 531  Line 521 
521            transfer_8to16sub2 = transfer_8to16sub2_ia64;            transfer_8to16sub2 = transfer_8to16sub2_ia64;
522            transfer_16to8add = transfer_16to8add_ia64;            transfer_16to8add = transfer_16to8add_ia64;
523            transfer8x8_copy = transfer8x8_copy_ia64;            transfer8x8_copy = transfer8x8_copy_ia64;
524            DEBUG("Using IA-64 assembler routines.\n");            DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines.");
525          }          }
526  #endif  #endif
527    
528  #ifdef ARCH_PPC  #if defined(ARCH_IS_PPC)
529  #ifdef ARCH_PPC_ALTIVEC          if ((cpu_flags & XVID_CPU_ASM))
530            {
531                    calc_cbp = calc_cbp_ppc;
532            }
533    
534            if ((cpu_flags & XVID_CPU_ALTIVEC))
535            {
536          calc_cbp = calc_cbp_altivec;          calc_cbp = calc_cbp_altivec;
537          fdct = fdct_altivec;          fdct = fdct_altivec;
538          idct = idct_altivec;          idct = idct_altivec;
# Line 544  Line 540 
540          sad16 = sad16_altivec;          sad16 = sad16_altivec;
541          sad8 = sad8_altivec;          sad8 = sad8_altivec;
542          dev16 = dev16_altivec;          dev16 = dev16_altivec;
543  #else          }
         calc_cbp = calc_cbp_ppc;  
544  #endif  #endif
545    
546    #if defined(_DEBUG)
547        xvid_debug = init->debug;
548  #endif  #endif
549    
550          return XVID_ERR_OK;      return 0;
551  }  }
552    
553    
554    static int
555    xvid_gbl_info(xvid_gbl_info_t * info)
556    {
557            if (XVID_MAJOR(info->version) != 1) /* v1.x.x */
558                    return XVID_ERR_VERSION;
559    
560            info->actual_version = XVID_VERSION;
561            info->build = "dev-api-4";
562            info->cpu_flags = detect_cpu_flags();
563    
564    #if defined(_SMP) && defined(WIN32)
565            info->num_threads = pthread_num_processors_np();;
566    #else
567            info->num_threads = 0;
568    #endif
569    
570            return 0;
571    }
572    
573    
574  static int  static int
575  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)  xvid_gbl_convert(xvid_gbl_convert_t* convert)
576  {  {
577          // const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);          int width;
578          const int width = convert->width;          int height;
579          const int height = convert->height;          int width2;
580          const int width2 = convert->width/2;          int height2;
         const int height2 = convert->height/2;  
581          IMAGE img;          IMAGE img;
582    
583          switch (convert->input.colorspace & ~XVID_CSP_VFLIP)          if (XVID_MAJOR(convert->version) != 1)   /* v1.x.x */
584                  return XVID_ERR_VERSION;
585    
586    #if 0
587            const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);
588    #endif
589            width = convert->width;
590            height = convert->height;
591            width2 = convert->width/2;
592            height2 = convert->height/2;
593    
594            switch (convert->input.csp & ~XVID_CSP_VFLIP)
595          {          {
596                  case XVID_CSP_YV12 :                  case XVID_CSP_YV12 :
597                          img.y = convert->input.y;                          img.y = convert->input.plane[0];
598                          img.v = (uint8_t*)convert->input.y + width*height;                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;
599                          img.u = (uint8_t*)convert->input.y + width*height + width2*height2;                          img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2;
600                          image_output(&img, width, height, width,                          image_output(&img, width, height, width,
601                                                  convert->output.y, convert->output.y_stride,                                                  (uint8_t**)convert->output.plane, convert->output.stride,
602                                                  convert->output.colorspace, convert->interlacing);                                                  convert->output.csp, convert->interlacing);
603                          break;                          break;
604    
605                  default :                  default :
# Line 581  Line 608 
608    
609    
610          emms();          emms();
611          return XVID_ERR_OK;          return 0;
612  }  }
613    
614    
# Line 630  Line 657 
657  {  {
658          int i, diff = 0;          int i, diff = 0;
659          for (i = 0; i < size; i++)          for (i = 0; i < size; i++)
660                  diff += ABS(blockA[i]-blockB[i]);                  diff += abs(blockA[i]-blockB[i]);
661          return diff;          return diff;
662  }  }
663    
# Line 643  Line 670 
670  #define TEST_FDCT  (TEST_FORWARD)  #define TEST_FDCT  (TEST_FORWARD)
671  #define TEST_IDCT  (0)  #define TEST_IDCT  (0)
672    
673  int test_transform(void * funcA, void * funcB, const char * nameB,  static int test_transform(void * funcA, void * funcB, const char * nameB,
674                                     int test, int flags)                                     int test, int flags)
675  {  {
676          int i;          int i;
# Line 723  Line 750 
750  #define TEST_DEQUANT_INTRA      (TEST_INTRA)  #define TEST_DEQUANT_INTRA      (TEST_INTRA)
751  #define TEST_DEQUANT_INTER      (0)  #define TEST_DEQUANT_INTER      (0)
752    
753  int test_quant(void * funcA, void * funcB, const char * nameB,  static int test_quant(void * funcA, void * funcB, const char * nameB,
754                             int test, int flags)                             int test, int flags)
755  {  {
756          int q,i;          int q,i;
757          int64_t timeSTART;          int64_t timeSTART;
758          int64_t timeA = 0;          int64_t timeA = 0;
759          int64_t timeB = 0;          int64_t timeB = 0;
760          int retA, retB;          int retA = 0, retB = 0;
761          DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
762          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
763          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
# Line 804  Line 831 
831    
832  int xvid_init_test(int flags)  int xvid_init_test(int flags)
833  {  {
834    #if defined(ARCH_IS_IA32)
835          int cpu_flags;          int cpu_flags;
836    #endif
837    
838          srand(time(0));          printf("XviD tests\n\n");
839    
840          printf("xvid_init_test\n");  #if defined(ARCH_IS_IA32)
841            cpu_flags = detect_cpu_flags();
842    #endif
843    
 #if defined(ARCH_X86)  
         cpu_flags = check_cpu_features();  
844          idct_int32_init();          idct_int32_init();
845          emms_mmx();          emms();
846    
847            srand(time(0));
848    
849            /* fDCT test */
850          printf("--- fdct ---\n");          printf("--- fdct ---\n");
851                  test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);                  test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
852    
853    #if defined(ARCH_IS_IA32)
854          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
855                  test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);                  test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
856          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
857                  test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);                  test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
858    #endif
859    
860            /* iDCT test */
861          printf("\n--- idct ---\n");          printf("\n--- idct ---\n");
862                  test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);                  test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
863    
864    #if defined(ARCH_IS_IA32)
865          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
866                  test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);                  test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
867          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
# Line 832  Line 870 
870                  test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);                  test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
871          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
872                  test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);                  test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
873    #endif
874    
875            /* Intra quantization test */
876          printf("\n--- quant intra ---\n");          printf("\n--- quant intra ---\n");
877                  test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);                  test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
878    
879    #if defined(ARCH_IS_IA32)
880          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
881                  test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);                  test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
882          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
883                  test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);                  test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
884          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
885                  test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);                  test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
886    #endif
887    
888            /* Inter quantization test */
889          printf("\n--- quant inter ---\n");          printf("\n--- quant inter ---\n");
890                  test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);                  test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
891    
892    #if defined(ARCH_IS_IA32)
893          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
894                  test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);                  test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
895          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
896                  test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);                  test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);
897          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
898                  test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);                  test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);
899    #endif
900    
901            /* Intra dequantization test */
902          printf("\n--- dequant intra ---\n");          printf("\n--- dequant intra ---\n");
903                  test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
904    
905    #if defined(ARCH_IS_IA32)
906          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
907                  test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
908          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
# Line 861  Line 911 
911                  test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
912          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
913                  test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);
914    #endif
915    
916            /* Inter dequantization test */
917          printf("\n--- dequant inter ---\n");          printf("\n--- dequant inter ---\n");
918                  test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);                  test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
919    
920    #if defined(ARCH_IS_IA32)
921          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
922                  test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);                  test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
923          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
# Line 872  Line 926 
926                  test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);                  test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
927          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
928                  test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);                  test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
929    #endif
930    
931          printf("\n--- quant4_intra ---\n");          /* Intra quantization test */
932            printf("\n--- quant4 intra ---\n");
933                  test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);                  test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
934    
935    #if defined(ARCH_IS_IA32)
936          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
937                  test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);                  test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
938          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
939                  test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);                  test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
940    #endif
941    
942          printf("\n--- quant4_inter ---\n");          /* Inter quantization test */
943            printf("\n--- quant4 inter ---\n");
944                  test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);                  test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
945    
946    #if defined(ARCH_IS_IA32)
947          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
948                  test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);                  test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
949          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
950                  test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);                  test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
951    #endif
952    
953          printf("\n--- dequant4_intra ---\n");          /* Intra dequantization test */
954            printf("\n--- dequant4 intra ---\n");
955                  test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
956    
957    #if defined(ARCH_IS_IA32)
958          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
959                  test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
960          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
961                  test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);                  test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
962    #endif
963    
964          printf("\n--- dequant4_inter ---\n");          /* Inter dequantization test */
965            printf("\n--- dequant4 inter ---\n");
966                  test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);                  test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
967    
968    #if defined(ARCH_IS_IA32)
969          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
970                  test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);                  test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
971          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
972                  test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);                  test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
   
         emms_mmx();  
   
973  #endif  #endif
974    
975          return XVID_ERR_OK;          emms();
976    
977            return 0;
978  }  }
979    
980    
981    /*****************************************************************************
982     * XviD Global Entry point
983     *
984     * Well this function initialize all internal function pointers according
985     * to the CPU features forced by the library client or autodetected (depending
986     * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
987     * image colorspace transformation tables.
988     *
989     ****************************************************************************/
990    
991    
992  int  int
993  xvid_init(void *handle,  xvid_global(void *handle,
994                    int opt,                    int opt,
995                    void *param1,                    void *param1,
996                    void *param2)                    void *param2)
997  {  {
998          switch(opt)          switch(opt)
999          {          {
1000                  case XVID_INIT_INIT :                  case XVID_GBL_INIT :
1001                          return xvid_init_init((XVID_INIT_PARAM*)param1);                          return xvid_gbl_init((xvid_gbl_init_t*)param1);
1002    
1003                  case XVID_INIT_CONVERT :          case XVID_GBL_INFO :
1004                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);              return xvid_gbl_info((xvid_gbl_info_t*)param1);
1005    
1006                  case XVID_INIT_TEST :                  case XVID_GBL_CONVERT :
1007                          return xvid_init_test((int)param1);                          return xvid_gbl_convert((xvid_gbl_convert_t*)param1);
1008    
1009                    case XVID_GBL_TEST :
1010                    {
1011                            ptr_t flags = (ptr_t)param1;
1012                            return xvid_init_test((int)flags);
1013                    }
1014                  default :                  default :
1015                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
1016          }          }
# Line 948  Line 1033 
1033                          void *param2)                          void *param2)
1034  {  {
1035          switch (opt) {          switch (opt) {
         case XVID_DEC_DECODE:  
                 return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2);  
   
1036          case XVID_DEC_CREATE:          case XVID_DEC_CREATE:
1037                  return decoder_create((XVID_DEC_PARAM *) param1);                  return decoder_create((xvid_dec_create_t *) param1);
1038    
1039          case XVID_DEC_DESTROY:          case XVID_DEC_DESTROY:
1040                  return decoder_destroy((DECODER *) handle);                  return decoder_destroy((DECODER *) handle);
1041    
1042            case XVID_DEC_DECODE:
1043                    return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);
1044    
1045          default:          default:
1046                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1047          }          }
# Line 982  Line 1067 
1067          switch (opt) {          switch (opt) {
1068          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1069    
1070                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)                  return enc_encode((Encoder *) handle,
1071                  return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,                                                            (xvid_enc_frame_t *) param1,
1072                                                            (XVID_ENC_STATS *) param2);                                                            (xvid_enc_stats_t *) param2);
                 else  
                 return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,  
                                                           (XVID_ENC_STATS *) param2);  
1073    
1074          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:
1075                  return encoder_create((XVID_ENC_PARAM *) param1);                  return enc_create((xvid_enc_create_t *) param1);
1076    
1077          case XVID_ENC_DESTROY:          case XVID_ENC_DESTROY:
1078                  return encoder_destroy((Encoder *) handle);                  return enc_destroy((Encoder *) handle);
1079    
1080          default:          default:
1081                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;

Legend:
Removed from v.1.33.2.21  
changed lines
  Added in v.1.45.2.7

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