[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.43, Wed Feb 19 21:13:00 2003 UTC revision 1.45.2.5, Mon Jun 9 01:16:57 2003 UTC
# Line 45  Line 45 
45  #include "utils/timer.h"  #include "utils/timer.h"
46  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
47    
48    #if defined(_DEBUG)
49    unsigned int xvid_debug = 0; /* xvid debug mask */
50    #endif
51    
52  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
53    
54  #if defined(_MSC_VER)  #if defined(_MSC_VER)
# Line 153  Line 157 
157    
158    
159  static  static
160  int xvid_init_init(XVID_INIT_PARAM * init_param)  int xvid_gbl_init(xvid_gbl_init_t * init)
 {  
         int cpu_flags;  
   
         /* Inform the client the API version */  
         init_param->api_version = API_VERSION;  
   
         /* Inform the client the core build - unused because we're still alpha */  
         init_param->core_build = 1000;  
   
         /* Do we have to force CPU features  ? */  
         if ((init_param->cpu_flags & XVID_CPU_FORCE)) {  
   
                 cpu_flags = init_param->cpu_flags;  
   
         } else {  
   
                 cpu_flags = detect_cpu_flags();  
         }  
   
         if ((init_param->cpu_flags & XVID_CPU_CHKONLY))  
161          {          {
162                  init_param->cpu_flags = cpu_flags;          unsigned int cpu_flags;
                 return XVID_ERR_OK;  
         }  
163    
164          init_param->cpu_flags = cpu_flags;          if (XVID_MAJOR(init->version) != 1) /* v1.x.x */
165                    return XVID_ERR_VERSION;
166    
167            cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags();
168    
169          /* Initialize the function pointers */          /* Initialize the function pointers */
170          idct_int32_init();          idct_int32_init();
# Line 552  Line 536 
536          }          }
537  #endif  #endif
538    
539          return XVID_ERR_OK;  #if defined(_DEBUG)
540        xvid_debug = init->debug;
541    #endif
542    
543        return 0;
544  }  }
545    
546    
547    static int
548    xvid_gbl_info(xvid_gbl_info_t * info)
549    {
550            if (XVID_MAJOR(info->version) != 1) /* v1.x.x */
551                    return XVID_ERR_VERSION;
552    
553            info->actual_version = XVID_VERSION;
554            info->build = "dev-api-4";
555            info->cpu_flags = detect_cpu_flags();
556    
557    #if defined(_SMP) && defined(WIN32)
558            info->num_threads = pthread_num_processors_np();;
559    #else
560            info->num_threads = 0;
561    #endif
562    
563            return 0;
564    }
565    
566    
567  static int  static int
568  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)  xvid_gbl_convert(xvid_gbl_convert_t* convert)
569  {  {
570  /*          int width;
571          const int flip1 =          int height;
572                  (convert->input.colorspace & XVID_CSP_VFLIP) ^          int width2;
573                  (convert->output.colorspace & XVID_CSP_VFLIP);          int height2;
 */  
         const int width = convert->width;  
         const int height = convert->height;  
         const int width2 = convert->width/2;  
         const int height2 = convert->height/2;  
574          IMAGE img;          IMAGE img;
575    
576          switch (convert->input.colorspace & ~XVID_CSP_VFLIP)          if (XVID_MAJOR(convert->version) != 1)   /* v1.x.x */
577                  return XVID_ERR_VERSION;
578    
579    #if 0
580            const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);
581    #endif
582            width = convert->width;
583            height = convert->height;
584            width2 = convert->width/2;
585            height2 = convert->height/2;
586    
587            switch (convert->input.csp & ~XVID_CSP_VFLIP)
588          {          {
589                  case XVID_CSP_YV12 :                  case XVID_CSP_YV12 :
590                          img.y = convert->input.y;                          img.y = convert->input.plane[0];
591                          img.v = (uint8_t*)convert->input.y + width*height;                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;
592                          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;
593                          image_output(&img, width, height, width,                          image_output(&img, width, height, width,
594                                                  convert->output.y, convert->output.y_stride,                                                  (uint8_t**)convert->output.plane, convert->output.stride,
595                                                  convert->output.colorspace, convert->interlacing);                                                  convert->output.csp, convert->interlacing);
596                          break;                          break;
597    
598                  default :                  default :
# Line 588  Line 601 
601    
602    
603          emms();          emms();
604          return XVID_ERR_OK;          return 0;
605  }  }
606    
607    
# Line 637  Line 650 
650  {  {
651          int i, diff = 0;          int i, diff = 0;
652          for (i = 0; i < size; i++)          for (i = 0; i < size; i++)
653                  diff += ABS(blockA[i]-blockB[i]);                  diff += abs(blockA[i]-blockB[i]);
654          return diff;          return diff;
655  }  }
656    
# Line 811  Line 824 
824    
825  int xvid_init_test(int flags)  int xvid_init_test(int flags)
826  {  {
827    #if defined(ARCH_IS_IA32)
828          int cpu_flags;          int cpu_flags;
829    #endif
830    
831          srand(time(0));          printf("XviD tests\n\n");
   
         printf("xvid_init_test\n");  
832    
833  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
834          cpu_flags = detect_cpu_flags();          cpu_flags = detect_cpu_flags();
835    #endif
836    
837          idct_int32_init();          idct_int32_init();
838          emms_mmx();          emms();
839    
840            srand(time(0));
841    
842            /* fDCT test */
843          printf("--- fdct ---\n");          printf("--- fdct ---\n");
844                  test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);                  test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
845    
846    #if defined(ARCH_IS_IA32)
847          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
848                  test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);                  test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
849          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
850                  test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);                  test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
851    #endif
852    
853            /* iDCT test */
854          printf("\n--- idct ---\n");          printf("\n--- idct ---\n");
855                  test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);                  test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
856    
857    #if defined(ARCH_IS_IA32)
858          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
859                  test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);                  test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
860          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
# Line 839  Line 863 
863                  test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);                  test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
864          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
865                  test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);                  test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
866    #endif
867    
868            /* Intra quantization test */
869          printf("\n--- quant intra ---\n");          printf("\n--- quant intra ---\n");
870                  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);
871    
872    #if defined(ARCH_IS_IA32)
873          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
874                  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);
875          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
876                  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);
877          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
878                  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);
879    #endif
880    
881            /* Inter quantization test */
882          printf("\n--- quant inter ---\n");          printf("\n--- quant inter ---\n");
883                  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);
884    
885    #if defined(ARCH_IS_IA32)
886          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
887                  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);
888          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
889                  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);
890          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
891                  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);
892    #endif
893    
894            /* Intra dequantization test */
895          printf("\n--- dequant intra ---\n");          printf("\n--- dequant intra ---\n");
896                  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);
897    
898    #if defined(ARCH_IS_IA32)
899          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
900                  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);
901          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
# Line 868  Line 904 
904                  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);
905          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
906                  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);
907    #endif
908    
909            /* Inter dequantization test */
910          printf("\n--- dequant inter ---\n");          printf("\n--- dequant inter ---\n");
911                  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);
912    
913    #if defined(ARCH_IS_IA32)
914          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
915                  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);
916          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
# Line 879  Line 919 
919                  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);
920          if (cpu_flags & XVID_CPU_SSE2)          if (cpu_flags & XVID_CPU_SSE2)
921                  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);
922    #endif
923    
924          printf("\n--- quant4_intra ---\n");          /* Intra quantization test */
925            printf("\n--- quant4 intra ---\n");
926                  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);
927    
928    #if defined(ARCH_IS_IA32)
929          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
930                  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);
931          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
932                  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);
933    #endif
934    
935          printf("\n--- quant4_inter ---\n");          /* Inter quantization test */
936            printf("\n--- quant4 inter ---\n");
937                  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);
938    
939    #if defined(ARCH_IS_IA32)
940          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
941                  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);
942          if (cpu_flags & XVID_CPU_MMXEXT)          if (cpu_flags & XVID_CPU_MMXEXT)
943                  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);
944    #endif
945    
946          printf("\n--- dequant4_intra ---\n");          /* Intra dequantization test */
947            printf("\n--- dequant4 intra ---\n");
948                  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);
949    
950    #if defined(ARCH_IS_IA32)
951          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
952                  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);
953          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
954                  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);
955    #endif
956    
957          printf("\n--- dequant4_inter ---\n");          /* Inter dequantization test */
958            printf("\n--- dequant4 inter ---\n");
959                  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);
960    
961    #if defined(ARCH_IS_IA32)
962          if (cpu_flags & XVID_CPU_MMX)          if (cpu_flags & XVID_CPU_MMX)
963                  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);
964          if (cpu_flags & XVID_CPU_3DNOWEXT)          if (cpu_flags & XVID_CPU_3DNOWEXT)
965                  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();  
   
