[svn] / branches / release-1_0-branch / xvidcore / examples / xvid_decraw.c Repository:
ViewVC logotype

Diff of /branches/release-1_0-branch/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/release-1_0-branch/xvidcore/examples/xvid_decraw.c revision 1414, Wed Apr 7 22:02:56 2004 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     *               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 14  Line 18 
18   *   *
19   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
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., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22     *
23     * $Id: xvid_decraw.c,v 1.10.2.1 2004-04-07 22:02:56 edgomez Exp $
24   *   *
25   *************************************************************************/   ****************************************************************************/
26    
27  /************************************************************************  /*****************************************************************************
28   *   *
29   *  Test routine for XviD decoding   *  Application notes :
  *  (C) Christoph Lampert, 2002/08/17  
30   *   *
31   *  An MPEG-4 bitstream is read from stdin and decoded,   *  An MPEG-4 bitstream is read from an input file (or stdin) and decoded,
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.
  *  
  *   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)  
  *  
  *  Parameters are: xvid_stat XDIM YDIM  
36   *   *
37   *  output and indivual m4v-files are saved, if corresponding flags are set   *  Use ./xvid_decraw -help for a list of options
38   *   *
39   ************************************************************************/   ****************************************************************************/
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <stdlib.h>  #include <stdlib.h>
43  #include <math.h>               // needed for log10  #include <string.h>
44  #include <sys/time.h>           // only needed for gettimeofday  #include <math.h>
45    #ifndef WIN32
46    #include <sys/time.h>
47    #else
48    #include <time.h>
49    #endif
50    
51  #include "../src/xvid.h"                /* comes with XviD */  #include "xvid.h"
52    
53  #define ABS_MAXFRAMENR 9999               // max number of frames  /*****************************************************************************
54     *               Global vars in module and constants
55     ****************************************************************************/
56    
57    /* max number of frames */
58    #define ABS_MAXFRAMENR 9999
59    
60    static int XDIM = 0;
61    static int YDIM = 0;
62    static int ARG_SAVEDECOUTPUT = 0;
63    static int ARG_SAVEMPEGSTREAM = 0;
64    static char *ARG_INPUTFILE = NULL;
65    static int CSP = XVID_CSP_I420;
66    static int BPP = 1;
67    
68    static char filepath[256] = "./";
69    static void *dec_handle = NULL;
70    
71    #define BUFFER_SIZE (2*1024*1024)
72    
73    /*****************************************************************************
74     *               Local prototypes
75     ****************************************************************************/
76    
77    static double msecond();
78    static int write_pgm(char *filename,
79                                             unsigned char *image);
80    static int dec_init(int use_assembler);
81    static int dec_main(unsigned char *istream,
82                                            unsigned char *ostream,
83                                            int istream_size,
84                                            xvid_dec_stats_t *xvid_dec_stats);
85    static int dec_stop();
86    static void usage();
87    
88    
89    const char * type2str(int type)
90    {
91        if (type==XVID_TYPE_IVOP)
92            return "I";
93        if (type==XVID_TYPE_PVOP)
94            return "P";
95        if (type==XVID_TYPE_BVOP)
96            return "B";
97        return "S";
98    }
99    
100    /*****************************************************************************
101     *        Main program
102     ****************************************************************************/
103    
104  int XDIM=720;  int main(int argc, char *argv[])
105  int YDIM=576;  {
106  int i,filenr = 0;          unsigned char *mp4_buffer = NULL;
107            unsigned char *mp4_ptr    = NULL;
108            unsigned char *out_buffer = NULL;
109            int useful_bytes;
110            xvid_dec_stats_t xvid_dec_stats;
111    
112  int save_dec_flag = 1;          // save decompressed bytestream?          double totaldectime;
 int save_m4v_flag = 0;          // save bytestream itself?  
113    
114  char filepath[256] = "./";      // the path where to save output          long totalsize;
115            int status;
116    
117  void *dec_handle = NULL;                // handle for decoding          int use_assembler = 0;
118    
119  /*********************************************************************/          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                                                    */  
 /*                                                                   */  
 /*********************************************************************/  
120    
121  double msecond()          FILE *in_file;
122  /* return the current time in seconds(!)  */          int filenr;
123  {          int i;
124          struct timeval  tv;  
125          gettimeofday(&tv, 0);          printf("xvid_decraw - raw mpeg4 bitstream decoder ");
126          return tv.tv_sec + tv.tv_usec * 1.0e-6;          printf("written by Christoph Lampert 2002-2003\n\n");
127    
128    /*****************************************************************************
129     * Command line parsing
130     ****************************************************************************/
131    
132            for (i=1; i< argc; i++) {
133    
134                    if (strcmp("-asm", argv[i]) == 0 ) {
135                            use_assembler = 1;
136                    } else if (strcmp("-d", argv[i]) == 0) {
137                            ARG_SAVEDECOUTPUT = 1;
138                    } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {
139                            i++;
140                            ARG_INPUTFILE = argv[i];
141                    } else if (strcmp("-m", argv[i]) == 0) {
142                            ARG_SAVEMPEGSTREAM = 1;
143                    } else if (strcmp("-c", argv[i]) == 0  && i < argc - 1 ) {
144                            i++;
145                            if (strcmp(argv[i], "rgb16") == 0) {
146                                    CSP = XVID_CSP_RGB555;
147                                    BPP = 2;
148                            } else if (strcmp(argv[i], "rgb24") == 0) {
149                                    CSP = XVID_CSP_BGR;
150                                    BPP = 3;
151                            } else if (strcmp(argv[i], "rgb32") == 0) {
152                                    CSP = XVID_CSP_BGRA;
153                                    BPP = 4;
154                            } else if (strcmp(argv[i], "yv12") == 0) {
155                                    CSP = XVID_CSP_YV12;
156                                    BPP = 1;
157                            } else {
158                                    CSP = XVID_CSP_I420;
159                                    BPP = 1;
160                            }
161                    } else if (strcmp("-help", argv[i]) == 0) {
162                            usage();
163                            return(0);
164                    } else {
165                            usage();
166                            exit(-1);
167                    }
168            }
169    
170    /*****************************************************************************
171     * Values checking
172     ****************************************************************************/
173    
174            if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
175                    in_file = stdin;
176            }
177            else {
178    
179                    in_file = fopen(ARG_INPUTFILE, "rb");
180                    if (in_file == NULL) {
181                            fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
182                            return(-1);
183                    }
184            }
185    
186    /*****************************************************************************
187     *        Memory allocation
188     ****************************************************************************/
189    
190            /* Memory for encoded mp4 stream */
191            mp4_buffer = (unsigned char *) malloc(BUFFER_SIZE);
192            mp4_ptr = mp4_buffer;
193            if (!mp4_buffer)
194                    goto free_all_memory;
195    
196    /*****************************************************************************
197     *        XviD PART  Start
198     ****************************************************************************/
199    
200            status = dec_init(use_assembler);
201            if (status) {
202                    fprintf(stderr,
203                                    "Decore INIT problem, return value %d\n", status);
204                    goto release_all;
205  }  }
206    
207    
208  /*********************************************************************/  /*****************************************************************************
209  /*                    input and output functions                         */   *                               Main loop
210  /*                                                                   */   ****************************************************************************/
211  /* the are small and simple routines for writing image               */  
212  /* image. It's just for convenience, again nothing specific to XviD  */          /* Fill the buffer */
213  /*                                                                   */          useful_bytes = fread(mp4_buffer, 1, BUFFER_SIZE, in_file);
214  /*********************************************************************/  
215            totaldectime = 0;
216            totalsize = 0;
217            filenr = 0;
218            mp4_ptr = mp4_buffer;
219    
220  int write_pgm(char *filename, unsigned char *image)          do {
221  {                  int used_bytes = 0;
222          FILE *filehandle;                  double dectime;
         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);  
223    
224                  fclose(filehandle);                  /*
225                  return 0;                   * If the buffer is half empty or there are no more bytes in it
226          }                   * then fill it.
227          else                   */
228                  return 1;                  if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) {
229  }                          int already_in_buffer = (mp4_buffer + BUFFER_SIZE - mp4_ptr);
230    
231                            /* Move data if needed */
232                            if (already_in_buffer > 0)
233                                    memcpy(mp4_buffer, mp4_ptr, already_in_buffer);
234    
235                            /* Update mp4_ptr */
236                            mp4_ptr = mp4_buffer;
237    
238  int write_ppm(char *filename, unsigned char *image)                          /* read new data */
239  {              if(feof(in_file))
240          FILE *filehandle;                                  break;
         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);  
