[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.15, Mon Jun 24 09:53:17 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 109  Line 112 
112    
113          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
114    
115          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
116          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,                  PMV_HALFPELREFINE8,
117    
118          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
119          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,                  PMV_HALFPELREFINE8,
120    
121          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 |
122          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8                  PMV_HALFPELREFINE8
123  };  };
124    
125    
# Line 156  Line 159 
159   *************************************************************************/   *************************************************************************/
160    
161  int  int
162  decore(unsigned long key, unsigned long opt, void * param1, void * param2)  decore(unsigned long key,
163               unsigned long opt,
164               void *param1,
165               void *param2)
166  {  {
167    
168          int xerr;          int xerr;
# Line 177  Line 183 
183                  DEC_PARAM * dparam = (DEC_PARAM *)param1;                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
184    
185                  /* Find the divx4 instance */                  /* Find the divx4 instance */
186                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
187                          dcur = dinst_add(key);                          dcur = dinst_add(key);
188                  }                  }
189    
# Line 209  Line 214 
214                  DINST * dcur;                  DINST * dcur;
215    
216                  /* Find the divx4 instance into the chain list */                  /* Find the divx4 instance into the chain list */
217                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
218                          return DEC_EXIT;                          return DEC_EXIT;
219                  }                  }
220    
# Line 228  Line 232 
232                  DINST * dcur;                  DINST * dcur;
233    
234                  /* Find the divx4 instance into the chain list */                  /* Find the divx4 instance into the chain list */
235                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
236                          return DEC_EXIT;                          return DEC_EXIT;
237                  }                  }
238    
# Line 245  Line 248 
248                  DINST * dcur;                  DINST * dcur;
249                  DEC_PARAM * dparam = (DEC_PARAM *)param1;                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
250    
251                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
252                          return DEC_EXIT;                          return DEC_EXIT;
253                  }                  }
254    
# Line 263  Line 265 
265                  DINST * dcur;                  DINST * dcur;
266                  DEC_FRAME * dframe = (DEC_FRAME *)param1;                  DEC_FRAME * dframe = (DEC_FRAME *)param1;
267    
268                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
269                          return DEC_EXIT;                          return DEC_EXIT;
270                  }                  }
271    
# Line 275  Line 276 
276                  dcur->xframe.stride = dframe->stride;                  dcur->xframe.stride = dframe->stride;
277    
278                  /* Does the frame need to be skipped ? */                  /* Does the frame need to be skipped ? */
279                  if (!dframe->render_flag)                          if (!dframe->render_flag) {
                 {  
280                          /*                          /*
281                           * Then we use the null colorspace to force XviD to                           * Then we use the null colorspace to force XviD to
282                           * skip the frame. The original colorspace will be                           * skip the frame. The original colorspace will be
# Line 290  Line 290 
290                  xerr = decoder_decode(dcur->handle, &dcur->xframe);                  xerr = decoder_decode(dcur->handle, &dcur->xframe);
291    
292                  /* Restore the real colorspace for this instance */                  /* Restore the real colorspace for this instance */
293                  if (!dframe->render_flag)                          if (!dframe->render_flag) {
                 {  
294                          dcur->xframe.colorspace = csp_tmp;                          dcur->xframe.colorspace = csp_tmp;
295                  }                  }
296    
# Line 311  Line 310 
310    
311    
312          /* XviD error code -> Divx4 */          /* XviD error code -> Divx4 */
313          switch(xerr)          switch (xerr) {
         {  
314          case XVID_ERR_OK :          case XVID_ERR_OK :
315                  return DEC_OK;                  return DEC_OK;
316          case XVID_ERR_MEMORY :          case XVID_ERR_MEMORY :
# Line 334  Line 332 
332  #define FRAMERATE_INCR          1001  #define FRAMERATE_INCR          1001
333    
334  int  int
335  encore(void * handle, int opt, void * param1, void * param2)  encore(void *handle,
336               int opt,
337               void *param1,
338               void *param2)
339  {  {
340    
341          int xerr;          int xerr;
# Line 354  Line 355 
355                  /* Settings are copied to the XviD encoder structure */                  /* Settings are copied to the XviD encoder structure */
356                  xparam.width = eparam->x_dim;                  xparam.width = eparam->x_dim;
357                  xparam.height = eparam->y_dim;                  xparam.height = eparam->y_dim;
358                  if ((eparam->framerate - (int)eparam->framerate) == 0)                          if ((eparam->framerate - (int) eparam->framerate) == 0) {
                 {  
359                          xparam.fincr = 1;                          xparam.fincr = 1;
360                          xparam.fbase = (int)eparam->framerate;                          xparam.fbase = (int)eparam->framerate;
361                  }                          } else {
                 else  
                 {  
362                          xparam.fincr = FRAMERATE_INCR;                          xparam.fincr = FRAMERATE_INCR;
363                          xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);                          xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);
364                  }                  }
# Line 372  Line 370 
370                  xparam.max_quantizer = eparam->max_quantizer;                  xparam.max_quantizer = eparam->max_quantizer;
371                  xparam.max_key_interval = eparam->max_key_interval;                  xparam.max_key_interval = eparam->max_key_interval;
372    
373    #ifdef BFRAMES
374                            xparam.global = 0;
375                            xparam.max_bframes = -1;        /* use "original" IP-frame encoder */
376                            xparam.bquant_ratio = 200;
377    #endif
378    
379                  /* Create the encoder session */                  /* Create the encoder session */
380                  xerr = encoder_create(&xparam);                  xerr = encoder_create(&xparam);
381    
382                  eparam->handle = xparam.handle;                  eparam->handle = xparam.handle;
383    
384                  /* Create an encoder instance in the chainlist */                  /* Create an encoder instance in the chainlist */
385                  if ((ecur = einst_find(xparam.handle)) == NULL)                          if ((ecur = einst_find(xparam.handle)) == NULL) {
                 {  
386                          ecur = einst_add(xparam.handle);                          ecur = einst_add(xparam.handle);
387    
388                          if(ecur == NULL) {                          if(ecur == NULL) {
# Line 390  Line 393 
393                  }                  }
394    
395                  ecur->quality = eparam->quality;                  ecur->quality = eparam->quality;
396                  if(ecur->quality < 0) ecur->quality = 0;                          if (ecur->quality < 0)
397                  if(ecur->quality > 6) ecur->quality = 6;                                  ecur->quality = 0;
398                            if (ecur->quality > 6)
399                                    ecur->quality = 6;
400    
401                  break;                  break;
402          }          }
# Line 400  Line 405 
405          {          {
406                  EINST *ecur;                  EINST *ecur;
407    
408                  if ((ecur = einst_find(handle)) == NULL)                          if ((ecur = einst_find(handle)) == NULL) {
                 {  
409                          return ENC_FAIL;                          return ENC_FAIL;
410                  }                  }
411    
# Line 421  Line 425 
425                  XVID_ENC_FRAME xframe;                  XVID_ENC_FRAME xframe;
426                  XVID_ENC_STATS xstats;                  XVID_ENC_STATS xstats;
427    
428                  if ((ecur = einst_find(handle)) == NULL)                          if ((ecur = einst_find(handle)) == NULL) {
                 {  
429                          return ENC_FAIL;                          return ENC_FAIL;
430                  }                  }
431    
# Line 433  Line 436 
436                  xframe.general = divx4_general_presets[ecur->quality];                  xframe.general = divx4_general_presets[ecur->quality];
437    
438                  xframe.image = eframe->image;                  xframe.image = eframe->image;
439                  xframe.colorspace =                          xframe.colorspace = xvid_to_opendivx_enc_csp(eframe->colorspace);
                         xvid_to_opendivx_enc_csp(eframe->colorspace);  
440    
441                  if (opt == ENC_OPT_ENCODE_VBR)                          if (opt == ENC_OPT_ENCODE_VBR) {
                 {  
442                          xframe.intra = eframe->intra;                          xframe.intra = eframe->intra;
443                          xframe.quant = eframe->quant;                          xframe.quant = eframe->quant;
444                  }                          } else {
                 else  
                 {  
445                          xframe.intra = -1;                          xframe.intra = -1;
446                          xframe.quant = 0;                          xframe.quant = 0;
447                  }                  }
448    
449                  /* Encode the frame */                  /* Encode the frame */
450                  xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) );                          xerr =
451                                    encoder_encode((Encoder *) handle, &xframe,
452                                                               (eresult ? &xstats : NULL));
453    
454                  /* Copy back the xvid structure to the divx4 one */                  /* Copy back the xvid structure to the divx4 one */
455                  if (eresult)                          if (eresult) {
                 {  
456                          eresult->is_key_frame = xframe.intra;                          eresult->is_key_frame = xframe.intra;
457                          eresult->quantizer = xstats.quant;                          eresult->quantizer = xstats.quant;
458                          eresult->total_bits = xframe.length * 8;                          eresult->total_bits = xframe.length * 8;
459                          eresult->motion_bits = xstats.hlength * 8;                          eresult->motion_bits = xstats.hlength * 8;
460                          eresult->texture_bits = eresult->total_bits - eresult->motion_bits;                                  eresult->texture_bits =
461                                            eresult->total_bits - eresult->motion_bits;
462                  }                  }
463    
464                  eframe->length = xframe.length;                  eframe->length = xframe.length;
# Line 470  Line 471 
471          }          }
472    
473          /* XviD Error code  -> Divx4 error code */          /* XviD Error code  -> Divx4 error code */
474          switch(xerr)          switch (xerr) {
         {  
475          case XVID_ERR_OK :          case XVID_ERR_OK :
476                  return ENC_OK;                  return ENC_OK;
477          case XVID_ERR_MEMORY :          case XVID_ERR_MEMORY :
# Line 492  Line 492 
492   ***************************************/   ***************************************/
493    
494  /* Find an element in the chainlist according to its key value */  /* Find an element in the chainlist according to its key value */
495  static DINST * dinst_find(unsigned long key)  static DINST *
496    dinst_find(unsigned long key)
497  {  {
498          DINST * dcur = dhead;          DINST * dcur = dhead;
499    
500          while (dcur)          while (dcur) {
501          {                  if (dcur->key == key) {
                 if (dcur->key == key)  
                 {  
502                          return dcur;                          return dcur;
503                  }                  }
504                  dcur = dcur->next;                  dcur = dcur->next;
# Line 510  Line 509 
509    
510    
511  /* Add an element to the chainlist */  /* Add an element to the chainlist */
512  static DINST * dinst_add(unsigned long key)  static DINST *
513    dinst_add(unsigned long key)
514  {  {
515          DINST * dnext = dhead;          DINST * dnext = dhead;
516    
517          dhead = malloc(sizeof(DINST));          dhead = malloc(sizeof(DINST));
518          if (dhead == NULL)          if (dhead == NULL) {
         {  
519                  dhead = dnext;                  dhead = dnext;
520                  return NULL;                  return NULL;
521          }          }
# Line 529  Line 528 
528    
529    
530  /* Remove an elmement from the chainlist */  /* Remove an elmement from the chainlist */
531  static void dinst_remove(unsigned long key)  static void
532    dinst_remove(unsigned long key)
533  {  {
534          DINST * dcur = dhead;          DINST * dcur = dhead;
535    
536          if (dhead == NULL)          if (dhead == NULL) {
         {  
537                  return;                  return;
538          }          }
539    
540          if (dcur->key == key)          if (dcur->key == key) {
         {  
541                  dhead = dcur->next;                  dhead = dcur->next;
542                  free(dcur);                  free(dcur);
543                  return;                  return;
544          }          }
545    
546          while (dcur->next)          while (dcur->next) {
547          {                  if (dcur->next->key == key) {
                 if (dcur->next->key == key)  
                 {  
548                          DINST * tmp = dcur->next;                          DINST * tmp = dcur->next;
549    
550                          dcur->next = tmp->next;                          dcur->next = tmp->next;
551                          free(tmp);                          free(tmp);
552                          return;                          return;
# Line 564  Line 561 
561   ***************************************/   ***************************************/
562    
563  /* Find an element in the chainlist according to its handle */  /* Find an element in the chainlist according to its handle */
564  static EINST * einst_find(void *handle)  static EINST *
565    einst_find(void *handle)
566  {  {
567          EINST * ecur = ehead;          EINST * ecur = ehead;
568    
569          while (ecur)          while (ecur) {
570          {                  if (ecur->handle == handle) {
                 if (ecur->handle == handle)  
                 {  
571                          return ecur;                          return ecur;
572                  }                  }
573                  ecur = ecur->next;                  ecur = ecur->next;
# Line 582  Line 578 
578    
579    
580  /* Add an element to the chainlist */  /* Add an element to the chainlist */
581  static EINST * einst_add(void *handle)  static EINST *
582    einst_add(void *handle)
583  {  {
584          EINST * enext = ehead;          EINST * enext = ehead;
585    
586          ehead = malloc(sizeof(EINST));          ehead = malloc(sizeof(EINST));
587          if (ehead == NULL)          if (ehead == NULL) {
         {  
588                  ehead = enext;                  ehead = enext;
589                  return NULL;                  return NULL;
590          }          }
# Line 601  Line 597 
597    
598    
599  /* Remove an elmement from the chainlist */  /* Remove an elmement from the chainlist */
600  static void einst_remove(void *handle)  static void
601    einst_remove(void *handle)
602  {  {
603          EINST * ecur = ehead;          EINST * ecur = ehead;
604    
605          if (ehead == NULL)          if (ehead == NULL) {
         {  
606                  return;                  return;
607          }          }
608    
609          if (ecur->handle == handle)          if (ecur->handle == handle) {
         {  
610                  ehead = ecur->next;                  ehead = ecur->next;
611                  free(ecur);                  free(ecur);
612                  return;                  return;
613          }          }
614    
615          while (ecur->next)          while (ecur->next) {
616          {                  if (ecur->next->handle == handle) {
                 if (ecur->next->handle == handle)  
                 {  
617                          EINST * tmp = ecur->next;                          EINST * tmp = ecur->next;
618    
619                          ecur->next = tmp->next;                          ecur->next = tmp->next;
620                          free(tmp);                          free(tmp);
621                          return;                          return;
# Line 629  Line 623 
623                  ecur = ecur->next;                  ecur = ecur->next;
624          }          }
625  }  }
626    
627  /***************************************  /***************************************
628   * Colorspace code converter           *   * Colorspace code converter           *
629   ***************************************/   ***************************************/
630    
631  static int xvid_to_opendivx_dec_csp(int csp)  static int
632    xvid_to_opendivx_dec_csp(int csp)
633  {  {
634    
635          switch(csp)          switch (csp) {
         {  
636          case DEC_YV12 :          case DEC_YV12 :
637                  return XVID_CSP_YV12;                  return XVID_CSP_YV12;
638          case DEC_420 :          case DEC_420 :
# Line 669  Line 664 
664          }          }
665  }  }
666    
667  static int xvid_to_opendivx_enc_csp(int csp)  static int
668    xvid_to_opendivx_enc_csp(int csp)
669  {  {
670    
671          switch (csp)          switch (csp) {
         {  
672          case ENC_CSP_RGB24 :          case ENC_CSP_RGB24 :
673                  return XVID_CSP_VFLIP | XVID_CSP_RGB24;                  return XVID_CSP_VFLIP | XVID_CSP_RGB24;
674          case ENC_CSP_YV12 :          case ENC_CSP_YV12 :

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

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