[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.9, Thu Jul 10 17:39:51 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 47  Line 45 
45  #include "utils/timer.h"  #include "utils/timer.h"
46  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
47    
 #if defined(_DEBUG)  
 unsigned int xvid_debug = 0; /* xvid debug mask */  
 #endif  
   
48  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
49    
50  #if defined(_MSC_VER)  #if defined(_MSC_VER)
# Line 159  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_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 288  Line 302 
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 305  Line 320 
320    
321                  /* Forward and Inverse Discrete Cosine Transformation functions */                  /* Forward and Inverse Discrete Cosine Transformation functions */
322                  fdct = fdct_mmx;                  fdct = fdct_mmx;
323                  idct = idct_mmx;                  idct = simple_idct_mmx; /* use simple idct by default */
324    
325                  /* Quantization related functions */                  /* Quantization related functions */
326                  quant_intra   = quant_intra_mmx;                  quant_intra   = quant_intra_mmx;
# Line 391  Line 406 
406          if ((cpu_flags & XVID_CPU_MMXEXT)) {          if ((cpu_flags & XVID_CPU_MMXEXT)) {
407    
408                  /* Inverse DCT */                  /* Inverse DCT */
409                  idct = idct_xmm;                  /* idct = idct_xmm; Don't use Walken idct anymore! */
410    
411                  /* Interpolation */                  /* Interpolation */
412                  interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_xmm;                  interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_xmm;
# Line 437  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 487  Line 502 
502                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
503  #endif  #endif
504                  /* Forward and Inverse DCT */                  /* Forward and Inverse DCT */
505  #if 0 /* Both function are known to be unprecise, better keep them deactivated */                  /* idct  = idct_sse2;
506                  idct  = idct_sse2;                  /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */
                 fdct = fdct_sse2;  
 #endif  
507          }          }
508  #endif  #endif
509    
# Line 517  Line 530 
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 538  Line 552 
552          }          }
553  #endif  #endif
554    
555  #if defined(_DEBUG)          return XVID_ERR_OK;
     xvid_debug = init->debug;  
 #endif  
   
     return 0;  
556  }  }
557    
558    
 static int  
 xvid_gbl_info(xvid_gbl_info_t * info)  
 {  
         if (XVID_MAJOR(info->version) != 1) /* v1.x.x */  
                 return XVID_ERR_VERSION;  
   
         info->actual_version = XVID_VERSION;  
         info->build = "dev-api-4";  
         info->cpu_flags = detect_cpu_flags();  
   
 #if defined(_SMP) && defined(WIN32)  
         info->num_threads = pthread_num_processors_np();;  
 #else  
         info->num_threads = 0;  
 #endif  
   
         return 0;  
 }  
   
559    
560  static int  static int
561  xvid_gbl_convert(xvid_gbl_convert_t* convert)  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
562  {  {
563          int width;  /*
564          int height;          const int flip1 =
565          int width2;                  (convert->input.colorspace & XVID_CSP_VFLIP) ^
566          int height2;                  (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;          IMAGE img;
573    
574          if (XVID_MAJOR(convert->version) != 1)   /* v1.x.x */          switch (convert->input.colorspace & ~XVID_CSP_VFLIP)
               return XVID_ERR_VERSION;  
   
 #if 0  
         const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);  
 #endif  
         width = convert->width;  
         height = convert->height;  
         width2 = convert->width/2;  
         height2 = convert->height/2;  
   
         switch (convert->input.csp & ~XVID_CSP_VFLIP)  
575          {          {
576                  case XVID_CSP_YV12 :                  case XVID_CSP_YV12 :
577                          img.y = convert->input.plane[0];                          img.y = convert->input.y;
578                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;                          img.v = (uint8_t*)convert->input.y + width*height;
579                          img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2;                          img.u = (uint8_t*)convert->input.y + width*height + width2*height2;
580                          image_output(&img, width, height, width,                          image_output(&img, width, height, width,
581                                                  (uint8_t**)convert->output.plane, convert->output.stride,                                                  convert->output.y, convert->output.y_stride,
582                                                  convert->output.csp, convert->interlacing);                                                  convert->output.colorspace, convert->interlacing);
583                          break;                          break;
584    
585                  default :                  default :
# Line 603  Line 588 
588    
589    
590          emms();          emms();
591          return 0;          return XVID_ERR_OK;
592  }  }
593    
594    
# Line 652  Line 637 
637  {  {
638          int i, diff = 0;          int i, diff = 0;
639          for (i = 0; i < size; i++)          for (i = 0; i < size; i++)
640                  diff += abs(blockA[i]-blockB[i]);                  diff += ABS(blockA[i]-blockB[i]);
641          return diff;          return diff;
642  }  }
643    
# Line 969  Line 954 
954    
955          emms();          emms();
956    
957          return 0;          return XVID_ERR_OK;
958  }  }
959    
960    
 /*****************************************************************************  
  * XviD Global Entry point  
  *  
  * Well this function initialize all internal function pointers according  
  * to the CPU features forced by the library client or autodetected (depending  
  * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all  
  * image colorspace transformation tables.  
  *  
  ****************************************************************************/  
   
   
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);
971    
972          case XVID_GBL_INFO :                  case XVID_INIT_CONVERT :
973              return xvid_gbl_info((xvid_gbl_info_t*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
974    
975                  case XVID_GBL_CONVERT :                  case XVID_INIT_TEST :
                         return xvid_gbl_convert((xvid_gbl_convert_t*)param1);  
   
                 case XVID_GBL_TEST :  
976                  {                  {
977                          ptr_t flags = (ptr_t)param1;                          ptr_t flags = (ptr_t)param1;
978                          return xvid_init_test((int)flags);                          return xvid_init_test((int)flags);
# Line 1028  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 1062  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.9  
changed lines
  Added in v.1.46

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