[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.4, Sat Mar 9 16:24:21 2002 UTC revision 1.17, Wed Sep 4 20:46:00 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 32  Line 32 
32   *   *
33   *      History:   *      History:
34   *   *
35     *      24.02.2002      #def BFRAMES compatibility
36   *      26.02.2001      fixed dec_csp bugs   *      26.02.2001      fixed dec_csp bugs
37   *      26.12.2001      xvid_init() support   *      26.12.2001      xvid_init() support
38   *      22.12.2001      removed some compiler warnings   *      22.12.2001      removed some compiler warnings
39   *      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>
40   *   *
41     *  $Id$
42     *
43   *************************************************************************/   *************************************************************************/
44    
45    #include <stdlib.h>
46  #include <malloc.h>  #include <string.h>
47  #include <string.h>     // memset  #include <stdio.h>
48    
49  #include "xvid.h"  #include "xvid.h"
50  #include "divx4.h"  #include "divx4.h"
# Line 50  Line 53 
53    
54  #define EMULATED_DIVX_VERSION 20011001  #define EMULATED_DIVX_VERSION 20011001
55    
56  // decore  /**************************************************************************
57     * Divx Instance Structure
58     *
59     * This chain list datatype allows XviD do instanciate multiples divx4
60     * sessions.
61     *
62     * ToDo : The way this chain list is used does not guarantee reentrance
63     *        because they are not protected by any kind of mutex to allow
64     *        only one modifier. We should add a mutex for each element in
65     *        the chainlist.
66     *************************************************************************/
67    
68    
69  typedef struct DINST  typedef struct DINST
# Line 61  Line 74 
74          void * handle;          void * handle;
75          XVID_DEC_FRAME xframe;          XVID_DEC_FRAME xframe;
76    
77  } DINST;  }
78    DINST;
79    
80    typedef struct EINST
81    {
82            struct EINST *next;
83    
84  static DINST * dhead = NULL;          void *handle;
85            int quality;
86    
87    }
88    EINST;
89    
90  DINST * dinst_find(unsigned long key)  /**************************************************************************
91  {   * Global data (needed to emulate correctly exported symbols from divx4)
92          DINST * dcur = dhead;   *************************************************************************/
93    
94          while (dcur)  /* This is not used in this module but is required by some divx4 encoders*/
95          {  int quiet_encore = 1;
                 if (dcur->key == key)  
                 {  
                         return dcur;  
                 }  
                 dcur = dcur->next;  
         }  
96    
97          return NULL;  /**************************************************************************
98  }   * Local data
99     *************************************************************************/
100    
101    /* The Divx4 instance chainlist */
102    static DINST *dhead = NULL;
103    static EINST *ehead = NULL;
104    
105  DINST * dinst_add(unsigned long key)  /* Divx4 quality to XviD encoder motion flag presets */
106  {  static int const divx4_motion_presets[7] = {
107          DINST * dnext = dhead;          0,
108    
109          dhead = malloc(sizeof(DINST));          PMV_EARLYSTOP16,
         if (dhead == NULL)  
         {  
                 dhead = dnext;  
                 return NULL;  
         }  
110    
111          dhead->key = key;          PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16,
         dhead->next = dnext;  
112    
113          return dhead;          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
 }  
114    
115            PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
116                    PMV_HALFPELREFINE8,
117    
118  void dinst_remove(unsigned long key)          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
119  {                  PMV_HALFPELREFINE8,
         DINST * dcur = dhead;  
120    
121          if (dhead == NULL)          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 |
122          {                  PMV_HALFPELREFINE8
123                  return;  };
         }  
124    
         if (dcur->key == key)  
         {  
                 dhead = dcur->next;  
                 free(dcur);  
                 return;  
         }  
125    
126          while (dcur->next)  /* Divx4 quality to general encoder flag presets */
127          {  static int const divx4_general_presets[7] = {
128                  if (dcur->next->key == key)          0,
129                  {          XVID_H263QUANT,
130                          DINST * tmp = dcur->next;          XVID_H263QUANT,
131                          dcur->next = tmp->next;          XVID_H263QUANT | XVID_HALFPEL,
132                          free(tmp);          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
133                          return;          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
134                  }          XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
135                  dcur = dcur->next;  };
         }  
 }  
