[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.10, Sun Apr 28 20:03:14 2002 UTC revision 1.12, Wed May 22 12:40:25 2002 UTC
# Line 43  Line 43 
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] = {
104          0,          0,
105    
         PMV_QUICKSTOP16,  
   
106          PMV_EARLYSTOP16,          PMV_EARLYSTOP16,
107    
108            PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16,
109    
110          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
111    
112          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |
113          PMV_EARLYSTOP8  | PMV_HALFPELDIAMOND8,          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,
114    
115          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |
116          PMV_EARLYSTOP8  | PMV_HALFPELDIAMOND8,          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8,
117    
118          PMV_EARLYSTOP16    | PMV_HALFPELREFINE16 |          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 |
119          PMV_EXTSEARCH16    | PMV_EARLYSTOP8 |          PMV_EARLYSTOP8  | PMV_HALFPELREFINE8
         PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8  
120  };  };
121    
122    
# Line 121  Line 131 
131          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
132  };  };
133    
 /*  
  * Current divx4 encoder quality  
  * ToDo : this data should not be shared between encoder instances  
  */  
 static int quality;  
   
134  /**************************************************************************  /**************************************************************************
135   * Local Prototypes   * Local Prototypes
136   *************************************************************************/   *************************************************************************/
# Line 136  Line 140 
140  static DINST * dinst_add(unsigned long key);  static DINST * dinst_add(unsigned long key);
141  static void    dinst_remove(unsigned long key);  static void    dinst_remove(unsigned long key);
142    
143    static EINST * einst_find(void *handle);
144    static EINST * einst_add(void *handle);
145    static void    einst_remove(void *handle);
146    
147  /* Converts divx4 colorspaces codes to xvid codes */  /* Converts divx4 colorspaces codes to xvid codes */
148  static int xvid_to_opendivx_dec_csp(int csp);  static int xvid_to_opendivx_dec_csp(int csp);
149  static int xvid_to_opendivx_enc_csp(int csp);  static int xvid_to_opendivx_enc_csp(int csp);
# Line 334  Line 342 
342          switch(opt) {          switch(opt) {
343          case ENC_OPT_INIT :          case ENC_OPT_INIT :
344          {          {
345                    EINST *ecur;
346                  ENC_PARAM * eparam = (ENC_PARAM *)param1;                  ENC_PARAM * eparam = (ENC_PARAM *)param1;
347                  XVID_INIT_PARAM xinit;                  XVID_INIT_PARAM xinit;
348                  XVID_ENC_PARAM xparam;                  XVID_ENC_PARAM xparam;
# Line 362  Line 371 
371                  xparam.min_quantizer = eparam->min_quantizer;                  xparam.min_quantizer = eparam->min_quantizer;
372                  xparam.max_quantizer = eparam->max_quantizer;                  xparam.max_quantizer = eparam->max_quantizer;
373                  xparam.max_key_interval = eparam->max_key_interval;                  xparam.max_key_interval = eparam->max_key_interval;
                 quality = eparam->quality;  
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 */
381                    if ((ecur = einst_find(xparam.handle)) == NULL)
382                    {
383                            ecur = einst_add(xparam.handle);
384    
385                            if(ecur == NULL) {
386                                    encoder_destroy((Encoder*)xparam.handle);
387                                    return ENC_MEMORY;
388                            }
389    
390                    }
391    
392                    ecur->quality = eparam->quality;
393                    if(ecur->quality < 0) ecur->quality = 0;
394                    if(ecur->quality > 6) ecur->quality = 6;
395    
396                  break;                  break;
397          }          }
398    
399          case ENC_OPT_RELEASE :          case ENC_OPT_RELEASE :
400          {          {
401                    EINST *ecur;
402    
403                    if ((ecur = einst_find(handle)) == NULL)
404                    {
405                            return ENC_FAIL;
406                    }
407    
408                  xerr = encoder_destroy((Encoder *) handle);                  xerr = encoder_destroy((Encoder *) handle);
409                  break;                  break;
410          }          }
# Line 381  Line 412 
412          case ENC_OPT_ENCODE :          case ENC_OPT_ENCODE :
413          case ENC_OPT_ENCODE_VBR :          case ENC_OPT_ENCODE_VBR :
414          {          {
415                    EINST *ecur;
416    
417                  ENC_FRAME * eframe = (ENC_FRAME *)param1;                  ENC_FRAME * eframe = (ENC_FRAME *)param1;
418                  ENC_RESULT * eresult = (ENC_RESULT *)param2;                  ENC_RESULT * eresult = (ENC_RESULT *)param2;
419                  XVID_ENC_FRAME xframe;                  XVID_ENC_FRAME xframe;
420                  XVID_ENC_STATS xstats;                  XVID_ENC_STATS xstats;
421    
422                    if ((ecur = einst_find(handle)) == NULL)
423                    {
424                            return ENC_FAIL;
425                    }
426    
427                  /* Copy the divx4 info into the xvid structure */                  /* Copy the divx4 info into the xvid structure */
428                  xframe.bitstream = eframe->bitstream;                  xframe.bitstream = eframe->bitstream;
429                  xframe.length = eframe->length;                  xframe.length = eframe->length;
430                    xframe.motion = divx4_motion_presets[ecur->quality];
431                  xframe.motion = divx4_motion_presets[quality];                  xframe.general = divx4_general_presets[ecur->quality];
                 xframe.general = divx4_general_presets[quality];  
432    
433                  xframe.image = eframe->image;                  xframe.image = eframe->image;
434                  xframe.colorspace =                  xframe.colorspace =
# Line 519  Line 556 
556          }          }
557  }  }
558    
559    
560    /***************************************
561     * EINST chainlist helper functions    *
562     ***************************************/
563    
564    /* Find an element in the chainlist according to its handle */
565    static EINST * einst_find(void *handle)
566    {
567            EINST * ecur = ehead;
568    
569            while (ecur)
570            {
571                    if (ecur->handle == handle)
572                    {
573                            return ecur;
574                    }
575                    ecur = ecur->next;
576            }
577    
578            return NULL;
579    }
580    
581    
582    /* Add an element to the chainlist */
583    static EINST * einst_add(void *handle)
584    {
585            EINST * enext = ehead;
586    
587            ehead = malloc(sizeof(EINST));
588            if (ehead == NULL)
589            {
590                    ehead = enext;
591                    return NULL;
592            }
593    
594            ehead->handle = handle;
595            ehead->next = enext;
596    
597            return ehead;
598    }
599    
600    
601    /* Remove an elmement from the chainlist */
602    static void einst_remove(void *handle)
603    {
604            EINST * ecur = ehead;
605    
606            if (ehead == NULL)
607            {
608                    return;
609            }
610    
611            if (ecur->handle == handle)
612            {
613                    ehead = ecur->next;
614                    free(ecur);
615                    return;
616            }
617    
618            while (ecur->next)
619            {
620                    if (ecur->next->handle == handle)
621                    {
622                            EINST * tmp = ecur->next;
623                            ecur->next = tmp->next;
624                            free(tmp);
625                            return;
626                    }
627                    ecur = ecur->next;
628            }
629    }
630  /***************************************  /***************************************
631   * Colorspace code converter           *   * Colorspace code converter           *
632   ***************************************/   ***************************************/

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.12

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