[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.6, Mon Apr 15 08:03:50 2002 UTC revision 1.11, Sat May 4 12:26:06 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>
45  #include <malloc.h>  #include <string.h>
46  #include <string.h>     // memset  #include <stdio.h>
47    
48  #include "xvid.h"  #include "xvid.h"
49  #include "divx4.h"  #include "divx4.h"
# Line 50  Line 52 
52    
53  #define EMULATED_DIVX_VERSION 20011001  #define EMULATED_DIVX_VERSION 20011001
54    
55  // decore  /**************************************************************************
56     * Divx Instance Structure
57     *
58     * This chain list datatype allows XviD do instanciate multiples divx4
59     * sessions.
60     *
61     * ToDo : The way this chain list is used does not guarantee reentrance
62     *        because they are not protected by any kind of mutex to allow
63     *        only one modifier. We should add a mutex for each element in
64     *        the chainlist.
65     *************************************************************************/
66    
67    
68  typedef struct DINST  typedef struct DINST
# Line 63  Line 75 
75    
76  } DINST;  } DINST;
77    
78    typedef struct EINST
79    {
80            struct EINST * next;
81    
82  static DINST * dhead = NULL;          void * handle;
83            int quality;
84    
85    } EINST;
86    
87  DINST * dinst_find(unsigned long key)  /**************************************************************************
88  {   * Global data (needed to emulate correctly exported symbols from divx4)
89          DINST * dcur = dhead;   *************************************************************************/
90    
91          while (dcur)  /* This is not used in this module but is required by some divx4 encoders*/
92          {  int quiet_encore = 1;
                 if (dcur->key == key)  
                 {  
                         return dcur;  
                 }  
                 dcur = dcur->next;  
         }  
93    
94          return NULL;  /**************************************************************************
95  }   * Local data
96     *************************************************************************/
97    
98    /* The Divx4 instance chainlist */
99    static DINST * dhead = NULL;
100    static EINST * ehead = NULL;
101    
102  DINST * dinst_add(unsigned long key)  /* Divx4 quality to XviD encoder motion flag presets */
103  {  static int const divx4_motion_presets[7] = {
104          DINST * dnext = dhead;          0,
105    
106          dhead = malloc(sizeof(DINST));          PMV_QUICKSTOP16,
         if (dhead == NULL)  
         {  
                 dhead = dnext;  
                 return NULL;  
         }  
107    
108          dhead->key = key;          PMV_EARLYSTOP16,
         dhead->next = dnext;  
109    
110          return dhead;          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
 }  
111    
112            PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |
113            PMV_EARLYSTOP8  | PMV_HALFPELDIAMOND8,
114    
115  void dinst_remove(unsigned long key)          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 |
116  {          PMV_EARLYSTOP8  | PMV_HALFPELDIAMOND8,
         DINST * dcur = dhead;  
117    
118          if (dhead == NULL)          PMV_EARLYSTOP16    | PMV_HALFPELREFINE16 |
119          {          PMV_EXTSEARCH16    | PMV_EARLYSTOP8 |
120                  return;          PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8
121          }  };
122    
         if (dcur->key == key)  
         {  
                 dhead = dcur->next;  
                 free(dcur);  
                 return;  
         }  
123    
124          while (dcur->next)  /* Divx4 quality to general encoder flag presets */
125          {  static int const divx4_general_presets[7] = {
126                  if (dcur->next->key == key)          0,
127                  {          XVID_H263QUANT,
128                          DINST * tmp = dcur->next;          XVID_H263QUANT,
129                          dcur->next = tmp->next;          XVID_H263QUANT | XVID_HALFPEL,
130                          free(tmp);          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
131                          return;          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
132                  }          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
133                  dcur = dcur->next;  };
         }  
 }  