241    
242                  fclose(filehandle);                          useful_bytes += fread(mp4_buffer + already_in_buffer,
243                  return 0;                                                                    1, BUFFER_SIZE - already_in_buffer,
244          }                                                                    in_file);
         else  
                 return 1;  
 }  
245    
246  /*********************************************************************/                  }
 /* Routines for decoding: init encoder, frame step, release encoder  */  
 /*********************************************************************/  
247    
 int dec_init(int use_assembler) /* init decoder before first run */  
 {  
         int xerr;  
248    
249          XVID_INIT_PARAM xinit;                  /* This loop is needed to handle VOL/NVOP reading */
250          XVID_DEC_PARAM xparam;                  do {
251    
252                  if(use_assembler)                          /* Decode frame */
253  #ifdef ARCH_IA64                          dectime = msecond();
254                          xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;                          used_bytes = dec_main(mp4_ptr, out_buffer, useful_bytes, &xvid_dec_stats);
255  #else                          dectime = msecond() - dectime;
256                          xinit.cpu_flags = 0;  
257  #endif                          /* Resize image buffer if needed */
258                  else                          if(xvid_dec_stats.type == XVID_TYPE_VOL) {
259                          xinit.cpu_flags = XVID_CPU_FORCE;  
260                                    /* Check if old buffer is smaller */
261                                    if(XDIM*YDIM < xvid_dec_stats.data.vol.width*xvid_dec_stats.data.vol.height) {
262    
263                                            /* Copy new witdh and new height from the vol structure */
264                                            XDIM = xvid_dec_stats.data.vol.width;
265                                            YDIM = xvid_dec_stats.data.vol.height;
266    
267                                            /* Free old output buffer*/
268                                            if(out_buffer) free(out_buffer);
269    
270                                            /* Allocate the new buffer */
271                                            out_buffer = (unsigned char*)malloc(XDIM*YDIM*4);
272                                            if(out_buffer == NULL)
273                                                    goto free_all_memory;
274    
275          xvid_init(NULL, 0, &xinit, NULL);                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);
276          xparam.width = XDIM;                                  }
277          xparam.height = YDIM;                          }
278    
279          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);                          /* Update buffer pointers */
280          dec_handle = xparam.handle;                          if(used_bytes > 0) {
281                                    mp4_ptr += used_bytes;
282                                    useful_bytes -= used_bytes;
283    
284          return xerr;                                  /* Total size */
285                                    totalsize += used_bytes;
286  }  }
287    
288  int dec_main(unsigned char *m4v_buffer, unsigned char *out_buffer,int *m4v_size)                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);
 {       /* decode one frame  */  
289    
290          int xerr;                  /* Check if there is a negative number of useful bytes left in buffer
291          XVID_DEC_FRAME xframe;                   * This means we went too far */
292            if(useful_bytes < 0)
293                break;
294    
295          xframe.bitstream = m4v_buffer;          /* Updated data - Count only usefull decode time */
296          xframe.length = 9999;                  totaldectime += dectime;
             xframe.image = out_buffer;  
         xframe.stride = XDIM;  
             xframe.colorspace = XVID_CSP_YV12;  
297    
                 do {  
                 xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);  
298    
299                          *m4v_size = xframe.length;          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
300                  xframe.bitstream += *m4v_size;                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
301    
302                  } while (*m4v_size<7);  /* this skips N-VOPs */                  /* Save individual mpeg4 stream if required */
303                    if(ARG_SAVEMPEGSTREAM) {
304                            FILE *filehandle = NULL;
305    
306          return xerr;                          sprintf(filename, "%sframe%05d.m4v", filepath, filenr);
307                            filehandle = fopen(filename, "wb");
308                            if(!filehandle) {
309                                    fprintf(stderr,
310                                                    "Error writing single mpeg4 stream to file %s\n",
311                                                    filename);
312                            }
313                            else {
314                                    fwrite(mp4_ptr-used_bytes, 1, used_bytes, filehandle);
315                                    fclose(filehandle);
316                            }
317  }  }
318    
319  int dec_stop()  /* close decoder to release resources */                  /* Save output frame if required */
320  {                  if (ARG_SAVEDECOUTPUT) {
321          int xerr;                          sprintf(filename, "%sdec%05d.tga", filepath, filenr);
322          xerr = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);                          if(write_tga(filename,out_buffer)) {
323                                    fprintf(stderr,
324          return xerr;                                                  "Error writing decoded PGM frame %s\n",
325                                                    filename);
326                            }
327  }  }
328    
329                    filenr++;
330    
331  /*********************************************************************/          } while ( (status>=0) && (filenr<ABS_MAXFRAMENR));
 /*                          Main program                             */  
 /*********************************************************************/  
