• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
34  function: stdio-based convenience library for opening/seeking/decoding
35 
36  ************************************************************************/
37 
38 #ifndef _OV_FILE_H_
39 #define _OV_FILE_H_
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif /* __cplusplus */
45 
46 #include <stdio.h>
47 #include "ivorbiscodec.h"
48 
49 /* The function prototypes for the callbacks are basically the same as for
50  * the stdio functions fread, fseek, fclose, ftell.
51  * The one difference is that the FILE * arguments have been replaced with
52  * a void * - this is to be used as a pointer to whatever internal data these
53  * functions might need. In the stdio case, it's just a FILE * cast to a void *
54  *
55  * If you use other functions, check the docs for these functions and return
56  * the right values. For seek_func(), you *MUST* return -1 if the stream is
57  * unseekable
58  */
59 typedef struct {
60   size_t (*read_func)  (void *ptr, size_t size, size_t nmemb, void *datasource);
61   int    (*seek_func)  (void *datasource, ogg_int64_t offset, int whence);
62   int    (*close_func) (void *datasource);
63   long   (*tell_func)  (void *datasource);
64 } ov_callbacks;
65 
66 typedef struct OggVorbis_File {
67   void            *datasource; /* Pointer to a FILE *, etc. */
68   int              seekable;
69   ogg_int64_t      offset;
70   ogg_int64_t      end;
71   ogg_sync_state   *oy;
72 
73   /* If the FILE handle isn't seekable (eg, a pipe), only the current
74      stream appears */
75   int              links;
76   ogg_int64_t     *offsets;
77   ogg_int64_t     *dataoffsets;
78   ogg_uint32_t    *serialnos;
79   ogg_int64_t     *pcmlengths;
80   vorbis_info     vi;
81   vorbis_comment  vc;
82 
83   /* Decoding working state local storage */
84   ogg_int64_t      pcm_offset;
85   int              ready_state;
86   ogg_uint32_t     current_serialno;
87   int              current_link;
88 
89   ogg_int64_t      bittrack;
90   ogg_int64_t      samptrack;
91 
92   ogg_stream_state *os; /* take physical pages, weld into a logical
93                           stream of packets */
94   vorbis_dsp_state *vd; /* central working state for the packet->PCM decoder */
95 
96   ov_callbacks callbacks;
97 
98 } OggVorbis_File;
99 
100 extern int ov_clear(OggVorbis_File *vf);
101 extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
102 extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
103 		char *initial, long ibytes, ov_callbacks callbacks);
104 
105 extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
106 extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
107 		char *initial, long ibytes, ov_callbacks callbacks);
108 extern int ov_test_open(OggVorbis_File *vf);
109 
110 extern long ov_bitrate(OggVorbis_File *vf,int i);
111 extern long ov_bitrate_instant(OggVorbis_File *vf);
112 extern long ov_streams(OggVorbis_File *vf);
113 extern long ov_seekable(OggVorbis_File *vf);
114 extern long ov_serialnumber(OggVorbis_File *vf,int i);
115 
116 extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
117 extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
118 extern ogg_int64_t ov_time_total(OggVorbis_File *vf,int i);
119 
120 extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
121 extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
122 extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
123 extern int ov_time_seek(OggVorbis_File *vf,ogg_int64_t pos);
124 extern int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
125 
126 extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
127 extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
128 extern ogg_int64_t ov_time_tell(OggVorbis_File *vf);
129 
130 extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
131 extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
132 
133 extern long ov_read(OggVorbis_File *vf,void *buffer,int length,
134 		    int *bitstream);
135 
136 #ifdef __cplusplus
137 }
138 #endif /* __cplusplus */
139 
140 #endif
141 
142 
143