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