3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
6 |
|
* Copyright(C) 2001-2003 Peter Ross <pross@xvid.org> |
7 |
|
* |
8 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation ; either version 2 of the License, or |
* the Free Software Foundation ; either version 2 of the License, or |
19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: xvid.c,v 1.45 2003-02-21 00:00:57 edgomez Exp $ |
* $Id: xvid.c,v 1.45.2.8 2003-06-11 14:10:40 Isibaar Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
47 |
#include "utils/timer.h" |
#include "utils/timer.h" |
48 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
49 |
|
|
50 |
|
#if defined(_DEBUG) |
51 |
|
unsigned int xvid_debug = 0; /* xvid debug mask */ |
52 |
|
#endif |
53 |
|
|
54 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
55 |
|
|
56 |
#if defined(_MSC_VER) |
#if defined(_MSC_VER) |
159 |
|
|
160 |
|
|
161 |
static |
static |
162 |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
int xvid_gbl_init(xvid_gbl_init_t * init) |
|
{ |
|
|
int cpu_flags; |
|
|
|
|
|
/* Inform the client the API version */ |
|
|
init_param->api_version = API_VERSION; |
|
|
|
|
|
/* Inform the client the core build - unused because we're still alpha */ |
|
|
init_param->core_build = 1000; |
|
|
|
|
|
/* Do we have to force CPU features ? */ |
|
|
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
|
|
|
|
|
cpu_flags = init_param->cpu_flags; |
|
|
|
|
|
} else { |
|
|
|
|
|
cpu_flags = detect_cpu_flags(); |
|
|
} |
|
|
|
|
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
|
163 |
{ |
{ |
164 |
init_param->cpu_flags = cpu_flags; |
unsigned int cpu_flags; |
|
return XVID_ERR_OK; |
|
|
} |
|
165 |
|
|
166 |
init_param->cpu_flags = cpu_flags; |
if (XVID_MAJOR(init->version) != 1) /* v1.x.x */ |
167 |
|
return XVID_ERR_VERSION; |
168 |
|
|
169 |
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
170 |
|
|
171 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
172 |
idct_int32_init(); |
idct_int32_init(); |
288 |
|
|
289 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
290 |
|
|
291 |
if ((cpu_flags & XVID_CPU_ASM)) |
if ((cpu_flags & XVID_CPU_ASM)) { |
|
{ |
|
292 |
vfilter_31 = xvid_VFilter_31_x86; |
vfilter_31 = xvid_VFilter_31_x86; |
293 |
hfilter_31 = xvid_HFilter_31_x86; |
hfilter_31 = xvid_HFilter_31_x86; |
294 |
} |
} |
487 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
488 |
#endif |
#endif |
489 |
/* Forward and Inverse DCT */ |
/* Forward and Inverse DCT */ |
490 |
|
#if 0 /* Both function are known to be unprecise, better keep them deactivated */ |
491 |
idct = idct_sse2; |
idct = idct_sse2; |
492 |
fdct = fdct_sse2; |
fdct = fdct_sse2; |
493 |
|
#endif |
494 |
} |
} |
495 |
#endif |
#endif |
496 |
|
|
539 |
} |
} |
540 |
#endif |
#endif |
541 |
|
|
542 |
return XVID_ERR_OK; |
#if defined(_DEBUG) |
543 |
|
xvid_debug = init->debug; |
544 |
|
#endif |
545 |
|
|
546 |
|
return 0; |
547 |
} |
} |
548 |
|
|
549 |
|
|
550 |
|
static int |
551 |
|
xvid_gbl_info(xvid_gbl_info_t * info) |
552 |
|
{ |
553 |
|
if (XVID_MAJOR(info->version) != 1) /* v1.x.x */ |
554 |
|
return XVID_ERR_VERSION; |
555 |
|
|
556 |
|
info->actual_version = XVID_VERSION; |
557 |
|
info->build = "dev-api-4"; |
558 |
|
info->cpu_flags = detect_cpu_flags(); |
559 |
|
|
560 |
|
#if defined(_SMP) && defined(WIN32) |
561 |
|
info->num_threads = pthread_num_processors_np();; |
562 |
|
#else |
563 |
|
info->num_threads = 0; |
564 |
|
#endif |
565 |
|
|
566 |
|
return 0; |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
static int |
static int |
571 |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
572 |
{ |
{ |
573 |
/* |
int width; |
574 |
const int flip1 = |
int height; |
575 |
(convert->input.colorspace & XVID_CSP_VFLIP) ^ |
int width2; |
576 |
(convert->output.colorspace & XVID_CSP_VFLIP); |
int height2; |
|
*/ |
|
|
const int width = convert->width; |
|
|
const int height = convert->height; |
|
|
const int width2 = convert->width/2; |
|
|
const int height2 = convert->height/2; |
|
577 |
IMAGE img; |
IMAGE img; |
578 |
|
|
579 |
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
if (XVID_MAJOR(convert->version) != 1) /* v1.x.x */ |
580 |
|
return XVID_ERR_VERSION; |
581 |
|
|
582 |
|
#if 0 |
583 |
|
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
584 |
|
#endif |
585 |
|
width = convert->width; |
586 |
|
height = convert->height; |
587 |
|
width2 = convert->width/2; |
588 |
|
height2 = convert->height/2; |
589 |
|
|
590 |
|
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
591 |
{ |
{ |
592 |
case XVID_CSP_YV12 : |
case XVID_CSP_YV12 : |
593 |
img.y = convert->input.y; |
img.y = convert->input.plane[0]; |
594 |
img.v = (uint8_t*)convert->input.y + width*height; |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
595 |
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; |
596 |
image_output(&img, width, height, width, |
image_output(&img, width, height, width, |
597 |
convert->output.y, convert->output.y_stride, |
(uint8_t**)convert->output.plane, convert->output.stride, |
598 |
convert->output.colorspace, convert->interlacing); |
convert->output.csp, convert->interlacing); |
599 |
break; |
break; |
600 |
|
|
601 |
default : |
default : |
604 |
|
|
605 |
|
|
606 |
emms(); |
emms(); |
607 |
return XVID_ERR_OK; |
return 0; |
608 |
} |
} |
609 |
|
|
610 |
|
|
653 |
{ |
{ |
654 |
int i, diff = 0; |
int i, diff = 0; |
655 |
for (i = 0; i < size; i++) |
for (i = 0; i < size; i++) |
656 |
diff += ABS(blockA[i]-blockB[i]); |
diff += abs(blockA[i]-blockB[i]); |
657 |
return diff; |
return diff; |
658 |
} |
} |
659 |
|
|
970 |
|
|
971 |
emms(); |
emms(); |
972 |
|
|
973 |
return XVID_ERR_OK; |
return 0; |
974 |
} |
} |
975 |
|
|
976 |
|
|
977 |
|
/***************************************************************************** |
978 |
|
* XviD Global Entry point |
979 |
|
* |
980 |
|
* Well this function initialize all internal function pointers according |
981 |
|
* to the CPU features forced by the library client or autodetected (depending |
982 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
983 |
|
* image colorspace transformation tables. |
984 |
|
* |
985 |
|
****************************************************************************/ |
986 |
|
|
987 |
|
|
988 |
int |
int |
989 |
xvid_init(void *handle, |
xvid_global(void *handle, |
990 |
int opt, |
int opt, |
991 |
void *param1, |
void *param1, |
992 |
void *param2) |
void *param2) |
993 |
{ |
{ |
994 |
switch(opt) |
switch(opt) |
995 |
{ |
{ |
996 |
case XVID_INIT_INIT : |
case XVID_GBL_INIT : |
997 |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
998 |
|
|
999 |
case XVID_INIT_CONVERT : |
case XVID_GBL_INFO : |
1000 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
1001 |
|
|
1002 |
case XVID_INIT_TEST : |
case XVID_GBL_CONVERT : |
1003 |
|
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
1004 |
|
|
1005 |
|
case XVID_GBL_TEST : |
1006 |
{ |
{ |
1007 |
ptr_t flags = (ptr_t)param1; |
ptr_t flags = (ptr_t)param1; |
1008 |
return xvid_init_test((int)flags); |
return xvid_init_test((int)flags); |
1029 |
void *param2) |
void *param2) |
1030 |
{ |
{ |
1031 |
switch (opt) { |
switch (opt) { |
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
|
|
|
|
1032 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
1033 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((xvid_dec_create_t *) param1); |
1034 |
|
|
1035 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
1036 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1037 |
|
|
1038 |
|
case XVID_DEC_DECODE: |
1039 |
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
1040 |
|
|
1041 |
default: |
default: |
1042 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1043 |
} |
} |
1063 |
switch (opt) { |
switch (opt) { |
1064 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1065 |
|
|
1066 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
return enc_encode((Encoder *) handle, |
1067 |
return encoder_encode_bframes((Encoder *) handle, |
(xvid_enc_frame_t *) param1, |
1068 |
(XVID_ENC_FRAME *) param1, |
(xvid_enc_stats_t *) param2); |
|
(XVID_ENC_STATS *) param2); |
|
|
else |
|
|
return encoder_encode((Encoder *) handle, |
|
|
(XVID_ENC_FRAME *) param1, |
|
|
(XVID_ENC_STATS *) param2); |
|
1069 |
|
|
1070 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
1071 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return enc_create((xvid_enc_create_t *) param1); |
1072 |
|
|
1073 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
1074 |
return encoder_destroy((Encoder *) handle); |
return enc_destroy((Encoder *) handle); |
1075 |
|
|
1076 |
default: |
default: |
1077 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |