1 |
/************************************************************************** |
/************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* opendivx api wrapper |
* OpenDivx API wrapper |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* 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 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
37 |
* 22.12.2001 removed some compiler warnings |
* 22.12.2001 removed some compiler warnings |
38 |
* 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
39 |
* |
* |
40 |
|
* $Id: divx4.c,v 1.10 2002-04-28 20:03:14 edgomez Exp $ |
41 |
|
* |
42 |
*************************************************************************/ |
*************************************************************************/ |
43 |
|
|
44 |
|
#include <stdlib.h> |
45 |
#include <malloc.h> |
#include <string.h> |
|
#include <string.h> // memset |
|
46 |
|
|
47 |
#include "xvid.h" |
#include "xvid.h" |
48 |
#include "divx4.h" |
#include "divx4.h" |
51 |
|
|
52 |
#define EMULATED_DIVX_VERSION 20011001 |
#define EMULATED_DIVX_VERSION 20011001 |
53 |
|
|
54 |
// decore |
/************************************************************************** |
55 |
|
* Divx Instance Structure |
56 |
|
* |
57 |
|
* This chain list datatype allows XviD do instanciate multiples divx4 |
58 |
|
* sessions. |
59 |
|
* |
60 |
|
* ToDo : The way this chain list is used does not guarantee reentrance |
61 |
|
* because they are not protected by any kind of mutex to allow |
62 |
|
* only one modifier. We should add a mutex for each element in |
63 |
|
* the chainlist. |
64 |
|
*************************************************************************/ |
65 |
|
|
66 |
|
|
67 |
typedef struct DINST |
typedef struct DINST |
74 |
|
|
75 |
} DINST; |
} DINST; |
76 |
|
|
77 |
|
/************************************************************************** |
78 |
|
* Global data (needed to emulate correctly exported symbols from divx4) |
79 |
|
*************************************************************************/ |
80 |
|
|
81 |
static DINST * dhead = NULL; |
/* This is not used in this module but is required by some divx4 encoders*/ |
82 |
|
int quiet_encore = 1; |
83 |
|
|
84 |
|
/************************************************************************** |
85 |
|
* Local data |
86 |
|
*************************************************************************/ |
87 |
|
|
88 |
DINST * dinst_find(unsigned long key) |
/* The Divx4 instance chainlist */ |
89 |
{ |
static DINST * dhead = NULL; |
|
DINST * dcur = dhead; |
|
90 |
|
|
91 |
while (dcur) |
/* Divx4 quality to XviD encoder motion flag presets */ |
92 |
{ |
static int const divx4_motion_presets[7] = { |
93 |
if (dcur->key == key) |
0, |
|
{ |
|
|
return dcur; |
|
|
} |
|
|
dcur = dcur->next; |
|
|
} |
|
94 |
|
|
95 |
return NULL; |
PMV_QUICKSTOP16, |
|
} |
|
96 |
|
|
97 |
|
PMV_EARLYSTOP16, |
98 |
|
|
99 |
DINST * dinst_add(unsigned long key) |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, |
|
{ |
|
|
DINST * dnext = dhead; |
|
100 |
|
|
101 |
dhead = malloc(sizeof(DINST)); |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | |
102 |
if (dhead == NULL) |
PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, |
|
{ |
|
|
dhead = dnext; |
|
|
return NULL; |
|
|
} |
|
103 |
|
|
104 |
dhead->key = key; |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | |
105 |
dhead->next = dnext; |
PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, |
106 |
|
|
107 |
return dhead; |
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | |
108 |
} |
PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | |
109 |
|
PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 |
110 |
|
}; |
111 |
|
|
112 |
|
|
113 |
void dinst_remove(unsigned long key) |
/* Divx4 quality to general encoder flag presets */ |
114 |
{ |
static int const divx4_general_presets[7] = { |
115 |
DINST * dcur = dhead; |
0, |
116 |
|
XVID_H263QUANT, |
117 |
|
XVID_H263QUANT, |
118 |
|
XVID_H263QUANT | XVID_HALFPEL, |
119 |
|
XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, |
120 |
|
XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, |
121 |
|
XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL |
122 |
|
}; |
123 |
|
|
124 |
if (dhead == NULL) |
/* |
125 |
{ |
* Current divx4 encoder quality |
126 |
return; |
* ToDo : this data should not be shared between encoder instances |
127 |
} |
*/ |
128 |
|
static int quality; |
129 |
|
|
130 |
if (dcur->key == key) |
/************************************************************************** |
131 |
{ |
* Local Prototypes |
132 |
dhead = dcur->next; |
*************************************************************************/ |
|
free(dcur); |
|
|
return; |
|
|
} |
|
133 |
|
|
134 |
while (dcur->next) |
/* Chain list helper functions */ |
135 |
{ |
static DINST * dinst_find(unsigned long key); |
136 |
if (dcur->next->key == key) |
static DINST * dinst_add(unsigned long key); |
137 |
{ |
static void dinst_remove(unsigned long key); |
138 |
DINST * tmp = dcur->next; |
|
139 |
dcur->next = tmp->next; |
/* Converts divx4 colorspaces codes to xvid codes */ |
140 |
free(tmp); |
static int xvid_to_opendivx_dec_csp(int csp); |
141 |
return; |
static int xvid_to_opendivx_enc_csp(int csp); |
|
} |
|
|
dcur = dcur->next; |
|
|
} |
|
|
} |
|
142 |
|
|
143 |
|
/************************************************************************** |
144 |
|
* decore part |
145 |
|
* |
146 |
|
* decore is the divx4 entry point used to decompress the mpeg4 bitstream |
147 |
|
* into a user defined image format. |
148 |
|
*************************************************************************/ |
149 |
|
|
150 |
int xvid_to_opendivx_dec_csp(int csp) |
int |
151 |
{ |
decore(unsigned long key, unsigned long opt, void * param1, void * param2) |
|
switch(csp) |
|
152 |
{ |
{ |
|
case DEC_YV12 : |
|
|
return XVID_CSP_YV12; |
|
|
case DEC_420 : |
|
|
return XVID_CSP_I420; |
|
|
case DEC_YUY2 : |
|
|
return XVID_CSP_YUY2; |
|
|
case DEC_UYVY : |
|
|
return XVID_CSP_UYVY; |
|
|
case DEC_RGB32 : |
|
|
return XVID_CSP_VFLIP | XVID_CSP_RGB32; |
|
|
case DEC_RGB24 : |
|
|
return XVID_CSP_VFLIP | XVID_CSP_RGB24; |
|
|
case DEC_RGB565 : |
|
|
return XVID_CSP_VFLIP | XVID_CSP_RGB565; |
|
|
case DEC_RGB555 : |
|
|
return XVID_CSP_VFLIP | XVID_CSP_RGB555; |
|
|
case DEC_RGB32_INV : |
|
|
return XVID_CSP_RGB32; |
|
|
case DEC_RGB24_INV : |
|
|
return XVID_CSP_RGB24; |
|
|
case DEC_RGB565_INV : |
|
|
return XVID_CSP_RGB565; |
|
|
case DEC_RGB555_INV : |
|
|
return XVID_CSP_RGB555; |
|
|
case DEC_USER : |
|
|
return XVID_CSP_USER; |
|
|
default : |
|
|
return -1; |
|
|
} |
|
|
} |
|
153 |
|
|
|
|
|
|
int decore(unsigned long key, unsigned long opt, |
|
|
void * param1, void * param2) |
|
|
{ |
|
154 |
int xerr; |
int xerr; |
155 |
|
|
156 |
switch (opt) |
switch (opt) { |
157 |
{ |
|
158 |
case DEC_OPT_MEMORY_REQS : |
case DEC_OPT_MEMORY_REQS : |
159 |
{ |
{ |
160 |
memset(param2, 0, sizeof(DEC_MEM_REQS)); |
memset(param2, 0, sizeof(DEC_MEM_REQS)); |
163 |
|
|
164 |
case DEC_OPT_INIT : |
case DEC_OPT_INIT : |
165 |
{ |
{ |
|
DEC_PARAM * dparam = (DEC_PARAM *)param1; |
|
166 |
XVID_INIT_PARAM xinit; |
XVID_INIT_PARAM xinit; |
167 |
XVID_DEC_PARAM xparam; |
XVID_DEC_PARAM xparam; |
168 |
DINST * dcur = dinst_find(key); |
DINST * dcur; |
169 |
if (dcur == NULL) |
DEC_PARAM * dparam = (DEC_PARAM *)param1; |
170 |
|
|
171 |
|
/* Find the divx4 instance */ |
172 |
|
if ((dcur = dinst_find(key)) == NULL) |
173 |
{ |
{ |
174 |
dcur = dinst_add(key); |
dcur = dinst_add(key); |
175 |
} |
} |
176 |
|
|
177 |
|
/* |
178 |
|
* XviD initialization |
179 |
|
* XviD will detect the host cpu type and activate optimized |
180 |
|
* functions according to the host cpu features. |
181 |
|
*/ |
182 |
xinit.cpu_flags = 0; |
xinit.cpu_flags = 0; |
183 |
xvid_init(NULL, 0, &xinit, NULL); |
xvid_init(NULL, 0, &xinit, NULL); |
184 |
|
|
185 |
|
/* XviD decoder initialization for this instance */ |
186 |
xparam.width = dparam->x_dim; |
xparam.width = dparam->x_dim; |
187 |
xparam.height = dparam->y_dim; |
xparam.height = dparam->y_dim; |
188 |
dcur->xframe.colorspace = xvid_to_opendivx_dec_csp(dparam->output_format); |
dcur->xframe.colorspace = |
189 |
|
xvid_to_opendivx_dec_csp(dparam->output_format); |
190 |
|
|
191 |
xerr = decoder_create(&xparam); |
xerr = decoder_create(&xparam); |
192 |
|
|
193 |
|
/* Store the xvid handle into the divx4 instance chainlist */ |
194 |
dcur->handle = xparam.handle; |
dcur->handle = xparam.handle; |
195 |
|
|
196 |
break; |
break; |
198 |
|
|
199 |
case DEC_OPT_RELEASE : |
case DEC_OPT_RELEASE : |
200 |
{ |
{ |
201 |
DINST * dcur = dinst_find(key); |
DINST * dcur; |
202 |
if (dcur == NULL) |
|
203 |
|
/* Find the divx4 instance into the chain list */ |
204 |
|
if ((dcur = dinst_find(key)) == NULL) |
205 |
{ |
{ |
206 |
return DEC_EXIT; |
return DEC_EXIT; |
207 |
} |
} |
208 |
|
|
209 |
|
/* Destroy the XviD decoder attached to this divx4 instance */ |
210 |
xerr = decoder_destroy(dcur->handle); |
xerr = decoder_destroy(dcur->handle); |
211 |
|
|
212 |
|
/* Remove the divx4 instance from the chainlist */ |
213 |
dinst_remove(key); |
dinst_remove(key); |
214 |
|
|
215 |
break; |
break; |
217 |
|
|
218 |
case DEC_OPT_SETPP : |
case DEC_OPT_SETPP : |
219 |
{ |
{ |
220 |
// DEC_SET * dset = (DEC_SET *)param1; |
DINST * dcur; |
221 |
DINST * dcur = dinst_find(key); |
|
222 |
if (dcur == NULL) |
/* Find the divx4 instance into the chain list */ |
223 |
|
if ((dcur = dinst_find(key)) == NULL) |
224 |
{ |
{ |
225 |
return DEC_EXIT; |
return DEC_EXIT; |
226 |
} |
} |
227 |
|
|
228 |
// dcur->xframe.pp = dset->postproc_level; |
/* |
229 |
|
* We return DEC_OK but XviD has no postprocessing implemented |
230 |
|
* in core. |
231 |
|
*/ |
232 |
return DEC_OK; |
return DEC_OK; |
233 |
} |
} |
234 |
|
|
235 |
case DEC_OPT_SETOUT : |
case DEC_OPT_SETOUT : |
236 |
{ |
{ |
237 |
|
DINST * dcur; |
238 |
DEC_PARAM * dparam = (DEC_PARAM *)param1; |
DEC_PARAM * dparam = (DEC_PARAM *)param1; |
239 |
DINST * dcur = dinst_find(key); |
|
240 |
if (dcur == NULL) |
if ((dcur = dinst_find(key)) == NULL) |
241 |
{ |
{ |
242 |
return DEC_EXIT; |
return DEC_EXIT; |
243 |
} |
} |
244 |
|
|
245 |
dcur->xframe.colorspace = xvid_to_opendivx_dec_csp(dparam->output_format); |
/* Change the output colorspace */ |
246 |
|
dcur->xframe.colorspace = |
247 |
|
xvid_to_opendivx_dec_csp(dparam->output_format); |
248 |
|
|
249 |
return DEC_OK; |
return DEC_OK; |
250 |
} |
} |
252 |
case DEC_OPT_FRAME: |
case DEC_OPT_FRAME: |
253 |
{ |
{ |
254 |
int csp_tmp = 0; |
int csp_tmp = 0; |
255 |
|
DINST * dcur; |
256 |
DEC_FRAME * dframe = (DEC_FRAME *)param1; |
DEC_FRAME * dframe = (DEC_FRAME *)param1; |
257 |
DINST * dcur = dinst_find(key); |
|
258 |
if (dcur == NULL) |
if ((dcur = dinst_find(key)) == NULL) |
259 |
{ |
{ |
260 |
return DEC_EXIT; |
return DEC_EXIT; |
261 |
} |
} |
262 |
|
|
263 |
|
/* Copy the divx4 fields to the XviD decoder structure */ |
264 |
dcur->xframe.bitstream = dframe->bitstream; |
dcur->xframe.bitstream = dframe->bitstream; |
265 |
dcur->xframe.length = dframe->length; |
dcur->xframe.length = dframe->length; |
266 |
dcur->xframe.image = dframe->bmp; |
dcur->xframe.image = dframe->bmp; |
267 |
dcur->xframe.stride = dframe->stride; |
dcur->xframe.stride = dframe->stride; |
268 |
|
|
269 |
|
/* Does the frame need to be skipped ? */ |
270 |
if (!dframe->render_flag) |
if (!dframe->render_flag) |
271 |
{ |
{ |
272 |
|
/* |
273 |
|
* Then we use the null colorspace to force XviD to |
274 |
|
* skip the frame. The original colorspace will be |
275 |
|
* restored after the decoder call |
276 |
|
*/ |
277 |
csp_tmp = dcur->xframe.colorspace; |
csp_tmp = dcur->xframe.colorspace; |
278 |
dcur->xframe.colorspace = XVID_CSP_NULL; |
dcur->xframe.colorspace = XVID_CSP_NULL; |
279 |
} |
} |
280 |
|
|
281 |
|
/* Decode the bitstream */ |
282 |
xerr = decoder_decode(dcur->handle, &dcur->xframe); |
xerr = decoder_decode(dcur->handle, &dcur->xframe); |
283 |
|
|
284 |
|
/* Restore the real colorspace for this instance */ |
285 |
if (!dframe->render_flag) |
if (!dframe->render_flag) |
286 |
{ |
{ |
287 |
dcur->xframe.colorspace = csp_tmp; |
dcur->xframe.colorspace = csp_tmp; |
290 |
break; |
break; |
291 |
} |
} |
292 |
|
|
|
|
|
293 |
case DEC_OPT_FRAME_311 : |
case DEC_OPT_FRAME_311 : |
294 |
|
/* XviD does not handle Divx ;-) 3.11 yet */ |
295 |
return DEC_EXIT; |
return DEC_EXIT; |
296 |
|
|
|
|
|
297 |
case DEC_OPT_VERSION: |
case DEC_OPT_VERSION: |
298 |
return EMULATED_DIVX_VERSION; |
return EMULATED_DIVX_VERSION; |
299 |
|
|
300 |
default : |
default : |
301 |
return DEC_EXIT; |
return DEC_EXIT; |
302 |
} |
} |
303 |
|
|
304 |
|
|
305 |
|
/* XviD error code -> Divx4 */ |
306 |
switch(xerr) |
switch(xerr) |
307 |
{ |
{ |
308 |
case XVID_ERR_OK : return DEC_OK; |
case XVID_ERR_OK : |
309 |
case XVID_ERR_MEMORY : return DEC_MEMORY; |
return DEC_OK; |
310 |
case XVID_ERR_FORMAT : return DEC_BAD_FORMAT; |
case XVID_ERR_MEMORY : |
311 |
default : // case XVID_ERR_FAIL : |
return DEC_MEMORY; |
312 |
|
case XVID_ERR_FORMAT : |
313 |
|
return DEC_BAD_FORMAT; |
314 |
|
default : |
315 |
return DEC_EXIT; |
return DEC_EXIT; |
316 |
} |
} |
317 |
} |
} |
318 |
|
|
319 |
|
/************************************************************************** |
320 |
|
* Encore Part |
321 |
|
* |
322 |
// encore |
* encore is the divx4 entry point used to compress a frame to a mpeg4 |
323 |
|
* bitstream. |
324 |
|
*************************************************************************/ |
325 |
|
|
326 |
#define FRAMERATE_INCR 1001 |
#define FRAMERATE_INCR 1001 |
327 |
|
|
328 |
int divx4_motion_presets[7] = { |
int |
329 |
0, PMV_QUICKSTOP16, PMV_EARLYSTOP16, PMV_EARLYSTOP16 | PMV_EARLYSTOP8, |
encore(void * handle, int opt, void * param1, void * param2) |
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, |
|
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, |
|
|
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | |
|
|
PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 |
|
|
}; |
|
|
|
|
|
int quality; |
|
|
|
|
|
int encore(void * handle, int opt, void * param1, void * param2) |
|
330 |
{ |
{ |
331 |
|
|
332 |
int xerr; |
int xerr; |
333 |
|
|
334 |
switch(opt) |
switch(opt) { |
|
{ |
|
335 |
case ENC_OPT_INIT : |
case ENC_OPT_INIT : |
336 |
{ |
{ |
337 |
ENC_PARAM * eparam = (ENC_PARAM *)param1; |
ENC_PARAM * eparam = (ENC_PARAM *)param1; |
338 |
XVID_INIT_PARAM xinit; |
XVID_INIT_PARAM xinit; |
339 |
XVID_ENC_PARAM xparam; |
XVID_ENC_PARAM xparam; |
340 |
|
|
341 |
|
/* Init XviD which will detect host cpu features */ |
342 |
xinit.cpu_flags = 0; |
xinit.cpu_flags = 0; |
343 |
xvid_init(NULL, 0, &xinit, NULL); |
xvid_init(NULL, 0, &xinit, NULL); |
344 |
|
|
345 |
|
/* Settings are copied to the XviD encoder structure */ |
346 |
xparam.width = eparam->x_dim; |
xparam.width = eparam->x_dim; |
347 |
xparam.height = eparam->y_dim; |
xparam.height = eparam->y_dim; |
348 |
if ((eparam->framerate - (int)eparam->framerate) == 0) |
if ((eparam->framerate - (int)eparam->framerate) == 0) |
355 |
xparam.fincr = FRAMERATE_INCR; |
xparam.fincr = FRAMERATE_INCR; |
356 |
xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate); |
xparam.fbase = (int)(FRAMERATE_INCR * eparam->framerate); |
357 |
} |
} |
358 |
xparam.bitrate = eparam->bitrate; |
xparam.rc_bitrate = eparam->bitrate; |
359 |
xparam.rc_buffersize = 10 * eparam->bitrate; |
xparam.rc_reaction_delay_factor = 16; |
360 |
|
xparam.rc_averaging_period = 100; |
361 |
|
xparam.rc_buffer = 100; |
362 |
xparam.min_quantizer = eparam->min_quantizer; |
xparam.min_quantizer = eparam->min_quantizer; |
363 |
xparam.max_quantizer = eparam->max_quantizer; |
xparam.max_quantizer = eparam->max_quantizer; |
364 |
xparam.max_key_interval = eparam->max_key_interval; |
xparam.max_key_interval = eparam->max_key_interval; |
365 |
quality = eparam->quality; |
quality = eparam->quality; |
366 |
|
|
367 |
|
/* Create the encoder session */ |
368 |
xerr = encoder_create(&xparam); |
xerr = encoder_create(&xparam); |
369 |
|
|
370 |
eparam->handle = xparam.handle; |
eparam->handle = xparam.handle; |
386 |
XVID_ENC_FRAME xframe; |
XVID_ENC_FRAME xframe; |
387 |
XVID_ENC_STATS xstats; |
XVID_ENC_STATS xstats; |
388 |
|
|
389 |
|
/* Copy the divx4 info into the xvid structure */ |
390 |
xframe.bitstream = eframe->bitstream; |
xframe.bitstream = eframe->bitstream; |
391 |
xframe.length = eframe->length; |
xframe.length = eframe->length; |
392 |
|
|
|
xframe.general = XVID_HALFPEL | XVID_H263QUANT; |
|
|
|
|
|
if(quality > 3) |
|
|
xframe.general |= XVID_INTER4V; |
|
|
|
|
393 |
xframe.motion = divx4_motion_presets[quality]; |
xframe.motion = divx4_motion_presets[quality]; |
394 |
|
xframe.general = divx4_general_presets[quality]; |
395 |
|
|
396 |
xframe.image = eframe->image; |
xframe.image = eframe->image; |
397 |
switch (eframe->colorspace) |
xframe.colorspace = |
398 |
{ |
xvid_to_opendivx_enc_csp(eframe->colorspace); |
|
case ENC_CSP_RGB24 : |
|
|
xframe.colorspace = XVID_CSP_VFLIP | XVID_CSP_RGB24; |
|
|
break; |
|
|
case ENC_CSP_YV12 : |
|
|
xframe.colorspace = XVID_CSP_YV12; |
|
|
break; |
|
|
case ENC_CSP_YUY2 : |
|
|
xframe.colorspace = XVID_CSP_YUY2; |
|
|
break; |
|
|
case ENC_CSP_UYVY : |
|
|
xframe.colorspace = XVID_CSP_UYVY; |
|
|
break; |
|
|
case ENC_CSP_I420 : |
|
|
xframe.colorspace = XVID_CSP_I420; |
|
|
break; |
|
|
} |
|
399 |
|
|
400 |
if (opt == ENC_OPT_ENCODE_VBR) |
if (opt == ENC_OPT_ENCODE_VBR) |
401 |
{ |
{ |
408 |
xframe.quant = 0; |
xframe.quant = 0; |
409 |
} |
} |
410 |
|
|
411 |
|
/* Encode the frame */ |
412 |
xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) ); |
xerr = encoder_encode((Encoder *) handle, &xframe, (eresult ? &xstats : NULL) ); |
413 |
|
|
414 |
|
/* Copy back the xvid structure to the divx4 one */ |
415 |
if (eresult) |
if (eresult) |
416 |
{ |
{ |
417 |
eresult->is_key_frame = xframe.intra; |
eresult->is_key_frame = xframe.intra; |
430 |
return ENC_FAIL; |
return ENC_FAIL; |
431 |
} |
} |
432 |
|
|
433 |
|
/* XviD Error code -> Divx4 error code */ |
434 |
switch(xerr) |
switch(xerr) |
435 |
{ |
{ |
436 |
case XVID_ERR_OK : return ENC_OK; |
case XVID_ERR_OK : |
437 |
case XVID_ERR_MEMORY : return ENC_MEMORY; |
return ENC_OK; |
438 |
case XVID_ERR_FORMAT : return ENC_BAD_FORMAT; |
case XVID_ERR_MEMORY : |
439 |
default : // case XVID_ERR_FAIL : |
return ENC_MEMORY; |
440 |
|
case XVID_ERR_FORMAT : |
441 |
|
return ENC_BAD_FORMAT; |
442 |
|
default : |
443 |
return ENC_FAIL; |
return ENC_FAIL; |
444 |
} |
} |
445 |
} |
} |
446 |
|
|
447 |
|
/************************************************************************** |
448 |
|
* Local Functions |
449 |
|
*************************************************************************/ |
450 |
|
|
451 |
|
/*************************************** |
452 |
|
* DINST chainlist helper functions * |
453 |
|
***************************************/ |
454 |
|
|
455 |
|
/* Find an element in the chainlist according to its key value */ |
456 |
|
static DINST * dinst_find(unsigned long key) |
457 |
|
{ |
458 |
|
DINST * dcur = dhead; |
459 |
|
|
460 |
|
while (dcur) |
461 |
|
{ |
462 |
|
if (dcur->key == key) |
463 |
|
{ |
464 |
|
return dcur; |
465 |
|
} |
466 |
|
dcur = dcur->next; |
467 |
|
} |
468 |
|
|
469 |
|
return NULL; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
/* Add an element to the chainlist */ |
474 |
|
static DINST * dinst_add(unsigned long key) |
475 |
|
{ |
476 |
|
DINST * dnext = dhead; |
477 |
|
|
478 |
|
dhead = malloc(sizeof(DINST)); |
479 |
|
if (dhead == NULL) |
480 |
|
{ |
481 |
|
dhead = dnext; |
482 |
|
return NULL; |
483 |
|
} |
484 |
|
|
485 |
|
dhead->key = key; |
486 |
|
dhead->next = dnext; |
487 |
|
|
488 |
|
return dhead; |
489 |
|
} |
490 |
|
|
491 |
|
|
492 |
|
/* Remove an elmement from the chainlist */ |
493 |
|
static void dinst_remove(unsigned long key) |
494 |
|
{ |
495 |
|
DINST * dcur = dhead; |
496 |
|
|
497 |
|
if (dhead == NULL) |
498 |
|
{ |
499 |
|
return; |
500 |
|
} |
501 |
|
|
502 |
|
if (dcur->key == key) |
503 |
|
{ |
504 |
|
dhead = dcur->next; |
505 |
|
free(dcur); |
506 |
|
return; |
507 |
|
} |
508 |
|
|
509 |
|
while (dcur->next) |
510 |
|
{ |
511 |
|
if (dcur->next->key == key) |
512 |
|
{ |
513 |
|
DINST * tmp = dcur->next; |
514 |
|
dcur->next = tmp->next; |
515 |
|
free(tmp); |
516 |
|
return; |
517 |
|
} |
518 |
|
dcur = dcur->next; |
519 |
|
} |
520 |
|
} |
521 |
|
|
522 |
|
/*************************************** |
523 |
|
* Colorspace code converter * |
524 |
|
***************************************/ |
525 |
|
|
526 |
|
static int xvid_to_opendivx_dec_csp(int csp) |
527 |
|
{ |
528 |
|
|
529 |
|
switch(csp) |
530 |
|
{ |
531 |
|
case DEC_YV12 : |
532 |
|
return XVID_CSP_YV12; |
533 |
|
case DEC_420 : |
534 |
|
return XVID_CSP_I420; |
535 |
|
case DEC_YUY2 : |
536 |
|
return XVID_CSP_YUY2; |
537 |
|
case DEC_UYVY : |
538 |
|
return XVID_CSP_UYVY; |
539 |
|
case DEC_RGB32 : |
540 |
|
return XVID_CSP_VFLIP | XVID_CSP_RGB32; |
541 |
|
case DEC_RGB24 : |
542 |
|
return XVID_CSP_VFLIP | XVID_CSP_RGB24; |
543 |
|
case DEC_RGB565 : |
544 |
|
return XVID_CSP_VFLIP | XVID_CSP_RGB565; |
545 |
|
case DEC_RGB555 : |
546 |
|
return XVID_CSP_VFLIP | XVID_CSP_RGB555; |
547 |
|
case DEC_RGB32_INV : |
548 |
|
return XVID_CSP_RGB32; |
549 |
|
case DEC_RGB24_INV : |
550 |
|
return XVID_CSP_RGB24; |
551 |
|
case DEC_RGB565_INV : |
552 |
|
return XVID_CSP_RGB565; |
553 |
|
case DEC_RGB555_INV : |
554 |
|
return XVID_CSP_RGB555; |
555 |
|
case DEC_USER : |
556 |
|
return XVID_CSP_USER; |
557 |
|
default : |
558 |
|
return -1; |
559 |
|
} |
560 |
|
} |
561 |
|
|
562 |
|
static int xvid_to_opendivx_enc_csp(int csp) |
563 |
|
{ |
564 |
|
|
565 |
|
switch (csp) |
566 |
|
{ |
567 |
|
case ENC_CSP_RGB24 : |
568 |
|
return XVID_CSP_VFLIP | XVID_CSP_RGB24; |
569 |
|
case ENC_CSP_YV12 : |
570 |
|
return XVID_CSP_YV12; |
571 |
|
case ENC_CSP_YUY2 : |
572 |
|
return XVID_CSP_YUY2; |
573 |
|
case ENC_CSP_UYVY : |
574 |
|
return XVID_CSP_UYVY; |
575 |
|
case ENC_CSP_I420 : |
576 |
|
return XVID_CSP_I420; |
577 |
|
default : |
578 |
|
return -1; |
579 |
|
} |
580 |
|
} |