1 #ifndef LIBRARIES_VORBISFILE_H 2 #define LIBRARIES_VORBISFILE_H 3 4 #include <sys/types.h> 5 #include <stdio.h> 6 7 8 /******************************/ 9 /******************************/ 10 /******************************/ 11 /* From <ogg/config_types.h> */ 12 /******************************/ 13 /******************************/ 14 /******************************/ 15 16 typedef int16_t ogg_int16_t; 17 typedef int32_t ogg_int32_t; 18 #ifdef __GNUC__ 19 typedef u_int32_t ogg_uint32_t; 20 #else 21 typedef uint32_t ogg_uint32_t; 22 #endif 23 typedef int64_t ogg_int64_t; 24 25 26 /******************************/ 27 /******************************/ 28 /******************************/ 29 /* From <ogg/ogg.h> */ 30 /******************************/ 31 /******************************/ 32 /******************************/ 33 34 typedef struct { 35 void *iov_base; 36 size_t iov_len; 37 } ogg_iovec_t; 38 39 typedef struct { 40 unsigned char *data; 41 int storage; 42 int fill; 43 int returned; 44 45 int unsynced; 46 int headerbytes; 47 int bodybytes; 48 } ogg_sync_state; 49 50 typedef struct { 51 long endbyte; 52 int endbit; 53 54 unsigned char *buffer; 55 unsigned char *ptr; 56 long storage; 57 } oggpack_buffer; 58 59 60 typedef struct { 61 unsigned char *body_data; /* bytes from packet bodies */ 62 long body_storage; /* storage elements allocated */ 63 long body_fill; /* elements stored; fill mark */ 64 long body_returned; /* elements of fill returned */ 65 66 67 int *lacing_vals; /* The values that will go to the segment table */ 68 ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact 69 this way, but it is simple coupled to the 70 lacing fifo */ 71 long lacing_storage; 72 long lacing_fill; 73 long lacing_packet; 74 long lacing_returned; 75 76 unsigned char header[282]; /* working space for header encode */ 77 int header_fill; 78 79 int e_o_s; /* set when we have buffered the last packet in the 80 logical bitstream */ 81 int b_o_s; /* set after we've written the initial page 82 of a logical bitstream */ 83 long serialno; 84 long pageno; 85 ogg_int64_t packetno; /* sequence number for decode; the framing 86 knows where there's a hole in the data, 87 but we need coupling so that the codec 88 (which is in a seperate abstraction 89 layer) also knows about the gap */ 90 ogg_int64_t granulepos; 91 92 } ogg_stream_state; 93 94 /* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/ 95 typedef struct { 96 unsigned char *header; 97 long header_len; 98 unsigned char *body; 99 long body_len; 100 } ogg_page; 101 102 /* ogg_packet is used to encapsulate the data and metadata belonging 103 to a single raw Ogg/Vorbis packet *************************************/ 104 typedef struct { 105 unsigned char *packet; 106 long bytes; 107 long b_o_s; 108 long e_o_s; 109 110 ogg_int64_t granulepos; 111 112 ogg_int64_t packetno; /* sequence number for decode; the framing 113 knows where there's a hole in the data, 114 but we need coupling so that the codec 115 (which is in a seperate abstraction 116 layer) also knows about the gap */ 117 } ogg_packet; 118 119 /******************************/ 120 /******************************/ 121 /******************************/ 122 /* From <vorbis/codec.h> */ 123 /******************************/ 124 /******************************/ 125 /******************************/ 126 127 typedef struct vorbis_info{ 128 int version; 129 int channels; 130 long rate; 131 132 /* The below bitrate declarations are *hints*. 133 Combinations of the three values carry the following implications: 134 135 all three set to the same value: 136 implies a fixed rate bitstream 137 only nominal set: 138 implies a VBR stream that averages the nominal bitrate. No hard 139 upper/lower limit 140 upper and or lower set: 141 implies a VBR bitstream that obeys the bitrate limits. nominal 142 may also be set to give a nominal rate. 143 none set: 144 the coder does not care to speculate. 145 */ 146 147 long bitrate_upper; 148 long bitrate_nominal; 149 long bitrate_lower; 150 long bitrate_window; 151 152 void *codec_setup; 153 } vorbis_info; 154 155 /* vorbis_dsp_state buffers the current vorbis audio 156 analysis/synthesis state. The DSP state belongs to a specific 157 logical bitstream ****************************************************/ 158 typedef struct vorbis_dsp_state{ 159 int analysisp; 160 vorbis_info *vi; 161 162 float **pcm; 163 float **pcmret; 164 int pcm_storage; 165 int pcm_current; 166 int pcm_returned; 167 168 int preextrapolate; 169 int eofflag; 170 171 long lW; 172 long W; 173 long nW; 174 long centerW; 175 176 ogg_int64_t granulepos; 177 ogg_int64_t sequence; 178 179 ogg_int64_t glue_bits; 180 ogg_int64_t time_bits; 181 ogg_int64_t floor_bits; 182 ogg_int64_t res_bits; 183 184 void *backend_state; 185 } vorbis_dsp_state; 186 187 typedef struct vorbis_block{ 188 /* necessary stream state for linking to the framing abstraction */ 189 float **pcm; /* this is a pointer into local storage */ 190 oggpack_buffer opb; 191 192 long lW; 193 long W; 194 long nW; 195 int pcmend; 196 int mode; 197 198 int eofflag; 199 ogg_int64_t granulepos; 200 ogg_int64_t sequence; 201 vorbis_dsp_state *vd; /* For read-only access of configuration */ 202 203 /* local storage to avoid remallocing; it's up to the mapping to 204 structure it */ 205 void *localstore; 206 long localtop; 207 long localalloc; 208 long totaluse; 209 struct alloc_chain *reap; 210 211 /* bitmetrics for the frame */ 212 long glue_bits; 213 long time_bits; 214 long floor_bits; 215 long res_bits; 216 217 void *internal; 218 219 } vorbis_block; 220 221 /* vorbis_block is a single block of data to be processed as part of 222 the analysis/synthesis stream; it belongs to a specific logical 223 bitstream, but is independant from other vorbis_blocks belonging to 224 that logical bitstream. *************************************************/ 225 226 struct alloc_chain{ 227 void *ptr; 228 struct alloc_chain *next; 229 }; 230 231 /* vorbis_info contains all the setup information specific to the 232 specific compression/decompression mode in progress (eg, 233 psychoacoustic settings, channel setup, options, codebook 234 etc). vorbis_info and substructures are in backends.h. 235 *********************************************************************/ 236 237 /* the comments are not part of vorbis_info so that vorbis_info can be 238 static storage */ 239 typedef struct vorbis_comment{ 240 /* unlimited user comment fields. libvorbis writes 'libvorbis' 241 whatever vendor is set to in encode */ 242 char **user_comments; 243 int *comment_lengths; 244 int comments; 245 char *vendor; 246 247 } vorbis_comment; 248 249 /* Vorbis ERRORS and return codes ***********************************/ 250 251 #define OV_FALSE -1 252 #define OV_EOF -2 253 #define OV_HOLE -3 254 255 #define OV_EREAD -128 256 #define OV_EFAULT -129 257 #define OV_EIMPL -130 258 #define OV_EINVAL -131 259 #define OV_ENOTVORBIS -132 260 #define OV_EBADHEADER -133 261 #define OV_EVERSION -134 262 #define OV_ENOTAUDIO -135 263 #define OV_EBADPACKET -136 264 #define OV_EBADLINK -137 265 #define OV_ENOSEEK -138 266 267 /******************************/ 268 /******************************/ 269 /******************************/ 270 /* From <vorbis/vorbisfile.h> */ 271 /******************************/ 272 /******************************/ 273 /******************************/ 274 275 typedef struct { 276 size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource); 277 int (*seek_func) (void *datasource, ogg_int64_t offset, int whence); 278 int (*close_func) (void *datasource); 279 long (*tell_func) (void *datasource); 280 } ov_callbacks; 281 282 #if 0 283 static int _ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){ 284 if(f==NULL)return(-1); 285 return fseek(f,off,whence); 286 } 287 288 static ov_callbacks OV_CALLBACKS_DEFAULT = { 289 (size_t (*)(void *, size_t, size_t, void *)) fread, 290 (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap, 291 (int (*)(void *)) fclose, 292 (long (*)(void *)) ftell 293 }; 294 295 static ov_callbacks OV_CALLBACKS_NOCLOSE = { 296 (size_t (*)(void *, size_t, size_t, void *)) fread, 297 (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap, 298 (int (*)(void *)) NULL, 299 (long (*)(void *)) ftell 300 }; 301 302 static ov_callbacks OV_CALLBACKS_STREAMONLY = { 303 (size_t (*)(void *, size_t, size_t, void *)) fread, 304 (int (*)(void *, ogg_int64_t, int)) NULL, 305 (int (*)(void *)) fclose, 306 (long (*)(void *)) NULL 307 }; 308 309 static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = { 310 (size_t (*)(void *, size_t, size_t, void *)) fread, 311 (int (*)(void *, ogg_int64_t, int)) NULL, 312 (int (*)(void *)) NULL, 313 (long (*)(void *)) NULL 314 }; 315 #endif 316 317 #define NOTOPEN 0 318 #define PARTOPEN 1 319 #define OPENED 2 320 #define STREAMSET 3 321 #define INITSET 4 322 323 #include <utility/hooks.h> 324 325 typedef struct OggVorbis_File { 326 void *datasource; /* Pointer to a FILE *, etc. */ 327 int seekable; 328 ogg_int64_t offset; 329 ogg_int64_t end; 330 ogg_sync_state oy; 331 332 /* If the FILE handle isn't seekable (eg, a pipe), only the current 333 stream appears */ 334 int links; 335 ogg_int64_t *offsets; 336 ogg_int64_t *dataoffsets; 337 long *serialnos; 338 ogg_int64_t *pcmlengths; /* overloaded to maintain binary 339 compatability; x2 size, stores both 340 beginning and end values */ 341 vorbis_info *vi; 342 vorbis_comment *vc; 343 344 /* Decoding working state local storage */ 345 ogg_int64_t pcm_offset; 346 int ready_state; 347 long current_serialno; 348 int current_link; 349 350 double bittrack; 351 double samptrack; 352 353 ogg_stream_state os; /* take physical pages, weld into a logical 354 stream of packets */ 355 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ 356 vorbis_block vb; /* local working space for packet->PCM decode */ 357 358 ov_callbacks callbacks; 359 } OggVorbis_File; 360 361 /******************************/ 362 /******************************/ 363 /******************************/ 364 /* From <vorbis/vorbisenc.h> */ 365 /******************************/ 366 /******************************/ 367 /******************************/ 368 369 /* deprecated rate management supported only for compatability */ 370 #define OV_ECTL_RATEMANAGE_GET 0x10 371 #define OV_ECTL_RATEMANAGE_SET 0x11 372 #define OV_ECTL_RATEMANAGE_AVG 0x12 373 #define OV_ECTL_RATEMANAGE_HARD 0x13 374 375 struct ovectl_ratemanage_arg { 376 int management_active; 377 378 long bitrate_hard_min; 379 long bitrate_hard_max; 380 double bitrate_hard_window; 381 382 long bitrate_av_lo; 383 long bitrate_av_hi; 384 double bitrate_av_window; 385 double bitrate_av_window_center; 386 }; 387 388 389 /* new rate setup */ 390 #define OV_ECTL_RATEMANAGE2_GET 0x14 391 #define OV_ECTL_RATEMANAGE2_SET 0x15 392 393 struct ovectl_ratemanage2_arg { 394 int management_active; 395 396 long bitrate_limit_min_kbps; 397 long bitrate_limit_max_kbps; 398 long bitrate_limit_reservoir_bits; 399 double bitrate_limit_reservoir_bias; 400 401 long bitrate_average_kbps; 402 double bitrate_average_damping; 403 }; 404 405 #define OV_ECTL_LOWPASS_GET 0x20 406 #define OV_ECTL_LOWPASS_SET 0x21 407 408 #define OV_ECTL_IBLOCK_GET 0x30 409 #define OV_ECTL_IBLOCK_SET 0x31 410 411 #define OV_ECTL_COUPLING_GET 0x40 412 #define OV_ECTL_COUPLING_SET 0x41 413 414 #endif /* LIBRARIES_VORBISFILE_H */