[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 1423, Mon Apr 12 14:05:08 2004 UTC revision 1547, Sat Sep 4 14:16:24 2004 UTC
# Line 20  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.12 2004-04-12 14:05:08 edgomez Exp $   * $Id: xvid_decraw.c,v 1.19 2004-09-04 14:16:24 edgomez Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 54  Line 54 
54   *               Global vars in module and constants   *               Global vars in module and constants
55   ****************************************************************************/   ****************************************************************************/
56    
 /* max number of frames */  
 #define ABS_MAXFRAMENR 9999  
   
57  #define USE_PNM 0  #define USE_PNM 0
58  #define USE_TGA 1  #define USE_TGA 1
59    
# Line 74  Line 71 
71    
72  #define BUFFER_SIZE (2*1024*1024)  #define BUFFER_SIZE (2*1024*1024)
73    
74    static const int display_buffer_bytes = 0;
75    
76  /*****************************************************************************  /*****************************************************************************
77   *               Local prototypes   *               Local prototypes
78   ****************************************************************************/   ****************************************************************************/
79    
80  static double msecond();  static double msecond();
 static int write_pgm(char *filename,  
                                          unsigned char *image);  
81  static int dec_init(int use_assembler, int debug_level);  static int dec_init(int use_assembler, int debug_level);
82  static int dec_main(unsigned char *istream,  static int dec_main(unsigned char *istream,
83                                          unsigned char *ostream,                                          unsigned char *ostream,
# Line 88  Line 85 
85                                          xvid_dec_stats_t *xvid_dec_stats);                                          xvid_dec_stats_t *xvid_dec_stats);
86  static int dec_stop();  static int dec_stop();
87  static void usage();  static void usage();
88    static int write_image(char *prefix, unsigned char *image);
89    static int write_pnm(char *filename, unsigned char *image);
90    static int write_tga(char *filename, unsigned char *image);
91    
92  const char * type2str(int type)  const char * type2str(int type)
93  {  {
# Line 111  Line 110 
110          unsigned char *mp4_ptr    = NULL;          unsigned char *mp4_ptr    = NULL;
111          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
112          int useful_bytes;          int useful_bytes;
113            int chunk;
114          xvid_dec_stats_t xvid_dec_stats;          xvid_dec_stats_t xvid_dec_stats;
115    
116          double totaldectime;          double totaldectime;
# Line 184  Line 184 
184                  }                  }
185          }          }
186    
187    #if defined(_MSC_VER)
188            if (ARG_INPUTFILE==NULL) {
189                    fprintf(stderr, "Warning: MSVC build does not read EOF correctly from stdin. Use the -i switch.\n\n");
190            }
191    #endif
192    
193  /*****************************************************************************  /*****************************************************************************
194   * Values checking   * Values checking
195   ****************************************************************************/   ****************************************************************************/
# Line 238  Line 244 
244          totalsize = 0;          totalsize = 0;
245          filenr = 0;          filenr = 0;
246          mp4_ptr = mp4_buffer;          mp4_ptr = mp4_buffer;
247            chunk = 0;
248    
249          do {          do {
250                  int used_bytes = 0;                  int used_bytes = 0;
# Line 296  Line 303 
303    
304                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);
305                                  }                                  }
306    
307                                    /* Save individual mpeg4 stream if required */
308                                    if(ARG_SAVEMPEGSTREAM) {
309                                            FILE *filehandle = NULL;
310    
311                                            sprintf(filename, "%svolhdr.m4v", filepath);
312                                            filehandle = fopen(filename, "wb");
313                                            if(!filehandle) {
314                                                    fprintf(stderr,
315                                                                    "Error writing vol header mpeg4 stream to file %s\n",
316                                                                    filename);
317                                            } else {
318                                                    fwrite(mp4_ptr, 1, used_bytes, filehandle);
319                                                    fclose(filehandle);
320                                            }
321                                    }
322                          }                          }
323    
324                          /* Update buffer pointers */                          /* Update buffer pointers */
# Line 307  Line 330 
330                                  totalsize += used_bytes;                                  totalsize += used_bytes;
331                          }                          }
332    
333                            if (display_buffer_bytes) {
334                                    printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes);
335                            }
336                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);
337    
338                  /* Check if there is a negative number of useful bytes left in buffer                  /* Check if there is a negative number of useful bytes left in buffer
# Line 318  Line 344 
344                  totaldectime += dectime;                  totaldectime += dectime;
345    
346    
347                    if (!display_buffer_bytes) {
348          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
349                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
350                    }
351    
352                  /* Save individual mpeg4 stream if required */                  /* Save individual mpeg4 stream if required */
353                  if(ARG_SAVEMPEGSTREAM) {                  if(ARG_SAVEMPEGSTREAM) {
# Line 343  Line 371 
371                          sprintf(filename, "%sdec%05d", filepath, filenr);                          sprintf(filename, "%sdec%05d", filepath, filenr);
372                          if(write_image(filename, out_buffer)) {                          if(write_image(filename, out_buffer)) {
373                                  fprintf(stderr,                                  fprintf(stderr,
374                                                  "Error writing decoded PGM frame %s\n",                                                  "Error writing decoded frame %s\n",
375                                                  filename);                                                  filename);
376                          }                          }
377                  }                  }
378    
379                  filenr++;                  filenr++;
380    
381          } while ( (status>=0) && (filenr<ABS_MAXFRAMENR));          } while (useful_bytes>0 || !feof(in_file));
382    
383            useful_bytes = 0; /* Empty buffer */
384    
385  /*****************************************************************************  /*****************************************************************************
386   *     Flush decoder buffers   *     Flush decoder buffers
# Line 366  Line 396 
396                      dectime = msecond();                      dectime = msecond();
397                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);
398                      dectime = msecond() - dectime;                      dectime = msecond() - dectime;
399                            if (display_buffer_bytes) {
400                                    printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes);
401                            }
402          }while(used_bytes>=0 && xvid_dec_stats.type <= 0);          }while(used_bytes>=0 && xvid_dec_stats.type <= 0);
403    
404          if (used_bytes < 0) {   /* XVID_ERR_END */          if (used_bytes < 0) {   /* XVID_ERR_END */
# Line 376  Line 409 
409                  totaldectime += dectime;                  totaldectime += dectime;
410    
411                  /* Prints some decoding stats */                  /* Prints some decoding stats */
412                    if (!display_buffer_bytes) {
413          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
414                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
415                    }
416    
417                  /* Save output frame if required */                  /* Save output frame if required */
418                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
419                          sprintf(filename, "%sdec%05d", filepath, filenr);                          sprintf(filename, "%sdec%05d", filepath, filenr);
420                          if(write_image(filename, out_buffer)) {                          if(write_image(filename, out_buffer)) {
421                                  fprintf(stderr,                                  fprintf(stderr,
422                                                  "Error writing decoded PGM frame %s\n",                                                  "Error writing decoded frame %s\n",
423                                                  filename);                                                  filename);
424                          }                          }
425                  }                  }
# Line 397  Line 432 
432   *     Calculate totals and averages for output, print results   *     Calculate totals and averages for output, print results
433   ****************************************************************************/   ****************************************************************************/
434    
435            if (filenr>0) {
436          totalsize    /= filenr;          totalsize    /= filenr;
437          totaldectime /= filenr;          totaldectime /= filenr;
   
438          printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n",          printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n",
439                     totaldectime, 1000/totaldectime, (int)totalsize);                     totaldectime, 1000/totaldectime, (int)totalsize);
440            }else{
441                    printf("Nothing was decoded!\n");
442            }
443    
444  /*****************************************************************************  /*****************************************************************************
445   *      XviD PART  Stop   *      XviD PART  Stop
# Line 465  Line 503 
503   *              output functions   *              output functions
504   ****************************************************************************/   ****************************************************************************/
505    
506  int write_image(char *prefix, unsigned char *image)  static int write_image(char *prefix, unsigned char *image)
507  {  {
508          char filename[1024];          char filename[1024];
509          char *ext;          char *ext;
# Line 493  Line 531 
531          return(ret);          return(ret);
532  }  }
533    
534  int write_tga(char *filename, unsigned char *image)  static int write_tga(char *filename, unsigned char *image)
535  {  {
536          FILE * f;          FILE * f;
537          char hdr[18];          char hdr[18];
# Line 574  Line 612 
612          return(0);          return(0);
613  }  }
614    
615  int write_pnm(char *filename, unsigned char *image)  static int write_pnm(char *filename, unsigned char *image)
616  {  {
617          FILE * f;          FILE * f;
618    
# Line 613  Line 651 
651    
652          return 0;          return 0;
653  }  }
654    
655  /*****************************************************************************  /*****************************************************************************
656   * Routines for decoding: init decoder, use, and stop decoder   * Routines for decoding: init decoder, use, and stop decoder
657   ****************************************************************************/   ****************************************************************************/
# Line 626  Line 665 
665          xvid_gbl_init_t   xvid_gbl_init;          xvid_gbl_init_t   xvid_gbl_init;
666          xvid_dec_create_t xvid_dec_create;          xvid_dec_create_t xvid_dec_create;
667    
668            /* Reset the structure with zeros */
669            memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t));
670            memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t));
671    
672          /*------------------------------------------------------------------------          /*------------------------------------------------------------------------
673           * XviD core initialization           * XviD core initialization
674           *----------------------------------------------------------------------*/           *----------------------------------------------------------------------*/
# Line 680  Line 723 
723    
724          xvid_dec_frame_t xvid_dec_frame;          xvid_dec_frame_t xvid_dec_frame;
725    
726            /* Reset all structures */
727            memset(&xvid_dec_frame, 0, sizeof(xvid_dec_frame_t));
728            memset(xvid_dec_stats, 0, sizeof(xvid_dec_stats_t));
729    
730          /* Set version */          /* Set version */
731          xvid_dec_frame.version = XVID_VERSION;          xvid_dec_frame.version = XVID_VERSION;
732          xvid_dec_stats->version = XVID_VERSION;          xvid_dec_stats->version = XVID_VERSION;

Legend:
Removed from v.1423  
changed lines
  Added in v.1547

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