332    
333  int main(int argc, char *argv[])  /*****************************************************************************
334  {   *     Flush decoder buffers
335    unsigned char *divx_buffer = NULL;   ****************************************************************************/
   unsigned char *divx_ptr = NULL;  
   unsigned char *out_buffer = NULL;  
336    
337    double dectime;          do {
   double totaldectime=0.;  
338    
339    long totalsize=0;                  /* Fake vars */
340    int status;                  int used_bytes;
341                    double dectime;
342    
343    int m4v_size;          do {
344    int frame_type[ABS_MAXFRAMENR];                      dectime = msecond();
345    int use_assembler=1;                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);
346                        dectime = msecond() - dectime;
347            }while(used_bytes>=0 && xvid_dec_stats.type <= 0);
348    
349    char filename[256];          if (used_bytes < 0) {   /* XVID_ERR_END */
350                break;
351            }
352    
353    FILE *filehandle;                  /* Updated data - Count only usefull decode time */
354                    totaldectime += dectime;
355    
356          if (argc>=3)                  /* Prints some decoding stats */
357          {       XDIM = atoi(argv[1]);          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
358                  YDIM = atoi(argv[2]);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
359                  if ( (XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048) )  
360                  {       fprintf(stderr,"Wrong frames size %d %d, trying PGM \n",XDIM, YDIM);                  /* Save output frame if required */
361                    if (ARG_SAVEDECOUTPUT) {
362                            sprintf(filename, "%sdec%05d.tga", filepath, filenr);
363                            if(write_tga(filename, out_buffer)) {
364                                    fprintf(stderr,
365                                                    "Error writing decoded PGM frame %s\n",
366                                                    filename);
367                  }                  }
368          }          }
         if (argc>=4 && !strcmp(argv[3],"noasm"))  
           use_assembler = 0;  
