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