[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.46, Mon Jun 9 17:07:10 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 = simple_idct_mmx; /* use simple idct by default */
   
                 /* Qpel stuff */  
                 xvid_QP_Funcs = &xvid_QP_Funcs_mmx;  
                 xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx;  
324    
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 */
409                  fdct = fdct_xmm_skal;                  /* idct = idct_xmm; Don't use Walken idct anymore! */
                 idct = idct_xmm;  
410    
411                  /* Interpolation */                  /* Interpolation */
412                  interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_xmm;                  interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_xmm;
# 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 446  Line 452 
452          if ((cpu_flags & XVID_CPU_3DNOWEXT)) {          if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
453    
454                  /* Inverse DCT */                  /* Inverse DCT */
455                  idct =  idct_3dne;                  /* idct =  idct_3dne; Don't use Walken idct anymore */
456    
457                  /* Buffer transfer */                  /* Buffer transfer */
458                  transfer_8to16copy =  transfer_8to16copy_3dne;                  transfer_8to16copy =  transfer_8to16copy_3dne;
# 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                  calc_cbp = calc_cbp_sse2;                  calc_cbp = calc_cbp_sse2;
492    
493                  /* Quantization */                  /* Quantization */
494                  quant_h263_intra   = quant_h263_intra_sse2;                  quant_intra   = quant_intra_sse2;
495                  quant_h263_inter   = quant_h263_inter_sse2;                  dequant_intra = dequant_intra_sse2;
496                  dequant_h263_intra = dequant_h263_intra_sse2;                  quant_inter   = quant_inter_sse2;
497                  dequant_h263_inter = dequant_h263_inter_sse2;                  dequant_inter = dequant_inter_sse2;
498    
499                  /* SAD operators */  #if defined(EXPERIMENTAL_SSE2_CODE)
500                    /* ME; slower than xmm */
501                  sad16    = sad16_sse2;                  sad16    = sad16_sse2;
502                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
   
                 /* DCT operators */  
                 fdct = fdct_sse2_skal;  
                 idct = idct_sse2_dmitry;  
         }  
503  #endif  #endif
504                    /* Forward and Inverse DCT */
505                    /* idct  = idct_sse2;
506                    /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */
507            }
508  #endif  #endif
509    
510  #if defined(ARCH_IS_IA64)  #if defined(ARCH_IS_IA64)
# Line 515  Line 520 
520            sad8 = sad8_ia64;            sad8 = sad8_ia64;
521            dev16 = dev16_ia64;            dev16 = dev16_ia64;
522  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */  /*        Halfpel8_Refine = Halfpel8_Refine_ia64; */
523            quant_h263_intra = quant_h263_intra_ia64;            quant_intra = quant_intra_ia64;
524            quant_h263_inter = quant_h263_inter_ia64;            dequant_intra = dequant_intra_ia64;
525            dequant_h263_intra = dequant_h263_intra_ia64;            quant_inter = quant_inter_ia64;
526            dequant_h263_inter = dequant_h263_inter_ia64;            dequant_inter = dequant_inter_ia64;
527            transfer_8to16copy = transfer_8to16copy_ia64;            transfer_8to16copy = transfer_8to16copy_ia64;
528            transfer_16to8copy = transfer_16to8copy_ia64;            transfer_16to8copy = transfer_16to8copy_ia64;
529            transfer_8to16sub = transfer_8to16sub_ia64;            transfer_8to16sub = transfer_8to16sub_ia64;
530            transfer_8to16sub2 = transfer_8to16sub2_ia64;            transfer_8to16sub2 = transfer_8to16sub2_ia64;
531            transfer_16to8add = transfer_16to8add_ia64;            transfer_16to8add = transfer_16to8add_ia64;
532            transfer8x8_copy = transfer8x8_copy_ia64;            transfer8x8_copy = transfer8x8_copy_ia64;
533              DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines.");
534          }          }
535  #endif  #endif
536    
# Line 546  Line 552 
552          }          }
553  #endif  #endif
554    
555  #if defined(_DEBUG)          return XVID_ERR_OK;
556      xvid_debug = init->debug;  }
557  #endif  
558    
559    
560    static int
561    xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
562    {
563    /*
564            const int flip1 =
565                    (convert->input.colorspace & XVID_CSP_VFLIP) ^
566                    (convert->output.colorspace & XVID_CSP_VFLIP);
567    */
568            const int width = convert->width;
569            const int height = convert->height;
570            const int width2 = convert->width/2;
571            const int height2 = convert->height/2;
572            IMAGE img;
573    
574            switch (convert->input.colorspace & ~XVID_CSP_VFLIP)
575            {
576                    case XVID_CSP_YV12 :
577                            img.y = convert->input.y;
578                            img.v = (uint8_t*)convert->input.y + width*height;
579                            img.u = (uint8_t*)convert->input.y + width*height + width2*height2;
580                            image_output(&img, width, height, width,
581                                                    convert->output.y, convert->output.y_stride,
582                                                    convert->output.colorspace, convert->interlacing);
583                            break;
584    
585                    default :
586                            return XVID_ERR_FORMAT;
587            }
588    
589    
590            emms();
591            return XVID_ERR_OK;
592    }
593    
594    
595    
596    void fill8(uint8_t * block, int size, int value)
597    {
598            int i;
599            for (i = 0; i < size; i++)
600                    block[i] = value;
601    }
602    
603    void fill16(int16_t * block, int size, int value)
604    {
605            int i;
606            for (i = 0; i < size; i++)
607                    block[i] = value;
608    }
609    
610    #define RANDOM(min,max) min + (rand() % (max-min))
611    
612    void random8(uint8_t * block, int size, int min, int max)
613    {
614            int i;
615            for (i = 0; i < size; i++)
616                    block[i] = RANDOM(min,max);
617    }
618    
619    void random16(int16_t * block, int size, int min, int max)
620    {
621            int i;
622            for (i = 0; i < size; i++)
623                    block[i] = RANDOM(min,max);
624    }
625    
626    int compare16(const int16_t * blockA, const int16_t * blockB, int size)
627    {
628            int i;
629            for (i = 0; i < size; i++)
630                    if (blockA[i] != blockB[i])
631                            return 1;
632    
633      return 0;      return 0;
634  }  }
635    
636    int diff16(const int16_t * blockA, const int16_t * blockB, int size)
637    {
638            int i, diff = 0;
639            for (i = 0; i < size; i++)
640                    diff += ABS(blockA[i]-blockB[i]);
641            return diff;
642    }
643    
644  static int  
645  xvid_gbl_info(xvid_gbl_info_t * info)  #define XVID_TEST_RANDOM        0x00000001      /* random input data */
646    #define XVID_TEST_VERBOSE       0x00000002      /* verbose error output */
647    
648    
649    #define TEST_FORWARD    0x00000001      /* intra */
650    #define TEST_FDCT  (TEST_FORWARD)
651    #define TEST_IDCT  (0)
652    
653    static int test_transform(void * funcA, void * funcB, const char * nameB,
654                                       int test, int flags)
655  {  {
656          if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */          int i;
657                  return XVID_ERR_VERSION;          int64_t timeSTART;
658            int64_t timeA = 0;
659            int64_t timeB = 0;
660            DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
661            DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
662            int min, max;
663            int count = 0;
664    
665            int tmp;
666            int min_error = 0x10000*64;
667            int max_error = 0;
668    
         info->actual_version = XVID_VERSION;  
         info->build = "xvid-1.0.0";  
         info->cpu_flags = detect_cpu_flags();  
669    
670  #if defined(_SMP) && defined(WIN32)          if ((test & TEST_FORWARD))      /* forward */
671          info->num_threads = pthread_num_processors_np();;          {
672  #else                  min = -256;
673          info->num_threads = 0;                  max = 255;
674  #endif          }else{          /* inverse */
675                    min = -2048;
676                    max = 2047;
677            }
678    
679            for (i = 0; i < 64*64; i++)
680            {
681                    if ((flags & XVID_TEST_RANDOM))
682                    {
683                            random16(arrayA, 64, min, max);
684                    }else{
685                            fill16(arrayA, 64, i);
686                    }
687                    memcpy(arrayB, arrayA, 64*sizeof(int16_t));
688    
689                    if ((test & TEST_FORWARD))
690                    {
691                            timeSTART = read_counter();
692                            ((fdctFunc*)funcA)(arrayA);
693                            timeA += read_counter() - timeSTART;
694    
695                            timeSTART = read_counter();
696                            ((fdctFunc*)funcB)(arrayB);
697                            timeB += read_counter() - timeSTART;
698                    }
699                    else
700                    {
701                            timeSTART = read_counter();
702                            ((idctFunc*)funcA)(arrayA);
703                            timeA += read_counter() - timeSTART;
704    
705                            timeSTART = read_counter();
706                            ((idctFunc*)funcB)(arrayB);
707                            timeB += read_counter() - timeSTART;
708                    }
709    
710                    tmp = diff16(arrayA, arrayB, 64) / 64;
711                    if (tmp > max_error)
712                            max_error = tmp;
713                    if (tmp < min_error)
714                            min_error = tmp;
715    
716                    count++;
717            }
718    
719            /* print the "average difference" of best/worst transforms */
720            printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error);
721    
722          return 0;          return 0;
723  }  }
724    
725    
726  static int  #define TEST_QUANT      0x00000001      /* forward quantization */
727  xvid_gbl_convert(xvid_gbl_convert_t* convert)  #define TEST_INTRA      0x00000002      /* intra */
728    #define TEST_QUANT_INTRA        (TEST_QUANT|TEST_INTRA)
729    #define TEST_QUANT_INTER        (TEST_QUANT)
730    #define TEST_DEQUANT_INTRA      (TEST_INTRA)
731    #define TEST_DEQUANT_INTER      (0)
732    
733    static int test_quant(void * funcA, void * funcB, const char * nameB,
734                               int test, int flags)
735  {  {
736          int width;          int q,i;
737          int height;          int64_t timeSTART;
738          int width2;          int64_t timeA = 0;
739          int height2;          int64_t timeB = 0;
740          IMAGE img;          int retA = 0, retB = 0;
741            DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
742            DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
743            DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
744            int min, max;
745            int count = 0;
746            int errors = 0;
747    
748          if (XVID_VERSION_MAJOR(convert->version) != 1)   /* v1.x.x */          if ((test & TEST_QUANT))        /* quant */
749                return XVID_ERR_VERSION;          {
750                    min = -2048;
751                    max = 2047;
752            }else{          /* dequant */
753                    min = -256;
754                    max = 255;
755            }
756    
757  #if 0          for (q = 1; q <= 31; q++)       /* quantizer */
758          const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);          {
759  #endif                  for (i = min; i < max; i++)     /* input coeff */
760          width = convert->width;                  {
761          height = convert->height;                          if ((flags & XVID_TEST_RANDOM))
762          width2 = convert->width/2;                          {
763          height2 = convert->height/2;                                  random16(arrayX, 64, min, max);
764                            }else{
765                                    fill16(arrayX, 64, i);
766                            }
767    
768          switch (convert->input.csp & ~XVID_CSP_VFLIP)                          if ((test & TEST_INTRA))        /* intra */
769          {          {
770                  case XVID_CSP_YV12 :                                  timeSTART = read_counter();
771                          img.y = convert->input.plane[0];                                  ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
772                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;                                  timeA += read_counter() - timeSTART;
773                          img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2;  
774                          image_output(&img, width, height, width,                                  timeSTART = read_counter();
775                                                  (uint8_t**)convert->output.plane, convert->output.stride,                                  ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
776                                                  convert->output.csp, convert->interlacing);                                  timeB += read_counter() - timeSTART;
777                          break;                          }
778                            else    /* inter */
779                            {
780                                    timeSTART = read_counter();
781                                    retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q);
782                                    timeA += read_counter() - timeSTART;
783    
784                                    timeSTART = read_counter();
785                                    retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q);
786                                    timeB += read_counter() - timeSTART;
787                            }
788    
789                  default :                          /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
790                          return XVID_ERR_FORMAT;                          if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) ||
791                                    compare16(arrayA, arrayB, 64))
792                            {
793                                    errors++;
794                                    if ((flags & XVID_TEST_VERBOSE))
795                                            printf("%s error: q=%i, i=%i\n", nameB, q, i);
796                            }
797    
798                            count++;
799                    }
800          }          }
801    
802            printf("%s:\t%i", nameB, (int)(timeB / count));
803            if (errors>0)
804                    printf("\t(%i errors out of %i)", errors, count);
805            printf("\n");
806    
         emms();  
807          return 0;          return 0;
808  }  }
809    
810  /*****************************************************************************  
811   * XviD Global Entry point  
812   *  int xvid_init_test(int flags)
813   * Well this function initialize all internal function pointers according  {
814   * to the CPU features forced by the library client or autodetected (depending  #if defined(ARCH_IS_IA32)
815   * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all          int cpu_flags;
816   * image colorspace transformation tables.  #endif
817   *  
818   ****************************************************************************/          printf("XviD tests\n\n");
819    
820    #if defined(ARCH_IS_IA32)
821            cpu_flags = detect_cpu_flags();
822    #endif
823    
824            idct_int32_init();
825            emms();
826    
827            srand(time(0));
828    
829            /* fDCT test */
830            printf("--- fdct ---\n");
831                    test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
832    
833    #if defined(ARCH_IS_IA32)
834            if (cpu_flags & XVID_CPU_MMX)
835                    test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
836            if (cpu_flags & XVID_CPU_SSE2)
837                    test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
838    #endif
839    
840            /* iDCT test */
841            printf("\n--- idct ---\n");
842                    test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
843    
844    #if defined(ARCH_IS_IA32)
845            if (cpu_flags & XVID_CPU_MMX)
846                    test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
847            if (cpu_flags & XVID_CPU_MMXEXT)
848                    test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags);
849            if (cpu_flags & XVID_CPU_3DNOWEXT)
850                    test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
851            if (cpu_flags & XVID_CPU_SSE2)
852                    test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
853    #endif
854    
855            /* Intra quantization test */
856            printf("\n--- quant intra ---\n");
857                    test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
858    
859    #if defined(ARCH_IS_IA32)
860            if (cpu_flags & XVID_CPU_MMX)
861                    test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
862            if (cpu_flags & XVID_CPU_3DNOWEXT)
863                    test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
864            if (cpu_flags & XVID_CPU_SSE2)
865                    test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
866    #endif
867    
868            /* Inter quantization test */
869            printf("\n--- quant inter ---\n");
870                    test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
871    
872    #if defined(ARCH_IS_IA32)
873            if (cpu_flags & XVID_CPU_MMX)
874                    test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
875            if (cpu_flags & XVID_CPU_3DNOWEXT)
876                    test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);
877            if (cpu_flags & XVID_CPU_SSE2)
878                    test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);
879    #endif
880    
881            /* Intra dequantization test */
882            printf("\n--- dequant intra ---\n");
883                    test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
884    
885    #if defined(ARCH_IS_IA32)
886            if (cpu_flags & XVID_CPU_MMX)
887                    test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
888            if (cpu_flags & XVID_CPU_MMXEXT)
889                    test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags);
890            if (cpu_flags & XVID_CPU_3DNOWEXT)
891                    test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
892            if (cpu_flags & XVID_CPU_SSE2)
893                    test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);
894    #endif
895    
896            /* Inter dequantization test */
897            printf("\n--- dequant inter ---\n");
898                    test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
899    
900    #if defined(ARCH_IS_IA32)
901            if (cpu_flags & XVID_CPU_MMX)
902                    test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
903            if (cpu_flags & XVID_CPU_MMXEXT)
904                    test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags);
905            if (cpu_flags & XVID_CPU_3DNOWEXT)
906                    test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
907            if (cpu_flags & XVID_CPU_SSE2)
908                    test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
909    #endif
910    
911            /* Intra quantization test */
912            printf("\n--- quant4 intra ---\n");
913                    test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
914    
915    #if defined(ARCH_IS_IA32)
916            if (cpu_flags & XVID_CPU_MMX)
917                    test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
918            if (cpu_flags & XVID_CPU_MMXEXT)
919                    test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
920    #endif
921    
922            /* Inter quantization test */
923            printf("\n--- quant4 inter ---\n");
924                    test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
925    
926    #if defined(ARCH_IS_IA32)
927            if (cpu_flags & XVID_CPU_MMX)
928                    test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
929            if (cpu_flags & XVID_CPU_MMXEXT)
930                    test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
931    #endif
932    
933            /* Intra dequantization test */
934            printf("\n--- dequant4 intra ---\n");
935                    test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
936    
937    #if defined(ARCH_IS_IA32)
938            if (cpu_flags & XVID_CPU_MMX)
939                    test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
940            if (cpu_flags & XVID_CPU_3DNOWEXT)
941                    test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
942    #endif
943    
944            /* Inter dequantization test */
945            printf("\n--- dequant4 inter ---\n");
946                    test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
947    
948    #if defined(ARCH_IS_IA32)
949            if (cpu_flags & XVID_CPU_MMX)
950                    test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
951            if (cpu_flags & XVID_CPU_3DNOWEXT)
952                    test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
953    #endif
954    
955            emms();
956    
957            return XVID_ERR_OK;
958    }
959    
960    
961  int  int
962  xvid_global(void *handle,  xvid_init(void *handle,
963                    int opt,                    int opt,
964                    void *param1,                    void *param1,
965                    void *param2)                    void *param2)
966  {  {
967          switch(opt)          switch(opt)
968          {          {
969                  case XVID_GBL_INIT :                  case XVID_INIT_INIT :
970                          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);  
971    
972                  case XVID_GBL_CONVERT :                  case XVID_INIT_CONVERT :
973                          return xvid_gbl_convert((xvid_gbl_convert_t*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
974    
975                    case XVID_INIT_TEST :
976                    {
977                            ptr_t flags = (ptr_t)param1;
978                            return xvid_init_test((int)flags);
979                    }
980                  default :                  default :
981                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
982          }          }
# Line 664  Line 999 
999                          void *param2)                          void *param2)
1000  {  {
1001          switch (opt) {          switch (opt) {
1002            case XVID_DEC_DECODE:
1003                    return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2);
1004    
1005          case XVID_DEC_CREATE:          case XVID_DEC_CREATE:
1006                  return decoder_create((xvid_dec_create_t *) param1);                  return decoder_create((XVID_DEC_PARAM *) param1);
1007    
1008          case XVID_DEC_DESTROY:          case XVID_DEC_DESTROY:
1009                  return decoder_destroy((DECODER *) handle);                  return decoder_destroy((DECODER *) handle);
1010    
         case XVID_DEC_DECODE:  
                 return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);  
   
1011          default:          default:
1012                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1013          }          }
# Line 698  Line 1033 
1033          switch (opt) {          switch (opt) {
1034          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1035    
1036                  return enc_encode((Encoder *) handle,                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)
1037                                                            (xvid_enc_frame_t *) param1,                          return encoder_encode_bframes((Encoder *) handle,
1038                                                            (xvid_enc_stats_t *) param2);                                                                                    (XVID_ENC_FRAME *) param1,
1039                                                                                      (XVID_ENC_STATS *) param2);
1040                    else
1041                            return encoder_encode((Encoder *) handle,
1042                                                                      (XVID_ENC_FRAME *) param1,
1043                                                                      (XVID_ENC_STATS *) param2);
1044    
1045          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:
1046                  return enc_create((xvid_enc_create_t *) param1);                  return encoder_create((XVID_ENC_PARAM *) param1);
1047    
1048          case XVID_ENC_DESTROY:          case XVID_ENC_DESTROY:
1049                  return enc_destroy((Encoder *) handle);                  return encoder_destroy((Encoder *) handle);
1050    
1051          default:          default:
1052                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;

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

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