136    
137    /**************************************************************************
138     * Local Prototypes
139     *************************************************************************/
140    
141  int xvid_to_opendivx_dec_csp(int csp)  /* Chain list helper functions */
142  {  static DINST *dinst_find(unsigned long key);
143          switch(csp)  static DINST *dinst_add(unsigned long key);
144          {  static void dinst_remove(unsigned long key);
145          case DEC_YV12 :  
146                  return XVID_CSP_YV12;  static EINST *einst_find(void *handle);
147          case DEC_420 :  static EINST *einst_add(void *handle);
148                  return XVID_CSP_I420;  static void einst_remove(void *handle);
149          case DEC_YUY2 :  
150                  return XVID_CSP_YUY2;  /* Converts divx4 colorspaces codes to xvid codes */
151          case DEC_UYVY :  static int xvid_to_opendivx_dec_csp(int csp);
152                  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;  
         }  
 }  
153    
154    /**************************************************************************
155     * decore part
156     *
157     * decore is the divx4 entry point used to decompress the mpeg4 bitstream
158     * into a user defined image format.
159     *************************************************************************/
160    
161  int decore(unsigned long key, unsigned long opt,  int
162                                          void * param1, void * param2)  decore(unsigned long key,
163               unsigned long opt,
164               void *param1,
165               void *param2)
166  {  {
167    
168          int xerr;          int xerr;
169    
170          switch (opt)          switch (opt) {
171          {  
172          case DEC_OPT_MEMORY_REQS :          case DEC_OPT_MEMORY_REQS :
173                  {                  {
174                          memset(param2, 0, sizeof(DEC_MEM_REQS));                          memset(param2, 0, sizeof(DEC_MEM_REQS));
# Line 183  Line 177 
177    
178          case DEC_OPT_INIT :          case DEC_OPT_INIT :
179                  {                  {
                         DEC_PARAM * dparam = (DEC_PARAM *)param1;  
180                          XVID_INIT_PARAM xinit;                          XVID_INIT_PARAM xinit;
181                          XVID_DEC_PARAM xparam;                          XVID_DEC_PARAM xparam;
182                          DINST * dcur = dinst_find(key);                          DINST *dcur;
183                          if (dcur == NULL)                          DEC_PARAM *dparam = (DEC_PARAM *) param1;
184                          {  
185                            /* Find the divx4 instance */
186                            if ((dcur = dinst_find(key)) == NULL) {
187                                  dcur = dinst_add(key);                                  dcur = dinst_add(key);
188                          }                          }
189    
190                            /*
191                             * XviD initialization
192                             * XviD will detect the host cpu type and activate optimized
193                             * functions according to the host cpu features.
194                             */
195                          xinit.cpu_flags = 0;                          xinit.cpu_flags = 0;
196                          xvid_init(NULL, 0, &xinit, NULL);                          xvid_init(NULL, 0, &xinit, NULL);
197    
198                            /* XviD decoder initialization for this instance */
199                          xparam.width = dparam->x_dim;                          xparam.width = dparam->x_dim;
200                          xparam.height = dparam->y_dim;                          xparam.height = dparam->y_dim;
201                          dcur->xframe.colorspace = xvid_to_opendivx_dec_csp(dparam->output_format);                          dcur->xframe.colorspace =
202                                    xvid_to_opendivx_dec_csp(dparam->output_format);
203    
204                          xerr = decoder_create(&xparam);                          xerr = decoder_create(&xparam);
205    
206                            /* Store the xvid handle into the divx4 instance chainlist */
207                          dcur->handle = xparam.handle;                          dcur->handle = xparam.handle;
208    
209                          break;                          break;
# Line 208  Line 211 
211    
212          case DEC_OPT_RELEASE :          case DEC_OPT_RELEASE :
213                  {                  {
214                          DINST * dcur = dinst_find(key);                          DINST *dcur;
215                          if (dcur == NULL)  
216                          {                          /* Find the divx4 instance into the chain list */
217                            if ((dcur = dinst_find(key)) == NULL) {
218                                  return DEC_EXIT;                                  return DEC_EXIT;
219                          }                          }
220    
221                            /* Destroy the XviD decoder attached to this divx4 instance */
222                          xerr = decoder_destroy(dcur->handle);                          xerr = decoder_destroy(dcur->handle);
223    
224                            /* Remove the divx4 instance from the chainlist */
225                          dinst_remove(key);                          dinst_remove(key);
226    
227                          break;                          break;
# Line 223  Line 229 
229    
230          case DEC_OPT_SETPP :          case DEC_OPT_SETPP :
231                  {                  {
232                          // DEC_SET * dset = (DEC_SET *)param1;                          DINST *dcur;
233                          DINST * dcur = dinst_find(key);  
234                          if (dcur == NULL)                          /* Find the divx4 instance into the chain list */
235                          {                          if ((dcur = dinst_find(key)) == NULL) {
236                                  return DEC_EXIT;                                  return DEC_EXIT;
237                          }                          }
238    
239                          // dcur->xframe.pp = dset->postproc_level;                          /*
240                             * We return DEC_OK but XviD has no postprocessing implemented
241                             * in core.
242                             */
243                          return DEC_OK;                          return DEC_OK;
244                  }                  }
245    
246          case DEC_OPT_SETOUT :          case DEC_OPT_SETOUT :
247                  {                  {
248                            DINST *dcur;
249                          DEC_PARAM * dparam = (DEC_PARAM *)param1;                          DEC_PARAM * dparam = (DEC_PARAM *)param1;
250                          DINST * dcur = dinst_find(key);  
251                          if (dcur == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                         {  
252                                  return DEC_EXIT;                                  return DEC_EXIT;
253                          }                          }
254    
255                          dcur->xframe.colorspace = xvid_to_opendivx_dec_csp(dparam->output_format);                          /* Change the output colorspace */
256                            dcur->xframe.colorspace =
257                                    xvid_to_opendivx_dec_csp(dparam->output_format);
258    
259                          return DEC_OK;                          return DEC_OK;
260                  }                  }
# Line 252  Line 262 
262          case DEC_OPT_FRAME:          case DEC_OPT_FRAME:
263                  {                  {
264                          int csp_tmp = 0;                          int csp_tmp = 0;
265                            DINST *dcur;
266                          DEC_FRAME * dframe = (DEC_FRAME *)param1;                          DEC_FRAME * dframe = (DEC_FRAME *)param1;
267                          DINST * dcur = dinst_find(key);  
268                          if (dcur == NULL)                          if ((dcur = dinst_find(key)) == NULL) {
                         {  
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                          if (!dframe->render_flag)                          /* Does the frame need to be skipped ? */
279                          {                          if (!dframe->render_flag) {
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                          if (!dframe->render_flag)                          /* Restore the real colorspace for this instance */
293                          {                          if (!dframe->render_flag) {
294                                  dcur->xframe.colorspace = csp_tmp;                                  dcur->xframe.colorspace = csp_tmp;
295                          }                          }
296    
297                          break;                          break;
298                  }                  }
299    
   
300          case DEC_OPT_FRAME_311 :          case DEC_OPT_FRAME_311 :
301                    /* XviD does not handle Divx ;-) 3.11 yet */
302                  return DEC_EXIT;                  return DEC_EXIT;
303    
   
304          case DEC_OPT_VERSION:          case DEC_OPT_VERSION:
305                  return EMULATED_DIVX_VERSION;                  return EMULATED_DIVX_VERSION;
306    
307          default :          default :
308                  return DEC_EXIT;                  return DEC_EXIT;
309          }          }
310    
311    
312          switch(xerr)          /* XviD error code -> Divx4 */
313          {          switch (xerr) {
314          case XVID_ERR_OK : return DEC_OK;          case XVID_ERR_OK:
315          case XVID_ERR_MEMORY : return DEC_MEMORY;                  return DEC_OK;
316          case XVID_ERR_FORMAT : return DEC_BAD_FORMAT;          case XVID_ERR_MEMORY:
317          default : // case XVID_ERR_FAIL :                  return DEC_MEMORY;
318            case XVID_ERR_FORMAT:
319                    return DEC_BAD_FORMAT;
320            default:
321                  return DEC_EXIT;                  return DEC_EXIT;
322          }          }
323  }  }
324    
325    /**************************************************************************
326     * Encore Part
327     *
328  // encore   * encore is the divx4 entry point used to compress a frame to a mpeg4
329     * bitstream.
330     *************************************************************************/
331    
332  #define FRAMERATE_INCR          1001  #define FRAMERATE_INCR          1001
333    
334  int divx4_motion_presets[7] = {  int
335          0, PMV_QUICKSTOP16, PMV_EARLYSTOP16, PMV_EARLYSTOP16 | PMV_EARLYSTOP8,  encore(void *handle,
336          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8,             int opt,
337          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8,             void *param1,
338          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 |             void *param2)
         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) {
                         {  
359                                  xparam.fincr = 1;                                  xparam.fincr = 1;
360                                  xparam.fbase = (int)eparam->framerate;                                  xparam.fbase = (int)eparam->framerate;
361                          }                          } else {
                         else  
                         {  
362                                  xparam.fincr = FRAMERATE_INCR;                                  xparam.fincr = FRAMERATE_INCR;
363                                  xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);                                  xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate);
364                          }                          }
365                          xparam.bitrate = eparam->bitrate;                          xparam.rc_bitrate = eparam->bitrate;
366                          xparam.rc_buffersize = 10 * eparam->bitrate;                          xparam.rc_reaction_delay_factor = 16;
367                            xparam.rc_averaging_period = 100;
368                            xparam.rc_buffer = 100;
369                          xparam.min_quantizer = eparam->min_quantizer;                          xparam.min_quantizer = eparam->min_quantizer;
370                          xparam.max_quantizer = eparam->max_quantizer;                          xparam.max_quantizer = eparam->max_quantizer;
371                          xparam.max_key_interval = eparam->max_key_interval;                          xparam.max_key_interval = eparam->max_key_interval;
                         quality = eparam->quality;  
372    
373                            /* Create the encoder session */
374                          xerr = encoder_create(&xparam);                          xerr = encoder_create(&xparam);
375    
376                          eparam->handle = xparam.handle;                          eparam->handle = xparam.handle;
377    
378                            /* Create an encoder instance in the chainlist */
379                            if ((ecur = einst_find(xparam.handle)) == NULL) {
380                                    ecur = einst_add(xparam.handle);
381    
382                                    if (ecur == NULL) {
383                                            encoder_destroy((Encoder *) xparam.handle);
384                                            return ENC_MEMORY;
385                                    }
386    
387                            }
388    
389                            ecur->quality = eparam->quality;
390                            if (ecur->quality < 0)
391                                    ecur->quality = 0;
392                            if (ecur->quality > 6)
393                                    ecur->quality = 6;
394    
395                          break;                          break;
396                  }                  }
397    
398          case ENC_OPT_RELEASE :          case ENC_OPT_RELEASE :
399                  {                  {
400                            EINST *ecur;
401    
402                            if ((ecur = einst_find(handle)) == NULL) {
403                                    return ENC_FAIL;
404                            }
405    
406                            einst_remove(handle);
407                          xerr = encoder_destroy((Encoder *) handle);                          xerr = encoder_destroy((Encoder *) handle);
408    
409                          break;                          break;
410                  }                  }
411    
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                                    return ENC_FAIL;
424                            }
425    
426                            /* Copy the divx4 info into the xvid structure */
427                          xframe.bitstream = eframe->bitstream;                          xframe.bitstream = eframe->bitstream;
428                          xframe.length = eframe->length;                          xframe.length = eframe->length;
429                            xframe.motion = divx4_motion_presets[ecur->quality];
430                          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];  
431    
432                          xframe.image = eframe->image;                          xframe.image = eframe->image;
433                          switch (eframe->colorspace)                          xframe.colorspace = 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;  
                         }  
434    
435                          if (opt == ENC_OPT_ENCODE_VBR)                          if (opt == ENC_OPT_ENCODE_VBR) {
                         {  
436                                  xframe.intra = eframe->intra;                                  xframe.intra = eframe->intra;
437                                  xframe.quant = eframe->quant;                                  xframe.quant = eframe->quant;
438                          }                          } else {
                         else  
                         {  
439                                  xframe.intra = -1;                                  xframe.intra = -1;
440                                  xframe.quant = 0;                                  xframe.quant = 0;
441                          }                          }
442    
443                          xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) );                          /* Encode the frame */
444                            xerr =
445                                    encoder_encode((Encoder *) handle, &xframe,
446                                                               (eresult ? &xstats : NULL));
447    
448                          if (eresult)                          /* Copy back the xvid structure to the divx4 one */
449                          {                          if (eresult) {
450                                  eresult->is_key_frame = xframe.intra;                                  eresult->is_key_frame = xframe.intra;
451                                  eresult->quantizer = xstats.quant;                                  eresult->quantizer = xstats.quant;
452                                  eresult->total_bits = xframe.length * 8;                                  eresult->total_bits = xframe.length * 8;
453                                  eresult->motion_bits = xstats.hlength * 8;                                  eresult->motion_bits = xstats.hlength * 8;
454                                  eresult->texture_bits = eresult->total_bits - eresult->motion_bits;                                  eresult->texture_bits =
455                                            eresult->total_bits - eresult->motion_bits;
456                          }                          }
457    
458                          eframe->length = xframe.length;                          eframe->length = xframe.length;
# Line 436  Line 464 
464                  return ENC_FAIL;                  return ENC_FAIL;
465          }          }
466    
467          switch(xerr)          /* XviD Error code  -> Divx4 error code */
468          {          switch (xerr) {
469          case XVID_ERR_OK : return ENC_OK;          case XVID_ERR_OK:
470          case XVID_ERR_MEMORY : return ENC_MEMORY;                  return ENC_OK;
471          case XVID_ERR_FORMAT : return ENC_BAD_FORMAT;          case XVID_ERR_MEMORY:
472          default : // case XVID_ERR_FAIL :                  return ENC_MEMORY;
473            case XVID_ERR_FORMAT:
474                    return ENC_BAD_FORMAT;
475            default:
476                  return ENC_FAIL;                  return ENC_FAIL;
477          }          }
478  }  }
479    
480    /**************************************************************************
481     * Local Functions
482     *************************************************************************/
483    
484    /***************************************
485     * DINST chainlist helper functions    *
486     ***************************************/
487    
488    /* Find an element in the chainlist according to its key value */
489    static DINST *
490    dinst_find(unsigned long key)
491    {
492            DINST *dcur = dhead;
493    
494            while (dcur) {
495                    if (dcur->key == key) {
496                            return dcur;
497                    }
498                    dcur = dcur->next;
499            }
500    
501            return NULL;
502    }
503    
504    
505    /* Add an element to the chainlist */
506    static DINST *
507    dinst_add(unsigned long key)
508    {
509            DINST *dnext = dhead;
510    
511            dhead = malloc(sizeof(DINST));
512            if (dhead == NULL) {
513                    dhead = dnext;
514                    return NULL;
515            }
516    
517            dhead->key = key;
518            dhead->next = dnext;
519    
520            return dhead;
521    }
522    
523    
524    /* Remove an elmement from the chainlist */
525    static void
526    dinst_remove(unsigned long key)
527    {
528            DINST *dcur = dhead;
529    
530            if (dhead == NULL) {
531                    return;
532            }
533    
534            if (dcur->key == key) {
535                    dhead = dcur->next;
536                    free(dcur);
537                    return;
538            }
539    
540            while (dcur->next) {
541                    if (dcur->next->key == key) {
542                            DINST *tmp = dcur->next;
543    
544                            dcur->next = tmp->next;
545                            free(tmp);
546                            return;
547                    }
548                    dcur = dcur->next;
549            }
550    }
551    
552    
553    /***************************************
554     * EINST chainlist helper functions    *
555     ***************************************/
556    
557    /* Find an element in the chainlist according to its handle */
558    static EINST *
559    einst_find(void *handle)
560    {
561            EINST *ecur = ehead;
562    
563            while (ecur) {
564                    if (ecur->handle == handle) {
565                            return ecur;
566                    }
567                    ecur = ecur->next;
568            }
569    
570            return NULL;
571    }
572    
573    
574    /* Add an element to the chainlist */
575    static EINST *
576    einst_add(void *handle)
577    {
578            EINST *enext = ehead;
579    
580            ehead = malloc(sizeof(EINST));
581            if (ehead == NULL) {
582                    ehead = enext;
583                    return NULL;
584            }
585    
586            ehead->handle = handle;
587            ehead->next = enext;
588    
589            return ehead;
590    }
591    
592    
593    /* Remove an elmement from the chainlist */
594    static void
595    einst_remove(void *handle)
596    {
597            EINST *ecur = ehead;
598    
599            if (ehead == NULL) {
600                    return;
601            }
602    
603            if (ecur->handle == handle) {
604                    ehead = ecur->next;
605                    free(ecur);
606                    return;
607            }
608    
609            while (ecur->next) {
610                    if (ecur->next->handle == handle) {
611                            EINST *tmp = ecur->next;
612    
613                            ecur->next = tmp->next;
614                            free(tmp);
615                            return;
616                    }
617                    ecur = ecur->next;
618            }
619    }
620    
621    /***************************************
622     * Colorspace code converter           *
623     ***************************************/
624    
625    static int
626    xvid_to_opendivx_dec_csp(int csp)
627    {
628    
629            switch (csp) {
630            case DEC_YV12:
631                    return XVID_CSP_YV12;
632            case DEC_420:
633                    return XVID_CSP_I420;
634            case DEC_YUY2:
635                    return XVID_CSP_YUY2;
636            case DEC_UYVY:
637                    return XVID_CSP_UYVY;
638            case DEC_RGB32:
639                    return XVID_CSP_VFLIP | XVID_CSP_RGB32;
640            case DEC_RGB24:
641                    return XVID_CSP_VFLIP | XVID_CSP_RGB24;
642            case DEC_RGB565:
643                    return XVID_CSP_VFLIP | XVID_CSP_RGB565;
644            case DEC_RGB555:
645                    return XVID_CSP_VFLIP | XVID_CSP_RGB555;
646            case DEC_RGB32_INV:
647                    return XVID_CSP_RGB32;
648            case DEC_RGB24_INV:
649                    return XVID_CSP_RGB24;
650            case DEC_RGB565_INV:
651                    return XVID_CSP_RGB565;
652            case DEC_RGB555_INV:
653                    return XVID_CSP_RGB555;
654            case DEC_USER:
655                    return XVID_CSP_USER;
656            default:
657                    return -1;
658            }
659    }
660    
661    static int
662    xvid_to_opendivx_enc_csp(int csp)
663    {
664    
665            switch (csp) {
666            case ENC_CSP_RGB24:
667                    return XVID_CSP_VFLIP | XVID_CSP_RGB24;
668            case ENC_CSP_YV12:
669                    return XVID_CSP_YV12;
670            case ENC_CSP_YUY2:
671                    return XVID_CSP_YUY2;
672            case ENC_CSP_UYVY:
673                    return XVID_CSP_UYVY;
674            case ENC_CSP_I420:
675                    return XVID_CSP_I420;
676            default:
677                    return -1;
678            }
679    }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.17

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