4 |
* - Console based decoding test application - |
* - Console based decoding test application - |
5 |
* |
* |
6 |
* Copyright(C) 2002-2003 Christoph Lampert |
* Copyright(C) 2002-2003 Christoph Lampert |
7 |
|
* 2002-2003 Edouard Gomez <ed.gomez@free.fr> |
8 |
* |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
10 |
* 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 |
32 |
* the speed for this is measured. |
* the speed for this is measured. |
33 |
* |
* |
34 |
* The program is plain C and needs no libraries except for libxvidcore, |
* The program is plain C and needs no libraries except for libxvidcore, |
35 |
* and maths-lib, so with UN*X you simply compile by |
* and maths-lib. |
36 |
* |
* |
37 |
* gcc xvid_decraw.c -lxvidcore -lm -o xvid_decraw |
* Use ./xvid_decraw -help for a list of options |
|
* |
|
|
* You have to specify the image dimensions (until the add the feature |
|
|
* to read this from the bitstream) |
|
|
* |
|
|
* Usage : xvid_decraw <-w width> <-h height> [OPTIONS] |
|
|
* Options : |
|
|
* -asm : use assembly optimizations (default=disabled) |
|
|
* -i string : input filename (default=stdin) |
|
|
* -t integer : input data type (raw=0, mp4u=1) |
|
|
* -d : save decoder output (0 False*, !=0 True) |
|
|
* -m : save mpeg4 raw stream to single files (0 False*, !=0 True) |
|
|
* -help : This help message |
|
|
* (* means default) |
|
38 |
* |
* |
39 |
****************************************************************************/ |
****************************************************************************/ |
40 |
|
|
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 still_left_in_buffer; |
int useful_bytes; |
109 |
xvid_dec_stats_t xvid_dec_stats; |
xvid_dec_stats_t xvid_dec_stats; |
110 |
|
|
111 |
double totaldectime; |
double totaldectime; |
132 |
|
|
133 |
if (strcmp("-asm", argv[i]) == 0 ) { |
if (strcmp("-asm", argv[i]) == 0 ) { |
134 |
use_assembler = 1; |
use_assembler = 1; |
135 |
} |
} else if (strcmp("-d", argv[i]) == 0) { |
|
else if (strcmp("-d", argv[i]) == 0) { |
|
136 |
ARG_SAVEDECOUTPUT = 1; |
ARG_SAVEDECOUTPUT = 1; |
137 |
} |
} else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) { |
|
else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) { |
|
138 |
i++; |
i++; |
139 |
ARG_INPUTFILE = argv[i]; |
ARG_INPUTFILE = argv[i]; |
140 |
} |
} else if (strcmp("-m", argv[i]) == 0) { |
|
else if (strcmp("-m", argv[i]) == 0) { |
|
141 |
ARG_SAVEMPEGSTREAM = 1; |
ARG_SAVEMPEGSTREAM = 1; |
142 |
} |
} else if (strcmp("-help", argv[i]) == 0) { |
|
else if (strcmp("-help", argv[i])) { |
|
143 |
usage(); |
usage(); |
144 |
return(0); |
return(0); |
145 |
} |
} else { |
|
else { |
|
146 |
usage(); |
usage(); |
147 |
exit(-1); |
exit(-1); |
148 |
} |
} |
|
|
|
149 |
} |
} |
150 |
|
|
151 |
/***************************************************************************** |
/***************************************************************************** |
191 |
****************************************************************************/ |
****************************************************************************/ |
192 |
|
|
193 |
/* Fill the buffer */ |
/* Fill the buffer */ |
194 |
still_left_in_buffer = fread(mp4_buffer, 1, BUFFER_SIZE, in_file); |
useful_bytes = fread(mp4_buffer, 1, BUFFER_SIZE, in_file); |
195 |
|
|
196 |
totaldectime = 0; |
totaldectime = 0; |
197 |
totalsize = 0; |
totalsize = 0; |
199 |
mp4_ptr = mp4_buffer; |
mp4_ptr = mp4_buffer; |
200 |
|
|
201 |
do { |
do { |
|
|
|
|
int mp4_size = (mp4_buffer + BUFFER_SIZE - mp4_ptr); |
|
202 |
int used_bytes = 0; |
int used_bytes = 0; |
203 |
double dectime; |
double dectime; |
204 |
|
|
206 |
* If the buffer is half empty or there are no more bytes in it |
* If the buffer is half empty or there are no more bytes in it |
207 |
* then fill it. |
* then fill it. |
208 |
*/ |
*/ |
209 |
if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2 || |
if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) { |
210 |
still_left_in_buffer <= 0) { |
int already_in_buffer = (mp4_buffer + BUFFER_SIZE - mp4_ptr); |
|
int rest = (mp4_buffer + BUFFER_SIZE - mp4_ptr); |
|
211 |
|
|
212 |
/* Move data if needed */ |
/* Move data if needed */ |
213 |
if (rest) |
if (already_in_buffer > 0) |
214 |
memcpy(mp4_buffer, mp4_ptr, rest); |
memcpy(mp4_buffer, mp4_ptr, already_in_buffer); |
215 |
|
|
216 |
/* Update mp4_ptr */ |
/* Update mp4_ptr */ |
217 |
mp4_ptr = mp4_buffer; |
mp4_ptr = mp4_buffer; |
220 |
if(feof(in_file)) |
if(feof(in_file)) |
221 |
break; |
break; |
222 |
|
|
223 |
still_left_in_buffer = fread(mp4_buffer + rest, |
useful_bytes += fread(mp4_buffer + already_in_buffer, |
224 |
1, |
1, BUFFER_SIZE - already_in_buffer, |
|
BUFFER_SIZE - rest, |
|
225 |
in_file); |
in_file); |
226 |
|
|
227 |
} |
} |
232 |
|
|
233 |
/* Decode frame */ |
/* Decode frame */ |
234 |
dectime = msecond(); |
dectime = msecond(); |
235 |
used_bytes = dec_main(mp4_ptr, out_buffer, mp4_size, &xvid_dec_stats); |
used_bytes = dec_main(mp4_ptr, out_buffer, useful_bytes, &xvid_dec_stats); |
236 |
dectime = msecond() - dectime; |
dectime = msecond() - dectime; |
237 |
|
|
238 |
/* Resize image buffer if needed */ |
/* Resize image buffer if needed */ |
239 |
if(xvid_dec_stats.type == XVID_TYPE_VOL) { |
if(xvid_dec_stats.type == XVID_TYPE_VOL) { |
240 |
|
|
241 |
/* Free old output buffer*/ |
/* Check if old buffer is smaller */ |
242 |
if(out_buffer) free(out_buffer); |
if(XDIM*YDIM < xvid_dec_stats.data.vol.width*xvid_dec_stats.data.vol.height) { |
243 |
|
|
244 |
/* Copy witdh and height from the vol structure */ |
/* Copy new witdh and new height from the vol structure */ |
245 |
XDIM = xvid_dec_stats.data.vol.width; |
XDIM = xvid_dec_stats.data.vol.width; |
246 |
YDIM = xvid_dec_stats.data.vol.height; |
YDIM = xvid_dec_stats.data.vol.height; |
247 |
|
|
248 |
|
/* Free old output buffer*/ |
249 |
|
if(out_buffer) free(out_buffer); |
250 |
|
|
251 |
/* Allocate the new buffer */ |
/* Allocate the new buffer */ |
252 |
if((out_buffer = (unsigned char*)malloc(XDIM*YDIM*4)) == NULL) |
out_buffer = (unsigned char*)malloc(XDIM*YDIM*4); |
253 |
|
if(out_buffer == NULL) |
254 |
goto free_all_memory; |
goto free_all_memory; |
255 |
|
|
256 |
|
fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM); |
257 |
|
} |
258 |
} |
} |
259 |
|
|
260 |
/* Update buffer pointers */ |
/* Update buffer pointers */ |
261 |
if(used_bytes > 0) { |
if(used_bytes > 0) { |
262 |
mp4_ptr += used_bytes; |
mp4_ptr += used_bytes; |
263 |
still_left_in_buffer -= used_bytes; |
useful_bytes -= used_bytes; |
264 |
|
|
265 |
/* Total size */ |
/* Total size */ |
266 |
totalsize += used_bytes; |
totalsize += used_bytes; |
267 |
} |
} |
268 |
|
|
269 |
}while(xvid_dec_stats.type <= 0 && still_left_in_buffer > 0); |
}while(xvid_dec_stats.type <= 0 && useful_bytes > 0); |
270 |
|
|
271 |
/* Negative buffer would mean we went too far */ |
/* Check if there is a negative number of useful bytes left in buffer |
272 |
if(still_left_in_buffer <= 0) |
* This means we went too far */ |
273 |
|
if(useful_bytes < 0) |
274 |
break; |
break; |
275 |
|
|
276 |
/* Updated data - Count only usefull decode time */ |
/* Updated data - Count only usefull decode time */ |
292 |
filename); |
filename); |
293 |
} |
} |
294 |
else { |
else { |
295 |
fwrite(mp4_buffer, 1, used_bytes, filehandle); |
fwrite(mp4_ptr-used_bytes, 1, used_bytes, filehandle); |
296 |
fclose(filehandle); |
fclose(filehandle); |
297 |
} |
} |
298 |
} |
} |
387 |
static void usage() |
static void usage() |
388 |
{ |
{ |
389 |
|
|
390 |
fprintf(stderr, "Usage : xvid_decraw <-w width> <-h height> [OPTIONS]\n"); |
fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n"); |
391 |
fprintf(stderr, "Options :\n"); |
fprintf(stderr, "Options :\n"); |
392 |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
393 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
|
fprintf(stderr, " -t integer : input data type (raw=0, mp4u=1)\n"); |
|
394 |
fprintf(stderr, " -d : save decoder output\n"); |
fprintf(stderr, " -d : save decoder output\n"); |
395 |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
396 |
fprintf(stderr, " -help : This help message\n"); |
fprintf(stderr, " -help : This help message\n"); |