[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.6, Wed Mar 27 12:58:29 2002 UTC revision 1.29, Tue Jul 9 01:48:49 2002 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      native api   *  - Native API implementation  -
5   *   *
6   *      This program is an implementation of a part of one or more MPEG-4   *      This program is an implementation of a part of one or more MPEG-4
7   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
# Line 24  Line 24 
24   *   *
25   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
26   *      along with this program; if not, write to the Free Software   *      along with this program; if not, write to the Free Software
27   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
28   *   *
29   *************************************************************************/   ****************************************************************************/
30    
31  /**************************************************************************  /*****************************************************************************
32   *   *
33   *      History:   *  History
34   *   *
35   *      17.03.2002      Added interpolate8x8_halfpel_hv_xmm   *      - 23.06.2002    added XVID_CPU_CHKONLY
36   *  22.12.2001  API change: added xvid_init() - Isibaar   *  - 17.03.2002        Added interpolate8x8_halfpel_hv_xmm
37   *      16.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *  - 22.12.2001  API change: added xvid_init() - Isibaar
38     *  - 16.12.2001        inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
39   *   *
40   *************************************************************************/   *  $Id$
41     *
42     ****************************************************************************/
43    
44  #include "xvid.h"  #include "xvid.h"
45  #include "decoder.h"  #include "decoder.h"
# Line 53  Line 55 
55  #include "motion/sad.h"  #include "motion/sad.h"
56  #include "utils/emms.h"  #include "utils/emms.h"
57  #include "utils/timer.h"  #include "utils/timer.h"
58    #include "bitstream/mbcoding.h"
59    
60  int xvid_init(void *handle, int opt, void *param1, void *param2)  /*****************************************************************************
61     * XviD Init Entry point
62     *
63     * Well this function initialize all internal function pointers according
64     * to the CPU features forced by the library client or autodetected (depending
65     * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
66     * image colorspace transformation tables.
67     *
68     * Returned value : XVID_ERR_OK
69     *                  + API_VERSION in the input XVID_INIT_PARAM structure
70     *                  + core build  "   "    "       "               "
71     *
72     ****************************************************************************/
73    
74    int
75    xvid_init(void *handle,
76                      int opt,
77                      void *param1,
78                      void *param2)
79  {  {
80          int cpu_flags;          int cpu_flags;
81          XVID_INIT_PARAM *init_param;          XVID_INIT_PARAM *init_param;
82    
83          init_param = (XVID_INIT_PARAM *) param1;          init_param = (XVID_INIT_PARAM *) param1;
84    
85          // force specific cpu settings?          /* Inform the client the API version */
86          if((init_param->cpu_flags & XVID_CPU_FORCE) > 0)          init_param->api_version = API_VERSION;
87    
88            /* Inform the client the core build - unused because we're still alpha */
89            init_param->core_build = 1000;
90    
91            if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
92            {
93                    init_param->cpu_flags = check_cpu_features();
94                    return XVID_ERR_OK;
95            }
96    
97            /* Do we have to force CPU features  ? */
98            if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) {
99                  cpu_flags = init_param->cpu_flags;                  cpu_flags = init_param->cpu_flags;
100          else {          } else {
101    
 #ifdef ARCH_X86  
102                  cpu_flags = check_cpu_features();                  cpu_flags = check_cpu_features();
 #else  
                 cpu_flags = 0;  
 #endif  
103                  init_param->cpu_flags = cpu_flags;                  init_param->cpu_flags = cpu_flags;
104          }          }
105    
106          // initialize the function pointers          /* Initialize the function pointers */
107          idct_int32_init();          idct_int32_init();
108            init_vlc_tables();
109    
110            /* Fixed Point Forward/Inverse DCT transformations */
111          fdct = fdct_int32;          fdct = fdct_int32;
112          idct = idct_int32;          idct = idct_int32;
113    
114            /* Only needed on PPC Altivec archs */
115            sadInit = 0;
116    
117            /* Restore FPU context : emms_c is a nop functions */
118          emms = emms_c;          emms = emms_c;
119    
120            /* Quantization functions */
121          quant_intra = quant_intra_c;          quant_intra = quant_intra_c;
122          dequant_intra = dequant_intra_c;          dequant_intra = dequant_intra_c;
123          quant_inter = quant_inter_c;          quant_inter = quant_inter_c;
# Line 92  Line 128 
128          quant4_inter = quant4_inter_c;          quant4_inter = quant4_inter_c;
129          dequant4_inter = dequant4_inter_c;          dequant4_inter = dequant4_inter_c;
130    
131            /* Block transfer related functions */
132          transfer_8to16copy = transfer_8to16copy_c;          transfer_8to16copy = transfer_8to16copy_c;
133          transfer_16to8copy = transfer_16to8copy_c;          transfer_16to8copy = transfer_16to8copy_c;
134          transfer_8to16sub = transfer_8to16sub_c;          transfer_8to16sub = transfer_8to16sub_c;
135            transfer_8to16sub2 = transfer_8to16sub2_c;
136          transfer_16to8add = transfer_16to8add_c;          transfer_16to8add = transfer_16to8add_c;
137          transfer8x8_copy = transfer8x8_copy_c;          transfer8x8_copy = transfer8x8_copy_c;
138    
139            /* Image interpolation related functions */
140          interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;          interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;
141          interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;          interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;
142          interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;          interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;
143    
144            /* Initialize internal colorspace transformation tables */
145          colorspace_init();          colorspace_init();
146    
147            /* All colorspace transformation functions User Format->YV12 */
148          rgb555_to_yv12 = rgb555_to_yv12_c;          rgb555_to_yv12 = rgb555_to_yv12_c;
149          rgb565_to_yv12 = rgb565_to_yv12_c;          rgb565_to_yv12 = rgb565_to_yv12_c;
150          rgb24_to_yv12 = rgb24_to_yv12_c;          rgb24_to_yv12 = rgb24_to_yv12_c;
# Line 112  Line 153 
153          yuyv_to_yv12 = yuyv_to_yv12_c;          yuyv_to_yv12 = yuyv_to_yv12_c;
154          uyvy_to_yv12 = uyvy_to_yv12_c;          uyvy_to_yv12 = uyvy_to_yv12_c;
155    
156            /* All colorspace transformation functions YV12->User format */
157          yv12_to_rgb555 = yv12_to_rgb555_c;          yv12_to_rgb555 = yv12_to_rgb555_c;
158          yv12_to_rgb565 = yv12_to_rgb565_c;          yv12_to_rgb565 = yv12_to_rgb565_c;
159          yv12_to_rgb24 = yv12_to_rgb24_c;          yv12_to_rgb24 = yv12_to_rgb24_c;
# Line 120  Line 162 
162          yv12_to_yuyv = yv12_to_yuyv_c;          yv12_to_yuyv = yv12_to_yuyv_c;
163          yv12_to_uyvy = yv12_to_uyvy_c;          yv12_to_uyvy = yv12_to_uyvy_c;
164    
165            /* Functions used in motion estimation algorithms */
166          calc_cbp = calc_cbp_c;          calc_cbp = calc_cbp_c;
167          sad16 = sad16_c;          sad16 = sad16_c;
168            sad16bi  = sad16bi_c;
169          sad8 = sad8_c;          sad8 = sad8_c;
170          dev16 = dev16_c;          dev16 = dev16_c;
171    
172  #ifdef ARCH_X86  #ifdef ARCH_X86
173          if((cpu_flags & XVID_CPU_MMX) > 0) {          if((cpu_flags & XVID_CPU_MMX) > 0) {
174    
175                    /* Forward and Inverse Discrete Cosine Transformation functions */
176                  fdct = fdct_mmx;                  fdct = fdct_mmx;
177                  idct = idct_mmx;                  idct = idct_mmx;
178    
179                    /* To restore FPU context after mmx use */
180                  emms = emms_mmx;                  emms = emms_mmx;
181    
182                    /* Quantization related functions */
183                  quant_intra = quant_intra_mmx;                  quant_intra = quant_intra_mmx;
184                  dequant_intra = dequant_intra_mmx;                  dequant_intra = dequant_intra_mmx;
185                  quant_inter = quant_inter_mmx;                  quant_inter = quant_inter_mmx;
# Line 142  Line 190 
190                  quant4_inter = quant4_inter_mmx;                  quant4_inter = quant4_inter_mmx;
191                  dequant4_inter = dequant4_inter_mmx;                  dequant4_inter = dequant4_inter_mmx;
192    
193                    /* Block related functions */
194                  transfer_8to16copy = transfer_8to16copy_mmx;                  transfer_8to16copy = transfer_8to16copy_mmx;
195                  transfer_16to8copy = transfer_16to8copy_mmx;                  transfer_16to8copy = transfer_16to8copy_mmx;
196                  transfer_8to16sub = transfer_8to16sub_mmx;                  transfer_8to16sub = transfer_8to16sub_mmx;
197                    transfer_8to16sub2 = transfer_8to16sub2_mmx;
198                  transfer_16to8add = transfer_16to8add_mmx;                  transfer_16to8add = transfer_16to8add_mmx;
199                  transfer8x8_copy = transfer8x8_copy_mmx;                  transfer8x8_copy = transfer8x8_copy_mmx;
200    
201    
202                    /* Image Interpolation related functions */
203                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;
204                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;
205                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;
206    
207                    /* Image RGB->YV12 related functions */
208                  rgb24_to_yv12 = rgb24_to_yv12_mmx;                  rgb24_to_yv12 = rgb24_to_yv12_mmx;
209                  rgb32_to_yv12 = rgb32_to_yv12_mmx;                  rgb32_to_yv12 = rgb32_to_yv12_mmx;
210                  yuv_to_yv12 = yuv_to_yv12_mmx;                  yuv_to_yv12 = yuv_to_yv12_mmx;
211                  yuyv_to_yv12 = yuyv_to_yv12_mmx;                  yuyv_to_yv12 = yuyv_to_yv12_mmx;
212                  uyvy_to_yv12 = uyvy_to_yv12_mmx;                  uyvy_to_yv12 = uyvy_to_yv12_mmx;
213    
214                    /* Image YV12->RGB related functions */
215                  yv12_to_rgb24 = yv12_to_rgb24_mmx;                  yv12_to_rgb24 = yv12_to_rgb24_mmx;
216                  yv12_to_rgb32 = yv12_to_rgb32_mmx;                  yv12_to_rgb32 = yv12_to_rgb32_mmx;
217                  yv12_to_yuyv = yv12_to_yuyv_mmx;                  yv12_to_yuyv = yv12_to_yuyv_mmx;
218                  yv12_to_uyvy = yv12_to_uyvy_mmx;                  yv12_to_uyvy = yv12_to_uyvy_mmx;
219    
220                    /* Motion estimation related functions */
221                  calc_cbp = calc_cbp_mmx;                  calc_cbp = calc_cbp_mmx;
222                  sad16 = sad16_mmx;                  sad16 = sad16_mmx;
223                  sad8 = sad8_mmx;                  sad8 = sad8_mmx;
# Line 171  Line 226 
226          }          }
227    
228          if((cpu_flags & XVID_CPU_MMXEXT) > 0) {          if((cpu_flags & XVID_CPU_MMXEXT) > 0) {
229    
230                    /* Inverse DCT */
231                  idct = idct_xmm;                  idct = idct_xmm;
232    
233                    /* Interpolation */
234                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;
235                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;
236                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;
237    
238                    /* Quantization */
239                    dequant_intra = dequant_intra_xmm;
240                    dequant_inter = dequant_inter_xmm;
241    
242                    /* Buffer transfer */
243                    transfer_8to16sub2 = transfer_8to16sub2_xmm;
244    
245                    /* Colorspace transformation */
246                  yuv_to_yv12 = yuv_to_yv12_xmm;                  yuv_to_yv12 = yuv_to_yv12_xmm;
247    
248                    /* ME functions */
249                  sad16 = sad16_xmm;                  sad16 = sad16_xmm;
250                    sad16bi = sad16bi_xmm;
251                  sad8 = sad8_xmm;                  sad8 = sad8_xmm;
252                  dev16 = dev16_xmm;                  dev16 = dev16_xmm;
253    
254          }          }
255    
256          if((cpu_flags & XVID_CPU_3DNOW) > 0) {          if((cpu_flags & XVID_CPU_3DNOW) > 0) {
257    
258                    /* Interpolation */
259                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
260                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
261                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
262          }          }
263    
264            if ((cpu_flags & XVID_CPU_SSE2) > 0) {
265    #ifdef EXPERIMENTAL_SSE2_CODE
266    
267                    calc_cbp = calc_cbp_sse2;
268    
269                    /* Quantization */
270                    quant_intra   = quant_intra_sse2;
271                    dequant_intra = dequant_intra_sse2;
272                    quant_inter   = quant_inter_sse2;
273                    dequant_inter = dequant_inter_sse2;
274    
275                    /* ME */
276                    sad16    = sad16_sse2;
277                    dev16    = dev16_sse2;
278    
279                    /* Forward and Inverse DCT */
280                    idct  = idct_sse2;
281                    fdct = fdct_sse2;
282  #endif  #endif
283            }
284    
285    #endif
286    
287    #ifdef ARCH_IA64
288            if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines?
289              idct_ia64_init();
290              fdct = fdct_ia64;
291              idct = idct_ia64;   //not yet working, crashes
292              interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
293              interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
294              interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
295              sad16 = sad16_ia64;
296              sad16bi = sad16bi_ia64;
297              sad8 = sad8_ia64;
298              dev16 = dev16_ia64;
299              quant_intra = quant_intra_ia64;
300              dequant_intra = dequant_intra_ia64;
301              quant_inter = quant_inter_ia64;
302              dequant_inter = dequant_inter_ia64;
303              transfer_8to16copy = transfer_8to16copy_ia64;
304              transfer_16to8copy = transfer_16to8copy_ia64;
305              transfer_8to16sub = transfer_8to16sub_ia64;
306              transfer_8to16sub2 = transfer_8to16sub2_ia64;
307              transfer_16to8add = transfer_16to8add_ia64;
308              transfer8x8_copy = transfer8x8_copy_ia64;
309              DEBUG("Using IA-64 assembler routines.\n");
310            }
311    #endif
312    
313  #ifdef ARCH_PPC  #ifdef ARCH_PPC
314  #ifdef ARCH_PPC_ALTIVEC  #ifdef ARCH_PPC_ALTIVEC
315          calc_cbp = calc_cbp_altivec;          calc_cbp = calc_cbp_altivec;
316            fdct = fdct_altivec;
317            idct = idct_altivec;
318            sadInit = sadInit_altivec;
319            sad16 = sad16_altivec;
320            sad8 = sad8_altivec;
321            dev16 = dev16_altivec;
322  #else  #else
323          calc_cbp = calc_cbp_ppc;          calc_cbp = calc_cbp_ppc;
324  #endif  #endif
325  #endif  #endif
326    
         // API version  
         init_param->api_version = API_VERSION;  
   
         // something clever has to be done for this  
         init_param->core_build = 1000;  
   
327          return XVID_ERR_OK;          return XVID_ERR_OK;
328  }  }
329    
330  int xvid_decore(void * handle, int opt, void * param1, void * param2)  /*****************************************************************************
331  {   * XviD Native decoder entry point
332          switch (opt)   *
333     * This function is just a wrapper to all the option cases.
334     *
335     * Returned values : XVID_ERR_FAIL when opt is invalid
336     *                   else returns the wrapped function result
337     *
338     ****************************************************************************/
339    
340    int
341    xvid_decore(void *handle,
342                            int opt,
343                            void *param1,
344                            void *param2)
345          {          {
346            switch (opt) {
347          case XVID_DEC_DECODE :          case XVID_DEC_DECODE :
348          return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1);          return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1);
349    
# Line 226  Line 359 
359  }  }
360    
361    
362  int xvid_encore(void * handle, int opt, void * param1, void * param2)  /*****************************************************************************
363  {   * XviD Native encoder entry point
364          switch (opt)   *
365     * This function is just a wrapper to all the option cases.
366     *
367     * Returned values : XVID_ERR_FAIL when opt is invalid
368     *                   else returns the wrapped function result
369     *
370     ****************************************************************************/
371    
372    int
373    xvid_encore(void *handle,
374                            int opt,
375                            void *param1,
376                            void *param2)
377          {          {
378            switch (opt) {
379          case XVID_ENC_ENCODE :          case XVID_ENC_ENCODE :
380          return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, (XVID_ENC_STATS *) param2);  #ifdef BFRAMES
381                    if (((Encoder *) handle)->mbParam.max_bframes >= 0)
382                    return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,
383                                                              (XVID_ENC_STATS *) param2);
384                    else
385    #endif
386                    return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,
387                                                              (XVID_ENC_STATS *) param2);
388    
389          case XVID_ENC_CREATE :          case XVID_ENC_CREATE :
390          return encoder_create((XVID_ENC_PARAM *) param1);          return encoder_create((XVID_ENC_PARAM *) param1);

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.29

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