[svn] / branches / dev-api-4 / xvidcore / examples / xvid_decraw.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/examples/xvid_decraw.c

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

trunk/xvidcore/examples/xvid_decraw.c revision 376, Sat Aug 17 20:03:36 2002 UTC branches/dev-api-4/xvidcore/examples/xvid_decraw.c revision 918, Tue Mar 11 23:39:47 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC - Example for encoding and decoding   *  XVID MPEG-4 VIDEO CODEC
4     *  - Console based decoding test application  -
5     *
6     *  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
# Line 14  Line 17 
17   *   *
18   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
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., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21     *
22     * $Id: xvid_decraw.c,v 1.7.2.1 2003-03-11 23:39:47 edgomez Exp $
23   *   *
24   *************************************************************************/   ****************************************************************************/
25    
26  /************************************************************************  /*****************************************************************************
27   *   *
28   *  Test routine for XviD decoding   *  Application notes :
  *  (C) Christoph Lampert, 2002/08/17  
29   *   *
30   *  An MPEG-4 bitstream is read from stdin and decoded,   *  An MPEG-4 bitstream is read from an input file (or stdin) and decoded,
31   *  the speed for this is measured   *  the speed for this is measured.
32   *   *
33   *  The program is plain C and needs no libraries except for libxvidcore,   *  The program is plain C and needs no libraries except for libxvidcore,
34   *  and maths-lib, so with UN*X you simply compile by   *  and maths-lib, so with UN*X you simply compile by
# Line 34  Line 38 
38   *  You have to specify the image dimensions (until the add the feature   *  You have to specify the image dimensions (until the add the feature
39   *  to read this from the bitstream)   *  to read this from the bitstream)
40   *   *
41   *  Parameters are: xvid_stat XDIM YDIM   * Usage : xvid_decraw <-w width> <-h height> [OPTIONS]
42   *   * Options :
43   *  output and indivual m4v-files are saved, if corresponding flags are set   *  -asm           : use assembly optimizations (default=disabled)
44     *  -i string      : input filename (default=stdin)
45     *  -t integer     : input data type (raw=0, mp4u=1)
46     *  -d             : save decoder output (0 False*, !=0 True)
47     *  -m             : save mpeg4 raw stream to single files (0 False*, !=0 True)
48     *  -help          : This help message
49     * (* means default)
50   *   *
51   ************************************************************************/   ****************************************************************************/
52    
53  #include <stdio.h>  #include <stdio.h>
54  #include <stdlib.h>  #include <stdlib.h>
55  #include <math.h>               // needed for log10  #include <string.h>
56  #include <sys/time.h>           // only needed for gettimeofday  #include <math.h>
57    #ifndef WIN32
58    #include <sys/time.h>
59    #else
60    #include <time.h>
61    #endif
62    
63  #include "../src/xvid.h"                /* comes with XviD */  #include "xvid.h"
64    
65  #define ABS_MAXFRAMENR 9999               // max number of frames  /*****************************************************************************
66     *               Global vars in module and constants
67     ****************************************************************************/
68    
69    /* max number of frames */
70    #define ABS_MAXFRAMENR 9999
71    
72    static int XDIM = 0;
73    static int YDIM = 0;
74    static int ARG_SAVEDECOUTPUT = 0;
75    static int ARG_SAVEMPEGSTREAM = 0;
76    static char *ARG_INPUTFILE = NULL;
77    
78    
79    static char filepath[256] = "./";
80    static void *dec_handle = NULL;
81    
82    # define BUFFER_SIZE (2*1024*1024)
83    
84    /*****************************************************************************
85     *               Local prototypes
86     ****************************************************************************/
87    
88    static double msecond();
89    static int write_pgm(char *filename,
90                                             unsigned char *image);
91    static int dec_init(int use_assembler);
92    static int dec_main(unsigned char *istream,
93                                            unsigned char *ostream,
94                                            int istream_size,
95                                            xvid_dec_stats_t *xvid_dec_stats);
96    static int dec_stop();
97    static void usage();
98    
99    /*****************************************************************************
100     *        Main program
101     ****************************************************************************/
102    
103  int XDIM=720;  int main(int argc, char *argv[])
104  int YDIM=576;  {
105  int i,filenr = 0;          unsigned char *mp4_buffer = NULL;
106            unsigned char *mp4_ptr    = NULL;
107            unsigned char *out_buffer = NULL;
108            unsigned char *type       = NULL;
109            int still_left_in_buffer;
110            int delayed_frames;
111            xvid_dec_stats_t xvid_dec_stats;
112    
113  int save_dec_flag = 1;          // save decompressed bytestream?          double totaldectime;
 int save_m4v_flag = 0;          // save bytestream itself?  
114    
115  char filepath[256] = "./";      // the path where to save output          long totalsize;
116            int status;
117    
118  void *dec_handle = NULL;                // handle for decoding          int use_assembler = 0;
119    
120  /*********************************************************************/          char filename[256];
 /*                     "statistical" functions                               */  
 /*                                                                   */  
 /*  these are not needed for decoding itself, but for measuring      */  
 /*  time (and maybe later quality), there in nothing specific to     */  
 /*  XviD in these                                                    */  
 /*                                                                   */  
 /*********************************************************************/  
121    
122  double msecond()          FILE *in_file;
123  /* return the current time in seconds(!)  */          int filenr;
124  {          int i;
         struct timeval  tv;  
         gettimeofday(&tv, 0);  
         return tv.tv_sec + tv.tv_usec * 1.0e-6;  
 }  
125    
126            printf("xvid_decraw - raw mpeg4 bitstream decoder ");
127            printf("written by Christoph Lampert 2002-2003\n\n");
128    
129  /*********************************************************************/  /*****************************************************************************
130  /*                    input and output functions                         */   * Command line parsing
131  /*                                                                   */   ****************************************************************************/
 /* the are small and simple routines for writing image               */  
 /* image. It's just for convenience, again nothing specific to XviD  */  
 /*                                                                   */  
 /*********************************************************************/  
132    
133  int write_pgm(char *filename, unsigned char *image)          for (i=1; i< argc; i++) {
 {  
         FILE *filehandle;  
         filehandle=fopen(filename,"wb");  
         if (filehandle)  
         {  
                 fprintf(filehandle,"P5\n\n");           //  
                 fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2);  
                 fwrite(image,XDIM,YDIM*3/2,filehandle);  
134    
135                  fclose(filehandle);                  if (strcmp("-asm", argv[i]) == 0 ) {
136                  return 0;                          use_assembler = 1;
137          }          }
138          else                  else if (strcmp("-d", argv[i]) == 0) {
139                  return 1;                          ARG_SAVEDECOUTPUT = 1;
140                    }
141                    else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {
142                            i++;
143                            ARG_INPUTFILE = argv[i];
144                    }
145                    else if (strcmp("-m", argv[i]) == 0) {
146                            ARG_SAVEMPEGSTREAM = 1;
147                    }
148                    else if (strcmp("-help", argv[i])) {
149                            usage();
150                            return(0);
151                    }
152                    else {
153                            usage();
154                            exit(-1);
155  }  }
156    
157            }
158    
159  int write_ppm(char *filename, unsigned char *image)  /*****************************************************************************
160  {   * Values checking
161          FILE *filehandle;   ****************************************************************************/
         filehandle=fopen(filename,"wb");  
         if (filehandle)  
         {  
                 fprintf(filehandle,"P6\n\n");           //  
                 fprintf(filehandle,"%d %d 255\n",XDIM,YDIM);  
                 fwrite(image,XDIM,YDIM*3,filehandle);  
162    
163                  fclose(filehandle);          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
164                  return 0;                  in_file = stdin;
165            }
166            else {
167    
168                    in_file = fopen(ARG_INPUTFILE, "rb");
169                    if (in_file == NULL) {
170                            fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
171                            return(-1);
172          }          }
         else  
                 return 1;  
