1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: stdio-based convenience library for opening/seeking/decoding
16 ********************************************************************/
24 #endif /* __cplusplus */
29 /* The function prototypes for the callbacks are basically the same as for
30 * the stdio functions fread, fseek, fclose, ftell.
31 * The one difference is that the FILE * arguments have been replaced with
32 * a void * - this is to be used as a pointer to whatever internal data these
33 * functions might need. In the stdio case, it's just a FILE * cast to a void *
35 * If you use other functions, check the docs for these functions and return
36 * the right values. For seek_func(), you *MUST* return -1 if the stream is
40 size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
41 int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
42 int (*close_func) (void *datasource);
43 long (*tell_func) (void *datasource);
46 /* a few sets of convenient callbacks, especially for use under
47 * Windows where ov_open_callbacks() should always be used instead of
48 * ov_open() to avoid problems with incompatable crt.o version linking
51 static int _ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){
52 if(f==NULL)return(-1);
53 return fseek(f,off,whence);
56 /* These structs below (OV_CALLBACKS_DEFAULT etc)are defined here as static
57 * data. That means that every file which includes this header will get its
58 * own copy of these structs whether it uses them or not.
60 * It would be *much* better to move these the vorbisfile.c, make them
61 * publicly available and then define them here as externs so that
62 * only one copy of them (the one in the library's vorbisfile.c) is ever
65 * Unfortunately this cannot be done at the moment because doing so would
66 * break the libvorbisfile ABI. A good time to do that would be at some
67 * other time when the ABI is being broken for some other reason. */
69 static ov_callbacks OV_CALLBACKS_DEFAULT = {
70 (size_t (*)(void *, size_t, size_t, void *)) fread,
71 (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
72 (int (*)(void *)) fclose,
73 (long (*)(void *)) ftell
76 static ov_callbacks OV_CALLBACKS_NOCLOSE = {
77 (size_t (*)(void *, size_t, size_t, void *)) fread,
78 (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
79 (int (*)(void *)) NULL,
80 (long (*)(void *)) ftell
83 static ov_callbacks OV_CALLBACKS_STREAMONLY = {
84 (size_t (*)(void *, size_t, size_t, void *)) fread,
85 (int (*)(void *, ogg_int64_t, int)) NULL,
86 (int (*)(void *)) fclose,
87 (long (*)(void *)) NULL
90 static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = {
91 (size_t (*)(void *, size_t, size_t, void *)) fread,
92 (int (*)(void *, ogg_int64_t, int)) NULL,
93 (int (*)(void *)) NULL,
94 (long (*)(void *)) NULL
103 typedef struct OggVorbis_File {
104 void *datasource; /* Pointer to a FILE *, etc. */
110 /* If the FILE handle isn't seekable (eg, a pipe), only the current
113 ogg_int64_t *offsets;
114 ogg_int64_t *dataoffsets;
116 ogg_int64_t *pcmlengths; /* overloaded to maintain binary
117 compatability; x2 size, stores both
118 beginning and end values */
122 /* Decoding working state local storage */
123 ogg_int64_t pcm_offset;
125 long current_serialno;
131 ogg_stream_state os; /* take physical pages, weld into a logical
133 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
134 vorbis_block vb; /* local working space for packet->PCM decode */
136 ov_callbacks callbacks;
141 extern int ov_clear(OggVorbis_File *vf);
142 extern int ov_fopen(char *path,OggVorbis_File *vf);
143 extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
144 extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
145 char *initial, long ibytes, ov_callbacks callbacks);
147 extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
148 extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
149 char *initial, long ibytes, ov_callbacks callbacks);
150 extern int ov_test_open(OggVorbis_File *vf);
152 extern long ov_bitrate(OggVorbis_File *vf,int i);
153 extern long ov_bitrate_instant(OggVorbis_File *vf);
154 extern long ov_streams(OggVorbis_File *vf);
155 extern long ov_seekable(OggVorbis_File *vf);
156 extern long ov_serialnumber(OggVorbis_File *vf,int i);
158 extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
159 extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
160 extern double ov_time_total(OggVorbis_File *vf,int i);
162 extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
163 extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
164 extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
165 extern int ov_time_seek(OggVorbis_File *vf,double pos);
166 extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
168 extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
169 extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
170 extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
171 extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
172 extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
174 extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
175 extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
176 extern double ov_time_tell(OggVorbis_File *vf);
178 extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
179 extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
181 extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
183 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
184 int bigendianp,int word,int sgned,int *bitstream);
185 extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
187 extern int ov_halfrate(OggVorbis_File *vf,int flag);
188 extern int ov_halfrate_p(OggVorbis_File *vf);
192 #endif /* __cplusplus */