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