[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.8, Wed Jun 11 14:10:40 2003 UTC revision 1.45.4.1, Sat May 3 23:23: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 46  Line 44 
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"
47    #include "image/qpel.h"
 #if defined(_DEBUG)  
 unsigned int xvid_debug = 0; /* xvid debug mask */  
 #endif  
48    
49  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
50    
# Line 159  Line 154 
154    
155    
156  static  static
157  int xvid_gbl_init(xvid_gbl_init_t * init)  int xvid_init_init(XVID_INIT_PARAM * init_param)
158    {
159            int cpu_flags;
160    
161            /* Inform the client the API version */
162            init_param->api_version = API_VERSION;
163    
164            /* Inform the client the core build - unused because we're still alpha */
165            init_param->core_build = 1000;
166    
167            /* Do we have to force CPU features  ? */
168            if ((init_param->cpu_flags & XVID_CPU_FORCE)) {
169    
170                    cpu_flags = init_param->cpu_flags;
171    
172            } else {
173    
174                    cpu_flags = detect_cpu_flags();
175            }
176    
177            if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
178  {  {
179          unsigned int cpu_flags;                  init_param->cpu_flags = cpu_flags;
180                    return XVID_ERR_OK;
181            }
182    
183          if (XVID_MAJOR(init->version) != 1) /* v1.x.x */          init_param->cpu_flags = cpu_flags;
                 return XVID_ERR_VERSION;  
184    
185          cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags();          /* Qpel stuff */
186            xvid_QP_Funcs = &xvid_QP_Funcs_C;
187            xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C;
188            xvid_Init_QP_mmx();
189    
190          /* Initialize the function pointers */          /* Initialize the function pointers */
191          idct_int32_init();          idct_int32_init();
# Line 288  Line 307 
307    
308  #if defined(ARCH_IS_IA32)  #if defined(ARCH_IS_IA32)
309    
310          if ((cpu_flags & XVID_CPU_ASM)) {          if ((cpu_flags & XVID_CPU_ASM))
311            {
312                  vfilter_31 = xvid_VFilter_31_x86;                  vfilter_31 = xvid_VFilter_31_x86;
313                  hfilter_31 = xvid_HFilter_31_x86;                  hfilter_31 = xvid_HFilter_31_x86;
314          }          }
# Line 303  Line 323 
323    
324          if ((cpu_flags & XVID_CPU_MMX)) {          if ((cpu_flags & XVID_CPU_MMX)) {
325    
326                    /* Qpel stuff */
327                    xvid_QP_Funcs = &xvid_QP_Funcs_mmx;
328                    xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx;
329                    xvid_Init_QP_mmx();
330    
331                  /* Forward and Inverse Discrete Cosine Transformation functions */                  /* Forward and Inverse Discrete Cosine Transformation functions */
332                  fdct = fdct_mmx;                  fdct = fdct_mmx;
333                  idct = idct_mmx;                  idct = idct_mmx;
# Line 487  Line 512 
512                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
513  #endif  #endif
514                  /* Forward and Inverse DCT */                  /* Forward and Inverse DCT */
 #if 0 /* Both function are known to be unprecise, better keep them deactivated */  
515                  idct  = idct_sse2;                  idct  = idct_sse2;
516                  fdct = fdct_sse2;                  fdct = fdct_sse2;
 #endif  
517          }          }
518  #endif  #endif
519    
# Line 539  Line 562 
562          }          }
563  #endif  #endif
564    
565  #if defined(_DEBUG)          return XVID_ERR_OK;
     xvid_debug = init->debug;  
 #endif  
   
     return 0;  
566  }  }
567    
568    
 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;  
 }  
   
569    
570  static int  static int
571  xvid_gbl_convert(xvid_gbl_convert_t* convert)  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
572  {  {
573          int width;  /*
574          int height;          const int flip1 =
575          int width2;                  (convert->input.colorspace & XVID_CSP_VFLIP) ^
576          int height2;                  (convert->output.colorspace & XVID_CSP_VFLIP);
577    */
578            const int width = convert->width;
579            const int height = convert->height;
580            const int width2 = convert->width/2;
581            const int height2 = convert->height/2;
582          IMAGE img;          IMAGE img;
583    
584          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)  
585          {          {
586                  case XVID_CSP_YV12 :                  case XVID_CSP_YV12 :
587                          img.y = convert->input.plane[0];                          img.y = convert->input.y;
588                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;                          img.v = (uint8_t*)convert->input.y + width*height;
589                          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;
590                          image_output(&img, width, height, width,                          image_output(&img, width, height, width,
591                                                  (uint8_t**)convert->output.plane, convert->output.stride,                                                  convert->output.y, convert->output.y_stride,
592                                                  convert->output.csp, convert->interlacing);                                                  convert->output.colorspace, convert->interlacing);
593                          break;                          break;
594    
595                  default :                  default :
# Line 604  Line 598 
598    
599    
600          emms();          emms();
601          return 0;          return XVID_ERR_OK;
602  }  }
603    
604    
# Line 653  Line 647 
647  {  {
648          int i, diff = 0;          int i, diff = 0;
649          for (i = 0; i < size; i++)          for (i = 0; i < size; i++)
650                  diff += abs(blockA[i]-blockB[i]);                  diff += ABS(blockA[i]-blockB[i]);
651          return diff;          return diff;
652  }  }
653    
# Line 970  Line 964 
964    
965          emms();          emms();
966    
967          return 0;          return XVID_ERR_OK;
968  }  }
969    
970    
 /*****************************************************************************  
  * 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.  
  *  
  ****************************************************************************/  
   
   
971  int  int
972  xvid_global(void *handle,  xvid_init(void *handle,
973                    int opt,                    int opt,
974                    void *param1,                    void *param1,
975                    void *param2)                    void *param2)
976  {  {
977          switch(opt)          switch(opt)
978          {          {
979                  case XVID_GBL_INIT :                  case XVID_INIT_INIT :
980                          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);  
981    
982                  case XVID_GBL_CONVERT :                  case XVID_INIT_CONVERT :
983                          return xvid_gbl_convert((xvid_gbl_convert_t*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
984    
985                  case XVID_GBL_TEST :                  case XVID_INIT_TEST :
986                  {                  {
987                          ptr_t flags = (ptr_t)param1;                          ptr_t flags = (ptr_t)param1;
988                          return xvid_init_test((int)flags);                          return xvid_init_test((int)flags);
# Line 1029  Line 1009 
1009                          void *param2)                          void *param2)
1010  {  {
1011          switch (opt) {          switch (opt) {
1012            case XVID_DEC_DECODE:
1013                    return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2);
1014    
1015          case XVID_DEC_CREATE:          case XVID_DEC_CREATE:
1016                  return decoder_create((xvid_dec_create_t *) param1);                  return decoder_create((XVID_DEC_PARAM *) param1);
1017    
1018          case XVID_DEC_DESTROY:          case XVID_DEC_DESTROY:
1019                  return decoder_destroy((DECODER *) handle);                  return decoder_destroy((DECODER *) handle);
1020    
         case XVID_DEC_DECODE:  
                 return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);  
   
1021          default:          default:
1022                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1023          }          }
# Line 1063  Line 1043 
1043          switch (opt) {          switch (opt) {
1044          case XVID_ENC_ENCODE:          case XVID_ENC_ENCODE:
1045    
1046                  return enc_encode((Encoder *) handle,                  if (((Encoder *) handle)->mbParam.max_bframes >= 0)
1047                                                            (xvid_enc_frame_t *) param1,                          return encoder_encode_bframes((Encoder *) handle,
1048                                                            (xvid_enc_stats_t *) param2);                                                                                    (XVID_ENC_FRAME *) param1,
1049                                                                                      (XVID_ENC_STATS *) param2);
1050                    else
1051                            return encoder_encode((Encoder *) handle,
1052                                                                      (XVID_ENC_FRAME *) param1,
1053                                                                      (XVID_ENC_STATS *) param2);
1054    
1055          case XVID_ENC_CREATE:          case XVID_ENC_CREATE:
1056                  return enc_create((xvid_enc_create_t *) param1);                  return encoder_create((XVID_ENC_PARAM *) param1);
1057    
1058          case XVID_ENC_DESTROY:          case XVID_ENC_DESTROY:
1059                  return enc_destroy((Encoder *) handle);                  return encoder_destroy((Encoder *) handle);
1060    
1061          default:          default:
1062                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;

Legend:
Removed from v.1.45.2.8  
changed lines
  Added in v.1.45.4.1

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