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