[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.9, Sun Apr 28 16:15:51 2002 UTC revision 1.13, Sun Jun 9 23:05:35 2002 UTC
# Line 1  Line 1 
1  /**************************************************************************  /**************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      OpenDivx API wrapper   *  - OpenDivx API wrapper -
5   *   *
6   *      This program is an implementation of a part of one or more MPEG-4   *      This program is an implementation of a part of one or more MPEG-4
7   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
# 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$
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 72  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 85  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 119  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 134  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 332  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 360  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                    einst_remove(handle);
409                  xerr = encoder_destroy((Encoder *) handle);                  xerr = encoder_destroy((Encoder *) handle);
410    
411                  break;                  break;
412          }          }
413    
414          case ENC_OPT_ENCODE :          case ENC_OPT_ENCODE :
415          case ENC_OPT_ENCODE_VBR :          case ENC_OPT_ENCODE_VBR :
416          {          {
417                    EINST *ecur;
418    
419                  ENC_FRAME * eframe = (ENC_FRAME *)param1;                  ENC_FRAME * eframe = (ENC_FRAME *)param1;
420                  ENC_RESULT * eresult = (ENC_RESULT *)param2;                  ENC_RESULT * eresult = (ENC_RESULT *)param2;
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)
425                    {
426                            return ENC_FAIL;
427                    }
428    
429                  /* Copy the divx4 info into the xvid structure */                  /* Copy the divx4 info into the xvid structure */
430                  xframe.bitstream = eframe->bitstream;                  xframe.bitstream = eframe->bitstream;
431                  xframe.length = eframe->length;                  xframe.length = eframe->length;
432                    xframe.motion = divx4_motion_presets[ecur->quality];
433                  xframe.motion = divx4_motion_presets[quality];                  xframe.general = divx4_general_presets[ecur->quality];
                 xframe.general = divx4_general_presets[quality];  
434    
435                  xframe.image = eframe->image;                  xframe.image = eframe->image;
436                  xframe.colorspace =                  xframe.colorspace =
# Line 517  Line 558 
558          }          }
559  }  }
560    
561    
562    /***************************************
563     * EINST chainlist helper functions    *
564     ***************************************/
565    
566    /* Find an element in the chainlist according to its handle */
567    static EINST * einst_find(void *handle)
568    {
569            EINST * ecur = ehead;
570    
571            while (ecur)
572            {
573                    if (ecur->handle == handle)
574                    {
575                            return ecur;
576                    }
577                    ecur = ecur->next;
578            }
579    
580            return NULL;
581    }
582    
583    
584    /* Add an element to the chainlist */
585    static EINST * einst_add(void *handle)
586    {
587            EINST * enext = ehead;
588    
589            ehead = malloc(sizeof(EINST));
590            if (ehead == NULL)
591            {
592                    ehead = enext;
593                    return NULL;
594            }
595    
596            ehead->handle = handle;
597            ehead->next = enext;
598    
599            return ehead;
600    }
601    
602    
603    /* Remove an elmement from the chainlist */
604    static void einst_remove(void *handle)
605    {
606            EINST * ecur = ehead;
607    
608            if (ehead == NULL)
609            {
610                    return;
611            }
612    
613            if (ecur->handle == handle)
614            {
615                    ehead = ecur->next;
616                    free(ecur);
617                    return;
618            }
619    
620            while (ecur->next)
621            {
622                    if (ecur->next->handle == handle)
623                    {
624                            EINST * tmp = ecur->next;
625                            ecur->next = tmp->next;
626                            free(tmp);
627                            return;
628                    }
629                    ecur = ecur->next;
630            }
631    }
632  /***************************************  /***************************************
633   * Colorspace code converter           *   * Colorspace code converter           *
634   ***************************************/   ***************************************/

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

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