134    
135    /**************************************************************************
136     * Local Prototypes
137     *************************************************************************/
138    
139  int xvid_to_opendivx_dec_csp(int csp)  /* Chain list helper functions */
140  {  static DINST * dinst_find(unsigned long key);
141          switch(csp)  static DINST * dinst_add(unsigned long key);
142          {  static void    dinst_remove(unsigned long key);
143          case DEC_YV12 :  
144                  return XVID_CSP_YV12;  static EINST * einst_find(void *handle);
145          case DEC_420 :  static EINST * einst_add(void *handle);
146                  return XVID_CSP_I420;  static void    einst_remove(void *handle);
147          case DEC_YUY2 :  
148                  return XVID_CSP_YUY2;  /* Converts divx4 colorspaces codes to xvid codes */
149          case DEC_UYVY :  static int xvid_to_opendivx_dec_csp(int csp);
150                  return XVID_CSP_UYVY;  static int xvid_to_opendivx_enc_csp(int csp);
         case DEC_RGB32 :  
                 return XVID_CSP_VFLIP | XVID_CSP_RGB32;  
         case DEC_RGB24 :  
                 return XVID_CSP_VFLIP | XVID_CSP_RGB24;  
         case DEC_RGB565 :  
                 return XVID_CSP_VFLIP | XVID_CSP_RGB565;  
         case DEC_RGB555 :  
                 return XVID_CSP_VFLIP | XVID_CSP_RGB555;  
         case DEC_RGB32_INV :  
                 return XVID_CSP_RGB32;  
         case DEC_RGB24_INV :  
                 return XVID_CSP_RGB24;  
         case DEC_RGB565_INV :  
                 return XVID_CSP_RGB565;  
         case DEC_RGB555_INV :  
                 return XVID_CSP_RGB555;  
         case DEC_USER :  
                 return XVID_CSP_USER;  
         default :  
                 return -1;  
         }  
 }  
