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

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

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