[svn] / trunk / xvidcore / examples / xvid_decraw.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/examples/xvid_decraw.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 547, Fri Sep 27 18:33:13 2002 UTC revision 1416, Sat Apr 10 04:25:31 2004 UTC
# Line 3  Line 3 
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     *               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
# Line 19  Line 20 
20   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   * $Id: xvid_decraw.c,v 1.2 2002-09-27 18:33:13 edgomez Exp $   * $Id: xvid_decraw.c,v 1.11 2004-04-10 04:25:31 suxen_drol Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 31  Line 32 
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)  
  *  -w integer     : frame width ([1.2048])  
  *  -h integer     : frame height ([1.2048])  
  *  -i string      : input filename (default=stdin)  
  *  -t integer     : input data type (raw=0, mp4u=1)  
  *  -d boolean     : save decoder output (0 False*, !=0 True)  
  *  -m boolean     : save mpeg4 raw stream to single files (0 False*, !=0 True)  
  *  -help          : This help message  
  * (* means default)  
38   *   *
39   ****************************************************************************/   ****************************************************************************/
40    
# Line 56  Line 42 
42  #include <stdlib.h>  #include <stdlib.h>
43  #include <string.h>  #include <string.h>
44  #include <math.h>  #include <math.h>
45  #ifndef _MSC_VER  #ifndef WIN32
46  #include <sys/time.h>  #include <sys/time.h>
47  #else  #else
48  #include <time.h>  #include <time.h>
# Line 75  Line 61 
61  static int YDIM = 0;  static int YDIM = 0;
62  static int ARG_SAVEDECOUTPUT = 0;  static int ARG_SAVEDECOUTPUT = 0;
63  static int ARG_SAVEMPEGSTREAM = 0;  static int ARG_SAVEMPEGSTREAM = 0;
 static int ARG_STREAMTYPE = 0;  
64  static char *ARG_INPUTFILE = NULL;  static char *ARG_INPUTFILE = NULL;
65    
66    
67  static char filepath[256] = "./";  static char filepath[256] = "./";
68  static void *dec_handle = NULL;  static void *dec_handle = NULL;
69    
70  # 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) )  
71    
72  /*****************************************************************************  /*****************************************************************************
73   *               Local prototypes   *               Local prototypes
# Line 97  Line 76 
76  static double msecond();  static double msecond();
77  static int write_pgm(char *filename,  static int write_pgm(char *filename,
78                       unsigned char *image);                       unsigned char *image);
79  static int dec_init(int use_assembler);  static int dec_init(int use_assembler, int debug_level);
80  static int dec_main(unsigned char *istream,  static int dec_main(unsigned char *istream,
81                      unsigned char *ostream,                      unsigned char *ostream,
82                      int istream_size,                      int istream_size,
83                      int *ostream_size);                                          xvid_dec_stats_t *xvid_dec_stats);
84  static int dec_stop();  static int dec_stop();
85  static void usage();  static void usage();
86    
87    
88    const char * type2str(int type)
89    {
90        if (type==XVID_TYPE_IVOP)
91            return "I";
92        if (type==XVID_TYPE_PVOP)
93            return "P";
94        if (type==XVID_TYPE_BVOP)
95            return "B";
96        return "S";
97    }
98    
99  /*****************************************************************************  /*****************************************************************************
100   *        Main program   *        Main program
101   ****************************************************************************/   ****************************************************************************/
# Line 114  Line 105 
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;          int useful_bytes;
109            xvid_dec_stats_t xvid_dec_stats;
110    
111          double totaldectime;          double totaldectime;
112    
# Line 122  Line 114 
114          int status;          int status;
115    
116          int use_assembler = 0;          int use_assembler = 0;
117            int debug_level = 0;
118    
119          char filename[256];          char filename[256];
120    
# Line 130  Line 123 
123          int i;          int i;
124    
125          printf("xvid_decraw - raw mpeg4 bitstream decoder ");          printf("xvid_decraw - raw mpeg4 bitstream decoder ");
126          printf("written by Christoph Lampert 2002\n\n");          printf("written by Christoph Lampert 2002-2003\n\n");
127    
128  /*****************************************************************************  /*****************************************************************************
129   * Command line parsing   * Command line parsing
# Line 140  Line 133 
133    
134                  if (strcmp("-asm", argv[i]) == 0 ) {                  if (strcmp("-asm", argv[i]) == 0 ) {
135                          use_assembler = 1;                          use_assembler = 1;
136                  }                  } else if (strcmp("-debug", argv[i]) == 0 && i < argc - 1 ) {
                 else if (strcmp("-w", argv[i]) == 0 && i < argc - 1 ) {  
                         i++;  
                         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 ) {  
137                          i++;                          i++;
138                          ARG_SAVEDECOUTPUT = atoi(argv[i]);                          if (sscanf(argv[i], "0x%x", &debug_level) != 1) {
139                                    debug_level = atoi(argv[i]);
140                  }                  }
141                  else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {                  } else if (strcmp("-d", argv[i]) == 0) {
142                            ARG_SAVEDECOUTPUT = 1;
143                    } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {
144                          i++;                          i++;
145                          ARG_INPUTFILE = argv[i];                          ARG_INPUTFILE = argv[i];
146                  }                  } else if (strcmp("-m", argv[i]) == 0) {
147                  else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) {                          ARG_SAVEMPEGSTREAM = 1;
148                          i++;                  } else if (strcmp("-help", argv[i]) == 0) {
                         ARG_SAVEMPEGSTREAM = atoi(argv[i]);  
                 }  
                 else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {  
                         i++;  
                         ARG_STREAMTYPE = atoi(argv[i]);  
                 }  
                 else if (strcmp("-help", argv[i])) {  
149                          usage();                          usage();
150                          return(0);                          return(0);
151                  }                  } else {
                 else {  
152                          usage();                          usage();
153                          exit(-1);                          exit(-1);
154                  }                  }
   
155          }          }
156    
157  /*****************************************************************************  /*****************************************************************************
158   * Values checking   * Values checking
159   ****************************************************************************/   ****************************************************************************/
160    
         if(XDIM <= 0 || XDIM > 2048 || YDIM <= 0 || YDIM > 2048) {  
                 usage();  
                 return -1;  
         }  
   
