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

Diff of /trunk/xvidcore/src/divx4.c

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

revision 158, Fri May 3 15:26:30 2002 UTC revision 159, Sat May 4 12:26:06 2002 UTC
# Line 37  Line 37 
37   *      22.12.2001      removed some compiler warnings   *      22.12.2001      removed some compiler warnings
38   *      16.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *      16.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
39   *   *
40   * $Id: divx4.c,v 1.10 2002-04-28 20:03:14 edgomez Exp $   * $Id: divx4.c,v 1.11 2002-05-04 12:26:06 edgomez Exp $
41   *   *
42   *************************************************************************/   *************************************************************************/
43    
44  #include <stdlib.h>  #include <stdlib.h>
45  #include <string.h>  #include <string.h>
46    #include <stdio.h>
47    
48  #include "xvid.h"  #include "xvid.h"
49  #include "divx4.h"  #include "divx4.h"
# Line 74  Line 75 
75    
76  } DINST;  } DINST;
77    
78    typedef struct EINST
79    {
80            struct EINST * next;
81    
82            void * handle;
83            int quality;
84    
85    } EINST;
86    
87  /**************************************************************************  /**************************************************************************
88   * Global data (needed to emulate correctly exported symbols from divx4)   * Global data (needed to emulate correctly exported symbols from divx4)
89   *************************************************************************/   *************************************************************************/
# Line 87  Line 97 
97    
98  /* The Divx4 instance chainlist */  /* The Divx4 instance chainlist */
99  static DINST * dhead = NULL;  static DINST * dhead = NULL;
100    static EINST * ehead = NULL;
101    
102  /* Divx4 quality to XviD encoder motion flag presets */  /* Divx4 quality to XviD encoder motion flag presets */
103  static int const divx4_motion_presets[7] = {  static int const divx4_motion_presets[7] = {
# Line 121  Line 132 
132          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
133  };  };
134    
 /*  
  * Current divx4 encoder quality  
  * ToDo : this data should not be shared between encoder instances  
  */  
 static int quality;  
   
