[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.14, Wed Jun 12 20:38:39 2002 UTC
# Line 73  Line 73 
73          void * handle;          void * handle;
74          XVID_DEC_FRAME xframe;          XVID_DEC_FRAME xframe;
75    
76  } DINST;  }
77    DINST;
78    
79  typedef struct EINST  typedef struct EINST
80  {  {
# Line 82  Line 83 
83          void * handle;          void * handle;
84          int quality;          int quality;
85    
86  } EINST;  }
87    EINST;
88    
89  /**************************************************************************  /**************************************************************************
90   * Global data (needed to emulate correctly exported symbols from divx4)   * Global data (needed to emulate correctly exported symbols from divx4)
# Line 109  Line 111 
111    
112          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
113    
114          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
115          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,                  PMV_HALFPELREFINE8,
116    
117          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
118          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,                  PMV_HALFPELREFINE8,
119    
120          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 |
121          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8                  PMV_HALFPELREFINE8
122  };  };
123    
124    
# Line 156  Line 158 
158   *************************************************************************/   *************************************************************************/
159    
160  int  int
161  decore(unsigned long key, unsigned long opt, void * param1, void * param2)  decore(unsigned long key,
162               unsigned long opt,
163               void *param1,
164               void *param2)
165  {  {
166    
167          int xerr;          int xerr;
# Line 177  Line 182 
182                  DEC_PARAM * dparam = (DEC_PARAM *)param1;                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
183    
184                  /* Find the divx4 instance */                  /* Find the divx4 instance */
185                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
186                          dcur = dinst_add(key);                          dcur = dinst_add(key);
187                  }                  }
188    
# Line 209  Line 213 
213                  DINST * dcur;                  DINST * dcur;
214    
215                  /* Find the divx4 instance into the chain list */                  /* Find the divx4 instance into the chain list */
216                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
217                          return DEC_EXIT;                          return DEC_EXIT;
218                  }                  }
219    
# Line 228  Line 231 
231                  DINST * dcur;                  DINST * dcur;
232    
233                  /* Find the divx4 instance into the chain list */                  /* Find the divx4 instance into the chain list */
234                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
235                          return DEC_EXIT;                          return DEC_EXIT;
236                  }                  }
237    
# Line 245  Line 247 
247                  DINST * dcur;                  DINST * dcur;
248                  DEC_PARAM * dparam = (DEC_PARAM *)param1;                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
249    
250                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
251                          return DEC_EXIT;                          return DEC_EXIT;
252                  }                  }
253    
# Line 263  Line 264 
264                  DINST * dcur;                  DINST * dcur;
265                  DEC_FRAME * dframe = (DEC_FRAME *)param1;                  DEC_FRAME * dframe = (DEC_FRAME *)param1;
266    
267                  if ((dcur = dinst_find(key)) == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                 {  
268                          return DEC_EXIT;                          return DEC_EXIT;
269                  }                  }
270    
# Line 275  Line 275 
275                  dcur->xframe.stride = dframe->stride;                  dcur->xframe.stride = dframe->stride;
276    
277                  /* Does the frame need to be skipped ? */                  /* Does the frame need to be skipped ? */
278                  if (!dframe->render_flag)                          if (!dframe->render_flag) {
                 {  
279                          /*                          /*
280                           * Then we use the null colorspace to force XviD to                           * Then we use the null colorspace to force XviD to
281                           * skip the frame. The original colorspace will be                           * skip the frame. The original colorspace will be
# Line 290  Line 289 
289                  xerr = decoder_decode(dcur->handle, &dcur->xframe);                  xerr = decoder_decode(dcur->handle, &dcur->xframe);
290    
291                  /* Restore the real colorspace for this instance */                  /* Restore the real colorspace for this instance */
292                  if (!dframe->render_flag)                          if (!dframe->render_flag) {
                 {  
293                          dcur->xframe.colorspace = csp_tmp;                          dcur->xframe.colorspace = csp_tmp;
294                  }                  }
295    
# Line 311  Line 309 
309    
310    
311          /* XviD error code -> Divx4 */          /* XviD error code -> Divx4 */
312          switch(xerr)          switch (xerr) {
         {  
313          case XVID_ERR_OK :          case XVID_ERR_OK :
314                  return DEC_OK;                  return DEC_OK;
315          case XVID_ERR_MEMORY :          case XVID_ERR_MEMORY :
# Line 334  Line 331 
331  #define FRAMERATE_INCR          1001  #define FRAMERATE_INCR          1001
332    
333  int  int
334  encore(void * handle, int opt, void * param1, void * param2)  encore(void *handle,
335               int opt,
336               void *param1,
337               void *param2)
338  {  {
339    
340          int xerr;          int xerr;
# Line 354  Line 354 
354                  /* Settings are copied to the XviD encoder structure */                  /* Settings are copied to the XviD encoder structure */
355                  xparam.width = eparam->x_dim;                  xparam.width = eparam->x_dim;
356                  xparam.height = eparam->y_dim;                  xparam.height = eparam->y_dim;
357                  if ((eparam->framerate - (int)eparam->framerate) == 0)                          if ((eparam->framerate - (int) eparam->framerate) == 0) {
                 {  
358                          xparam.fincr = 1;                          xparam.fincr = 1;
359                          xparam.fbase = (int)eparam->framerate;                          xparam.fbase = (int)eparam->framerate;
360                  }                          } else {
                 else  
                 {  
361                          xparam.fincr = FRAMERATE_INCR;                          xparam.fincr = FRAMERATE_INCR;
362                          xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);                          xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);
363                  }                  }
# Line 378  Line 375 
375                  eparam->handle = xparam.handle;                  eparam->handle = xparam.handle;
376    
377                  /* Create an encoder instance in the chainlist */                  /* Create an encoder instance in the chainlist */
378                  if ((ecur = einst_find(xparam.handle)) == NULL)                          if ((ecur = einst_find(xparam.handle)) == NULL) {
                 {  
379                          ecur = einst_add(xparam.handle);                          ecur = einst_add(xparam.handle);
380    
381                          if(ecur == NULL) {                          if(ecur == NULL) {
# Line 390  Line 386 
386                  }                  }
387    
388                  ecur->quality = eparam->quality;                  ecur->quality = eparam->quality;
389                  if(ecur->quality < 0) ecur->quality = 0;                          if (ecur->quality < 0)
390                  if(ecur->quality > 6) ecur->quality = 6;                                  ecur->quality = 0;
391                            if (ecur->quality > 6)
392                                    ecur->quality = 6;
393    
394                  break;                  break;
395          }          }
# Line 400  Line 398 
398          {          {
399                  EINST *ecur;                  EINST *ecur;
400    
401                  if ((ecur = einst_find(handle)) == NULL)                          if ((ecur = einst_find(handle)) == NULL) {
                 {  
402                          return ENC_FAIL;                          return ENC_FAIL;
403                  }                  }
404    
# Line 421  Line 418 
418                  XVID_ENC_FRAME xframe;                  XVID_ENC_FRAME xframe;
419                  XVID_ENC_STATS xstats;                  XVID_ENC_STATS xstats;
420    
421                  if ((ecur = einst_find(handle)) == NULL)                          if ((ecur = einst_find(handle)) == NULL) {
                 {  
422                          return ENC_FAIL;                          return ENC_FAIL;
423                  }                  }
424    
# Line 433  Line 429 
429                  xframe.general = divx4_general_presets[ecur->quality];                  xframe.general = divx4_general_presets[ecur->quality];
430    
431                  xframe.image = eframe->image;                  xframe.image = eframe->image;
432                  xframe.colorspace =                          xframe.colorspace = xvid_to_opendivx_enc_csp(eframe->colorspace);
                         xvid_to_opendivx_enc_csp(eframe->colorspace);  
433    
434                  if (opt == ENC_OPT_ENCODE_VBR)                          if (opt == ENC_OPT_ENCODE_VBR) {
                 {  
435                          xframe.intra = eframe->intra;                          xframe.intra = eframe->intra;
436                          xframe.quant = eframe->quant;                          xframe.quant = eframe->quant;
437                  }                          } else {
                 else  
                 {  
438                          xframe.intra = -1;                          xframe.intra = -1;
439                          xframe.quant = 0;                          xframe.quant = 0;
440                  }                  }
441    
442                  /* Encode the frame */                  /* Encode the frame */
443                  xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) );                          xerr =
444                                    encoder_encode((Encoder *) handle, &xframe,
445                                                               (eresult ? &xstats : NULL));
446    
447                  /* Copy back the xvid structure to the divx4 one */                  /* Copy back the xvid structure to the divx4 one */
448                  if (eresult)                          if (eresult) {
                 {  
449                          eresult->is_key_frame = xframe.intra;                          eresult->is_key_frame = xframe.intra;
450                          eresult->quantizer = xstats.quant;                          eresult->quantizer = xstats.quant;
451                          eresult->total_bits = xframe.length * 8;                          eresult->total_bits = xframe.length * 8;
452                          eresult->motion_bits = xstats.hlength * 8;                          eresult->motion_bits = xstats.hlength * 8;
453                          eresult->texture_bits = eresult->total_bits - eresult->motion_bits;                                  eresult->texture_bits =
454                                            eresult->total_bits - eresult->motion_bits;
455                  }                  }
456    
457                  eframe->length = xframe.length;                  eframe->length = xframe.length;
# Line 470  Line 464 
464          }          }
465    
466          /* XviD Error code  -> Divx4 error code */          /* XviD Error code  -> Divx4 error code */
467          switch(xerr)          switch (xerr) {
         {  
468          case XVID_ERR_OK :          case XVID_ERR_OK :
469                  return ENC_OK;                  return ENC_OK;
470          case XVID_ERR_MEMORY :          case XVID_ERR_MEMORY :
# Line 492  Line 485 
485   ***************************************/   ***************************************/
486    
487  /* Find an element in the chainlist according to its key value */  /* Find an element in the chainlist according to its key value */
488  static DINST * dinst_find(unsigned long key)  static DINST *
489    dinst_find(unsigned long key)
490  {  {
491          DINST * dcur = dhead;          DINST * dcur = dhead;
492    
493          while (dcur)          while (dcur) {
494          {                  if (dcur->key == key) {
                 if (dcur->key == key)  
                 {  
495                          return dcur;                          return dcur;
496                  }                  }
497                  dcur = dcur->next;                  dcur = dcur->next;
# Line 510  Line 502 
502    
503    
504  /* Add an element to the chainlist */  /* Add an element to the chainlist */
505  static DINST * dinst_add(unsigned long key)  static DINST *
506    dinst_add(unsigned long key)
507  {  {
508          DINST * dnext = dhead;          DINST * dnext = dhead;
509    
510          dhead = malloc(sizeof(DINST));          dhead = malloc(sizeof(DINST));
511          if (dhead == NULL)          if (dhead == NULL) {
         {  
512                  dhead = dnext;                  dhead = dnext;
513                  return NULL;                  return NULL;
514          }          }
# Line 529  Line 521 
521    
522    
523  /* Remove an elmement from the chainlist */  /* Remove an elmement from the chainlist */
524  static void dinst_remove(unsigned long key)  static void
525    dinst_remove(unsigned long key)
526  {  {
527          DINST * dcur = dhead;          DINST * dcur = dhead;
528    
529          if (dhead == NULL)          if (dhead == NULL) {
         {  
530                  return;                  return;
531          }          }
532    
533          if (dcur->key == key)          if (dcur->key == key) {
         {  
534                  dhead = dcur->next;                  dhead = dcur->next;
535                  free(dcur);                  free(dcur);
536                  return;                  return;
537          }          }
538    
539          while (dcur->next)          while (dcur->next) {
540          {                  if (dcur->next->key == key) {
                 if (dcur->next->key == key)  
                 {  
541                          DINST * tmp = dcur->next;                          DINST * tmp = dcur->next;
542    
543                          dcur->next = tmp->next;                          dcur->next = tmp->next;
544                          free(tmp);                          free(tmp);
545                          return;                          return;
# Line 564  Line 554 
554   ***************************************/   ***************************************/
555    
556  /* Find an element in the chainlist according to its handle */  /* Find an element in the chainlist according to its handle */
557  static EINST * einst_find(void *handle)  static EINST *
558    einst_find(void *handle)
559  {  {
560          EINST * ecur = ehead;          EINST * ecur = ehead;
561    
562          while (ecur)          while (ecur) {
563          {                  if (ecur->handle == handle) {
                 if (ecur->handle == handle)  
                 {  
564                          return ecur;                          return ecur;
565                  }                  }
566                  ecur = ecur->next;                  ecur = ecur->next;
# Line 582  Line 571 
571    
572    
573  /* Add an element to the chainlist */  /* Add an element to the chainlist */
574  static EINST * einst_add(void *handle)  static EINST *
575    einst_add(void *handle)
576  {  {
577          EINST * enext = ehead;          EINST * enext = ehead;
578    
579          ehead = malloc(sizeof(EINST));          ehead = malloc(sizeof(EINST));
580          if (ehead == NULL)          if (ehead == NULL) {
         {  
581                  ehead = enext;                  ehead = enext;
582                  return NULL;                  return NULL;
583          }          }
# Line 601  Line 590 
590    
591    
592  /* Remove an elmement from the chainlist */  /* Remove an elmement from the chainlist */
593  static void einst_remove(void *handle)  static void
594    einst_remove(void *handle)
595  {  {
596          EINST * ecur = ehead;          EINST * ecur = ehead;
597    
598          if (ehead == NULL)          if (ehead == NULL) {
         {  
599                  return;                  return;
600          }          }
601    
602          if (ecur->handle == handle)          if (ecur->handle == handle) {
         {  
603                  ehead = ecur->next;                  ehead = ecur->next;
604                  free(ecur);                  free(ecur);
605                  return;                  return;
606          }          }
607    
608          while (ecur->next)          while (ecur->next) {
609          {                  if (ecur->next->handle == handle) {
                 if (ecur->next->handle == handle)  
                 {  
610                          EINST * tmp = ecur->next;                          EINST * tmp = ecur->next;
611    
612                          ecur->next = tmp->next;                          ecur->next = tmp->next;
613                          free(tmp);                          free(tmp);
614                          return;                          return;
# Line 629  Line 616 
616                  ecur = ecur->next;                  ecur = ecur->next;
617          }          }
618  }  }
619    
620  /***************************************  /***************************************
621   * Colorspace code converter           *   * Colorspace code converter           *
622   ***************************************/   ***************************************/
623    
624  static int xvid_to_opendivx_dec_csp(int csp)  static int
625    xvid_to_opendivx_dec_csp(int csp)
626  {  {
627    
628          switch(csp)          switch (csp) {
         {  
629          case DEC_YV12 :          case DEC_YV12 :
630                  return XVID_CSP_YV12;                  return XVID_CSP_YV12;
631          case DEC_420 :          case DEC_420 :
# Line 669  Line 657 
657          }          }
658  }  }
659    
660  static int xvid_to_opendivx_enc_csp(int csp)  static int
661    xvid_to_opendivx_enc_csp(int csp)
662  {  {
663    
664          switch (csp)          switch (csp) {
         {  
665          case ENC_CSP_RGB24 :          case ENC_CSP_RGB24 :
666                  return XVID_CSP_VFLIP | XVID_CSP_RGB24;                  return XVID_CSP_VFLIP | XVID_CSP_RGB24;
667          case ENC_CSP_YV12 :          case ENC_CSP_YV12 :

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

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