Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * |
michael@0 | 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
michael@0 | 10 | |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: libvorbis codec headers |
michael@0 | 14 | last mod: $Id: codec.h 17021 2010-03-24 09:29:41Z xiphmont $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #ifndef _vorbis_codec_h_ |
michael@0 | 19 | #define _vorbis_codec_h_ |
michael@0 | 20 | |
michael@0 | 21 | #ifdef __cplusplus |
michael@0 | 22 | extern "C" |
michael@0 | 23 | { |
michael@0 | 24 | #endif /* __cplusplus */ |
michael@0 | 25 | |
michael@0 | 26 | #include <ogg/ogg.h> |
michael@0 | 27 | |
michael@0 | 28 | typedef struct vorbis_info{ |
michael@0 | 29 | int version; |
michael@0 | 30 | int channels; |
michael@0 | 31 | long rate; |
michael@0 | 32 | |
michael@0 | 33 | /* The below bitrate declarations are *hints*. |
michael@0 | 34 | Combinations of the three values carry the following implications: |
michael@0 | 35 | |
michael@0 | 36 | all three set to the same value: |
michael@0 | 37 | implies a fixed rate bitstream |
michael@0 | 38 | only nominal set: |
michael@0 | 39 | implies a VBR stream that averages the nominal bitrate. No hard |
michael@0 | 40 | upper/lower limit |
michael@0 | 41 | upper and or lower set: |
michael@0 | 42 | implies a VBR bitstream that obeys the bitrate limits. nominal |
michael@0 | 43 | may also be set to give a nominal rate. |
michael@0 | 44 | none set: |
michael@0 | 45 | the coder does not care to speculate. |
michael@0 | 46 | */ |
michael@0 | 47 | |
michael@0 | 48 | long bitrate_upper; |
michael@0 | 49 | long bitrate_nominal; |
michael@0 | 50 | long bitrate_lower; |
michael@0 | 51 | long bitrate_window; |
michael@0 | 52 | |
michael@0 | 53 | void *codec_setup; |
michael@0 | 54 | } vorbis_info; |
michael@0 | 55 | |
michael@0 | 56 | /* vorbis_dsp_state buffers the current vorbis audio |
michael@0 | 57 | analysis/synthesis state. The DSP state belongs to a specific |
michael@0 | 58 | logical bitstream ****************************************************/ |
michael@0 | 59 | typedef struct vorbis_dsp_state{ |
michael@0 | 60 | int analysisp; |
michael@0 | 61 | vorbis_info *vi; |
michael@0 | 62 | |
michael@0 | 63 | float **pcm; |
michael@0 | 64 | float **pcmret; |
michael@0 | 65 | int pcm_storage; |
michael@0 | 66 | int pcm_current; |
michael@0 | 67 | int pcm_returned; |
michael@0 | 68 | |
michael@0 | 69 | int preextrapolate; |
michael@0 | 70 | int eofflag; |
michael@0 | 71 | |
michael@0 | 72 | long lW; |
michael@0 | 73 | long W; |
michael@0 | 74 | long nW; |
michael@0 | 75 | long centerW; |
michael@0 | 76 | |
michael@0 | 77 | ogg_int64_t granulepos; |
michael@0 | 78 | ogg_int64_t sequence; |
michael@0 | 79 | |
michael@0 | 80 | ogg_int64_t glue_bits; |
michael@0 | 81 | ogg_int64_t time_bits; |
michael@0 | 82 | ogg_int64_t floor_bits; |
michael@0 | 83 | ogg_int64_t res_bits; |
michael@0 | 84 | |
michael@0 | 85 | void *backend_state; |
michael@0 | 86 | } vorbis_dsp_state; |
michael@0 | 87 | |
michael@0 | 88 | typedef struct vorbis_block{ |
michael@0 | 89 | /* necessary stream state for linking to the framing abstraction */ |
michael@0 | 90 | float **pcm; /* this is a pointer into local storage */ |
michael@0 | 91 | oggpack_buffer opb; |
michael@0 | 92 | |
michael@0 | 93 | long lW; |
michael@0 | 94 | long W; |
michael@0 | 95 | long nW; |
michael@0 | 96 | int pcmend; |
michael@0 | 97 | int mode; |
michael@0 | 98 | |
michael@0 | 99 | int eofflag; |
michael@0 | 100 | ogg_int64_t granulepos; |
michael@0 | 101 | ogg_int64_t sequence; |
michael@0 | 102 | vorbis_dsp_state *vd; /* For read-only access of configuration */ |
michael@0 | 103 | |
michael@0 | 104 | /* local storage to avoid remallocing; it's up to the mapping to |
michael@0 | 105 | structure it */ |
michael@0 | 106 | void *localstore; |
michael@0 | 107 | long localtop; |
michael@0 | 108 | long localalloc; |
michael@0 | 109 | long totaluse; |
michael@0 | 110 | struct alloc_chain *reap; |
michael@0 | 111 | |
michael@0 | 112 | /* bitmetrics for the frame */ |
michael@0 | 113 | long glue_bits; |
michael@0 | 114 | long time_bits; |
michael@0 | 115 | long floor_bits; |
michael@0 | 116 | long res_bits; |
michael@0 | 117 | |
michael@0 | 118 | void *internal; |
michael@0 | 119 | |
michael@0 | 120 | } vorbis_block; |
michael@0 | 121 | |
michael@0 | 122 | /* vorbis_block is a single block of data to be processed as part of |
michael@0 | 123 | the analysis/synthesis stream; it belongs to a specific logical |
michael@0 | 124 | bitstream, but is independent from other vorbis_blocks belonging to |
michael@0 | 125 | that logical bitstream. *************************************************/ |
michael@0 | 126 | |
michael@0 | 127 | struct alloc_chain{ |
michael@0 | 128 | void *ptr; |
michael@0 | 129 | struct alloc_chain *next; |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | /* vorbis_info contains all the setup information specific to the |
michael@0 | 133 | specific compression/decompression mode in progress (eg, |
michael@0 | 134 | psychoacoustic settings, channel setup, options, codebook |
michael@0 | 135 | etc). vorbis_info and substructures are in backends.h. |
michael@0 | 136 | *********************************************************************/ |
michael@0 | 137 | |
michael@0 | 138 | /* the comments are not part of vorbis_info so that vorbis_info can be |
michael@0 | 139 | static storage */ |
michael@0 | 140 | typedef struct vorbis_comment{ |
michael@0 | 141 | /* unlimited user comment fields. libvorbis writes 'libvorbis' |
michael@0 | 142 | whatever vendor is set to in encode */ |
michael@0 | 143 | char **user_comments; |
michael@0 | 144 | int *comment_lengths; |
michael@0 | 145 | int comments; |
michael@0 | 146 | char *vendor; |
michael@0 | 147 | |
michael@0 | 148 | } vorbis_comment; |
michael@0 | 149 | |
michael@0 | 150 | |
michael@0 | 151 | /* libvorbis encodes in two abstraction layers; first we perform DSP |
michael@0 | 152 | and produce a packet (see docs/analysis.txt). The packet is then |
michael@0 | 153 | coded into a framed OggSquish bitstream by the second layer (see |
michael@0 | 154 | docs/framing.txt). Decode is the reverse process; we sync/frame |
michael@0 | 155 | the bitstream and extract individual packets, then decode the |
michael@0 | 156 | packet back into PCM audio. |
michael@0 | 157 | |
michael@0 | 158 | The extra framing/packetizing is used in streaming formats, such as |
michael@0 | 159 | files. Over the net (such as with UDP), the framing and |
michael@0 | 160 | packetization aren't necessary as they're provided by the transport |
michael@0 | 161 | and the streaming layer is not used */ |
michael@0 | 162 | |
michael@0 | 163 | /* Vorbis PRIMITIVES: general ***************************************/ |
michael@0 | 164 | |
michael@0 | 165 | extern void vorbis_info_init(vorbis_info *vi); |
michael@0 | 166 | extern void vorbis_info_clear(vorbis_info *vi); |
michael@0 | 167 | extern int vorbis_info_blocksize(vorbis_info *vi,int zo); |
michael@0 | 168 | extern void vorbis_comment_init(vorbis_comment *vc); |
michael@0 | 169 | extern void vorbis_comment_add(vorbis_comment *vc, const char *comment); |
michael@0 | 170 | extern void vorbis_comment_add_tag(vorbis_comment *vc, |
michael@0 | 171 | const char *tag, const char *contents); |
michael@0 | 172 | extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count); |
michael@0 | 173 | extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag); |
michael@0 | 174 | extern void vorbis_comment_clear(vorbis_comment *vc); |
michael@0 | 175 | |
michael@0 | 176 | extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); |
michael@0 | 177 | extern int vorbis_block_clear(vorbis_block *vb); |
michael@0 | 178 | extern void vorbis_dsp_clear(vorbis_dsp_state *v); |
michael@0 | 179 | extern double vorbis_granule_time(vorbis_dsp_state *v, |
michael@0 | 180 | ogg_int64_t granulepos); |
michael@0 | 181 | |
michael@0 | 182 | extern const char *vorbis_version_string(void); |
michael@0 | 183 | |
michael@0 | 184 | /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/ |
michael@0 | 185 | |
michael@0 | 186 | extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi); |
michael@0 | 187 | extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op); |
michael@0 | 188 | extern int vorbis_analysis_headerout(vorbis_dsp_state *v, |
michael@0 | 189 | vorbis_comment *vc, |
michael@0 | 190 | ogg_packet *op, |
michael@0 | 191 | ogg_packet *op_comm, |
michael@0 | 192 | ogg_packet *op_code); |
michael@0 | 193 | extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals); |
michael@0 | 194 | extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals); |
michael@0 | 195 | extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb); |
michael@0 | 196 | extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op); |
michael@0 | 197 | |
michael@0 | 198 | extern int vorbis_bitrate_addblock(vorbis_block *vb); |
michael@0 | 199 | extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, |
michael@0 | 200 | ogg_packet *op); |
michael@0 | 201 | |
michael@0 | 202 | /* Vorbis PRIMITIVES: synthesis layer *******************************/ |
michael@0 | 203 | extern int vorbis_synthesis_idheader(ogg_packet *op); |
michael@0 | 204 | extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc, |
michael@0 | 205 | ogg_packet *op); |
michael@0 | 206 | |
michael@0 | 207 | extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi); |
michael@0 | 208 | extern int vorbis_synthesis_restart(vorbis_dsp_state *v); |
michael@0 | 209 | extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op); |
michael@0 | 210 | extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op); |
michael@0 | 211 | extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb); |
michael@0 | 212 | extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm); |
michael@0 | 213 | extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm); |
michael@0 | 214 | extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples); |
michael@0 | 215 | extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op); |
michael@0 | 216 | |
michael@0 | 217 | extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag); |
michael@0 | 218 | extern int vorbis_synthesis_halfrate_p(vorbis_info *v); |
michael@0 | 219 | |
michael@0 | 220 | /* Vorbis ERRORS and return codes ***********************************/ |
michael@0 | 221 | |
michael@0 | 222 | #define OV_FALSE -1 |
michael@0 | 223 | #define OV_EOF -2 |
michael@0 | 224 | #define OV_HOLE -3 |
michael@0 | 225 | |
michael@0 | 226 | #define OV_EREAD -128 |
michael@0 | 227 | #define OV_EFAULT -129 |
michael@0 | 228 | #define OV_EIMPL -130 |
michael@0 | 229 | #define OV_EINVAL -131 |
michael@0 | 230 | #define OV_ENOTVORBIS -132 |
michael@0 | 231 | #define OV_EBADHEADER -133 |
michael@0 | 232 | #define OV_EVERSION -134 |
michael@0 | 233 | #define OV_ENOTAUDIO -135 |
michael@0 | 234 | #define OV_EBADPACKET -136 |
michael@0 | 235 | #define OV_EBADLINK -137 |
michael@0 | 236 | #define OV_ENOSEEK -138 |
michael@0 | 237 | |
michael@0 | 238 | #ifdef __cplusplus |
michael@0 | 239 | } |
michael@0 | 240 | #endif /* __cplusplus */ |
michael@0 | 241 | |
michael@0 | 242 | #endif |
michael@0 | 243 |