[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.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 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 473  Line 488 
488    
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 */
# Line 481  Line 499 
499                  quant_inter   = quant_inter_sse2;                  quant_inter   = quant_inter_sse2;
500                  dequant_inter = dequant_inter_sse2;                  dequant_inter = dequant_inter_sse2;
501    
 #if defined(EXPERIMENTAL_SSE2_CODE)  
502                  /* ME; slower than xmm */                  /* ME; slower than xmm */
503                  sad16    = sad16_sse2;                  sad16    = sad16_sse2;
504                  dev16    = dev16_sse2;                  dev16    = dev16_sse2;
505  #endif  #endif
506                  /* Forward and Inverse DCT */                  /* Forward and Inverse DCT */
507  #if 0 /* Both function are known to be unprecise, better keep them deactivated */                  /* idct  = idct_sse2;
508                  idct  = idct_sse2;                  /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */
                 fdct = fdct_sse2;  
 #endif  
509          }          }
510  #endif  #endif
511    
# Line 517  Line 532 
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 538  Line 554 
554          }          }
555  #endif  #endif
556    
557  #if defined(_DEBUG)          return XVID_ERR_OK;
     xvid_debug = init->debug;  
 #endif  
   
     return 0;  
558  }  }
559    
560    
 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;  
 }  
   
561    
562  static int  static int
563  xvid_gbl_convert(xvid_gbl_convert_t* convert)  xvid_init_convert(XVID_INIT_CONVERTINFO* convert)
564  {  {
565          int width;  /*
566          int height;          const int flip1 =
567          int width2;                  (convert->input.colorspace & XVID_CSP_VFLIP) ^
568          int height2;                  (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;          IMAGE img;
575    
576          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)  
577          {          {
578                  case XVID_CSP_YV12 :                  case XVID_CSP_YV12 :
579                          img.y = convert->input.plane[0];                          img.y = convert->input.y;
580                          img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;                          img.v = (uint8_t*)convert->input.y + width*height;
581                          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;
582                          image_output(&img, width, height, width,                          image_output(&img, width, height, width,
583                                                  (uint8_t**)convert->output.plane, convert->output.stride,                                                  convert->output.y, convert->output.y_stride,
584                                                  convert->output.csp, convert->interlacing);                                                  convert->output.colorspace, convert->interlacing);
585                          break;                          break;
586    
587                  default :                  default :
# Line 603  Line 590 
590    
591    
592          emms();          emms();
593          return 0;          return XVID_ERR_OK;
594  }  }
595    
596    
# Line 652  Line 639 
639  {  {
640          int i, diff = 0;          int i, diff = 0;
641          for (i = 0; i < size; i++)          for (i = 0; i < size; i++)
642                  diff += abs(blockA[i]-blockB[i]);                  diff += ABS(blockA[i]-blockB[i]);
643          return diff;          return diff;
644  }  }
645    
# Line 969  Line 956 
956    
957          emms();          emms();
958    
959          return 0;          return XVID_ERR_OK;
960  }  }
961    
962    
 /*****************************************************************************  
  * 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.  
  *  
  ****************************************************************************/  
   
   
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);
973    
974          case XVID_GBL_INFO :                  case XVID_INIT_CONVERT :
975              return xvid_gbl_info((xvid_gbl_info_t*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
976    
977                  case XVID_GBL_CONVERT :                  case XVID_INIT_TEST :
                         return xvid_gbl_convert((xvid_gbl_convert_t*)param1);  
   
                 case XVID_GBL_TEST :  
978                  {                  {
979                          ptr_t flags = (ptr_t)param1;                          ptr_t flags = (ptr_t)param1;
980                          return xvid_init_test((int)flags);                          return xvid_init_test((int)flags);
# Line 1028  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 1062  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.9  
changed lines
  Added in v.1.47

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