135  /**************************************************************************  /**************************************************************************
136   * Local Prototypes   * Local Prototypes
137   *************************************************************************/   *************************************************************************/
# Line 136  Line 141 
141  static DINST * dinst_add(unsigned long key);  static DINST * dinst_add(unsigned long key);
142  static void    dinst_remove(unsigned long key);  static void    dinst_remove(unsigned long key);
143    
144    static EINST * einst_find(void *handle);
145    static EINST * einst_add(void *handle);
146    static void    einst_remove(void *handle);
147    
148  /* Converts divx4 colorspaces codes to xvid codes */  /* Converts divx4 colorspaces codes to xvid codes */
149  static int xvid_to_opendivx_dec_csp(int csp);  static int xvid_to_opendivx_dec_csp(int csp);
150  static int xvid_to_opendivx_enc_csp(int csp);  static int xvid_to_opendivx_enc_csp(int csp);
# Line 334  Line 343 
343          switch(opt) {          switch(opt) {
344          case ENC_OPT_INIT :          case ENC_OPT_INIT :
345          {          {
346                    EINST *ecur;
347                  ENC_PARAM * eparam = (ENC_PARAM *)param1;                  ENC_PARAM * eparam = (ENC_PARAM *)param1;
348                  XVID_INIT_PARAM xinit;                  XVID_INIT_PARAM xinit;
349                  XVID_ENC_PARAM xparam;                  XVID_ENC_PARAM xparam;
# Line 362  Line 372 
372                  xparam.min_quantizer = eparam->min_quantizer;                  xparam.min_quantizer = eparam->min_quantizer;
373                  xparam.max_quantizer = eparam->max_quantizer;                  xparam.max_quantizer = eparam->max_quantizer;
374                  xparam.max_key_interval = eparam->max_key_interval;                  xparam.max_key_interval = eparam->max_key_interval;
                 quality = eparam->quality;  
375    
376                  /* Create the encoder session */                  /* Create the encoder session */
377                  xerr = encoder_create(&xparam);                  xerr = encoder_create(&xparam);
378    
379                  eparam->handle = xparam.handle;                  eparam->handle = xparam.handle;
380    
381                    /* Create an encoder instance in the chainlist */
382                    if ((ecur = einst_find(xparam.handle)) == NULL)
383                    {
384                            ecur = einst_add(xparam.handle);
385    
386                            if(ecur == NULL) {
387                                    encoder_destroy((Encoder*)xparam.handle);
388                                    return ENC_MEMORY;
389                            }
390    
391                    }
392    
393                    ecur->quality = eparam->quality;
394                    if(ecur->quality < 0) ecur->quality = 0;
395                    if(ecur->quality > 6) ecur->quality = 6;
396    
397                  break;                  break;
398          }          }
399    
400          case ENC_OPT_RELEASE :          case ENC_OPT_RELEASE :
401          {          {
402                    EINST *ecur;
403    
404                    if ((ecur = einst_find(handle)) == NULL)
405                    {
406                            return ENC_FAIL;
407                    }
408    
409                  xerr = encoder_destroy((Encoder *) handle);                  xerr = encoder_destroy((Encoder *) handle);
410                  break;                  break;
411          }          }
# Line 381  Line 413 
413          case ENC_OPT_ENCODE :          case ENC_OPT_ENCODE :
414          case ENC_OPT_ENCODE_VBR :          case ENC_OPT_ENCODE_VBR :
415          {          {
416                    EINST *ecur;
417    
418                  ENC_FRAME * eframe = (ENC_FRAME *)param1;                  ENC_FRAME * eframe = (ENC_FRAME *)param1;
419                  ENC_RESULT * eresult = (ENC_RESULT *)param2;                  ENC_RESULT * eresult = (ENC_RESULT *)param2;
420                  XVID_ENC_FRAME xframe;                  XVID_ENC_FRAME xframe;
421                  XVID_ENC_STATS xstats;                  XVID_ENC_STATS xstats;
422    
423                    if ((ecur = einst_find(handle)) == NULL)
424                    {
425                            return ENC_FAIL;
426                    }
427    
428                  /* Copy the divx4 info into the xvid structure */                  /* Copy the divx4 info into the xvid structure */
429                  xframe.bitstream = eframe->bitstream;                  xframe.bitstream = eframe->bitstream;
430                  xframe.length = eframe->length;                  xframe.length = eframe->length;
431                    xframe.motion = divx4_motion_presets[ecur->quality];
432                  xframe.motion = divx4_motion_presets[quality];                  xframe.general = divx4_general_presets[ecur->quality];
                 xframe.general = divx4_general_presets[quality];  
433    
434                  xframe.image = eframe->image;                  xframe.image = eframe->image;
435                  xframe.colorspace =                  xframe.colorspace =
# Line 519  Line 557 
557          }          }
558  }  }
559    
560    
561    /***************************************
562     * EINST chainlist helper functions    *
563     ***************************************/
564    
565    /* Find an element in the chainlist according to its handle */
566    static EINST * einst_find(void *handle)
567    {
568            EINST * ecur = ehead;
569    
570            while (ecur)
571            {
572                    if (ecur->handle == handle)
573                    {
574                            return ecur;
575                    }
576                    ecur = ecur->next;
577            }
578    
579            return NULL;
580    }
581    
582    
583    /* Add an element to the chainlist */
584    static EINST * einst_add(void *handle)
585    {
586            EINST * enext = ehead;
587    
588            ehead = malloc(sizeof(EINST));
589            if (ehead == NULL)
590            {
591                    ehead = enext;
592                    return NULL;
593            }
594    
595            ehead->handle = handle;
596            ehead->next = enext;
597    
598            return ehead;
599    }
600    
601    
602    /* Remove an elmement from the chainlist */
603    static void einst_remove(void *handle)
604    {
605            EINST * ecur = ehead;
606    
607            if (ehead == NULL)
608            {
609                    return;
610            }
611    
612            if (ecur->handle == handle)
613            {
614                    ehead = ecur->next;
615                    free(ecur);
616                    return;
617            }
618    
619            while (ecur->next)
620            {
621                    if (ecur->next->handle == handle)
622                    {
623                            EINST * tmp = ecur->next;
624                            ecur->next = tmp->next;
625                            free(tmp);
626                            return;
627                    }
628                    ecur = ecur->next;
629            }
630    }
631  /***************************************  /***************************************
632   * Colorspace code converter           *   * Colorspace code converter           *
633   ***************************************/   ***************************************/

Legend:
Removed from v.158  
changed lines
  Added in v.159

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