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