Parent Directory
|
Revision Log
Revision 1.22 - (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.21 | * 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 : | edgomez | 1.18 | * |
15 : | edgomez | 1.21 | * 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 : | edgomez | 1.13 | * 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 : | edgomez | 1.21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
28 : | * | ||
29 : | *************************************************************************/ | ||
30 : | |||
31 : | /************************************************************************** | ||
32 : | * | ||
33 : | * History: | ||
34 : | edgomez | 1.20 | * |
35 : | edgomez | 1.21 | * 24.02.2002 #def BFRAMES compatibility |
36 : | * 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 : | edgomez | 1.20 | * |
41 : | edgomez | 1.22 | * $Id: divx4.c,v 1.21 2003/02/15 15:22:17 edgomez 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.21 | 0, |
110 : | edgomez | 1.9 | |
111 : | edgomez | 1.21 | PMV_ADVANCEDDIAMOND16, |
112 : | edgomez | 1.9 | |
113 : | edgomez | 1.21 | PMV_HALFPELREFINE16, |
114 : | edgomez | 1.9 | |
115 : | edgomez | 1.21 | PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8, |
116 : | edgomez | 1.9 | |
117 : | edgomez | 1.21 | PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8, |
118 : | edgomez | 1.9 | |
119 : | edgomez | 1.21 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | 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 : | edgomez | 1.14 | 0, |
126 : | XVID_H263QUANT, | ||
127 : | edgomez | 1.9 | XVID_H263QUANT, |
128 : | XVID_H263QUANT | XVID_HALFPEL, | ||
129 : | XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, | ||
130 : | edgomez | 1.14 | 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 : | edgomez | 1.14 | 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 : | static EINST *einst_find(void *handle); | ||
144 : | static EINST *einst_add(void *handle); | ||
145 : | static void einst_remove(void *handle); | ||
146 : | edgomez | 1.11 | |
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 : | edgomez | 1.14 | decore(unsigned long key, |
160 : | unsigned long opt, | ||
161 : | void *param1, | ||
162 : | void *param2) | ||
163 : | edgomez | 1.9 | { |
164 : | |||
165 : | int xerr; | ||
166 : | |||
167 : | switch (opt) { | ||
168 : | |||
169 : | edgomez | 1.14 | case DEC_OPT_MEMORY_REQS: |
170 : | edgomez | 1.9 | { |
171 : | edgomez | 1.14 | memset(param2, 0, sizeof(DEC_MEM_REQS)); |
172 : | return DEC_OK; | ||
173 : | edgomez | 1.9 | } |
174 : | |||
175 : | edgomez | 1.14 | case DEC_OPT_INIT: |
176 : | { | ||
177 : | XVID_INIT_PARAM xinit; | ||
178 : | XVID_DEC_PARAM xparam; | ||
179 : | DINST *dcur; | ||
180 : | DEC_PARAM *dparam = (DEC_PARAM *) param1; | ||
181 : | edgomez | 1.9 | |
182 : | edgomez | 1.14 | /* Find the divx4 instance */ |
183 : | if ((dcur = dinst_find(key)) == NULL) { | ||
184 : | dcur = dinst_add(key); | ||
185 : | } | ||
186 : | edgomez | 1.9 | |
187 : | edgomez | 1.14 | /* |
188 : | * XviD initialization | ||
189 : | * XviD will detect the host cpu type and activate optimized | ||
190 : | * functions according to the host cpu features. | ||
191 : | */ | ||
192 : | xinit.cpu_flags = 0; | ||
193 : | xvid_init(NULL, 0, &xinit, NULL); | ||
194 : | edgomez | 1.9 | |
195 : | edgomez | 1.14 | /* XviD decoder initialization for this instance */ |
196 : | xparam.width = dparam->x_dim; | ||
197 : | xparam.height = dparam->y_dim; | ||
198 : | dcur->xframe.colorspace = | ||
199 : | xvid_to_opendivx_dec_csp(dparam->output_format); | ||
200 : | edgomez | 1.9 | |
201 : | edgomez | 1.14 | xerr = decoder_create(&xparam); |
202 : | edgomez | 1.9 | |
203 : | edgomez | 1.14 | /* Store the xvid handle into the divx4 instance chainlist */ |
204 : | dcur->handle = xparam.handle; | ||
205 : | edgomez | 1.9 | |
206 : | edgomez | 1.14 | break; |
207 : | } | ||
208 : | edgomez | 1.9 | |
209 : | edgomez | 1.14 | case DEC_OPT_RELEASE: |
210 : | edgomez | 1.9 | { |
211 : | edgomez | 1.14 | DINST *dcur; |
212 : | |||
213 : | /* Find the divx4 instance into the chain list */ | ||
214 : | if ((dcur = dinst_find(key)) == NULL) { | ||
215 : | return DEC_EXIT; | ||
216 : | } | ||
217 : | edgomez | 1.9 | |
218 : | edgomez | 1.14 | /* Destroy the XviD decoder attached to this divx4 instance */ |
219 : | xerr = decoder_destroy(dcur->handle); | ||
220 : | edgomez | 1.9 | |
221 : | edgomez | 1.14 | /* Remove the divx4 instance from the chainlist */ |
222 : | dinst_remove(key); | ||
223 : | edgomez | 1.9 | |
224 : | edgomez | 1.14 | break; |
225 : | edgomez | 1.9 | } |
226 : | |||
227 : | edgomez | 1.14 | case DEC_OPT_SETPP: |
228 : | edgomez | 1.9 | { |
229 : | edgomez | 1.14 | DINST *dcur; |
230 : | |||
231 : | /* Find the divx4 instance into the chain list */ | ||
232 : | if ((dcur = dinst_find(key)) == NULL) { | ||
233 : | return DEC_EXIT; | ||
234 : | } | ||
235 : | |||
236 : | edgomez | 1.9 | /* |
237 : | edgomez | 1.14 | * We return DEC_OK but XviD has no postprocessing implemented |
238 : | * in core. | ||
239 : | edgomez | 1.9 | */ |
240 : | edgomez | 1.14 | return DEC_OK; |
241 : | edgomez | 1.9 | } |
242 : | |||
243 : | edgomez | 1.14 | case DEC_OPT_SETOUT: |
244 : | edgomez | 1.9 | { |
245 : | edgomez | 1.14 | DINST *dcur; |
246 : | DEC_PARAM *dparam = (DEC_PARAM *) param1; | ||
247 : | |||
248 : | if ((dcur = dinst_find(key)) == NULL) { | ||
249 : | return DEC_EXIT; | ||
250 : | } | ||
251 : | |||
252 : | /* Change the output colorspace */ | ||
253 : | dcur->xframe.colorspace = | ||
254 : | xvid_to_opendivx_dec_csp(dparam->output_format); | ||
255 : | |||
256 : | return DEC_OK; | ||
257 : | edgomez | 1.9 | } |
258 : | |||
259 : | edgomez | 1.14 | case DEC_OPT_FRAME: |
260 : | { | ||
261 : | int csp_tmp = 0; | ||
262 : | DINST *dcur; | ||
263 : | DEC_FRAME *dframe = (DEC_FRAME *) param1; | ||
264 : | |||
265 : | if ((dcur = dinst_find(key)) == NULL) { | ||
266 : | return DEC_EXIT; | ||
267 : | } | ||
268 : | |||
269 : | /* Copy the divx4 fields to the XviD decoder structure */ | ||
270 : | dcur->xframe.bitstream = dframe->bitstream; | ||
271 : | dcur->xframe.length = dframe->length; | ||
272 : | dcur->xframe.image = dframe->bmp; | ||
273 : | dcur->xframe.stride = dframe->stride; | ||
274 : | |||
275 : | /* Does the frame need to be skipped ? */ | ||
276 : | if (!dframe->render_flag) { | ||
277 : | /* | ||
278 : | * Then we use the null colorspace to force XviD to | ||
279 : | * skip the frame. The original colorspace will be | ||
280 : | * restored after the decoder call | ||
281 : | */ | ||
282 : | csp_tmp = dcur->xframe.colorspace; | ||
283 : | dcur->xframe.colorspace = XVID_CSP_NULL; | ||
284 : | } | ||
285 : | |||
286 : | /* Decode the bitstream */ | ||
287 : | edgomez | 1.21 | xerr = decoder_decode(dcur->handle, &dcur->xframe, NULL); |
288 : | edgomez | 1.14 | |
289 : | /* Restore the real colorspace for this instance */ | ||
290 : | if (!dframe->render_flag) { | ||
291 : | dcur->xframe.colorspace = csp_tmp; | ||
292 : | } | ||
293 : | |||
294 : | break; | ||
295 : | } | ||
296 : | edgomez | 1.9 | |
297 : | edgomez | 1.14 | case DEC_OPT_FRAME_311: |
298 : | edgomez | 1.9 | /* XviD does not handle Divx ;-) 3.11 yet */ |
299 : | return DEC_EXIT; | ||
300 : | |||
301 : | case DEC_OPT_VERSION: | ||
302 : | return EMULATED_DIVX_VERSION; | ||
303 : | |||
304 : | edgomez | 1.14 | default: |
305 : | edgomez | 1.9 | return DEC_EXIT; |
306 : | } | ||
307 : | |||
308 : | |||
309 : | /* XviD error code -> Divx4 */ | ||
310 : | edgomez | 1.14 | switch (xerr) { |
311 : | case XVID_ERR_OK: | ||
312 : | edgomez | 1.9 | return DEC_OK; |
313 : | edgomez | 1.14 | case XVID_ERR_MEMORY: |
314 : | edgomez | 1.9 | return DEC_MEMORY; |
315 : | edgomez | 1.14 | case XVID_ERR_FORMAT: |
316 : | edgomez | 1.9 | return DEC_BAD_FORMAT; |
317 : | edgomez | 1.14 | default: |
318 : | edgomez | 1.9 | return DEC_EXIT; |
319 : | } | ||
320 : | } | ||
321 : | |||
322 : | /************************************************************************** | ||
323 : | * Encore Part | ||
324 : | * | ||
325 : | * encore is the divx4 entry point used to compress a frame to a mpeg4 | ||
326 : | * bitstream. | ||
327 : | *************************************************************************/ | ||
328 : | |||
329 : | #define FRAMERATE_INCR 1001 | ||
330 : | |||
331 : | int | ||
332 : | edgomez | 1.14 | encore(void *handle, |
333 : | int opt, | ||
334 : | void *param1, | ||
335 : | void *param2) | ||
336 : | edgomez | 1.9 | { |
337 : | |||
338 : | int xerr; | ||
339 : | |||
340 : | edgomez | 1.14 | switch (opt) { |
341 : | case ENC_OPT_INIT: | ||
342 : | edgomez | 1.9 | { |
343 : | edgomez | 1.14 | EINST *ecur; |
344 : | ENC_PARAM *eparam = (ENC_PARAM *) param1; | ||
345 : | XVID_INIT_PARAM xinit; | ||
346 : | XVID_ENC_PARAM xparam; | ||
347 : | |||
348 : | /* Init XviD which will detect host cpu features */ | ||
349 : | xinit.cpu_flags = 0; | ||
350 : | xvid_init(NULL, 0, &xinit, NULL); | ||
351 : | |||
352 : | /* Settings are copied to the XviD encoder structure */ | ||
353 : | xparam.width = eparam->x_dim; | ||
354 : | xparam.height = eparam->y_dim; | ||
355 : | if ((eparam->framerate - (int) eparam->framerate) == 0) { | ||
356 : | xparam.fincr = 1; | ||
357 : | xparam.fbase = (int) eparam->framerate; | ||
358 : | } else { | ||
359 : | xparam.fincr = FRAMERATE_INCR; | ||
360 : | xparam.fbase = (int) (FRAMERATE_INCR * eparam->framerate); | ||
361 : | } | ||
362 : | xparam.rc_bitrate = eparam->bitrate; | ||
363 : | xparam.rc_reaction_delay_factor = 16; | ||
364 : | xparam.rc_averaging_period = 100; | ||
365 : | xparam.rc_buffer = 100; | ||
366 : | xparam.min_quantizer = eparam->min_quantizer; | ||
367 : | xparam.max_quantizer = eparam->max_quantizer; | ||
368 : | xparam.max_key_interval = eparam->max_key_interval; | ||
369 : | edgomez | 1.21 | |
370 : | xparam.global = 0; | ||
371 : | xparam.max_bframes = -1; /* use "original" IP-frame encoder */ | ||
372 : | xparam.bquant_ratio = 200; | ||
373 : | xparam.frame_drop_ratio = 0; /* dont drop frames */ | ||
374 : | edgomez | 1.14 | |
375 : | /* Create the encoder session */ | ||
376 : | xerr = encoder_create(&xparam); | ||
377 : | |||
378 : | eparam->handle = xparam.handle; | ||
379 : | |||
380 : | /* Create an encoder instance in the chainlist */ | ||
381 : | if ((ecur = einst_find(xparam.handle)) == NULL) { | ||
382 : | ecur = einst_add(xparam.handle); | ||
383 : | |||
384 : | if (ecur == NULL) { | ||
385 : | encoder_destroy((Encoder *) xparam.handle); | ||
386 : | return ENC_MEMORY; | ||
387 : | } | ||
388 : | |||
389 : | } | ||
390 : | edgomez | 1.9 | |
391 : | edgomez | 1.14 | ecur->quality = eparam->quality; |
392 : | if (ecur->quality < 0) | ||
393 : | ecur->quality = 0; | ||
394 : | if (ecur->quality > 6) | ||
395 : | ecur->quality = 6; | ||
396 : | edgomez | 1.9 | |
397 : | edgomez | 1.14 | break; |
398 : | } | ||
399 : | edgomez | 1.9 | |
400 : | edgomez | 1.14 | case ENC_OPT_RELEASE: |
401 : | edgomez | 1.11 | { |
402 : | edgomez | 1.14 | EINST *ecur; |
403 : | edgomez | 1.11 | |
404 : | edgomez | 1.14 | if ((ecur = einst_find(handle)) == NULL) { |
405 : | return ENC_FAIL; | ||
406 : | edgomez | 1.11 | } |
407 : | |||
408 : | edgomez | 1.14 | einst_remove(handle); |
409 : | xerr = encoder_destroy((Encoder *) handle); | ||
410 : | |||
411 : | break; | ||
412 : | edgomez | 1.11 | } |
413 : | |||
414 : | edgomez | 1.14 | case ENC_OPT_ENCODE: |
415 : | case ENC_OPT_ENCODE_VBR: | ||
416 : | edgomez | 1.11 | { |
417 : | edgomez | 1.14 | EINST *ecur; |
418 : | edgomez | 1.11 | |
419 : | edgomez | 1.14 | ENC_FRAME *eframe = (ENC_FRAME *) param1; |
420 : | ENC_RESULT *eresult = (ENC_RESULT *) param2; | ||
421 : | XVID_ENC_FRAME xframe; | ||
422 : | XVID_ENC_STATS xstats; | ||
423 : | edgomez | 1.9 | |
424 : | edgomez | 1.14 | if ((ecur = einst_find(handle)) == NULL) { |
425 : | return ENC_FAIL; | ||
426 : | } | ||
427 : | edgomez | 1.11 | |
428 : | edgomez | 1.14 | /* Copy the divx4 info into the xvid structure */ |
429 : | xframe.bitstream = eframe->bitstream; | ||
430 : | xframe.length = eframe->length; | ||
431 : | xframe.motion = divx4_motion_presets[ecur->quality]; | ||
432 : | xframe.general = divx4_general_presets[ecur->quality]; | ||
433 : | |||
434 : | xframe.image = eframe->image; | ||
435 : | xframe.colorspace = xvid_to_opendivx_enc_csp(eframe->colorspace); | ||
436 : | |||
437 : | if (opt == ENC_OPT_ENCODE_VBR) { | ||
438 : | xframe.intra = eframe->intra; | ||
439 : | xframe.quant = eframe->quant; | ||
440 : | } else { | ||
441 : | xframe.intra = -1; | ||
442 : | xframe.quant = 0; | ||
443 : | } | ||
444 : | edgomez | 1.9 | |
445 : | edgomez | 1.14 | /* Encode the frame */ |
446 : | xerr = | ||
447 : | encoder_encode((Encoder *) handle, &xframe, | ||
448 : | (eresult ? &xstats : NULL)); | ||
449 : | |||
450 : | /* Copy back the xvid structure to the divx4 one */ | ||
451 : | if (eresult) { | ||
452 : | eresult->is_key_frame = xframe.intra; | ||
453 : | eresult->quantizer = xstats.quant; | ||
454 : | eresult->total_bits = xframe.length * 8; | ||
455 : | eresult->motion_bits = xstats.hlength * 8; | ||
456 : | eresult->texture_bits = | ||
457 : | eresult->total_bits - eresult->motion_bits; | ||
458 : | } | ||
459 : | edgomez | 1.9 | |
460 : | edgomez | 1.14 | eframe->length = xframe.length; |
461 : | edgomez | 1.9 | |
462 : | edgomez | 1.14 | break; |
463 : | edgomez | 1.9 | } |
464 : | |||
465 : | default: | ||
466 : | return ENC_FAIL; | ||
467 : | } | ||
468 : | |||
469 : | /* XviD Error code -> Divx4 error code */ | ||
470 : | edgomez | 1.14 | switch (xerr) { |
471 : | case XVID_ERR_OK: | ||
472 : | edgomez | 1.9 | return ENC_OK; |
473 : | edgomez | 1.14 | case XVID_ERR_MEMORY: |
474 : | edgomez | 1.9 | return ENC_MEMORY; |
475 : | edgomez | 1.14 | case XVID_ERR_FORMAT: |
476 : | edgomez | 1.9 | return ENC_BAD_FORMAT; |
477 : | edgomez | 1.14 | default: |
478 : | edgomez | 1.9 | return ENC_FAIL; |
479 : | } | ||
480 : | } | ||
481 : | |||
482 : | /************************************************************************** | ||
483 : | * Local Functions | ||
484 : | *************************************************************************/ | ||
485 : | Isibaar | 1.1 | |
486 : | edgomez | 1.9 | /*************************************** |
487 : | * DINST chainlist helper functions * | ||
488 : | ***************************************/ | ||
489 : | Isibaar | 1.1 | |
490 : | edgomez | 1.9 | /* Find an element in the chainlist according to its key value */ |
491 : | edgomez | 1.14 | static DINST * |
492 : | dinst_find(unsigned long key) | ||
493 : | Isibaar | 1.1 | { |
494 : | edgomez | 1.14 | DINST *dcur = dhead; |
495 : | Isibaar | 1.1 | |
496 : | edgomez | 1.14 | while (dcur) { |
497 : | if (dcur->key == key) { | ||
498 : | Isibaar | 1.1 | return dcur; |
499 : | } | ||
500 : | dcur = dcur->next; | ||
501 : | } | ||
502 : | |||
503 : | return NULL; | ||
504 : | } | ||
505 : | |||
506 : | |||
507 : | edgomez | 1.9 | /* Add an element to the chainlist */ |
508 : | edgomez | 1.14 | static DINST * |
509 : | dinst_add(unsigned long key) | ||
510 : | Isibaar | 1.1 | { |
511 : | edgomez | 1.14 | DINST *dnext = dhead; |
512 : | Isibaar | 1.1 | |
513 : | dhead = malloc(sizeof(DINST)); | ||
514 : | edgomez | 1.14 | if (dhead == NULL) { |
515 : | Isibaar | 1.1 | dhead = dnext; |
516 : | return NULL; | ||
517 : | } | ||
518 : | |||
519 : | dhead->key = key; | ||
520 : | dhead->next = dnext; | ||
521 : | |||
522 : | return dhead; | ||
523 : | } | ||
524 : | |||
525 : | |||
526 : | edgomez | 1.9 | /* Remove an elmement from the chainlist */ |
527 : | edgomez | 1.14 | static void |
528 : | dinst_remove(unsigned long key) | ||
529 : | Isibaar | 1.1 | { |
530 : | edgomez | 1.14 | DINST *dcur = dhead; |
531 : | Isibaar | 1.1 | |
532 : | edgomez | 1.14 | if (dhead == NULL) { |
533 : | Isibaar | 1.1 | return; |
534 : | } | ||
535 : | |||
536 : | edgomez | 1.14 | if (dcur->key == key) { |
537 : | Isibaar | 1.1 | dhead = dcur->next; |
538 : | free(dcur); | ||
539 : | return; | ||
540 : | } | ||
541 : | |||
542 : | edgomez | 1.14 | while (dcur->next) { |
543 : | if (dcur->next->key == key) { | ||
544 : | DINST *tmp = dcur->next; | ||
545 : | |||
546 : | Isibaar | 1.1 | dcur->next = tmp->next; |
547 : | free(tmp); | ||
548 : | return; | ||
549 : | } | ||
550 : | dcur = dcur->next; | ||
551 : | } | ||
552 : | } | ||
553 : | |||
554 : | edgomez | 1.11 | |
555 : | /*************************************** | ||
556 : | * EINST chainlist helper functions * | ||
557 : | ***************************************/ | ||
558 : | |||
559 : | /* Find an element in the chainlist according to its handle */ | ||
560 : | edgomez | 1.14 | static EINST * |
561 : | einst_find(void *handle) | ||
562 : | edgomez | 1.11 | { |
563 : | edgomez | 1.14 | EINST *ecur = ehead; |
564 : | edgomez | 1.11 | |
565 : | edgomez | 1.14 | while (ecur) { |
566 : | if (ecur->handle == handle) { | ||
567 : | edgomez | 1.11 | return ecur; |
568 : | } | ||
569 : | ecur = ecur->next; | ||
570 : | } | ||
571 : | |||
572 : | return NULL; | ||
573 : | } | ||
574 : | |||
575 : | |||
576 : | /* Add an element to the chainlist */ | ||
577 : | edgomez | 1.14 | static EINST * |
578 : | einst_add(void *handle) | ||
579 : | edgomez | 1.11 | { |
580 : | edgomez | 1.14 | EINST *enext = ehead; |
581 : | edgomez | 1.11 | |
582 : | ehead = malloc(sizeof(EINST)); | ||
583 : | edgomez | 1.14 | if (ehead == NULL) { |
584 : | edgomez | 1.11 | ehead = enext; |
585 : | return NULL; | ||
586 : | } | ||
587 : | |||
588 : | ehead->handle = handle; | ||
589 : | ehead->next = enext; | ||
590 : | |||
591 : | return ehead; | ||
592 : | } | ||
593 : | |||
594 : | |||
595 : | /* Remove an elmement from the chainlist */ | ||
596 : | edgomez | 1.14 | static void |
597 : | einst_remove(void *handle) | ||
598 : | edgomez | 1.11 | { |
599 : | edgomez | 1.14 | EINST *ecur = ehead; |
600 : | edgomez | 1.11 | |
601 : | edgomez | 1.14 | if (ehead == NULL) { |
602 : | edgomez | 1.11 | return; |
603 : | } | ||
604 : | |||
605 : | edgomez | 1.14 | if (ecur->handle == handle) { |
606 : | edgomez | 1.11 | ehead = ecur->next; |
607 : | free(ecur); | ||
608 : | return; | ||
609 : | } | ||
610 : | |||
611 : | edgomez | 1.14 | while (ecur->next) { |
612 : | if (ecur->next->handle == handle) { | ||
613 : | EINST *tmp = ecur->next; | ||
614 : | |||
615 : | edgomez | 1.11 | ecur->next = tmp->next; |
616 : | free(tmp); | ||
617 : | return; | ||
618 : | } | ||
619 : | ecur = ecur->next; | ||
620 : | } | ||
621 : | } | ||
622 : | edgomez | 1.14 | |
623 : | edgomez | 1.9 | /*************************************** |
624 : | * Colorspace code converter * | ||
625 : | ***************************************/ | ||
626 : | Isibaar | 1.1 | |
627 : | edgomez | 1.14 | static int |
628 : | xvid_to_opendivx_dec_csp(int csp) | ||
629 : | Isibaar | 1.1 | { |
630 : | edgomez | 1.9 | |
631 : | edgomez | 1.14 | switch (csp) { |
632 : | case DEC_YV12: | ||
633 : | Isibaar | 1.1 | return XVID_CSP_YV12; |
634 : | edgomez | 1.14 | case DEC_420: |
635 : | Isibaar | 1.1 | return XVID_CSP_I420; |
636 : | edgomez | 1.14 | case DEC_YUY2: |
637 : | Isibaar | 1.1 | return XVID_CSP_YUY2; |
638 : | edgomez | 1.14 | case DEC_UYVY: |
639 : | Isibaar | 1.1 | return XVID_CSP_UYVY; |
640 : | edgomez | 1.14 | case DEC_RGB32: |
641 : | Isibaar | 1.1 | return XVID_CSP_VFLIP | XVID_CSP_RGB32; |
642 : | edgomez | 1.14 | case DEC_RGB24: |
643 : | Isibaar | 1.1 | return XVID_CSP_VFLIP | XVID_CSP_RGB24; |
644 : | edgomez | 1.14 | case DEC_RGB565: |
645 : | Isibaar | 1.1 | return XVID_CSP_VFLIP | XVID_CSP_RGB565; |
646 : | edgomez | 1.14 | case DEC_RGB555: |
647 : | Isibaar | 1.1 | return XVID_CSP_VFLIP | XVID_CSP_RGB555; |
648 : | edgomez | 1.14 | case DEC_RGB32_INV: |
649 : | Isibaar | 1.1 | return XVID_CSP_RGB32; |
650 : | edgomez | 1.14 | case DEC_RGB24_INV: |
651 : | Isibaar | 1.1 | return XVID_CSP_RGB24; |
652 : | edgomez | 1.14 | case DEC_RGB565_INV: |
653 : | Isibaar | 1.1 | return XVID_CSP_RGB565; |
654 : | edgomez | 1.14 | case DEC_RGB555_INV: |
655 : | Isibaar | 1.1 | return XVID_CSP_RGB555; |
656 : | edgomez | 1.14 | case DEC_USER: |
657 : | return XVID_CSP_USER; | ||
658 : | default: | ||
659 : | Isibaar | 1.1 | return -1; |
660 : | } | ||
661 : | } | ||
662 : | |||
663 : | edgomez | 1.14 | static int |
664 : | xvid_to_opendivx_enc_csp(int csp) | ||
665 : | Isibaar | 1.1 | { |
666 : | |||
667 : | edgomez | 1.14 | switch (csp) { |
668 : | case ENC_CSP_RGB24: | ||
669 : | edgomez | 1.9 | return XVID_CSP_VFLIP | XVID_CSP_RGB24; |
670 : | edgomez | 1.14 | case ENC_CSP_YV12: |
671 : | edgomez | 1.9 | return XVID_CSP_YV12; |
672 : | edgomez | 1.14 | case ENC_CSP_YUY2: |
673 : | edgomez | 1.9 | return XVID_CSP_YUY2; |
674 : | edgomez | 1.14 | case ENC_CSP_UYVY: |
675 : | edgomez | 1.9 | return XVID_CSP_UYVY; |
676 : | edgomez | 1.14 | case ENC_CSP_I420: |
677 : | edgomez | 1.9 | return XVID_CSP_I420; |
678 : | edgomez | 1.14 | default: |
679 : | edgomez | 1.9 | return -1; |
680 : | Isibaar | 1.1 | } |
681 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |