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

Annotation of /xvidcore/src/divx4.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (view) (download)

1 : Isibaar 1.1 /**************************************************************************
2 :     *
3 : edgomez 1.13 * XVID MPEG-4 VIDEO CODEC
4 :     * - OpenDivx API wrapper -
5 : Isibaar 1.1 *
6 : suxen_drol 1.19 * Copyright(C) 2001-2002 Peter Ross <pross@xvid.org>
7 : edgomez 1.18 *
8 : edgomez 1.20 * This file is part of XviD, a free MPEG-4 video encoder/decoder
9 : edgomez 1.13 *
10 : edgomez 1.20 * 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 1.13 * the Free Software Foundation; either version 2 of the License, or
13 :     * (at your option) any later version.
14 :     *
15 :     * 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 :     *
20 :     * 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 1.20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * 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$
54 : edgomez 1.10 *
55 : Isibaar 1.1 *************************************************************************/
56 :    
57 : knhor 1.7 #include <stdlib.h>
58 : edgomez 1.9 #include <string.h>
59 : edgomez 1.11 #include <stdio.h>
60 : Isibaar 1.1
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 1.9 /**************************************************************************
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 1.1
80 :    
81 :     typedef struct DINST
82 :     {
83 :     unsigned long key;
84 : edgomez 1.14 struct DINST *next;
85 : Isibaar 1.1
86 : edgomez 1.14 void *handle;
87 : Isibaar 1.1 XVID_DEC_FRAME xframe;
88 :    
89 : edgomez 1.14 }
90 :     DINST;
91 : Isibaar 1.1
92 : edgomez 1.11 typedef struct EINST
93 :     {
94 : edgomez 1.14 struct EINST *next;
95 : edgomez 1.11
96 : edgomez 1.14 void *handle;
97 : edgomez 1.11 int quality;
98 :    
99 : edgomez 1.14 }
100 :     EINST;
101 : edgomez 1.11
102 : edgomez 1.9 /**************************************************************************
103 :     * Global data (needed to emulate correctly exported symbols from divx4)
104 :     *************************************************************************/
105 :    
106 :     /* This is not used in this module but is required by some divx4 encoders*/
107 :     int quiet_encore = 1;
108 :    
109 :     /**************************************************************************
110 :     * Local data
111 :     *************************************************************************/
112 :    
113 :     /* The Divx4 instance chainlist */
114 : edgomez 1.14 static DINST *dhead = NULL;
115 :     static EINST *ehead = NULL;
116 : edgomez 1.9
117 :     /* Divx4 quality to XviD encoder motion flag presets */
118 :     static int const divx4_motion_presets[7] = {
119 : edgomez 1.14 0,
120 : edgomez 1.9
121 : edgomez 1.14 PMV_EARLYSTOP16,
122 : edgomez 1.9
123 : chl 1.12 PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16,
124 : edgomez 1.9
125 :     PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
126 :    
127 : edgomez 1.14 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
128 :     PMV_HALFPELREFINE8,
129 : edgomez 1.9
130 : edgomez 1.14 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |
131 :     PMV_HALFPELREFINE8,
132 : edgomez 1.9
133 : edgomez 1.14 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 |
134 :     PMV_HALFPELREFINE8
135 : edgomez 1.9 };
136 :    
137 :    
138 :     /* Divx4 quality to general encoder flag presets */
139 :     static int const divx4_general_presets[7] = {
140 : edgomez 1.14 0,
141 :     XVID_H263QUANT,
142 : edgomez 1.9 XVID_H263QUANT,
143 :     XVID_H263QUANT | XVID_HALFPEL,
144 :     XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
145 : edgomez 1.14 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL,
146 : edgomez 1.9 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
147 :     };
148 :    
149 :     /**************************************************************************
150 :     * Local Prototypes
151 :     *************************************************************************/
152 :    
153 :     /* Chain list helper functions */
154 : edgomez 1.14 static DINST *dinst_find(unsigned long key);
155 :     static DINST *dinst_add(unsigned long key);
156 :     static void dinst_remove(unsigned long key);
157 :    
158 :     static EINST *einst_find(void *handle);
159 :     static EINST *einst_add(void *handle);
160 :     static void einst_remove(void *handle);
161 : edgomez 1.11
162 : edgomez 1.9 /* 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 :    
166 :     /**************************************************************************
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 :    
173 :     int
174 : edgomez 1.14 decore(unsigned long key,
175 :     unsigned long opt,
176 :     void *param1,
177 :     void *param2)
178 : edgomez 1.9 {
179 :    
180 :     int xerr;
181 :    
182 :     switch (opt) {
183 :    
184 : edgomez 1.14 case DEC_OPT_MEMORY_REQS:
185 : edgomez 1.9 {
186 : edgomez 1.14 memset(param2, 0, sizeof(DEC_MEM_REQS));
187 :     return DEC_OK;
188 : edgomez 1.9 }
189 :    
190 : edgomez 1.14 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 : edgomez 1.9
197 : edgomez 1.14 /* Find the divx4 instance */
198 :     if ((dcur = dinst_find(key)) == NULL) {
199 :     dcur = dinst_add(key);
200 :     }
201 : edgomez 1.9
202 : edgomez 1.14 /*
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 : edgomez 1.9
210 : edgomez 1.14 /* 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 1.9
216 : edgomez 1.14 xerr = decoder_create(&xparam);
217 : edgomez 1.9
218 : edgomez 1.14 /* Store the xvid handle into the divx4 instance chainlist */
219 :     dcur->handle = xparam.handle;
220 : edgomez 1.9
221 : edgomez 1.14 break;
222 :     }
223 : edgomez 1.9
224 : edgomez 1.14 case DEC_OPT_RELEASE:
225 : edgomez 1.9 {
226 : edgomez 1.14 DINST *dcur;
227 :    
228 :     /* Find the divx4 instance into the chain list */
229 :     if ((dcur = dinst_find(key)) == NULL) {
230 :     return DEC_EXIT;
231 :     }
232 : edgomez 1.9
233 : edgomez 1.14 /* Destroy the XviD decoder attached to this divx4 instance */
234 :     xerr = decoder_destroy(dcur->handle);
235 : edgomez 1.9
236 : edgomez 1.14 /* Remove the divx4 instance from the chainlist */
237 :     dinst_remove(key);
238 : edgomez 1.9
239 : edgomez 1.14 break;
240 : edgomez 1.9 }
241 :    
242 : edgomez 1.14 case DEC_OPT_SETPP:
243 : edgomez 1.9 {
244 : edgomez 1.14 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 1.9 /*
252 : edgomez 1.14 * We return DEC_OK but XviD has no postprocessing implemented
253 :     * in core.
254 : edgomez 1.9 */
255 : edgomez 1.14 return DEC_OK;
256 : edgomez 1.9 }
257 :    
258 : edgomez 1.14 case DEC_OPT_SETOUT:
259 : edgomez 1.9 {
260 : edgomez 1.14 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 : edgomez 1.9 }
273 :    
274 : edgomez 1.14 case DEC_OPT_FRAME:
275 :     {
276 :     int csp_tmp = 0;
277 :     DINST *dcur;
278 :     DEC_FRAME *dframe = (DEC_FRAME *) param1;
279 :    
280 :     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 : edgomez 1.9
312 : edgomez 1.14 case DEC_OPT_FRAME_311:
313 : edgomez 1.9 /* XviD does not handle Divx ;-) 3.11 yet */
314 :     return DEC_EXIT;
315 :    
316 :     case DEC_OPT_VERSION:
317 :     return EMULATED_DIVX_VERSION;
318 :    
319 : edgomez 1.14 default:
320 : edgomez 1.9 return DEC_EXIT;
321 :     }
322 :    
323 :    
324 :     /* XviD error code -> Divx4 */
325 : edgomez 1.14 switch (xerr) {
326 :     case XVID_ERR_OK:
327 : edgomez 1.9 return DEC_OK;
328 : edgomez 1.14 case XVID_ERR_MEMORY:
329 : edgomez 1.9 return DEC_MEMORY;
330 : edgomez 1.14 case XVID_ERR_FORMAT:
331 : edgomez 1.9 return DEC_BAD_FORMAT;
332 : edgomez 1.14 default:
333 : edgomez 1.9 return DEC_EXIT;
334 :     }
335 :     }
336 :    
337 :     /**************************************************************************
338 :     * Encore Part
339 :     *
340 :     * encore is the divx4 entry point used to compress a frame to a mpeg4
341 :     * bitstream.
342 :     *************************************************************************/
343 :    
344 :     #define FRAMERATE_INCR 1001
345 :    
346 :     int
347 : edgomez 1.14 encore(void *handle,
348 :     int opt,
349 :     void *param1,
350 :     void *param2)
351 : edgomez 1.9 {
352 :    
353 :     int xerr;
354 :    
355 : edgomez 1.14 switch (opt) {
356 :     case ENC_OPT_INIT:
357 : edgomez 1.9 {
358 : edgomez 1.14 EINST *ecur;
359 :     ENC_PARAM *eparam = (ENC_PARAM *) param1;
360 :     XVID_INIT_PARAM xinit;
361 :     XVID_ENC_PARAM xparam;
362 :    
363 :     /* Init XviD which will detect host cpu features */
364 :     xinit.cpu_flags = 0;
365 :     xvid_init(NULL, 0, &xinit, NULL);
366 :    
367 :     /* 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 :    
385 :     /* Create the encoder session */
386 :     xerr = encoder_create(&xparam);
387 :    
388 :     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 :     }
400 : edgomez 1.9
401 : edgomez 1.14 ecur->quality = eparam->quality;
402 :     if (ecur->quality < 0)
403 :     ecur->quality = 0;
404 :     if (ecur->quality > 6)
405 :     ecur->quality = 6;
406 : edgomez 1.9
407 : edgomez 1.14 break;
408 :     }
409 : edgomez 1.9
410 : edgomez 1.14 case ENC_OPT_RELEASE:
411 : edgomez 1.11 {
412 : edgomez 1.14 EINST *ecur;
413 : edgomez 1.11
414 : edgomez 1.14 if ((ecur = einst_find(handle)) == NULL) {
415 :     return ENC_FAIL;
416 : edgomez 1.11 }
417 :    
418 : edgomez 1.14 einst_remove(handle);
419 :     xerr = encoder_destroy((Encoder *) handle);
420 :    
421 :     break;
422 : edgomez 1.11 }
423 :    
424 : edgomez 1.14 case ENC_OPT_ENCODE:
425 :     case ENC_OPT_ENCODE_VBR:
426 : edgomez 1.11 {
427 : edgomez 1.14 EINST *ecur;
428 : edgomez 1.11
429 : edgomez 1.14 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 1.9
434 : edgomez 1.14 if ((ecur = einst_find(handle)) == NULL) {
435 :     return ENC_FAIL;
436 :     }
437 : edgomez 1.11
438 : edgomez 1.14 /* 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 :    
444 :     xframe.image = eframe->image;
445 :     xframe.colorspace = xvid_to_opendivx_enc_csp(eframe->colorspace);
446 :    
447 :     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 : edgomez 1.9
455 : edgomez 1.14 /* Encode the frame */
456 :     xerr =
457 :     encoder_encode((Encoder *) handle, &xframe,
458 :     (eresult ? &xstats : NULL));
459 :    
460 :     /* 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 : edgomez 1.9
470 : edgomez 1.14 eframe->length = xframe.length;
471 : edgomez 1.9
472 : edgomez 1.14 break;
473 : edgomez 1.9 }
474 :    
475 :     default:
476 :     return ENC_FAIL;
477 :     }
478 :    
479 :     /* XviD Error code -> Divx4 error code */
480 : edgomez 1.14 switch (xerr) {
481 :     case XVID_ERR_OK:
482 : edgomez 1.9 return ENC_OK;
483 : edgomez 1.14 case XVID_ERR_MEMORY:
484 : edgomez 1.9 return ENC_MEMORY;
485 : edgomez 1.14 case XVID_ERR_FORMAT:
486 : edgomez 1.9 return ENC_BAD_FORMAT;
487 : edgomez 1.14 default:
488 : edgomez 1.9 return ENC_FAIL;
489 :     }
490 :     }
491 :    
492 :     /**************************************************************************
493 :     * Local Functions
494 :     *************************************************************************/
495 : Isibaar 1.1
496 : edgomez 1.9 /***************************************
497 :     * DINST chainlist helper functions *
498 :     ***************************************/
499 : Isibaar 1.1
500 : edgomez 1.9 /* Find an element in the chainlist according to its key value */
501 : edgomez 1.14 static DINST *
502 :     dinst_find(unsigned long key)
503 : Isibaar 1.1 {
504 : edgomez 1.14 DINST *dcur = dhead;
505 : Isibaar 1.1
506 : edgomez 1.14 while (dcur) {
507 :     if (dcur->key == key) {
508 : Isibaar 1.1 return dcur;
509 :     }
510 :     dcur = dcur->next;
511 :     }
512 :    
513 :     return NULL;
514 :     }
515 :    
516 :    
517 : edgomez 1.9 /* Add an element to the chainlist */
518 : edgomez 1.14 static DINST *
519 :     dinst_add(unsigned long key)
520 : Isibaar 1.1 {
521 : edgomez 1.14 DINST *dnext = dhead;
522 : Isibaar 1.1
523 :     dhead = malloc(sizeof(DINST));
524 : edgomez 1.14 if (dhead == NULL) {
525 : Isibaar 1.1 dhead = dnext;
526 :     return NULL;
527 :     }
528 :    
529 :     dhead->key = key;
530 :     dhead->next = dnext;
531 :    
532 :     return dhead;
533 :     }
534 :    
535 :    
536 : edgomez 1.9 /* Remove an elmement from the chainlist */
537 : edgomez 1.14 static void
538 :     dinst_remove(unsigned long key)
539 : Isibaar 1.1 {
540 : edgomez 1.14 DINST *dcur = dhead;
541 : Isibaar 1.1
542 : edgomez 1.14 if (dhead == NULL) {
543 : Isibaar 1.1 return;
544 :     }
545 :    
546 : edgomez 1.14 if (dcur->key == key) {
547 : Isibaar 1.1 dhead = dcur->next;
548 :     free(dcur);
549 :     return;
550 :     }
551 :    
552 : edgomez 1.14 while (dcur->next) {
553 :     if (dcur->next->key == key) {
554 :     DINST *tmp = dcur->next;
555 :    
556 : Isibaar 1.1 dcur->next = tmp->next;
557 :     free(tmp);
558 :     return;
559 :     }
560 :     dcur = dcur->next;
561 :     }
562 :     }
563 :    
564 : edgomez 1.11
565 :     /***************************************
566 :     * EINST chainlist helper functions *
567 :     ***************************************/
568 :    
569 :     /* Find an element in the chainlist according to its handle */
570 : edgomez 1.14 static EINST *
571 :     einst_find(void *handle)
572 : edgomez 1.11 {
573 : edgomez 1.14 EINST *ecur = ehead;
574 : edgomez 1.11
575 : edgomez 1.14 while (ecur) {
576 :     if (ecur->handle == handle) {
577 : edgomez 1.11 return ecur;
578 :     }
579 :     ecur = ecur->next;
580 :     }
581 :    
582 :     return NULL;
583 :     }
584 :    
585 :    
586 :     /* Add an element to the chainlist */
587 : edgomez 1.14 static EINST *
588 :     einst_add(void *handle)
589 : edgomez 1.11 {
590 : edgomez 1.14 EINST *enext = ehead;
591 : edgomez 1.11
592 :     ehead = malloc(sizeof(EINST));
593 : edgomez 1.14 if (ehead == NULL) {
594 : edgomez 1.11 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 1.14 static void
607 :     einst_remove(void *handle)
608 : edgomez 1.11 {
609 : edgomez 1.14 EINST *ecur = ehead;
610 : edgomez 1.11
611 : edgomez 1.14 if (ehead == NULL) {
612 : edgomez 1.11 return;
613 :     }
614 :    
615 : edgomez 1.14 if (ecur->handle == handle) {
616 : edgomez 1.11 ehead = ecur->next;
617 :     free(ecur);
618 :     return;
619 :     }
620 :    
621 : edgomez 1.14 while (ecur->next) {
622 :     if (ecur->next->handle == handle) {
623 :     EINST *tmp = ecur->next;
624 :    
625 : edgomez 1.11 ecur->next = tmp->next;
626 :     free(tmp);
627 :     return;
628 :     }
629 :     ecur = ecur->next;
630 :     }
631 :     }
632 : edgomez 1.14
633 : edgomez 1.9 /***************************************
634 :     * Colorspace code converter *
635 :     ***************************************/
636 : Isibaar 1.1
637 : edgomez 1.14 static int
638 :     xvid_to_opendivx_dec_csp(int csp)
639 : Isibaar 1.1 {
640 : edgomez 1.9
641 : edgomez 1.14 switch (csp) {
642 :     case DEC_YV12:
643 : Isibaar 1.1 return XVID_CSP_YV12;
644 : edgomez 1.14 case DEC_420:
645 : Isibaar 1.1 return XVID_CSP_I420;
646 : edgomez 1.14 case DEC_YUY2:
647 : Isibaar 1.1 return XVID_CSP_YUY2;
648 : edgomez 1.14 case DEC_UYVY:
649 : Isibaar 1.1 return XVID_CSP_UYVY;
650 : edgomez 1.14 case DEC_RGB32:
651 : Isibaar 1.1 return XVID_CSP_VFLIP | XVID_CSP_RGB32;
652 : edgomez 1.14 case DEC_RGB24:
653 : Isibaar 1.1 return XVID_CSP_VFLIP | XVID_CSP_RGB24;
654 : edgomez 1.14 case DEC_RGB565:
655 : Isibaar 1.1 return XVID_CSP_VFLIP | XVID_CSP_RGB565;
656 : edgomez 1.14 case DEC_RGB555:
657 : Isibaar 1.1 return XVID_CSP_VFLIP | XVID_CSP_RGB555;
658 : edgomez 1.14 case DEC_RGB32_INV:
659 : Isibaar 1.1 return XVID_CSP_RGB32;
660 : edgomez 1.14 case DEC_RGB24_INV:
661 : Isibaar 1.1 return XVID_CSP_RGB24;
662 : edgomez 1.14 case DEC_RGB565_INV:
663 : Isibaar 1.1 return XVID_CSP_RGB565;
664 : edgomez 1.14 case DEC_RGB555_INV:
665 : Isibaar 1.1 return XVID_CSP_RGB555;
666 : edgomez 1.14 case DEC_USER:
667 :     return XVID_CSP_USER;
668 :     default:
669 : Isibaar 1.1 return -1;
670 :     }
671 :     }
672 :    
673 : edgomez 1.14 static int
674 :     xvid_to_opendivx_enc_csp(int csp)
675 : Isibaar 1.1 {
676 :    
677 : edgomez 1.14 switch (csp) {
678 :     case ENC_CSP_RGB24:
679 : edgomez 1.9 return XVID_CSP_VFLIP | XVID_CSP_RGB24;
680 : edgomez 1.14 case ENC_CSP_YV12:
681 : edgomez 1.9 return XVID_CSP_YV12;
682 : edgomez 1.14 case ENC_CSP_YUY2:
683 : edgomez 1.9 return XVID_CSP_YUY2;
684 : edgomez 1.14 case ENC_CSP_UYVY:
685 : edgomez 1.9 return XVID_CSP_UYVY;
686 : edgomez 1.14 case ENC_CSP_I420:
687 : edgomez 1.9 return XVID_CSP_I420;
688 : edgomez 1.14 default:
689 : edgomez 1.9 return -1;
690 : Isibaar 1.1 }
691 :     }

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