3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Console based decoding test application - |
* - Console based decoding test application - |
5 |
* |
* |
6 |
* Copyright(C) 2002 Christoph Lampert |
* Copyright(C) 2002-2003 Christoph Lampert |
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: xvid_decraw.c,v 1.3 2002-09-27 20:58:30 edgomez Exp $ |
* $Id: xvid_decraw.c,v 1.7.2.1 2003-03-11 23:39:47 edgomez Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
41 |
* Usage : xvid_decraw <-w width> <-h height> [OPTIONS] |
* Usage : xvid_decraw <-w width> <-h height> [OPTIONS] |
42 |
* Options : |
* Options : |
43 |
* -asm : use assembly optimizations (default=disabled) |
* -asm : use assembly optimizations (default=disabled) |
|
* -w integer : frame width ([1.2048]) |
|
|
* -h integer : frame height ([1.2048]) |
|
44 |
* -i string : input filename (default=stdin) |
* -i string : input filename (default=stdin) |
45 |
* -t integer : input data type (raw=0, mp4u=1) |
* -t integer : input data type (raw=0, mp4u=1) |
46 |
* -d boolean : save decoder output (0 False*, !=0 True) |
* -d : save decoder output (0 False*, !=0 True) |
47 |
* -m boolean : save mpeg4 raw stream to single files (0 False*, !=0 True) |
* -m : save mpeg4 raw stream to single files (0 False*, !=0 True) |
48 |
* -help : This help message |
* -help : This help message |
49 |
* (* means default) |
* (* means default) |
50 |
* |
* |
54 |
#include <stdlib.h> |
#include <stdlib.h> |
55 |
#include <string.h> |
#include <string.h> |
56 |
#include <math.h> |
#include <math.h> |
57 |
#ifndef _MSC_VER |
#ifndef WIN32 |
58 |
#include <sys/time.h> |
#include <sys/time.h> |
59 |
#else |
#else |
60 |
#include <time.h> |
#include <time.h> |
73 |
static int YDIM = 0; |
static int YDIM = 0; |
74 |
static int ARG_SAVEDECOUTPUT = 0; |
static int ARG_SAVEDECOUTPUT = 0; |
75 |
static int ARG_SAVEMPEGSTREAM = 0; |
static int ARG_SAVEMPEGSTREAM = 0; |
|
static int ARG_STREAMTYPE = 0; |
|
76 |
static char *ARG_INPUTFILE = NULL; |
static char *ARG_INPUTFILE = NULL; |
77 |
|
|
78 |
|
|
79 |
static char filepath[256] = "./"; |
static char filepath[256] = "./"; |
80 |
static void *dec_handle = NULL; |
static void *dec_handle = NULL; |
81 |
|
|
82 |
# define BUFFER_SIZE 10*XDIM*YDIM |
# define BUFFER_SIZE (2*1024*1024) |
|
|
|
|
#define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \ |
|
|
(((long)(c))<<8) |((long)(d))) |
|
|
|
|
|
#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ |
|
|
(((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) |
|
83 |
|
|
84 |
/***************************************************************************** |
/***************************************************************************** |
85 |
* Local prototypes |
* Local prototypes |
92 |
static int dec_main(unsigned char *istream, |
static int dec_main(unsigned char *istream, |
93 |
unsigned char *ostream, |
unsigned char *ostream, |
94 |
int istream_size, |
int istream_size, |
95 |
int *ostream_size); |
xvid_dec_stats_t *xvid_dec_stats); |
96 |
static int dec_stop(); |
static int dec_stop(); |
97 |
static void usage(); |
static void usage(); |
98 |
|
|
105 |
unsigned char *mp4_buffer = NULL; |
unsigned char *mp4_buffer = NULL; |
106 |
unsigned char *mp4_ptr = NULL; |
unsigned char *mp4_ptr = NULL; |
107 |
unsigned char *out_buffer = NULL; |
unsigned char *out_buffer = NULL; |
108 |
int bigendian = 0; |
unsigned char *type = NULL; |
109 |
|
int still_left_in_buffer; |
110 |
|
int delayed_frames; |
111 |
|
xvid_dec_stats_t xvid_dec_stats; |
112 |
|
|
113 |
double totaldectime; |
double totaldectime; |
114 |
|
|
124 |
int i; |
int i; |
125 |
|
|
126 |
printf("xvid_decraw - raw mpeg4 bitstream decoder "); |
printf("xvid_decraw - raw mpeg4 bitstream decoder "); |
127 |
printf("written by Christoph Lampert 2002\n\n"); |
printf("written by Christoph Lampert 2002-2003\n\n"); |
128 |
|
|
129 |
/***************************************************************************** |
/***************************************************************************** |
130 |
* Command line parsing |
* Command line parsing |
135 |
if (strcmp("-asm", argv[i]) == 0 ) { |
if (strcmp("-asm", argv[i]) == 0 ) { |
136 |
use_assembler = 1; |
use_assembler = 1; |
137 |
} |
} |
138 |
else if (strcmp("-w", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-d", argv[i]) == 0) { |
139 |
i++; |
ARG_SAVEDECOUTPUT = 1; |
|
XDIM = atoi(argv[i]); |
|
|
} |
|
|
else if (strcmp("-h", argv[i]) == 0 && i < argc - 1 ) { |
|
|
i++; |
|
|
YDIM = atoi(argv[i]); |
|
|
} |
|
|
else if (strcmp("-d", argv[i]) == 0 && i < argc - 1 ) { |
|
|
i++; |
|
|
ARG_SAVEDECOUTPUT = atoi(argv[i]); |
|
140 |
} |
} |
141 |
else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) { |
142 |
i++; |
i++; |
143 |
ARG_INPUTFILE = argv[i]; |
ARG_INPUTFILE = argv[i]; |
144 |
} |
} |
145 |
else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) { |
else if (strcmp("-m", argv[i]) == 0) { |
146 |
i++; |
ARG_SAVEMPEGSTREAM = 1; |
|
ARG_SAVEMPEGSTREAM = atoi(argv[i]); |
|
|
} |
|
|
else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) { |
|
|
i++; |
|
|
ARG_STREAMTYPE = atoi(argv[i]); |
|
147 |
} |
} |
148 |
else if (strcmp("-help", argv[i])) { |
else if (strcmp("-help", argv[i])) { |
149 |
usage(); |
usage(); |
160 |
* Values checking |
* Values checking |
161 |
****************************************************************************/ |
****************************************************************************/ |
162 |
|
|
|
if(XDIM <= 0 || XDIM > 2048 || YDIM <= 0 || YDIM > 2048) { |
|
|
usage(); |
|
|
return -1; |
|
|
} |
|
|
|
|
163 |
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
164 |
in_file = stdin; |
in_file = stdin; |
165 |
} |
} |
168 |
in_file = fopen(ARG_INPUTFILE, "rb"); |
in_file = fopen(ARG_INPUTFILE, "rb"); |
169 |
if (in_file == NULL) { |
if (in_file == NULL) { |
170 |
fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE); |
fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE); |
171 |
return -1; |
return(-1); |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
182 |
if (!mp4_buffer) |
if (!mp4_buffer) |
183 |
goto free_all_memory; |
goto free_all_memory; |
184 |
|
|
|
/* Memory for frame output */ |
|
|
out_buffer = (unsigned char *) malloc(XDIM*YDIM*4); |
|
|
if (!out_buffer) |
|
|
goto free_all_memory; |
|
|
|
|
|
|
|
185 |
/***************************************************************************** |
/***************************************************************************** |
186 |
* XviD PART Start |
* XviD PART Start |
187 |
****************************************************************************/ |
****************************************************************************/ |
198 |
* Main loop |
* Main loop |
199 |
****************************************************************************/ |
****************************************************************************/ |
200 |
|
|
201 |
if(ARG_STREAMTYPE) { |
/* Fill the buffer */ |
202 |
|
still_left_in_buffer = fread(mp4_buffer, 1, BUFFER_SIZE, in_file); |
|
unsigned char header[4]; |
|
|
|
|
|
/* MP4U format : read header */ |
|
|
if(feof(in_file)) |
|
|
goto release_all; |
|
|
fread(header, 4, 1, in_file); |
|
|
|
|
|
if(header[0] != '2' || header[1] != 'M' || |
|
|
header[2] != 'O' || header[3] != 'G') { |
|
|
fprintf(stderr, "Error, this not a mp4u container file\n"); |
|
|
goto release_all; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
totalsize = LONG_PACK('M','P','4','U'); |
|
|
mp4_ptr = (unsigned char *)&totalsize; |
|
|
if(*mp4_ptr == 'M') |
|
|
bigendian = 1; |
|
|
else |
|
|
bigendian = 0; |
|
203 |
|
|
204 |
totaldectime = 0; |
totaldectime = 0; |
205 |
totalsize = 0; |
totalsize = 0; |
206 |
filenr = 0; |
filenr = 0; |
207 |
|
delayed_frames = 0; |
208 |
mp4_ptr = mp4_buffer; |
mp4_ptr = mp4_buffer; |
209 |
|
|
210 |
do { |
do { |
213 |
int used_bytes = 0; |
int used_bytes = 0; |
214 |
double dectime; |
double dectime; |
215 |
|
|
|
/* Read data from input file */ |
|
|
if(ARG_STREAMTYPE) { |
|
|
|
|
|
/* MP4U container */ |
|
|
|
|
|
/* Read stream size first */ |
|
|
if(feof(in_file)) |
|
|
break; |
|
|
fread(&mp4_size, sizeof(long), 1, in_file); |
|
|
|
|
|
if(bigendian) |
|
|
mp4_size = SWAP(mp4_size); |
|
|
|
|
|
/* Read mp4_size_bytes */ |
|
|
if(feof(in_file)) |
|
|
break; |
|
|
fread(mp4_buffer, mp4_size, 1, in_file); |
|
|
|
|
216 |
/* |
/* |
217 |
* When reading mp4u, we don't have to care about buffer |
* If the buffer is half empty or there are no more bytes in it |
218 |
* filling as we know exactly how much bytes there are in |
* then fill it. |
|
* next frame |
|
219 |
*/ |
*/ |
220 |
mp4_ptr = mp4_buffer; |
if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2 || |
221 |
|
still_left_in_buffer <= 0) { |
|
} |
|
|
else { |
|
|
|
|
|
/* Real raw stream */ |
|
|
|
|
|
/* buffer more than half empty -> Fill it */ |
|
|
if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) { |
|
222 |
int rest = (mp4_buffer + BUFFER_SIZE - mp4_ptr); |
int rest = (mp4_buffer + BUFFER_SIZE - mp4_ptr); |
223 |
|
|
224 |
/* Move data if needed */ |
/* Move data if needed */ |
231 |
/* read new data */ |
/* read new data */ |
232 |
if(feof(in_file)) |
if(feof(in_file)) |
233 |
break; |
break; |
234 |
fread(mp4_buffer + rest, BUFFER_SIZE - rest, 1, in_file); |
|
235 |
} |
still_left_in_buffer = fread(mp4_buffer + rest, |
236 |
|
1, |
237 |
|
BUFFER_SIZE - rest, |
238 |
|
in_file); |
239 |
|
|
240 |
} |
} |
241 |
|
|
242 |
|
|
243 |
|
/* This loop is needed to handle VOL/NVOP reading */ |
244 |
|
do { |
245 |
|
|
246 |
/* Decode frame */ |
/* Decode frame */ |
247 |
dectime = msecond(); |
dectime = msecond(); |
248 |
status = dec_main(mp4_ptr, out_buffer, mp4_size, &used_bytes); |
used_bytes = dec_main(mp4_ptr, out_buffer, mp4_size, &xvid_dec_stats); |
249 |
dectime = msecond() - dectime; |
dectime = msecond() - dectime; |
250 |
|
|
251 |
if (status) { |
/* Resize image buffer if needed */ |
252 |
break; |
if(xvid_dec_stats.type == XVID_TYPE_VOL) { |
253 |
|
|
254 |
|
/* Free old output buffer*/ |
255 |
|
if(out_buffer) free(out_buffer); |
256 |
|
|
257 |
|
/* Copy witdh and height from the vol structure */ |
258 |
|
XDIM = xvid_dec_stats.data.vol.width; |
259 |
|
YDIM = xvid_dec_stats.data.vol.height; |
260 |
|
|
261 |
|
/* Allocate the new buffer */ |
262 |
|
if((out_buffer = (unsigned char*)malloc(XDIM*YDIM*4)) == NULL) |
263 |
|
goto free_all_memory; |
264 |
} |
} |
265 |
|
|
266 |
/* |
/* Update buffer pointers */ |
267 |
* Only needed for real raw stream, mp4u uses |
if(used_bytes > 0) { |
|
* mp4_ptr = mp4_buffer for each frame |
|
|
*/ |
|
268 |
mp4_ptr += used_bytes; |
mp4_ptr += used_bytes; |
269 |
|
still_left_in_buffer -= used_bytes; |
270 |
|
|
271 |
/* Updated data */ |
/* Total size */ |
272 |
totalsize += used_bytes; |
totalsize += used_bytes; |
273 |
|
} |
274 |
|
|
275 |
|
}while(xvid_dec_stats.type != XVID_TYPE_IVOP && |
276 |
|
xvid_dec_stats.type != XVID_TYPE_PVOP && |
277 |
|
xvid_dec_stats.type != XVID_TYPE_BVOP && |
278 |
|
xvid_dec_stats.type != XVID_TYPE_SVOP && |
279 |
|
still_left_in_buffer > 0); |
280 |
|
|
281 |
|
/* Negative buffer would mean we went too far */ |
282 |
|
if(still_left_in_buffer < 0) break; |
283 |
|
|
284 |
|
/* Skip when decoder is buffering images because of bframes */ |
285 |
|
if(xvid_dec_stats.type == XVID_TYPE_NOTHING) { |
286 |
|
delayed_frames++; |
287 |
|
continue; |
288 |
|
} |
289 |
|
|
290 |
|
/* Updated data - Count only usefull decode time */ |
291 |
totaldectime += dectime; |
totaldectime += dectime; |
292 |
|
|
293 |
/* Prints some decoding stats */ |
/* Prints some decoding stats */ |
294 |
printf("Frame %5d: dectime =%6.1f ms length=%7d bytes \n", |
switch(xvid_dec_stats.type) { |
295 |
filenr, dectime, used_bytes); |
case XVID_TYPE_IVOP: |
296 |
|
type = "I"; |
297 |
|
break; |
298 |
|
case XVID_TYPE_PVOP: |
299 |
|
type = "P"; |
300 |
|
break; |
301 |
|
case XVID_TYPE_BVOP: |
302 |
|
type = "B"; |
303 |
|
break; |
304 |
|
case XVID_TYPE_SVOP: |
305 |
|
type = "S"; |
306 |
|
break; |
307 |
|
} |
308 |
|
|
309 |
|
printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", |
310 |
|
filenr, type, dectime, used_bytes); |
311 |
|
|
312 |
/* Save individual mpeg4 strean if required */ |
/* Save individual mpeg4 stream if required */ |
313 |
if (ARG_SAVEMPEGSTREAM) { |
if (ARG_SAVEMPEGSTREAM) { |
314 |
FILE *filehandle = NULL; |
FILE *filehandle = NULL; |
315 |
|
|
321 |
filename); |
filename); |
322 |
} |
} |
323 |
else { |
else { |
324 |
fwrite(mp4_buffer, used_bytes, 1, filehandle); |
fwrite(mp4_buffer, 1, used_bytes, filehandle); |
325 |
fclose(filehandle); |
fclose(filehandle); |
326 |
} |
} |
327 |
} |
} |
328 |
|
|
|
|
|
329 |
/* Save output frame if required */ |
/* Save output frame if required */ |
330 |
if (ARG_SAVEDECOUTPUT) { |
if (ARG_SAVEDECOUTPUT) { |
331 |
sprintf(filename, "%sdec%05d.pgm", filepath, filenr); |
sprintf(filename, "%sdec%05d.pgm", filepath, filenr); |
340 |
|
|
341 |
} while ( (status>=0) && (filenr<ABS_MAXFRAMENR) ); |
} while ( (status>=0) && (filenr<ABS_MAXFRAMENR) ); |
342 |
|
|
343 |
|
/***************************************************************************** |
344 |
|
* Flush decoder buffers |
345 |
|
****************************************************************************/ |
346 |
|
|
347 |
|
while(delayed_frames--) { |
348 |
|
|
349 |
|
/* Fake vars */ |
350 |
|
int used_bytes; |
351 |
|
double dectime; |
352 |
|
|
353 |
|
/* Decode frame */ |
354 |
|
dectime = msecond(); |
355 |
|
used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats); |
356 |
|
dectime = msecond() - dectime; |
357 |
|
|
358 |
|
/* Updated data - Count only usefull decode time */ |
359 |
|
totaldectime += dectime; |
360 |
|
|
361 |
|
/* Prints some decoding stats */ |
362 |
|
printf("Frame %5d: dectime(ms) =%6.1f, length(bytes) =%7d\n", |
363 |
|
filenr, dectime, used_bytes); |
364 |
|
|
365 |
|
/* Save output frame if required */ |
366 |
|
if (ARG_SAVEDECOUTPUT) { |
367 |
|
sprintf(filename, "%sdec%05d.pgm", filepath, filenr); |
368 |
|
if(write_pgm(filename, out_buffer)) { |
369 |
|
fprintf(stderr, |
370 |
|
"Error writing decoded PGM frame %s\n", |
371 |
|
filename); |
372 |
|
} |
373 |
|
} |
374 |
|
|
375 |
|
filenr++; |
376 |
|
|
377 |
|
} |
378 |
|
|
379 |
/***************************************************************************** |
/***************************************************************************** |
380 |
* Calculate totals and averages for output, print results |
* Calculate totals and averages for output, print results |
383 |
totalsize /= filenr; |
totalsize /= filenr; |
384 |
totaldectime /= filenr; |
totaldectime /= filenr; |
385 |
|
|
386 |
printf("Avg: dectime %5.2f ms, %5.2f fps, mp4 stream size =%d\n", |
printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n", |
387 |
totaldectime, 1000/totaldectime, totalsize); |
totaldectime, 1000/totaldectime, (int)totalsize); |
388 |
|
|
389 |
/***************************************************************************** |
/***************************************************************************** |
390 |
* XviD PART Stop |
* XviD PART Stop |
391 |
/****************************************************************************/ |
****************************************************************************/ |
392 |
|
|
393 |
release_all: |
release_all: |
394 |
if (dec_handle) { |
if (dec_handle) { |
401 |
free(out_buffer); |
free(out_buffer); |
402 |
free(mp4_buffer); |
free(mp4_buffer); |
403 |
|
|
404 |
return 0; |
return(0); |
405 |
} |
} |
406 |
|
|
407 |
/***************************************************************************** |
/***************************************************************************** |
414 |
fprintf(stderr, "Usage : xvid_decraw <-w width> <-h height> [OPTIONS]\n"); |
fprintf(stderr, "Usage : xvid_decraw <-w width> <-h height> [OPTIONS]\n"); |
415 |
fprintf(stderr, "Options :\n"); |
fprintf(stderr, "Options :\n"); |
416 |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
|
fprintf(stderr, " -w integer : frame width ([1.2048])\n"); |
|
|
fprintf(stderr, " -h integer : frame height ([1.2048])\n"); |
|
417 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
418 |
fprintf(stderr, " -t integer : input data type (raw=0, mp4u=1)\n"); |
fprintf(stderr, " -t integer : input data type (raw=0, mp4u=1)\n"); |
419 |
fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); |
fprintf(stderr, " -d : save decoder output\n"); |
420 |
fprintf(stderr, " -m boolean : save mpeg4 raw stream to individual files (0 False*, !=0 True)\n"); |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
421 |
fprintf(stderr, " -help : This help message\n"); |
fprintf(stderr, " -help : This help message\n"); |
422 |
fprintf(stderr, " (* means default)\n"); |
fprintf(stderr, " (* means default)\n"); |
423 |
|
|
431 |
static double |
static double |
432 |
msecond() |
msecond() |
433 |
{ |
{ |
434 |
#ifndef _MSC_VER |
#ifndef WIN32 |
435 |
struct timeval tv; |
struct timeval tv; |
436 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
437 |
return (double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3; |
return((double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3); |
438 |
#else |
#else |
439 |
clock_t clk; |
clock_t clk; |
440 |
clk = clock(); |
clk = clock(); |
441 |
return clk * 1000 / CLOCKS_PER_SEC; |
return(clk * 1000 / CLOCKS_PER_SEC); |
442 |
#endif |
#endif |
443 |
} |
} |
444 |
|
|
|
|
|
445 |
/***************************************************************************** |
/***************************************************************************** |
446 |
* output functions |
* output functions |
447 |
****************************************************************************/ |
****************************************************************************/ |
483 |
/* Close file */ |
/* Close file */ |
484 |
fclose(filehandle); |
fclose(filehandle); |
485 |
|
|
486 |
return 0; |
return(0); |
487 |
} |
} |
488 |
else |
else |
489 |
return 1; |
return(1); |
490 |
} |
} |
491 |
|
|
492 |
/***************************************************************************** |
/***************************************************************************** |
497 |
static int |
static int |
498 |
dec_init(int use_assembler) |
dec_init(int use_assembler) |
499 |
{ |
{ |
500 |
int xerr; |
int ret; |
501 |
|
|
502 |
|
xvid_gbl_init_t xvid_gbl_init; |
503 |
|
xvid_dec_create_t xvid_dec_create; |
504 |
|
|
505 |
|
/*------------------------------------------------------------------------ |
506 |
|
* XviD core initialization |
507 |
|
*----------------------------------------------------------------------*/ |
508 |
|
|
509 |
XVID_INIT_PARAM xinit; |
/* Version */ |
510 |
XVID_DEC_PARAM xparam; |
xvid_gbl_init.version = XVID_VERSION; |
511 |
|
|
512 |
|
/* Assembly setting */ |
513 |
if(use_assembler) |
if(use_assembler) |
514 |
#ifdef ARCH_IA64 |
#ifdef ARCH_IS_IA64 |
515 |
xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
516 |
#else |
#else |
517 |
xinit.cpu_flags = 0; |
xvid_gbl_init.cpu_flags = 0; |
518 |
#endif |
#endif |
519 |
else |
else |
520 |
xinit.cpu_flags = XVID_CPU_FORCE; |
xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; |
521 |
|
|
522 |
xvid_init(NULL, 0, &xinit, NULL); |
xvid_global(NULL, 0, &xvid_gbl_init, NULL); |
|
xparam.width = XDIM; |
|
|
xparam.height = YDIM; |
|
523 |
|
|
524 |
xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL); |
/*------------------------------------------------------------------------ |
525 |
dec_handle = xparam.handle; |
* XviD encoder initialization |
526 |
|
*----------------------------------------------------------------------*/ |
527 |
|
|
528 |
return xerr; |
/* Version */ |
529 |
|
xvid_dec_create.version = XVID_VERSION; |
530 |
|
|
531 |
|
/* |
532 |
|
* Image dimensions -- set to 0, xvidcore will resize when ever it is |
533 |
|
* needed |
534 |
|
*/ |
535 |
|
xvid_dec_create.width = 0; |
536 |
|
xvid_dec_create.height = 0; |
537 |
|
|
538 |
|
ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL); |
539 |
|
|
540 |
|
dec_handle = xvid_dec_create.handle; |
541 |
|
|
542 |
|
return(ret); |
543 |
} |
} |
544 |
|
|
545 |
/* decode one frame */ |
/* decode one frame */ |
547 |
dec_main(unsigned char *istream, |
dec_main(unsigned char *istream, |
548 |
unsigned char *ostream, |
unsigned char *ostream, |
549 |
int istream_size, |
int istream_size, |
550 |
int *ostream_size) |
xvid_dec_stats_t *xvid_dec_stats) |
551 |
{ |
{ |
552 |
|
|
553 |
int xerr; |
int ret; |
554 |
XVID_DEC_FRAME xframe; |
|
555 |
|
xvid_dec_frame_t xvid_dec_frame; |
556 |
|
|
557 |
|
/* Set version */ |
558 |
|
xvid_dec_frame.version = XVID_VERSION; |
559 |
|
xvid_dec_stats->version = XVID_VERSION; |
560 |
|
|
561 |
|
/* No general flags to set */ |
562 |
|
xvid_dec_frame.general = 0; |
563 |
|
|
564 |
xframe.bitstream = istream; |
/* Input stream */ |
565 |
xframe.length = istream_size; |
xvid_dec_frame.bitstream = istream; |
566 |
xframe.image = ostream; |
xvid_dec_frame.length = istream_size; |
|
xframe.stride = XDIM; |
|
|
xframe.colorspace = XVID_CSP_YV12; |
|
567 |
|
|
568 |
xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL); |
/* Output frame structure */ |
569 |
|
xvid_dec_frame.output.plane[0] = ostream; |
570 |
|
xvid_dec_frame.output.stride[0] = XDIM; |
571 |
|
xvid_dec_frame.output.csp = XVID_CSP_I420; |
572 |
|
|
573 |
*ostream_size = xframe.length; |
ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats); |
574 |
|
|
575 |
return xerr; |
return(ret); |
576 |
} |
} |
577 |
|
|
578 |
/* close decoder to release resources */ |
/* close decoder to release resources */ |
579 |
static int |
static int |
580 |
dec_stop() |
dec_stop() |
581 |
{ |
{ |
582 |
int xerr; |
int ret; |
583 |
|
|
584 |
xerr = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL); |
ret = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL); |
585 |
|
|
586 |
return xerr; |
return(ret); |
587 |
} |
} |