--- branches/dev-api-4/xvidcore/examples/xvid_decraw.c 2003/03/11 23:39:47 918 +++ branches/dev-api-4/xvidcore/examples/xvid_decraw.c 2003/06/09 13:55:56 1054 @@ -4,6 +4,7 @@ * - Console based decoding test application - * * Copyright(C) 2002-2003 Christoph Lampert + * 2002-2003 Edouard Gomez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_decraw.c,v 1.7.2.1 2003-03-11 23:39:47 edgomez Exp $ + * $Id: xvid_decraw.c,v 1.7.2.3 2003-06-09 13:49:13 edgomez Exp $ * ****************************************************************************/ @@ -29,24 +30,11 @@ * * An MPEG-4 bitstream is read from an input file (or stdin) and decoded, * the speed for this is measured. - * - * The program is plain C and needs no libraries except for libxvidcore, - * and maths-lib, so with UN*X you simply compile by - * - * gcc xvid_decraw.c -lxvidcore -lm -o xvid_decraw * - * 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) + * The program is plain C and needs no libraries except for libxvidcore, + * and maths-lib. + * + * Use ./xvid_decraw -help for a list of options * ****************************************************************************/ @@ -96,6 +84,18 @@ static int dec_stop(); static void usage(); + +const char * type2str(int type) +{ + if (type==XVID_TYPE_IVOP) + return "I"; + if (type==XVID_TYPE_PVOP) + return "P"; + if (type==XVID_TYPE_BVOP) + return "B"; + return "S"; +} + /***************************************************************************** * Main program ****************************************************************************/ @@ -105,9 +105,7 @@ unsigned char *mp4_buffer = NULL; unsigned char *mp4_ptr = NULL; unsigned char *out_buffer = NULL; - unsigned char *type = NULL; int still_left_in_buffer; - int delayed_frames; xvid_dec_stats_t xvid_dec_stats; double totaldectime; @@ -204,7 +202,6 @@ totaldectime = 0; totalsize = 0; filenr = 0; - delayed_frames = 0; mp4_ptr = mp4_buffer; do { @@ -229,7 +226,7 @@ mp4_ptr = mp4_buffer; /* read new data */ - if(feof(in_file)) + if(feof(in_file)) break; still_left_in_buffer = fread(mp4_buffer + rest, @@ -272,42 +269,18 @@ totalsize += used_bytes; } - }while(xvid_dec_stats.type != XVID_TYPE_IVOP && - xvid_dec_stats.type != XVID_TYPE_PVOP && - xvid_dec_stats.type != XVID_TYPE_BVOP && - xvid_dec_stats.type != XVID_TYPE_SVOP && - still_left_in_buffer > 0); + }while(xvid_dec_stats.type <= 0 && still_left_in_buffer > 0); /* Negative buffer would mean we went too far */ - if(still_left_in_buffer < 0) break; + if(still_left_in_buffer <= 0) + break; - /* Skip when decoder is buffering images because of bframes */ - if(xvid_dec_stats.type == XVID_TYPE_NOTHING) { - delayed_frames++; - continue; - } - - /* Updated data - Count only usefull decode time */ + /* Updated data - Count only usefull decode time */ totaldectime += dectime; - /* Prints some decoding stats */ - switch(xvid_dec_stats.type) { - case XVID_TYPE_IVOP: - type = "I"; - break; - case XVID_TYPE_PVOP: - type = "P"; - break; - case XVID_TYPE_BVOP: - type = "B"; - break; - case XVID_TYPE_SVOP: - type = "S"; - break; - } - - printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", - filenr, type, dectime, used_bytes); + + printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", + filenr, type2str(xvid_dec_stats.type), dectime, used_bytes); /* Save individual mpeg4 stream if required */ if(ARG_SAVEMPEGSTREAM) { @@ -344,23 +317,28 @@ * Flush decoder buffers ****************************************************************************/ - while(delayed_frames--) { + do { /* Fake vars */ int used_bytes; double dectime; - /* Decode frame */ - dectime = msecond(); - used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats); - dectime = msecond() - dectime; + do { + dectime = msecond(); + used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats); + dectime = msecond() - dectime; + }while(used_bytes>=0 && xvid_dec_stats.type <= 0); + + if (used_bytes < 0) { /* XVID_ERR_END */ + break; + } /* Updated data - Count only usefull decode time */ totaldectime += dectime; /* Prints some decoding stats */ - printf("Frame %5d: dectime(ms) =%6.1f, length(bytes) =%7d\n", - filenr, dectime, used_bytes); + printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", + filenr, type2str(xvid_dec_stats.type), dectime, used_bytes); /* Save output frame if required */ if (ARG_SAVEDECOUTPUT) { @@ -374,7 +352,7 @@ filenr++; - } + }while(1); /***************************************************************************** * Calculate totals and averages for output, print results