Complete first-cut rearrangement of bisection and initialization code to reduce strea...
[platform/upstream/libvorbis.git] / include / vorbis / vorbisfile.h
1 /********************************************************************
2  *                                                                  *
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.       *
7  *                                                                  *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
9  * by the Xiph.Org Foundation http://www.xiph.org/                  *
10  *                                                                  *
11  ********************************************************************
12
13  function: stdio-based convenience library for opening/seeking/decoding
14  last mod: $Id$
15
16  ********************************************************************/
17
18 #ifndef _OV_FILE_H_
19 #define _OV_FILE_H_
20
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif /* __cplusplus */
25
26 #include <stdio.h>
27 #include "codec.h"
28
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 *
34  *
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
37  * unseekable
38  */
39 typedef struct {
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);
44 } ov_callbacks;
45
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
49  * issues. */
50
51 #include <stdio.h>
52 static int _ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){
53   if(f==NULL)return(-1);
54
55   fprintf(stderr,"seek: %s %ld\n",(whence==SEEK_END?"END":(whence==SEEK_SET?"SET":"CUR")), (long)off);
56
57 #ifdef __MINGW32__
58   return fseeko64(f,off,whence);
59 #elif defined (_WIN32)
60   return _fseeki64(f,off,whence);
61 #else
62   return fseek(f,off,whence);
63 #endif
64 }
65
66 /* These structs below (OV_CALLBACKS_DEFAULT etc) are defined here as
67  * static data. That means that every file which includes this header
68  * will get its own copy of these structs whether it uses them or
69  * not. This is essential on platforms such as Windows on which
70  * several different versions of stdio support may be linked to by
71  * different DLLs, and we need to be certain we know which one we're
72  * using (the same one as the main application).
73  */
74
75 static ov_callbacks OV_CALLBACKS_DEFAULT = {
76   (size_t (*)(void *, size_t, size_t, void *))  fread,
77   (int (*)(void *, ogg_int64_t, int))           _ov_header_fseek_wrap,
78   (int (*)(void *))                             fclose,
79   (long (*)(void *))                            ftell
80 };
81
82 static ov_callbacks OV_CALLBACKS_NOCLOSE = {
83   (size_t (*)(void *, size_t, size_t, void *))  fread,
84   (int (*)(void *, ogg_int64_t, int))           _ov_header_fseek_wrap,
85   (int (*)(void *))                             NULL,
86   (long (*)(void *))                            ftell
87 };
88
89 static ov_callbacks OV_CALLBACKS_STREAMONLY = {
90   (size_t (*)(void *, size_t, size_t, void *))  fread,
91   (int (*)(void *, ogg_int64_t, int))           NULL,
92   (int (*)(void *))                             fclose,
93   (long (*)(void *))                            NULL
94 };
95
96 static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = {
97   (size_t (*)(void *, size_t, size_t, void *))  fread,
98   (int (*)(void *, ogg_int64_t, int))           NULL,
99   (int (*)(void *))                             NULL,
100   (long (*)(void *))                            NULL
101 };
102
103 #define  NOTOPEN   0
104 #define  PARTOPEN  1
105 #define  OPENED    2
106 #define  STREAMSET 3
107 #define  INITSET   4
108
109 typedef struct OggVorbis_File {
110   void            *datasource; /* Pointer to a FILE *, etc. */
111   int              seekable;
112   ogg_int64_t      offset;
113   ogg_int64_t      end;
114   ogg_sync_state   oy;
115
116   /* If the FILE handle isn't seekable (eg, a pipe), only the current
117      stream appears */
118   int              links;
119   ogg_int64_t     *offsets;
120   ogg_int64_t     *dataoffsets;
121   long            *serialnos;
122   ogg_int64_t     *pcmlengths; /* overloaded to maintain binary
123                                   compatability; x2 size, stores both
124                                   beginning and end values */
125   vorbis_info     *vi;
126   vorbis_comment  *vc;
127
128   /* Decoding working state local storage */
129   ogg_int64_t      pcm_offset;
130   int              ready_state;
131   long             current_serialno;
132   int              current_link;
133
134   double           bittrack;
135   double           samptrack;
136
137   ogg_stream_state os; /* take physical pages, weld into a logical
138                           stream of packets */
139   vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
140   vorbis_block     vb; /* local working space for packet->PCM decode */
141
142   ov_callbacks callbacks;
143
144 } OggVorbis_File;
145
146
147 extern int ov_clear(OggVorbis_File *vf);
148 extern int ov_fopen(char *path,OggVorbis_File *vf);
149 extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
150 extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
151                 char *initial, long ibytes, ov_callbacks callbacks);
152
153 extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
154 extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
155                 char *initial, long ibytes, ov_callbacks callbacks);
156 extern int ov_test_open(OggVorbis_File *vf);
157
158 extern long ov_bitrate(OggVorbis_File *vf,int i);
159 extern long ov_bitrate_instant(OggVorbis_File *vf);
160 extern long ov_streams(OggVorbis_File *vf);
161 extern long ov_seekable(OggVorbis_File *vf);
162 extern long ov_serialnumber(OggVorbis_File *vf,int i);
163
164 extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
165 extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
166 extern double ov_time_total(OggVorbis_File *vf,int i);
167
168 extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
169 extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
170 extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
171 extern int ov_time_seek(OggVorbis_File *vf,double pos);
172 extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
173
174 extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
175 extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
176 extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
177 extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
178 extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
179
180 extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
181 extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
182 extern double ov_time_tell(OggVorbis_File *vf);
183
184 extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
185 extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
186
187 extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
188                           int *bitstream);
189 extern long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
190                           int bigendianp,int word,int sgned,int *bitstream,
191                           void (*filter)(float **pcm,long channels,long samples,void *filter_param),void *filter_param);
192 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
193                     int bigendianp,int word,int sgned,int *bitstream);
194 extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
195
196 extern int ov_halfrate(OggVorbis_File *vf,int flag);
197 extern int ov_halfrate_p(OggVorbis_File *vf);
198
199 #ifdef __cplusplus
200 }
201 #endif /* __cplusplus */
202
203 #endif
204