[svn] / trunk / xvidcore / src / divx4.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/divx4.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 648 - (view) (download)

1 : Isibaar 3 /**************************************************************************
2 :     *
3 : edgomez 193 * XVID MPEG-4 VIDEO CODEC
4 :     * - OpenDivx API wrapper -
5 : Isibaar 3 *
6 : suxen_drol 499 * Copyright(C) 2001-2002 Peter Ross <pross@xvid.org>
7 : edgomez 398 *
8 : edgomez 648 * This file is part of XviD, a free MPEG-4 video encoder/decoder
9 : Isibaar 3 *
10 : edgomez 648 * XviD is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by
12 : edgomez 193 * the Free Software Foundation; either version 2 of the License, or
13 :     * (at your option) any later version.
14 : Isibaar 3 *
15 : edgomez 193 * This program is distributed in the hope that it will be useful,
16 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     * GNU General Public License for more details.
19 : Isibaar 3 *
20 : edgomez 193 * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software
22 : edgomez 648 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 : Isibaar 3 *
24 : edgomez 648 * Under section 8 of the GNU General Public License, the copyright
25 :     * holders of XVID explicitly forbid distribution in the following
26 :     * countries:
27 :     *
28 :     * - Japan
29 :     * - United States of America
30 :     *
31 :     * Linking XviD statically or dynamically with other modules is making a
32 :     * combined work based on XviD. Thus, the terms and conditions of the
33 :     * GNU General Public License cover the whole combination.
34 :     *
35 :     * As a special exception, the copyright holders of XviD give you
36 :     * permission to link XviD with independent modules that communicate with
37 :     * XviD solely through the VFW1.1 and DShow interfaces, regardless of the
38 :     * license terms of these independent modules, and to copy and distribute
39 :     * the resulting combined work under terms of your choice, provided that
40 :     * every copy of the combined work is accompanied by a complete copy of
41 :     * the source code of XviD (the version of XviD used to produce the
42 :     * combined work), being distributed under the terms of the GNU General
43 :     * Public License plus this exception. An independent module is a module
44 :     * which is not derived from or based on XviD.
45 :     *
46 :     * Note that people who make modified versions of XviD are not obligated
47 :     * to grant this special exception for their modified versions; it is
48 :     * their choice whether to do so. The GNU General Public License gives
49 :     * permission to release a modified version without this exception; this
50 :     * exception also makes it possible to release a modified version which
51 :     * carries forward this exception.
52 :     *
53 :     * $Id: divx4.c,v 1.20 2002-11-16 23:38:16 edgomez Exp $
54 :     *
55 : Isibaar 3 *************************************************************************/
56 :    
57 : knhor 129 #include <stdlib.h>
58 : edgomez 143 #include <string.h>
59 : edgomez 159 #include <stdio.h>
60 : Isibaar 3
61 :     #include "xvid.h"
62 :     #include "divx4.h"
63 :     #include "decoder.h"
64 :     #include "encoder.h"
65 :    
66 :     #define EMULATED_DIVX_VERSION 20011001
67 :    
68 : edgomez 143 /**************************************************************************
69 :     * Divx Instance Structure
70 :     *
71 :     * This chain list datatype allows XviD do instanciate multiples divx4
72 :     * sessions.
73 :     *
74 :     * ToDo : The way this chain list is used does not guarantee reentrance
75 :     * because they are not protected by any kind of mutex to allow
76 :     * only one modifier. We should add a mutex for each element in
77 :     * the chainlist.
78 :     *************************************************************************/
79 : Isibaar 3
80 :    
81 :     typedef struct DINST
82 :     {
83 :     unsigned long key;
84 : edgomez 195 struct DINST *next;
85 : Isibaar 3
86 : edgomez 195 void *handle;
87 : Isibaar 3 XVID_DEC_FRAME xframe;
88 :    
89 : edgomez 195 }
90 :     DINST;
91 : Isibaar 3
92 : edgomez 159 typedef struct EINST
93 :     {
94 : edgomez 195 struct EINST *next;
95 : edgomez 159
96 : edgomez 195 void *handle;
97 : edgomez 159 int quality;
98 :    
99 : edgomez 195 }
100 :     EINST;
101 : edgomez 159
102 : edgomez 143 /**************************************************************************
103 :     * Global data (needed to emulate correctly exported symbols from divx4)
104 :     *************************************************************************/
105 : Isibaar 3
106 : edgomez 143 /* This is not used in this module but is required by some divx4 encoders*/
107 :     int quiet_encore = 1;
108 : Isibaar 3
109 : edgomez 143 /**************************************************************************
110 :     * Local data
111 :     *************************************************************************/
112 : Isibaar 3
113 : edgomez 143 /* The Divx4 instance chainlist */
114 : edgomez 195 static DINST *dhead = NULL;
115 :     static EINST *ehead = NULL;
116 : Isibaar 3
117 : edgomez 143 /* Divx4 quality to XviD encoder motion flag presets */
118 :     static int const divx4_motion_presets[7] = {
119 : edgomez 195 0,
120 : Isibaar 3
121 : edgomez 195 PMV_EARLYSTOP16,
122 : Isibaar 3
123 : chl 180 PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16,
124 :    
125 : edgomez 143 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
126 : Isibaar 3
127 : edgomez 195 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
128 :     PMV_HALFPELREFINE8,
129 : Isibaar 3
130 : edgomez 195 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
131 :     PMV_HALFPELREFINE8,
132 : Isibaar 3
133 : edgomez 195 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 |
134 :     PMV_HALFPELREFINE8
135 : edgomez 143 };
136 : Isibaar 3
137 :    
138 : edgomez 143 /* Divx4 quality to general encoder flag presets */
139 :     static int const divx4_general_presets[7] = {
140 : edgomez 195 0,
141 : edgomez 143 XVID_H263QUANT,
142 : edgomez 195 XVID_H263QUANT,
143 : edgomez 143 XVID_H263QUANT | XVID_HALFPEL,
144 :     XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
145 : edgomez 195 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
146 : edgomez 143 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
147 :     };
148 : Isibaar 3
149 : edgomez 143 /**************************************************************************
150 :     * Local Prototypes
151 :     *************************************************************************/
152 : Isibaar 3
153 : edgomez 143 /* Chain list helper functions */
154 : edgomez 195 static DINST *dinst_find(unsigned long key);
155 :     static DINST *dinst_add(unsigned long key);
156 :     static void dinst_remove(unsigned long key);
157 : Isibaar 3
158 : edgomez 195 static EINST *einst_find(void *handle);
159 :     static EINST *einst_add(void *handle);
160 :     static void einst_remove(void *handle);
161 : edgomez 159
162 : edgomez 143 /* Converts divx4 colorspaces codes to xvid codes */
163 :     static int xvid_to_opendivx_dec_csp(int csp);
164 :     static int xvid_to_opendivx_enc_csp(int csp);
165 : Isibaar 3
166 : edgomez 143 /**************************************************************************
167 :     * decore part
168 :     *
169 :     * decore is the divx4 entry point used to decompress the mpeg4 bitstream
170 :     * into a user defined image format.
171 :     *************************************************************************/
172 : Isibaar 3
173 : edgomez 143 int
174 : edgomez 195 decore(unsigned long key,
175 :     unsigned long opt,
176 :     void *param1,
177 :     void *param2)
178 : Isibaar 3 {
179 : edgomez 143
180 : Isibaar 3 int xerr;
181 :    
182 : edgomez 143 switch (opt) {
183 :    
184 : edgomez 195 case DEC_OPT_MEMORY_REQS:
185 : Isibaar 3 {
186 : edgomez 195 memset(param2, 0, sizeof(DEC_MEM_REQS));
187 :     return DEC_OK;
188 : Isibaar 3 }
189 :    
190 : edgomez 195 case DEC_OPT_INIT:
191 :     {
192 :     XVID_INIT_PARAM xinit;
193 :     XVID_DEC_PARAM xparam;
194 :     DINST *dcur;
195 :     DEC_PARAM *dparam = (DEC_PARAM *) param1;
196 : Isibaar 3
197 : edgomez 195 /* Find the divx4 instance */
198 :     if ((dcur = dinst_find(key)) == NULL) {
199 :     dcur = dinst_add(key);
200 :     }
201 : Isibaar 3
202 : edgomez 195 /*
203 :     * XviD initialization
204 :     * XviD will detect the host cpu type and activate optimized
205 :     * functions according to the host cpu features.
206 :     */
207 :     xinit.cpu_flags = 0;
208 :     xvid_init(NULL, 0, &xinit, NULL);
209 : Isibaar 3
210 : edgomez 195 /* XviD decoder initialization for this instance */
211 :     xparam.width = dparam->x_dim;
212 :     xparam.height = dparam->y_dim;
213 :     dcur->xframe.colorspace =
214 :     xvid_to_opendivx_dec_csp(dparam->output_format);
215 : edgomez 143
216 : edgomez 195 xerr = decoder_create(&xparam);
217 : Isibaar 3
218 : edgomez 195 /* Store the xvid handle into the divx4 instance chainlist */
219 :     dcur->handle = xparam.handle;
220 : Isibaar 3
221 : edgomez 195 break;
222 : edgomez 143 }
223 : Isibaar 3
224 : edgomez 195 case DEC_OPT_RELEASE:
225 : Isibaar 3 {
226 : edgomez 195 DINST *dcur;
227 : Isibaar 3
228 : edgomez 195 /* Find the divx4 instance into the chain list */
229 :     if ((dcur = dinst_find(key)) == NULL) {
230 :     return DEC_EXIT;
231 :     }
232 : Isibaar 3
233 : edgomez 195 /* Destroy the XviD decoder attached to this divx4 instance */
234 :     xerr = decoder_destroy(dcur->handle);
235 : edgomez 143
236 : edgomez 195 /* Remove the divx4 instance from the chainlist */
237 :     dinst_remove(key);
238 :    
239 :     break;
240 : edgomez 143 }
241 : edgomez 19
242 : edgomez 195 case DEC_OPT_SETPP:
243 : edgomez 143 {
244 : edgomez 195 DINST *dcur;
245 :    
246 :     /* Find the divx4 instance into the chain list */
247 :     if ((dcur = dinst_find(key)) == NULL) {
248 :     return DEC_EXIT;
249 :     }
250 :    
251 : edgomez 143 /*
252 : edgomez 195 * We return DEC_OK but XviD has no postprocessing implemented
253 :     * in core.
254 : edgomez 143 */
255 : edgomez 195 return DEC_OK;
256 : edgomez 143 }
257 : Isibaar 3
258 : edgomez 195 case DEC_OPT_SETOUT:
259 : edgomez 143 {
260 : edgomez 195 DINST *dcur;
261 :     DEC_PARAM *dparam = (DEC_PARAM *) param1;
262 :    
263 :     if ((dcur = dinst_find(key)) == NULL) {
264 :     return DEC_EXIT;
265 :     }
266 :    
267 :     /* Change the output colorspace */
268 :     dcur->xframe.colorspace =
269 :     xvid_to_opendivx_dec_csp(dparam->output_format);
270 :    
271 :     return DEC_OK;
272 : Isibaar 3 }
273 :    
274 : edgomez 195 case DEC_OPT_FRAME:
275 :     {
276 :     int csp_tmp = 0;
277 :     DINST *dcur;
278 :     DEC_FRAME *dframe = (DEC_FRAME *) param1;
279 : Isibaar 3
280 : edgomez 195 if ((dcur = dinst_find(key)) == NULL) {
281 :     return DEC_EXIT;
282 :     }
283 :    
284 :     /* Copy the divx4 fields to the XviD decoder structure */
285 :     dcur->xframe.bitstream = dframe->bitstream;
286 :     dcur->xframe.length = dframe->length;
287 :     dcur->xframe.image = dframe->bmp;
288 :     dcur->xframe.stride = dframe->stride;
289 :    
290 :     /* Does the frame need to be skipped ? */
291 :     if (!dframe->render_flag) {
292 :     /*
293 :     * Then we use the null colorspace to force XviD to
294 :     * skip the frame. The original colorspace will be
295 :     * restored after the decoder call
296 :     */
297 :     csp_tmp = dcur->xframe.colorspace;
298 :     dcur->xframe.colorspace = XVID_CSP_NULL;
299 :     }
300 :    
301 :     /* Decode the bitstream */
302 :     xerr = decoder_decode(dcur->handle, &dcur->xframe);
303 :    
304 :     /* Restore the real colorspace for this instance */
305 :     if (!dframe->render_flag) {
306 :     dcur->xframe.colorspace = csp_tmp;
307 :     }
308 :    
309 :     break;
310 :     }
311 :    
312 :     case DEC_OPT_FRAME_311:
313 : edgomez 143 /* XviD does not handle Divx ;-) 3.11 yet */
314 : Isibaar 3 return DEC_EXIT;
315 :    
316 :     case DEC_OPT_VERSION:
317 :     return EMULATED_DIVX_VERSION;
318 : edgomez 143
319 : edgomez 195 default:
320 : Isibaar 3 return DEC_EXIT;
321 :     }
322 :    
323 :    
324 : edgomez 143 /* XviD error code -> Divx4 */
325 : edgomez 195 switch (xerr) {
326 :     case XVID_ERR_OK:
327 : edgomez 143 return DEC_OK;
328 : edgomez 195 case XVID_ERR_MEMORY:
329 : edgomez 143 return DEC_MEMORY;
330 : edgomez 195 case XVID_ERR_FORMAT:
331 : edgomez 143 return DEC_BAD_FORMAT;
332 : edgomez 195 default:
333 : Isibaar 3 return DEC_EXIT;
334 :     }
335 :     }
336 :    
337 : edgomez 143 /**************************************************************************
338 :     * Encore Part
339 :     *
340 :     * encore is the divx4 entry point used to compress a frame to a mpeg4
341 :     * bitstream.
342 :     *************************************************************************/
343 : Isibaar 3
344 :     #define FRAMERATE_INCR 1001
345 :    
346 : edgomez 143 int
347 : edgomez 195 encore(void *handle,
348 :     int opt,
349 :     void *param1,
350 :     void *param2)
351 : edgomez 143 {
352 : Isibaar 9
353 : Isibaar 3 int xerr;
354 :    
355 : edgomez 195 switch (opt) {
356 :     case ENC_OPT_INIT:
357 : edgomez 143 {
358 : edgomez 195 EINST *ecur;
359 :     ENC_PARAM *eparam = (ENC_PARAM *) param1;
360 :     XVID_INIT_PARAM xinit;
361 :     XVID_ENC_PARAM xparam;
362 : Isibaar 3
363 : edgomez 195 /* Init XviD which will detect host cpu features */
364 :     xinit.cpu_flags = 0;
365 :     xvid_init(NULL, 0, &xinit, NULL);
366 : Isibaar 3
367 : edgomez 195 /* Settings are copied to the XviD encoder structure */
368 :     xparam.width = eparam->x_dim;
369 :     xparam.height = eparam->y_dim;
370 :     if ((eparam->framerate - (int) eparam->framerate) == 0) {
371 :     xparam.fincr = 1;
372 :     xparam.fbase = (int) eparam->framerate;
373 :     } else {
374 :     xparam.fincr = FRAMERATE_INCR;
375 :     xparam.fbase = (int) (FRAMERATE_INCR * eparam->framerate);
376 :     }
377 :     xparam.rc_bitrate = eparam->bitrate;
378 :     xparam.rc_reaction_delay_factor = 16;
379 :     xparam.rc_averaging_period = 100;
380 :     xparam.rc_buffer = 100;
381 :     xparam.min_quantizer = eparam->min_quantizer;
382 :     xparam.max_quantizer = eparam->max_quantizer;
383 :     xparam.max_key_interval = eparam->max_key_interval;
384 : Isibaar 3
385 : edgomez 195 /* Create the encoder session */
386 :     xerr = encoder_create(&xparam);
387 : edgomez 159
388 : edgomez 195 eparam->handle = xparam.handle;
389 :    
390 :     /* Create an encoder instance in the chainlist */
391 :     if ((ecur = einst_find(xparam.handle)) == NULL) {
392 :     ecur = einst_add(xparam.handle);
393 :    
394 :     if (ecur == NULL) {
395 :     encoder_destroy((Encoder *) xparam.handle);
396 :     return ENC_MEMORY;
397 :     }
398 :    
399 : edgomez 159 }
400 :    
401 : edgomez 195 ecur->quality = eparam->quality;
402 :     if (ecur->quality < 0)
403 :     ecur->quality = 0;
404 :     if (ecur->quality > 6)
405 :     ecur->quality = 6;
406 :    
407 :     break;
408 : edgomez 159 }
409 :    
410 : edgomez 195 case ENC_OPT_RELEASE:
411 :     {
412 :     EINST *ecur;
413 : edgomez 159
414 : edgomez 195 if ((ecur = einst_find(handle)) == NULL) {
415 :     return ENC_FAIL;
416 :     }
417 : Isibaar 3
418 : edgomez 195 einst_remove(handle);
419 :     xerr = encoder_destroy((Encoder *) handle);
420 : edgomez 159
421 : edgomez 195 break;
422 : edgomez 159 }
423 :    
424 : edgomez 195 case ENC_OPT_ENCODE:
425 :     case ENC_OPT_ENCODE_VBR:
426 :     {
427 :     EINST *ecur;
428 : Isibaar 3
429 : edgomez 195 ENC_FRAME *eframe = (ENC_FRAME *) param1;
430 :     ENC_RESULT *eresult = (ENC_RESULT *) param2;
431 :     XVID_ENC_FRAME xframe;
432 :     XVID_ENC_STATS xstats;
433 : edgomez 159
434 : edgomez 195 if ((ecur = einst_find(handle)) == NULL) {
435 :     return ENC_FAIL;
436 :     }
437 : Isibaar 3
438 : edgomez 195 /* Copy the divx4 info into the xvid structure */
439 :     xframe.bitstream = eframe->bitstream;
440 :     xframe.length = eframe->length;
441 :     xframe.motion = divx4_motion_presets[ecur->quality];
442 :     xframe.general = divx4_general_presets[ecur->quality];
443 : edgomez 159
444 : edgomez 195 xframe.image = eframe->image;
445 :     xframe.colorspace = xvid_to_opendivx_enc_csp(eframe->colorspace);
446 : Isibaar 3
447 : edgomez 195 if (opt == ENC_OPT_ENCODE_VBR) {
448 :     xframe.intra = eframe->intra;
449 :     xframe.quant = eframe->quant;
450 :     } else {
451 :     xframe.intra = -1;
452 :     xframe.quant = 0;
453 :     }
454 : Isibaar 3
455 : edgomez 195 /* Encode the frame */
456 :     xerr =
457 :     encoder_encode((Encoder *) handle, &xframe,
458 :     (eresult ? &xstats : NULL));
459 : Isibaar 3
460 : edgomez 195 /* Copy back the xvid structure to the divx4 one */
461 :     if (eresult) {
462 :     eresult->is_key_frame = xframe.intra;
463 :     eresult->quantizer = xstats.quant;
464 :     eresult->total_bits = xframe.length * 8;
465 :     eresult->motion_bits = xstats.hlength * 8;
466 :     eresult->texture_bits =
467 :     eresult->total_bits - eresult->motion_bits;
468 :     }
469 : Isibaar 3
470 : edgomez 195 eframe->length = xframe.length;
471 : Isibaar 3
472 : edgomez 195 break;
473 :     }
474 : Isibaar 3
475 :     default:
476 :     return ENC_FAIL;
477 :     }
478 :    
479 : edgomez 143 /* XviD Error code -> Divx4 error code */
480 : edgomez 195 switch (xerr) {
481 :     case XVID_ERR_OK:
482 : edgomez 143 return ENC_OK;
483 : edgomez 195 case XVID_ERR_MEMORY:
484 : edgomez 143 return ENC_MEMORY;
485 : edgomez 195 case XVID_ERR_FORMAT:
486 : edgomez 143 return ENC_BAD_FORMAT;
487 : edgomez 195 default:
488 : Isibaar 3 return ENC_FAIL;
489 :     }
490 :     }
491 :    
492 : edgomez 143 /**************************************************************************
493 :     * Local Functions
494 :     *************************************************************************/
495 :    
496 :     /***************************************
497 :     * DINST chainlist helper functions *
498 :     ***************************************/
499 :    
500 :     /* Find an element in the chainlist according to its key value */
501 : edgomez 195 static DINST *
502 :     dinst_find(unsigned long key)
503 : edgomez 143 {
504 : edgomez 195 DINST *dcur = dhead;
505 : edgomez 143
506 : edgomez 195 while (dcur) {
507 :     if (dcur->key == key) {
508 : edgomez 143 return dcur;
509 :     }
510 :     dcur = dcur->next;
511 :     }
512 :    
513 :     return NULL;
514 :     }
515 :    
516 :    
517 :     /* Add an element to the chainlist */
518 : edgomez 195 static DINST *
519 :     dinst_add(unsigned long key)
520 : edgomez 143 {
521 : edgomez 195 DINST *dnext = dhead;
522 : edgomez 143
523 :     dhead = malloc(sizeof(DINST));
524 : edgomez 195 if (dhead == NULL) {
525 : edgomez 143 dhead = dnext;
526 :     return NULL;
527 :     }
528 :    
529 :     dhead->key = key;
530 :     dhead->next = dnext;
531 :    
532 :     return dhead;
533 :     }
534 :    
535 :    
536 :     /* Remove an elmement from the chainlist */
537 : edgomez 195 static void
538 :     dinst_remove(unsigned long key)
539 : edgomez 143 {
540 : edgomez 195 DINST *dcur = dhead;
541 : edgomez 143
542 : edgomez 195 if (dhead == NULL) {
543 : edgomez 143 return;
544 :     }
545 :    
546 : edgomez 195 if (dcur->key == key) {
547 : edgomez 143 dhead = dcur->next;
548 :     free(dcur);
549 :     return;
550 :     }
551 :    
552 : edgomez 195 while (dcur->next) {
553 :     if (dcur->next->key == key) {
554 :     DINST *tmp = dcur->next;
555 :    
556 : edgomez 143 dcur->next = tmp->next;
557 :     free(tmp);
558 :     return;
559 :     }
560 :     dcur = dcur->next;
561 :     }
562 :     }
563 :    
564 : edgomez 159
565 : edgomez 143 /***************************************
566 : edgomez 159 * EINST chainlist helper functions *
567 :     ***************************************/
568 :    
569 :     /* Find an element in the chainlist according to its handle */
570 : edgomez 195 static EINST *
571 :     einst_find(void *handle)
572 : edgomez 159 {
573 : edgomez 195 EINST *ecur = ehead;
574 : edgomez 159
575 : edgomez 195 while (ecur) {
576 :     if (ecur->handle == handle) {
577 : edgomez 159 return ecur;
578 :     }
579 :     ecur = ecur->next;
580 :     }
581 :    
582 :     return NULL;
583 :     }
584 :    
585 :    
586 :     /* Add an element to the chainlist */
587 : edgomez 195 static EINST *
588 :     einst_add(void *handle)
589 : edgomez 159 {
590 : edgomez 195 EINST *enext = ehead;
591 : edgomez 159
592 :     ehead = malloc(sizeof(EINST));
593 : edgomez 195 if (ehead == NULL) {
594 : edgomez 159 ehead = enext;
595 :     return NULL;
596 :     }
597 :    
598 :     ehead->handle = handle;
599 :     ehead->next = enext;
600 :    
601 :     return ehead;
602 :     }
603 :    
604 :    
605 :     /* Remove an elmement from the chainlist */
606 : edgomez 195 static void
607 :     einst_remove(void *handle)
608 : edgomez 159 {
609 : edgomez 195 EINST *ecur = ehead;
610 : edgomez 159
611 : edgomez 195 if (ehead == NULL) {
612 : edgomez 159 return;
613 :     }
614 :    
615 : edgomez 195 if (ecur->handle == handle) {
616 : edgomez 159 ehead = ecur->next;
617 :     free(ecur);
618 :     return;
619 :     }
620 :    
621 : edgomez 195 while (ecur->next) {
622 :     if (ecur->next->handle == handle) {
623 :     EINST *tmp = ecur->next;
624 :    
625 : edgomez 159 ecur->next = tmp->next;
626 :     free(tmp);
627 :     return;
628 :     }
629 :     ecur = ecur->next;
630 :     }
631 :     }
632 : edgomez 195
633 : edgomez 159 /***************************************
634 : edgomez 143 * Colorspace code converter *
635 :     ***************************************/
636 :    
637 : edgomez 195 static int
638 :     xvid_to_opendivx_dec_csp(int csp)
639 : edgomez 143 {
640 :    
641 : edgomez 195 switch (csp) {
642 :     case DEC_YV12:
643 : edgomez 143 return XVID_CSP_YV12;
644 : edgomez 195 case DEC_420:
645 : edgomez 143 return XVID_CSP_I420;
646 : edgomez 195 case DEC_YUY2:
647 : edgomez 143 return XVID_CSP_YUY2;
648 : edgomez 195 case DEC_UYVY:
649 : edgomez 143 return XVID_CSP_UYVY;
650 : edgomez 195 case DEC_RGB32:
651 : edgomez 143 return XVID_CSP_VFLIP | XVID_CSP_RGB32;
652 : edgomez 195 case DEC_RGB24:
653 : edgomez 143 return XVID_CSP_VFLIP | XVID_CSP_RGB24;
654 : edgomez 195 case DEC_RGB565:
655 : edgomez 143 return XVID_CSP_VFLIP | XVID_CSP_RGB565;
656 : edgomez 195 case DEC_RGB555:
657 : edgomez 143 return XVID_CSP_VFLIP | XVID_CSP_RGB555;
658 : edgomez 195 case DEC_RGB32_INV:
659 : edgomez 143 return XVID_CSP_RGB32;
660 : edgomez 195 case DEC_RGB24_INV:
661 : edgomez 143 return XVID_CSP_RGB24;
662 : edgomez 195 case DEC_RGB565_INV:
663 : edgomez 143 return XVID_CSP_RGB565;
664 : edgomez 195 case DEC_RGB555_INV:
665 : edgomez 143 return XVID_CSP_RGB555;
666 : edgomez 195 case DEC_USER:
667 :     return XVID_CSP_USER;
668 :     default:
669 : edgomez 143 return -1;
670 :     }
671 :     }
672 :    
673 : edgomez 195 static int
674 :     xvid_to_opendivx_enc_csp(int csp)
675 : edgomez 143 {
676 :    
677 : edgomez 195 switch (csp) {
678 :     case ENC_CSP_RGB24:
679 : edgomez 143 return XVID_CSP_VFLIP | XVID_CSP_RGB24;
680 : edgomez 195 case ENC_CSP_YV12:
681 : edgomez 143 return XVID_CSP_YV12;
682 : edgomez 195 case ENC_CSP_YUY2:
683 : edgomez 143 return XVID_CSP_YUY2;
684 : edgomez 195 case ENC_CSP_UYVY:
685 : edgomez 143 return XVID_CSP_UYVY;
686 : edgomez 195 case ENC_CSP_I420:
687 : edgomez 143 return XVID_CSP_I420;
688 : edgomez 195 default:
689 : edgomez 143 return -1;
690 :     }
691 :     }

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