vorbisfile.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. last mod: $Id: vorbisfile.h,v 1.2 2008-04-10 22:54:16 adrian_henke Exp $
  14. ********************************************************************/
  15. #ifndef _OV_FILE_H_
  16. #define _OV_FILE_H_
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif /* __cplusplus */
  21. #include <stdio.h>
  22. #include "codec.h"
  23. /* The function prototypes for the callbacks are basically the same as for
  24. * the stdio functions fread, fseek, fclose, ftell.
  25. * The one difference is that the FILE * arguments have been replaced with
  26. * a void * - this is to be used as a pointer to whatever internal data these
  27. * functions might need. In the stdio case, it's just a FILE * cast to a void *
  28. *
  29. * If you use other functions, check the docs for these functions and return
  30. * the right values. For seek_func(), you *MUST* return -1 if the stream is
  31. * unseekable
  32. */
  33. typedef struct {
  34. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  35. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  36. int (*close_func) (void *datasource);
  37. long (*tell_func) (void *datasource);
  38. } ov_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 incompatable 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. return fseek(f,(long)off,whence);
  46. }
  47. static const ov_callbacks OV_CALLBACKS_DEFAULT = {
  48. (size_t (*)(void *, size_t, size_t, void *)) fread,
  49. (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
  50. (int (*)(void *)) fclose,
  51. (long (*)(void *)) ftell
  52. };
  53. static const ov_callbacks OV_CALLBACKS_NOCLOSE = {
  54. (size_t (*)(void *, size_t, size_t, void *)) fread,
  55. (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
  56. (int (*)(void *)) NULL,
  57. (long (*)(void *)) ftell
  58. };
  59. static const ov_callbacks OV_CALLBACKS_STREAMONLY = {
  60. (size_t (*)(void *, size_t, size_t, void *)) fread,
  61. (int (*)(void *, ogg_int64_t, int)) NULL,
  62. (int (*)(void *)) fclose,
  63. (long (*)(void *)) NULL
  64. };
  65. static const ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = {
  66. (size_t (*)(void *, size_t, size_t, void *)) fread,
  67. (int (*)(void *, ogg_int64_t, int)) NULL,
  68. (int (*)(void *)) NULL,
  69. (long (*)(void *)) NULL
  70. };
  71. #define NOTOPEN 0
  72. #define PARTOPEN 1
  73. #define OPENED 2
  74. #define STREAMSET 3
  75. #define INITSET 4
  76. typedef struct OggVorbis_File {
  77. void *datasource; /* Pointer to a FILE *, etc. */
  78. int seekable;
  79. ogg_int64_t offset;
  80. ogg_int64_t end;
  81. ogg_sync_state oy;
  82. /* If the FILE handle isn't seekable (eg, a pipe), only the current
  83. stream appears */
  84. int links;
  85. ogg_int64_t *offsets;
  86. ogg_int64_t *dataoffsets;
  87. long *serialnos;
  88. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  89. compatability; x2 size, stores both
  90. beginning and end values */
  91. vorbis_info *vi;
  92. vorbis_comment *vc;
  93. /* Decoding working state local storage */
  94. ogg_int64_t pcm_offset;
  95. int ready_state;
  96. long current_serialno;
  97. int current_link;
  98. double bittrack;
  99. double samptrack;
  100. ogg_stream_state os; /* take physical pages, weld into a logical
  101. stream of packets */
  102. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  103. vorbis_block vb; /* local working space for packet->PCM decode */
  104. ov_callbacks callbacks;
  105. } OggVorbis_File;
  106. extern int ov_clear(OggVorbis_File *vf);
  107. extern int ov_fopen(char *path,OggVorbis_File *vf);
  108. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  109. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  110. char *initial, long ibytes, ov_callbacks callbacks);
  111. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  112. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  113. char *initial, long ibytes, ov_callbacks callbacks);
  114. extern int ov_test_open(OggVorbis_File *vf);
  115. extern long ov_bitrate(OggVorbis_File *vf,int i);
  116. extern long ov_bitrate_instant(OggVorbis_File *vf);
  117. extern long ov_streams(OggVorbis_File *vf);
  118. extern long ov_seekable(OggVorbis_File *vf);
  119. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  120. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  121. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  122. extern double ov_time_total(OggVorbis_File *vf,int i);
  123. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  124. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  125. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  126. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  127. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  128. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  129. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  130. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  131. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  132. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  133. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  134. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  135. extern double ov_time_tell(OggVorbis_File *vf);
  136. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  137. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  138. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  139. int *bitstream);
  140. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141. int bigendianp,int word,int sgned,int *bitstream);
  142. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  143. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  144. extern int ov_halfrate_p(OggVorbis_File *vf);
  145. #ifdef __cplusplus
  146. }
  147. #endif /* __cplusplus */
  148. #endif