151    
152    /**************************************************************************
153     * decore part
154     *
155     * decore is the divx4 entry point used to decompress the mpeg4 bitstream
156     * into a user defined image format.
157     *************************************************************************/
158    
159  int decore(unsigned long key, unsigned long opt,  int
160                                          void * param1, void * param2)  decore(unsigned long key, unsigned long opt, void * param1, void * param2)
161  {  {
162    
163          int xerr;          int xerr;
164    
165          switch (opt)          switch (opt) {
166          {  
167          case DEC_OPT_MEMORY_REQS :          case DEC_OPT_MEMORY_REQS :
168                  {                  {
169                          memset(param2, 0, sizeof(DEC_MEM_REQS));                          memset(param2, 0, sizeof(DEC_MEM_REQS));
# Line 183  Line 172 
172    
173          case DEC_OPT_INIT :          case DEC_OPT_INIT :
174                  {                  {
                         DEC_PARAM * dparam = (DEC_PARAM *)param1;  
175                          XVID_INIT_PARAM xinit;                          XVID_INIT_PARAM xinit;
176                          XVID_DEC_PARAM xparam;                          XVID_DEC_PARAM xparam;
177                          DINST * dcur = dinst_find(key);                  DINST * dcur;
178                          if (dcur == NULL)                  DEC_PARAM * dparam = (DEC_PARAM *)param1;
179    
180                    /* Find the divx4 instance */
181                    if ((dcur = dinst_find(key)) == NULL)
182                          {                          {
183                                  dcur = dinst_add(key);                                  dcur = dinst_add(key);
184                          }                          }
185    
186                    /*
187                     * XviD initialization
188                     * XviD will detect the host cpu type and activate optimized
189                     * functions according to the host cpu features.
190                     */
191                          xinit.cpu_flags = 0;                          xinit.cpu_flags = 0;
192                          xvid_init(NULL, 0, &xinit, NULL);                          xvid_init(NULL, 0, &xinit, NULL);
193    
194                    /* XviD decoder initialization for this instance */
195                          xparam.width = dparam->x_dim;                          xparam.width = dparam->x_dim;
196                          xparam.height = dparam->y_dim;                          xparam.height = dparam->y_dim;
197                          dcur->xframe.colorspace = xvid_to_opendivx_dec_csp(dparam->output_format);                  dcur->xframe.colorspace =
198                            xvid_to_opendivx_dec_csp(dparam->output_format);
199    
200                          xerr = decoder_create(&xparam);                          xerr = decoder_create(&xparam);
201    
202                    /* Store the xvid handle into the divx4 instance chainlist */
203                          dcur->handle = xparam.handle;                          dcur->handle = xparam.handle;
204    
205                          break;                          break;
# Line 208  Line 207 
207    
208          case DEC_OPT_RELEASE :          case DEC_OPT_RELEASE :
209                  {                  {
210                          DINST * dcur = dinst_find(key);                  DINST * dcur;
211                          if (dcur == NULL)  
212                    /* Find the divx4 instance into the chain list */
213                    if ((dcur = dinst_find(key)) == NULL)
214                          {                          {
215                                  return DEC_EXIT;                                  return DEC_EXIT;
216                          }                          }
217    
218                    /* Destroy the XviD decoder attached to this divx4 instance */
219                          xerr = decoder_destroy(dcur->handle);                          xerr = decoder_destroy(dcur->handle);
220    
221                    /* Remove the divx4 instance from the chainlist */
222                          dinst_remove(key);                          dinst_remove(key);
223    
224                          break;                          break;
# Line 223  Line 226 
226    
227          case DEC_OPT_SETPP :          case DEC_OPT_SETPP :
228                  {                  {
229                          // DEC_SET * dset = (DEC_SET *)param1;                  DINST * dcur;
230                          DINST * dcur = dinst_find(key);  
231                          if (dcur == NULL)                  /* Find the divx4 instance into the chain list */
232                    if ((dcur = dinst_find(key)) == NULL)
233                          {                          {
234                                  return DEC_EXIT;                                  return DEC_EXIT;
235                          }                          }
236    
237                          // dcur->xframe.pp = dset->postproc_level;                  /*
238                     * We return DEC_OK but XviD has no postprocessing implemented
239                     * in core.
240                     */
241                          return DEC_OK;                          return DEC_OK;
242                  }                  }
243    
244          case DEC_OPT_SETOUT :          case DEC_OPT_SETOUT :
245                  {                  {
246                    DINST * dcur;
247                          DEC_PARAM * dparam = (DEC_PARAM *)param1;                          DEC_PARAM * dparam = (DEC_PARAM *)param1;
248                          DINST * dcur = dinst_find(key);  
249                          if (dcur == NULL)                  if ((dcur = dinst_find(key)) == NULL)
250                          {                          {
251                                  return DEC_EXIT;                                  return DEC_EXIT;
252                          }                          }
253    
254                          dcur->xframe.colorspace = xvid_to_opendivx_dec_csp(dparam->output_format);                  /* Change the output colorspace */
255                    dcur->xframe.colorspace =
256                            xvid_to_opendivx_dec_csp(dparam->output_format);
257    
258                          return DEC_OK;                          return DEC_OK;
259                  }                  }
# Line 252  Line 261 
261          case DEC_OPT_FRAME:          case DEC_OPT_FRAME:
262                  {                  {
263                          int csp_tmp = 0;                          int csp_tmp = 0;
264                    DINST * dcur;
265                          DEC_FRAME * dframe = (DEC_FRAME *)param1;                          DEC_FRAME * dframe = (DEC_FRAME *)param1;
266                          DINST * dcur = dinst_find(key);  
267                          if (dcur == NULL)                  if ((dcur = dinst_find(key)) == NULL)
268                          {                          {
269                                  return DEC_EXIT;                                  return DEC_EXIT;
270                          }                          }
271    
272                    /* Copy the divx4 fields to the XviD decoder structure */
273                          dcur->xframe.bitstream = dframe->bitstream;                          dcur->xframe.bitstream = dframe->bitstream;
274                          dcur->xframe.length = dframe->length;                          dcur->xframe.length = dframe->length;
275                          dcur->xframe.image = dframe->bmp;                          dcur->xframe.image = dframe->bmp;
276                          dcur->xframe.stride = dframe->stride;                          dcur->xframe.stride = dframe->stride;
277    
278                    /* Does the frame need to be skipped ? */
279                          if (!dframe->render_flag)                          if (!dframe->render_flag)
280                          {                          {
281                            /*
282                             * Then we use the null colorspace to force XviD to
283                             * skip the frame. The original colorspace will be
284                             * restored after the decoder call
285                             */
286                                  csp_tmp = dcur->xframe.colorspace;                                  csp_tmp = dcur->xframe.colorspace;
287                                  dcur->xframe.colorspace = XVID_CSP_NULL;                                  dcur->xframe.colorspace = XVID_CSP_NULL;
288                          }                          }
289    
290                    /* Decode the bitstream */
291                          xerr = decoder_decode(dcur->handle, &dcur->xframe);                          xerr = decoder_decode(dcur->handle, &dcur->xframe);
292    
293                    /* Restore the real colorspace for this instance */
294                          if (!dframe->render_flag)                          if (!dframe->render_flag)
295                          {                          {
296                                  dcur->xframe.colorspace = csp_tmp;                                  dcur->xframe.colorspace = csp_tmp;
# Line 281  Line 299 
299                          break;                          break;
300                  }                  }
301    
   
302          case DEC_OPT_FRAME_311 :          case DEC_OPT_FRAME_311 :
303                    /* XviD does not handle Divx ;-) 3.11 yet */
304                  return DEC_EXIT;                  return DEC_EXIT;
305    
   
306          case DEC_OPT_VERSION:          case DEC_OPT_VERSION:
307                  return EMULATED_DIVX_VERSION;                  return EMULATED_DIVX_VERSION;
308    
309          default :          default :
310                  return DEC_EXIT;                  return DEC_EXIT;
311          }          }
312    
313    
314            /* XviD error code -> Divx4 */
315          switch(xerr)          switch(xerr)
316          {          {
317          case XVID_ERR_OK : return DEC_OK;          case XVID_ERR_OK :
318          case XVID_ERR_MEMORY : return DEC_MEMORY;                  return DEC_OK;
319          case XVID_ERR_FORMAT : return DEC_BAD_FORMAT;          case XVID_ERR_MEMORY :
320          default : // case XVID_ERR_FAIL :                  return DEC_MEMORY;
321            case XVID_ERR_FORMAT :
322                    return DEC_BAD_FORMAT;
323            default :
324                  return DEC_EXIT;                  return DEC_EXIT;
325          }          }
326  }  }
327    
328    /**************************************************************************
329     * Encore Part
330     *
331  // encore   * encore is the divx4 entry point used to compress a frame to a mpeg4
332     * bitstream.
333     *************************************************************************/
334    
335  #define FRAMERATE_INCR          1001  #define FRAMERATE_INCR          1001
336    
337  int divx4_motion_presets[7] = {  int
338          0, PMV_QUICKSTOP16, PMV_EARLYSTOP16, PMV_EARLYSTOP16 | PMV_EARLYSTOP8,  encore(void * handle, int opt, void * param1, void * param2)
         PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8,  
         PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8,  
         PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 |  
         PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8  
 };  
   
 int quality;  
   
 int encore(void * handle, int opt, void * param1, void * param2)  
339  {  {
340    
341          int xerr;          int xerr;
342    
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;
350    
351                    /* Init XviD which will detect host cpu features */
352                          xinit.cpu_flags = 0;                          xinit.cpu_flags = 0;
353                          xvid_init(NULL, 0, &xinit, NULL);                          xvid_init(NULL, 0, &xinit, NULL);
354    
355                    /* 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)
# Line 354  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 */
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 372  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 */
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.general = XVID_HALFPEL | XVID_H263QUANT;                  xframe.general = divx4_general_presets[ecur->quality];
   
                         if(quality > 3)  
                                 xframe.general |= XVID_INTER4V;  
   
                         xframe.motion = divx4_motion_presets[quality];  
433    
434                          xframe.image = eframe->image;                          xframe.image = eframe->image;
435                          switch (eframe->colorspace)                  xframe.colorspace =
436                          {                          xvid_to_opendivx_enc_csp(eframe->colorspace);
                         case ENC_CSP_RGB24 :  
                                 xframe.colorspace = XVID_CSP_VFLIP | XVID_CSP_RGB24;  
                                 break;  
                         case ENC_CSP_YV12 :  
                                 xframe.colorspace = XVID_CSP_YV12;  
                                 break;  
                         case ENC_CSP_YUY2 :  
                                 xframe.colorspace = XVID_CSP_YUY2;  
                                 break;  
                         case ENC_CSP_UYVY :  
                                 xframe.colorspace = XVID_CSP_UYVY;  
                                 break;  
                         case ENC_CSP_I420 :  
                                 xframe.colorspace = XVID_CSP_I420;  
                                 break;  
                         }  
437    
438                          if (opt == ENC_OPT_ENCODE_VBR)                          if (opt == ENC_OPT_ENCODE_VBR)
439                          {                          {
# Line 418  Line 446 
446                                  xframe.quant = 0;                                  xframe.quant = 0;
447                          }                          }
448    
449                    /* Encode the frame */
450                          xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) );                          xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) );
451    
452                    /* Copy back the xvid structure to the divx4 one */
453                          if (eresult)                          if (eresult)
454                          {                          {
455                                  eresult->is_key_frame = xframe.intra;                                  eresult->is_key_frame = xframe.intra;
# Line 438  Line 468 
468                  return ENC_FAIL;                  return ENC_FAIL;
469          }          }
470    
471            /* XviD Error code  -> Divx4 error code */
472          switch(xerr)          switch(xerr)
473          {          {
474          case XVID_ERR_OK : return ENC_OK;          case XVID_ERR_OK :
475          case XVID_ERR_MEMORY : return ENC_MEMORY;                  return ENC_OK;
476          case XVID_ERR_FORMAT : return ENC_BAD_FORMAT;          case XVID_ERR_MEMORY :
477          default : // case XVID_ERR_FAIL :                  return ENC_MEMORY;
478            case XVID_ERR_FORMAT :
479                    return ENC_BAD_FORMAT;
480            default :
481                  return ENC_FAIL;                  return ENC_FAIL;
482          }          }
483  }  }
484    
485    /**************************************************************************
486     * Local Functions
487     *************************************************************************/
488    
489    /***************************************
490     * DINST chainlist helper functions    *
491     ***************************************/
492    
493    /* Find an element in the chainlist according to its key value */
494    static DINST * dinst_find(unsigned long key)
495    {
496            DINST * dcur = dhead;
497    
498            while (dcur)
499            {
500                    if (dcur->key == key)
501                    {
502                            return dcur;
503                    }
504                    dcur = dcur->next;
505            }
506    
507            return NULL;
508    }
509    
510    
511    /* Add an element to the chainlist */
512    static DINST * dinst_add(unsigned long key)
513    {
514            DINST * dnext = dhead;
515    
516            dhead = malloc(sizeof(DINST));
517            if (dhead == NULL)
518            {
519                    dhead = dnext;
520                    return NULL;
521            }
522    
523            dhead->key = key;
524            dhead->next = dnext;
525    
526            return dhead;
527    }
528    
529    
530    /* Remove an elmement from the chainlist */
531    static void dinst_remove(unsigned long key)
532    {
533            DINST * dcur = dhead;
534    
535            if (dhead == NULL)
536            {
537                    return;
538            }
539    
540            if (dcur->key == key)
541            {
542                    dhead = dcur->next;
543                    free(dcur);
544                    return;
545            }
546    
547            while (dcur->next)
548            {
549                    if (dcur->next->key == key)
550                    {
551                            DINST * tmp = dcur->next;
552                            dcur->next = tmp->next;
553                            free(tmp);
554                            return;
555                    }
556                    dcur = dcur->next;
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           *
633     ***************************************/
634    
635    static int xvid_to_opendivx_dec_csp(int csp)
636    {
637    
638            switch(csp)
639            {
640            case DEC_YV12 :
641                    return XVID_CSP_YV12;
642            case DEC_420 :
643                    return XVID_CSP_I420;
644            case DEC_YUY2 :
645                    return XVID_CSP_YUY2;
646            case DEC_UYVY :
647                    return XVID_CSP_UYVY;
648            case DEC_RGB32 :
649                    return XVID_CSP_VFLIP | XVID_CSP_RGB32;
650            case DEC_RGB24 :
651                    return XVID_CSP_VFLIP | XVID_CSP_RGB24;
652            case DEC_RGB565 :
653                    return XVID_CSP_VFLIP | XVID_CSP_RGB565;
654            case DEC_RGB555 :
655                    return XVID_CSP_VFLIP | XVID_CSP_RGB555;
656            case DEC_RGB32_INV :
657                    return XVID_CSP_RGB32;
658            case DEC_RGB24_INV :
659                    return XVID_CSP_RGB24;
660            case DEC_RGB565_INV :
661                    return XVID_CSP_RGB565;
662            case DEC_RGB555_INV :
663                    return XVID_CSP_RGB555;
664            case DEC_USER :
665                    return XVID_CSP_USER;
666            default :
667                    return -1;
668            }
669    }
670    
671    static int xvid_to_opendivx_enc_csp(int csp)
672    {
673    
674            switch (csp)
675            {
676            case ENC_CSP_RGB24 :
677                    return XVID_CSP_VFLIP | XVID_CSP_RGB24;
678            case ENC_CSP_YV12 :
679                    return XVID_CSP_YV12;
680            case ENC_CSP_YUY2 :
681                    return XVID_CSP_YUY2;
682            case ENC_CSP_UYVY :
683                    return XVID_CSP_UYVY;
684            case ENC_CSP_I420 :
685                    return XVID_CSP_I420;
686            default :
687                    return -1;
688            }
689    }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

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