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