153 |
|
|
154 |
|
|
155 |
static |
static |
156 |
int xvid_gbl_init(xvid_gbl_init_t * init) |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
157 |
{ |
{ |
158 |
unsigned int cpu_flags; |
int cpu_flags; |
159 |
|
|
160 |
|
/* Inform the client the API version */ |
161 |
|
init_param->api_version = API_VERSION; |
162 |
|
|
163 |
|
/* Inform the client the core build - unused because we're still alpha */ |
164 |
|
init_param->core_build = 1000; |
165 |
|
|
166 |
|
/* Do we have to force CPU features ? */ |
167 |
|
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
168 |
|
|
169 |
|
cpu_flags = init_param->cpu_flags; |
170 |
|
|
171 |
if (XVID_MAJOR(init->version) != 1) /* v1.x.x */ |
} else { |
172 |
return XVID_ERR_VERSION; |
|
173 |
|
cpu_flags = detect_cpu_flags(); |
174 |
|
} |
175 |
|
|
176 |
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
177 |
|
{ |
178 |
|
init_param->cpu_flags = cpu_flags; |
179 |
|
return XVID_ERR_OK; |
180 |
|
} |
181 |
|
|
182 |
|
init_param->cpu_flags = cpu_flags; |
183 |
|
|
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
|
184 |
|
|
185 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
186 |
idct_int32_init(); |
idct_int32_init(); |
320 |
|
|
321 |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
322 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
323 |
idct = idct_mmx; |
idct = simple_idct_mmx; /* use simple idct by default */ |
324 |
|
|
325 |
/* Quantization related functions */ |
/* Quantization related functions */ |
326 |
quant_intra = quant_intra_mmx; |
quant_intra = quant_intra_mmx; |
406 |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
407 |
|
|
408 |
/* Inverse DCT */ |
/* Inverse DCT */ |
409 |
idct = idct_xmm; |
/* idct = idct_xmm; Don't use Walken idct anymore! */ |
410 |
|
|
411 |
/* Interpolation */ |
/* Interpolation */ |
412 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
452 |
if ((cpu_flags & XVID_CPU_3DNOWEXT)) { |
if ((cpu_flags & XVID_CPU_3DNOWEXT)) { |
453 |
|
|
454 |
/* Inverse DCT */ |
/* Inverse DCT */ |
455 |
idct = idct_3dne; |
/* idct = idct_3dne; Don't use Walken idct anymore */ |
456 |
|
|
457 |
/* Buffer transfer */ |
/* Buffer transfer */ |
458 |
transfer_8to16copy = transfer_8to16copy_3dne; |
transfer_8to16copy = transfer_8to16copy_3dne; |
502 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
503 |
#endif |
#endif |
504 |
/* Forward and Inverse DCT */ |
/* Forward and Inverse DCT */ |
505 |
idct = idct_sse2; |
/* idct = idct_sse2; |
506 |
fdct = fdct_sse2; |
/* fdct = fdct_sse2; Both are none to be unprecise - better deactivate for now */ |
507 |
} |
} |
508 |
#endif |
#endif |
509 |
|
|
552 |
} |
} |
553 |
#endif |
#endif |
554 |
|
|
555 |
return 0; |
return XVID_ERR_OK; |
556 |
} |
} |
557 |
|
|
558 |
|
|
|
static int |
|
|
xvid_gbl_info(xvid_gbl_info_t * info) |
|
|
{ |
|
|
if (XVID_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; |
|
|
} |
|
|
|
|
559 |
|
|
560 |
static int |
static int |
561 |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
562 |
{ |
{ |
563 |
int width; |
/* |
564 |
int height; |
const int flip1 = |
565 |
int width2; |
(convert->input.colorspace & XVID_CSP_VFLIP) ^ |
566 |
int height2; |
(convert->output.colorspace & XVID_CSP_VFLIP); |
567 |
|
*/ |
568 |
|
const int width = convert->width; |
569 |
|
const int height = convert->height; |
570 |
|
const int width2 = convert->width/2; |
571 |
|
const int height2 = convert->height/2; |
572 |
IMAGE img; |
IMAGE img; |
573 |
|
|
574 |
if (XVID_MAJOR(convert->version) != 1) /* v1.x.x */ |
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
|
return XVID_ERR_VERSION; |
|
|
|
|
|
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
|
|
width = convert->width; |
|
|
height = convert->height; |
|
|
width2 = convert->width/2; |
|
|
height2 = convert->height/2; |
|
|
|
|
|
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
|
575 |
{ |
{ |
576 |
case XVID_CSP_YV12 : |
case XVID_CSP_YV12 : |
577 |
img.y = convert->input.plane[0]; |
img.y = convert->input.y; |
578 |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
img.v = (uint8_t*)convert->input.y + width*height; |
579 |
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; |
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
580 |
image_output(&img, width, height, width, |
image_output(&img, width, height, width, |
581 |
(uint8_t**)convert->output.plane, convert->output.stride, |
convert->output.y, convert->output.y_stride, |
582 |
convert->output.csp, convert->interlacing); |
convert->output.colorspace, convert->interlacing); |
583 |
break; |
break; |
584 |
|
|
585 |
default : |
default : |
588 |
|
|
589 |
|
|
590 |
emms(); |
emms(); |
591 |
return 0; |
return XVID_ERR_OK; |
592 |
} |
} |
593 |
|
|
594 |
|
|
954 |
|
|
955 |
emms(); |
emms(); |
956 |
|
|
957 |
return 0; |
return XVID_ERR_OK; |
958 |
} |
} |
959 |
|
|
960 |
|
|
|
/***************************************************************************** |
|
|
* 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. |
|
|
* |
|
|
****************************************************************************/ |
|
|
|
|
|
|
|
961 |
int |
int |
962 |
xvid_global(void *handle, |
xvid_init(void *handle, |
963 |
int opt, |
int opt, |
964 |
void *param1, |
void *param1, |
965 |
void *param2) |
void *param2) |
966 |
{ |
{ |
967 |
switch(opt) |
switch(opt) |
968 |
{ |
{ |
969 |
case XVID_GBL_INIT : |
case XVID_INIT_INIT : |
970 |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
971 |
|
|
972 |
case XVID_GBL_INFO : |
case XVID_INIT_CONVERT : |
973 |
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
974 |
|
|
975 |
case XVID_GBL_CONVERT : |
case XVID_INIT_TEST : |
|
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
|
|
|
|
|
case XVID_GBL_TEST : |
|
976 |
{ |
{ |
977 |
ptr_t flags = (ptr_t)param1; |
ptr_t flags = (ptr_t)param1; |
978 |
return xvid_init_test((int)flags); |
return xvid_init_test((int)flags); |
999 |
void *param2) |
void *param2) |
1000 |
{ |
{ |
1001 |
switch (opt) { |
switch (opt) { |
1002 |
|
case XVID_DEC_DECODE: |
1003 |
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
1004 |
|
|
1005 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
1006 |
return decoder_create((xvid_dec_create_t *) param1); |
return decoder_create((XVID_DEC_PARAM *) param1); |
1007 |
|
|
1008 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
1009 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1010 |
|
|
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
|
|
|
|
1011 |
default: |
default: |
1012 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1013 |
} |
} |
1033 |
switch (opt) { |
switch (opt) { |
1034 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1035 |
|
|
1036 |
return enc_encode((Encoder *) handle, |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
1037 |
(xvid_enc_frame_t *) param1, |
return encoder_encode_bframes((Encoder *) handle, |
1038 |
(xvid_enc_stats_t *) param2); |
(XVID_ENC_FRAME *) param1, |
1039 |
|
(XVID_ENC_STATS *) param2); |
1040 |
|
else |
1041 |
|
return encoder_encode((Encoder *) handle, |
1042 |
|
(XVID_ENC_FRAME *) param1, |
1043 |
|
(XVID_ENC_STATS *) param2); |
1044 |
|
|
1045 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
1046 |
return enc_create((xvid_enc_create_t *) param1); |
return encoder_create((XVID_ENC_PARAM *) param1); |
1047 |
|
|
1048 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
1049 |
return enc_destroy((Encoder *) handle); |
return encoder_destroy((Encoder *) handle); |
1050 |
|
|
1051 |
default: |
default: |
1052 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |