[svn] / branches / dev-api-4 / xvidcore / vfw / src / codec.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/vfw/src/codec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1203, Tue Nov 11 16:25:39 2003 UTC revision 1305, Sat Jan 3 12:06:11 2004 UTC
# Line 285  Line 285 
285                           * builds and that activates lot of other debug printfs. We only                           * builds and that activates lot of other debug printfs. We only
286                           * want these all the time */                           * want these all the time */
287                          char buf[1024];                          char buf[1024];
288                          sprintf(buf, "[%5i]   type=%c   Q:%2i   length:%6i",                          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,
# Line 299  Line 299 
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)
# Line 311  Line 356 
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    
# Line 321  Line 367 
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;
# Line 352  Line 398 
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;
# Line 362  Line 408 
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;
# Line 384  Line 430 
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;
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;
# Line 400  Line 446 
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          }          }
# Line 442  Line 488 
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;
# Line 472  Line 518 
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);
# Line 489  Line 539 
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) {
# Line 555  Line 607 
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;
# Line 578  Line 645 
645                  frame.motion |= XVID_ME_DETECT_STATIC_MOTION;                  frame.motion |= XVID_ME_DETECT_STATIC_MOTION;
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)
# Line 637  Line 709 
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);
# Line 654  Line 719 
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 :
# Line 789  Line 854 
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;
# Line 822  Line 889 
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    
# Line 872  Line 943 
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                  }                  }
# Line 902  Line 973 
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;

Legend:
Removed from v.1203  
changed lines
  Added in v.1305

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4