root/liboggz/trunk/src/liboggz/oggz_private.h

Revision 3795, 8.7 kB (checked in by conrad, 2 weeks ago)

add API functions for getting and seting preroll:
oggz_get_preroll(), oggz_set_preroll()
Set preroll in oggz_auto.c for vorbis and speex

Line 
1 /*
2    Copyright (C) 2003 Commonwealth Scientific and Industrial Research
3    Organisation (CSIRO) Australia
4
5    Redistribution and use in source and binary forms, with or without
6    modification, are permitted provided that the following conditions
7    are met:
8
9    - Redistributions of source code must retain the above copyright
10    notice, this list of conditions and the following disclaimer.
11
12    - Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15
16    - Neither the name of CSIRO Australia nor the names of its
17    contributors may be used to endorse or promote products derived from
18    this software without specific prior written permission.
19
20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
24    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef __OGGZ_PRIVATE_H__
34 #define __OGGZ_PRIVATE_H__
35
36 #include <stdio.h>
37 #include <sys/types.h>
38
39 #include <ogg/ogg.h>
40 #include <oggz/oggz_constants.h>
41 #include <oggz/oggz_off_t.h>
42
43 #include "oggz_macros.h"
44 #include "oggz_vector.h"
45 #include "oggz_dlist.h"
46
47 #define OGGZ_AUTO_MULT 1000Ull
48
49 typedef struct _OGGZ OGGZ;
50 typedef struct _OggzComment OggzComment;
51 typedef struct _OggzIO OggzIO;
52 typedef struct _OggzReader OggzReader;
53 typedef struct _OggzWriter OggzWriter;
54
55
56 typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno,
57                                void * user_data);
58 typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og, long serialno,
59                              void * user_data);
60
61 /* oggz_stream */
62 #include "oggz_stream_private.h"
63
64 typedef ogg_int64_t (*OggzMetric) (OGGZ * oggz, long serialno,
65                                    ogg_int64_t granulepos,
66                                    void * user_data);
67
68 typedef int (*OggzOrder) (OGGZ * oggz, ogg_packet * op, void * target,
69                           void * user_data);
70
71 typedef int (*OggzWriteHungry) (OGGZ * oggz, int empty, void * user_data);
72
73 /* oggz_io */
74 typedef size_t (*OggzIORead) (void * user_handle, void * buf, size_t n);
75 typedef size_t (*OggzIOWrite) (void * user_handle, void * buf, size_t n);
76 typedef int (*OggzIOSeek) (void * user_handle, long offset, int whence);
77 typedef long (*OggzIOTell) (void * user_handle);
78 typedef int (*OggzIOFlush) (void * user_handle);
79
80 struct _oggz_stream_t {
81   ogg_stream_state ogg_stream;
82
83   /** STATIC INFO */
84   int content;
85   int numheaders;
86   int preroll;
87   ogg_int64_t granulerate_n;
88   ogg_int64_t granulerate_d;
89   ogg_int64_t basegranule;
90   int granuleshift;
91
92   /* The comments */
93   char * vendor;
94   OggzVector * comments;
95
96   /** CURRENT STATE **/
97   /* non b_o_s packet has been written (not just queued) */
98   int delivered_non_b_o_s;
99
100   int b_o_s; /* beginning of stream */
101   int e_o_s; /* end of stream */
102   ogg_int64_t granulepos;
103   ogg_int64_t packetno;
104
105   /** CALLBACKS **/
106   OggzMetric metric;
107   void * metric_user_data;
108   int metric_internal;
109
110   OggzOrder order;
111   void * order_user_data;
112
113   OggzReadPacket read_packet;
114   void * read_user_data;
115
116   OggzReadPage read_page;
117   void * read_page_user_data;
118
119   /* calculated granulepos values, not extracted values */
120   ogg_int64_t last_granulepos;
121   ogg_int64_t page_granulepos;
122   void * calculate_data;
123   ogg_packet  * last_packet;
124 };
125
126 struct _OggzReader {
127   ogg_sync_state ogg_sync;
128
129   /* XXX: these two can prolly be removed again :) */
130   ogg_stream_state ogg_stream;
131   long current_serialno;
132
133   OggzReadPacket read_packet;
134   void * read_user_data;
135
136   OggzReadPage read_page;
137   void * read_page_user_data;
138
139   ogg_int64_t current_unit;
140   ogg_int64_t current_granulepos;
141
142 #if 0
143   oggz_off_t offset_page_end; /* offset of end of current page */
144 #endif
145 };
146
147 /**
148  * Bundle a packet with the stream it is being queued for; used in
149  * the packet_queue vector
150  */
151 typedef struct {
152   ogg_packet op;
153   oggz_stream_t * stream;
154   int flush;
155   int * guard;
156 } oggz_writer_packet_t;
157
158 enum oggz_writer_state {
159   OGGZ_MAKING_PACKETS = 0,
160   OGGZ_WRITING_PAGES = 1
161 };
162
163 struct _OggzWriter {
164   oggz_writer_packet_t * next_zpacket; /* stashed in case of FLUSH_BEFORE */
165   OggzVector * packet_queue;
166
167   OggzWriteHungry hungry;
168   void * hungry_user_data;
169   int hungry_only_when_empty;
170
171   int writing; /* already mid-write; check for recursive writes */
172   int state; /* OGGZ_MAKING_PACKETS or OGGZ_WRITING_PAGES */
173
174   int flushing; /* whether current packet is being flushed or just paged out */
175
176 #if 0
177   int eog; /* end of page */
178   int eop; /* end of packet */
179 #endif
180   int eos; /* end of stream */
181
182   oggz_writer_packet_t * current_zpacket;
183
184   int packet_offset; /* n bytes already copied out of current packet */
185   int page_offset; /* n bytes already copied out of current page */
186
187   ogg_stream_state * current_stream;
188
189   int no_more_packets; /* used only in the local oggz_write loop to indicate
190                           end of stream */
191
192 };
193
194 struct _OggzIO {
195   OggzIORead read;
196   void * read_user_handle;
197
198   OggzIOWrite write;
199   void * write_user_handle;
200
201   OggzIOSeek seek;
202   void * seek_user_handle;
203
204   OggzIOTell tell;
205   void * tell_user_handle;
206
207   OggzIOFlush flush;
208   void * flush_user_handle;
209 };
210
211 struct _OggzComment {
212   /** The name of the comment, eg. "AUTHOR" */
213   char * name;
214
215   /** The value of the comment, as UTF-8 */
216   char * value;
217 };
218
219 struct _OGGZ {
220   int flags;
221   FILE * file;
222   OggzIO * io;
223
224   ogg_packet current_packet;
225   ogg_page current_page;
226
227   oggz_off_t offset; /* offset of current page start */
228   oggz_off_t offset_data_begin; /* offset of unit 0 page start */
229
230   long run_blocksize; /* blocksize to use for oggz_run() */
231   int cb_next;
232
233   OggzVector * streams;
234   int all_at_eos; /* all streams are at eos */
235
236   OggzMetric metric;
237   void * metric_user_data;
238   int metric_internal;
239
240   OggzOrder order;
241   void * order_user_data;
242
243   union {
244     OggzReader reader;
245     OggzWriter writer;
246   } x;
247
248   OggzDList * packet_buffer;
249 };
250
251 OGGZ * oggz_read_init (OGGZ * oggz);
252 OGGZ * oggz_read_close (OGGZ * oggz);
253
254 OGGZ * oggz_write_init (OGGZ * oggz);
255 int oggz_write_flush (OGGZ * oggz);
256 OGGZ * oggz_write_close (OGGZ * oggz);
257
258 int oggz_map_return_value_to_error (int cb_ret);
259
260 int oggz_get_bos (OGGZ * oggz, long serialno);
261 ogg_int64_t oggz_get_unit (OGGZ * oggz, long serialno, ogg_int64_t granulepos);
262
263 int oggz_set_metric_internal (OGGZ * oggz, long serialno, OggzMetric metric,
264                               void * user_data, int internal);
265 int oggz_has_metrics (OGGZ * oggz);
266
267 int oggz_purge (OGGZ * oggz);
268
269 /* metric_internal */
270
271 int
272 oggz_set_granulerate (OGGZ * oggz, long serialno,
273                                     ogg_int64_t granule_rate_numerator,
274                                     ogg_int64_t granule_rate_denominator);
275
276 int
277 oggz_get_granulerate (OGGZ * oggz, long serialno,
278                                     ogg_int64_t * granulerate_n,
279                                     ogg_int64_t * granulerate_d);
280
281 int oggz_set_granuleshift (OGGZ * oggz, long serialno, int granuleshift);
282 int oggz_get_granuleshift (OGGZ * oggz, long serialno);
283
284 int oggz_set_preroll (OGGZ * oggz, long serialno, int preroll);
285 int oggz_get_preroll (OGGZ * oggz, long serialno);
286
287 /* oggz_auto */
288  
289 int
290 oggz_auto_read_bos_page (OGGZ * oggz, ogg_page * og, long serialno,
291                          void * user_data);
292 int
293 oggz_auto_read_bos_packet (OGGZ * oggz, ogg_packet * op, long serialno,
294                            void * user_data);
295
296 int
297 oggz_auto_read_comments (OGGZ * oggz, oggz_stream_t * stream, long serialno,
298                          ogg_packet * op);
299
300 int oggz_auto_identify_page (OGGZ *oggz, ogg_page *og, long serialno);
301 int oggz_auto_identify_packet (OGGZ * oggz, ogg_packet * op, long serialno);
302
303 /* comments */
304 int oggz_comments_init (oggz_stream_t * stream);
305 int oggz_comments_free (oggz_stream_t * stream);
306 int oggz_comments_decode (OGGZ * oggz, long serialno,
307                           unsigned char * comments, long length);
308 long oggz_comments_encode (OGGZ * oggz, long serialno,
309                            unsigned char * buf, long length);
310
311 /* oggz_io */
312 size_t oggz_io_read (OGGZ * oggz, void * buf, size_t n);
313 size_t oggz_io_write (OGGZ * oggz, void * buf, size_t n);
314 int oggz_io_seek (OGGZ * oggz, long offset, int whence);
315 long oggz_io_tell (OGGZ * oggz);
316 int oggz_io_flush (OGGZ * oggz);
317
318 #endif /* __OGGZ_PRIVATE_H__ */
Note: See TracBrowser for help on using the browser.