173  }  }
174    
175  /*********************************************************************/  /*****************************************************************************
176  /* Routines for decoding: init encoder, frame step, release encoder  */   *        Memory allocation
177  /*********************************************************************/   ****************************************************************************/
178    
179  int dec_init(int use_assembler) /* init decoder before first run */          /* Memory for encoded mp4 stream */
180  {          mp4_buffer = (unsigned char *) malloc(BUFFER_SIZE);
181          int xerr;          mp4_ptr = mp4_buffer;
182            if (!mp4_buffer)
183                    goto free_all_memory;
184    
185          XVID_INIT_PARAM xinit;  /*****************************************************************************
186          XVID_DEC_PARAM xparam;   *        XviD PART  Start
187     ****************************************************************************/
188    
189                  if(use_assembler)          status = dec_init(use_assembler);
190  #ifdef ARCH_IA64          if (status) {
191                          xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;                  fprintf(stderr,
192  #else                                  "Decore INIT problem, return value %d\n", status);
193                          xinit.cpu_flags = 0;                  goto release_all;
194  #endif          }
                 else  
                         xinit.cpu_flags = XVID_CPU_FORCE;  
195    
         xvid_init(NULL, 0, &xinit, NULL);  
         xparam.width = XDIM;  
         xparam.height = YDIM;  
196    
197          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);  /*****************************************************************************
198          dec_handle = xparam.handle;   *                               Main loop
199     ****************************************************************************/
200    
201            /* Fill the buffer */
202            still_left_in_buffer = fread(mp4_buffer, 1, BUFFER_SIZE, in_file);
203    
204            totaldectime = 0;
205            totalsize = 0;
206            filenr = 0;
207            delayed_frames = 0;
208            mp4_ptr = mp4_buffer;
209    
210          return xerr;          do {
211  }  
212                    int mp4_size = (mp4_buffer + BUFFER_SIZE - mp4_ptr);
213                    int used_bytes = 0;
214                    double dectime;
215    
216                    /*
217                     * If the buffer is half empty or there are no more bytes in it
218                     * then fill it.
219                     */
220                    if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2 ||
221                            still_left_in_buffer <= 0) {
222                            int rest = (mp4_buffer + BUFFER_SIZE - mp4_ptr);
223    
224                            /* Move data if needed */
225                            if (rest)
226                                    memcpy(mp4_buffer, mp4_ptr, rest);
227    
228                            /* Update mp4_ptr */
229                            mp4_ptr = mp4_buffer;
230    
231  int dec_main(unsigned char *m4v_buffer, unsigned char *out_buffer,int *m4v_size)                          /* read new data */
232  {       /* decode one frame  */                          if(feof(in_file))
233                                    break;
234    
235                            still_left_in_buffer = fread(mp4_buffer + rest,
236                                                                                     1,
237                                                                                     BUFFER_SIZE - rest,
238                                                                                     in_file);
239    
240          int xerr;                  }
         XVID_DEC_FRAME xframe;  
241    
         xframe.bitstream = m4v_buffer;  
         xframe.length = 9999;  
             xframe.image = out_buffer;  
         xframe.stride = XDIM;  
             xframe.colorspace = XVID_CSP_YV12;  
242    
243                    /* This loop is needed to handle VOL/NVOP reading */
244                  do {                  do {
                 xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);  
245    
246                          *m4v_size = xframe.length;                          /* Decode frame */
247                  xframe.bitstream += *m4v_size;                          dectime = msecond();
248                            used_bytes = dec_main(mp4_ptr, out_buffer, mp4_size, &xvid_dec_stats);
249                            dectime = msecond() - dectime;
250    
251                            /* Resize image buffer if needed */
252                            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                  } while (*m4v_size<7);  /* this skips N-VOPs */                          /* Update buffer pointers */
267                            if(used_bytes > 0) {
268                                    mp4_ptr += used_bytes;
269                                    still_left_in_buffer -= used_bytes;
270    
271          return xerr;                                  /* Total size */
272                                    totalsize += used_bytes;
273  }  }
274    
275  int dec_stop()  /* close decoder to release resources */                  }while(xvid_dec_stats.type != XVID_TYPE_IVOP &&
276  {                             xvid_dec_stats.type != XVID_TYPE_PVOP &&
277          int xerr;                             xvid_dec_stats.type != XVID_TYPE_BVOP &&
278          xerr = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);                             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          return xerr;                  /* 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;
292    
293  /*********************************************************************/                  /* Prints some decoding stats */
294  /*                          Main program                             */                  switch(xvid_dec_stats.type) {
295  /*********************************************************************/                  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  int main(int argc, char *argv[])                  printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
310  {                             filenr, type, dectime, used_bytes);
   unsigned char *divx_buffer = NULL;  
   unsigned char *divx_ptr = NULL;  
   unsigned char *out_buffer = NULL;  
311    
312    double dectime;                  /* Save individual mpeg4 stream if required */
313    double totaldectime=0.;                  if(ARG_SAVEMPEGSTREAM) {
314                            FILE *filehandle = NULL;
315    
316    long totalsize=0;                          sprintf(filename, "%sframe%05d.m4v", filepath, filenr);
317    int status;                          filehandle = fopen(filename, "wb");
318                            if(!filehandle) {
319                                    fprintf(stderr,
320                                                    "Error writing single mpeg4 stream to file %s\n",
321                                                    filename);
322                            }
323                            else {
324                                    fwrite(mp4_buffer, 1, used_bytes, filehandle);
325                                    fclose(filehandle);
326                            }
327                    }
328    
329    int m4v_size;                  /* Save output frame if required */
330    int frame_type[ABS_MAXFRAMENR];                  if (ARG_SAVEDECOUTPUT) {
331    int use_assembler=1;                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);
332                            if(write_pgm(filename,out_buffer)) {
333                                    fprintf(stderr,
334                                                    "Error writing decoded PGM frame %s\n",
335                                                    filename);
336                            }
337                    }
338    
339    char filename[256];                  filenr++;
340    
341    FILE *filehandle;          } 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          if (argc>=3)                  /* Prints some decoding stats */
362          {       XDIM = atoi(argv[1]);                  printf("Frame %5d: dectime(ms) =%6.1f, length(bytes) =%7d\n",
363                  YDIM = atoi(argv[2]);                             filenr, dectime, used_bytes);
364                  if ( (XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048) )  
365                  {       fprintf(stderr,"Wrong frames size %d %d, trying PGM \n",XDIM, YDIM);                  /* 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          }          }
         if (argc>=4 && !strcmp(argv[3],"noasm"))  
           use_assembler = 0;  
374    
375                    filenr++;
376    
377  /* allocate memory */          }
378    
379    divx_buffer = (unsigned char *) malloc(10*XDIM*YDIM);  /*****************************************************************************
380    // this should really be enough memory!   *     Calculate totals and averages for output, print results
381    if (!divx_buffer)   ****************************************************************************/
     goto free_all_memory;  
   divx_ptr = divx_buffer+10*XDIM*YDIM;  
382    
383    out_buffer = (unsigned char *) malloc(4*XDIM*YDIM);   /* YUV needs less */          totalsize    /= filenr;
384    if (!out_buffer)          totaldectime /= filenr;
     goto free_all_memory;  
385    
386            printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n",
387                       totaldectime, 1000/totaldectime, (int)totalsize);
388    
389  /*********************************************************************/  /*****************************************************************************
390  /*                         XviD PART  Start                          */   *      XviD PART  Stop
391  /*********************************************************************/   ****************************************************************************/
392    
393          status = dec_init(use_assembler);   release_all:
394            if (dec_handle) {
395                    status = dec_stop();
396          if (status)          if (status)
397          {                          fprintf(stderr, "decore RELEASE problem return value %d\n", status);
                 printf("Decore INIT problem, return value %d\n", status);  
                 goto release_all;  
398          }          }
399    
400     free_all_memory:
401            free(out_buffer);
402            free(mp4_buffer);
403    
404            return(0);
405    }
406    
407  /*********************************************************************/  /*****************************************************************************
408  /*                               Main loop                           */   *               Usage function
409  /*********************************************************************/   ****************************************************************************/
410    
411    do  static void usage()
412      {      {
413    
414          if (divx_ptr > divx_buffer+5*XDIM*YDIM) /* buffer more than half empty */          fprintf(stderr, "Usage : xvid_decraw <-w width> <-h height> [OPTIONS]\n");
415          {       int rest=(divx_buffer+10*XDIM*YDIM-divx_ptr);          fprintf(stderr, "Options :\n");
416                  if (rest)          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");
417                          memcpy(divx_buffer, divx_ptr, rest);          fprintf(stderr, " -i string      : input filename (default=stdin)\n");
418                  divx_ptr = divx_buffer;          fprintf(stderr, " -t integer     : input data type (raw=0, mp4u=1)\n");
419                  fread(divx_buffer+rest, 1, 5*XDIM*YDIM, stdin); /* read new data */          fprintf(stderr, " -d             : save decoder output\n");
420            fprintf(stderr, " -m             : save mpeg4 raw stream to individual files\n");
421            fprintf(stderr, " -help          : This help message\n");
422            fprintf(stderr, " (* means default)\n");
423    
424          }          }
425    
426          dectime = -msecond();  /*****************************************************************************
427          status = dec_main(divx_ptr, out_buffer, &m4v_size);   *               "helper" functions
428     ****************************************************************************/
429    
430          if (status)  /* return the current time in milli seconds */
431    static double
432    msecond()
433          {          {
434                  break;  #ifndef WIN32
435            struct timeval  tv;
436            gettimeofday(&tv, 0);
437            return((double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3);
438    #else
439            clock_t clk;
440            clk = clock();
441            return(clk * 1000 / CLOCKS_PER_SEC);
442    #endif
443          }          }
         dectime += msecond();  
         divx_ptr += m4v_size;  
444    
445          totalsize += m4v_size;  /*****************************************************************************
446     *              output functions
447     ****************************************************************************/
448    
449    static int
450    write_pgm(char *filename,
451                      unsigned char *image)
452    {
453            int loop;
454    
455            unsigned char *y = image;
456            unsigned char *u = image + XDIM*YDIM;
457            unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;
458    
459          printf("Frame %5d: dectime =%6.1f ms length=%7d bytes \n",          FILE *filehandle;
460                          filenr, dectime*1000, m4v_size);          filehandle=fopen(filename,"w+b");
461            if (filehandle) {
462    
463                    /* Write header */
464                    fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2);
465    
466                    /* Write Y data */
467                    fwrite(y, 1, XDIM*YDIM, filehandle);
468    
469          if (save_m4v_flag)                  for(loop=0; loop<YDIM/2; loop++)
470          {          {
471                  sprintf(filename, "%sframe%05d.m4v", filepath, filenr);                          /* Write U scanline */
472                  filehandle = fopen(filename, "wb");                          fwrite(u, 1, XDIM/2, filehandle);
473                  fwrite(divx_buffer, m4v_size, 1, filehandle);  
474                  fclose(filehandle);                          /* Write V scanline */
475                            fwrite(v, 1, XDIM/2, filehandle);
476    
477                            /* Update pointers */
478                            u += XDIM/2;
479                            v += XDIM/2;
480    
481          }          }
         totaldectime += dectime;  
482    
483                    /* Close file */
484                    fclose(filehandle);
485    
486                    return(0);
487            }
488            else
489                    return(1);
490    }
491    
492  /*********************************************************************/  /*****************************************************************************
493  /*        analyse the decoded frame and compare to original          */   * Routines for decoding: init decoder, use, and stop decoder
494  /*********************************************************************/   ****************************************************************************/
495    
496          if (save_dec_flag)  /* init decoder before first run */
497    static int
498    dec_init(int use_assembler)
499          {          {
500                  sprintf(filename, "%sdec%05d.pgm", filepath, filenr);          int ret;
                 write_pgm(filename,out_buffer);  
         }  
501    
502          filenr++;          xvid_gbl_init_t   xvid_gbl_init;
503            xvid_dec_create_t xvid_dec_create;
504    
505     } while ( (status>=0) && (filenr<ABS_MAXFRAMENR) );          /*------------------------------------------------------------------------
506             * XviD core initialization
507             *----------------------------------------------------------------------*/
508    
509            /* Version */
510            xvid_gbl_init.version = XVID_VERSION;
511    
512  /*********************************************************************/          /* Assembly setting */
513  /*     calculate totals and averages for output, print results       */          if(use_assembler)
514  /*********************************************************************/  #ifdef ARCH_IS_IA64
515                    xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;
516    #else
517            xvid_gbl_init.cpu_flags = 0;
518    #endif
519            else
520                    xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
521    
522          totalsize    /= filenr;          xvid_global(NULL, 0, &xvid_gbl_init, NULL);
         totaldectime /= filenr;  
523    
524          fprintf(stderr,"Avg: dectime %5.2f ms, %5.2f fps, filesize =%d\n",          /*------------------------------------------------------------------------
525                  1000*totaldectime, 1./totaldectime, totalsize);           * XviD encoder initialization
526             *----------------------------------------------------------------------*/
527    
528  /*********************************************************************/          /* Version */
529  /*                         XviD PART  Stop                           */          xvid_dec_create.version = XVID_VERSION;
 /*********************************************************************/  
530    
531  release_all:          /*
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          if (dec_handle)  /* decode one frame  */
546    static int
547    dec_main(unsigned char *istream,
548                     unsigned char *ostream,
549                     int istream_size,
550                     xvid_dec_stats_t *xvid_dec_stats)
551          {          {
552                  status = dec_stop();  
553                  if (status)          int ret;
554                          printf("Decore RELEASE problem return value %d\n", status);  
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            /* Input stream */
565            xvid_dec_frame.bitstream        = istream;
566            xvid_dec_frame.length           = istream_size;
567    
568            /* 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            ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);
574    
575            return(ret);
576          }          }
577    
578  free_all_memory:  /* close decoder to release resources */
579          free(out_buffer);  static int
580          free(divx_buffer);  dec_stop()
581    {
582            int ret;
583    
584            ret = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);
585    
586    return 0;          return(ret);
587  }  }

Legend:
Removed from v.376  
changed lines
  Added in v.918

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