161          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
162                  in_file = stdin;                  in_file = stdin;
163          }          }
# Line 193  Line 166 
166                  in_file = fopen(ARG_INPUTFILE, "rb");                  in_file = fopen(ARG_INPUTFILE, "rb");
167                  if (in_file == NULL) {                  if (in_file == NULL) {
168                          fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);                          fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
169                          return -1;                          return(-1);
170                  }                  }
171          }          }
172    
# Line 207  Line 180 
180          if (!mp4_buffer)          if (!mp4_buffer)
181                  goto free_all_memory;                  goto free_all_memory;
182    
         /* Memory for frame output */  
         out_buffer = (unsigned char *) malloc(XDIM*YDIM*4);  
         if (!out_buffer)  
                 goto free_all_memory;  
   
   
183  /*****************************************************************************  /*****************************************************************************
184   *        XviD PART  Start   *        XviD PART  Start
185   ****************************************************************************/   ****************************************************************************/
186    
187          status = dec_init(use_assembler);          status = dec_init(use_assembler, debug_level);
188          if (status) {          if (status) {
189                  fprintf(stderr,                  fprintf(stderr,
190                          "Decore INIT problem, return value %d\n", status);                          "Decore INIT problem, return value %d\n", status);
# Line 229  Line 196 
196   *                               Main loop   *                               Main loop
197   ****************************************************************************/   ****************************************************************************/
198    
199          if(ARG_STREAMTYPE) {          /* Fill the buffer */
200            useful_bytes = 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;  
201    
202          totaldectime = 0;          totaldectime = 0;
203          totalsize = 0;          totalsize = 0;
# Line 259  Line 205 
205          mp4_ptr = mp4_buffer;          mp4_ptr = mp4_buffer;
206    
207          do {          do {
   
                 int mp4_size = (mp4_buffer + BUFFER_SIZE - mp4_ptr);  
208                  int used_bytes = 0;                  int used_bytes = 0;
209                  double dectime;                  double dectime;
210    
                 /* 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);  
   
211                          /*                          /*
212                           * 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
213                           * filling as we know exactly how much bytes there are in                   * then fill it.
                          * next frame  
214                           */                           */
                         mp4_ptr = mp4_buffer;  
   
                 }  
                 else {  
   
                         /* Real raw stream */  
   
                         /* buffer more than half empty -> Fill it */  
215                          if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) {                          if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) {
216                                  int rest = (mp4_buffer + BUFFER_SIZE - mp4_ptr);                          int already_in_buffer = (mp4_buffer + BUFFER_SIZE - mp4_ptr);
217    
218                                  /* Move data if needed */                                  /* Move data if needed */
219                                  if (rest)                          if (already_in_buffer > 0)
220                                          memcpy(mp4_buffer, mp4_ptr, rest);                                  memcpy(mp4_buffer, mp4_ptr, already_in_buffer);
221    
222                                  /* Update mp4_ptr */                                  /* Update mp4_ptr */
223                                  mp4_ptr = mp4_buffer;                                  mp4_ptr = mp4_buffer;
# Line 308  Line 225 
225                                  /* read new data */                                  /* read new data */
226                                  if(feof(in_file))                                  if(feof(in_file))
227                                          break;                                          break;
228                                  fread(mp4_buffer + rest, BUFFER_SIZE - rest, 1, in_file);  
229                          }                          useful_bytes += fread(mp4_buffer + already_in_buffer,
230                                                                      1, BUFFER_SIZE - already_in_buffer,
231                                                                      in_file);
232    
233                  }                  }
234    
235    
236                    /* This loop is needed to handle VOL/NVOP reading */
237                    do {
238    
239                  /* Decode frame */                  /* Decode frame */
240                  dectime = msecond();                  dectime = msecond();
241                  status = dec_main(mp4_ptr, out_buffer, mp4_size, &used_bytes);                          used_bytes = dec_main(mp4_ptr, out_buffer, useful_bytes, &xvid_dec_stats);
242                  dectime = msecond() - dectime;                  dectime = msecond() - dectime;
243    
244                  if (status) {                          /* Resize image buffer if needed */
245                          break;                          if(xvid_dec_stats.type == XVID_TYPE_VOL) {
246    
247                                    /* Check if old buffer is smaller */
248                                    if(XDIM*YDIM < xvid_dec_stats.data.vol.width*xvid_dec_stats.data.vol.height) {
249    
250                                            /* Copy new witdh and new height from the vol structure */
251                                            XDIM = xvid_dec_stats.data.vol.width;
252                                            YDIM = xvid_dec_stats.data.vol.height;
253    
254                                            /* Free old output buffer*/
255                                            if(out_buffer) free(out_buffer);
256    
257                                            /* Allocate the new buffer */
258                                            out_buffer = (unsigned char*)malloc(XDIM*YDIM*4);
259                                            if(out_buffer == NULL)
260                                                    goto free_all_memory;
261    
262                                            fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);
263                                    }
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                                    useful_bytes -= used_bytes;
270    
271                  /* Updated data */                                  /* Total size */
272                  totalsize += used_bytes;                  totalsize += used_bytes;
273                            }
274    
275                    }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);
276    
277                    /* Check if there is a negative number of useful bytes left in buffer
278                     * This means we went too far */
279            if(useful_bytes < 0)
280                break;
281    
282            /* Updated data - Count only usefull decode time */
283                  totaldectime += dectime;                  totaldectime += dectime;
284    
                 /* Prints some decoding stats */  
                 printf("Frame %5d: dectime =%6.1f ms length=%7d bytes \n",  
                        filenr, dectime, used_bytes);  
285    
286                  /* Save individual mpeg4 strean if required */          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
287                               filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
288    
289                    /* Save individual mpeg4 stream if required */
290                  if (ARG_SAVEMPEGSTREAM) {                  if (ARG_SAVEMPEGSTREAM) {
291                          FILE *filehandle = NULL;                          FILE *filehandle = NULL;
292    
# Line 348  Line 298 
298                                          filename);                                          filename);
299                          }                          }
300                          else {                          else {
301                                  fwrite(mp4_buffer, used_bytes, 1, filehandle);                                  fwrite(mp4_ptr-used_bytes, 1, used_bytes, filehandle);
302                                  fclose(filehandle);                                  fclose(filehandle);
303                          }                          }
304                  }                  }
305    
   