369    
370                    filenr++;
371    
372  /* allocate memory */          }while(1);
373    
374    divx_buffer = (unsigned char *) malloc(10*XDIM*YDIM);  /*****************************************************************************
375    // this should really be enough memory!   *     Calculate totals and averages for output, print results
376    if (!divx_buffer)   ****************************************************************************/
     goto free_all_memory;  
   divx_ptr = divx_buffer+10*XDIM*YDIM;  
377    
378    out_buffer = (unsigned char *) malloc(4*XDIM*YDIM);   /* YUV needs less */          totalsize    /= filenr;
379    if (!out_buffer)          totaldectime /= filenr;
     goto free_all_memory;  
380    
381            printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n",
382                       totaldectime, 1000/totaldectime, (int)totalsize);
383    
384  /*********************************************************************/  /*****************************************************************************
385  /*                         XviD PART  Start                          */   *      XviD PART  Stop
386  /*********************************************************************/   ****************************************************************************/
387    
388          status = dec_init(use_assembler);   release_all:
389            if (dec_handle) {
390                    status = dec_stop();
391          if (status)          if (status)
392          {                          fprintf(stderr, "decore RELEASE problem return value %d\n", status);
                 printf("Decore INIT problem, return value %d\n", status);  
                 goto release_all;  
393          }          }
394    
395     free_all_memory:
396            free(out_buffer);
397            free(mp4_buffer);
398    
399            return(0);
400    }
401    
402  /*********************************************************************/  /*****************************************************************************
403  /*                               Main loop                           */   *               Usage function
404  /*********************************************************************/   ****************************************************************************/
405    
406    do  static void usage()
407      {      {
408    
409          if (divx_ptr > divx_buffer+5*XDIM*YDIM) /* buffer more than half empty */          fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n");
410          {       int rest=(divx_buffer+10*XDIM*YDIM-divx_ptr);          fprintf(stderr, "Options :\n");
411                  if (rest)          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");
412                          memcpy(divx_buffer, divx_ptr, rest);          fprintf(stderr, " -i string      : input filename (default=stdin)\n");
413                  divx_ptr = divx_buffer;          fprintf(stderr, " -d             : save decoder output\n");
414                  fread(divx_buffer+rest, 1, 5*XDIM*YDIM, stdin); /* read new data */          fprintf(stderr, " -c csp         : choose colorspace output (csp can be one of rgb16, rgb24, rgb32, yv12, i420)\n");
415            fprintf(stderr, " -m             : save mpeg4 raw stream to individual files\n");
416            fprintf(stderr, " -help          : This help message\n");
417            fprintf(stderr, " (* means default)\n");
418    
419          }          }
420    
421          dectime = -msecond();  /*****************************************************************************
422          status = dec_main(divx_ptr, out_buffer, &m4v_size);   *               "helper" functions
423     ****************************************************************************/
424    
425          if (status)  /* return the current time in milli seconds */
426    static double
427    msecond()
428          {          {
429                  break;  #ifndef WIN32
430            struct timeval  tv;
431            gettimeofday(&tv, 0);
432            return((double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3);
433    #else
434            clock_t clk;
435            clk = clock();
436            return(clk * 1000 / CLOCKS_PER_SEC);
437    #endif
438          }          }
         dectime += msecond();  
         divx_ptr += m4v_size;  
439    
440          totalsize += m4v_size;  /*****************************************************************************
441     *              output functions
442     ****************************************************************************/
443    
444    int write_tga(char *filename, unsigned char *image)
445    {
446            FILE * f;
447            char hdr[18];
448    
449            f = fopen(filename, "wb");
450            if ( f == NULL) {
451                    return -1;
452            }
453    
454            hdr[0]  = 0; /* ID length */
455            hdr[1]  = 0; /* Color map type */
456            hdr[2]  = (BPP>1)?2:3; /* Uncompressed true color (2) or greymap (3) */
457            hdr[3]  = 0; /* Color map specification (not used) */
458            hdr[4]  = 0; /* Color map specification (not used) */
459            hdr[5]  = 0; /* Color map specification (not used) */
460            hdr[6]  = 0; /* Color map specification (not used) */
461            hdr[7]  = 0; /* Color map specification (not used) */
462            hdr[8]  = 0; /* LSB X origin */
463            hdr[9]  = 0; /* MSB X origin */
464            hdr[10] = 0; /* LSB Y origin */
465            hdr[11] = 0; /* MSB Y origin */
466            hdr[12] = (XDIM>>0)&0xff; /* LSB Width */
467            hdr[13] = (XDIM>>8)&0xff; /* MSB Width */
468            if (BPP > 1) {
469                    hdr[14] = (YDIM>>0)&0xff; /* LSB Height */
470                    hdr[15] = (YDIM>>8)&0xff; /* MSB Height */
471            } else {
472                    hdr[14] = ((YDIM*3)>>1)&0xff; /* LSB Height */
473                    hdr[15] = ((YDIM*3)>>9)&0xff; /* MSB Height */
474            }
475            hdr[16] = BPP*8;
476            hdr[17] = 0x00 | (1<<5) /* Up to down */ | (0<<4); /* Image descriptor */
477    
478            /* Write header */
479            fwrite(hdr, 1, sizeof(hdr), f);
480    
481    #ifdef ARCH_IS_LITTLE_ENDIAN
482            /* write first plane */
483            fwrite(image, 1, XDIM*YDIM*BPP, f);
484    #else
485            {
486                    int i;
487                    for (i=0; i<width*height*BPP;i+=BPP) {
488                            if (BPP == 1) {
489                                    fputc(image+i, f);
490                            } else if (BPP == 2) {
491                                    fputc(image+i+1, f);
492                                    fputc(image+i+0, f);
493                            } else if (BPP == 3) {
494                                    fputc(image+i+2, f);
495                                    fputc(image+i+1, f);
496                                    fputc(image+i+0, f);
497                            } else if (BPP == 4) {
498                                    fputc(image+i+3, f);
499                                    fputc(image+i+2, f);
500                                    fputc(image+i+1, f);
501                                    fputc(image+i+0, f);
502                            }
503                    }
504            }
505    #endif
506    
507          printf("Frame %5d: dectime =%6.1f ms length=%7d bytes \n",          /* Write Y and V planes for YUV formats */
508                          filenr, dectime*1000, m4v_size);          if (BPP == 1) {
509                    int i;
510    
511          if (save_m4v_flag)                  /* Write the two chrominance planes */
512          {                  for (i=0; i<YDIM/2; i++) {
513                  sprintf(filename, "%sframe%05d.m4v", filepath, filenr);                          fwrite(image+XDIM*YDIM+XDIM/2*i, 1, XDIM/2, f);
514                  filehandle = fopen(filename, "wb");                          fwrite(image+5*XDIM*YDIM/4 + XDIM/2*i, 1, XDIM/2, f);
515                  fwrite(divx_buffer, m4v_size, 1, filehandle);                  }
                 fclose(filehandle);  
516          }          }
         totaldectime += dectime;  
517    
518    
519  /*********************************************************************/          /* Close the file */
520  /*        analyse the decoded frame and compare to original          */          fclose(f);
 /*********************************************************************/  
521    
522          if (save_dec_flag)          return(0);
         {  
                 sprintf(filename, "%sdec%05d.pgm", filepath, filenr);  
                 write_pgm(filename,out_buffer);  
523          }          }
524    
525          filenr++;  /*****************************************************************************
526     * Routines for decoding: init decoder, use, and stop decoder
527     ****************************************************************************/
528    
529     } while ( (status>=0) && (filenr<ABS_MAXFRAMENR) );  /* init decoder before first run */
530    static int
531    dec_init(int use_assembler)
532    {
533            int ret;
534    
535            xvid_gbl_init_t   xvid_gbl_init;
536            xvid_dec_create_t xvid_dec_create;
537    
538  /*********************************************************************/          /*------------------------------------------------------------------------
539  /*     calculate totals and averages for output, print results       */           * XviD core initialization
540  /*********************************************************************/           *----------------------------------------------------------------------*/
541    
542          totalsize    /= filenr;          /* Version */
543          totaldectime /= filenr;          xvid_gbl_init.version = XVID_VERSION;
544    
545          fprintf(stderr,"Avg: dectime %5.2f ms, %5.2f fps, filesize =%d\n",          /* Assembly setting */
546                  1000*totaldectime, 1./totaldectime, totalsize);          if(use_assembler)
547    #ifdef ARCH_IS_IA64
548                    xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;
549    #else
550            xvid_gbl_init.cpu_flags = 0;
551    #endif
552            else
553                    xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
554    
555  /*********************************************************************/          xvid_global(NULL, 0, &xvid_gbl_init, NULL);
 /*                         XviD PART  Stop                           */  
 /*********************************************************************/  
556    
557  release_all:          /*------------------------------------------------------------------------
558             * XviD encoder initialization
559             *----------------------------------------------------------------------*/
560    
561            /* Version */
562            xvid_dec_create.version = XVID_VERSION;
563    
564            /*
565             * Image dimensions -- set to 0, xvidcore will resize when ever it is
566             * needed
567             */
568            xvid_dec_create.width = 0;
569            xvid_dec_create.height = 0;
570    
571            ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL);
572    
573          if (dec_handle)          dec_handle = xvid_dec_create.handle;
574    
575            return(ret);
576    }
577    
578    /* decode one frame  */
579    static int
580    dec_main(unsigned char *istream,
581                     unsigned char *ostream,
582                     int istream_size,
583                     xvid_dec_stats_t *xvid_dec_stats)
584          {          {
585                  status = dec_stop();  
586                  if (status)          int ret;
587                          printf("Decore RELEASE problem return value %d\n", status);  
588            xvid_dec_frame_t xvid_dec_frame;
589    
590            /* Set version */
591            xvid_dec_frame.version = XVID_VERSION;
592            xvid_dec_stats->version = XVID_VERSION;
593    
594            /* No general flags to set */
595            xvid_dec_frame.general          = 0;
596    
597            /* Input stream */
598            xvid_dec_frame.bitstream        = istream;
599            xvid_dec_frame.length           = istream_size;
600    
601            /* Output frame structure */
602            xvid_dec_frame.output.plane[0]  = ostream;
603            xvid_dec_frame.output.stride[0] = XDIM*BPP;
604            xvid_dec_frame.output.csp = CSP;
605    
606            ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);
607    
608            return(ret);
609          }          }
610    
611  free_all_memory:  /* close decoder to release resources */
612          free(out_buffer);  static int
613          free(divx_buffer);  dec_stop()
614    {
615            int ret;
616    
617            ret = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);
618    
619    return 0;          return(ret);
620  }  }

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

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