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