--- xvid.c 2003/10/01 23:23:01 1.45.2.15 +++ xvid.c 2003/06/11 14:10:55 1.47 @@ -3,8 +3,6 @@ * XVID MPEG-4 VIDEO CODEC * - Native API implementation - * - * Copyright(C) 2001-2003 Peter Ross - * * This program is free software ; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation ; either version 2 of the License, or @@ -19,7 +17,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid.c,v 1.45.2.15 2003/10/01 23:23:01 edgomez Exp $ + * $Id: xvid.c,v 1.47 2003/06/11 14:10:55 Isibaar Exp $ * ****************************************************************************/ @@ -46,11 +44,6 @@ #include "utils/emms.h" #include "utils/timer.h" #include "bitstream/mbcoding.h" -#include "image/qpel.h" - -#if defined(_DEBUG) -unsigned int xvid_debug = 0; /* xvid debug mask */ -#endif #if defined(ARCH_IS_IA32) @@ -151,7 +144,7 @@ * to the CPU features forced by the library client or autodetected (depending * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all * image colorspace transformation tables. - * + * * Returned value : XVID_ERR_OK * + API_VERSION in the input XVID_INIT_PARAM structure * + core build " " " " " @@ -159,15 +152,35 @@ ****************************************************************************/ -static -int xvid_gbl_init(xvid_gbl_init_t * init) +static +int xvid_init_init(XVID_INIT_PARAM * init_param) { - unsigned int cpu_flags; + 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)) { - if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */ - return XVID_ERR_VERSION; + cpu_flags = init_param->cpu_flags; + + } else { + + cpu_flags = detect_cpu_flags(); + } + + if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) + { + init_param->cpu_flags = cpu_flags; + return XVID_ERR_OK; + } + + init_param->cpu_flags = cpu_flags; - cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); /* Initialize the function pointers */ idct_int32_init(); @@ -183,11 +196,6 @@ /* Restore FPU context : emms_c is a nop functions */ emms = emms_c; - /* Qpel stuff */ - xvid_QP_Funcs = &xvid_QP_Funcs_C; - xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C; - xvid_Init_QP(); - /* Quantization functions */ quant_intra = quant_intra_c; dequant_intra = dequant_intra_c; @@ -271,7 +279,7 @@ yv12_to_rgba = yv12_to_rgba_c; yv12_to_yuyv = yv12_to_yuyv_c; yv12_to_uyvy = yv12_to_uyvy_c; - + yv12_to_rgb555i = yv12_to_rgb555i_c; yv12_to_rgb565i = yv12_to_rgb565i_c; yv12_to_bgri = yv12_to_bgri_c; @@ -289,12 +297,13 @@ sad8bi = sad8bi_c; dev16 = dev16_c; sad16v = sad16v_c; - + /* Halfpel8_Refine = Halfpel8_Refine_c; */ #if defined(ARCH_IS_IA32) - if ((cpu_flags & XVID_CPU_ASM)) { + if ((cpu_flags & XVID_CPU_ASM)) + { vfilter_31 = xvid_VFilter_31_x86; hfilter_31 = xvid_HFilter_31_x86; } @@ -313,10 +322,6 @@ fdct = fdct_mmx; idct = idct_mmx; - /* Qpel stuff */ - xvid_QP_Funcs = &xvid_QP_Funcs_mmx; - xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx; - /* Quantization related functions */ quant_intra = quant_intra_mmx; dequant_intra = dequant_intra_mmx; @@ -370,7 +375,7 @@ yv12_to_bgra = yv12_to_bgra_mmx; yv12_to_yuyv = yv12_to_yuyv_mmx; yv12_to_uyvy = yv12_to_uyvy_mmx; - + yv12_to_yuyvi = yv12_to_yuyvi_mmx; yv12_to_uyvyi = yv12_to_uyvyi_mmx; @@ -480,10 +485,12 @@ interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; } -#if defined(EXPERIMENTAL_SSE2_CODE) /* mark the whole SSE2 stuff as experimental. At least on - my P4, it crashes... */ + if ((cpu_flags & XVID_CPU_SSE2)) { +#if defined(EXPERIMENTAL_SSE2_CODE) /* many people reported crashes with SSE2 */ + /* better deactivate it completely and fix everything */ + /* in dev-api-4 */ calc_cbp = calc_cbp_sse2; /* Quantization */ @@ -495,14 +502,12 @@ /* ME; slower than xmm */ sad16 = sad16_sse2; dev16 = dev16_sse2; - /* Forward and Inverse DCT */ -#if 0 /* Both function are known to be unprecise, better keep them deactivated */ - idct = idct_sse2; - fdct = fdct_sse2; #endif + /* Forward and Inverse DCT */ + /* idct = idct_sse2; + /* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */ } #endif -#endif #if defined(ARCH_IS_IA64) if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ @@ -527,8 +532,9 @@ transfer_8to16sub2 = transfer_8to16sub2_ia64; transfer_16to8add = transfer_16to8add_ia64; transfer8x8_copy = transfer8x8_copy_ia64; + DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines."); } -#endif +#endif #if defined(ARCH_IS_PPC) if ((cpu_flags & XVID_CPU_ASM)) @@ -548,63 +554,34 @@ } #endif -#if defined(_DEBUG) - xvid_debug = init->debug; -#endif - - return 0; + return XVID_ERR_OK; } -static int -xvid_gbl_info(xvid_gbl_info_t * info) -{ - if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */ - return XVID_ERR_VERSION; - - info->actual_version = XVID_VERSION; - info->build = "dev-api-4"; - info->cpu_flags = detect_cpu_flags(); - -#if defined(_SMP) && defined(WIN32) - info->num_threads = pthread_num_processors_np();; -#else - info->num_threads = 0; -#endif - - return 0; -} - static int -xvid_gbl_convert(xvid_gbl_convert_t* convert) +xvid_init_convert(XVID_INIT_CONVERTINFO* convert) { - int width; - int height; - int width2; - int height2; +/* + const int flip1 = + (convert->input.colorspace & XVID_CSP_VFLIP) ^ + (convert->output.colorspace & XVID_CSP_VFLIP); +*/ + const int width = convert->width; + const int height = convert->height; + const int width2 = convert->width/2; + const int height2 = convert->height/2; IMAGE img; - if (XVID_VERSION_MAJOR(convert->version) != 1) /* v1.x.x */ - return XVID_ERR_VERSION; - -#if 0 - const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); -#endif - width = convert->width; - height = convert->height; - width2 = convert->width/2; - height2 = convert->height/2; - - switch (convert->input.csp & ~XVID_CSP_VFLIP) + switch (convert->input.colorspace & ~XVID_CSP_VFLIP) { case XVID_CSP_YV12 : - img.y = convert->input.plane[0]; - img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; - img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; + img.y = convert->input.y; + img.v = (uint8_t*)convert->input.y + width*height; + img.u = (uint8_t*)convert->input.y + width*height + width2*height2; image_output(&img, width, height, width, - (uint8_t**)convert->output.plane, convert->output.stride, - convert->output.csp, convert->interlacing); + convert->output.y, convert->output.y_stride, + convert->output.colorspace, convert->interlacing); break; default : @@ -613,7 +590,7 @@ emms(); - return 0; + return XVID_ERR_OK; } @@ -662,7 +639,7 @@ { int i, diff = 0; for (i = 0; i < size; i++) - diff += abs(blockA[i]-blockB[i]); + diff += ABS(blockA[i]-blockB[i]); return diff; } @@ -686,7 +663,7 @@ DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); int min, max; int count = 0; - + int tmp; int min_error = 0x10000*64; int max_error = 0; @@ -828,7 +805,7 @@ if (errors>0) printf("\t(%i errors out of %i)", errors, count); printf("\n"); - + return 0; } @@ -979,39 +956,25 @@ emms(); - return 0; + return XVID_ERR_OK; } -/***************************************************************************** - * XviD Global Entry point - * - * Well this function initialize all internal function pointers according - * to the CPU features forced by the library client or autodetected (depending - * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all - * image colorspace transformation tables. - * - ****************************************************************************/ - - int -xvid_global(void *handle, +xvid_init(void *handle, int opt, void *param1, void *param2) { switch(opt) { - case XVID_GBL_INIT : - return xvid_gbl_init((xvid_gbl_init_t*)param1); + case XVID_INIT_INIT : + return xvid_init_init((XVID_INIT_PARAM*)param1); - case XVID_GBL_INFO : - return xvid_gbl_info((xvid_gbl_info_t*)param1); + case XVID_INIT_CONVERT : + return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); - case XVID_GBL_CONVERT : - return xvid_gbl_convert((xvid_gbl_convert_t*)param1); - - case XVID_GBL_TEST : + case XVID_INIT_TEST : { ptr_t flags = (ptr_t)param1; return xvid_init_test((int)flags); @@ -1038,15 +1001,15 @@ void *param2) { switch (opt) { + case XVID_DEC_DECODE: + return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); + case XVID_DEC_CREATE: - return decoder_create((xvid_dec_create_t *) param1); + return decoder_create((XVID_DEC_PARAM *) param1); case XVID_DEC_DESTROY: return decoder_destroy((DECODER *) handle); - case XVID_DEC_DECODE: - return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); - default: return XVID_ERR_FAIL; } @@ -1072,15 +1035,20 @@ switch (opt) { case XVID_ENC_ENCODE: - return enc_encode((Encoder *) handle, - (xvid_enc_frame_t *) param1, - (xvid_enc_stats_t *) param2); + if (((Encoder *) handle)->mbParam.max_bframes >= 0) + return encoder_encode_bframes((Encoder *) handle, + (XVID_ENC_FRAME *) param1, + (XVID_ENC_STATS *) param2); + else + return encoder_encode((Encoder *) handle, + (XVID_ENC_FRAME *) param1, + (XVID_ENC_STATS *) param2); case XVID_ENC_CREATE: - return enc_create((xvid_enc_create_t *) param1); + return encoder_create((XVID_ENC_PARAM *) param1); case XVID_ENC_DESTROY: - return enc_destroy((Encoder *) handle); + return encoder_destroy((Encoder *) handle); default: return XVID_ERR_FAIL;