306                  /* Save output frame if required */                  /* Save output frame if required */
307                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
308                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);
# Line 368  Line 317 
317    
318          } while ( (status>=0) && (filenr<ABS_MAXFRAMENR) );          } while ( (status>=0) && (filenr<ABS_MAXFRAMENR) );
319    
320    /*****************************************************************************
321     *     Flush decoder buffers
322     ****************************************************************************/
323    
324            do {
325    
326                    /* Fake vars */
327                    int used_bytes;
328                    double dectime;
329    
330            do {
331                        dectime = msecond();
332                        used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);
333                        dectime = msecond() - dectime;
334            }while(used_bytes>=0 && xvid_dec_stats.type <= 0);
335    
336            if (used_bytes < 0) {   /* XVID_ERR_END */
337                break;
338            }
339    
340                    /* Updated data - Count only usefull decode time */
341                    totaldectime += dectime;
342    
343                    /* Prints some decoding stats */
344            printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
345                               filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
346    
347                    /* Save output frame if required */
348                    if (ARG_SAVEDECOUTPUT) {
349                            sprintf(filename, "%sdec%05d.pgm", filepath, filenr);
350                            if(write_pgm(filename, out_buffer)) {
351                                    fprintf(stderr,
352                                                    "Error writing decoded PGM frame %s\n",
353                                                    filename);
354                            }
355                    }
356    
357                    filenr++;
358    
359            }while(1);
360    
361  /*****************************************************************************  /*****************************************************************************
362   *     Calculate totals and averages for output, print results   *     Calculate totals and averages for output, print results
# Line 376  Line 365 
365          totalsize    /= filenr;          totalsize    /= filenr;
366          totaldectime /= filenr;          totaldectime /= filenr;
367    
368          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",
369                  totaldectime, 1000/totaldectime, totalsize);                     totaldectime, 1000/totaldectime, (int)totalsize);
370    
371  /*****************************************************************************  /*****************************************************************************
372   *      XviD PART  Stop   *      XviD PART  Stop
373  /****************************************************************************/   ****************************************************************************/
374    
375   release_all:   release_all:
376          if (dec_handle) {          if (dec_handle) {
# Line 394  Line 383 
383          free(out_buffer);          free(out_buffer);
384          free(mp4_buffer);          free(mp4_buffer);
385    
386          return 0;          return(0);
387  }  }
388    
389  /*****************************************************************************  /*****************************************************************************
# Line 404  Line 393 
393  static void usage()  static void usage()
394  {  {
395    
396          fprintf(stderr, "Usage : xvid_decraw <-w width> <-h height> [OPTIONS]\n");          fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n");
397          fprintf(stderr, "Options :\n");          fprintf(stderr, "Options :\n");
398          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");
399          fprintf(stderr, " -w integer     : frame width ([1.2048])\n");          fprintf(stderr, " -debug         : debug level (debug=0)\n");
         fprintf(stderr, " -h integer     : frame height ([1.2048])\n");  
400          fprintf(stderr, " -i string      : input filename (default=stdin)\n");          fprintf(stderr, " -i string      : input filename (default=stdin)\n");
401          fprintf(stderr, " -t integer     : input data type (raw=0, mp4u=1)\n");          fprintf(stderr, " -d             : save decoder output\n");
402          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -m             : save mpeg4 raw stream to individual files\n");
         fprintf(stderr, " -m boolean     : save mpeg4 raw stream to individual files (0 False*, !=0 True)\n");  
403          fprintf(stderr, " -help          : This help message\n");          fprintf(stderr, " -help          : This help message\n");
404          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
405    
# Line 426  Line 413 
413  static double  static double
414  msecond()  msecond()
415  {  {
416  #ifndef _MSC_VER  #ifndef WIN32
417          struct timeval  tv;          struct timeval  tv;
418          gettimeofday(&tv, 0);          gettimeofday(&tv, 0);
419          return tv.tv_sec*10e3 + tv.tv_usec * 1.0e-3;          return((double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3);
420  #else  #else
421          clock_t clk;          clock_t clk;
422          clk = clock();          clk = clock();
423          return clk * 1000 / CLOCKS_PER_SEC;          return(clk * 1000 / CLOCKS_PER_SEC);
424  #endif  #endif
425  }  }
426    
   
427  /*****************************************************************************  /*****************************************************************************
428   *              output functions   *              output functions
429   ****************************************************************************/   ****************************************************************************/
# Line 479  Line 465 
465                  /* Close file */                  /* Close file */
466                  fclose(filehandle);                  fclose(filehandle);
467    
468                  return 0;                  return(0);
469          }          }
470          else          else
471                  return 1;                  return(1);
472  }  }
473    
474  /*****************************************************************************  /*****************************************************************************
# Line 491  Line 477 
477    
478  /* init decoder before first run */  /* init decoder before first run */
479  static int  static int
480  dec_init(int use_assembler)  dec_init(int use_assembler, int debug_level)
481  {  {
482          int xerr;          int ret;
483    
484            xvid_gbl_init_t   xvid_gbl_init;
485            xvid_dec_create_t xvid_dec_create;
486    
487          XVID_INIT_PARAM xinit;          /*------------------------------------------------------------------------
488          XVID_DEC_PARAM xparam;           * XviD core initialization
489             *----------------------------------------------------------------------*/
490    
491            /* Version */
492            xvid_gbl_init.version = XVID_VERSION;
493    
494            /* Assembly setting */
495                  if(use_assembler)                  if(use_assembler)
496  #ifdef ARCH_IA64  #ifdef ARCH_IS_IA64
497                          xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;
498  #else  #else
499                          xinit.cpu_flags = 0;          xvid_gbl_init.cpu_flags = 0;
500  #endif  #endif
501                  else                  else
502                          xinit.cpu_flags = XVID_CPU_FORCE;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
503    
504            xvid_gbl_init.debug = debug_level;
505    
506          xvid_init(NULL, 0, &xinit, NULL);          xvid_global(NULL, 0, &xvid_gbl_init, NULL);
         xparam.width = XDIM;  
         xparam.height = YDIM;  
507    
508          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);          /*------------------------------------------------------------------------
509          dec_handle = xparam.handle;           * XviD encoder initialization
510             *----------------------------------------------------------------------*/
511    
512          return xerr;          /* Version */
513            xvid_dec_create.version = XVID_VERSION;
514    
515            /*
516             * Image dimensions -- set to 0, xvidcore will resize when ever it is
517             * needed
518             */
519            xvid_dec_create.width = 0;
520            xvid_dec_create.height = 0;
521    
522            ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL);
523    
524            dec_handle = xvid_dec_create.handle;
525    
526            return(ret);
527  }  }
528    
529  /* decode one frame  */  /* decode one frame  */
# Line 522  Line 531 
531  dec_main(unsigned char *istream,  dec_main(unsigned char *istream,
532           unsigned char *ostream,           unsigned char *ostream,
533           int istream_size,           int istream_size,
534           int *ostream_size)                   xvid_dec_stats_t *xvid_dec_stats)
535  {  {
536    
537          int xerr;          int ret;
538          XVID_DEC_FRAME xframe;  
539            xvid_dec_frame_t xvid_dec_frame;
540    
541            /* Set version */
542            xvid_dec_frame.version = XVID_VERSION;
543            xvid_dec_stats->version = XVID_VERSION;
544    
545            /* No general flags to set */
546            xvid_dec_frame.general          = 0;
547    
548          xframe.bitstream = istream;          /* Input stream */
549          xframe.length = istream_size;          xvid_dec_frame.bitstream        = istream;
550          xframe.image = ostream;          xvid_dec_frame.length           = istream_size;
         xframe.stride = XDIM;  
         xframe.colorspace = XVID_CSP_YV12;  
551    
552          xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);          /* Output frame structure */
553            xvid_dec_frame.output.plane[0]  = ostream;
554            xvid_dec_frame.output.stride[0] = XDIM;
555            xvid_dec_frame.output.csp       = XVID_CSP_I420;
556    
557          *ostream_size = xframe.length;          ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);
558    
559          return xerr;          return(ret);
560  }  }
561    
562  /* close decoder to release resources */  /* close decoder to release resources */
563  static int  static int
564  dec_stop()  dec_stop()
565  {  {
566          int xerr;          int ret;
567    
568          xerr = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);          ret = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);
569    
570          return xerr;          return(ret);
571  }  }

Legend:
Removed from v.547  
changed lines
  Added in v.1416

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4