[cvs] / xvidcore / src / xvid.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/xvid.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (view) (download)

1 : edgomez 1.16 /*****************************************************************************
2 : edgomez 1.17 *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Native API implementation -
5 :     *
6 :     * 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
8 :     * to use this software module in hardware or software products are
9 :     * advised that its use may infringe existing patents or copyrights, and
10 :     * any such use would be at such party's own risk. The original
11 :     * developer of this software module and his/her company, and subsequent
12 :     * editors and their companies, will have no liability for use of this
13 :     * software or modifications or derivatives thereof.
14 :     *
15 :     * This program is free software ; you can redistribute it and/or modify
16 :     * it under the terms of the GNU General Public License as published by
17 :     * the Free Software Foundation ; either version 2 of the License, or
18 :     * (at your option) any later version.
19 :     *
20 :     * This program is distributed in the hope that it will be useful,
21 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
22 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 :     * GNU General Public License for more details.
24 :     *
25 :     * You should have received a copy of the GNU General Public License
26 :     * along with this program ; if not, write to the Free Software
27 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 :     *
29 :     ****************************************************************************/
30 : Isibaar 1.24
31 : edgomez 1.16 /*****************************************************************************
32 : edgomez 1.17 *
33 :     * History
34 :     *
35 : suxen_drol 1.21 * - 23.06.2002 added XVID_CPU_CHKONLY
36 : edgomez 1.17 * - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm
37 :     * - 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 : Isibaar 1.24 * $Id: xvid.c,v 1.23 2002/06/26 15:59:51 ia64p Exp $
41 : edgomez 1.17 *
42 :     ****************************************************************************/
43 : Isibaar 1.1
44 :     #include "xvid.h"
45 :     #include "decoder.h"
46 :     #include "encoder.h"
47 :     #include "bitstream/cbp.h"
48 :     #include "dct/idct.h"
49 :     #include "dct/fdct.h"
50 :     #include "image/colorspace.h"
51 :     #include "image/interpolate8x8.h"
52 :     #include "utils/mem_transfer.h"
53 :     #include "quant/quant_h263.h"
54 :     #include "quant/quant_mpeg4.h"
55 :     #include "motion/sad.h"
56 :     #include "utils/emms.h"
57 :     #include "utils/timer.h"
58 : Isibaar 1.9 #include "bitstream/mbcoding.h"
59 : Isibaar 1.1
60 : edgomez 1.16 /*****************************************************************************
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 : edgomez 1.15 int
75 :     xvid_init(void *handle,
76 :     int opt,
77 :     void *param1,
78 :     void *param2)
79 : Isibaar 1.1 {
80 :     int cpu_flags;
81 :     XVID_INIT_PARAM *init_param;
82 :    
83 :     init_param = (XVID_INIT_PARAM *) param1;
84 :    
85 : suxen_drol 1.21 /* Inform the client the API version */
86 :     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 : edgomez 1.16 /* Do we have to force CPU features ? */
98 :     if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) {
99 : Isibaar 1.1 cpu_flags = init_param->cpu_flags;
100 : edgomez 1.16 } else {
101 : Isibaar 1.1
102 :     cpu_flags = check_cpu_features();
103 :     init_param->cpu_flags = cpu_flags;
104 :     }
105 :    
106 : edgomez 1.16 /* Initialize the function pointers */
107 : Isibaar 1.1 idct_int32_init();
108 : Isibaar 1.9 init_vlc_tables();
109 :    
110 : edgomez 1.16 /* Fixed Point Forward/Inverse DCT transformations */
111 : Isibaar 1.1 fdct = fdct_int32;
112 :     idct = idct_int32;
113 :    
114 : edgomez 1.16 /* Only needed on PPC Altivec archs */
115 : canard 1.10 sadInit = 0;
116 : edgomez 1.15
117 : edgomez 1.16 /* Restore FPU context : emms_c is a nop functions */
118 : Isibaar 1.1 emms = emms_c;
119 :    
120 : edgomez 1.16 /* Quantization functions */
121 :     quant_intra = quant_intra_c;
122 : Isibaar 1.1 dequant_intra = dequant_intra_c;
123 : edgomez 1.16 quant_inter = quant_inter_c;
124 : Isibaar 1.1 dequant_inter = dequant_inter_c;
125 :    
126 : edgomez 1.16 quant4_intra = quant4_intra_c;
127 : Isibaar 1.1 dequant4_intra = dequant4_intra_c;
128 : edgomez 1.16 quant4_inter = quant4_inter_c;
129 : Isibaar 1.1 dequant4_inter = dequant4_inter_c;
130 :    
131 : edgomez 1.16 /* Block transfer related functions */
132 : Isibaar 1.1 transfer_8to16copy = transfer_8to16copy_c;
133 :     transfer_16to8copy = transfer_16to8copy_c;
134 : edgomez 1.16 transfer_8to16sub = transfer_8to16sub_c;
135 : suxen_drol 1.11 transfer_8to16sub2 = transfer_8to16sub2_c;
136 : edgomez 1.16 transfer_16to8add = transfer_16to8add_c;
137 :     transfer8x8_copy = transfer8x8_copy_c;
138 : Isibaar 1.1
139 : edgomez 1.16 /* Image interpolation related functions */
140 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;
141 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;
142 : Isibaar 1.1 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;
143 :    
144 : edgomez 1.16 /* Initialize internal colorspace transformation tables */
145 : Isibaar 1.1 colorspace_init();
146 :    
147 : edgomez 1.16 /* All colorspace transformation functions User Format->YV12 */
148 : Isibaar 1.1 rgb555_to_yv12 = rgb555_to_yv12_c;
149 :     rgb565_to_yv12 = rgb565_to_yv12_c;
150 : edgomez 1.16 rgb24_to_yv12 = rgb24_to_yv12_c;
151 :     rgb32_to_yv12 = rgb32_to_yv12_c;
152 :     yuv_to_yv12 = yuv_to_yv12_c;
153 :     yuyv_to_yv12 = yuyv_to_yv12_c;
154 :     uyvy_to_yv12 = uyvy_to_yv12_c;
155 : Isibaar 1.1
156 : edgomez 1.16 /* All colorspace transformation functions YV12->User format */
157 : Isibaar 1.1 yv12_to_rgb555 = yv12_to_rgb555_c;
158 :     yv12_to_rgb565 = yv12_to_rgb565_c;
159 : edgomez 1.16 yv12_to_rgb24 = yv12_to_rgb24_c;
160 :     yv12_to_rgb32 = yv12_to_rgb32_c;
161 :     yv12_to_yuv = yv12_to_yuv_c;
162 :     yv12_to_yuyv = yv12_to_yuyv_c;
163 :     yv12_to_uyvy = yv12_to_uyvy_c;
164 : Isibaar 1.1
165 : edgomez 1.16 /* Functions used in motion estimation algorithms */
166 : Isibaar 1.1 calc_cbp = calc_cbp_c;
167 : edgomez 1.16 sad16 = sad16_c;
168 :     sad16bi = sad16bi_c;
169 :     sad8 = sad8_c;
170 :     dev16 = dev16_c;
171 : Isibaar 1.1
172 :     #ifdef ARCH_X86
173 : edgomez 1.15 if ((cpu_flags & XVID_CPU_MMX) > 0) {
174 : edgomez 1.16
175 :     /* Forward and Inverse Discrete Cosine Transformation functions */
176 : Isibaar 1.1 fdct = fdct_mmx;
177 :     idct = idct_mmx;
178 :    
179 : edgomez 1.16 /* To restore FPU context after mmx use */
180 : Isibaar 1.1 emms = emms_mmx;
181 :    
182 : edgomez 1.16 /* Quantization related functions */
183 :     quant_intra = quant_intra_mmx;
184 : Isibaar 1.1 dequant_intra = dequant_intra_mmx;
185 : edgomez 1.16 quant_inter = quant_inter_mmx;
186 : Isibaar 1.1 dequant_inter = dequant_inter_mmx;
187 :    
188 : edgomez 1.16 quant4_intra = quant4_intra_mmx;
189 : Isibaar 1.1 dequant4_intra = dequant4_intra_mmx;
190 : edgomez 1.16 quant4_inter = quant4_inter_mmx;
191 : Isibaar 1.1 dequant4_inter = dequant4_inter_mmx;
192 :    
193 : edgomez 1.16 /* Block related functions */
194 : Isibaar 1.1 transfer_8to16copy = transfer_8to16copy_mmx;
195 :     transfer_16to8copy = transfer_16to8copy_mmx;
196 : edgomez 1.16 transfer_8to16sub = transfer_8to16sub_mmx;
197 : edgomez 1.22 transfer_8to16sub2 = transfer_8to16sub2_mmx;
198 : edgomez 1.16 transfer_16to8add = transfer_16to8add_mmx;
199 :     transfer8x8_copy = transfer8x8_copy_mmx;
200 : edgomez 1.22
201 : edgomez 1.16
202 :     /* Image Interpolation related functions */
203 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;
204 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;
205 : Isibaar 1.1 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;
206 :    
207 : edgomez 1.16 /* Image RGB->YV12 related functions */
208 : Isibaar 1.1 rgb24_to_yv12 = rgb24_to_yv12_mmx;
209 :     rgb32_to_yv12 = rgb32_to_yv12_mmx;
210 : edgomez 1.16 yuv_to_yv12 = yuv_to_yv12_mmx;
211 :     yuyv_to_yv12 = yuyv_to_yv12_mmx;
212 :     uyvy_to_yv12 = uyvy_to_yv12_mmx;
213 : Isibaar 1.1
214 : edgomez 1.16 /* Image YV12->RGB related functions */
215 : Isibaar 1.1 yv12_to_rgb24 = yv12_to_rgb24_mmx;
216 :     yv12_to_rgb32 = yv12_to_rgb32_mmx;
217 : edgomez 1.16 yv12_to_yuyv = yv12_to_yuyv_mmx;
218 :     yv12_to_uyvy = yv12_to_uyvy_mmx;
219 : Isibaar 1.1
220 : edgomez 1.16 /* Motion estimation related functions */
221 : Isibaar 1.1 calc_cbp = calc_cbp_mmx;
222 : edgomez 1.16 sad16 = sad16_mmx;
223 :     sad8 = sad8_mmx;
224 :     dev16 = dev16_mmx;
225 : Isibaar 1.1
226 :     }
227 :    
228 : edgomez 1.15 if ((cpu_flags & XVID_CPU_MMXEXT) > 0) {
229 : edgomez 1.16
230 :     /* Inverse DCT */
231 : Isibaar 1.1 idct = idct_xmm;
232 : edgomez 1.16
233 :     /* Interpolation */
234 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;
235 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;
236 : h 1.3 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;
237 : edgomez 1.19
238 :     /* Buffer transfer */
239 :     transfer_8to16sub2 = transfer_8to16sub2_xmm;
240 : edgomez 1.16
241 :     /* Colorspace transformation */
242 : Isibaar 1.1 yuv_to_yv12 = yuv_to_yv12_xmm;
243 :    
244 : edgomez 1.16 /* ME functions */
245 : Isibaar 1.1 sad16 = sad16_xmm;
246 : Isibaar 1.24 sad16bi = sad16bi_xmm;
247 : edgomez 1.16 sad8 = sad8_xmm;
248 : Isibaar 1.1 dev16 = dev16_xmm;
249 :    
250 :     }
251 :    
252 : edgomez 1.15 if ((cpu_flags & XVID_CPU_3DNOW) > 0) {
253 : edgomez 1.16
254 :     /* Interpolation */
255 : Isibaar 1.1 interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
256 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
257 : h 1.4 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
258 : Isibaar 1.1 }
259 :    
260 : edgomez 1.15 if ((cpu_flags & XVID_CPU_SSE2) > 0) {
261 : Isibaar 1.14 #ifdef EXPERIMENTAL_SSE2_CODE
262 : edgomez 1.16
263 : Isibaar 1.24 calc_cbp = calc_cbp_sse2;
264 :    
265 : edgomez 1.16 /* Quantization */
266 :     quant_intra = quant_intra_sse2;
267 : Isibaar 1.14 dequant_intra = dequant_intra_sse2;
268 : edgomez 1.16 quant_inter = quant_inter_sse2;
269 : Isibaar 1.14 dequant_inter = dequant_inter_sse2;
270 : h 1.13
271 : edgomez 1.16 /* ME */
272 :     sad16 = sad16_sse2;
273 :     dev16 = dev16_sse2;
274 :    
275 :     /* Forward and Inverse DCT */
276 :     idct = idct_sse2;
277 : Isibaar 1.14 fdct = fdct_sse2;
278 :     #endif
279 : h 1.12 }
280 : edgomez 1.16
281 : Isibaar 1.1 #endif
282 : Isibaar 1.18
283 :     #ifdef ARCH_IA64
284 :     if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines?
285 :     idct_ia64_init();
286 :     fdct = fdct_ia64;
287 :     idct = idct_ia64; //not yet working, crashes
288 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
289 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
290 :     interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
291 :     sad16 = sad16_ia64;
292 :     sad16bi = sad16bi_ia64;
293 :     sad8 = sad8_ia64;
294 :     dev16 = dev16_ia64;
295 :     quant_intra = quant_intra_ia64;
296 :     dequant_intra = dequant_intra_ia64;
297 :     quant_inter = quant_inter_ia64;
298 :     dequant_inter = dequant_inter_ia64;
299 :     transfer_8to16copy = transfer_8to16copy_ia64;
300 :     transfer_16to8copy = transfer_16to8copy_ia64;
301 :     transfer_8to16sub = transfer_8to16sub_ia64;
302 :     transfer_8to16sub2 = transfer_8to16sub2_ia64;
303 :     transfer_16to8add = transfer_16to8add_ia64;
304 :     transfer8x8_copy = transfer8x8_copy_ia64;
305 :     DEBUG("Using IA-64 assembler routines.\n");
306 :     }
307 :     #endif
308 : edgomez 1.16
309 : canard 1.5 #ifdef ARCH_PPC
310 : canard 1.6 #ifdef ARCH_PPC_ALTIVEC
311 :     calc_cbp = calc_cbp_altivec;
312 : canard 1.7 fdct = fdct_altivec;
313 :     idct = idct_altivec;
314 : canard 1.10 sadInit = sadInit_altivec;
315 : canard 1.8 sad16 = sad16_altivec;
316 :     sad8 = sad8_altivec;
317 :     dev16 = dev16_altivec;
318 : canard 1.6 #else
319 : canard 1.5 calc_cbp = calc_cbp_ppc;
320 : canard 1.6 #endif
321 : canard 1.5 #endif
322 : Isibaar 1.1
323 :     return XVID_ERR_OK;
324 :     }
325 :    
326 : edgomez 1.16 /*****************************************************************************
327 :     * XviD Native decoder entry point
328 :     *
329 :     * This function is just a wrapper to all the option cases.
330 :     *
331 :     * Returned values : XVID_ERR_FAIL when opt is invalid
332 :     * else returns the wrapped function result
333 :     *
334 :     ****************************************************************************/
335 :    
336 : edgomez 1.15 int
337 :     xvid_decore(void *handle,
338 :     int opt,
339 :     void *param1,
340 :     void *param2)
341 : Isibaar 1.1 {
342 : edgomez 1.15 switch (opt) {
343 :     case XVID_DEC_DECODE:
344 :     return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1);
345 :    
346 :     case XVID_DEC_CREATE:
347 :     return decoder_create((XVID_DEC_PARAM *) param1);
348 :    
349 :     case XVID_DEC_DESTROY:
350 :     return decoder_destroy((DECODER *) handle);
351 : Isibaar 1.1
352 :     default:
353 : edgomez 1.15 return XVID_ERR_FAIL;
354 :     }
355 : Isibaar 1.1 }
356 :    
357 : edgomez 1.16
358 :     /*****************************************************************************
359 :     * XviD Native encoder entry point
360 :     *
361 :     * This function is just a wrapper to all the option cases.
362 :     *
363 :     * Returned values : XVID_ERR_FAIL when opt is invalid
364 :     * else returns the wrapped function result
365 :     *
366 :     ****************************************************************************/
367 : Isibaar 1.1
368 : edgomez 1.15 int
369 :     xvid_encore(void *handle,
370 :     int opt,
371 :     void *param1,
372 :     void *param2)
373 : Isibaar 1.1 {
374 : edgomez 1.15 switch (opt) {
375 :     case XVID_ENC_ENCODE:
376 : suxen_drol 1.20 #ifdef BFRAMES
377 :     if (((Encoder *) handle)->mbParam.max_bframes >= 0)
378 :     return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1,
379 :     (XVID_ENC_STATS *) param2);
380 :     else
381 :     #endif
382 : edgomez 1.15 return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1,
383 :     (XVID_ENC_STATS *) param2);
384 :    
385 :     case XVID_ENC_CREATE:
386 :     return encoder_create((XVID_ENC_PARAM *) param1);
387 :    
388 :     case XVID_ENC_DESTROY:
389 :     return encoder_destroy((Encoder *) handle);
390 : Isibaar 1.1
391 :     default:
392 : edgomez 1.15 return XVID_ERR_FAIL;
393 :     }
394 : Isibaar 1.1 }

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