Chris@2: /********************************************************************
Chris@2:  *                                                                  *
Chris@2:  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
Chris@2:  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
Chris@2:  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
Chris@2:  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
Chris@2:  *                                                                  *
Chris@2:  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
Chris@2:  * by the Xiph.Org Foundation http://www.xiph.org/                  *
Chris@2:  *                                                                  *
Chris@2:  ********************************************************************
Chris@2: 
Chris@2:  function: stdio-based convenience library for opening/seeking/decoding
Chris@2:  last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $
Chris@2: 
Chris@2:  ********************************************************************/
Chris@2: 
Chris@2: #ifndef _OV_FILE_H_
Chris@2: #define _OV_FILE_H_
Chris@2: 
Chris@2: #ifdef __cplusplus
Chris@2: extern "C"
Chris@2: {
Chris@2: #endif /* __cplusplus */
Chris@2: 
Chris@2: #include <stdio.h>
Chris@2: #include "codec.h"
Chris@2: 
Chris@2: /* The function prototypes for the callbacks are basically the same as for
Chris@2:  * the stdio functions fread, fseek, fclose, ftell.
Chris@2:  * The one difference is that the FILE * arguments have been replaced with
Chris@2:  * a void * - this is to be used as a pointer to whatever internal data these
Chris@2:  * functions might need. In the stdio case, it's just a FILE * cast to a void *
Chris@2:  *
Chris@2:  * If you use other functions, check the docs for these functions and return
Chris@2:  * the right values. For seek_func(), you *MUST* return -1 if the stream is
Chris@2:  * unseekable
Chris@2:  */
Chris@2: typedef struct {
Chris@2:   size_t (*read_func)  (void *ptr, size_t size, size_t nmemb, void *datasource);
Chris@2:   int    (*seek_func)  (void *datasource, ogg_int64_t offset, int whence);
Chris@2:   int    (*close_func) (void *datasource);
Chris@2:   long   (*tell_func)  (void *datasource);
Chris@2: } ov_callbacks;
Chris@2: 
Chris@2: #ifndef OV_EXCLUDE_STATIC_CALLBACKS
Chris@2: 
Chris@2: /* a few sets of convenient callbacks, especially for use under
Chris@2:  * Windows where ov_open_callbacks() should always be used instead of
Chris@2:  * ov_open() to avoid problems with incompatible crt.o version linking
Chris@2:  * issues. */
Chris@2: 
Chris@2: static int _ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){
Chris@2:   if(f==NULL)return(-1);
Chris@2: 
Chris@2: #ifdef __MINGW32__
Chris@2:   return fseeko64(f,off,whence);
Chris@2: #elif defined (_WIN32)
Chris@2:   return _fseeki64(f,off,whence);
Chris@2: #else
Chris@2:   return fseek(f,off,whence);
Chris@2: #endif
Chris@2: }
Chris@2: 
Chris@2: /* These structs below (OV_CALLBACKS_DEFAULT etc) are defined here as
Chris@2:  * static data. That means that every file which includes this header
Chris@2:  * will get its own copy of these structs whether it uses them or
Chris@2:  * not unless it #defines OV_EXCLUDE_STATIC_CALLBACKS.
Chris@2:  * These static symbols are essential on platforms such as Windows on
Chris@2:  * which several different versions of stdio support may be linked to
Chris@2:  * by different DLLs, and we need to be certain we know which one
Chris@2:  * we're using (the same one as the main application).
Chris@2:  */
Chris@2: 
Chris@2: static ov_callbacks OV_CALLBACKS_DEFAULT = {
Chris@2:   (size_t (*)(void *, size_t, size_t, void *))  fread,
Chris@2:   (int (*)(void *, ogg_int64_t, int))           _ov_header_fseek_wrap,
Chris@2:   (int (*)(void *))                             fclose,
Chris@2:   (long (*)(void *))                            ftell
Chris@2: };
Chris@2: 
Chris@2: static ov_callbacks OV_CALLBACKS_NOCLOSE = {
Chris@2:   (size_t (*)(void *, size_t, size_t, void *))  fread,
Chris@2:   (int (*)(void *, ogg_int64_t, int))           _ov_header_fseek_wrap,
Chris@2:   (int (*)(void *))                             NULL,
Chris@2:   (long (*)(void *))                            ftell
Chris@2: };
Chris@2: 
Chris@2: static ov_callbacks OV_CALLBACKS_STREAMONLY = {
Chris@2:   (size_t (*)(void *, size_t, size_t, void *))  fread,
Chris@2:   (int (*)(void *, ogg_int64_t, int))           NULL,
Chris@2:   (int (*)(void *))                             fclose,
Chris@2:   (long (*)(void *))                            NULL
Chris@2: };
Chris@2: 
Chris@2: static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = {
Chris@2:   (size_t (*)(void *, size_t, size_t, void *))  fread,
Chris@2:   (int (*)(void *, ogg_int64_t, int))           NULL,
Chris@2:   (int (*)(void *))                             NULL,
Chris@2:   (long (*)(void *))                            NULL
Chris@2: };
Chris@2: 
Chris@2: #endif
Chris@2: 
Chris@2: #define  NOTOPEN   0
Chris@2: #define  PARTOPEN  1
Chris@2: #define  OPENED    2
Chris@2: #define  STREAMSET 3
Chris@2: #define  INITSET   4
Chris@2: 
Chris@2: typedef struct OggVorbis_File {
Chris@2:   void            *datasource; /* Pointer to a FILE *, etc. */
Chris@2:   int              seekable;
Chris@2:   ogg_int64_t      offset;
Chris@2:   ogg_int64_t      end;
Chris@2:   ogg_sync_state   oy;
Chris@2: 
Chris@2:   /* If the FILE handle isn't seekable (eg, a pipe), only the current
Chris@2:      stream appears */
Chris@2:   int              links;
Chris@2:   ogg_int64_t     *offsets;
Chris@2:   ogg_int64_t     *dataoffsets;
Chris@2:   long            *serialnos;
Chris@2:   ogg_int64_t     *pcmlengths; /* overloaded to maintain binary
Chris@2:                                   compatibility; x2 size, stores both
Chris@2:                                   beginning and end values */
Chris@2:   vorbis_info     *vi;
Chris@2:   vorbis_comment  *vc;
Chris@2: 
Chris@2:   /* Decoding working state local storage */
Chris@2:   ogg_int64_t      pcm_offset;
Chris@2:   int              ready_state;
Chris@2:   long             current_serialno;
Chris@2:   int              current_link;
Chris@2: 
Chris@2:   double           bittrack;
Chris@2:   double           samptrack;
Chris@2: 
Chris@2:   ogg_stream_state os; /* take physical pages, weld into a logical
Chris@2:                           stream of packets */
Chris@2:   vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
Chris@2:   vorbis_block     vb; /* local working space for packet->PCM decode */
Chris@2: 
Chris@2:   ov_callbacks callbacks;
Chris@2: 
Chris@2: } OggVorbis_File;
Chris@2: 
Chris@2: 
Chris@2: extern int ov_clear(OggVorbis_File *vf);
Chris@2: extern int ov_fopen(const char *path,OggVorbis_File *vf);
Chris@2: extern int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
Chris@2: extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
Chris@2:                 const char *initial, long ibytes, ov_callbacks callbacks);
Chris@2: 
Chris@2: extern int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
Chris@2: extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
Chris@2:                 const char *initial, long ibytes, ov_callbacks callbacks);
Chris@2: extern int ov_test_open(OggVorbis_File *vf);
Chris@2: 
Chris@2: extern long ov_bitrate(OggVorbis_File *vf,int i);
Chris@2: extern long ov_bitrate_instant(OggVorbis_File *vf);
Chris@2: extern long ov_streams(OggVorbis_File *vf);
Chris@2: extern long ov_seekable(OggVorbis_File *vf);
Chris@2: extern long ov_serialnumber(OggVorbis_File *vf,int i);
Chris@2: 
Chris@2: extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
Chris@2: extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
Chris@2: extern double ov_time_total(OggVorbis_File *vf,int i);
Chris@2: 
Chris@2: extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
Chris@2: extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
Chris@2: extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
Chris@2: extern int ov_time_seek(OggVorbis_File *vf,double pos);
Chris@2: extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
Chris@2: 
Chris@2: extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
Chris@2: extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
Chris@2: extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
Chris@2: extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
Chris@2: extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
Chris@2: 
Chris@2: extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
Chris@2: extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
Chris@2: extern double ov_time_tell(OggVorbis_File *vf);
Chris@2: 
Chris@2: extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
Chris@2: extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
Chris@2: 
Chris@2: extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
Chris@2:                           int *bitstream);
Chris@2: extern long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
Chris@2:                           int bigendianp,int word,int sgned,int *bitstream,
Chris@2:                           void (*filter)(float **pcm,long channels,long samples,void *filter_param),void *filter_param);
Chris@2: extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
Chris@2:                     int bigendianp,int word,int sgned,int *bitstream);
Chris@2: extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
Chris@2: 
Chris@2: extern int ov_halfrate(OggVorbis_File *vf,int flag);
Chris@2: extern int ov_halfrate_p(OggVorbis_File *vf);
Chris@2: 
Chris@2: #ifdef __cplusplus
Chris@2: }
Chris@2: #endif /* __cplusplus */
Chris@2: 
Chris@2: #endif
Chris@2: