зеркало из https://github.com/mozilla/gecko-dev.git
Bug 468296 - Update libogg to SVN r16911. r=chris.double
This commit is contained in:
Родитель
3983e1190a
Коммит
975e8199ff
|
@ -1,3 +1,12 @@
|
|||
Version 1.1.4 (2009 June 24)
|
||||
|
||||
* New async error reporting mechanism. Calls made after a fatal error are
|
||||
now safely handled in the event an error code is ignored
|
||||
* Added allocation checks useful to some embedded applications
|
||||
* fix possible read past end of buffer when reading 0 bits
|
||||
* Updates to API documentation
|
||||
* Build fixes
|
||||
|
||||
Version 1.1.3 (2005 November 27)
|
||||
|
||||
* Correct a bug in the granulepos field of pages where no packet ends
|
||||
|
|
|
@ -23,13 +23,16 @@ Directory:
|
|||
|
||||
./include Library API headers and codebooks
|
||||
|
||||
./debian Rules/spec files for building Debian .deb packages
|
||||
|
||||
./doc Ogg specification documents
|
||||
|
||||
./win32 Win32 projects and build automation
|
||||
|
||||
./mac MacOS 9 projects and build automation
|
||||
./macosx MacOS X project and build files
|
||||
|
||||
./macos Classic MacOS 9 projects and build automation
|
||||
|
||||
./debian Rules/spec files for building Debian .deb packages
|
||||
(may not be present, depending on your distribution)
|
||||
|
||||
WHAT IS OGG?:
|
||||
|
||||
|
@ -82,6 +85,33 @@ You can also run one of the batch files from the commandline.
|
|||
|
||||
E.g.: build_ogg_dynamic
|
||||
|
||||
CROSS COMPILING FROM LINUX TO WIN32:
|
||||
|
||||
It is also possible to cross compile from Linux to windows using the MinGW
|
||||
cross tools and even to run the test suite under Wine, the Linux/*nix
|
||||
windows emulator.
|
||||
|
||||
On Debian and Ubuntu systems, these cross compiler tools can be installed
|
||||
by doing:
|
||||
|
||||
sudo apt-get mingw32 mingw32-binutils mingw32-runtime wine
|
||||
|
||||
Once these tools are installed its possible to compile and test by
|
||||
executing the following commands:
|
||||
|
||||
./configure --host=i586-mingw32msvc --target=i586-mingw32msvc \
|
||||
--build=i586-linux
|
||||
make
|
||||
make check
|
||||
|
||||
The above has been tested with the following versions of the tools on
|
||||
Ubuntu's Hardy Heron release:
|
||||
|
||||
mingw32 4.2.1.dfsg-1ubuntu1
|
||||
mingw32-binutils 2.17.50-20070129.1-1
|
||||
mingw32-runtime 3.13-1
|
||||
wine 0.9.59-0ubuntu4
|
||||
|
||||
BUILDING ON MACOS 9:
|
||||
|
||||
Ogg on MacOS 9 is built using CodeWarrior 5.3. To build it, first
|
||||
|
@ -100,4 +130,4 @@ and #include "ogg/ogg.h" wherever you need to acces Ogg functionality.
|
|||
(Build instructions for Ogg codecs such as vorbis are similar and may
|
||||
be found in those source modules' README files)
|
||||
|
||||
$Id: README 10478 2005-11-28 04:23:35Z giles $
|
||||
$Id: README 14726 2008-04-14 08:40:46Z erikd $
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
The source from this directory was copied from the libogg-1.1.3 source
|
||||
distribution using the update.sh script. The only changes made were
|
||||
The source from this directory was copied from the libogg subversion
|
||||
repository using the update.sh script. The only changes made were
|
||||
those applied by update.sh and the addition/upate of Makefile.in files
|
||||
for the Mozilla build system.
|
||||
|
||||
The svn revision number used was r16911.
|
||||
|
||||
The int-types.patch address a bug that config_types.h generated from
|
||||
Linux platform can't be used on OpenSolaris directly see Mozilla bug
|
||||
449754
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: toplevel libogg include
|
||||
last mod: $Id: ogg.h 7188 2004-07-20 07:26:04Z xiphmont $
|
||||
last mod: $Id: ogg.h 16051 2009-05-27 05:00:06Z xiphmont $
|
||||
|
||||
********************************************************************/
|
||||
#ifndef _OGG_H
|
||||
|
@ -21,8 +21,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <ogg/os_types.h>
|
||||
|
||||
typedef struct {
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
} ogg_iovec_t;
|
||||
|
||||
typedef struct {
|
||||
long endbyte;
|
||||
int endbit;
|
||||
|
@ -110,6 +116,7 @@ typedef struct {
|
|||
/* 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);
|
||||
|
@ -128,6 +135,7 @@ 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);
|
||||
|
@ -148,6 +156,8 @@ extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
|
|||
/* Ogg BITSTREAM PRIMITIVES: encoding **************************/
|
||||
|
||||
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_flush(ogg_stream_state *os, ogg_page *og);
|
||||
|
||||
|
@ -157,6 +167,7 @@ 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 char *ogg_sync_buffer(ogg_sync_state *oy, long size);
|
||||
extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
|
||||
|
@ -173,18 +184,19 @@ 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 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 int ogg_page_serialno(ogg_page *og);
|
||||
extern long ogg_page_pageno(ogg_page *og);
|
||||
extern int ogg_page_packets(ogg_page *og);
|
||||
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 int 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 void ogg_packet_clear(ogg_packet *op);
|
||||
|
||||
|
@ -194,9 +206,3 @@ extern void ogg_packet_clear(ogg_packet *op);
|
|||
#endif
|
||||
|
||||
#endif /* _OGG_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
********************************************************************
|
||||
|
||||
function: #ifdef jail to whip a few platforms into the UNIX ideal.
|
||||
last mod: $Id: os_types.h 7524 2004-08-11 04:20:36Z conrad $
|
||||
last mod: $Id: os_types.h 16649 2009-10-25 00:49:58Z ds $
|
||||
|
||||
********************************************************************/
|
||||
#ifndef _OS_TYPES_H
|
||||
|
@ -27,13 +27,15 @@
|
|||
#if defined(_WIN32)
|
||||
|
||||
# if defined(__CYGWIN__)
|
||||
# include <_G_config.h>
|
||||
typedef _G_int64_t ogg_int64_t;
|
||||
typedef _G_int32_t ogg_int32_t;
|
||||
typedef _G_uint32_t ogg_uint32_t;
|
||||
typedef _G_int16_t ogg_int16_t;
|
||||
typedef _G_uint16_t ogg_uint16_t;
|
||||
# include <stdint.h>
|
||||
typedef int16_t ogg_int16_t;
|
||||
typedef uint16_t ogg_uint16_t;
|
||||
typedef int32_t ogg_int32_t;
|
||||
typedef uint32_t ogg_uint32_t;
|
||||
typedef int64_t ogg_int64_t;
|
||||
typedef uint64_t ogg_uint64_t;
|
||||
# elif defined(__MINGW32__)
|
||||
# include <sys/types.h>
|
||||
typedef short ogg_int16_t;
|
||||
typedef unsigned short ogg_uint16_t;
|
||||
typedef int ogg_int32_t;
|
||||
|
@ -64,7 +66,7 @@
|
|||
typedef UInt32 ogg_uint32_t;
|
||||
typedef SInt64 ogg_int64_t;
|
||||
|
||||
#elif defined(__MACOSX__) /* MacOS X Framework build */
|
||||
#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */
|
||||
|
||||
# include <sys/types.h>
|
||||
typedef int16_t ogg_int16_t;
|
||||
|
@ -73,6 +75,16 @@
|
|||
typedef u_int32_t ogg_uint32_t;
|
||||
typedef int64_t ogg_int64_t;
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
/* Haiku */
|
||||
# include <sys/types.h>
|
||||
typedef short ogg_int16_t;
|
||||
typedef unsigned short ogg_uint16_t;
|
||||
typedef int ogg_int32_t;
|
||||
typedef unsigned int ogg_uint32_t;
|
||||
typedef long long ogg_int64_t;
|
||||
|
||||
#elif defined(__BEOS__)
|
||||
|
||||
/* Be */
|
||||
|
@ -117,6 +129,15 @@
|
|||
typedef unsigned int ogg_uint32_t;
|
||||
typedef long long int ogg_int64_t;
|
||||
|
||||
#elif defined(__TMS320C6X__)
|
||||
|
||||
/* TI C64x compiler */
|
||||
typedef signed short ogg_int16_t;
|
||||
typedef unsigned short ogg_uint16_t;
|
||||
typedef signed int ogg_int32_t;
|
||||
typedef unsigned int ogg_uint32_t;
|
||||
typedef long long int ogg_int64_t;
|
||||
|
||||
#else
|
||||
|
||||
# include <sys/types.h>
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: packing variable sized words into an octet stream
|
||||
last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $
|
||||
last mod: $Id: bitwise.c 16051 2009-05-27 05:00:06Z xiphmont $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
|
@ -47,28 +47,48 @@ void oggpackB_writeinit(oggpack_buffer *b){
|
|||
oggpack_writeinit(b);
|
||||
}
|
||||
|
||||
int oggpack_writecheck(oggpack_buffer *b){
|
||||
if(!b->ptr || !b->storage)return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int oggpackB_writecheck(oggpack_buffer *b){
|
||||
return oggpack_writecheck(b);
|
||||
}
|
||||
|
||||
void oggpack_writetrunc(oggpack_buffer *b,long bits){
|
||||
long bytes=bits>>3;
|
||||
if(b->ptr){
|
||||
bits-=bytes*8;
|
||||
b->ptr=b->buffer+bytes;
|
||||
b->endbit=bits;
|
||||
b->endbyte=bytes;
|
||||
*b->ptr&=mask[bits];
|
||||
}
|
||||
}
|
||||
|
||||
void oggpackB_writetrunc(oggpack_buffer *b,long bits){
|
||||
long bytes=bits>>3;
|
||||
if(b->ptr){
|
||||
bits-=bytes*8;
|
||||
b->ptr=b->buffer+bytes;
|
||||
b->endbit=bits;
|
||||
b->endbyte=bytes;
|
||||
*b->ptr&=mask8B[bits];
|
||||
}
|
||||
}
|
||||
|
||||
/* Takes only up to 32 bits. */
|
||||
void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
|
||||
if(b->endbyte+4>=b->storage){
|
||||
b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
|
||||
void *ret;
|
||||
if(!b->ptr)return;
|
||||
ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
|
||||
if(!ret){
|
||||
oggpack_writeclear(b);
|
||||
return;
|
||||
}
|
||||
b->buffer=ret;
|
||||
b->storage+=BUFFER_INCREMENT;
|
||||
b->ptr=b->buffer+b->endbyte;
|
||||
}
|
||||
|
@ -102,7 +122,14 @@ void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
|
|||
/* Takes only up to 32 bits. */
|
||||
void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
|
||||
if(b->endbyte+4>=b->storage){
|
||||
b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
|
||||
void *ret;
|
||||
if(!b->ptr)return;
|
||||
ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
|
||||
if(!ret){
|
||||
oggpack_writeclear(b);
|
||||
return;
|
||||
}
|
||||
b->buffer=ret;
|
||||
b->storage+=BUFFER_INCREMENT;
|
||||
b->ptr=b->buffer+b->endbyte;
|
||||
}
|
||||
|
@ -165,8 +192,15 @@ static void oggpack_writecopy_helper(oggpack_buffer *b,
|
|||
}else{
|
||||
/* aligned block copy */
|
||||
if(b->endbyte+bytes+1>=b->storage){
|
||||
void *ret;
|
||||
if(!b->ptr)return;
|
||||
b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
|
||||
b->buffer=_ogg_realloc(b->buffer,b->storage);
|
||||
ret=_ogg_realloc(b->buffer,b->storage);
|
||||
if(!ret){
|
||||
oggpack_writeclear(b);
|
||||
return;
|
||||
}
|
||||
b->buffer=ret;
|
||||
b->ptr=b->buffer+b->endbyte;
|
||||
}
|
||||
|
||||
|
@ -193,6 +227,7 @@ void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
|
|||
}
|
||||
|
||||
void oggpack_reset(oggpack_buffer *b){
|
||||
if(!b->ptr)return;
|
||||
b->ptr=b->buffer;
|
||||
b->buffer[0]=0;
|
||||
b->endbit=b->endbyte=0;
|
||||
|
@ -203,7 +238,7 @@ void oggpackB_reset(oggpack_buffer *b){
|
|||
}
|
||||
|
||||
void oggpack_writeclear(oggpack_buffer *b){
|
||||
_ogg_free(b->buffer);
|
||||
if(b->buffer)_ogg_free(b->buffer);
|
||||
memset(b,0,sizeof(*b));
|
||||
}
|
||||
|
||||
|
@ -355,6 +390,9 @@ long oggpackB_read(oggpack_buffer *b,int bits){
|
|||
/* not the main path */
|
||||
ret=-1L;
|
||||
if(b->endbyte*8+bits>b->storage*8)goto overflow;
|
||||
/* 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);
|
||||
}
|
||||
|
||||
ret=b->ptr[0]<<(24+b->endbit);
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: code raw [Vorbis] packets into framed OggSquish stream and
|
||||
function: code raw packets into framed OggSquish stream and
|
||||
decode Ogg streams back into raw packets
|
||||
last mod: $Id: framing.c 9601 2005-07-23 00:19:14Z giles $
|
||||
last mod: $Id: framing.c 16051 2009-05-27 05:00:06Z xiphmont $
|
||||
|
||||
note: The CRC code is directly derived from public domain code by
|
||||
Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
|
||||
|
@ -26,23 +26,23 @@
|
|||
|
||||
/* A complete description of Ogg framing exists in docs/framing.html */
|
||||
|
||||
int ogg_page_version(ogg_page *og){
|
||||
int ogg_page_version(const ogg_page *og){
|
||||
return((int)(og->header[4]));
|
||||
}
|
||||
|
||||
int ogg_page_continued(ogg_page *og){
|
||||
int ogg_page_continued(const ogg_page *og){
|
||||
return((int)(og->header[5]&0x01));
|
||||
}
|
||||
|
||||
int ogg_page_bos(ogg_page *og){
|
||||
int ogg_page_bos(const ogg_page *og){
|
||||
return((int)(og->header[5]&0x02));
|
||||
}
|
||||
|
||||
int ogg_page_eos(ogg_page *og){
|
||||
int ogg_page_eos(const ogg_page *og){
|
||||
return((int)(og->header[5]&0x04));
|
||||
}
|
||||
|
||||
ogg_int64_t ogg_page_granulepos(ogg_page *og){
|
||||
ogg_int64_t ogg_page_granulepos(const ogg_page *og){
|
||||
unsigned char *page=og->header;
|
||||
ogg_int64_t granulepos=page[13]&(0xff);
|
||||
granulepos= (granulepos<<8)|(page[12]&0xff);
|
||||
|
@ -55,14 +55,14 @@ ogg_int64_t ogg_page_granulepos(ogg_page *og){
|
|||
return(granulepos);
|
||||
}
|
||||
|
||||
int ogg_page_serialno(ogg_page *og){
|
||||
int ogg_page_serialno(const ogg_page *og){
|
||||
return(og->header[14] |
|
||||
(og->header[15]<<8) |
|
||||
(og->header[16]<<16) |
|
||||
(og->header[17]<<24));
|
||||
}
|
||||
|
||||
long ogg_page_pageno(ogg_page *og){
|
||||
long ogg_page_pageno(const ogg_page *og){
|
||||
return(og->header[18] |
|
||||
(og->header[19]<<8) |
|
||||
(og->header[20]<<16) |
|
||||
|
@ -88,7 +88,7 @@ more page packet), the return will be:
|
|||
ogg_page_continued(page) !=0
|
||||
*/
|
||||
|
||||
int ogg_page_packets(ogg_page *og){
|
||||
int ogg_page_packets(const ogg_page *og){
|
||||
int i,n=og->header[26],count=0;
|
||||
for(i=0;i<n;i++)
|
||||
if(og->header[27+i]<255)count++;
|
||||
|
@ -189,12 +189,17 @@ int ogg_stream_init(ogg_stream_state *os,int serialno){
|
|||
if(os){
|
||||
memset(os,0,sizeof(*os));
|
||||
os->body_storage=16*1024;
|
||||
os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data));
|
||||
|
||||
os->lacing_storage=1024;
|
||||
|
||||
os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data));
|
||||
os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
|
||||
os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
|
||||
|
||||
if(!os->body_data || !os->lacing_vals || !os->granule_vals){
|
||||
ogg_stream_clear(os);
|
||||
return -1;
|
||||
}
|
||||
|
||||
os->serialno=serialno;
|
||||
|
||||
return(0);
|
||||
|
@ -202,6 +207,12 @@ int ogg_stream_init(ogg_stream_state *os,int serialno){
|
|||
return(-1);
|
||||
}
|
||||
|
||||
/* async/delayed error detection for the ogg_stream_state */
|
||||
int ogg_stream_check(ogg_stream_state *os){
|
||||
if(!os || !os->body_data) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* _clear does not free os, only the non-flat storage within */
|
||||
int ogg_stream_clear(ogg_stream_state *os){
|
||||
if(os){
|
||||
|
@ -225,19 +236,41 @@ int ogg_stream_destroy(ogg_stream_state *os){
|
|||
/* Helpers for ogg_stream_encode; this keeps the structure and
|
||||
what's happening fairly clear */
|
||||
|
||||
static void _os_body_expand(ogg_stream_state *os,int needed){
|
||||
static int _os_body_expand(ogg_stream_state *os,int needed){
|
||||
if(os->body_storage<=os->body_fill+needed){
|
||||
os->body_storage+=(needed+1024);
|
||||
os->body_data=_ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
|
||||
void *ret;
|
||||
ret=_ogg_realloc(os->body_data,(os->body_storage+needed+1024)*
|
||||
sizeof(*os->body_data));
|
||||
if(!ret){
|
||||
ogg_stream_clear(os);
|
||||
return -1;
|
||||
}
|
||||
os->body_storage+=(needed+1024);
|
||||
os->body_data=ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _os_lacing_expand(ogg_stream_state *os,int needed){
|
||||
static int _os_lacing_expand(ogg_stream_state *os,int needed){
|
||||
if(os->lacing_storage<=os->lacing_fill+needed){
|
||||
os->lacing_storage+=(needed+32);
|
||||
os->lacing_vals=_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
|
||||
os->granule_vals=_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
|
||||
void *ret;
|
||||
ret=_ogg_realloc(os->lacing_vals,(os->lacing_storage+needed+32)*
|
||||
sizeof(*os->lacing_vals));
|
||||
if(!ret){
|
||||
ogg_stream_clear(os);
|
||||
return -1;
|
||||
}
|
||||
os->lacing_vals=ret;
|
||||
ret=_ogg_realloc(os->granule_vals,(os->lacing_storage+needed+32)*
|
||||
sizeof(*os->granule_vals));
|
||||
if(!ret){
|
||||
ogg_stream_clear(os);
|
||||
return -1;
|
||||
}
|
||||
os->granule_vals=ret;
|
||||
os->lacing_storage+=(needed+32);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* checksum the page */
|
||||
|
@ -268,8 +301,16 @@ void ogg_page_checksum_set(ogg_page *og){
|
|||
}
|
||||
|
||||
/* submit data to the internal buffer of the framing engine */
|
||||
int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
|
||||
int lacing_vals=op->bytes/255+1,i;
|
||||
int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count,
|
||||
long e_o_s, ogg_int64_t granulepos){
|
||||
|
||||
int bytes = 0, lacing_vals, i;
|
||||
|
||||
if(ogg_stream_check(os)) return -1;
|
||||
if(!iov) return 0;
|
||||
|
||||
for (i = 0; i < count; ++i) bytes += (int)iov[i].iov_len;
|
||||
lacing_vals=bytes/255+1;
|
||||
|
||||
if(os->body_returned){
|
||||
/* advance packet data according to the body_returned pointer. We
|
||||
|
@ -284,24 +325,26 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
|
|||
}
|
||||
|
||||
/* make sure we have the buffer storage */
|
||||
_os_body_expand(os,op->bytes);
|
||||
_os_lacing_expand(os,lacing_vals);
|
||||
if(_os_body_expand(os,bytes) || _os_lacing_expand(os,lacing_vals))
|
||||
return -1;
|
||||
|
||||
/* Copy in the submitted packet. Yes, the copy is a waste; this is
|
||||
the liability of overly clean abstraction for the time being. It
|
||||
will actually be fairly easy to eliminate the extra copy in the
|
||||
future */
|
||||
|
||||
memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
|
||||
os->body_fill+=op->bytes;
|
||||
for (i = 0; i < count; ++i) {
|
||||
memcpy(os->body_data+os->body_fill, iov[i].iov_base, iov[i].iov_len);
|
||||
os->body_fill += (int)iov[i].iov_len;
|
||||
}
|
||||
|
||||
/* Store lacing vals for this packet */
|
||||
for(i=0;i<lacing_vals-1;i++){
|
||||
os->lacing_vals[os->lacing_fill+i]=255;
|
||||
os->granule_vals[os->lacing_fill+i]=os->granulepos;
|
||||
}
|
||||
os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
|
||||
os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
|
||||
os->lacing_vals[os->lacing_fill+i]=bytes%255;
|
||||
os->granulepos=os->granule_vals[os->lacing_fill+i]=granulepos;
|
||||
|
||||
/* flag the first segment as the beginning of the packet */
|
||||
os->lacing_vals[os->lacing_fill]|= 0x100;
|
||||
|
@ -311,11 +354,18 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
|
|||
/* for the sake of completeness */
|
||||
os->packetno++;
|
||||
|
||||
if(op->e_o_s)os->e_o_s=1;
|
||||
if(e_o_s)os->e_o_s=1;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
|
||||
ogg_iovec_t iov;
|
||||
iov.iov_base = op->packet;
|
||||
iov.iov_len = op->bytes;
|
||||
return ogg_stream_iovecin(os, &iov, 1, op->e_o_s, op->granulepos);
|
||||
}
|
||||
|
||||
/* This will flush remaining packets into a page (returning nonzero),
|
||||
even if there is not enough data to trigger a flush normally
|
||||
(undersized page). If there are no packets or partial packets to
|
||||
|
@ -338,7 +388,8 @@ int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
|
|||
long acc=0;
|
||||
ogg_int64_t granule_pos=-1;
|
||||
|
||||
if(maxvals==0)return(0);
|
||||
if(ogg_stream_check(os)) return 0;
|
||||
if(maxvals==0)return 0;
|
||||
|
||||
/* construct a page */
|
||||
/* decide how many segments to include */
|
||||
|
@ -445,6 +496,7 @@ returned are to static buffers; do not free. The returned buffers are
|
|||
good only until the next call (using the same ogg_stream_state) */
|
||||
|
||||
int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
|
||||
if(ogg_stream_check(os)) return 0;
|
||||
|
||||
if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
|
||||
os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
|
||||
|
@ -455,10 +507,11 @@ int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
|
|||
}
|
||||
|
||||
/* not enough data to construct a page and not end of stream */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ogg_stream_eos(ogg_stream_state *os){
|
||||
if(ogg_stream_check(os)) return 1;
|
||||
return os->e_o_s;
|
||||
}
|
||||
|
||||
|
@ -480,6 +533,7 @@ int ogg_stream_eos(ogg_stream_state *os){
|
|||
/* initialize the struct to a known state */
|
||||
int ogg_sync_init(ogg_sync_state *oy){
|
||||
if(oy){
|
||||
oy->storage = -1; /* used as a readiness flag */
|
||||
memset(oy,0,sizeof(*oy));
|
||||
}
|
||||
return(0);
|
||||
|
@ -489,7 +543,7 @@ int ogg_sync_init(ogg_sync_state *oy){
|
|||
int ogg_sync_clear(ogg_sync_state *oy){
|
||||
if(oy){
|
||||
if(oy->data)_ogg_free(oy->data);
|
||||
ogg_sync_init(oy);
|
||||
memset(oy,0,sizeof(*oy));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
@ -502,7 +556,13 @@ int ogg_sync_destroy(ogg_sync_state *oy){
|
|||
return(0);
|
||||
}
|
||||
|
||||
int ogg_sync_check(ogg_sync_state *oy){
|
||||
if(oy->storage<0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *ogg_sync_buffer(ogg_sync_state *oy, long size){
|
||||
if(ogg_sync_check(oy)) return NULL;
|
||||
|
||||
/* first, clear out any space that has been previously returned */
|
||||
if(oy->returned){
|
||||
|
@ -515,11 +575,17 @@ char *ogg_sync_buffer(ogg_sync_state *oy, long size){
|
|||
if(size>oy->storage-oy->fill){
|
||||
/* We need to extend the internal buffer */
|
||||
long newsize=size+oy->fill+4096; /* an extra page to be nice */
|
||||
void *ret;
|
||||
|
||||
if(oy->data)
|
||||
oy->data=_ogg_realloc(oy->data,newsize);
|
||||
ret=_ogg_realloc(oy->data,newsize);
|
||||
else
|
||||
oy->data=_ogg_malloc(newsize);
|
||||
ret=_ogg_malloc(newsize);
|
||||
if(!ret){
|
||||
ogg_sync_clear(oy);
|
||||
return NULL;
|
||||
}
|
||||
oy->data=ret;
|
||||
oy->storage=newsize;
|
||||
}
|
||||
|
||||
|
@ -528,7 +594,8 @@ char *ogg_sync_buffer(ogg_sync_state *oy, long size){
|
|||
}
|
||||
|
||||
int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
|
||||
if(oy->fill+bytes>oy->storage)return(-1);
|
||||
if(ogg_sync_check(oy))return -1;
|
||||
if(oy->fill+bytes>oy->storage)return -1;
|
||||
oy->fill+=bytes;
|
||||
return(0);
|
||||
}
|
||||
|
@ -548,6 +615,8 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
|
|||
unsigned char *next;
|
||||
long bytes=oy->fill-oy->returned;
|
||||
|
||||
if(ogg_sync_check(oy))return 0;
|
||||
|
||||
if(oy->headerbytes==0){
|
||||
int headerbytes,i;
|
||||
if(bytes<27)return(0); /* not enough for a header */
|
||||
|
@ -624,8 +693,8 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
|
|||
if(!next)
|
||||
next=oy->data+oy->fill;
|
||||
|
||||
oy->returned=next-oy->data;
|
||||
return(-(next-page));
|
||||
oy->returned=(int)(next-oy->data);
|
||||
return((long)-(next-page));
|
||||
}
|
||||
|
||||
/* sync the stream and get a page. Keep trying until we find a page.
|
||||
|
@ -641,6 +710,8 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
|
|||
|
||||
int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
|
||||
|
||||
if(ogg_sync_check(oy))return 0;
|
||||
|
||||
/* all we need to do is verify a page at the head of the stream
|
||||
buffer. If it doesn't verify, we look for the next potential
|
||||
frame */
|
||||
|
@ -685,6 +756,8 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
|
|||
long pageno=ogg_page_pageno(og);
|
||||
int segments=header[26];
|
||||
|
||||
if(ogg_stream_check(os)) return -1;
|
||||
|
||||
/* clean up 'returned data' */
|
||||
{
|
||||
long lr=os->lacing_returned;
|
||||
|
@ -716,7 +789,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
|
|||
if(serialno!=os->serialno)return(-1);
|
||||
if(version>0)return(-1);
|
||||
|
||||
_os_lacing_expand(os,segments+1);
|
||||
if(_os_lacing_expand(os,segments+1)) return -1;
|
||||
|
||||
/* are we in sequence? */
|
||||
if(pageno!=os->pageno){
|
||||
|
@ -753,7 +826,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
|
|||
}
|
||||
|
||||
if(bodysize){
|
||||
_os_body_expand(os,bodysize);
|
||||
if(_os_body_expand(os,bodysize)) return -1;
|
||||
memcpy(os->body_data+os->body_fill,body,bodysize);
|
||||
os->body_fill+=bodysize;
|
||||
}
|
||||
|
@ -798,6 +871,8 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
|
|||
|
||||
/* clear things to an initial state. Good to call, eg, before seeking */
|
||||
int ogg_sync_reset(ogg_sync_state *oy){
|
||||
if(ogg_sync_check(oy))return -1;
|
||||
|
||||
oy->fill=0;
|
||||
oy->returned=0;
|
||||
oy->unsynced=0;
|
||||
|
@ -807,6 +882,8 @@ int ogg_sync_reset(ogg_sync_state *oy){
|
|||
}
|
||||
|
||||
int ogg_stream_reset(ogg_stream_state *os){
|
||||
if(ogg_stream_check(os)) return -1;
|
||||
|
||||
os->body_fill=0;
|
||||
os->body_returned=0;
|
||||
|
||||
|
@ -826,6 +903,7 @@ int ogg_stream_reset(ogg_stream_state *os){
|
|||
}
|
||||
|
||||
int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
|
||||
if(ogg_stream_check(os)) return -1;
|
||||
ogg_stream_reset(os);
|
||||
os->serialno=serialno;
|
||||
return(0);
|
||||
|
@ -886,10 +964,12 @@ static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
|
|||
}
|
||||
|
||||
int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
|
||||
if(ogg_stream_check(os)) return 0;
|
||||
return _packetout(os,op,1);
|
||||
}
|
||||
|
||||
int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
|
||||
if(ogg_stream_check(os)) return 0;
|
||||
return _packetout(os,op,0);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче