[cvs] / xvidcore / src / divx4.c Repository:
ViewVC logotype

Diff of /xvidcore/src/divx4.c

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

revision 1.13, Sun Jun 9 23:05:35 2002 UTC revision 1.16.2.3, Thu Nov 7 10:28:15 2002 UTC
# Line 32  Line 32 
32   *   *
33   *  History:   *  History:
34   *   *
35     *      24.02.2002      #def BFRAMES compatibility
36   *  26.02.2001  fixed dec_csp bugs   *  26.02.2001  fixed dec_csp bugs
37   *  26.12.2001  xvid_init() support   *  26.12.2001  xvid_init() support
38   *  22.12.2001  removed some compiler warnings   *  22.12.2001  removed some compiler warnings
# Line 73  Line 74 
74          void * handle;          void * handle;
75          XVID_DEC_FRAME xframe;          XVID_DEC_FRAME xframe;
76    
77  } DINST;  }
78    DINST;
79    
80  typedef struct EINST  typedef struct EINST
81  {  {
# Line 82  Line 84 
84          void * handle;          void * handle;
85          int quality;          int quality;
86    
87  } EINST;  }
88    EINST;
89    
90  /**************************************************************************  /**************************************************************************
91   * Global data (needed to emulate correctly exported symbols from divx4)   * Global data (needed to emulate correctly exported symbols from divx4)
# Line 103  Line 106 
106  static int const divx4_motion_presets[7] = {  static int const divx4_motion_presets[7] = {
107          0,          0,
108    
109          PMV_EARLYSTOP16,          0,
110    
111          PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16,          PMV_ADVANCEDDIAMOND16,
112    
113          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,          PMV_HALFPELREFINE16,
114    
115          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8,
         PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,  
116    
117          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8,
         PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,  
118    
119          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 |          PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_HALFPELREFINE8
         PMV_EARLYSTOP8  | PMV_HALFPELREFINE8  
120  };  };
121    
122    
# Line 156  Line 156 
156   *************************************************************************/   *************************************************************************/
157    
158  int  int
159  decore(unsigned long key, unsigned long opt, void * param1, void * param2)  decore(unsigned long key,
160               unsigned long opt,
161               void *param1,
162               void *param2)
163  {  {
164    
165          int xerr;          int xerr;
# Line 177  Line 180 
180                  DEC_PARAM * dparam = (DEC_PARAM *)param1;                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
181    
182                  /* Find the divx4 instance */                  /* Find the divx4 instance */
183                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
184                          dcur = dinst_add(key);                          dcur = dinst_add(key);
185                  }                  }
186    
# Line 209  Line 211 
211                  DINST * dcur;                  DINST * dcur;
212    
213                  /* Find the divx4 instance into the chain list */                  /* Find the divx4 instance into the chain list */
214                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
215                          return DEC_EXIT;                          return DEC_EXIT;
216                  }                  }
217    
# Line 228  Line 229 
229                  DINST * dcur;                  DINST * dcur;
230    
231                  /* Find the divx4 instance into the chain list */                  /* Find the divx4 instance into the chain list */
232                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
233                          return DEC_EXIT;                          return DEC_EXIT;
234                  }                  }
235    
# Line 245  Line 245 
245                  DINST * dcur;                  DINST * dcur;
246                  DEC_PARAM * dparam = (DEC_PARAM *)param1;                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
247    
248                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
249                          return DEC_EXIT;                          return DEC_EXIT;
250                  }                  }
251    
# Line 263  Line 262 
262                  DINST * dcur;                  DINST * dcur;
263                  DEC_FRAME * dframe = (DEC_FRAME *)param1;                  DEC_FRAME * dframe = (DEC_FRAME *)param1;
264    
265                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
266                          return DEC_EXIT;                          return DEC_EXIT;
267                  }                  }
268    
# Line 275  Line 273 
273                  dcur->xframe.stride = dframe->stride;                  dcur->xframe.stride = dframe->stride;
274    
275                  /* Does the frame need to be skipped ? */                  /* Does the frame need to be skipped ? */
276                  if (!dframe->render_flag)                          if (!dframe->render_flag) {
                 {  
277                          /*                          /*
278                           * Then we use the null colorspace to force XviD to                           * Then we use the null colorspace to force XviD to
279                           * skip the frame. The original colorspace will be                           * skip the frame. The original colorspace will be
# Line 287  Line 284 
284                  }                  }
285    
286                  /* Decode the bitstream */                  /* Decode the bitstream */
287                  xerr = decoder_decode(dcur->handle, &dcur->xframe);                          xerr = decoder_decode(dcur->handle, &dcur->xframe, NULL);
288    
289                  /* Restore the real colorspace for this instance */                  /* Restore the real colorspace for this instance */
290                  if (!dframe->render_flag)                          if (!dframe->render_flag) {
                 {  
291                          dcur->xframe.colorspace = csp_tmp;                          dcur->xframe.colorspace = csp_tmp;
292                  }                  }
293    
# Line 311  Line 307 
307    
308    
309          /* XviD error code -> Divx4 */          /* XviD error code -> Divx4 */
310          switch(xerr)          switch (xerr) {
         {  
311          case XVID_ERR_OK :          case XVID_ERR_OK :
312                  return DEC_OK;                  return DEC_OK;
313          case XVID_ERR_MEMORY :          case XVID_ERR_MEMORY :
# Line 334  Line 329 
329  #define FRAMERATE_INCR          1001  #define FRAMERATE_INCR          1001
330    
331  int  int
332  encore(void * handle, int opt, void * param1, void * param2)  encore(void *handle,
333               int opt,
334               void *param1,
335               void *param2)
336  {  {
337    
338          int xerr;          int xerr;
# Line 354  Line 352 
352                  /* Settings are copied to the XviD encoder structure */                  /* Settings are copied to the XviD encoder structure */
353                  xparam.width = eparam->x_dim;                  xparam.width = eparam->x_dim;
354                  xparam.height = eparam->y_dim;                  xparam.height = eparam->y_dim;
355                  if ((eparam->framerate - (int)eparam->framerate) == 0)                          if ((eparam->framerate - (int) eparam->framerate) == 0) {
                 {  
356                          xparam.fincr = 1;                          xparam.fincr = 1;
357                          xparam.fbase = (int)eparam->framerate;                          xparam.fbase = (int)eparam->framerate;
358                  }                          } else {
                 else  
                 {  
359                          xparam.fincr = FRAMERATE_INCR;                          xparam.fincr = FRAMERATE_INCR;
360                          xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);                          xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);
361                  }                  }
# Line 372  Line 367 
367                  xparam.max_quantizer = eparam->max_quantizer;                  xparam.max_quantizer = eparam->max_quantizer;
368                  xparam.max_key_interval = eparam->max_key_interval;                  xparam.max_key_interval = eparam->max_key_interval;
369    
370                            xparam.global = 0;
371                            xparam.max_bframes = -1;        /* use "original" IP-frame encoder */
372                            xparam.bquant_ratio = 200;
373                            xparam.frame_drop_ratio = 0;    /* dont drop frames */
374    
375                  /* Create the encoder session */                  /* Create the encoder session */
376                  xerr = encoder_create(&xparam);                  xerr = encoder_create(&xparam);
377    
378                  eparam->handle = xparam.handle;                  eparam->handle = xparam.handle;
379    
380                  /* Create an encoder instance in the chainlist */                  /* Create an encoder instance in the chainlist */
381                  if ((ecur = einst_find(xparam.handle)) == NULL)                          if ((ecur = einst_find(xparam.handle)) == NULL) {
                 {  
382                          ecur = einst_add(xparam.handle);                          ecur = einst_add(xparam.handle);
383    
384                          if(ecur == NULL) {                          if(ecur == NULL) {
# Line 390  Line 389 
389                  }                  }
390    
391                  ecur->quality = eparam->quality;                  ecur->quality = eparam->quality;
392                  if(ecur->quality < 0) ecur->quality = 0;                          if (ecur->quality < 0)
393                  if(ecur->quality > 6) ecur->quality = 6;                                  ecur->quality = 0;
394                            if (ecur->quality > 6)
395                                    ecur->quality = 6;
396    
397                  break;                  break;
398          }          }
# Line 400  Line 401 
401          {          {
402                  EINST *ecur;                  EINST *ecur;
403    
404                  if ((ecur = einst_find(handle)) == NULL)                          if ((ecur = einst_find(handle)) == NULL) {
                 {  
405                          return ENC_FAIL;                          return ENC_FAIL;
406                  }                  }
407    
# Line 421  Line 421 
421                  XVID_ENC_FRAME xframe;                  XVID_ENC_FRAME xframe;
422                  XVID_ENC_STATS xstats;                  XVID_ENC_STATS xstats;
423    
424                  if ((ecur = einst_find(handle)) == NULL)                          if ((ecur = einst_find(handle)) == NULL) {
                 {  
425                          return ENC_FAIL;                          return ENC_FAIL;
426                  }                  }
427    
# Line 433  Line 432 
432                  xframe.general = divx4_general_presets[ecur->quality];                  xframe.general = divx4_general_presets[ecur->quality];
433    
434                  xframe.image = eframe->image;                  xframe.image = eframe->image;
435                  xframe.colorspace =                          xframe.colorspace = xvid_to_opendivx_enc_csp(eframe->colorspace);
                         xvid_to_opendivx_enc_csp(eframe->colorspace);  
436    
437                  if (opt == ENC_OPT_ENCODE_VBR)                          if (opt == ENC_OPT_ENCODE_VBR) {
                 {  
438                          xframe.intra = eframe->intra;                          xframe.intra = eframe->intra;
439                          xframe.quant = eframe->quant;                          xframe.quant = eframe->quant;
440                  }                          } else {
                 else  
                 {  
441                          xframe.intra = -1;                          xframe.intra = -1;
442                          xframe.quant = 0;                          xframe.quant = 0;
443                  }                  }
444    
445                  /* Encode the frame */                  /* Encode the frame */
446                  xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) );                          xerr =
447                                    encoder_encode((Encoder *) handle, &xframe,
448                                                               (eresult ? &xstats : NULL));
449    
450                  /* Copy back the xvid structure to the divx4 one */                  /* Copy back the xvid structure to the divx4 one */
451                  if (eresult)                          if (eresult) {
                 {  
452                          eresult->is_key_frame = xframe.intra;                          eresult->is_key_frame = xframe.intra;
453                          eresult->quantizer = xstats.quant;                          eresult->quantizer = xstats.quant;
454                          eresult->total_bits = xframe.length * 8;                          eresult->total_bits = xframe.length * 8;
455                          eresult->motion_bits = xstats.hlength * 8;                          eresult->motion_bits = xstats.hlength * 8;
456                          eresult->texture_bits = eresult->total_bits - eresult->motion_bits;                                  eresult->texture_bits =
457                                            eresult->total_bits - eresult->motion_bits;
458                  }                  }
459    
460                  eframe->length = xframe.length;                  eframe->length = xframe.length;
# Line 470  Line 467 
467          }          }
468    
469          /* XviD Error code  -> Divx4 error code */          /* XviD Error code  -> Divx4 error code */
470          switch(xerr)          switch (xerr) {
         {  
471          case XVID_ERR_OK :          case XVID_ERR_OK :
472                  return ENC_OK;                  return ENC_OK;
473          case XVID_ERR_MEMORY :          case XVID_ERR_MEMORY :
# Line 492  Line 488 
488   ***************************************/   ***************************************/
489    
490  /* Find an element in the chainlist according to its key value */  /* Find an element in the chainlist according to its key value */
491  static DINST * dinst_find(unsigned long key)  static DINST *
492    dinst_find(unsigned long key)
493  {  {
494          DINST * dcur = dhead;          DINST * dcur = dhead;
495    
496          while (dcur)          while (dcur) {
497          {                  if (dcur->key == key) {
                 if (dcur->key == key)  
                 {  
498                          return dcur;                          return dcur;
499                  }                  }
500                  dcur = dcur->next;                  dcur = dcur->next;
# Line 510  Line 505 
505    
506    
507  /* Add an element to the chainlist */  /* Add an element to the chainlist */
508  static DINST * dinst_add(unsigned long key)  static DINST *
509    dinst_add(unsigned long key)
510  {  {
511          DINST * dnext = dhead;          DINST * dnext = dhead;
512    
513          dhead = malloc(sizeof(DINST));          dhead = malloc(sizeof(DINST));
514          if (dhead == NULL)          if (dhead == NULL) {
         {  
515                  dhead = dnext;                  dhead = dnext;
516                  return NULL;                  return NULL;
517          }          }
# Line 529  Line 524 
524    
525    
526  /* Remove an elmement from the chainlist */  /* Remove an elmement from the chainlist */
527  static void dinst_remove(unsigned long key)  static void
528    dinst_remove(unsigned long key)
529  {  {
530          DINST * dcur = dhead;          DINST * dcur = dhead;
531    
532          if (dhead == NULL)          if (dhead == NULL) {
         {  
533                  return;                  return;
534          }          }
535    
536          if (dcur->key == key)          if (dcur->key == key) {
         {  
537                  dhead = dcur->next;                  dhead = dcur->next;
538                  free(dcur);                  free(dcur);
539                  return;                  return;
540          }          }
541    
542          while (dcur->next)          while (dcur->next) {
543          {                  if (dcur->next->key == key) {
                 if (dcur->next->key == key)  
                 {  
544                          DINST * tmp = dcur->next;                          DINST * tmp = dcur->next;
545    
546                          dcur->next = tmp->next;                          dcur->next = tmp->next;
547                          free(tmp);                          free(tmp);
548                          return;                          return;
# Line 564  Line 557 
557   ***************************************/   ***************************************/
558    
559  /* Find an element in the chainlist according to its handle */  /* Find an element in the chainlist according to its handle */
560  static EINST * einst_find(void *handle)  static EINST *
561    einst_find(void *handle)
562  {  {
563          EINST * ecur = ehead;          EINST * ecur = ehead;
564    
565          while (ecur)          while (ecur) {
566          {                  if (ecur->handle == handle) {
                 if (ecur->handle == handle)  
                 {  
567                          return ecur;                          return ecur;
568                  }                  }
569                  ecur = ecur->next;                  ecur = ecur->next;
# Line 582  Line 574 
574    
575    
576  /* Add an element to the chainlist */  /* Add an element to the chainlist */
577  static EINST * einst_add(void *handle)  static EINST *
578    einst_add(void *handle)
579  {  {
580          EINST * enext = ehead;          EINST * enext = ehead;
581    
582          ehead = malloc(sizeof(EINST));          ehead = malloc(sizeof(EINST));
583          if (ehead == NULL)          if (ehead == NULL) {
         {  
584                  ehead = enext;                  ehead = enext;
585                  return NULL;                  return NULL;
586          }          }
# Line 601  Line 593 
593    
594    
595  /* Remove an elmement from the chainlist */  /* Remove an elmement from the chainlist */
596  static void einst_remove(void *handle)  static void
597    einst_remove(void *handle)
598  {  {
599          EINST * ecur = ehead;          EINST * ecur = ehead;
600    
601          if (ehead == NULL)          if (ehead == NULL) {
         {  
602                  return;                  return;
603          }          }
604    
605          if (ecur->handle == handle)          if (ecur->handle == handle) {
         {  
606                  ehead = ecur->next;                  ehead = ecur->next;
607                  free(ecur);                  free(ecur);
608                  return;                  return;
609          }          }
610    
611          while (ecur->next)          while (ecur->next) {
612          {                  if (ecur->next->handle == handle) {
                 if (ecur->next->handle == handle)  
                 {  
613                          EINST * tmp = ecur->next;                          EINST * tmp = ecur->next;
614    
615                          ecur->next = tmp->next;                          ecur->next = tmp->next;
616                          free(tmp);                          free(tmp);
617                          return;                          return;
# Line 629  Line 619 
619                  ecur = ecur->next;                  ecur = ecur->next;
620          }          }
621  }  }
622    
623  /***************************************  /***************************************
624   * Colorspace code converter           *   * Colorspace code converter           *
625   ***************************************/   ***************************************/
626    
627  static int xvid_to_opendivx_dec_csp(int csp)  static int
628    xvid_to_opendivx_dec_csp(int csp)
629  {  {
630    
631          switch(csp)          switch (csp) {
         {  
632          case DEC_YV12 :          case DEC_YV12 :
633                  return XVID_CSP_YV12;                  return XVID_CSP_YV12;
634          case DEC_420 :          case DEC_420 :
# Line 669  Line 660 
660          }          }
661  }  }
662    
663  static int xvid_to_opendivx_enc_csp(int csp)  static int
664    xvid_to_opendivx_enc_csp(int csp)
665  {  {
666    
667          switch (csp)          switch (csp) {
         {  
668          case ENC_CSP_RGB24 :          case ENC_CSP_RGB24 :
669                  return XVID_CSP_VFLIP | XVID_CSP_RGB24;                  return XVID_CSP_VFLIP | XVID_CSP_RGB24;
670          case ENC_CSP_YV12 :          case ENC_CSP_YV12 :

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.16.2.3

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