1
0
Fork 0
forked from len0rd/rockbox

libtremor:

Merge in upstream revision 17375.
This removes tremor's internal ogg code and now uses libogg instead so a bunch of changes are just adjusting to the new api. Also brings in improvements to vorbisfile which fixes FS#10484.
Disabled a lot of unused code in the libogg files and moved some small functions into the ogg.h header so they can be inlined. Some small tweaks to fix warnings.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28742 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Nils Wallménius 2010-12-06 14:36:52 +00:00
parent 1f64b7fb1f
commit 67efbc1387
8 changed files with 3153 additions and 1504 deletions

File diff suppressed because it is too large Load diff

View file

@ -279,7 +279,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
long *bufend = buf + n;
while (bufptr<bufend) {
if (b->headend > 8) {
if(b->endbyte < b->storage - 8) {
ogg_uint32_t *ptr;
unsigned long bit, bitend;
unsigned long adr;
@ -292,10 +292,10 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
const ogg_uint32_t *book_codelist = book->codelist;
const char *book_dec_codelengths = book->dec_codelengths;
adr = (unsigned long)b->headptr;
bit = (adr&3)*8+b->headbit;
adr = (unsigned long)b->ptr;
bit = (adr&3)*8+b->endbit;
ptr = (ogg_uint32_t*)(adr&~3);
bitend = ((adr&3)+b->headend)*8;
bitend = ((adr&3)+(b->storage-b->endbyte))*8;
while (bufptr<bufend){
if (UNLIKELY(cachesize<book_dec_maxlength)) {
if (bit-cachesize+32>=bitend)
@ -323,11 +323,11 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
cache >>= l;
}
adr=(unsigned long)b->headptr;
adr=(unsigned long)b->ptr;
bit-=(adr&3)*8+cachesize;
b->headend-=(bit/8);
b->headptr+=bit/8;
b->headbit=bit%8;
b->endbyte+=bit/8;
b->ptr+=bit/8;
b->endbit=bit&7;
} else {
long r = decode_packed_entry_number(book, b);
if (r == -1) return bufptr-buf;
@ -337,7 +337,6 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
return n;
}
/* Decode side is specced and easier, because we don't need to find
matches using different criteria; we simply read and map. There are
two things we need to do 'depending':
@ -570,3 +569,4 @@ long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,
}
return(0);
}

File diff suppressed because it is too large Load diff

View file

@ -240,7 +240,7 @@ int vorbis_synthesis_idheader(ogg_packet *op){
char buffer[6];
if(op){
oggpack_readinit(&opb,op->packet);
oggpack_readinit(&opb,op->packet,op->bytes);
if(!op->b_o_s)
return(0); /* Not the initial packet */
@ -268,7 +268,7 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
oggpack_buffer opb;
if(op){
oggpack_readinit(&opb,op->packet);
oggpack_readinit(&opb,op->packet,op->bytes);
/* Which of the three types of header is this? */
/* Also verify header-ness, vorbis */

View file

@ -56,7 +56,7 @@ typedef struct OggVorbis_File {
int seekable;
ogg_int64_t offset;
ogg_int64_t end;
ogg_sync_state *oy;
ogg_sync_state oy;
/* If the FILE handle isn't seekable (eg, a pipe), only the current
stream appears */
@ -77,7 +77,7 @@ typedef struct OggVorbis_File {
ogg_int64_t bittrack;
ogg_int64_t samptrack;
ogg_stream_state *os; /* take physical pages, weld into a logical
ogg_stream_state os; /* take physical pages, weld into a logical
stream of packets */
vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
vorbis_block vb; /* local working space for packet->PCM decode */
@ -87,13 +87,11 @@ typedef struct OggVorbis_File {
} OggVorbis_File;
extern int ov_clear(OggVorbis_File *vf);
//extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
char *initial, long ibytes, ov_callbacks callbacks);
const char *initial, long ibytes, ov_callbacks callbacks);
//extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
char *initial, long ibytes, ov_callbacks callbacks);
const char *initial, long ibytes, ov_callbacks callbacks);
extern int ov_test_open(OggVorbis_File *vf);
extern long ov_bitrate(OggVorbis_File *vf,int i);

View file

@ -1,17 +1,17 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* 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. *
* *
* THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
* BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: subsumed libogg includes
function: toplevel libogg include
last mod: $Id$
********************************************************************/
#ifndef _OGG_H
@ -21,241 +21,238 @@
extern "C" {
#endif
#include <stddef.h>
#include "os_types.h"
typedef struct ogg_buffer_state{
struct ogg_buffer *unused_buffers;
struct ogg_reference *unused_references;
int outstanding;
int shutdown;
} ogg_buffer_state;
typedef struct ogg_buffer {
unsigned char *data;
long size;
int refcount;
union {
ogg_buffer_state *owner;
struct ogg_buffer *next;
} ptr;
} ogg_buffer;
typedef struct ogg_reference {
ogg_buffer *buffer;
long begin;
long length;
struct ogg_reference *next;
} ogg_reference;
typedef struct oggpack_buffer {
int headbit;
unsigned char *headptr;
long headend;
/* memory management */
ogg_reference *head;
ogg_reference *tail;
/* render the byte/bit counter API constant time */
long count; /* doesn't count the tail */
} oggpack_buffer;
typedef struct oggbyte_buffer {
ogg_reference *baseref;
ogg_reference *ref;
unsigned char *ptr;
long pos;
long end;
} oggbyte_buffer;
typedef struct ogg_sync_state {
/* decode memory management pool */
ogg_buffer_state *bufferpool;
/* stream buffers */
ogg_reference *fifo_head;
ogg_reference *fifo_tail;
long fifo_fill;
/* stream sync management */
int unsynced;
int headerbytes;
int bodybytes;
} ogg_sync_state;
typedef struct ogg_stream_state {
ogg_reference *header_head;
ogg_reference *header_tail;
ogg_reference *body_head;
ogg_reference *body_tail;
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 */
long 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 seperate abstraction
layer) also knows about the gap */
ogg_int64_t granulepos;
int lacing_fill;
ogg_uint32_t body_fill;
/* decode-side state data */
int holeflag;
int spanflag;
int clearflag;
int laceptr;
ogg_uint32_t body_fill_next;
} ogg_stream_state;
extern const unsigned long mask[] ICONST_ATTR;
typedef struct {
ogg_reference *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 seperate abstraction
layer) also knows about the gap */
void *iov_base;
size_t iov_len;
} ogg_iovec_t;
typedef struct {
long endbyte;
int endbit;
unsigned char *buffer;
unsigned char *ptr;
long storage;
} oggpack_buffer;
/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
typedef struct {
unsigned char *header;
long header_len;
unsigned char *body;
long body_len;
} ogg_page;
/* ogg_stream_state contains the current encode/decode state of a logical
Ogg bitstream **********************************************************/
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;
} ogg_stream_state;
/* ogg_packet is used to encapsulate the data and metadata belonging
to a single raw Ogg/Vorbis packet *************************************/
typedef struct {
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 */
} ogg_packet;
typedef struct {
ogg_reference *header;
int header_len;
ogg_reference *body;
long body_len;
} ogg_page;
unsigned char *data;
int storage;
int fill;
int returned;
int unsynced;
int headerbytes;
int bodybytes;
} ogg_sync_state;
/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
/*
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);
/* extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits); */
extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r);
extern long oggpack_look_full(oggpack_buffer *b,int bits);
extern long oggpack_read(oggpack_buffer *b,register int bits);
//extern long oggpack_look(oggpack_buffer *b,int bits);
static inline long oggpack_look(oggpack_buffer *b,int bits){
unsigned long ret;
unsigned long m;
/* Inline a few, often called functions */
if(bits<0 || bits>32) return -1;
m=mask[bits];
bits+=b->endbit;
/* mark read process as having run off the end */
static inline void _adv_halt(oggpack_buffer *b){
b->headptr=b->head->buffer->data+b->head->begin+b->head->length;
b->headend=-1;
b->headbit=0;
}
/* spans forward, skipping as many bytes as headend is negative; if
headend is zero, simply finds next byte. If we're up to the end
of the buffer, leaves headend at zero. If we've read past the end,
halt the decode process. */
static inline void _span(oggpack_buffer *b){
while(b->headend<1){
if(b->head->next){
b->count+=b->head->length;
b->head=b->head->next;
b->headptr=b->head->buffer->data+b->head->begin-b->headend;
b->headend+=b->head->length;
}else{
/* we've either met the end of decode, or gone past it. halt
only if we're past */
if(b->headend<0 || b->headbit)
/* read has fallen off the end */
_adv_halt(b);
break;
}
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);
}
}
/* limited to 32 at a time */
static inline void oggpack_adv(oggpack_buffer *b,int bits){
bits+=b->headbit;
b->headbit=bits&7;
b->headptr+=bits/8;
if((b->headend-=((unsigned)bits)/8)<1)_span(b);
}
static inline long oggpack_look(oggpack_buffer *b, int bits){
if(bits+b->headbit < b->headend<<3){
extern const unsigned long oggpack_mask[];
unsigned long m=oggpack_mask[bits];
unsigned long ret=-1;
bits+=b->headbit;
ret=b->headptr[0]>>b->headbit;
if(bits>8){
ret|=b->headptr[1]<<(8-b->headbit);
if(bits>16){
ret|=b->headptr[2]<<(16-b->headbit);
if(bits>24){
ret|=b->headptr[3]<<(24-b->headbit);
if(bits>32 && b->headbit)
ret|=b->headptr[4]<<(32-b->headbit);
}
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);
}
}
return ret&m;
}else{
return oggpack_look_full(b, bits);
}
return(m&ret);
}
extern long oggpack_look1(oggpack_buffer *b);
//extern void oggpack_adv(oggpack_buffer *b,int bits);
static inline void oggpack_adv(oggpack_buffer *b,int bits){
bits+=b->endbit;
if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
b->ptr+=bits/8;
b->endbyte+=bits/8;
b->endbit=bits&7;
return;
overflow:
b->ptr=NULL;
b->endbyte=b->storage;
b->endbit=1;
}
extern void oggpack_adv1(oggpack_buffer *b);
extern long oggpack_read(oggpack_buffer *b,int bits);
extern long oggpack_read1(oggpack_buffer *b);
#if 0
extern long oggpack_bytes(oggpack_buffer *b);
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
/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
extern ogg_sync_state *ogg_sync_create(void);
extern int ogg_sync_destroy(ogg_sync_state *oy);
extern int ogg_sync_init(ogg_sync_state *oy);
extern int ogg_sync_clear(ogg_sync_state *oy);
extern int ogg_sync_reset(ogg_sync_state *oy);
extern int ogg_sync_destroy(ogg_sync_state *oy);
extern int ogg_sync_check(ogg_sync_state *oy);
extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size);
extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
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 ***************************/
extern ogg_stream_state *ogg_stream_create(int serialno);
extern int ogg_stream_destroy(ogg_stream_state *os);
extern int ogg_stream_init(ogg_stream_state *os,int serialno);
extern int ogg_stream_clear(ogg_stream_state *os);
extern int ogg_stream_reset(ogg_stream_state *os);
extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
extern int ogg_stream_destroy(ogg_stream_state *os);
extern int ogg_stream_check(ogg_stream_state *os);
extern int ogg_stream_eos(ogg_stream_state *os);
extern int ogg_page_checksum_set(ogg_page *og);
extern void ogg_page_checksum_set(ogg_page *og);
extern int ogg_page_version(ogg_page *og);
extern int ogg_page_continued(ogg_page *og);
extern int ogg_page_bos(ogg_page *og);
extern int ogg_page_eos(ogg_page *og);
extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
extern int ogg_page_version(const ogg_page *og);
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);
extern long ogg_page_pageno(const ogg_page *og);
extern int ogg_page_packets(const ogg_page *og);
extern int ogg_packet_release(ogg_packet *op);
extern int ogg_page_release(ogg_page *og);
extern void ogg_page_dup(ogg_page *d, ogg_page *s);
/* Ogg BITSTREAM PRIMITIVES: return codes ***************************/
#define OGG_SUCCESS 0
#define OGG_HOLE -10
#define OGG_SPAN -11
#define OGG_EVERSION -12
#define OGG_ESERIAL -13
#define OGG_EINVAL -14
#define OGG_EEOS -15
extern void ogg_packet_clear(ogg_packet *op);
#ifdef __cplusplus

View file

@ -37,7 +37,7 @@ static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep
/* first things first. Make sure decode is ready */
_vorbis_block_ripcord(vb);
oggpack_readinit(opb,op->packet);
oggpack_readinit(opb,op->packet,op->bytes);
/* Check the packet type */
if(oggpack_read(opb,1)!=0){
@ -102,6 +102,8 @@ int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
return _vorbis_synthesis1(vb,op,1);
}
/* used to track pcm position without actually performing decode.
Useful for sequential 'fast forward' */
int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
return _vorbis_synthesis1(vb,op,0);
}
@ -111,7 +113,7 @@ long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
oggpack_buffer opb;
int mode;
oggpack_readinit(&opb,op->packet);
oggpack_readinit(&opb,op->packet,op->bytes);
/* Check the packet type */
if(oggpack_read(&opb,1)!=0){

File diff suppressed because it is too large Load diff