openalbridge/oggvorbis.h
changeset 2213 bd51bbf06033
child 2257 7eb31efcfb9b
equal deleted inserted replaced
2212:6b5da1a2765a 2213:bd51bbf06033
       
     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-2002             *
       
     9  * by the Xiph.Org Foundation http://www.xiph.org/                  *
       
    10  *                                                                  *
       
    11  ********************************************************************/
       
    12 
       
    13 #ifndef _OGGVORBIS_H
       
    14 #define _OGGVORBIS_H
       
    15 
       
    16 /*data types for ogg and vorbis that are required to be external*/
       
    17 #ifndef ogg_int64_t	
       
    18 #define ogg_int64_t int64_t
       
    19 #endif
       
    20 
       
    21 typedef struct {
       
    22 	unsigned char *data;
       
    23 	int storage;
       
    24 	int fill;
       
    25 	int returned;
       
    26 	
       
    27 	int unsynced;
       
    28 	int headerbytes;
       
    29 	int bodybytes;
       
    30 } ogg_sync_state;
       
    31 typedef struct vorbis_info{
       
    32 	int version;
       
    33 	int channels;
       
    34 	long rate;
       
    35 	
       
    36 	/* The below bitrate declarations are *hints*.
       
    37 	 Combinations of the three values carry the following implications:
       
    38 	 
       
    39 	 all three set to the same value:
       
    40 	 implies a fixed rate bitstream
       
    41 	 only nominal set:
       
    42 	 implies a VBR stream that averages the nominal bitrate.  No hard
       
    43 	 upper/lower limit
       
    44 	 upper and or lower set:
       
    45 	 implies a VBR bitstream that obeys the bitrate limits. nominal
       
    46 	 may also be set to give a nominal rate.
       
    47 	 none set:
       
    48 	 the coder does not care to speculate.
       
    49 	 */
       
    50 	
       
    51 	long bitrate_upper;
       
    52 	long bitrate_nominal;
       
    53 	long bitrate_lower;
       
    54 	long bitrate_window;
       
    55 	
       
    56 	void *codec_setup;
       
    57 } vorbis_info;
       
    58 typedef struct vorbis_comment{
       
    59 	/* unlimited user comment fields.  libvorbis writes 'libvorbis' whatever vendor is set to in encode */
       
    60 	char **user_comments;
       
    61 	int   *comment_lengths;
       
    62 	int    comments;
       
    63 	char  *vendor;
       
    64 	
       
    65 } vorbis_comment;
       
    66 typedef struct {
       
    67 	unsigned char   *body_data;    /* bytes from packet bodies */
       
    68 	long    body_storage;          /* storage elements allocated */
       
    69 	long    body_fill;             /* elements stored; fill mark */
       
    70 	long    body_returned;         /* elements of fill returned */
       
    71 	
       
    72 	
       
    73 	int     *lacing_vals;      /* The values that will go to the segment table */
       
    74 	ogg_int64_t *granule_vals; 
       
    75 	/* granulepos values for headers. Not compact
       
    76 	 this way, but it is simple coupled to the lacing fifo */
       
    77 	long    lacing_storage;
       
    78 	long    lacing_fill;
       
    79 	long    lacing_packet;
       
    80 	long    lacing_returned;
       
    81 	
       
    82 	unsigned char    header[282];      /* working space for header encode */
       
    83 	int              header_fill;
       
    84 	
       
    85 	int     e_o_s;          /* set when we have buffered the last packet in the logical bitstream */
       
    86 	int     b_o_s;          /* set after we've written the initial page of a logical bitstream */
       
    87 	long    serialno;
       
    88 	long    pageno;
       
    89 	ogg_int64_t  packetno;      
       
    90 	/* sequence number for decode; the framing
       
    91 	 knows where there's a hole in the data,
       
    92 	 but we need coupling so that the codec
       
    93 	 (which is in a seperate abstraction
       
    94 	 layer) also knows about the gap */
       
    95 	ogg_int64_t   granulepos;
       
    96 	
       
    97 } ogg_stream_state;
       
    98 typedef struct vorbis_dsp_state{
       
    99 	int analysisp;
       
   100 	vorbis_info *vi;
       
   101 	
       
   102 	float **pcm;
       
   103 	float **pcmret;
       
   104 	int      pcm_storage;
       
   105 	int      pcm_current;
       
   106 	int      pcm_returned;
       
   107 	
       
   108 	int  preextrapolate;
       
   109 	int  eofflag;
       
   110 	
       
   111 	long lW;
       
   112 	long W;
       
   113 	long nW;
       
   114 	long centerW;
       
   115 	
       
   116 	ogg_int64_t granulepos;
       
   117 	ogg_int64_t sequence;
       
   118 	
       
   119 	ogg_int64_t glue_bits;
       
   120 	ogg_int64_t time_bits;
       
   121 	ogg_int64_t floor_bits;
       
   122 	ogg_int64_t res_bits;
       
   123 	
       
   124 	void       *backend_state;
       
   125 } vorbis_dsp_state;
       
   126 typedef struct {
       
   127 	long endbyte;
       
   128 	int  endbit;
       
   129 	
       
   130 	unsigned char *buffer;
       
   131 	unsigned char *ptr;
       
   132 	long storage;
       
   133 } oggpack_buffer;
       
   134 typedef struct vorbis_block{
       
   135 	/* necessary stream state for linking to the framing abstraction */
       
   136 	float  **pcm;       /* this is a pointer into local storage */
       
   137 	oggpack_buffer opb;
       
   138 	
       
   139 	long  lW;
       
   140 	long  W;
       
   141 	long  nW;
       
   142 	int   pcmend;
       
   143 	int   mode;
       
   144 	
       
   145 	int         eofflag;
       
   146 	ogg_int64_t granulepos;
       
   147 	ogg_int64_t sequence;
       
   148 	vorbis_dsp_state *vd; /* For read-only access of configuration */
       
   149 	
       
   150 	/* local storage to avoid remallocing; it's up to the mapping to structure it */
       
   151 	void               *localstore;
       
   152 	long                localtop;
       
   153 	long                localalloc;
       
   154 	long                totaluse;
       
   155 	struct alloc_chain *reap;
       
   156 	
       
   157 	/* bitmetrics for the frame */
       
   158 	long glue_bits;
       
   159 	long time_bits;
       
   160 	long floor_bits;
       
   161 	long res_bits;
       
   162 	
       
   163 	void *internal;
       
   164 	
       
   165 } vorbis_block;
       
   166 typedef struct {
       
   167 	size_t (*read_func)  (void *ptr, size_t size, size_t nmemb, void *datasource);
       
   168 	int    (*seek_func)  (void *datasource, ogg_int64_t offset, int whence);
       
   169 	int    (*close_func) (void *datasource);
       
   170 	long   (*tell_func)  (void *datasource);
       
   171 } ov_callbacks;
       
   172 typedef struct OggVorbis_File {
       
   173 	void            *datasource; /* Pointer to a FILE *, etc. */
       
   174 	int              seekable;
       
   175 	ogg_int64_t      offset;
       
   176 	ogg_int64_t      end;
       
   177 	ogg_sync_state   oy;
       
   178 	
       
   179 	/* If the FILE handle isn't seekable (eg, a pipe), only the current stream appears */
       
   180 	int              links;
       
   181 	ogg_int64_t     *offsets;
       
   182 	ogg_int64_t     *dataoffsets;
       
   183 	long            *serialnos;
       
   184 	ogg_int64_t     *pcmlengths; 
       
   185 	/* overloaded to maintain binary
       
   186 	 compatability; x2 size, stores both
       
   187 	 beginning and end values */
       
   188 	vorbis_info     *vi;
       
   189 	vorbis_comment  *vc;
       
   190 	
       
   191 	/* Decoding working state local storage */
       
   192 	ogg_int64_t      pcm_offset;
       
   193 	int              ready_state;
       
   194 	long             current_serialno;
       
   195 	int              current_link;
       
   196 	
       
   197 	double           bittrack;
       
   198 	double           samptrack;
       
   199 	
       
   200 	ogg_stream_state os; /* take physical pages, weld into a logical stream of packets */
       
   201 	vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
       
   202 	vorbis_block     vb; /* local working space for packet->PCM decode */
       
   203 	
       
   204 	ov_callbacks callbacks;
       
   205 	
       
   206 } OggVorbis_File;
       
   207 
       
   208 
       
   209 extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
       
   210 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
       
   211 extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
       
   212 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
       
   213 extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
       
   214 extern vorbis_comment *ov_comment(OggVorbis_File *f, int num);
       
   215 
       
   216 #endif /*_OGGVORBIS_H*/