966  #endif  #endif
967    
968          return XVID_ERR_OK;          emms();
969    
970            return 0;
971  }  }
972    
973    
974    /*****************************************************************************
975     * XviD Global Entry point
976     *
977     * Well this function initialize all internal function pointers according
978     * to the CPU features forced by the library client or autodetected (depending
979     * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
980     * image colorspace transformation tables.
981     *
982     ****************************************************************************/
983    
984    
985  int  int
986  xvid_init(void *handle,  xvid_global(void *handle,
987                    int opt,                    int opt,
988                    void *param1,                    void *param1,
989                    void *param2)                    void *param2)
990  {  {
991          switch(opt)          switch(opt)
992          {          {
993                  case XVID_INIT_INIT :                  case XVID_GBL_INIT :
994                          return xvid_init_init((XVID_INIT_PARAM*)param1);                          return xvid_gbl_init((xvid_gbl_init_t*)param1);
995    
996                  case XVID_INIT_CONVERT :          case XVID_GBL_INFO :
997                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);              return xvid_gbl_info((xvid_gbl_info_t*)param1);
998    
999                  case XVID_INIT_TEST :                  case XVID_GBL_CONVERT :
1000                          return xvid_init_test((int)param1);                          return xvid_gbl_convert((xvid_gbl_convert_t*)param1);
1001    
1002                    case XVID_GBL_TEST :
1003                    {
1004                            ptr_t flags = (ptr_t)param1;
1005                            return xvid_init_test((int)flags);
1006                    }
1007                  default :                  default :
1008                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
1009          }          }
# Line 955  Line 1026 
1026                          void *param2)                          void *param2)
1027  {  {
1028          switch (opt) {          switch (opt) {
         case XVID_DEC_DECODE:  
                 return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2);  
   
1029          case XVID_DEC_CREATE:          case XVID_DEC_CREATE:
1030                  return decoder_create((XVID_DEC_PARAM *) param1);                  return decoder_create((xvid_dec_create_t *) param1);
1031    
1032          case XVID_DEC_DESTROY:          case XVID_DEC_DESTROY:
1033                  return decoder_destroy((DECODER *) handle);                  return decoder_destroy((DECODER *) handle);
1034    
1035            case XVID_DEC_DECODE:
1036                    return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);
1037    
1038          default:          default:
1039                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1040          }          }
# Line 989  Line 1060 
1060          switch (opt) {          switch (opt) {
1061          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1062    
1063                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)                  return enc_encode((Encoder *) handle,
1064                  return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,                                                            (xvid_enc_frame_t *) param1,
1065                                                            (XVID_ENC_STATS *) param2);                                                            (xvid_enc_stats_t *) param2);
                 else  
                 return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,  
                                                           (XVID_ENC_STATS *) param2);  
1066    
1067          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:
1068                  return encoder_create((XVID_ENC_PARAM *) param1);                  return enc_create((xvid_enc_create_t *) param1);
1069    
1070          case XVID_ENC_DESTROY:          case XVID_ENC_DESTROY:
1071                  return encoder_destroy((Encoder *) handle);                  return enc_destroy((Encoder *) handle);
1072    
1073          default:          default:
1074                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.45.2.5

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