49 |
|
|
50 |
#include <windows.h> |
#include <windows.h> |
51 |
#include <vfw.h> |
#include <vfw.h> |
52 |
|
#include <stdio.h> |
53 |
#include "vfwext.h" |
#include "vfwext.h" |
54 |
|
|
55 |
#include <xvid.h> |
#include <xvid.h> |
281 |
{ |
{ |
282 |
xvid_plg_data_t *data = (xvid_plg_data_t *) param1; |
xvid_plg_data_t *data = (xvid_plg_data_t *) param1; |
283 |
|
|
284 |
DPRINTF("[%5i] type=%c Q:%2i length:%6i", |
/* We don't use DPRINTF here because it's active only for _DEBUG |
285 |
|
* builds and that activates lot of other debug printfs. We only |
286 |
|
* want these all the time */ |
287 |
|
char buf[1024]; |
288 |
|
sprintf(buf, "[%6i] type=%c Q:%2i length:%6i", |
289 |
data->frame_num, |
data->frame_num, |
290 |
type2char(data->type), |
type2char(data->type), |
291 |
data->quant, |
data->quant, |
292 |
data->length); |
data->length); |
293 |
|
OutputDebugString(buf); |
294 |
|
|
295 |
return 0; |
return 0; |
296 |
} |
} |
297 |
} |
} |
299 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
300 |
} |
} |
301 |
|
|
302 |
|
#define XVID_DLL_NAME "xvidcore.dll" |
303 |
|
|
304 |
|
static int init_dll() |
305 |
|
{ |
306 |
|
if (m_hdll != NULL) return 0; |
307 |
|
|
308 |
|
DPRINTF("init_dll"); |
309 |
|
m_hdll = LoadLibrary(XVID_DLL_NAME); |
310 |
|
if (m_hdll == NULL) { |
311 |
|
DPRINTF("dll load failed"); |
312 |
|
MessageBox(0, XVID_DLL_NAME " not found","Error", 0); |
313 |
|
return XVID_ERR_FAIL; |
314 |
|
} |
315 |
|
|
316 |
|
xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); |
317 |
|
if (xvid_global_func == NULL) { |
318 |
|
MessageBox(0, "xvid_global() not found", "Error", 0); |
319 |
|
return XVID_ERR_FAIL; |
320 |
|
} |
321 |
|
|
322 |
|
xvid_encore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_encore"); |
323 |
|
if (xvid_encore_func == NULL) { |
324 |
|
MessageBox(0, "xvid_encore() not found", "Error", 0); |
325 |
|
return XVID_ERR_FAIL; |
326 |
|
} |
327 |
|
|
328 |
|
xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); |
329 |
|
if (xvid_decore_func == NULL) { |
330 |
|
MessageBox(0, "xvid_decore() not found", "Error", 0); |
331 |
|
return XVID_ERR_FAIL; |
332 |
|
} |
333 |
|
|
334 |
|
xvid_plugin_single_func = |
335 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_single")); |
336 |
|
xvid_plugin_2pass1_func = |
337 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_2pass1")); |
338 |
|
xvid_plugin_2pass2_func = |
339 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_2pass2")); |
340 |
|
xvid_plugin_lumimasking_func = |
341 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_lumimasking")); |
342 |
|
xvid_plugin_psnr_func = |
343 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_psnr")); |
344 |
|
|
345 |
|
return 0; |
346 |
|
} |
347 |
|
|
348 |
|
|
349 |
LRESULT compress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) |
LRESULT compress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) |
356 |
xvid_plugin_2pass2_t pass2; |
xvid_plugin_2pass2_t pass2; |
357 |
int i; |
int i; |
358 |
|
|
359 |
|
if (init_dll() != 0) return ICERR_ERROR; |
360 |
/* destroy previously created codec */ |
/* destroy previously created codec */ |
361 |
if(codec->ehandle) { |
if(codec->ehandle) { |
362 |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
xvid_encore_func(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
363 |
codec->ehandle = NULL; |
codec->ehandle = NULL; |
364 |
} |
} |
365 |
|
|
367 |
init.version = XVID_VERSION; |
init.version = XVID_VERSION; |
368 |
init.cpu_flags = codec->config.cpu; |
init.cpu_flags = codec->config.cpu; |
369 |
init.debug = codec->config.debug; |
init.debug = codec->config.debug; |
370 |
xvid_global(0, XVID_GBL_INIT, &init, NULL); |
xvid_global_func(0, XVID_GBL_INIT, &init, NULL); |
371 |
|
|
372 |
memset(&create, 0, sizeof(create)); |
memset(&create, 0, sizeof(create)); |
373 |
create.version = XVID_VERSION; |
create.version = XVID_VERSION; |
398 |
single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; |
single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; |
399 |
single.averaging_period = codec->config.rc_averaging_period; |
single.averaging_period = codec->config.rc_averaging_period; |
400 |
single.buffer = codec->config.rc_buffer; |
single.buffer = codec->config.rc_buffer; |
401 |
plugins[create.num_plugins].func = xvid_plugin_single; |
plugins[create.num_plugins].func = xvid_plugin_single_func; |
402 |
plugins[create.num_plugins].param = &single; |
plugins[create.num_plugins].param = &single; |
403 |
create.num_plugins++; |
create.num_plugins++; |
404 |
break; |
break; |
408 |
pass1.version = XVID_VERSION; |
pass1.version = XVID_VERSION; |
409 |
pass1.filename = codec->config.stats; |
pass1.filename = codec->config.stats; |
410 |
|
|
411 |
plugins[create.num_plugins].func = xvid_plugin_2pass1; |
plugins[create.num_plugins].func = xvid_plugin_2pass1_func; |
412 |
plugins[create.num_plugins].param = &pass1; |
plugins[create.num_plugins].param = &pass1; |
413 |
create.num_plugins++; |
create.num_plugins++; |
414 |
break; |
break; |
424 |
pass2.filename = codec->config.stats; |
pass2.filename = codec->config.stats; |
425 |
|
|
426 |
pass2.keyframe_boost = codec->config.keyframe_boost; /* keyframe boost percentage: [0..100...]; */ |
pass2.keyframe_boost = codec->config.keyframe_boost; /* keyframe boost percentage: [0..100...]; */ |
|
pass2.payback_method = codec->config.bitrate_payback_method; |
|
|
pass2.bitrate_payback_delay = codec->config.bitrate_payback_delay; |
|
427 |
pass2.curve_compression_high = codec->config.curve_compression_high; |
pass2.curve_compression_high = codec->config.curve_compression_high; |
428 |
pass2.curve_compression_low = codec->config.curve_compression_low; |
pass2.curve_compression_low = codec->config.curve_compression_low; |
429 |
|
pass2.overflow_control_strength = codec->config.overflow_control_strength; |
430 |
pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; |
pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; |
431 |
pass2.max_overflow_degradation = codec->config.twopass_max_overflow_degradation; |
pass2.max_overflow_degradation = codec->config.twopass_max_overflow_degradation; |
|
pass2.kftreshold = codec->config.kftreshold; |
|
432 |
pass2.kfreduction = codec->config.kfreduction; |
pass2.kfreduction = codec->config.kfreduction; |
433 |
pass2.min_key_interval = codec->config.min_key_interval; |
pass2.kfthreshold = codec->config.kfthreshold; |
434 |
pass2.container_frame_overhead = 24; /* AVI */ |
pass2.container_frame_overhead = 24; /* AVI */ |
435 |
|
|
436 |
plugins[create.num_plugins].func = xvid_plugin_2pass2; |
plugins[create.num_plugins].func = xvid_plugin_2pass2_func; |
437 |
plugins[create.num_plugins].param = &pass2; |
plugins[create.num_plugins].param = &pass2; |
438 |
create.num_plugins++; |
create.num_plugins++; |
439 |
break; |
break; |
446 |
} |
} |
447 |
|
|
448 |
if ((profiles[codec->config.profile].flags & PROFILE_ADAPTQUANT) && codec->config.lum_masking) { |
if ((profiles[codec->config.profile].flags & PROFILE_ADAPTQUANT) && codec->config.lum_masking) { |
449 |
plugins[create.num_plugins].func = xvid_plugin_lumimasking; |
plugins[create.num_plugins].func = xvid_plugin_lumimasking_func; |
450 |
plugins[create.num_plugins].param = NULL; |
plugins[create.num_plugins].param = NULL; |
451 |
create.num_plugins++; |
create.num_plugins++; |
452 |
} |
} |
488 |
|
|
489 |
create.num_threads = codec->config.num_threads; |
create.num_threads = codec->config.num_threads; |
490 |
|
|
491 |
switch(xvid_encore(0, XVID_ENC_CREATE, &create, NULL)) |
switch(xvid_encore_func(0, XVID_ENC_CREATE, &create, NULL)) |
492 |
{ |
{ |
493 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
494 |
return ICERR_ERROR; |
return ICERR_ERROR; |
518 |
|
|
519 |
LRESULT compress_end(CODEC * codec) |
LRESULT compress_end(CODEC * codec) |
520 |
{ |
{ |
521 |
|
if (m_hdll != NULL) { |
522 |
if (codec->ehandle != NULL) { |
if (codec->ehandle != NULL) { |
523 |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
xvid_encore_func(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
524 |
codec->ehandle = NULL; |
codec->ehandle = NULL; |
525 |
} |
} |
526 |
|
FreeLibrary(m_hdll); |
527 |
|
m_hdll = NULL; |
528 |
|
} |
529 |
|
|
530 |
if (codec->config.display_status) |
if (codec->config.display_status) |
531 |
status_destroy(&codec->status); |
status_destroy(&codec->status); |
539 |
int i; |
int i; |
540 |
|
|
541 |
for (i=0; i<config->num_zones && config->zones[i].frame <= framenum; i++) ; |
for (i=0; i<config->num_zones && config->zones[i].frame <= framenum; i++) ; |
|
i--; |
|
542 |
|
|
543 |
|
if (--i < 0) return; /* there are no zones, or we're before the first zone */ |
544 |
|
|
545 |
|
if (framenum == config->zones[i].frame) |
546 |
frame->type = config->zones[i].type; |
frame->type = config->zones[i].type; |
547 |
|
|
548 |
if (config->zones[i].greyscale) { |
if (config->zones[i].greyscale) { |
607 |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
608 |
frame.vol_flags |= XVID_VOL_INTERLACING; |
frame.vol_flags |= XVID_VOL_INTERLACING; |
609 |
|
|
610 |
|
if (codec->config.ar_mode == 0) { /* PAR */ |
611 |
|
if (codec->config.display_aspect_ratio != 5) { |
612 |
|
frame.par = codec->config.display_aspect_ratio + 1; |
613 |
|
} else { |
614 |
|
frame.par = XVID_PAR_EXT; |
615 |
|
frame.par_width = codec->config.par_x; |
616 |
|
frame.par_height= codec->config.par_y; |
617 |
|
} |
618 |
|
} else { /* AR */ |
619 |
|
/* custom pixel aspect ratio -> calculated from DAR */ |
620 |
|
frame.par = XVID_PAR_EXT; |
621 |
|
frame.par_width = (100 * inhdr->biHeight) / codec->config.ar_y; |
622 |
|
frame.par_height= (100 * inhdr->biWidth) / codec->config.ar_x; |
623 |
|
} |
624 |
|
|
625 |
/* vop stuff */ |
/* vop stuff */ |
626 |
|
|
627 |
frame.vop_flags |= XVID_VOP_HALFPEL; |
frame.vop_flags |= XVID_VOP_HALFPEL; |
642 |
|
|
643 |
if (codec->config.cartoon_mode) { |
if (codec->config.cartoon_mode) { |
644 |
frame.vop_flags |= XVID_VOP_CARTOON; |
frame.vop_flags |= XVID_VOP_CARTOON; |
|
#if 0 /* Seems to cause crashes with P4 cpus */ |
|
645 |
frame.motion |= XVID_ME_DETECT_STATIC_MOTION; |
frame.motion |= XVID_ME_DETECT_STATIC_MOTION; |
|
#endif |
|
646 |
} |
} |
647 |
|
|
648 |
|
if (codec->config.turbo) |
649 |
|
frame.motion |= XVID_ME_FASTREFINE16 | XVID_ME_FASTREFINE8 | |
650 |
|
XVID_ME_SKIP_DELTASEARCH | XVID_ME_FAST_MODEINTERPOLATE | |
651 |
|
XVID_ME_BFRAME_EARLYSTOP; |
652 |
|
|
653 |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
654 |
|
|
655 |
switch (codec->config.vhq_mode) |
switch (codec->config.vhq_mode) |
709 |
|
|
710 |
// force keyframe spacing in 2-pass 1st pass |
// force keyframe spacing in 2-pass 1st pass |
711 |
if (codec->config.motion_search == 0) |
if (codec->config.motion_search == 0) |
|
{ |
|
712 |
frame.type = XVID_TYPE_IVOP; |
frame.type = XVID_TYPE_IVOP; |
|
} |
|
|
else if (codec->keyspacing < codec->config.min_key_interval && codec->framenum) |
|
|
{ |
|
|
DPRINTF("current frame forced to p-frame"); |
|
|
frame.type = XVID_TYPE_PVOP; |
|
|
} |
|
713 |
|
|
714 |
/* frame-based stuff */ |
/* frame-based stuff */ |
715 |
apply_zone_modifiers(&frame, &codec->config, codec->framenum); |
apply_zone_modifiers(&frame, &codec->config, codec->framenum); |
719 |
memset(&stats, 0, sizeof(stats)); |
memset(&stats, 0, sizeof(stats)); |
720 |
stats.version = XVID_VERSION; |
stats.version = XVID_VERSION; |
721 |
|
|
722 |
length = xvid_encore(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats); |
length = xvid_encore_func(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats); |
723 |
switch (length) |
switch (length) |
724 |
{ |
{ |
725 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
854 |
xvid_gbl_init_t init; |
xvid_gbl_init_t init; |
855 |
xvid_dec_create_t create; |
xvid_dec_create_t create; |
856 |
|
|
857 |
|
if (init_dll() != 0) return ICERR_ERROR; |
858 |
|
|
859 |
memset(&init, 0, sizeof(init)); |
memset(&init, 0, sizeof(init)); |
860 |
init.version = XVID_VERSION; |
init.version = XVID_VERSION; |
861 |
init.cpu_flags = codec->config.cpu; |
init.cpu_flags = codec->config.cpu; |
862 |
xvid_global(0, XVID_GBL_INIT, &init, NULL); |
xvid_global_func(0, XVID_GBL_INIT, &init, NULL); |
863 |
|
|
864 |
memset(&create, 0, sizeof(create)); |
memset(&create, 0, sizeof(create)); |
865 |
create.version = XVID_VERSION; |
create.version = XVID_VERSION; |
866 |
create.width = lpbiInput->bmiHeader.biWidth; |
create.width = lpbiInput->bmiHeader.biWidth; |
867 |
create.height = lpbiInput->bmiHeader.biHeight; |
create.height = lpbiInput->bmiHeader.biHeight; |
868 |
|
|
869 |
switch(xvid_decore(0, XVID_DEC_CREATE, &create, NULL)) |
switch(xvid_decore_func(0, XVID_DEC_CREATE, &create, NULL)) |
870 |
{ |
{ |
871 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
872 |
return ICERR_ERROR; |
return ICERR_ERROR; |
889 |
|
|
890 |
LRESULT decompress_end(CODEC * codec) |
LRESULT decompress_end(CODEC * codec) |
891 |
{ |
{ |
892 |
if (codec->dhandle != NULL) |
if (m_hdll != NULL) { |
893 |
{ |
if (codec->dhandle != NULL) { |
894 |
xvid_decore(codec->dhandle, XVID_DEC_DESTROY, NULL, NULL); |
xvid_decore_func(codec->dhandle, XVID_DEC_DESTROY, NULL, NULL); |
895 |
codec->dhandle = NULL; |
codec->dhandle = NULL; |
896 |
} |
} |
897 |
|
FreeLibrary(m_hdll); |
898 |
|
m_hdll = NULL; |
899 |
|
} |
900 |
|
|
901 |
return ICERR_OK; |
return ICERR_OK; |
902 |
} |
} |
903 |
|
|
943 |
convert.interlacing = 0; |
convert.interlacing = 0; |
944 |
if (convert.input.csp == XVID_CSP_NULL || |
if (convert.input.csp == XVID_CSP_NULL || |
945 |
convert.output.csp == XVID_CSP_NULL || |
convert.output.csp == XVID_CSP_NULL || |
946 |
xvid_global(0, XVID_GBL_CONVERT, &convert, NULL) < 0) |
xvid_global_func(0, XVID_GBL_CONVERT, &convert, NULL) < 0) |
947 |
{ |
{ |
948 |
return ICERR_BADFORMAT; |
return ICERR_BADFORMAT; |
949 |
} |
} |
973 |
frame.output.csp = XVID_CSP_NULL; |
frame.output.csp = XVID_CSP_NULL; |
974 |
} |
} |
975 |
|
|
976 |
switch (xvid_decore(codec->dhandle, XVID_DEC_DECODE, &frame, NULL)) |
switch (xvid_decore_func(codec->dhandle, XVID_DEC_DECODE, &frame, NULL)) |
977 |
{ |
{ |
978 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
979 |
return ICERR_ERROR; |
return ICERR_ERROR; |