|
Packit |
a38265 |
/*
|
|
Packit |
a38265 |
Copyright (C) 2003 Commonwealth Scientific and Industrial Research
|
|
Packit |
a38265 |
Organisation (CSIRO) Australia
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
Redistribution and use in source and binary forms, with or without
|
|
Packit |
a38265 |
modification, are permitted provided that the following conditions
|
|
Packit |
a38265 |
are met:
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
- Redistributions of source code must retain the above copyright
|
|
Packit |
a38265 |
notice, this list of conditions and the following disclaimer.
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
- Redistributions in binary form must reproduce the above copyright
|
|
Packit |
a38265 |
notice, this list of conditions and the following disclaimer in the
|
|
Packit |
a38265 |
documentation and/or other materials provided with the distribution.
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
- Neither the name of CSIRO Australia nor the names of its
|
|
Packit |
a38265 |
contributors may be used to endorse or promote products derived from
|
|
Packit |
a38265 |
this software without specific prior written permission.
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
a38265 |
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
a38265 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
Packit |
a38265 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
|
|
Packit |
a38265 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
Packit |
a38265 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
Packit |
a38265 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
a38265 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
a38265 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
Packit |
a38265 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
Packit |
a38265 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
a38265 |
*/
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#include "config.h"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#include <stdio.h>
|
|
Packit |
a38265 |
#include <stdlib.h>
|
|
Packit |
a38265 |
#include "oggz/oggz.h"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#ifdef HAVE_INTTYPES_H
|
|
Packit |
a38265 |
# include <inttypes.h>
|
|
Packit |
a38265 |
#else
|
|
Packit |
a38265 |
# define PRId64 "I64d"
|
|
Packit |
a38265 |
#endif
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
static int got_an_eos = 0;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
static int
|
|
Packit |
a38265 |
read_packet (OGGZ * oggz, oggz_packet * zp, long serialno, void * user_data)
|
|
Packit |
a38265 |
{
|
|
Packit |
a38265 |
ogg_packet * op = &zp->op;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#if 0
|
|
Packit |
a38265 |
if (got_an_eos) {
|
|
Packit |
a38265 |
printf ("[%010lu]\t%ld bytes\tgranulepos %ld\n", serialno, op->bytes,
|
|
Packit |
a38265 |
(long)op->granulepos);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
#endif
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (op->b_o_s) {
|
|
Packit |
a38265 |
printf ("%010lu: [%" PRId64 "] BOS %8s\n", serialno, op->granulepos, op->packet);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (op->e_o_s) {
|
|
Packit |
a38265 |
got_an_eos = 1;
|
|
Packit |
a38265 |
printf ("%010lu: [%" PRId64 "] EOS\n", serialno, op->granulepos);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
return 0;
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
static size_t
|
|
Packit |
a38265 |
my_io_read (void * user_handle, void * buf, size_t n)
|
|
Packit |
a38265 |
{
|
|
Packit |
a38265 |
FILE * f = (FILE *)user_handle;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
return fread (buf, 1, n, f);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
static int
|
|
Packit |
a38265 |
my_io_seek (void * user_handle, long offset, int whence)
|
|
Packit |
a38265 |
{
|
|
Packit |
a38265 |
FILE * f = (FILE *)user_handle;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
return (fseek (f, offset, whence));
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
static long
|
|
Packit |
a38265 |
my_io_tell (void * user_handle)
|
|
Packit |
a38265 |
{
|
|
Packit |
a38265 |
FILE * f = (FILE *)user_handle;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
return ftell (f);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
int
|
|
Packit |
a38265 |
main (int argc, char ** argv)
|
|
Packit |
a38265 |
{
|
|
Packit |
a38265 |
FILE * f;
|
|
Packit |
a38265 |
OGGZ * oggz;
|
|
Packit |
a38265 |
long n;
|
|
Packit |
a38265 |
ogg_int64_t units;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (argc < 2) {
|
|
Packit |
a38265 |
printf ("usage: %s filename\n", argv[0]);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if ((f = fopen ((char *)argv[1], "rb")) == NULL) {
|
|
Packit |
a38265 |
printf ("unable to open file %s\n", argv[1]);
|
|
Packit |
a38265 |
exit (1);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if ((oggz = oggz_new (OGGZ_READ | OGGZ_AUTO)) == NULL) {
|
|
Packit |
a38265 |
printf ("unable to create oggz\n");
|
|
Packit |
a38265 |
exit (1);
|
|
Packit |
a38265 |
}
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
oggz_io_set_read (oggz, my_io_read, f);
|
|
Packit |
a38265 |
oggz_io_set_seek (oggz, my_io_seek, f);
|
|
Packit |
a38265 |
oggz_io_set_tell (oggz, my_io_tell, f);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
oggz_set_read_callback (oggz, -1, read_packet, NULL);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
while ((n = oggz_read (oggz, 1024)) > 0);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
units = oggz_tell_units (oggz);
|
|
Packit |
a38265 |
printf ("Total length: %" PRId64 " ms\n", units);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
oggz_seek_units (oggz, units/2, SEEK_SET);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
printf ("seeked to byte offset %" PRId64 "\n", oggz_tell (oggz));
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
while ((n = oggz_read (oggz, 1024)) > 0);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
oggz_close (oggz);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
exit (0);
|
|
Packit |
a38265 |
}
|