2005-02-17 09:08:18 +00:00
|
|
|
/********************************************************************
|
|
|
|
* *
|
2010-12-06 14:36:52 +00:00
|
|
|
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
2005-02-17 09:08:18 +00:00
|
|
|
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
|
|
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
|
|
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
|
|
|
* *
|
2010-12-06 14:36:52 +00:00
|
|
|
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
|
|
|
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
2005-02-17 09:08:18 +00:00
|
|
|
* *
|
|
|
|
********************************************************************
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
function: toplevel libogg include
|
|
|
|
last mod: $Id$
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
********************************************************************/
|
|
|
|
#ifndef _OGG_H
|
|
|
|
#define _OGG_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
#include <stddef.h>
|
2005-02-17 09:08:18 +00:00
|
|
|
#include "os_types.h"
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
extern const unsigned long mask[] ICONST_ATTR;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
typedef struct {
|
|
|
|
void *iov_base;
|
|
|
|
size_t iov_len;
|
|
|
|
} ogg_iovec_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
long endbyte;
|
|
|
|
int endbit;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
unsigned char *buffer;
|
2005-02-17 09:08:18 +00:00
|
|
|
unsigned char *ptr;
|
2010-12-06 14:36:52 +00:00
|
|
|
long storage;
|
|
|
|
} oggpack_buffer;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
typedef struct {
|
|
|
|
unsigned char *header;
|
|
|
|
long header_len;
|
|
|
|
unsigned char *body;
|
|
|
|
long body_len;
|
|
|
|
} ogg_page;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
/* ogg_stream_state contains the current encode/decode state of a logical
|
|
|
|
Ogg bitstream **********************************************************/
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
typedef struct {
|
|
|
|
unsigned char *body_data; /* bytes from packet bodies */
|
|
|
|
long body_storage; /* storage elements allocated */
|
|
|
|
long body_fill; /* elements stored; fill mark */
|
|
|
|
long body_returned; /* elements of fill returned */
|
|
|
|
|
|
|
|
|
|
|
|
int *lacing_vals; /* The values that will go to the segment table */
|
|
|
|
ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
|
|
|
|
this way, but it is simple coupled to the
|
|
|
|
lacing fifo */
|
|
|
|
long lacing_storage;
|
|
|
|
long lacing_fill;
|
|
|
|
long lacing_packet;
|
|
|
|
long lacing_returned;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
unsigned char header[282]; /* working space for header encode */
|
|
|
|
int header_fill;
|
|
|
|
#endif
|
|
|
|
int e_o_s; /* set when we have buffered the last packet in the
|
|
|
|
logical bitstream */
|
|
|
|
int b_o_s; /* set after we've written the initial page
|
|
|
|
of a logical bitstream */
|
|
|
|
ogg_uint32_t serialno;
|
|
|
|
long pageno;
|
|
|
|
ogg_int64_t packetno; /* sequence number for decode; the framing
|
|
|
|
knows where there's a hole in the data,
|
|
|
|
but we need coupling so that the codec
|
|
|
|
(which is in a separate abstraction
|
|
|
|
layer) also knows about the gap */
|
|
|
|
ogg_int64_t granulepos;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
} ogg_stream_state;
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
/* ogg_packet is used to encapsulate the data and metadata belonging
|
|
|
|
to a single raw Ogg/Vorbis packet *************************************/
|
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
typedef struct {
|
2010-12-06 14:36:52 +00:00
|
|
|
unsigned char *packet;
|
|
|
|
long bytes;
|
|
|
|
long b_o_s;
|
|
|
|
long e_o_s;
|
|
|
|
|
|
|
|
ogg_int64_t granulepos;
|
|
|
|
|
|
|
|
ogg_int64_t packetno; /* sequence number for decode; the framing
|
|
|
|
knows where there's a hole in the data,
|
|
|
|
but we need coupling so that the codec
|
|
|
|
(which is in a separate abstraction
|
|
|
|
layer) also knows about the gap */
|
2005-02-17 09:08:18 +00:00
|
|
|
} ogg_packet;
|
|
|
|
|
|
|
|
typedef struct {
|
2010-12-06 14:36:52 +00:00
|
|
|
unsigned char *data;
|
|
|
|
int storage;
|
|
|
|
int fill;
|
|
|
|
int returned;
|
|
|
|
|
|
|
|
int unsynced;
|
|
|
|
int headerbytes;
|
|
|
|
int bodybytes;
|
|
|
|
} ogg_sync_state;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
|
2010-12-06 14:36:52 +00:00
|
|
|
/*
|
|
|
|
extern void oggpack_writeinit(oggpack_buffer *b);
|
|
|
|
extern int oggpack_writecheck(oggpack_buffer *b);
|
|
|
|
extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
|
|
|
|
extern void oggpack_writealign(oggpack_buffer *b);
|
|
|
|
extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
|
|
|
|
extern void oggpack_reset(oggpack_buffer *b);
|
|
|
|
extern void oggpack_writeclear(oggpack_buffer *b); */
|
|
|
|
extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
|
2011-08-28 16:35:45 +00:00
|
|
|
/*
|
|
|
|
extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
|
|
|
|
extern long oggpack_look(oggpack_buffer *b,int bits);
|
|
|
|
*/
|
2010-12-06 14:36:52 +00:00
|
|
|
|
|
|
|
static inline long oggpack_look(oggpack_buffer *b,int bits){
|
|
|
|
unsigned long ret;
|
|
|
|
unsigned long m;
|
|
|
|
|
|
|
|
if(bits<0 || bits>32) return -1;
|
|
|
|
m=mask[bits];
|
|
|
|
bits+=b->endbit;
|
|
|
|
|
|
|
|
if(b->endbyte >= b->storage-4){
|
|
|
|
/* not the main path */
|
|
|
|
if(b->endbyte > b->storage-((bits+7)>>3)) return -1;
|
|
|
|
/* special case to avoid reading b->ptr[0], which might be past the end of
|
|
|
|
the buffer; also skips some useless accounting */
|
|
|
|
else if(!bits)return(0L);
|
|
|
|
}
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
ret=b->ptr[0]>>b->endbit;
|
|
|
|
if(bits>8){
|
|
|
|
ret|=b->ptr[1]<<(8-b->endbit);
|
|
|
|
if(bits>16){
|
|
|
|
ret|=b->ptr[2]<<(16-b->endbit);
|
|
|
|
if(bits>24){
|
|
|
|
ret|=b->ptr[3]<<(24-b->endbit);
|
|
|
|
if(bits>32 && b->endbit)
|
|
|
|
ret|=b->ptr[4]<<(32-b->endbit);
|
|
|
|
}
|
2005-12-21 19:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 14:36:52 +00:00
|
|
|
return(m&ret);
|
2005-12-21 19:46:34 +00:00
|
|
|
}
|
2011-08-28 17:28:44 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern long oggpack_look1(oggpack_buffer *b);
|
2011-08-28 17:28:44 +00:00
|
|
|
extern void oggpack_adv(oggpack_buffer *b,int bits);
|
|
|
|
*/
|
2010-12-06 14:36:52 +00:00
|
|
|
|
2011-08-28 17:28:44 +00:00
|
|
|
static inline void oggpack_adv(oggpack_buffer *b, unsigned int bits){
|
2010-12-06 14:36:52 +00:00
|
|
|
bits+=b->endbit;
|
2005-12-21 19:46:34 +00:00
|
|
|
|
2011-08-28 17:28:44 +00:00
|
|
|
if(b->endbyte > b->storage-(int)((bits+7)>>3)) goto overflow;
|
2010-12-06 14:36:52 +00:00
|
|
|
|
|
|
|
b->ptr+=bits/8;
|
|
|
|
b->endbyte+=bits/8;
|
|
|
|
b->endbit=bits&7;
|
|
|
|
return;
|
|
|
|
|
|
|
|
overflow:
|
|
|
|
b->ptr=NULL;
|
|
|
|
b->endbyte=b->storage;
|
|
|
|
b->endbit=1;
|
2005-12-21 19:46:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-28 17:28:44 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern void oggpack_adv1(oggpack_buffer *b);
|
2011-08-28 17:28:44 +00:00
|
|
|
*/
|
2010-12-06 14:36:52 +00:00
|
|
|
extern long oggpack_read(oggpack_buffer *b,int bits);
|
2011-08-28 17:28:44 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern long oggpack_read1(oggpack_buffer *b);
|
2011-08-28 16:35:45 +00:00
|
|
|
extern long oggpack_bytes(oggpack_buffer *b);
|
|
|
|
*/
|
2010-12-06 17:16:45 +00:00
|
|
|
static inline long oggpack_bytes(oggpack_buffer *b){
|
|
|
|
return(b->endbyte+(b->endbit+7)/8);
|
|
|
|
}
|
2010-12-06 14:36:52 +00:00
|
|
|
#if 0
|
|
|
|
extern long oggpack_bits(oggpack_buffer *b);
|
|
|
|
extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
|
|
|
|
|
|
|
|
extern void oggpackB_writeinit(oggpack_buffer *b);
|
|
|
|
extern int oggpackB_writecheck(oggpack_buffer *b);
|
|
|
|
extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
|
|
|
|
extern void oggpackB_writealign(oggpack_buffer *b);
|
|
|
|
extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
|
|
|
|
extern void oggpackB_reset(oggpack_buffer *b);
|
|
|
|
extern void oggpackB_writeclear(oggpack_buffer *b);
|
|
|
|
extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
|
|
|
|
extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
|
|
|
|
extern long oggpackB_look(oggpack_buffer *b,int bits);
|
|
|
|
extern long oggpackB_look1(oggpack_buffer *b);
|
|
|
|
extern void oggpackB_adv(oggpack_buffer *b,int bits);
|
|
|
|
extern void oggpackB_adv1(oggpack_buffer *b);
|
|
|
|
extern long oggpackB_read(oggpack_buffer *b,int bits);
|
|
|
|
extern long oggpackB_read1(oggpack_buffer *b);
|
|
|
|
extern long oggpackB_bytes(oggpack_buffer *b);
|
|
|
|
extern long oggpackB_bits(oggpack_buffer *b);
|
|
|
|
extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
|
|
|
|
# endif
|
|
|
|
/* Ogg BITSTREAM PRIMITIVES: encoding **************************/
|
|
|
|
#if 0
|
|
|
|
extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
|
|
|
|
extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
|
|
|
|
int count, long e_o_s, ogg_int64_t granulepos);
|
|
|
|
extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
|
|
|
|
extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill);
|
|
|
|
extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
|
|
|
|
#endif
|
2005-02-17 09:08:18 +00:00
|
|
|
/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
|
|
|
|
|
2011-10-08 10:09:11 +00:00
|
|
|
extern int _os_body_expand(ogg_stream_state *os,int needed);
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
extern int ogg_sync_init(ogg_sync_state *oy);
|
|
|
|
extern int ogg_sync_clear(ogg_sync_state *oy);
|
2005-02-17 09:08:18 +00:00
|
|
|
extern int ogg_sync_reset(ogg_sync_state *oy);
|
2011-08-28 16:35:45 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern int ogg_sync_destroy(ogg_sync_state *oy);
|
|
|
|
extern int ogg_sync_check(ogg_sync_state *oy);
|
2011-08-28 16:35:45 +00:00
|
|
|
*/
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
|
2005-02-17 09:08:18 +00:00
|
|
|
extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
|
|
|
|
extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
|
2011-08-28 16:35:45 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
|
2011-08-28 16:35:45 +00:00
|
|
|
*/
|
2011-10-08 10:09:11 +00:00
|
|
|
extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og, bool copy_body);
|
2005-02-17 09:08:18 +00:00
|
|
|
extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
|
|
|
|
extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
|
|
|
|
|
|
|
|
/* Ogg BITSTREAM PRIMITIVES: general ***************************/
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
extern int ogg_stream_init(ogg_stream_state *os,int serialno);
|
|
|
|
extern int ogg_stream_clear(ogg_stream_state *os);
|
2005-02-17 09:08:18 +00:00
|
|
|
extern int ogg_stream_reset(ogg_stream_state *os);
|
|
|
|
extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
|
2011-08-28 16:35:45 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern int ogg_stream_destroy(ogg_stream_state *os);
|
|
|
|
extern int ogg_stream_check(ogg_stream_state *os);
|
2011-08-28 16:35:45 +00:00
|
|
|
*/
|
2005-02-17 09:08:18 +00:00
|
|
|
extern int ogg_stream_eos(ogg_stream_state *os);
|
|
|
|
|
2011-08-28 16:35:45 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern void ogg_page_checksum_set(ogg_page *og);
|
|
|
|
extern int ogg_page_version(const ogg_page *og);
|
2011-08-28 16:35:45 +00:00
|
|
|
*/
|
2010-12-06 14:36:52 +00:00
|
|
|
extern int ogg_page_continued(const ogg_page *og);
|
|
|
|
extern int ogg_page_bos(const ogg_page *og);
|
|
|
|
extern int ogg_page_eos(const ogg_page *og);
|
|
|
|
extern ogg_int64_t ogg_page_granulepos(const ogg_page *og);
|
|
|
|
extern ogg_uint32_t ogg_page_serialno(const ogg_page *og);
|
2011-08-28 16:35:45 +00:00
|
|
|
/*
|
2010-12-06 14:36:52 +00:00
|
|
|
extern long ogg_page_pageno(const ogg_page *og);
|
|
|
|
extern int ogg_page_packets(const ogg_page *og);
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
extern void ogg_packet_clear(ogg_packet *op);
|
2011-08-28 16:35:45 +00:00
|
|
|
*/
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _OGG_H */
|