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