ivorbisfile.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /************************************************************************
  2. * Copyright (C) 2002-2009, Xiph.org Foundation
  3. * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the names of the Xiph.org Foundation nor Pinknoise
  17. * Productions Ltd nor the names of its contributors may be used to
  18. * endorse or promote products derived from this software without
  19. * specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ************************************************************************
  33. function: stdio-based convenience library for opening/seeking/decoding
  34. ************************************************************************/
  35. #ifndef _OV_FILE_H_
  36. #define _OV_FILE_H_
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif /* __cplusplus */
  41. #include <stdio.h>
  42. #include "ivorbiscodec.h"
  43. /* The function prototypes for the callbacks are basically the same as for
  44. * the stdio functions fread, fseek, fclose, ftell.
  45. * The one difference is that the FILE * arguments have been replaced with
  46. * a void * - this is to be used as a pointer to whatever internal data these
  47. * functions might need. In the stdio case, it's just a FILE * cast to a void *
  48. *
  49. * If you use other functions, check the docs for these functions and return
  50. * the right values. For seek_func(), you *MUST* return -1 if the stream is
  51. * unseekable
  52. */
  53. typedef struct {
  54. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  55. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  56. int (*close_func) (void *datasource);
  57. long (*tell_func) (void *datasource);
  58. } ov_callbacks;
  59. typedef struct OggVorbis_File {
  60. void *datasource; /* Pointer to a FILE *, etc. */
  61. int seekable;
  62. ogg_int64_t offset;
  63. ogg_int64_t end;
  64. ogg_sync_state *oy;
  65. /* If the FILE handle isn't seekable (eg, a pipe), only the current
  66. stream appears */
  67. int links;
  68. ogg_int64_t *offsets;
  69. ogg_int64_t *dataoffsets;
  70. ogg_uint32_t *serialnos;
  71. ogg_int64_t *pcmlengths;
  72. vorbis_info vi;
  73. vorbis_comment vc;
  74. /* Decoding working state local storage */
  75. ogg_int64_t pcm_offset;
  76. int ready_state;
  77. ogg_uint32_t current_serialno;
  78. int current_link;
  79. ogg_int64_t bittrack;
  80. ogg_int64_t samptrack;
  81. ogg_stream_state *os; /* take physical pages, weld into a logical
  82. stream of packets */
  83. vorbis_dsp_state *vd; /* central working state for the packet->PCM decoder */
  84. ov_callbacks callbacks;
  85. } OggVorbis_File;
  86. extern int ov_clear(OggVorbis_File *vf);
  87. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  88. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  89. char *initial, long ibytes, ov_callbacks callbacks);
  90. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  91. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  92. char *initial, long ibytes, ov_callbacks callbacks);
  93. extern int ov_test_open(OggVorbis_File *vf);
  94. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95. extern long ov_bitrate_instant(OggVorbis_File *vf);
  96. extern long ov_streams(OggVorbis_File *vf);
  97. extern long ov_seekable(OggVorbis_File *vf);
  98. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  99. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  100. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  101. extern ogg_int64_t ov_time_total(OggVorbis_File *vf,int i);
  102. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  103. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  104. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  105. extern int ov_time_seek(OggVorbis_File *vf,ogg_int64_t pos);
  106. extern int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  107. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  108. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  109. extern ogg_int64_t ov_time_tell(OggVorbis_File *vf);
  110. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  111. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  112. extern long ov_read(OggVorbis_File *vf,void *buffer,int length,
  113. int *bitstream);
  114. #ifdef __cplusplus
  115. }
  116. #endif /* __cplusplus */
  117. #endif