Changeset 2571

Show
Ignore:
Timestamp:
2006-12-10 02:56:22 (2 years ago)
Author:
conrad
Message:

modify read-file example to print out stored and calculated granulepos,
and use oggz_run()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • liboggz/trunk/src/examples/read-file.c

    r1347 r2571  
    3131*/ 
    3232 
     33#include "config.h" 
     34 
    3335#include <stdio.h> 
    3436#include <stdlib.h> 
     37#ifdef HAVE_INTTYPES_H 
     38#  include <inttypes.h> 
     39#else 
     40#  define PRId64 "I64d" 
     41#endif 
     42  
    3543#include <oggz/oggz.h> 
    3644 
    3745static int got_an_eos = 0; 
    3846 
     47static void 
     48print_granulepos (ogg_int64_t granulepos, int granuleshift) 
     49{ 
     50  if (granuleshift < 1) { 
     51    printf ("%" PRId64, granulepos); 
     52  } else { 
     53    ogg_int64_t iframe, pframe; 
     54    iframe = granulepos >> granuleshift; 
     55    pframe = granulepos - (iframe << granuleshift); 
     56 
     57    printf ("%" PRId64 "|%" PRId64, iframe, pframe); 
     58  } 
     59} 
     60 
     61 
    3962static int 
    4063read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) 
    4164{ 
    42 #if 0 
    43   if (got_an_eos) { 
    44     printf ("[%010ld]\t%ld bytes\tgranulepos %ld\n", serialno, op->bytes, 
    45             (long)op->granulepos); 
    46   } 
    47 #endif 
     65  int granuleshift; 
     66 
     67  granuleshift = oggz_get_granuleshift (oggz, serialno); 
     68 
     69  printf ("%010ld: op->granulepos: ", serialno); 
     70  print_granulepos (op->granulepos, granuleshift); 
     71  printf ("  oggz_tell_granulepos(): "); 
     72  print_granulepos (oggz_tell_granulepos (oggz), granuleshift); 
    4873 
    4974  if (op->b_o_s) { 
    50     printf ("%010ld: [%lld] BOS %8s\n", serialno, op->granulepos, op->packet); 
     75    printf (" *** bos"); 
    5176  } 
    5277 
    5378  if (op->e_o_s) { 
    5479    got_an_eos = 1; 
    55     printf ("%010ld: [%lld] EOS\n", serialno, op->granulepos); 
     80    printf (" *** eos"); 
    5681  } 
     82 
     83  printf ("\n"); 
    5784 
    5885  return 0; 
     
    6390{ 
    6491  OGGZ * oggz; 
    65   long n; 
    6692 
    6793  if (argc < 2) { 
     
    76102  oggz_set_read_callback (oggz, -1, read_packet, NULL); 
    77103 
    78   while ((n = oggz_read (oggz, 1024)) > 0); 
     104  oggz_run (oggz); 
    79105 
    80106  oggz_close (oggz);