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> |
57 |
#include "codec.h" |
#include "codec.h" |
58 |
#include "status.h" |
#include "status.h" |
59 |
|
|
60 |
|
HINSTANCE m_hdll; |
61 |
|
int (*xvid_global_func)(void *handle, int opt, void *param1, void *param2); |
62 |
|
int (*xvid_encore_func)(void *handle, int opt, void *param1, void *param2); |
63 |
|
int (*xvid_decore_func)(void *handle, int opt, void *param1, void *param2); |
64 |
|
|
65 |
|
xvid_plugin_func *xvid_plugin_single_func, |
66 |
|
*xvid_plugin_2pass1_func, |
67 |
|
*xvid_plugin_2pass2_func, |
68 |
|
*xvid_plugin_lumimasking_func, |
69 |
|
*xvid_plugin_psnr_func; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
static const int pmvfast_presets[7] = { |
static const int pmvfast_presets[7] = { |
74 |
0, 0, 0, 0, |
0, 0, 0, 0, |
84 |
or XVID_CSP_NULL if failure |
or XVID_CSP_NULL if failure |
85 |
*/ |
*/ |
86 |
|
|
87 |
int get_colorspace(BITMAPINFOHEADER * hdr) |
static int get_colorspace(BITMAPINFOHEADER * hdr) |
88 |
{ |
{ |
89 |
/* rgb only: negative height specifies top down image */ |
/* rgb only: negative height specifies top down image */ |
90 |
int rgb_flip = (hdr->biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
int rgb_flip = (hdr->biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
266 |
} |
} |
267 |
|
|
268 |
|
|
269 |
const char type2char(int type) |
static char type2char(int type) |
270 |
{ |
{ |
271 |
if (type==XVID_TYPE_IVOP) |
if (type==XVID_TYPE_IVOP) |
272 |
return 'I'; |
return 'I'; |
277 |
return 'S'; |
return 'S'; |
278 |
} |
} |
279 |
|
|
280 |
int vfw_debug(void *handle, |
static int vfw_debug(void *handle, |
281 |
int opt, |
int opt, |
282 |
void *param1, |
void *param1, |
283 |
void *param2) |
void *param2) |
284 |
{ |
{ |
285 |
switch (opt) { |
switch (opt) { |
|
case XVID_PLG_INFO: |
|
286 |
case XVID_PLG_CREATE: |
case XVID_PLG_CREATE: |
287 |
|
*((void**)param2) = NULL; |
288 |
|
case XVID_PLG_INFO: |
289 |
case XVID_PLG_DESTROY: |
case XVID_PLG_DESTROY: |
290 |
case XVID_PLG_BEFORE: |
case XVID_PLG_BEFORE: |
291 |
return 0; |
return 0; |
294 |
{ |
{ |
295 |
xvid_plg_data_t *data = (xvid_plg_data_t *) param1; |
xvid_plg_data_t *data = (xvid_plg_data_t *) param1; |
296 |
|
|
297 |
DPRINTF("[%5i] type=%c Q:%2i length:%6i", |
/* We don't use DPRINTF here because it's active only for _DEBUG |
298 |
|
* builds and that activates lot of other debug printfs. We only |
299 |
|
* want these all the time */ |
300 |
|
char buf[1024]; |
301 |
|
sprintf(buf, "[%6i] type=%c Q:%2i length:%6i", |
302 |
data->frame_num, |
data->frame_num, |
303 |
type2char(data->type), |
type2char(data->type), |
304 |
data->quant, |
data->quant, |
305 |
data->length); |
data->length); |
306 |
|
OutputDebugString(buf); |
307 |
|
|
308 |
return 0; |
return 0; |
309 |
} |
} |
310 |
} |
} |
312 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
313 |
} |
} |
314 |
|
|
315 |
|
#define XVID_DLL_NAME "xvidcore.dll" |
316 |
|
|
317 |
|
static int init_dll() |
318 |
|
{ |
319 |
|
if (m_hdll != NULL) return 0; |
320 |
|
|
321 |
|
DPRINTF("init_dll"); |
322 |
|
m_hdll = LoadLibrary(XVID_DLL_NAME); |
323 |
|
if (m_hdll == NULL) { |
324 |
|
DPRINTF("dll load failed"); |
325 |
|
MessageBox(0, XVID_DLL_NAME " not found!","Error!", MB_ICONEXCLAMATION|MB_OK); |
326 |
|
return XVID_ERR_FAIL; |
327 |
|
} |
328 |
|
|
329 |
|
xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); |
330 |
|
if (xvid_global_func == NULL) { |
331 |
|
MessageBox(0, "xvid_global() not found", "Error", 0); |
332 |
|
return XVID_ERR_FAIL; |
333 |
|
} |
334 |
|
|
335 |
|
xvid_encore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_encore"); |
336 |
|
if (xvid_encore_func == NULL) { |
337 |
|
MessageBox(0, "xvid_encore() not found", "Error", 0); |
338 |
|
return XVID_ERR_FAIL; |
339 |
|
} |
340 |
|
|
341 |
|
xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); |
342 |
|
if (xvid_decore_func == NULL) { |
343 |
|
MessageBox(0, "xvid_decore() not found", "Error", 0); |
344 |
|
return XVID_ERR_FAIL; |
345 |
|
} |
346 |
|
|
347 |
|
xvid_plugin_single_func = |
348 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_single")); |
349 |
|
xvid_plugin_2pass1_func = |
350 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_2pass1")); |
351 |
|
xvid_plugin_2pass2_func = |
352 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_2pass2")); |
353 |
|
xvid_plugin_lumimasking_func = |
354 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_lumimasking")); |
355 |
|
xvid_plugin_psnr_func = |
356 |
|
(int (__cdecl *)(void *, int, void *, void *))(GetProcAddress(m_hdll, "xvid_plugin_psnr")); |
357 |
|
|
358 |
|
return 0; |
359 |
|
} |
360 |
|
|
361 |
|
/* constant-quant zones for fixed quant encoding */ |
362 |
|
static void |
363 |
|
prepare_cquant_zones(CONFIG * config) { |
364 |
|
|
365 |
|
int i = 0; |
366 |
|
if (config->num_zones == 0 || config->zones[0].frame != 0) { |
367 |
|
/* first zone does not start at frame 0 or doesn't exist */ |
368 |
|
|
369 |
|
if (config->num_zones >= MAX_ZONES) config->num_zones--; /* we scrifice last zone */ |
370 |
|
|
371 |
|
config->zones[config->num_zones].frame = 0; |
372 |
|
config->zones[config->num_zones].mode = RC_ZONE_QUANT; |
373 |
|
config->zones[config->num_zones].weight = 100; |
374 |
|
config->zones[config->num_zones].quant = config->desired_quant; |
375 |
|
config->zones[config->num_zones].type = XVID_TYPE_AUTO; |
376 |
|
config->zones[config->num_zones].greyscale = 0; |
377 |
|
config->zones[config->num_zones].chroma_opt = 0; |
378 |
|
config->zones[config->num_zones].bvop_threshold = 0; |
379 |
|
config->num_zones++; |
380 |
|
|
381 |
|
sort_zones(config->zones, config->num_zones, &i); |
382 |
|
} |
383 |
|
|
384 |
|
/* step 2: let's change all weight zones into quant zones */ |
385 |
|
|
386 |
|
for(i = 0; i < config->num_zones; i++) |
387 |
|
if (config->zones[i].mode == RC_ZONE_WEIGHT) { |
388 |
|
config->zones[i].mode = RC_ZONE_QUANT; |
389 |
|
config->zones[i].quant = (100*config->desired_quant) / config->zones[i].weight; |
390 |
|
} |
391 |
|
} |
392 |
|
|
393 |
|
/* full first pass zones */ |
394 |
|
static void |
395 |
|
prepare_full1pass_zones(CONFIG * config) { |
396 |
|
|
397 |
|
int i = 0; |
398 |
|
if (config->num_zones == 0 || config->zones[0].frame != 0) { |
399 |
|
/* first zone does not start at frame 0 or doesn't exist */ |
400 |
|
|
401 |
|
if (config->num_zones >= MAX_ZONES) config->num_zones--; /* we scrifice last zone */ |
402 |
|
|
403 |
|
config->zones[config->num_zones].frame = 0; |
404 |
|
config->zones[config->num_zones].mode = RC_ZONE_QUANT; |
405 |
|
config->zones[config->num_zones].weight = 100; |
406 |
|
config->zones[config->num_zones].quant = 200; |
407 |
|
config->zones[config->num_zones].type = XVID_TYPE_AUTO; |
408 |
|
config->zones[config->num_zones].greyscale = 0; |
409 |
|
config->zones[config->num_zones].chroma_opt = 0; |
410 |
|
config->zones[config->num_zones].bvop_threshold = 0; |
411 |
|
config->num_zones++; |
412 |
|
|
413 |
|
sort_zones(config->zones, config->num_zones, &i); |
414 |
|
} |
415 |
|
|
416 |
|
/* step 2: let's change all weight zones into quant zones */ |
417 |
|
|
418 |
|
for(i = 0; i < config->num_zones; i++) |
419 |
|
if (config->zones[i].mode == RC_ZONE_WEIGHT) { |
420 |
|
config->zones[i].mode = RC_ZONE_QUANT; |
421 |
|
config->zones[i].quant = 200; |
422 |
|
} |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
LRESULT compress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) |
LRESULT compress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) |
432 |
xvid_plugin_2pass1_t pass1; |
xvid_plugin_2pass1_t pass1; |
433 |
xvid_plugin_2pass2_t pass2; |
xvid_plugin_2pass2_t pass2; |
434 |
int i; |
int i; |
435 |
|
HANDLE hFile; |
436 |
|
|
437 |
|
CONFIG tmpCfg; /* if we want to alter config to suit our needs, it shouldn't be visible to user later */ |
438 |
|
memcpy(&tmpCfg, &codec->config, sizeof(CONFIG)); |
439 |
|
|
440 |
|
if (init_dll() != 0) return ICERR_ERROR; |
441 |
/* destroy previously created codec */ |
/* destroy previously created codec */ |
442 |
if(codec->ehandle) { |
if(codec->ehandle) { |
443 |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
xvid_encore_func(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
444 |
codec->ehandle = NULL; |
codec->ehandle = NULL; |
445 |
} |
} |
446 |
|
|
448 |
init.version = XVID_VERSION; |
init.version = XVID_VERSION; |
449 |
init.cpu_flags = codec->config.cpu; |
init.cpu_flags = codec->config.cpu; |
450 |
init.debug = codec->config.debug; |
init.debug = codec->config.debug; |
451 |
xvid_global(0, XVID_GBL_INIT, &init, NULL); |
xvid_global_func(0, XVID_GBL_INIT, &init, NULL); |
452 |
|
|
453 |
memset(&create, 0, sizeof(create)); |
memset(&create, 0, sizeof(create)); |
454 |
create.version = XVID_VERSION; |
create.version = XVID_VERSION; |
455 |
|
|
|
/* zones */ |
|
|
create.zones = malloc(sizeof(xvid_enc_zone_t) * codec->config.num_zones); |
|
|
create.num_zones = codec->config.num_zones; |
|
|
for (i=0; i < create.num_zones; i++) { |
|
|
create.zones[i].frame = codec->config.zones[i].frame; |
|
|
if (codec->config.zones[i].mode == RC_ZONE_QUANT) { |
|
|
create.zones[i].mode = XVID_ZONE_QUANT; |
|
|
create.zones[i].increment = codec->config.zones[i].quant; |
|
|
}else{ |
|
|
create.zones[i].mode = XVID_ZONE_WEIGHT; |
|
|
create.zones[i].increment = codec->config.zones[i].weight; |
|
|
} |
|
|
create.zones[i].base = 100; |
|
|
} |
|
|
|
|
456 |
/* plugins */ |
/* plugins */ |
457 |
create.plugins = plugins; |
create.plugins = plugins; |
458 |
switch (codec->config.mode) |
switch (codec->config.mode) |
464 |
single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; |
single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; |
465 |
single.averaging_period = codec->config.rc_averaging_period; |
single.averaging_period = codec->config.rc_averaging_period; |
466 |
single.buffer = codec->config.rc_buffer; |
single.buffer = codec->config.rc_buffer; |
467 |
plugins[create.num_plugins].func = xvid_plugin_single; |
plugins[create.num_plugins].func = xvid_plugin_single_func; |
468 |
plugins[create.num_plugins].param = &single; |
plugins[create.num_plugins].param = &single; |
469 |
create.num_plugins++; |
create.num_plugins++; |
470 |
|
if (!codec->config.use_2pass_bitrate) /* constant-quant mode */ |
471 |
|
prepare_cquant_zones(&tmpCfg); |
472 |
break; |
break; |
473 |
|
|
474 |
case RC_MODE_2PASS1 : |
case RC_MODE_2PASS1 : |
475 |
memset(&pass1, 0, sizeof(pass1)); |
memset(&pass1, 0, sizeof(pass1)); |
476 |
pass1.version = XVID_VERSION; |
pass1.version = XVID_VERSION; |
477 |
pass1.filename = codec->config.stats; |
pass1.filename = codec->config.stats; |
478 |
|
if (codec->config.full1pass) |
479 |
plugins[create.num_plugins].func = xvid_plugin_2pass1; |
prepare_full1pass_zones(&tmpCfg); |
480 |
|
plugins[create.num_plugins].func = xvid_plugin_2pass1_func; |
481 |
plugins[create.num_plugins].param = &pass1; |
plugins[create.num_plugins].param = &pass1; |
482 |
create.num_plugins++; |
create.num_plugins++; |
483 |
break; |
break; |
492 |
} |
} |
493 |
pass2.filename = codec->config.stats; |
pass2.filename = codec->config.stats; |
494 |
|
|
495 |
|
hFile = CreateFile(pass2.filename, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); |
496 |
|
if (hFile == INVALID_HANDLE_VALUE) |
497 |
|
{ |
498 |
|
MessageBox(0, "Statsfile not found!","Error!", MB_ICONEXCLAMATION|MB_OK); |
499 |
|
return XVID_ERR_FAIL; |
500 |
|
} else |
501 |
|
{ |
502 |
|
CloseHandle(hFile); |
503 |
|
} |
504 |
|
|
505 |
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; |
|
506 |
pass2.curve_compression_high = codec->config.curve_compression_high; |
pass2.curve_compression_high = codec->config.curve_compression_high; |
507 |
pass2.curve_compression_low = codec->config.curve_compression_low; |
pass2.curve_compression_low = codec->config.curve_compression_low; |
508 |
|
pass2.overflow_control_strength = codec->config.overflow_control_strength; |
509 |
pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; |
pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; |
510 |
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; |
|
511 |
pass2.kfreduction = codec->config.kfreduction; |
pass2.kfreduction = codec->config.kfreduction; |
512 |
pass2.min_key_interval = codec->config.min_key_interval; |
pass2.kfthreshold = codec->config.kfthreshold; |
513 |
pass2.container_frame_overhead = 24; /* AVI */ |
pass2.container_frame_overhead = 24; /* AVI */ |
514 |
|
|
515 |
plugins[create.num_plugins].func = xvid_plugin_2pass2; |
plugins[create.num_plugins].func = xvid_plugin_2pass2_func; |
516 |
plugins[create.num_plugins].param = &pass2; |
plugins[create.num_plugins].param = &pass2; |
517 |
create.num_plugins++; |
create.num_plugins++; |
518 |
break; |
break; |
524 |
break; |
break; |
525 |
} |
} |
526 |
|
|
527 |
|
/* zones - copy from tmpCfg in case we automatically altered them above */ |
528 |
|
create.zones = malloc(sizeof(xvid_enc_zone_t) * tmpCfg.num_zones); |
529 |
|
create.num_zones = tmpCfg.num_zones; |
530 |
|
for (i=0; i < create.num_zones; i++) { |
531 |
|
create.zones[i].frame = tmpCfg.zones[i].frame; |
532 |
|
if (tmpCfg.zones[i].mode == RC_ZONE_QUANT) { |
533 |
|
create.zones[i].mode = XVID_ZONE_QUANT; |
534 |
|
create.zones[i].increment = tmpCfg.zones[i].quant; |
535 |
|
}else{ |
536 |
|
create.zones[i].mode = XVID_ZONE_WEIGHT; |
537 |
|
create.zones[i].increment = tmpCfg.zones[i].weight; |
538 |
|
} |
539 |
|
create.zones[i].base = 100; |
540 |
|
} |
541 |
|
|
542 |
|
/* lumimasking plugin */ |
543 |
if ((profiles[codec->config.profile].flags & PROFILE_ADAPTQUANT) && codec->config.lum_masking) { |
if ((profiles[codec->config.profile].flags & PROFILE_ADAPTQUANT) && codec->config.lum_masking) { |
544 |
plugins[create.num_plugins].func = xvid_plugin_lumimasking; |
plugins[create.num_plugins].func = xvid_plugin_lumimasking_func; |
545 |
plugins[create.num_plugins].param = NULL; |
plugins[create.num_plugins].param = NULL; |
546 |
create.num_plugins++; |
create.num_plugins++; |
547 |
} |
} |
583 |
|
|
584 |
create.num_threads = codec->config.num_threads; |
create.num_threads = codec->config.num_threads; |
585 |
|
|
586 |
switch(xvid_encore(0, XVID_ENC_CREATE, &create, NULL)) |
switch(xvid_encore_func(0, XVID_ENC_CREATE, &create, NULL)) |
587 |
{ |
{ |
588 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
589 |
return ICERR_ERROR; |
return ICERR_ERROR; |
613 |
|
|
614 |
LRESULT compress_end(CODEC * codec) |
LRESULT compress_end(CODEC * codec) |
615 |
{ |
{ |
616 |
|
if (m_hdll != NULL) { |
617 |
if (codec->ehandle != NULL) { |
if (codec->ehandle != NULL) { |
618 |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
xvid_encore_func(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
619 |
codec->ehandle = NULL; |
codec->ehandle = NULL; |
620 |
} |
} |
621 |
|
FreeLibrary(m_hdll); |
622 |
|
m_hdll = NULL; |
623 |
|
} |
624 |
|
|
625 |
if (codec->config.display_status) |
if (codec->config.display_status) |
626 |
status_destroy(&codec->status); |
status_destroy(&codec->status); |
634 |
int i; |
int i; |
635 |
|
|
636 |
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--; |
|
637 |
|
|
638 |
|
if (--i < 0) return; /* there are no zones, or we're before the first zone */ |
639 |
|
|
640 |
|
if (framenum == config->zones[i].frame) |
641 |
frame->type = config->zones[i].type; |
frame->type = config->zones[i].type; |
642 |
|
|
643 |
if (config->zones[i].greyscale) { |
if (config->zones[i].greyscale) { |
702 |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
703 |
frame.vol_flags |= XVID_VOL_INTERLACING; |
frame.vol_flags |= XVID_VOL_INTERLACING; |
704 |
|
|
705 |
|
if (codec->config.ar_mode == 0) { /* PAR */ |
706 |
|
if (codec->config.display_aspect_ratio != 5) { |
707 |
|
frame.par = codec->config.display_aspect_ratio + 1; |
708 |
|
} else { |
709 |
|
frame.par = XVID_PAR_EXT; |
710 |
|
frame.par_width = codec->config.par_x; |
711 |
|
frame.par_height= codec->config.par_y; |
712 |
|
} |
713 |
|
} else { /* AR */ |
714 |
|
/* custom pixel aspect ratio -> calculated from DAR */ |
715 |
|
frame.par = XVID_PAR_EXT; |
716 |
|
frame.par_width = (100 * inhdr->biHeight) / codec->config.ar_y; |
717 |
|
frame.par_height= (100 * inhdr->biWidth) / codec->config.ar_x; |
718 |
|
} |
719 |
|
|
720 |
/* vop stuff */ |
/* vop stuff */ |
721 |
|
|
722 |
frame.vop_flags |= XVID_VOP_HALFPEL; |
frame.vop_flags |= XVID_VOP_HALFPEL; |
737 |
|
|
738 |
if (codec->config.cartoon_mode) { |
if (codec->config.cartoon_mode) { |
739 |
frame.vop_flags |= XVID_VOP_CARTOON; |
frame.vop_flags |= XVID_VOP_CARTOON; |
|
#if 0 /* Seems to cause crashes with P4 cpus */ |
|
740 |
frame.motion |= XVID_ME_DETECT_STATIC_MOTION; |
frame.motion |= XVID_ME_DETECT_STATIC_MOTION; |
|
#endif |
|
741 |
} |
} |
742 |
|
|
743 |
|
if (codec->config.turbo) |
744 |
|
frame.motion |= XVID_ME_FASTREFINE16 | XVID_ME_FASTREFINE8 | |
745 |
|
XVID_ME_SKIP_DELTASEARCH | XVID_ME_FAST_MODEINTERPOLATE | |
746 |
|
XVID_ME_BFRAME_EARLYSTOP; |
747 |
|
|
748 |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
749 |
|
|
750 |
switch (codec->config.vhq_mode) |
switch (codec->config.vhq_mode) |
788 |
if ((frame.input.csp = get_colorspace(inhdr)) == XVID_CSP_NULL) |
if ((frame.input.csp = get_colorspace(inhdr)) == XVID_CSP_NULL) |
789 |
return ICERR_BADFORMAT; |
return ICERR_BADFORMAT; |
790 |
|
|
791 |
if (frame.input.csp == XVID_CSP_I420 || frame.input.csp == XVID_CSP_YV12) |
if (frame.input.csp == XVID_CSP_I420 || frame.input.csp == XVID_CSP_YV12) { |
792 |
frame.input.stride[0] = (frame.input.stride[0]*2)/3; |
frame.input.stride[0] = (4 * icc->lpbiInput->biWidth + 3) / 4; |
793 |
|
frame.input.stride[1] = frame.input.stride[2] = frame.input.stride[0] / 2 ; |
794 |
|
} |
795 |
|
|
796 |
frame.bitstream = icc->lpOutput; |
frame.bitstream = icc->lpOutput; |
797 |
frame.length = icc->lpbiOutput->biSizeImage; |
frame.length = icc->lpbiOutput->biSizeImage; |
806 |
|
|
807 |
// force keyframe spacing in 2-pass 1st pass |
// force keyframe spacing in 2-pass 1st pass |
808 |
if (codec->config.motion_search == 0) |
if (codec->config.motion_search == 0) |
|
{ |
|
809 |
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; |
|
|
} |
|
810 |
|
|
811 |
/* frame-based stuff */ |
/* frame-based stuff */ |
812 |
apply_zone_modifiers(&frame, &codec->config, codec->framenum); |
apply_zone_modifiers(&frame, &codec->config, codec->framenum); |
816 |
memset(&stats, 0, sizeof(stats)); |
memset(&stats, 0, sizeof(stats)); |
817 |
stats.version = XVID_VERSION; |
stats.version = XVID_VERSION; |
818 |
|
|
819 |
length = xvid_encore(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats); |
length = xvid_encore_func(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats); |
820 |
switch (length) |
switch (length) |
821 |
{ |
{ |
822 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
945 |
return ICERR_OK; |
return ICERR_OK; |
946 |
} |
} |
947 |
|
|
948 |
|
#define REG_GET_N(X, Y, Z) \ |
949 |
|
{ \ |
950 |
|
DWORD size = sizeof(int); \ |
951 |
|
if (RegQueryValueEx(hKey, X, 0, 0, (LPBYTE)&Y, &size) != ERROR_SUCCESS) { \ |
952 |
|
Y=Z; \ |
953 |
|
} \ |
954 |
|
}while(0) |
955 |
|
|
956 |
LRESULT decompress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) |
LRESULT decompress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) |
957 |
{ |
{ |
958 |
xvid_gbl_init_t init; |
xvid_gbl_init_t init; |
959 |
xvid_dec_create_t create; |
xvid_dec_create_t create; |
960 |
|
HKEY hKey; |
961 |
|
|
962 |
|
if (init_dll() != 0) return ICERR_ERROR; |
963 |
|
|
964 |
memset(&init, 0, sizeof(init)); |
memset(&init, 0, sizeof(init)); |
965 |
init.version = XVID_VERSION; |
init.version = XVID_VERSION; |
966 |
init.cpu_flags = codec->config.cpu; |
init.cpu_flags = codec->config.cpu; |
967 |
xvid_global(0, XVID_GBL_INIT, &init, NULL); |
xvid_global_func(0, XVID_GBL_INIT, &init, NULL); |
968 |
|
|
969 |
memset(&create, 0, sizeof(create)); |
memset(&create, 0, sizeof(create)); |
970 |
create.version = XVID_VERSION; |
create.version = XVID_VERSION; |
971 |
create.width = lpbiInput->bmiHeader.biWidth; |
create.width = lpbiInput->bmiHeader.biWidth; |
972 |
create.height = lpbiInput->bmiHeader.biHeight; |
create.height = lpbiInput->bmiHeader.biHeight; |
973 |
|
|
974 |
switch(xvid_decore(0, XVID_DEC_CREATE, &create, NULL)) |
switch(xvid_decore_func(0, XVID_DEC_CREATE, &create, NULL)) |
975 |
{ |
{ |
976 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
977 |
return ICERR_ERROR; |
return ICERR_ERROR; |
988 |
|
|
989 |
codec->dhandle = create.handle; |
codec->dhandle = create.handle; |
990 |
|
|
991 |
|
RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey); |
992 |
|
|
993 |
|
REG_GET_N("Deblock_Y", pp_dy, 0) |
994 |
|
REG_GET_N("Deblock_UV", pp_duv, 0) |
995 |
|
REG_GET_N("Dering", pp_dr, 0) |
996 |
|
REG_GET_N("FilmEffect", pp_fe, 0) |
997 |
|
|
998 |
|
RegCloseKey(hKey); |
999 |
|
|
1000 |
return ICERR_OK; |
return ICERR_OK; |
1001 |
} |
} |
1002 |
|
|
1003 |
|
|
1004 |
LRESULT decompress_end(CODEC * codec) |
LRESULT decompress_end(CODEC * codec) |
1005 |
{ |
{ |
1006 |
if (codec->dhandle != NULL) |
if (m_hdll != NULL) { |
1007 |
{ |
if (codec->dhandle != NULL) { |
1008 |
xvid_decore(codec->dhandle, XVID_DEC_DESTROY, NULL, NULL); |
xvid_decore_func(codec->dhandle, XVID_DEC_DESTROY, NULL, NULL); |
1009 |
codec->dhandle = NULL; |
codec->dhandle = NULL; |
1010 |
} |
} |
1011 |
|
FreeLibrary(m_hdll); |
1012 |
|
m_hdll = NULL; |
1013 |
|
} |
1014 |
|
|
1015 |
return ICERR_OK; |
return ICERR_OK; |
1016 |
} |
} |
1017 |
|
|
1057 |
convert.interlacing = 0; |
convert.interlacing = 0; |
1058 |
if (convert.input.csp == XVID_CSP_NULL || |
if (convert.input.csp == XVID_CSP_NULL || |
1059 |
convert.output.csp == XVID_CSP_NULL || |
convert.output.csp == XVID_CSP_NULL || |
1060 |
xvid_global(0, XVID_GBL_CONVERT, &convert, NULL) < 0) |
xvid_global_func(0, XVID_GBL_CONVERT, &convert, NULL) < 0) |
1061 |
{ |
{ |
1062 |
return ICERR_BADFORMAT; |
return ICERR_BADFORMAT; |
1063 |
} |
} |
1087 |
frame.output.csp = XVID_CSP_NULL; |
frame.output.csp = XVID_CSP_NULL; |
1088 |
} |
} |
1089 |
|
|
1090 |
switch (xvid_decore(codec->dhandle, XVID_DEC_DECODE, &frame, NULL)) |
if (pp_dy)frame.general |= XVID_DEBLOCKY; |
1091 |
|
if (pp_duv) frame.general |= XVID_DEBLOCKUV; |
1092 |
|
/* if (pp_dr) frame.general |= XVID_DERING; */ |
1093 |
|
if (pp_fe) frame.general |= XVID_FILMEFFECT; |
1094 |
|
|
1095 |
|
switch (xvid_decore_func(codec->dhandle, XVID_DEC_DECODE, &frame, NULL)) |
1096 |
{ |
{ |
1097 |
case XVID_ERR_FAIL : |
case XVID_ERR_FAIL : |
1098 |
return ICERR_ERROR; |
return ICERR_ERROR; |