Parent Directory | Revision Log
Revision 1.12 - (view) (download)
1 : | Isibaar | 1.1 | /************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | edgomez | 1.9 | * OpenDivx API wrapper |
5 : | Isibaar | 1.1 | * |
6 : | * 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 | ||
8 : | * to use this software module in hardware or software products are | ||
9 : | * advised that its use may infringe existing patents or copyrights, and | ||
10 : | * any such use would be at such party's own risk. The original | ||
11 : | * developer of this software module and his/her company, and subsequent | ||
12 : | * editors and their companies, will have no liability for use of this | ||
13 : | * software or modifications or derivatives thereof. | ||
14 : | * | ||
15 : | * This program is free software; you can redistribute it and/or modify | ||
16 : | * it under the terms of the GNU General Public License as published by | ||
17 : | * the Free Software Foundation; either version 2 of the License, or | ||
18 : | * (at your option) any later version. | ||
19 : | * | ||
20 : | * This program is distributed in the hope that it will be useful, | ||
21 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
23 : | * GNU General Public License for more details. | ||
24 : | * | ||
25 : | * You should have received a copy of the GNU General Public License | ||
26 : | * along with this program; if not, write to the Free Software | ||
27 : | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 : | * | ||
29 : | *************************************************************************/ | ||
30 : | |||
31 : | /************************************************************************** | ||
32 : | * | ||
33 : | * History: | ||
34 : | * | ||
35 : | edgomez | 1.11 | * 26.02.2001 fixed dec_csp bugs |
36 : | * 26.12.2001 xvid_init() support | ||
37 : | * 22.12.2001 removed some compiler warnings | ||
38 : | * 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> | ||
39 : | Isibaar | 1.1 | * |
40 : | chl | 1.12 | * $Id: divx4.c,v 1.11 2002/05/04 12:26:06 edgomez Exp $ |
41 : | edgomez | 1.10 | * |
42 : | Isibaar | 1.1 | *************************************************************************/ |
43 : | |||
44 : | knhor | 1.7 | #include <stdlib.h> |
45 : | edgomez | 1.9 | #include <string.h> |
46 : | edgomez | 1.11 | #include <stdio.h> |
47 : | Isibaar | 1.1 | |
48 : | #include "xvid.h" | ||
49 : | #include "divx4.h" | ||
50 : | #include "decoder.h" | ||
51 : | #include "encoder.h" | ||
52 : | |||
53 : | #define EMULATED_DIVX_VERSION 20011001 | ||
54 : | |||
55 : | edgomez | 1.9 | /************************************************************************** |
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 : | Isibaar | 1.1 | |
67 : | |||
68 : | typedef struct DINST | ||
69 : | { | ||
70 : | unsigned long key; | ||
71 : | struct DINST * next; | ||
72 : | |||
73 : | void * handle; | ||
74 : | XVID_DEC_FRAME xframe; | ||
75 : | |||
76 : | } DINST; | ||
77 : | |||
78 : | edgomez | 1.11 | typedef struct EINST |
79 : | { | ||
80 : | struct EINST * next; | ||
81 : | |||
82 : | void * handle; | ||
83 : | int quality; | ||
84 : | |||
85 : | } EINST; | ||
86 : | |||
87 : | edgomez | 1.9 | /************************************************************************** |
88 : | * Global data (needed to emulate correctly exported symbols from divx4) | ||
89 : | *************************************************************************/ | ||
90 : | |||
91 : | /* This is not used in this module but is required by some divx4 encoders*/ | ||
92 : | int quiet_encore = 1; | ||
93 : | |||
94 : | /************************************************************************** | ||
95 : | * Local data | ||
96 : | *************************************************************************/ | ||
97 : | |||
98 : | /* The Divx4 instance chainlist */ | ||
99 : | static DINST * dhead = NULL; | ||
100 : | edgomez | 1.11 | static EINST * ehead = NULL; |
101 : | edgomez | 1.9 | |
102 : | /* Divx4 quality to XviD encoder motion flag presets */ | ||
103 : | static int const divx4_motion_presets[7] = { | ||
104 : | 0, | ||
105 : | |||
106 : | chl | 1.12 | PMV_EARLYSTOP16, |
107 : | edgomez | 1.9 | |
108 : | chl | 1.12 | PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16, |
109 : | edgomez | 1.9 | |
110 : | PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, | ||
111 : | |||
112 : | PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | | ||
113 : | chl | 1.12 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8, |
114 : | edgomez | 1.9 | |
115 : | PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | | ||
116 : | chl | 1.12 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8, |
117 : | edgomez | 1.9 | |
118 : | chl | 1.12 | PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | |
119 : | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | ||
120 : | edgomez | 1.9 | }; |
121 : | |||
122 : | |||
123 : | /* Divx4 quality to general encoder flag presets */ | ||
124 : | static int const divx4_general_presets[7] = { | ||
125 : | 0, | ||
126 : | XVID_H263QUANT, | ||
127 : | XVID_H263QUANT, | ||
128 : | XVID_H263QUANT | XVID_HALFPEL, | ||
129 : | XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, | ||
130 : | chl | 1.12 | XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, |
131 : | edgomez | 1.9 | XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL |
132 : | }; | ||
133 : | |||
134 : | /************************************************************************** | ||
135 : | * Local Prototypes | ||
136 : | *************************************************************************/ | ||
137 : | |||
138 : | /* Chain list helper functions */ | ||
139 : | static DINST * dinst_find(unsigned long key); | ||
140 : | static DINST * dinst_add(unsigned long key); | ||
141 : | static void dinst_remove(unsigned long key); | ||
142 : | |||
143 : | edgomez | 1.11 | static EINST * einst_find(void *handle); |
144 : | static EINST * einst_add(void *handle); | ||
145 : | static void einst_remove(void *handle); | ||
146 : | |||
147 : | edgomez | 1.9 | /* Converts divx4 colorspaces codes to xvid codes */ |
148 : | static int xvid_to_opendivx_dec_csp(int csp); | ||
149 : | static int xvid_to_opendivx_enc_csp(int csp); | ||
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 | ||
159 : | decore(unsigned long key, unsigned long opt, void * param1, void * param2) | ||
160 : | { | ||
161 : | |||
162 : | int xerr; | ||
163 : | |||
164 : | switch (opt) { | ||
165 : | |||
166 : | case DEC_OPT_MEMORY_REQS : | ||
167 : | { | ||
168 : | memset(param2, 0, sizeof(DEC_MEM_REQS)); | ||
169 : | return DEC_OK; | ||
170 : | } | ||
171 : | |||
172 : | case DEC_OPT_INIT : | ||
173 : | { | ||
174 : | XVID_INIT_PARAM xinit; | ||
175 : | XVID_DEC_PARAM xparam; | ||
176 : | DINST * dcur; | ||
177 : | 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); | ||
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; | ||
191 : | xvid_init(NULL, 0, &xinit, NULL); | ||
192 : | |||
193 : | /* XviD decoder initialization for this instance */ | ||
194 : | xparam.width = dparam->x_dim; | ||
195 : | xparam.height = dparam->y_dim; | ||
196 : | dcur->xframe.colorspace = | ||
197 : | xvid_to_opendivx_dec_csp(dparam->output_format); | ||
198 : | |||
199 : | xerr = decoder_create(&xparam); | ||
200 : | |||
201 : | /* Store the xvid handle into the divx4 instance chainlist */ | ||
202 : | dcur->handle = xparam.handle; | ||
203 : | |||
204 : | break; | ||
205 : | } | ||
206 : | |||
207 : | case DEC_OPT_RELEASE : | ||
208 : | { | ||
209 : | DINST * dcur; | ||
210 : | |||
211 : | /* Find the divx4 instance into the chain list */ | ||
212 : | if ((dcur = dinst_find(key)) == NULL) | ||
213 : | { | ||
214 : | return DEC_EXIT; | ||
215 : | } | ||
216 : | |||
217 : | /* Destroy the XviD decoder attached to this divx4 instance */ | ||
218 : | xerr = decoder_destroy(dcur->handle); | ||
219 : | |||
220 : | /* Remove the divx4 instance from the chainlist */ | ||
221 : | dinst_remove(key); | ||
222 : | |||
223 : | break; | ||
224 : | } | ||
225 : | |||
226 : | case DEC_OPT_SETPP : | ||
227 : | { | ||
228 : | DINST * dcur; | ||
229 : | |||
230 : | /* Find the divx4 instance into the chain list */ | ||
231 : | if ((dcur = dinst_find(key)) == NULL) | ||
232 : | { | ||
233 : | return DEC_EXIT; | ||
234 : | } | ||
235 : | |||
236 : | /* | ||
237 : | * We return DEC_OK but XviD has no postprocessing implemented | ||
238 : | * in core. | ||
239 : | */ | ||
240 : | return DEC_OK; | ||
241 : | } | ||
242 : | |||
243 : | case DEC_OPT_SETOUT : | ||
244 : | { | ||
245 : | DINST * dcur; | ||
246 : | DEC_PARAM * dparam = (DEC_PARAM *)param1; | ||
247 : | |||
248 : | if ((dcur = dinst_find(key)) == NULL) | ||
249 : | { | ||
250 : | return DEC_EXIT; | ||
251 : | } | ||
252 : | |||
253 : | /* Change the output colorspace */ | ||
254 : | dcur->xframe.colorspace = | ||
255 : | xvid_to_opendivx_dec_csp(dparam->output_format); | ||
256 : | |||
257 : | return DEC_OK; | ||
258 : | } | ||
259 : | Isibaar | 1.1 | |
260 : | edgomez | 1.9 | case DEC_OPT_FRAME: |
261 : | { | ||
262 : | int csp_tmp = 0; | ||
263 : | DINST * dcur; | ||
264 : | DEC_FRAME * dframe = (DEC_FRAME *)param1; | ||
265 : | |||
266 : | if ((dcur = dinst_find(key)) == NULL) | ||
267 : | { | ||
268 : | return DEC_EXIT; | ||
269 : | } | ||
270 : | |||
271 : | /* Copy the divx4 fields to the XviD decoder structure */ | ||
272 : | dcur->xframe.bitstream = dframe->bitstream; | ||
273 : | dcur->xframe.length = dframe->length; | ||
274 : | dcur->xframe.image = dframe->bmp; | ||
275 : | dcur->xframe.stride = dframe->stride; | ||
276 : | |||
277 : | /* Does the frame need to be skipped ? */ | ||
278 : | 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; | ||
286 : | dcur->xframe.colorspace = XVID_CSP_NULL; | ||
287 : | } | ||
288 : | |||
289 : | /* Decode the bitstream */ | ||
290 : | xerr = decoder_decode(dcur->handle, &dcur->xframe); | ||
291 : | |||
292 : | /* Restore the real colorspace for this instance */ | ||
293 : | if (!dframe->render_flag) | ||
294 : | { | ||
295 : | dcur->xframe.colorspace = csp_tmp; | ||
296 : | } | ||
297 : | |||
298 : | break; | ||
299 : | } | ||
300 : | |||
301 : | case DEC_OPT_FRAME_311 : | ||
302 : | /* XviD does not handle Divx ;-) 3.11 yet */ | ||
303 : | return DEC_EXIT; | ||
304 : | |||
305 : | case DEC_OPT_VERSION: | ||
306 : | return EMULATED_DIVX_VERSION; | ||
307 : | |||
308 : | default : | ||
309 : | return DEC_EXIT; | ||
310 : | } | ||
311 : | |||
312 : | |||
313 : | /* XviD error code -> Divx4 */ | ||
314 : | switch(xerr) | ||
315 : | { | ||
316 : | case XVID_ERR_OK : | ||
317 : | return DEC_OK; | ||
318 : | case XVID_ERR_MEMORY : | ||
319 : | return DEC_MEMORY; | ||
320 : | case XVID_ERR_FORMAT : | ||
321 : | return DEC_BAD_FORMAT; | ||
322 : | default : | ||
323 : | return DEC_EXIT; | ||
324 : | } | ||
325 : | } | ||
326 : | |||
327 : | /************************************************************************** | ||
328 : | * Encore Part | ||
329 : | * | ||
330 : | * encore is the divx4 entry point used to compress a frame to a mpeg4 | ||
331 : | * bitstream. | ||
332 : | *************************************************************************/ | ||
333 : | |||
334 : | #define FRAMERATE_INCR 1001 | ||
335 : | |||
336 : | int | ||
337 : | encore(void * handle, int opt, void * param1, void * param2) | ||
338 : | { | ||
339 : | |||
340 : | int xerr; | ||
341 : | |||
342 : | switch(opt) { | ||
343 : | case ENC_OPT_INIT : | ||
344 : | { | ||
345 : | edgomez | 1.11 | EINST *ecur; |
346 : | edgomez | 1.9 | ENC_PARAM * eparam = (ENC_PARAM *)param1; |
347 : | XVID_INIT_PARAM xinit; | ||
348 : | XVID_ENC_PARAM xparam; | ||
349 : | |||
350 : | /* Init XviD which will detect host cpu features */ | ||
351 : | xinit.cpu_flags = 0; | ||
352 : | xvid_init(NULL, 0, &xinit, NULL); | ||
353 : | |||
354 : | /* Settings are copied to the XviD encoder structure */ | ||
355 : | xparam.width = eparam->x_dim; | ||
356 : | xparam.height = eparam->y_dim; | ||
357 : | if ((eparam->framerate - (int)eparam->framerate) == 0) | ||
358 : | { | ||
359 : | xparam.fincr = 1; | ||
360 : | xparam.fbase = (int)eparam->framerate; | ||
361 : | } | ||
362 : | else | ||
363 : | { | ||
364 : | xparam.fincr = FRAMERATE_INCR; | ||
365 : | xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate); | ||
366 : | } | ||
367 : | xparam.rc_bitrate = eparam->bitrate; | ||
368 : | xparam.rc_reaction_delay_factor = 16; | ||
369 : | xparam.rc_averaging_period = 100; | ||
370 : | xparam.rc_buffer = 100; | ||
371 : | xparam.min_quantizer = eparam->min_quantizer; | ||
372 : | xparam.max_quantizer = eparam->max_quantizer; | ||
373 : | xparam.max_key_interval = eparam->max_key_interval; | ||
374 : | |||
375 : | /* Create the encoder session */ | ||
376 : | xerr = encoder_create(&xparam); | ||
377 : | |||
378 : | eparam->handle = xparam.handle; | ||
379 : | |||
380 : | edgomez | 1.11 | /* 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 : | edgomez | 1.9 | break; |
397 : | } | ||
398 : | |||
399 : | case ENC_OPT_RELEASE : | ||
400 : | { | ||
401 : | edgomez | 1.11 | EINST *ecur; |
402 : | |||
403 : | if ((ecur = einst_find(handle)) == NULL) | ||
404 : | { | ||
405 : | return ENC_FAIL; | ||
406 : | } | ||
407 : | |||
408 : | edgomez | 1.9 | xerr = encoder_destroy((Encoder *) handle); |
409 : | break; | ||
410 : | } | ||
411 : | |||
412 : | case ENC_OPT_ENCODE : | ||
413 : | case ENC_OPT_ENCODE_VBR : | ||
414 : | { | ||
415 : | edgomez | 1.11 | EINST *ecur; |
416 : | |||
417 : | edgomez | 1.9 | ENC_FRAME * eframe = (ENC_FRAME *)param1; |
418 : | ENC_RESULT * eresult = (ENC_RESULT *)param2; | ||
419 : | XVID_ENC_FRAME xframe; | ||
420 : | XVID_ENC_STATS xstats; | ||
421 : | |||
422 : | edgomez | 1.11 | if ((ecur = einst_find(handle)) == NULL) |
423 : | { | ||
424 : | return ENC_FAIL; | ||
425 : | } | ||
426 : | |||
427 : | edgomez | 1.9 | /* Copy the divx4 info into the xvid structure */ |
428 : | xframe.bitstream = eframe->bitstream; | ||
429 : | xframe.length = eframe->length; | ||
430 : | edgomez | 1.11 | xframe.motion = divx4_motion_presets[ecur->quality]; |
431 : | xframe.general = divx4_general_presets[ecur->quality]; | ||
432 : | edgomez | 1.9 | |
433 : | xframe.image = eframe->image; | ||
434 : | xframe.colorspace = | ||
435 : | xvid_to_opendivx_enc_csp(eframe->colorspace); | ||
436 : | |||
437 : | if (opt == ENC_OPT_ENCODE_VBR) | ||
438 : | { | ||
439 : | xframe.intra = eframe->intra; | ||
440 : | xframe.quant = eframe->quant; | ||
441 : | } | ||
442 : | else | ||
443 : | { | ||
444 : | xframe.intra = -1; | ||
445 : | xframe.quant = 0; | ||
446 : | } | ||
447 : | |||
448 : | /* Encode the frame */ | ||
449 : | xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) ); | ||
450 : | |||
451 : | /* Copy back the xvid structure to the divx4 one */ | ||
452 : | if (eresult) | ||
453 : | { | ||
454 : | eresult->is_key_frame = xframe.intra; | ||
455 : | eresult->quantizer = xstats.quant; | ||
456 : | eresult->total_bits = xframe.length * 8; | ||
457 : | eresult->motion_bits = xstats.hlength * 8; | ||
458 : | eresult->texture_bits = eresult->total_bits - eresult->motion_bits; | ||
459 : | } | ||
460 : | |||
461 : | eframe->length = xframe.length; | ||
462 : | |||
463 : | break; | ||
464 : | } | ||
465 : | |||
466 : | default: | ||
467 : | return ENC_FAIL; | ||
468 : | } | ||
469 : | |||
470 : | /* XviD Error code -> Divx4 error code */ | ||
471 : | switch(xerr) | ||
472 : | { | ||
473 : | case XVID_ERR_OK : | ||
474 : | return ENC_OK; | ||
475 : | case XVID_ERR_MEMORY : | ||
476 : | return ENC_MEMORY; | ||
477 : | case XVID_ERR_FORMAT : | ||
478 : | return ENC_BAD_FORMAT; | ||
479 : | default : | ||
480 : | return ENC_FAIL; | ||
481 : | } | ||
482 : | } | ||
483 : | |||
484 : | /************************************************************************** | ||
485 : | * Local Functions | ||
486 : | *************************************************************************/ | ||
487 : | Isibaar | 1.1 | |
488 : | edgomez | 1.9 | /*************************************** |
489 : | * DINST chainlist helper functions * | ||
490 : | ***************************************/ | ||
491 : | Isibaar | 1.1 | |
492 : | edgomez | 1.9 | /* Find an element in the chainlist according to its key value */ |
493 : | static DINST * dinst_find(unsigned long key) | ||
494 : | Isibaar | 1.1 | { |
495 : | DINST * dcur = dhead; | ||
496 : | |||
497 : | while (dcur) | ||
498 : | { | ||
499 : | if (dcur->key == key) | ||
500 : | { | ||
501 : | return dcur; | ||
502 : | } | ||
503 : | dcur = dcur->next; | ||
504 : | } | ||
505 : | |||
506 : | return NULL; | ||
507 : | } | ||
508 : | |||
509 : | |||
510 : | edgomez | 1.9 | /* Add an element to the chainlist */ |
511 : | static DINST * dinst_add(unsigned long key) | ||
512 : | Isibaar | 1.1 | { |
513 : | DINST * dnext = dhead; | ||
514 : | |||
515 : | dhead = malloc(sizeof(DINST)); | ||
516 : | if (dhead == NULL) | ||
517 : | { | ||
518 : | dhead = dnext; | ||
519 : | return NULL; | ||
520 : | } | ||
521 : | |||
522 : | dhead->key = key; | ||
523 : | dhead->next = dnext; | ||
524 : | |||
525 : | return dhead; | ||
526 : | } | ||
527 : | |||
528 : | |||
529 : | edgomez | 1.9 | /* Remove an elmement from the chainlist */ |
530 : | static void dinst_remove(unsigned long key) | ||
531 : | Isibaar | 1.1 | { |
532 : | DINST * dcur = dhead; | ||
533 : | |||
534 : | if (dhead == NULL) | ||
535 : | { | ||
536 : | return; | ||
537 : | } | ||
538 : | |||
539 : | if (dcur->key == key) | ||
540 : | { | ||
541 : | dhead = dcur->next; | ||
542 : | free(dcur); | ||
543 : | return; | ||
544 : | } | ||
545 : | |||
546 : | while (dcur->next) | ||
547 : | { | ||
548 : | if (dcur->next->key == key) | ||
549 : | { | ||
550 : | DINST * tmp = dcur->next; | ||
551 : | dcur->next = tmp->next; | ||
552 : | free(tmp); | ||
553 : | return; | ||
554 : | } | ||
555 : | dcur = dcur->next; | ||
556 : | } | ||
557 : | } | ||
558 : | |||
559 : | edgomez | 1.11 | |
560 : | /*************************************** | ||
561 : | * EINST chainlist helper functions * | ||
562 : | ***************************************/ | ||
563 : | |||
564 : | /* Find an element in the chainlist according to its handle */ | ||
565 : | static EINST * einst_find(void *handle) | ||
566 : | { | ||
567 : | EINST * ecur = ehead; | ||
568 : | |||
569 : | while (ecur) | ||
570 : | { | ||
571 : | if (ecur->handle == handle) | ||
572 : | { | ||
573 : | return ecur; | ||
574 : | } | ||
575 : | ecur = ecur->next; | ||
576 : | } | ||
577 : | |||
578 : | return NULL; | ||
579 : | } | ||
580 : | |||
581 : | |||
582 : | /* Add an element to the chainlist */ | ||
583 : | static EINST * einst_add(void *handle) | ||
584 : | { | ||
585 : | EINST * enext = ehead; | ||
586 : | |||
587 : | ehead = malloc(sizeof(EINST)); | ||
588 : | if (ehead == NULL) | ||
589 : | { | ||
590 : | ehead = enext; | ||
591 : | return NULL; | ||
592 : | } | ||
593 : | |||
594 : | ehead->handle = handle; | ||
595 : | ehead->next = enext; | ||
596 : | |||
597 : | return ehead; | ||
598 : | } | ||
599 : | |||
600 : | |||
601 : | /* Remove an elmement from the chainlist */ | ||
602 : | static void einst_remove(void *handle) | ||
603 : | { | ||
604 : | EINST * ecur = ehead; | ||
605 : | |||
606 : | if (ehead == NULL) | ||
607 : | { | ||
608 : | return; | ||
609 : | } | ||
610 : | |||
611 : | if (ecur->handle == handle) | ||
612 : | { | ||
613 : | ehead = ecur->next; | ||
614 : | free(ecur); | ||
615 : | return; | ||
616 : | } | ||
617 : | |||
618 : | while (ecur->next) | ||
619 : | { | ||
620 : | if (ecur->next->handle == handle) | ||
621 : | { | ||
622 : | EINST * tmp = ecur->next; | ||
623 : | ecur->next = tmp->next; | ||
624 : | free(tmp); | ||
625 : | return; | ||
626 : | } | ||
627 : | ecur = ecur->next; | ||
628 : | } | ||
629 : | } | ||
630 : | edgomez | 1.9 | /*************************************** |
631 : | * Colorspace code converter * | ||
632 : | ***************************************/ | ||
633 : | Isibaar | 1.1 | |
634 : | edgomez | 1.9 | static int xvid_to_opendivx_dec_csp(int csp) |
635 : | Isibaar | 1.1 | { |
636 : | edgomez | 1.9 | |
637 : | Isibaar | 1.1 | switch(csp) |
638 : | { | ||
639 : | case DEC_YV12 : | ||
640 : | return XVID_CSP_YV12; | ||
641 : | case DEC_420 : | ||
642 : | return XVID_CSP_I420; | ||
643 : | case DEC_YUY2 : | ||
644 : | return XVID_CSP_YUY2; | ||
645 : | case DEC_UYVY : | ||
646 : | return XVID_CSP_UYVY; | ||
647 : | case DEC_RGB32 : | ||
648 : | return XVID_CSP_VFLIP | XVID_CSP_RGB32; | ||
649 : | case DEC_RGB24 : | ||
650 : | return XVID_CSP_VFLIP | XVID_CSP_RGB24; | ||
651 : | case DEC_RGB565 : | ||
652 : | return XVID_CSP_VFLIP | XVID_CSP_RGB565; | ||
653 : | case DEC_RGB555 : | ||
654 : | return XVID_CSP_VFLIP | XVID_CSP_RGB555; | ||
655 : | case DEC_RGB32_INV : | ||
656 : | return XVID_CSP_RGB32; | ||
657 : | case DEC_RGB24_INV : | ||
658 : | return XVID_CSP_RGB24; | ||
659 : | case DEC_RGB565_INV : | ||
660 : | return XVID_CSP_RGB565; | ||
661 : | case DEC_RGB555_INV : | ||
662 : | return XVID_CSP_RGB555; | ||
663 : | case DEC_USER : | ||
664 : | return XVID_CSP_USER; | ||
665 : | default : | ||
666 : | return -1; | ||
667 : | } | ||
668 : | } | ||
669 : | |||
670 : | edgomez | 1.9 | static int xvid_to_opendivx_enc_csp(int csp) |
671 : | Isibaar | 1.1 | { |
672 : | |||
673 : | edgomez | 1.9 | switch (csp) |
674 : | Isibaar | 1.1 | { |
675 : | edgomez | 1.9 | case ENC_CSP_RGB24 : |
676 : | return XVID_CSP_VFLIP | XVID_CSP_RGB24; | ||
677 : | case ENC_CSP_YV12 : | ||
678 : | return XVID_CSP_YV12; | ||
679 : | case ENC_CSP_YUY2 : | ||
680 : | return XVID_CSP_YUY2; | ||
681 : | case ENC_CSP_UYVY : | ||
682 : | return XVID_CSP_UYVY; | ||
683 : | case ENC_CSP_I420 : | ||
684 : | return XVID_CSP_I420; | ||
685 : | Isibaar | 1.1 | default : |
686 : | edgomez | 1.9 | return -1; |
687 : | Isibaar | 1.1 | } |
688 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |