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 https://xiph.org/ *
|
---|
10 | * *
|
---|
11 | ********************************************************************
|
---|
12 |
|
---|
13 | function: stdio-based convenience library for opening/seeking/decoding
|
---|
14 |
|
---|
15 | ********************************************************************/
|
---|
16 |
|
---|
17 | #ifndef _OV_FILE_H_
|
---|
18 | #define _OV_FILE_H_
|
---|
19 |
|
---|
20 | #ifdef __cplusplus
|
---|
21 | extern "C"
|
---|
22 | {
|
---|
23 | #endif /* __cplusplus */
|
---|
24 |
|
---|
25 | #include <stdio.h>
|
---|
26 | #include "codec.h"
|
---|
27 |
|
---|
28 | /* The function prototypes for the callbacks are basically the same as for
|
---|
29 | * the stdio functions fread, fseek, fclose, ftell.
|
---|
30 | * The one difference is that the FILE * arguments have been replaced with
|
---|
31 | * a void * - this is to be used as a pointer to whatever internal data these
|
---|
32 | * functions might need. In the stdio case, it's just a FILE * cast to a void *
|
---|
33 | *
|
---|
34 | * If you use other functions, check the docs for these functions and return
|
---|
35 | * the right values. For seek_func(), you *MUST* return -1 if the stream is
|
---|
36 | * unseekable
|
---|
37 | */
|
---|
38 | typedef struct {
|
---|
39 | size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
|
---|
40 | int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
|
---|
41 | int (*close_func) (void *datasource);
|
---|
42 | long (*tell_func) (void *datasource);
|
---|
43 | } ov_callbacks;
|
---|
44 |
|
---|
45 | #ifndef OV_EXCLUDE_STATIC_CALLBACKS
|
---|
46 |
|
---|
47 | /* a few sets of convenient callbacks, especially for use under
|
---|
48 | * Windows where ov_open_callbacks() should always be used instead of
|
---|
49 | * ov_open() to avoid problems with incompatible crt.o version linking
|
---|
50 | * issues. */
|
---|
51 |
|
---|
52 | static int _ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){
|
---|
53 | if(f==NULL)return(-1);
|
---|
54 |
|
---|
55 | #ifdef __MINGW32__
|
---|
56 | return fseeko64(f,off,whence);
|
---|
57 | #elif defined (_WIN32)
|
---|
58 | return _fseeki64(f,off,whence);
|
---|
59 | #else
|
---|
60 | return fseek(f,off,whence);
|
---|
61 | #endif
|
---|
62 | }
|
---|
63 |
|
---|
64 | /* These structs below (OV_CALLBACKS_DEFAULT etc) are defined here as
|
---|
65 | * static data. That means that every file which includes this header
|
---|
66 | * will get its own copy of these structs whether it uses them or
|
---|
67 | * not unless it #defines OV_EXCLUDE_STATIC_CALLBACKS.
|
---|
68 | * These static symbols are essential on platforms such as Windows on
|
---|
69 | * which several different versions of stdio support may be linked to
|
---|
70 | * by different DLLs, and we need to be certain we know which one
|
---|
71 | * we're using (the same one as the main application).
|
---|
72 | */
|
---|
73 |
|
---|
74 | static ov_callbacks OV_CALLBACKS_DEFAULT = {
|
---|
75 | (size_t (*)(void *, size_t, size_t, void *)) fread,
|
---|
76 | (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
|
---|
77 | (int (*)(void *)) fclose,
|
---|
78 | (long (*)(void *)) ftell
|
---|
79 | };
|
---|
80 |
|
---|
81 | static ov_callbacks OV_CALLBACKS_NOCLOSE = {
|
---|
82 | (size_t (*)(void *, size_t, size_t, void *)) fread,
|
---|
83 | (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
|
---|
84 | (int (*)(void *)) NULL,
|
---|
85 | (long (*)(void *)) ftell
|
---|
86 | };
|
---|
87 |
|
---|
88 | static ov_callbacks OV_CALLBACKS_STREAMONLY = {
|
---|
89 | (size_t (*)(void *, size_t, size_t, void *)) fread,
|
---|
90 | (int (*)(void *, ogg_int64_t, int)) NULL,
|
---|
91 | (int (*)(void *)) fclose,
|
---|
92 | (long (*)(void *)) NULL
|
---|
93 | };
|
---|
94 |
|
---|
95 | static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = {
|
---|
96 | (size_t (*)(void *, size_t, size_t, void *)) fread,
|
---|
97 | (int (*)(void *, ogg_int64_t, int)) NULL,
|
---|
98 | (int (*)(void *)) NULL,
|
---|
99 | (long (*)(void *)) NULL
|
---|
100 | };
|
---|
101 |
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | #define NOTOPEN 0
|
---|
105 | #define PARTOPEN 1
|
---|
106 | #define OPENED 2
|
---|
107 | #define STREAMSET 3
|
---|
108 | #define INITSET 4
|
---|
109 |
|
---|
110 | typedef struct OggVorbis_File {
|
---|
111 | void *datasource; /* Pointer to a FILE *, etc. */
|
---|
112 | int seekable;
|
---|
113 | ogg_int64_t offset;
|
---|
114 | ogg_int64_t end;
|
---|
115 | ogg_sync_state oy;
|
---|
116 |
|
---|
117 | /* If the FILE handle isn't seekable (eg, a pipe), only the current
|
---|
118 | stream appears */
|
---|
119 | int links;
|
---|
120 | ogg_int64_t *offsets;
|
---|
121 | ogg_int64_t *dataoffsets;
|
---|
122 | long *serialnos;
|
---|
123 | ogg_int64_t *pcmlengths; /* overloaded to maintain binary
|
---|
124 | compatibility; x2 size, stores both
|
---|
125 | beginning and end values */
|
---|
126 | vorbis_info *vi;
|
---|
127 | vorbis_comment *vc;
|
---|
128 |
|
---|
129 | /* Decoding working state local storage */
|
---|
130 | ogg_int64_t pcm_offset;
|
---|
131 | int ready_state;
|
---|
132 | long current_serialno;
|
---|
133 | int current_link;
|
---|
134 |
|
---|
135 | double bittrack;
|
---|
136 | double samptrack;
|
---|
137 |
|
---|
138 | ogg_stream_state os; /* take physical pages, weld into a logical
|
---|
139 | stream of packets */
|
---|
140 | vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
|
---|
141 | vorbis_block vb; /* local working space for packet->PCM decode */
|
---|
142 |
|
---|
143 | ov_callbacks callbacks;
|
---|
144 |
|
---|
145 | } OggVorbis_File;
|
---|
146 |
|
---|
147 |
|
---|
148 | extern int ov_clear(OggVorbis_File *vf);
|
---|
149 | extern int ov_fopen(const char *path,OggVorbis_File *vf);
|
---|
150 | extern int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
|
---|
151 | extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
|
---|
152 | const char *initial, long ibytes, ov_callbacks callbacks);
|
---|
153 |
|
---|
154 | extern int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
|
---|
155 | extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
|
---|
156 | const char *initial, long ibytes, ov_callbacks callbacks);
|
---|
157 | extern int ov_test_open(OggVorbis_File *vf);
|
---|
158 |
|
---|
159 | extern long ov_bitrate(OggVorbis_File *vf,int i);
|
---|
160 | extern long ov_bitrate_instant(OggVorbis_File *vf);
|
---|
161 | extern long ov_streams(OggVorbis_File *vf);
|
---|
162 | extern long ov_seekable(OggVorbis_File *vf);
|
---|
163 | extern long ov_serialnumber(OggVorbis_File *vf,int i);
|
---|
164 |
|
---|
165 | extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
|
---|
166 | extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
|
---|
167 | extern double ov_time_total(OggVorbis_File *vf,int i);
|
---|
168 |
|
---|
169 | extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
|
---|
170 | extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
|
---|
171 | extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
|
---|
172 | extern int ov_time_seek(OggVorbis_File *vf,double pos);
|
---|
173 | extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
|
---|
174 |
|
---|
175 | extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
|
---|
176 | extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
|
---|
177 | extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
|
---|
178 | extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
|
---|
179 | extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
|
---|
180 |
|
---|
181 | extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
|
---|
182 | extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
|
---|
183 | extern double ov_time_tell(OggVorbis_File *vf);
|
---|
184 |
|
---|
185 | extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
|
---|
186 | extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
|
---|
187 |
|
---|
188 | extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
|
---|
189 | int *bitstream);
|
---|
190 | extern long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
|
---|
191 | int bigendianp,int word,int sgned,int *bitstream,
|
---|
192 | void (*filter)(float **pcm,long channels,long samples,void *filter_param),void *filter_param);
|
---|
193 | extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
|
---|
194 | int bigendianp,int word,int sgned,int *bitstream);
|
---|
195 | extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
|
---|
196 |
|
---|
197 | extern int ov_halfrate(OggVorbis_File *vf,int flag);
|
---|
198 | extern int ov_halfrate_p(OggVorbis_File *vf);
|
---|
199 |
|
---|
200 | #ifdef __cplusplus
|
---|
201 | }
|
---|
202 | #endif /* __cplusplus */
|
---|
203 |
|
---|
204 | #endif
|
---|
205 |
|
---|