[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 1678, Wed Feb 15 19:16:39 2006 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.24 2006-02-15 19:16:39 Isibaar 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    #define MIN_USEFUL_BYTES 1
77    
78  /*****************************************************************************  /*****************************************************************************
79   *               Local prototypes   *               Local prototypes
80   ****************************************************************************/   ****************************************************************************/
81    
82  static double msecond();  static double msecond();
 static int write_pgm(char *filename,  
                                          unsigned char *image);  
83  static int dec_init(int use_assembler, int debug_level);  static int dec_init(int use_assembler, int debug_level);
84  static int dec_main(unsigned char *istream,  static int dec_main(unsigned char *istream,
85                                          unsigned char *ostream,                                          unsigned char *ostream,
# Line 88  Line 87 
87                                          xvid_dec_stats_t *xvid_dec_stats);                                          xvid_dec_stats_t *xvid_dec_stats);
88  static int dec_stop();  static int dec_stop();
89  static void usage();  static void usage();
90    static int write_image(char *prefix, unsigned char *image);
91    static int write_pnm(char *filename, unsigned char *image);
92    static int write_tga(char *filename, unsigned char *image);
93    
94  const char * type2str(int type)  const char * type2str(int type)
95  {  {
# Line 111  Line 112 
112          unsigned char *mp4_ptr    = NULL;          unsigned char *mp4_ptr    = NULL;
113          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
114          int useful_bytes;          int useful_bytes;
115            int chunk;
116          xvid_dec_stats_t xvid_dec_stats;          xvid_dec_stats_t xvid_dec_stats;
117    
118          double totaldectime;          double totaldectime;
# Line 184  Line 186 
186                  }                  }
187          }          }
188    
189    #if defined(_MSC_VER)
190            if (ARG_INPUTFILE==NULL) {
191                    fprintf(stderr, "Warning: MSVC build does not read EOF correctly from stdin. Use the -i switch.\n\n");
192            }
193    #endif
194    
195  /*****************************************************************************  /*****************************************************************************
196   * Values checking   * Values checking
197   ****************************************************************************/   ****************************************************************************/
# Line 238  Line 246 
246          totalsize = 0;          totalsize = 0;
247          filenr = 0;          filenr = 0;
248          mp4_ptr = mp4_buffer;          mp4_ptr = mp4_buffer;
249            chunk = 0;
250    
251          do {          do {
252                  int used_bytes = 0;                  int used_bytes = 0;
# Line 258  Line 267 
267                          mp4_ptr = mp4_buffer;                          mp4_ptr = mp4_buffer;
268    
269                          /* read new data */                          /* read new data */
270              if(feof(in_file))              if(!feof(in_file)) {
                                 break;  
   
271                          useful_bytes += fread(mp4_buffer + already_in_buffer,                          useful_bytes += fread(mp4_buffer + already_in_buffer,
272                                                                    1, BUFFER_SIZE - already_in_buffer,                                                                    1, BUFFER_SIZE - already_in_buffer,
273                                                                    in_file);                                                                    in_file);
274                            }
275                  }                  }
276    
277    
# 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                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);                          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 > MIN_USEFUL_BYTES);
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
339                   * This means we went too far */                   * This means we went too far */
# 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>MIN_USEFUL_BYTES || !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 457  Line 495 
495  #else  #else
496          clock_t clk;          clock_t clk;
497          clk = clock();          clk = clock();
498          return(clk * 1000 / CLOCKS_PER_SEC);          return(clk * 1000.0 / CLOCKS_PER_SEC);
499  #endif  #endif
500  }  }
501    
# 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 536  Line 574 
574  #else  #else
575          {          {
576                  int i;                  int i;
577                  for (i=0; i<width*height*BPP;i+=BPP) {                  for (i=0; i<XDIM*YDIM*BPP;i+=BPP) {
578                          if (BPP == 1) {                          if (BPP == 1) {
579                                  fputc(image+i, f);                                  fputc(*(image+i), f);
580                          } else if (BPP == 2) {                          } else if (BPP == 2) {
581                                  fputc(image+i+1, f);                                  fputc(*(image+i+1), f);
582                                  fputc(image+i+0, f);                                  fputc(*(image+i+0), f);
583                          } else if (BPP == 3) {                          } else if (BPP == 3) {
584                                  fputc(image+i+2, f);                                  fputc(*(image+i+2), f);
585                                  fputc(image+i+1, f);                                  fputc(*(image+i+1), f);
586                                  fputc(image+i+0, f);                                  fputc(*(image+i+0), f);
587                          } else if (BPP == 4) {                          } else if (BPP == 4) {
588                                  fputc(image+i+3, f);                                  fputc(*(image+i+3), f);
589                                  fputc(image+i+2, f);                                  fputc(*(image+i+2), f);
590                                  fputc(image+i+1, f);                                  fputc(*(image+i+1), f);
591                                  fputc(image+i+0, f);                                  fputc(*(image+i+0), f);
592                          }                          }
593                  }                  }
594          }          }
# 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 585  Line 623 
623    
624          if (BPP == 1) {          if (BPP == 1) {
625                  int i;                  int i;
626                  fprintf(f, "P5\n#xvid\n%i %i\n255\n", XDIM, YDIM*3/2);                  fprintf(f, "P5\n%i %i\n255\n", XDIM, YDIM*3/2);
627    
628                  fwrite(image, 1, XDIM*YDIM, f);                  fwrite(image, 1, XDIM*YDIM, f);
629    
# 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.1678

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