[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.5, Thu Mar 21 23:59:48 2002 UTC revision 1.31, Thu Jul 18 13:47:46 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 50  Line 52 
52  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
53  #include "quant/quant_h263.h"  #include "quant/quant_h263.h"
54  #include "quant/quant_mpeg4.h"  #include "quant/quant_mpeg4.h"
55    #include "motion/motion.h"
56  #include "motion/sad.h"  #include "motion/sad.h"
57  #include "utils/emms.h"  #include "utils/emms.h"
58  #include "utils/timer.h"  #include "utils/timer.h"
59    #include "bitstream/mbcoding.h"
60    
61    #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)
62    
63    #ifdef WIN32
64    #include <windows.h>
65    #else
66    #include <signal.h>
67    #include <setjmp.h>
68    #endif
69    
70  int xvid_init(void *handle, int opt, void *param1, void *param2)  
71    #ifndef WIN32
72    
73    static jmp_buf mark;
74    
75    static void
76    sigill_handler(int signal)
77    {
78       longjmp(mark, 1);
79    }
80    #endif
81    
82    
83    /*
84    calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled
85    return values:
86    -1 : could not determine
87    0  : SIGILL was *not* signalled
88    1  : SIGILL was signalled
89    */
90    
91    int
92    sigill_check(void (*func)())
93    {
94    #ifdef WIN32
95            _try {
96                    func();
97            }
98            _except(EXCEPTION_EXECUTE_HANDLER) {
99    
100                    if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
101                            return 1;
102            }
103            return 0;
104    #else
105        void * old_handler;
106        int jmpret;
107    
108    
109        old_handler = signal(SIGILL, sigill_handler);
110        if (old_handler == SIG_ERR)
111        {
112            return -1;
113        }
114    
115        jmpret = setjmp(mark);
116        if (jmpret == 0)
117        {
118            func();
119        }
120    
121        signal(SIGILL, old_handler);
122    
123        return jmpret;
124    #endif
125    }
126    #endif
127    
128    /*****************************************************************************
129     * XviD Init Entry point
130     *
131     * Well this function initialize all internal function pointers according
132     * to the CPU features forced by the library client or autodetected (depending
133     * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
134     * image colorspace transformation tables.
135     *
136     * Returned value : XVID_ERR_OK
137     *                  + API_VERSION in the input XVID_INIT_PARAM structure
138     *                  + core build  "   "    "       "               "
139     *
140     ****************************************************************************/
141    
142    int
143    xvid_init(void *handle,
144                      int opt,
145                      void *param1,
146                      void *param2)
147  {  {
148          int cpu_flags;          int cpu_flags;
149          XVID_INIT_PARAM *init_param;          XVID_INIT_PARAM *init_param;
150    
151          init_param = (XVID_INIT_PARAM *) param1;          init_param = (XVID_INIT_PARAM *) param1;
152    
153          // force specific cpu settings?          /* Inform the client the API version */
154          if((init_param->cpu_flags & XVID_CPU_FORCE) > 0)          init_param->api_version = API_VERSION;
155    
156            /* Inform the client the core build - unused because we're still alpha */
157            init_param->core_build = 1000;
158    
159            /* Do we have to force CPU features  ? */
160            if ((init_param->cpu_flags & XVID_CPU_FORCE)) {
161    
162                  cpu_flags = init_param->cpu_flags;                  cpu_flags = init_param->cpu_flags;
         else {  
163    
164  #ifdef ARCH_X86          } else {
165    
166                  cpu_flags = check_cpu_features();                  cpu_flags = check_cpu_features();
167  #else  
168                  cpu_flags = 0;  #if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE)
169                    if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))
170                            cpu_flags &= ~XVID_CPU_SSE;
171    
172                    if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))
173                            cpu_flags &= ~XVID_CPU_SSE2;
174  #endif  #endif
175            }
176    
177            if ((init_param->cpu_flags & XVID_CPU_CHKONLY))
178            {
179                  init_param->cpu_flags = cpu_flags;                  init_param->cpu_flags = cpu_flags;
180                    return XVID_ERR_OK;
181          }          }
182    
183          // initialize the function pointers          init_param->cpu_flags = cpu_flags;
184    
185    
186            /* Initialize the function pointers */
187          idct_int32_init();          idct_int32_init();
188            init_vlc_tables();
189    
190            /* Fixed Point Forward/Inverse DCT transformations */
191          fdct = fdct_int32;          fdct = fdct_int32;
192          idct = idct_int32;          idct = idct_int32;
193    
194            /* Only needed on PPC Altivec archs */
195            sadInit = 0;
196    
197            /* Restore FPU context : emms_c is a nop functions */
198          emms = emms_c;          emms = emms_c;
199    
200            /* Quantization functions */
201          quant_intra = quant_intra_c;          quant_intra = quant_intra_c;
202          dequant_intra = dequant_intra_c;          dequant_intra = dequant_intra_c;
203          quant_inter = quant_inter_c;          quant_inter = quant_inter_c;
# Line 92  Line 208 
208          quant4_inter = quant4_inter_c;          quant4_inter = quant4_inter_c;
209          dequant4_inter = dequant4_inter_c;          dequant4_inter = dequant4_inter_c;
210    
211            /* Block transfer related functions */
212          transfer_8to16copy = transfer_8to16copy_c;          transfer_8to16copy = transfer_8to16copy_c;
213          transfer_16to8copy = transfer_16to8copy_c;          transfer_16to8copy = transfer_16to8copy_c;
214          transfer_8to16sub = transfer_8to16sub_c;          transfer_8to16sub = transfer_8to16sub_c;
215            transfer_8to16sub2 = transfer_8to16sub2_c;
216          transfer_16to8add = transfer_16to8add_c;          transfer_16to8add = transfer_16to8add_c;
217          transfer8x8_copy = transfer8x8_copy_c;          transfer8x8_copy = transfer8x8_copy_c;
218    
219            /* Image interpolation related functions */
220          interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;          interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;
221          interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;          interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;
222          interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;          interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;
223    
224            /* Initialize internal colorspace transformation tables */
225          colorspace_init();          colorspace_init();
226    
227            /* All colorspace transformation functions User Format->YV12 */
228          rgb555_to_yv12 = rgb555_to_yv12_c;          rgb555_to_yv12 = rgb555_to_yv12_c;
229          rgb565_to_yv12 = rgb565_to_yv12_c;          rgb565_to_yv12 = rgb565_to_yv12_c;
230          rgb24_to_yv12 = rgb24_to_yv12_c;          rgb24_to_yv12 = rgb24_to_yv12_c;
# Line 112  Line 233 
233          yuyv_to_yv12 = yuyv_to_yv12_c;          yuyv_to_yv12 = yuyv_to_yv12_c;
234          uyvy_to_yv12 = uyvy_to_yv12_c;          uyvy_to_yv12 = uyvy_to_yv12_c;
235    
236            /* All colorspace transformation functions YV12->User format */
237          yv12_to_rgb555 = yv12_to_rgb555_c;          yv12_to_rgb555 = yv12_to_rgb555_c;
238          yv12_to_rgb565 = yv12_to_rgb565_c;          yv12_to_rgb565 = yv12_to_rgb565_c;
239          yv12_to_rgb24 = yv12_to_rgb24_c;          yv12_to_rgb24 = yv12_to_rgb24_c;
# Line 120  Line 242 
242          yv12_to_yuyv = yv12_to_yuyv_c;          yv12_to_yuyv = yv12_to_yuyv_c;
243          yv12_to_uyvy = yv12_to_uyvy_c;          yv12_to_uyvy = yv12_to_uyvy_c;
244    
245            /* Functions used in motion estimation algorithms */
246          calc_cbp = calc_cbp_c;          calc_cbp = calc_cbp_c;
247          sad16 = sad16_c;          sad16 = sad16_c;
248            sad16bi  = sad16bi_c;
249          sad8 = sad8_c;          sad8 = sad8_c;
250          dev16 = dev16_c;          dev16 = dev16_c;
251            Halfpel8_Refine = Halfpel8_Refine_c;
252    
253  #ifdef ARCH_X86  #ifdef ARCH_X86
254          if((cpu_flags & XVID_CPU_MMX) > 0) {          if((cpu_flags & XVID_CPU_MMX) > 0) {
255    
256                    /* Forward and Inverse Discrete Cosine Transformation functions */
257                  fdct = fdct_mmx;                  fdct = fdct_mmx;
258                  idct = idct_mmx;                  idct = idct_mmx;
259    
260                    /* To restore FPU context after mmx use */
261                  emms = emms_mmx;                  emms = emms_mmx;
262    
263                    /* Quantization related functions */
264                  quant_intra = quant_intra_mmx;                  quant_intra = quant_intra_mmx;
265                  dequant_intra = dequant_intra_mmx;                  dequant_intra = dequant_intra_mmx;
266                  quant_inter = quant_inter_mmx;                  quant_inter = quant_inter_mmx;
# Line 142  Line 271 
271                  quant4_inter = quant4_inter_mmx;                  quant4_inter = quant4_inter_mmx;
272                  dequant4_inter = dequant4_inter_mmx;                  dequant4_inter = dequant4_inter_mmx;
273    
274                    /* Block related functions */
275                  transfer_8to16copy = transfer_8to16copy_mmx;                  transfer_8to16copy = transfer_8to16copy_mmx;
276                  transfer_16to8copy = transfer_16to8copy_mmx;                  transfer_16to8copy = transfer_16to8copy_mmx;
277                  transfer_8to16sub = transfer_8to16sub_mmx;                  transfer_8to16sub = transfer_8to16sub_mmx;
278                    transfer_8to16sub2 = transfer_8to16sub2_mmx;
279                  transfer_16to8add = transfer_16to8add_mmx;                  transfer_16to8add = transfer_16to8add_mmx;
280                  transfer8x8_copy = transfer8x8_copy_mmx;                  transfer8x8_copy = transfer8x8_copy_mmx;
281    
282    
283                    /* Image Interpolation related functions */
284                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;
285                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;
286                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;
287    
288                    /* Image RGB->YV12 related functions */
289                  rgb24_to_yv12 = rgb24_to_yv12_mmx;                  rgb24_to_yv12 = rgb24_to_yv12_mmx;
290                  rgb32_to_yv12 = rgb32_to_yv12_mmx;                  rgb32_to_yv12 = rgb32_to_yv12_mmx;
291                  yuv_to_yv12 = yuv_to_yv12_mmx;                  yuv_to_yv12 = yuv_to_yv12_mmx;
292                  yuyv_to_yv12 = yuyv_to_yv12_mmx;                  yuyv_to_yv12 = yuyv_to_yv12_mmx;
293                  uyvy_to_yv12 = uyvy_to_yv12_mmx;                  uyvy_to_yv12 = uyvy_to_yv12_mmx;
294    
295                    /* Image YV12->RGB related functions */
296                  yv12_to_rgb24 = yv12_to_rgb24_mmx;                  yv12_to_rgb24 = yv12_to_rgb24_mmx;
297                  yv12_to_rgb32 = yv12_to_rgb32_mmx;                  yv12_to_rgb32 = yv12_to_rgb32_mmx;
298                  yv12_to_yuyv = yv12_to_yuyv_mmx;                  yv12_to_yuyv = yv12_to_yuyv_mmx;
299                  yv12_to_uyvy = yv12_to_uyvy_mmx;                  yv12_to_uyvy = yv12_to_uyvy_mmx;
300    
301                    /* Motion estimation related functions */
302                  calc_cbp = calc_cbp_mmx;                  calc_cbp = calc_cbp_mmx;
303                  sad16 = sad16_mmx;                  sad16 = sad16_mmx;
304                  sad8 = sad8_mmx;                  sad8 = sad8_mmx;
# Line 171  Line 307 
307          }          }
308    
309          if((cpu_flags & XVID_CPU_MMXEXT) > 0) {          if((cpu_flags & XVID_CPU_MMXEXT) > 0) {
310    
311                    /* Inverse DCT */
312                  idct = idct_xmm;                  idct = idct_xmm;
313    
314                    /* Interpolation */
315                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;
316                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;
317                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;
318    
319                    /* Quantization */
320                    dequant_intra = dequant_intra_xmm;
321                    dequant_inter = dequant_inter_xmm;
322    
323                    /* Buffer transfer */
324                    transfer_8to16sub2 = transfer_8to16sub2_xmm;
325    
326                    /* Colorspace transformation */
327                  yuv_to_yv12 = yuv_to_yv12_xmm;                  yuv_to_yv12 = yuv_to_yv12_xmm;
328    
329                    /* ME functions */
330                  sad16 = sad16_xmm;                  sad16 = sad16_xmm;
331                    sad16bi = sad16bi_xmm;
332                  sad8 = sad8_xmm;                  sad8 = sad8_xmm;
333                  dev16 = dev16_xmm;                  dev16 = dev16_xmm;
334    
335          }          }
336    
337          if((cpu_flags & XVID_CPU_3DNOW) > 0) {          if((cpu_flags & XVID_CPU_3DNOW) > 0) {
338    
339                    /* Interpolation */
340                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;                  interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
341                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;                  interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
342                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;                  interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
343          }          }
344    
345            if ((cpu_flags & XVID_CPU_SSE2) > 0) {
346    #ifdef EXPERIMENTAL_SSE2_CODE
347    
348                    calc_cbp = calc_cbp_sse2;
349    
350                    /* Quantization */
351                    quant_intra   = quant_intra_sse2;
352                    dequant_intra = dequant_intra_sse2;
353                    quant_inter   = quant_inter_sse2;
354                    dequant_inter = dequant_inter_sse2;
355    
356                    /* ME */
357                    sad16    = sad16_sse2;
358                    dev16    = dev16_sse2;
359    
360                    /* Forward and Inverse DCT */
361                    idct  = idct_sse2;
362                    fdct = fdct_sse2;
363  #endif  #endif
364  #ifdef ARCH_PPC          }
365          calc_cbp = calc_cbp_ppc;  
366  #endif  #endif
367    
368          // API version  #ifdef ARCH_IA64
369          init_param->api_version = API_VERSION;          if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines?
370              idct_ia64_init();
371              fdct = fdct_ia64;
372              idct = idct_ia64;   //not yet working, crashes
373              interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
374              interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
375              interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
376              sad16 = sad16_ia64;
377              sad16bi = sad16bi_ia64;
378              sad8 = sad8_ia64;
379              dev16 = dev16_ia64;
380              Halfpel8_Refine = Halfpel8_Refine_ia64;
381              quant_intra = quant_intra_ia64;
382              dequant_intra = dequant_intra_ia64;
383              quant_inter = quant_inter_ia64;
384              dequant_inter = dequant_inter_ia64;
385              transfer_8to16copy = transfer_8to16copy_ia64;
386              transfer_16to8copy = transfer_16to8copy_ia64;
387              transfer_8to16sub = transfer_8to16sub_ia64;
388              transfer_8to16sub2 = transfer_8to16sub2_ia64;
389              transfer_16to8add = transfer_16to8add_ia64;
390              transfer8x8_copy = transfer8x8_copy_ia64;
391              DEBUG("Using IA-64 assembler routines.\n");
392            }
393    #endif
394    
395          // something clever has to be done for this  #ifdef ARCH_PPC
396          init_param->core_build = 1000;  #ifdef ARCH_PPC_ALTIVEC
397            calc_cbp = calc_cbp_altivec;
398            fdct = fdct_altivec;
399            idct = idct_altivec;
400            sadInit = sadInit_altivec;
401            sad16 = sad16_altivec;
402            sad8 = sad8_altivec;
403            dev16 = dev16_altivec;
404    #else
405            calc_cbp = calc_cbp_ppc;
406    #endif
407    #endif
408    
409          return XVID_ERR_OK;          return XVID_ERR_OK;
410  }  }
411    
412  int xvid_decore(void * handle, int opt, void * param1, void * param2)  /*****************************************************************************
413  {   * XviD Native decoder entry point
414          switch (opt)   *
415     * This function is just a wrapper to all the option cases.
416     *
417     * Returned values : XVID_ERR_FAIL when opt is invalid
418     *                   else returns the wrapped function result
419     *
420     ****************************************************************************/
421    
422    int
423    xvid_decore(void *handle,
424                            int opt,
425                            void *param1,
426                            void *param2)
427          {          {
428            switch (opt) {
429          case XVID_DEC_DECODE :          case XVID_DEC_DECODE :
430          return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1);          return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1);
431    
# Line 222  Line 441 
441  }  }
442    
443    
444  int xvid_encore(void * handle, int opt, void * param1, void * param2)  /*****************************************************************************
445  {   * XviD Native encoder entry point
446          switch (opt)   *
447     * This function is just a wrapper to all the option cases.
448     *
449     * Returned values : XVID_ERR_FAIL when opt is invalid
450     *                   else returns the wrapped function result
451     *
452     ****************************************************************************/
453    
454    int
455    xvid_encore(void *handle,
456                            int opt,
457                            void *param1,
458                            void *param2)
459          {          {
460            switch (opt) {
461          case XVID_ENC_ENCODE :          case XVID_ENC_ENCODE :
462          return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, (XVID_ENC_STATS *) param2);  #ifdef BFRAMES
463                    if (((Encoder *) handle)->mbParam.max_bframes >= 0)
464                    return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,
465                                                              (XVID_ENC_STATS *) param2);
466                    else
467    #endif
468                    return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,
469                                                              (XVID_ENC_STATS *) param2);
470    
471          case XVID_ENC_CREATE :          case XVID_ENC_CREATE :
472          return encoder_create((XVID_ENC_PARAM *) param1);          return encoder_create((XVID_ENC_PARAM *) param1);

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.31

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