[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.45.2.22, Sun Nov 30 16:13:15 2003 UTC revision 1.47, Wed Jun 11 14:10:55 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   *   *
  *  Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>  
  *  
6   *  This program is free software ; you can redistribute it and/or modify   *  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   *  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   *  the Free Software Foundation ; either version 2 of the License, or
# Line 39  Line 37 
37  #include "image/reduced.h"  #include "image/reduced.h"
38  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
39  #include "utils/mbfunctions.h"  #include "utils/mbfunctions.h"
40  #include "quant/quant.h"  #include "quant/quant_h263.h"
41    #include "quant/quant_mpeg4.h"
42  #include "motion/motion.h"  #include "motion/motion.h"
43  #include "motion/sad.h"  #include "motion/sad.h"
44  #include "utils/emms.h"  #include "utils/emms.h"
45  #include "utils/timer.h"  #include "utils/timer.h"
46  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
 #include "image/qpel.h"  
   
 #if defined(_DEBUG)  
 unsigned int xvid_debug = 0; /* xvid debug mask */  
 #endif  
47    
48  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
49    
50  #if defined(_MSC_VER)  #if defined(_MSC_VER)
51  #       include <windows.h>  #       include <windows.h>
52  #else  #else
# Line 158  Line 153 
153    
154    
155  static  static
156  int xvid_gbl_init(xvid_gbl_init_t * init)  int xvid_init_init(XVID_INIT_PARAM * init_param)
157    {
158            int cpu_flags;
159    
160            /* 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            /* Do we have to force CPU features  ? */
167            if ((init_param->cpu_flags & XVID_CPU_FORCE)) {
168    
169                    cpu_flags = init_param->cpu_flags;
170    
171            } else {
172    
173                    cpu_flags = detect_cpu_flags();
174            }
175    
176            if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
177  {  {
178          unsigned int cpu_flags;                  init_param->cpu_flags = cpu_flags;
179                    return XVID_ERR_OK;
180            }
181    
182          if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */          init_param->cpu_flags = cpu_flags;
                 return XVID_ERR_VERSION;  
183    
         cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags();  
184    
185          /* Initialize the function pointers */          /* Initialize the function pointers */
186          idct_int32_init();          idct_int32_init();
# Line 181  Line 196 
196          /* Restore FPU context : emms_c is a nop functions */          /* Restore FPU context : emms_c is a nop functions */
197          emms = emms_c;          emms = emms_c;
198    
         /* Qpel stuff */  
         xvid_QP_Funcs = &xvid_QP_Funcs_C;  
         xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C;  
         xvid_Init_QP();  
   
199          /* Quantization functions */          /* Quantization functions */
200          quant_h263_intra   = quant_h263_intra_c;          quant_intra   = quant_intra_c;
201          quant_h263_inter   = quant_h263_inter_c;          dequant_intra = dequant_intra_c;
202          dequant_h263_intra = dequant_h263_intra_c;          quant_inter   = quant_inter_c;
203          dequant_h263_inter = dequant_h263_inter_c;          dequant_inter = dequant_inter_c;
204    
205          quant_mpeg_intra   = quant_mpeg_intra_c;          quant4_intra   = quant4_intra_c;
206          quant_mpeg_inter   = quant_mpeg_inter_c;          dequant4_intra = dequant4_intra_c;
207          dequant_mpeg_intra = dequant_mpeg_intra_c;          quant4_inter   = quant4_inter_c;
208          dequant_mpeg_inter = dequant_mpeg_inter_c;          dequant4_inter = dequant4_inter_c;
209    
210          /* Block transfer related functions */          /* Block transfer related functions */
211          transfer_8to16copy = transfer_8to16copy_c;          transfer_8to16copy = transfer_8to16copy_c;
# Line 228  Line 238 
238          interpolate8x8_avg2 = interpolate8x8_avg2_c;          interpolate8x8_avg2 = interpolate8x8_avg2_c;
239          interpolate8x8_avg4 = interpolate8x8_avg4_c;          interpolate8x8_avg4 = interpolate8x8_avg4_c;
240    
241          /* reduced resolution */          /* reduced resoltuion */
242          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;          copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;
243          add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;          add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;
244          vfilter_31 = xvid_VFilter_31_C;          vfilter_31 = xvid_VFilter_31_C;
# Line 287  Line 297 
297          sad8bi     = sad8bi_c;          sad8bi     = sad8bi_c;
298          dev16      = dev16_c;          dev16      = dev16_c;
299          sad16v     = sad16v_c;          sad16v     = sad16v_c;
300          sse8_16bit = sse8_16bit_c;  
301    /*      Halfpel8_Refine = Halfpel8_Refine_c; */
302    
303  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
304    
305          if ((cpu_flags & XVID_CPU_ASM)) {          if ((cpu_flags & XVID_CPU_ASM))
306            {
307                  vfilter_31 = xvid_VFilter_31_x86;                  vfilter_31 = xvid_VFilter_31_x86;
308                  hfilter_31 = xvid_HFilter_31_x86;                  hfilter_31 = xvid_HFilter_31_x86;
309          }          }
# Line 307  Line 319 
319          if ((cpu_flags & XVID_CPU_MMX)) {          if ((cpu_flags & XVID_CPU_MMX)) {
320    
321                  /* Forward and Inverse Discrete Cosine Transformation functions */                  /* Forward and Inverse Discrete Cosine Transformation functions */
322                  fdct = fdct_mmx_skal;                  fdct = fdct_mmx;
323                  idct = idct_mmx;                  idct = idct_mmx;
324    
                 /* Qpel stuff */  
                 xvid_QP_Funcs = &xvid_QP_Funcs_mmx;  
                 xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx;  
   
325                  /* Quantization related functions */                  /* Quantization related functions */
326                  quant_h263_intra   = quant_h263_intra_mmx;                  quant_intra   = quant_intra_mmx;
327                  quant_h263_inter   = quant_h263_inter_mmx;                  dequant_intra = dequant_intra_mmx;
328                  dequant_h263_intra = dequant_h263_intra_mmx;                  quant_inter   = quant_inter_mmx;
329                  dequant_h263_inter = dequant_h263_inter_mmx;                  dequant_inter = dequant_inter_mmx;
330    
331                  quant_mpeg_intra   = quant_mpeg_intra_mmx;                  quant4_intra   = quant4_intra_mmx;
332                  quant_mpeg_inter   = quant_mpeg_inter_mmx;                  dequant4_intra = dequant4_intra_mmx;
333                  dequant_mpeg_intra = dequant_mpeg_intra_mmx;                  quant4_inter   = quant4_inter_mmx;
334                  dequant_mpeg_inter = dequant_mpeg_inter_mmx;                  dequant4_inter = dequant4_inter_mmx;
335    
336                  /* Block related functions */                  /* Block related functions */
337                  transfer_8to16copy = transfer_8to16copy_mmx;                  transfer_8to16copy = transfer_8to16copy_mmx;
# Line 379  Line 387 
387                  sad8bi  = sad8bi_mmx;                  sad8bi  = sad8bi_mmx;
388                  dev16    = dev16_mmx;                  dev16    = dev16_mmx;
389                  sad16v   = sad16v_mmx;                  sad16v   = sad16v_mmx;
                 sse8_16bit = sse8_16bit_mmx;  
390          }          }
391    
392          /* these 3dnow functions are faster than mmx, but slower than xmm. */          /* these 3dnow functions are faster than mmx, but slower than xmm. */
# Line 398  Line 405 
405    
406          if ((cpu_flags & XVID_CPU_MMXEXT)) {          if ((cpu_flags & XVID_CPU_MMXEXT)) {
407    
408                  /* DCT */                  /* Inverse DCT */
                 fdct = fdct_xmm_skal;  
409                  idct = idct_xmm;                  idct = idct_xmm;
410    
411                  /* Interpolation */                  /* Interpolation */
# Line 412  Line 418 
418                  add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm;                  add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm;
419    
420                  /* Quantization */                  /* Quantization */
421                  quant_mpeg_intra = quant_mpeg_intra_xmm;                  quant4_intra = quant4_intra_xmm;
422                  quant_mpeg_inter = quant_mpeg_inter_xmm;                  quant4_inter = quant4_inter_xmm;
423    
424                  dequant_h263_intra = dequant_h263_intra_xmm;                  dequant_intra = dequant_intra_xmm;
425                  dequant_h263_inter = dequant_h263_inter_xmm;                  dequant_inter = dequant_inter_xmm;
426    
427                  /* Buffer transfer */                  /* Buffer transfer */
428                  transfer_8to16sub2 = transfer_8to16sub2_xmm;                  transfer_8to16sub2 = transfer_8to16sub2_xmm;
# Line 458  Line 464 
464                  transfer8x8_copy = transfer8x8_copy_3dne;                  transfer8x8_copy = transfer8x8_copy_3dne;
465    
466                  /* Quantization */                  /* Quantization */
467                  quant_h263_intra = quant_h263_intra_3dne;                  dequant4_intra = dequant4_intra_3dne;
468                  quant_h263_inter = quant_h263_inter_3dne;                  dequant4_inter = dequant4_inter_3dne;
469                  dequant_mpeg_intra = dequant_mpeg_intra_3dne;                  quant_intra = quant_intra_3dne;
470                  dequant_mpeg_inter = dequant_mpeg_inter_3dne;                  quant_inter = quant_inter_3dne;
471                  dequant_h263_intra = dequant_h263_intra_3dne;                  dequant_intra = dequant_intra_3dne;
472                  dequant_h263_inter = dequant_h263_inter_3dne;                  dequant_inter = dequant_inter_3dne;
473    
474                  /* ME functions */                  /* ME functions */
475                  calc_cbp = calc_cbp_3dne;                  calc_cbp = calc_cbp_3dne;
# Line 479  Line 485 
485                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne;
486          }          }
487    
488  #if defined(EXPERIMENTAL_SSE2_CODE) /* mark the whole SSE2 stuff as experimental. At least on  
                                                                            my P4, it crashes... */  
489          if ((cpu_flags & XVID_CPU_SSE2)) {          if ((cpu_flags & XVID_CPU_SSE2)) {
490    
491    #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                  calc_cbp = calc_cbp_sse2;                  calc_cbp = calc_cbp_sse2;
495    
496                  /* Quantization */                  /* Quantization */
497                  quant_h263_intra   = quant_h263_intra_sse2;                  quant_intra   = quant_intra_sse2;
498                  quant_h263_inter   = quant_h263_inter_sse2;                  dequant_intra = dequant_intra_sse2;
499                  dequant_h263_intra = dequant_h263_intra_sse2;                  quant_inter   = quant_inter_sse2;
500                  dequant_h263_inter = dequant_h263_inter_sse2;                  dequant_inter = dequant_inter_sse2;
501    
502                  /* SAD operators */                  /* ME; slower than xmm */
503                  sad16    = sad16_sse2;                  sad16    = sad16_sse2;
504                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
   
                 /* DCT operators */  
                 fdct = fdct_sse2_skal;  
                 idct = idct_sse2_dmitry;  
         }  
505  #endif  #endif
506                    /* Forward and Inverse DCT */
507                    /* idct  = idct_sse2;
508                    /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */
509            }
510  #endif  #endif
511    
512  #if defined(ARCH_IS_IA64)  #if defined(ARCH_IS_IA64)
# Line 515  Line 522 
522            sad8 = sad8_ia64;            sad8 = sad8_ia64;
523            dev16 = dev16_ia64;            dev16 = dev16_ia64;
524  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */
525            quant_h263_intra = quant_h263_intra_ia64;            quant_intra = quant_intra_ia64;
526            quant_h263_inter = quant_h263_inter_ia64;            dequant_intra = dequant_intra_ia64;
527            dequant_h263_intra = dequant_h263_intra_ia64;            quant_inter = quant_inter_ia64;
528            dequant_h263_inter = dequant_h263_inter_ia64;            dequant_inter = dequant_inter_ia64;
529            transfer_8to16copy = transfer_8to16copy_ia64;            transfer_8to16copy = transfer_8to16copy_ia64;
530            transfer_16to8copy = transfer_16to8copy_ia64;            transfer_16to8copy = transfer_16to8copy_ia64;
531            transfer_8to16sub = transfer_8to16sub_ia64;            transfer_8to16sub = transfer_8to16sub_ia64;
532            transfer_8to16sub2 = transfer_8to16sub2_ia64;            transfer_8to16sub2 = transfer_8to16sub2_ia64;
533            transfer_16to8add = transfer_16to8add_ia64;            transfer_16to8add = transfer_16to8add_ia64;
534            transfer8x8_copy = transfer8x8_copy_ia64;            transfer8x8_copy = transfer8x8_copy_ia64;
535              DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines.");
536          }          }
537  #endif  #endif
538    
# Line 546  Line 554 
554          }          }
555  #endif  #endif
556    
557  #if defined(_DEBUG)          return XVID_ERR_OK;
558      xvid_debug = init->debug;  }
559  #endif  
560    
561    
562    static int
563    xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
564    {
565    /*
566            const int flip1 =
567                    (convert->input.colorspace & XVID_CSP_VFLIP) ^
568                    (convert->output.colorspace & XVID_CSP_VFLIP);
569    */
570            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;      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  static int  
647  xvid_gbl_info(xvid_gbl_info_t * info)  #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    static int test_transform(void * funcA, void * funcB, const char * nameB,
656                                       int test, int flags)
657  {  {
658          if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */          int i;
659                  return XVID_ERR_VERSION;          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    
         info->actual_version = XVID_VERSION;  
         info->build = "xvid-1.0.0";  
         info->cpu_flags = detect_cpu_flags();  
671    
672  #if defined(_SMP) && defined(WIN32)          if ((test & TEST_FORWARD))      /* forward */
673          info->num_threads = pthread_num_processors_np();;          {
674  #else                  min = -256;
675          info->num_threads = 0;                  max = 255;
676  #endif          }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;          return 0;
725  }  }
726    
727    
728  static int  #define TEST_QUANT      0x00000001      /* forward quantization */
729  xvid_gbl_convert(xvid_gbl_convert_t* convert)  #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    static int test_quant(void * funcA, void * funcB, const char * nameB,
736                               int test, int flags)
737  {  {
738          int width;          int q,i;
739          int height;          int64_t timeSTART;
740          int width2;          int64_t timeA = 0;
741          int height2;          int64_t timeB = 0;
742          IMAGE img;          int retA = 0, retB = 0;
743            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 (XVID_VERSION_MAJOR(convert->version) != 1)   /* v1.x.x */          if ((test & TEST_QUANT))        /* quant */
751                return XVID_ERR_VERSION;          {
752                    min = -2048;
753                    max = 2047;
754            }else{          /* dequant */
755                    min = -256;
756                    max = 255;
757            }
758    
759  #if 0          for (q = 1; q <= 31; q++)       /* quantizer */
760          const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);          {
761  #endif                  for (i = min; i < max; i++)     /* input coeff */
762          width = convert->width;                  {
763          height = convert->height;                          if ((flags & XVID_TEST_RANDOM))
764          width2 = convert->width/2;                          {
765          height2 = convert->height/2;                                  random16(arrayX, 64, min, max);
766                            }else{
767                                    fill16(arrayX, 64, i);
768                            }
769    
770          switch (convert->input.csp & ~XVID_CSP_VFLIP)                          if ((test & TEST_INTRA))        /* intra */
771          {          {
772                  case XVID_CSP_YV12 :                                  timeSTART = read_counter();
773                          img.y = convert->input.plane[0];                                  ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
774                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;                                  timeA += read_counter() - timeSTART;
775                          img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2;  
776                          image_output(&img, width, height, width,                                  timeSTART = read_counter();
777                                                  (uint8_t**)convert->output.plane, convert->output.stride,                                  ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
778                                                  convert->output.csp, convert->interlacing);                                  timeB += read_counter() - timeSTART;
779                          break;                          }
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                  default :                          /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
792                          return XVID_ERR_FORMAT;                          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    
         emms();  
809          return 0;          return 0;
810  }  }
811    
812  /*****************************************************************************  
813   * XviD Global Entry point  
814   *  int xvid_init_test(int flags)
815   * Well this function initialize all internal function pointers according  {
816   * to the CPU features forced by the library client or autodetected (depending  #if defined(ARCH_IS_IA32)
817   * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all          int cpu_flags;
818   * image colorspace transformation tables.  #endif
819   *  
820   ****************************************************************************/          printf("XviD tests\n\n");
821    
822    #if defined(ARCH_IS_IA32)
823            cpu_flags = detect_cpu_flags();
824    #endif
825    
826            idct_int32_init();
827            emms();
828    
829            srand(time(0));
830    
831            /* fDCT test */
832            printf("--- fdct ---\n");
833                    test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
834    
835    #if defined(ARCH_IS_IA32)
836            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    #endif
841    
842            /* iDCT test */
843            printf("\n--- idct ---\n");
844                    test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
845    
846    #if defined(ARCH_IS_IA32)
847            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    #endif
856    
857            /* Intra quantization test */
858            printf("\n--- quant intra ---\n");
859                    test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
860    
861    #if defined(ARCH_IS_IA32)
862            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    #endif
869    
870            /* Inter quantization test */
871            printf("\n--- quant inter ---\n");
872                    test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
873    
874    #if defined(ARCH_IS_IA32)
875            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    #endif
882    
883            /* Intra dequantization test */
884            printf("\n--- dequant intra ---\n");
885                    test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
886    
887    #if defined(ARCH_IS_IA32)
888            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    #endif
897    
898            /* Inter dequantization test */
899            printf("\n--- dequant inter ---\n");
900                    test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
901    
902    #if defined(ARCH_IS_IA32)
903            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    #endif
912    
913            /* Intra quantization test */
914            printf("\n--- quant4 intra ---\n");
915                    test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
916    
917    #if defined(ARCH_IS_IA32)
918            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    #endif
923    
924            /* Inter quantization test */
925            printf("\n--- quant4 inter ---\n");
926                    test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
927    
928    #if defined(ARCH_IS_IA32)
929            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    #endif
934    
935            /* Intra dequantization test */
936            printf("\n--- dequant4 intra ---\n");
937                    test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
938    
939    #if defined(ARCH_IS_IA32)
940            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    #endif
945    
946            /* Inter dequantization test */
947            printf("\n--- dequant4 inter ---\n");
948                    test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
949    
950    #if defined(ARCH_IS_IA32)
951            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    #endif
956    
957            emms();
958    
959            return XVID_ERR_OK;
960    }
961    
962    
963  int  int
964  xvid_global(void *handle,  xvid_init(void *handle,
965                    int opt,                    int opt,
966                    void *param1,                    void *param1,
967                    void *param2)                    void *param2)
968  {  {
969          switch(opt)          switch(opt)
970          {          {
971                  case XVID_GBL_INIT :                  case XVID_INIT_INIT :
972                          return xvid_gbl_init((xvid_gbl_init_t*)param1);                          return xvid_init_init((XVID_INIT_PARAM*)param1);
   
         case XVID_GBL_INFO :  
             return xvid_gbl_info((xvid_gbl_info_t*)param1);  
973    
974                  case XVID_GBL_CONVERT :                  case XVID_INIT_CONVERT :
975                          return xvid_gbl_convert((xvid_gbl_convert_t*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
976    
977                    case XVID_INIT_TEST :
978                    {
979                            ptr_t flags = (ptr_t)param1;
980                            return xvid_init_test((int)flags);
981                    }
982                  default :                  default :
983                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
984          }          }
# Line 664  Line 1001 
1001                          void *param2)                          void *param2)
1002  {  {
1003          switch (opt) {          switch (opt) {
1004            case XVID_DEC_DECODE:
1005                    return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2);
1006    
1007          case XVID_DEC_CREATE:          case XVID_DEC_CREATE:
1008                  return decoder_create((xvid_dec_create_t *) param1);                  return decoder_create((XVID_DEC_PARAM *) param1);
1009    
1010          case XVID_DEC_DESTROY:          case XVID_DEC_DESTROY:
1011                  return decoder_destroy((DECODER *) handle);                  return decoder_destroy((DECODER *) handle);
1012    
         case XVID_DEC_DECODE:  
                 return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);  
   
1013          default:          default:
1014                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1015          }          }
# Line 698  Line 1035 
1035          switch (opt) {          switch (opt) {
1036          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1037    
1038                  return enc_encode((Encoder *) handle,                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)
1039                                                            (xvid_enc_frame_t *) param1,                          return encoder_encode_bframes((Encoder *) handle,
1040                                                            (xvid_enc_stats_t *) param2);                                                                                    (XVID_ENC_FRAME *) param1,
1041                                                                                      (XVID_ENC_STATS *) param2);
1042                    else
1043                            return encoder_encode((Encoder *) handle,
1044                                                                      (XVID_ENC_FRAME *) param1,
1045                                                                      (XVID_ENC_STATS *) param2);
1046    
1047          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:
1048                  return enc_create((xvid_enc_create_t *) param1);                  return encoder_create((XVID_ENC_PARAM *) param1);
1049    
1050          case XVID_ENC_DESTROY:          case XVID_ENC_DESTROY:
1051                  return enc_destroy((Encoder *) handle);                  return encoder_destroy((Encoder *) handle);
1052    
1053          default:          default:
1054                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;

Legend:
Removed from v.1.45.2.22  
changed lines
  Added in v.1.47

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