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