Parent Directory | Revision Log
Revision 245 - (view) (download)
1 : | edgomez | 200 | /***************************************************************************** |
2 : | edgomez | 201 | * |
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 : | edgomez | 200 | /***************************************************************************** |
31 : | edgomez | 201 | * |
32 : | * History | ||
33 : | * | ||
34 : | suxen_drol | 234 | * - 23.06.2002 added XVID_CPU_CHKONLY |
35 : | edgomez | 201 | * - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
36 : | * - 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 : | ia64p | 245 | * $Id: xvid.c,v 1.23 2002-06-26 15:59:51 ia64p Exp $ |
40 : | edgomez | 201 | * |
41 : | ****************************************************************************/ | ||
42 : | Isibaar | 3 | |
43 : | #include "xvid.h" | ||
44 : | #include "decoder.h" | ||
45 : | #include "encoder.h" | ||
46 : | #include "bitstream/cbp.h" | ||
47 : | #include "dct/idct.h" | ||
48 : | #include "dct/fdct.h" | ||
49 : | #include "image/colorspace.h" | ||
50 : | #include "image/interpolate8x8.h" | ||
51 : | #include "utils/mem_transfer.h" | ||
52 : | #include "quant/quant_h263.h" | ||
53 : | #include "quant/quant_mpeg4.h" | ||
54 : | #include "motion/sad.h" | ||
55 : | #include "utils/emms.h" | ||
56 : | #include "utils/timer.h" | ||
57 : | Isibaar | 100 | #include "bitstream/mbcoding.h" |
58 : | Isibaar | 3 | |
59 : | edgomez | 200 | /***************************************************************************** |
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 : | edgomez | 195 | int |
74 : | xvid_init(void *handle, | ||
75 : | int opt, | ||
76 : | void *param1, | ||
77 : | void *param2) | ||
78 : | Isibaar | 3 | { |
79 : | int cpu_flags; | ||
80 : | XVID_INIT_PARAM *init_param; | ||
81 : | |||
82 : | init_param = (XVID_INIT_PARAM *) param1; | ||
83 : | |||
84 : | suxen_drol | 234 | /* Inform the client the API version */ |
85 : | 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 : | edgomez | 200 | /* Do we have to force CPU features ? */ |
97 : | if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { | ||
98 : | Isibaar | 3 | cpu_flags = init_param->cpu_flags; |
99 : | edgomez | 200 | } else { |
100 : | Isibaar | 3 | |
101 : | cpu_flags = check_cpu_features(); | ||
102 : | init_param->cpu_flags = cpu_flags; | ||
103 : | } | ||
104 : | |||
105 : | edgomez | 200 | /* Initialize the function pointers */ |
106 : | Isibaar | 3 | idct_int32_init(); |
107 : | Isibaar | 100 | init_vlc_tables(); |
108 : | |||
109 : | edgomez | 200 | /* Fixed Point Forward/Inverse DCT transformations */ |
110 : | Isibaar | 3 | fdct = fdct_int32; |
111 : | idct = idct_int32; | ||
112 : | |||
113 : | edgomez | 200 | /* Only needed on PPC Altivec archs */ |
114 : | canard | 115 | sadInit = 0; |
115 : | edgomez | 195 | |
116 : | edgomez | 200 | /* Restore FPU context : emms_c is a nop functions */ |
117 : | Isibaar | 3 | emms = emms_c; |
118 : | |||
119 : | edgomez | 200 | /* Quantization functions */ |
120 : | quant_intra = quant_intra_c; | ||
121 : | Isibaar | 3 | dequant_intra = dequant_intra_c; |
122 : | edgomez | 200 | quant_inter = quant_inter_c; |
123 : | Isibaar | 3 | dequant_inter = dequant_inter_c; |
124 : | |||
125 : | edgomez | 200 | quant4_intra = quant4_intra_c; |
126 : | Isibaar | 3 | dequant4_intra = dequant4_intra_c; |
127 : | edgomez | 200 | quant4_inter = quant4_inter_c; |
128 : | Isibaar | 3 | dequant4_inter = dequant4_inter_c; |
129 : | |||
130 : | edgomez | 200 | /* Block transfer related functions */ |
131 : | Isibaar | 3 | transfer_8to16copy = transfer_8to16copy_c; |
132 : | transfer_16to8copy = transfer_16to8copy_c; | ||
133 : | edgomez | 200 | transfer_8to16sub = transfer_8to16sub_c; |
134 : | suxen_drol | 118 | transfer_8to16sub2 = transfer_8to16sub2_c; |
135 : | edgomez | 200 | transfer_16to8add = transfer_16to8add_c; |
136 : | transfer8x8_copy = transfer8x8_copy_c; | ||
137 : | Isibaar | 3 | |
138 : | edgomez | 200 | /* Image interpolation related functions */ |
139 : | interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; | ||
140 : | interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; | ||
141 : | Isibaar | 3 | interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
142 : | |||
143 : | edgomez | 200 | /* Initialize internal colorspace transformation tables */ |
144 : | Isibaar | 3 | colorspace_init(); |
145 : | |||
146 : | edgomez | 200 | /* All colorspace transformation functions User Format->YV12 */ |
147 : | Isibaar | 3 | rgb555_to_yv12 = rgb555_to_yv12_c; |
148 : | rgb565_to_yv12 = rgb565_to_yv12_c; | ||
149 : | edgomez | 200 | rgb24_to_yv12 = rgb24_to_yv12_c; |
150 : | rgb32_to_yv12 = rgb32_to_yv12_c; | ||
151 : | yuv_to_yv12 = yuv_to_yv12_c; | ||
152 : | yuyv_to_yv12 = yuyv_to_yv12_c; | ||
153 : | uyvy_to_yv12 = uyvy_to_yv12_c; | ||
154 : | Isibaar | 3 | |
155 : | edgomez | 200 | /* All colorspace transformation functions YV12->User format */ |
156 : | Isibaar | 3 | yv12_to_rgb555 = yv12_to_rgb555_c; |
157 : | yv12_to_rgb565 = yv12_to_rgb565_c; | ||
158 : | edgomez | 200 | yv12_to_rgb24 = yv12_to_rgb24_c; |
159 : | yv12_to_rgb32 = yv12_to_rgb32_c; | ||
160 : | yv12_to_yuv = yv12_to_yuv_c; | ||
161 : | yv12_to_yuyv = yv12_to_yuyv_c; | ||
162 : | yv12_to_uyvy = yv12_to_uyvy_c; | ||
163 : | Isibaar | 3 | |
164 : | edgomez | 200 | /* Functions used in motion estimation algorithms */ |
165 : | Isibaar | 3 | calc_cbp = calc_cbp_c; |
166 : | edgomez | 200 | sad16 = sad16_c; |
167 : | sad16bi = sad16bi_c; | ||
168 : | sad8 = sad8_c; | ||
169 : | dev16 = dev16_c; | ||
170 : | Isibaar | 3 | |
171 : | #ifdef ARCH_X86 | ||
172 : | edgomez | 195 | if ((cpu_flags & XVID_CPU_MMX) > 0) { |
173 : | edgomez | 200 | |
174 : | /* Forward and Inverse Discrete Cosine Transformation functions */ | ||
175 : | Isibaar | 3 | fdct = fdct_mmx; |
176 : | idct = idct_mmx; | ||
177 : | |||
178 : | edgomez | 200 | /* To restore FPU context after mmx use */ |
179 : | Isibaar | 3 | emms = emms_mmx; |
180 : | |||
181 : | edgomez | 200 | /* Quantization related functions */ |
182 : | quant_intra = quant_intra_mmx; | ||
183 : | Isibaar | 3 | dequant_intra = dequant_intra_mmx; |
184 : | edgomez | 200 | quant_inter = quant_inter_mmx; |
185 : | Isibaar | 3 | dequant_inter = dequant_inter_mmx; |
186 : | |||
187 : | edgomez | 200 | quant4_intra = quant4_intra_mmx; |
188 : | Isibaar | 3 | dequant4_intra = dequant4_intra_mmx; |
189 : | edgomez | 200 | quant4_inter = quant4_inter_mmx; |
190 : | Isibaar | 3 | dequant4_inter = dequant4_inter_mmx; |
191 : | |||
192 : | edgomez | 200 | /* Block related functions */ |
193 : | Isibaar | 3 | transfer_8to16copy = transfer_8to16copy_mmx; |
194 : | transfer_16to8copy = transfer_16to8copy_mmx; | ||
195 : | edgomez | 200 | transfer_8to16sub = transfer_8to16sub_mmx; |
196 : | edgomez | 236 | transfer_8to16sub2 = transfer_8to16sub2_mmx; |
197 : | edgomez | 200 | transfer_16to8add = transfer_16to8add_mmx; |
198 : | transfer8x8_copy = transfer8x8_copy_mmx; | ||
199 : | Isibaar | 3 | |
200 : | edgomez | 236 | |
201 : | edgomez | 200 | /* Image Interpolation related functions */ |
202 : | interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; | ||
203 : | interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; | ||
204 : | Isibaar | 3 | interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
205 : | |||
206 : | edgomez | 200 | /* Image RGB->YV12 related functions */ |
207 : | Isibaar | 3 | rgb24_to_yv12 = rgb24_to_yv12_mmx; |
208 : | rgb32_to_yv12 = rgb32_to_yv12_mmx; | ||
209 : | edgomez | 200 | yuv_to_yv12 = yuv_to_yv12_mmx; |
210 : | yuyv_to_yv12 = yuyv_to_yv12_mmx; | ||
211 : | uyvy_to_yv12 = uyvy_to_yv12_mmx; | ||
212 : | Isibaar | 3 | |
213 : | edgomez | 200 | /* Image YV12->RGB related functions */ |
214 : | Isibaar | 3 | yv12_to_rgb24 = yv12_to_rgb24_mmx; |
215 : | yv12_to_rgb32 = yv12_to_rgb32_mmx; | ||
216 : | edgomez | 200 | yv12_to_yuyv = yv12_to_yuyv_mmx; |
217 : | yv12_to_uyvy = yv12_to_uyvy_mmx; | ||
218 : | Isibaar | 3 | |
219 : | edgomez | 200 | /* Motion estimation related functions */ |
220 : | Isibaar | 3 | calc_cbp = calc_cbp_mmx; |
221 : | edgomez | 200 | sad16 = sad16_mmx; |
222 : | sad8 = sad8_mmx; | ||
223 : | dev16 = dev16_mmx; | ||
224 : | Isibaar | 3 | |
225 : | } | ||
226 : | |||
227 : | edgomez | 195 | if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
228 : | edgomez | 200 | |
229 : | /* Inverse DCT */ | ||
230 : | Isibaar | 3 | idct = idct_xmm; |
231 : | edgomez | 200 | |
232 : | /* Interpolation */ | ||
233 : | interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; | ||
234 : | interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; | ||
235 : | h | 38 | interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
236 : | edgomez | 200 | |
237 : | edgomez | 218 | /* Buffer transfer */ |
238 : | transfer_8to16sub2 = transfer_8to16sub2_xmm; | ||
239 : | |||
240 : | edgomez | 200 | /* Colorspace transformation */ |
241 : | Isibaar | 3 | yuv_to_yv12 = yuv_to_yv12_xmm; |
242 : | |||
243 : | edgomez | 200 | /* ME functions */ |
244 : | Isibaar | 3 | sad16 = sad16_xmm; |
245 : | edgomez | 200 | sad8 = sad8_xmm; |
246 : | Isibaar | 3 | dev16 = dev16_xmm; |
247 : | |||
248 : | } | ||
249 : | |||
250 : | edgomez | 195 | if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
251 : | edgomez | 200 | |
252 : | /* Interpolation */ | ||
253 : | Isibaar | 3 | interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
254 : | interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; | ||
255 : | h | 40 | interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
256 : | Isibaar | 3 | } |
257 : | |||
258 : | edgomez | 195 | if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
259 : | Isibaar | 154 | #ifdef EXPERIMENTAL_SSE2_CODE |
260 : | edgomez | 200 | |
261 : | /* Quantization */ | ||
262 : | quant_intra = quant_intra_sse2; | ||
263 : | Isibaar | 154 | dequant_intra = dequant_intra_sse2; |
264 : | edgomez | 200 | quant_inter = quant_inter_sse2; |
265 : | Isibaar | 154 | dequant_inter = dequant_inter_sse2; |
266 : | h | 135 | |
267 : | edgomez | 200 | /* ME */ |
268 : | Isibaar | 154 | calc_cbp = calc_cbp_sse2; |
269 : | edgomez | 200 | sad16 = sad16_sse2; |
270 : | dev16 = dev16_sse2; | ||
271 : | |||
272 : | /* Forward and Inverse DCT */ | ||
273 : | idct = idct_sse2; | ||
274 : | Isibaar | 154 | fdct = fdct_sse2; |
275 : | #endif | ||
276 : | h | 126 | } |
277 : | edgomez | 200 | |
278 : | Isibaar | 3 | #endif |
279 : | edgomez | 200 | |
280 : | Isibaar | 209 | #ifdef ARCH_IA64 |
281 : | if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? | ||
282 : | idct_ia64_init(); | ||
283 : | fdct = fdct_ia64; | ||
284 : | idct = idct_ia64; //not yet working, crashes | ||
285 : | interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; | ||
286 : | interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; | ||
287 : | interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; | ||
288 : | sad16 = sad16_ia64; | ||
289 : | sad16bi = sad16bi_ia64; | ||
290 : | sad8 = sad8_ia64; | ||
291 : | dev16 = dev16_ia64; | ||
292 : | quant_intra = quant_intra_ia64; | ||
293 : | dequant_intra = dequant_intra_ia64; | ||
294 : | quant_inter = quant_inter_ia64; | ||
295 : | dequant_inter = dequant_inter_ia64; | ||
296 : | transfer_8to16copy = transfer_8to16copy_ia64; | ||
297 : | transfer_16to8copy = transfer_16to8copy_ia64; | ||
298 : | transfer_8to16sub = transfer_8to16sub_ia64; | ||
299 : | transfer_8to16sub2 = transfer_8to16sub2_ia64; | ||
300 : | transfer_16to8add = transfer_16to8add_ia64; | ||
301 : | transfer8x8_copy = transfer8x8_copy_ia64; | ||
302 : | DEBUG("Using IA-64 assembler routines.\n"); | ||
303 : | } | ||
304 : | #endif | ||
305 : | |||
306 : | canard | 52 | #ifdef ARCH_PPC |
307 : | canard | 71 | #ifdef ARCH_PPC_ALTIVEC |
308 : | calc_cbp = calc_cbp_altivec; | ||
309 : | canard | 76 | fdct = fdct_altivec; |
310 : | idct = idct_altivec; | ||
311 : | canard | 115 | sadInit = sadInit_altivec; |
312 : | canard | 89 | sad16 = sad16_altivec; |
313 : | sad8 = sad8_altivec; | ||
314 : | dev16 = dev16_altivec; | ||
315 : | canard | 71 | #else |
316 : | canard | 52 | calc_cbp = calc_cbp_ppc; |
317 : | #endif | ||
318 : | canard | 71 | #endif |
319 : | edgomez | 195 | |
320 : | Isibaar | 3 | return XVID_ERR_OK; |
321 : | } | ||
322 : | |||
323 : | edgomez | 200 | /***************************************************************************** |
324 : | * XviD Native decoder entry point | ||
325 : | * | ||
326 : | * This function is just a wrapper to all the option cases. | ||
327 : | * | ||
328 : | * Returned values : XVID_ERR_FAIL when opt is invalid | ||
329 : | * else returns the wrapped function result | ||
330 : | * | ||
331 : | ****************************************************************************/ | ||
332 : | |||
333 : | edgomez | 195 | int |
334 : | xvid_decore(void *handle, | ||
335 : | int opt, | ||
336 : | void *param1, | ||
337 : | void *param2) | ||
338 : | Isibaar | 3 | { |
339 : | edgomez | 195 | switch (opt) { |
340 : | case XVID_DEC_DECODE: | ||
341 : | return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); | ||
342 : | Isibaar | 3 | |
343 : | edgomez | 195 | case XVID_DEC_CREATE: |
344 : | return decoder_create((XVID_DEC_PARAM *) param1); | ||
345 : | Isibaar | 3 | |
346 : | edgomez | 195 | case XVID_DEC_DESTROY: |
347 : | return decoder_destroy((DECODER *) handle); | ||
348 : | |||
349 : | Isibaar | 3 | default: |
350 : | edgomez | 195 | return XVID_ERR_FAIL; |
351 : | } | ||
352 : | Isibaar | 3 | } |
353 : | |||
354 : | |||
355 : | edgomez | 200 | /***************************************************************************** |
356 : | * XviD Native encoder entry point | ||
357 : | * | ||
358 : | * This function is just a wrapper to all the option cases. | ||
359 : | * | ||
360 : | * Returned values : XVID_ERR_FAIL when opt is invalid | ||
361 : | * else returns the wrapped function result | ||
362 : | * | ||
363 : | ****************************************************************************/ | ||
364 : | |||
365 : | edgomez | 195 | int |
366 : | xvid_encore(void *handle, | ||
367 : | int opt, | ||
368 : | void *param1, | ||
369 : | void *param2) | ||
370 : | Isibaar | 3 | { |
371 : | edgomez | 195 | switch (opt) { |
372 : | case XVID_ENC_ENCODE: | ||
373 : | suxen_drol | 232 | #ifdef BFRAMES |
374 : | if (((Encoder *) handle)->mbParam.max_bframes >= 0) | ||
375 : | return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, | ||
376 : | (XVID_ENC_STATS *) param2); | ||
377 : | else | ||
378 : | #endif | ||
379 : | edgomez | 195 | return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
380 : | (XVID_ENC_STATS *) param2); | ||
381 : | Isibaar | 3 | |
382 : | edgomez | 195 | case XVID_ENC_CREATE: |
383 : | return encoder_create((XVID_ENC_PARAM *) param1); | ||
384 : | Isibaar | 3 | |
385 : | edgomez | 195 | case XVID_ENC_DESTROY: |
386 : | return encoder_destroy((Encoder *) handle); | ||
387 : | |||
388 : | Isibaar | 3 | default: |
389 : | edgomez | 195 | return XVID_ERR_FAIL; |
390 : | } | ||
391 : | Isibaar | 3 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |