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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.22

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