vorbisfile.h 7.8 KB

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