parent
af41d7bffa
commit
a04be3e44b
|
@ -5,13 +5,13 @@
|
||||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||||
* *
|
* *
|
||||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 *
|
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2014 *
|
||||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||||
* *
|
* *
|
||||||
********************************************************************
|
********************************************************************
|
||||||
|
|
||||||
function: packing variable sized words into an octet stream
|
function: packing variable sized words into an octet stream
|
||||||
last mod: $Id: bitwise.c 17287 2010-06-10 13:42:06Z tterribe $
|
last mod: $Id: bitwise.c 19149 2014-05-27 16:26:23Z giles $
|
||||||
|
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
|
@ -187,8 +187,22 @@ static void oggpack_writecopy_helper(oggpack_buffer *b,
|
||||||
unsigned char *ptr=(unsigned char *)source;
|
unsigned char *ptr=(unsigned char *)source;
|
||||||
|
|
||||||
long bytes=bits/8;
|
long bytes=bits/8;
|
||||||
|
long pbytes=(b->endbit+bits)/8;
|
||||||
bits-=bytes*8;
|
bits-=bytes*8;
|
||||||
|
|
||||||
|
/* expand storage up-front */
|
||||||
|
if(b->endbyte+pbytes>=b->storage){
|
||||||
|
void *ret;
|
||||||
|
if(!b->ptr) goto err;
|
||||||
|
if(b->storage>b->endbyte+pbytes+BUFFER_INCREMENT) goto err;
|
||||||
|
b->storage=b->endbyte+pbytes+BUFFER_INCREMENT;
|
||||||
|
ret=_ogg_realloc(b->buffer,b->storage);
|
||||||
|
if(!ret) goto err;
|
||||||
|
b->buffer=ret;
|
||||||
|
b->ptr=b->buffer+b->endbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* copy whole octets */
|
||||||
if(b->endbit){
|
if(b->endbit){
|
||||||
int i;
|
int i;
|
||||||
/* unaligned copy. Do it the hard way. */
|
/* unaligned copy. Do it the hard way. */
|
||||||
|
@ -196,23 +210,13 @@ static void oggpack_writecopy_helper(oggpack_buffer *b,
|
||||||
w(b,(unsigned long)(ptr[i]),8);
|
w(b,(unsigned long)(ptr[i]),8);
|
||||||
}else{
|
}else{
|
||||||
/* aligned block copy */
|
/* aligned block copy */
|
||||||
if(b->endbyte+bytes+1>=b->storage){
|
|
||||||
void *ret;
|
|
||||||
if(!b->ptr) goto err;
|
|
||||||
if(b->endbyte+bytes+BUFFER_INCREMENT>b->storage) goto err;
|
|
||||||
b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
|
|
||||||
ret=_ogg_realloc(b->buffer,b->storage);
|
|
||||||
if(!ret) goto err;
|
|
||||||
b->buffer=ret;
|
|
||||||
b->ptr=b->buffer+b->endbyte;
|
|
||||||
}
|
|
||||||
|
|
||||||
memmove(b->ptr,source,bytes);
|
memmove(b->ptr,source,bytes);
|
||||||
b->ptr+=bytes;
|
b->ptr+=bytes;
|
||||||
b->endbyte+=bytes;
|
b->endbyte+=bytes;
|
||||||
*b->ptr=0;
|
*b->ptr=0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy trailing bits */
|
||||||
if(bits){
|
if(bits){
|
||||||
if(msb)
|
if(msb)
|
||||||
w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
|
w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
|
||||||
|
@ -613,9 +617,190 @@ void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
|
||||||
if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
|
if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void copytest(int prefill, int copy){
|
||||||
|
oggpack_buffer source_write;
|
||||||
|
oggpack_buffer dest_write;
|
||||||
|
oggpack_buffer source_read;
|
||||||
|
oggpack_buffer dest_read;
|
||||||
|
unsigned char *source;
|
||||||
|
unsigned char *dest;
|
||||||
|
long source_bytes,dest_bytes;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
oggpack_writeinit(&source_write);
|
||||||
|
oggpack_writeinit(&dest_write);
|
||||||
|
|
||||||
|
for(i=0;i<(prefill+copy+7)/8;i++)
|
||||||
|
oggpack_write(&source_write,(i^0x5a)&0xff,8);
|
||||||
|
source=oggpack_get_buffer(&source_write);
|
||||||
|
source_bytes=oggpack_bytes(&source_write);
|
||||||
|
|
||||||
|
/* prefill */
|
||||||
|
oggpack_writecopy(&dest_write,source,prefill);
|
||||||
|
|
||||||
|
/* check buffers; verify end byte masking */
|
||||||
|
dest=oggpack_get_buffer(&dest_write);
|
||||||
|
dest_bytes=oggpack_bytes(&dest_write);
|
||||||
|
if(dest_bytes!=(prefill+7)/8){
|
||||||
|
fprintf(stderr,"wrong number of bytes after prefill! %ld!=%d\n",dest_bytes,(prefill+7)/8);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
oggpack_readinit(&source_read,source,source_bytes);
|
||||||
|
oggpack_readinit(&dest_read,dest,dest_bytes);
|
||||||
|
|
||||||
|
for(i=0;i<prefill;i+=8){
|
||||||
|
int s=oggpack_read(&source_read,prefill-i<8?prefill-i:8);
|
||||||
|
int d=oggpack_read(&dest_read,prefill-i<8?prefill-i:8);
|
||||||
|
if(s!=d){
|
||||||
|
fprintf(stderr,"prefill=%d mismatch! byte %d, %x!=%x\n",prefill,i/8,s,d);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(prefill<dest_bytes){
|
||||||
|
if(oggpack_read(&dest_read,dest_bytes-prefill)!=0){
|
||||||
|
fprintf(stderr,"prefill=%d mismatch! trailing bits not zero\n",prefill);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* second copy */
|
||||||
|
oggpack_writecopy(&dest_write,source,copy);
|
||||||
|
|
||||||
|
/* check buffers; verify end byte masking */
|
||||||
|
dest=oggpack_get_buffer(&dest_write);
|
||||||
|
dest_bytes=oggpack_bytes(&dest_write);
|
||||||
|
if(dest_bytes!=(copy+prefill+7)/8){
|
||||||
|
fprintf(stderr,"wrong number of bytes after prefill+copy! %ld!=%d\n",dest_bytes,(copy+prefill+7)/8);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
oggpack_readinit(&source_read,source,source_bytes);
|
||||||
|
oggpack_readinit(&dest_read,dest,dest_bytes);
|
||||||
|
|
||||||
|
for(i=0;i<prefill;i+=8){
|
||||||
|
int s=oggpack_read(&source_read,prefill-i<8?prefill-i:8);
|
||||||
|
int d=oggpack_read(&dest_read,prefill-i<8?prefill-i:8);
|
||||||
|
if(s!=d){
|
||||||
|
fprintf(stderr,"prefill=%d mismatch! byte %d, %x!=%x\n",prefill,i/8,s,d);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oggpack_readinit(&source_read,source,source_bytes);
|
||||||
|
for(i=0;i<copy;i+=8){
|
||||||
|
int s=oggpack_read(&source_read,copy-i<8?copy-i:8);
|
||||||
|
int d=oggpack_read(&dest_read,copy-i<8?copy-i:8);
|
||||||
|
if(s!=d){
|
||||||
|
fprintf(stderr,"prefill=%d copy=%d mismatch! byte %d, %x!=%x\n",prefill,copy,i/8,s,d);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(copy+prefill<dest_bytes){
|
||||||
|
if(oggpack_read(&dest_read,dest_bytes-copy-prefill)!=0){
|
||||||
|
fprintf(stderr,"prefill=%d copy=%d mismatch! trailing bits not zero\n",prefill,copy);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oggpack_writeclear(&source_write);
|
||||||
|
oggpack_writeclear(&dest_write);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void copytestB(int prefill, int copy){
|
||||||
|
oggpack_buffer source_write;
|
||||||
|
oggpack_buffer dest_write;
|
||||||
|
oggpack_buffer source_read;
|
||||||
|
oggpack_buffer dest_read;
|
||||||
|
unsigned char *source;
|
||||||
|
unsigned char *dest;
|
||||||
|
long source_bytes,dest_bytes;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
oggpackB_writeinit(&source_write);
|
||||||
|
oggpackB_writeinit(&dest_write);
|
||||||
|
|
||||||
|
for(i=0;i<(prefill+copy+7)/8;i++)
|
||||||
|
oggpackB_write(&source_write,(i^0x5a)&0xff,8);
|
||||||
|
source=oggpackB_get_buffer(&source_write);
|
||||||
|
source_bytes=oggpackB_bytes(&source_write);
|
||||||
|
|
||||||
|
/* prefill */
|
||||||
|
oggpackB_writecopy(&dest_write,source,prefill);
|
||||||
|
|
||||||
|
/* check buffers; verify end byte masking */
|
||||||
|
dest=oggpackB_get_buffer(&dest_write);
|
||||||
|
dest_bytes=oggpackB_bytes(&dest_write);
|
||||||
|
if(dest_bytes!=(prefill+7)/8){
|
||||||
|
fprintf(stderr,"wrong number of bytes after prefill! %ld!=%d\n",dest_bytes,(prefill+7)/8);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
oggpackB_readinit(&source_read,source,source_bytes);
|
||||||
|
oggpackB_readinit(&dest_read,dest,dest_bytes);
|
||||||
|
|
||||||
|
for(i=0;i<prefill;i+=8){
|
||||||
|
int s=oggpackB_read(&source_read,prefill-i<8?prefill-i:8);
|
||||||
|
int d=oggpackB_read(&dest_read,prefill-i<8?prefill-i:8);
|
||||||
|
if(s!=d){
|
||||||
|
fprintf(stderr,"prefill=%d mismatch! byte %d, %x!=%x\n",prefill,i/8,s,d);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(prefill<dest_bytes){
|
||||||
|
if(oggpackB_read(&dest_read,dest_bytes-prefill)!=0){
|
||||||
|
fprintf(stderr,"prefill=%d mismatch! trailing bits not zero\n",prefill);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* second copy */
|
||||||
|
oggpackB_writecopy(&dest_write,source,copy);
|
||||||
|
|
||||||
|
/* check buffers; verify end byte masking */
|
||||||
|
dest=oggpackB_get_buffer(&dest_write);
|
||||||
|
dest_bytes=oggpackB_bytes(&dest_write);
|
||||||
|
if(dest_bytes!=(copy+prefill+7)/8){
|
||||||
|
fprintf(stderr,"wrong number of bytes after prefill+copy! %ld!=%d\n",dest_bytes,(copy+prefill+7)/8);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
oggpackB_readinit(&source_read,source,source_bytes);
|
||||||
|
oggpackB_readinit(&dest_read,dest,dest_bytes);
|
||||||
|
|
||||||
|
for(i=0;i<prefill;i+=8){
|
||||||
|
int s=oggpackB_read(&source_read,prefill-i<8?prefill-i:8);
|
||||||
|
int d=oggpackB_read(&dest_read,prefill-i<8?prefill-i:8);
|
||||||
|
if(s!=d){
|
||||||
|
fprintf(stderr,"prefill=%d mismatch! byte %d, %x!=%x\n",prefill,i/8,s,d);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oggpackB_readinit(&source_read,source,source_bytes);
|
||||||
|
for(i=0;i<copy;i+=8){
|
||||||
|
int s=oggpackB_read(&source_read,copy-i<8?copy-i:8);
|
||||||
|
int d=oggpackB_read(&dest_read,copy-i<8?copy-i:8);
|
||||||
|
if(s!=d){
|
||||||
|
fprintf(stderr,"prefill=%d copy=%d mismatch! byte %d, %x!=%x\n",prefill,copy,i/8,s,d);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(copy+prefill<dest_bytes){
|
||||||
|
if(oggpackB_read(&dest_read,dest_bytes-copy-prefill)!=0){
|
||||||
|
fprintf(stderr,"prefill=%d copy=%d mismatch! trailing bits not zero\n",prefill,copy);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oggpackB_writeclear(&source_write);
|
||||||
|
oggpackB_writeclear(&dest_write);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
long bytes,i;
|
long bytes,i,j;
|
||||||
static unsigned long testbuffer1[]=
|
static unsigned long testbuffer1[]=
|
||||||
{18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
|
{18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
|
||||||
567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
|
567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
|
||||||
|
@ -761,7 +946,31 @@ int main(void){
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
oggpack_writeclear(&o);
|
oggpack_writeclear(&o);
|
||||||
fprintf(stderr,"ok.\n");
|
fprintf(stderr,"ok.");
|
||||||
|
|
||||||
|
/* this is partly glassbox; we're mostly concerned about the allocation boundaries */
|
||||||
|
|
||||||
|
fprintf(stderr,"\nTesting aligned writecopies (LSb): ");
|
||||||
|
for(i=0;i<71;i++)
|
||||||
|
for(j=0;j<5;j++)
|
||||||
|
copytest(j*8,i);
|
||||||
|
for(i=BUFFER_INCREMENT*8-71;i<BUFFER_INCREMENT*8+71;i++)
|
||||||
|
for(j=0;j<5;j++)
|
||||||
|
copytest(j*8,i);
|
||||||
|
fprintf(stderr,"ok. ");
|
||||||
|
|
||||||
|
fprintf(stderr,"\nTesting unaligned writecopies (LSb): ");
|
||||||
|
for(i=0;i<71;i++)
|
||||||
|
for(j=1;j<40;j++)
|
||||||
|
if(j&0x7)
|
||||||
|
copytest(j,i);
|
||||||
|
for(i=BUFFER_INCREMENT*8-71;i<BUFFER_INCREMENT*8+71;i++)
|
||||||
|
for(j=1;j<40;j++)
|
||||||
|
if(j&0x7)
|
||||||
|
copytest(j,i);
|
||||||
|
|
||||||
|
fprintf(stderr,"ok. \n");
|
||||||
|
|
||||||
|
|
||||||
/********** lazy, cut-n-paste retest with MSb packing ***********/
|
/********** lazy, cut-n-paste retest with MSb packing ***********/
|
||||||
|
|
||||||
|
@ -846,9 +1055,31 @@ int main(void){
|
||||||
fprintf(stderr,"failed; read past end without -1.\n");
|
fprintf(stderr,"failed; read past end without -1.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
fprintf(stderr,"ok.");
|
||||||
oggpackB_writeclear(&o);
|
oggpackB_writeclear(&o);
|
||||||
fprintf(stderr,"ok.\n\n");
|
|
||||||
|
|
||||||
|
/* this is partly glassbox; we're mostly concerned about the allocation boundaries */
|
||||||
|
|
||||||
|
fprintf(stderr,"\nTesting aligned writecopies (MSb): ");
|
||||||
|
for(i=0;i<71;i++)
|
||||||
|
for(j=0;j<5;j++)
|
||||||
|
copytestB(j*8,i);
|
||||||
|
for(i=BUFFER_INCREMENT*8-71;i<BUFFER_INCREMENT*8+71;i++)
|
||||||
|
for(j=0;j<5;j++)
|
||||||
|
copytestB(j*8,i);
|
||||||
|
fprintf(stderr,"ok. ");
|
||||||
|
|
||||||
|
fprintf(stderr,"\nTesting unaligned writecopies (MSb): ");
|
||||||
|
for(i=0;i<71;i++)
|
||||||
|
for(j=1;j<40;j++)
|
||||||
|
if(j&0x7)
|
||||||
|
copytestB(j,i);
|
||||||
|
for(i=BUFFER_INCREMENT*8-71;i<BUFFER_INCREMENT*8+71;i++)
|
||||||
|
for(j=1;j<40;j++)
|
||||||
|
if(j&0x7)
|
||||||
|
copytestB(j,i);
|
||||||
|
|
||||||
|
fprintf(stderr,"ok. \n\n");
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
function: code raw packets into framed OggSquish stream and
|
function: code raw packets into framed OggSquish stream and
|
||||||
decode Ogg streams back into raw packets
|
decode Ogg streams back into raw packets
|
||||||
last mod: $Id: framing.c 17592 2010-11-01 20:27:54Z xiphmont $
|
last mod: $Id: framing.c 18758 2013-01-08 16:29:56Z tterribe $
|
||||||
|
|
||||||
note: The CRC code is directly derived from public domain code by
|
note: The CRC code is directly derived from public domain code by
|
||||||
Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
|
Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ogg/ogg.h>
|
#include <ogg/ogg.h>
|
||||||
|
|
||||||
|
@ -76,16 +77,16 @@ long ogg_page_pageno(const ogg_page *og){
|
||||||
page, it's counted */
|
page, it's counted */
|
||||||
|
|
||||||
/* NOTE:
|
/* NOTE:
|
||||||
If a page consists of a packet begun on a previous page, and a new
|
If a page consists of a packet begun on a previous page, and a new
|
||||||
packet begun (but not completed) on this page, the return will be:
|
packet begun (but not completed) on this page, the return will be:
|
||||||
ogg_page_packets(page) ==1,
|
ogg_page_packets(page) ==1,
|
||||||
ogg_page_continued(page) !=0
|
ogg_page_continued(page) !=0
|
||||||
|
|
||||||
If a page happens to be a single packet that was begun on a
|
If a page happens to be a single packet that was begun on a
|
||||||
previous page, and spans to the next page (in the case of a three or
|
previous page, and spans to the next page (in the case of a three or
|
||||||
more page packet), the return will be:
|
more page packet), the return will be:
|
||||||
ogg_page_packets(page) ==0,
|
ogg_page_packets(page) ==0,
|
||||||
ogg_page_continued(page) !=0
|
ogg_page_continued(page) !=0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ogg_page_packets(const ogg_page *og){
|
int ogg_page_packets(const ogg_page *og){
|
||||||
|
@ -236,39 +237,51 @@ int ogg_stream_destroy(ogg_stream_state *os){
|
||||||
/* Helpers for ogg_stream_encode; this keeps the structure and
|
/* Helpers for ogg_stream_encode; this keeps the structure and
|
||||||
what's happening fairly clear */
|
what's happening fairly clear */
|
||||||
|
|
||||||
static int _os_body_expand(ogg_stream_state *os,int needed){
|
static int _os_body_expand(ogg_stream_state *os,long needed){
|
||||||
if(os->body_storage<=os->body_fill+needed){
|
if(os->body_storage-needed<=os->body_fill){
|
||||||
|
long body_storage;
|
||||||
void *ret;
|
void *ret;
|
||||||
ret=_ogg_realloc(os->body_data,(os->body_storage+needed+1024)*
|
if(os->body_storage>LONG_MAX-needed){
|
||||||
sizeof(*os->body_data));
|
ogg_stream_clear(os);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
body_storage=os->body_storage+needed;
|
||||||
|
if(body_storage<LONG_MAX-1024)body_storage+=1024;
|
||||||
|
ret=_ogg_realloc(os->body_data,body_storage*sizeof(*os->body_data));
|
||||||
if(!ret){
|
if(!ret){
|
||||||
ogg_stream_clear(os);
|
ogg_stream_clear(os);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
os->body_storage+=(needed+1024);
|
os->body_storage=body_storage;
|
||||||
os->body_data=ret;
|
os->body_data=ret;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _os_lacing_expand(ogg_stream_state *os,int needed){
|
static int _os_lacing_expand(ogg_stream_state *os,long needed){
|
||||||
if(os->lacing_storage<=os->lacing_fill+needed){
|
if(os->lacing_storage-needed<=os->lacing_fill){
|
||||||
|
long lacing_storage;
|
||||||
void *ret;
|
void *ret;
|
||||||
ret=_ogg_realloc(os->lacing_vals,(os->lacing_storage+needed+32)*
|
if(os->lacing_storage>LONG_MAX-needed){
|
||||||
sizeof(*os->lacing_vals));
|
ogg_stream_clear(os);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
lacing_storage=os->lacing_storage+needed;
|
||||||
|
if(lacing_storage<LONG_MAX-32)lacing_storage+=32;
|
||||||
|
ret=_ogg_realloc(os->lacing_vals,lacing_storage*sizeof(*os->lacing_vals));
|
||||||
if(!ret){
|
if(!ret){
|
||||||
ogg_stream_clear(os);
|
ogg_stream_clear(os);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
os->lacing_vals=ret;
|
os->lacing_vals=ret;
|
||||||
ret=_ogg_realloc(os->granule_vals,(os->lacing_storage+needed+32)*
|
ret=_ogg_realloc(os->granule_vals,lacing_storage*
|
||||||
sizeof(*os->granule_vals));
|
sizeof(*os->granule_vals));
|
||||||
if(!ret){
|
if(!ret){
|
||||||
ogg_stream_clear(os);
|
ogg_stream_clear(os);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
os->granule_vals=ret;
|
os->granule_vals=ret;
|
||||||
os->lacing_storage+=(needed+32);
|
os->lacing_storage=lacing_storage;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -304,12 +317,17 @@ void ogg_page_checksum_set(ogg_page *og){
|
||||||
int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count,
|
int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count,
|
||||||
long e_o_s, ogg_int64_t granulepos){
|
long e_o_s, ogg_int64_t granulepos){
|
||||||
|
|
||||||
int bytes = 0, lacing_vals, i;
|
long bytes = 0, lacing_vals;
|
||||||
|
int i;
|
||||||
|
|
||||||
if(ogg_stream_check(os)) return -1;
|
if(ogg_stream_check(os)) return -1;
|
||||||
if(!iov) return 0;
|
if(!iov) return 0;
|
||||||
|
|
||||||
for (i = 0; i < count; ++i) bytes += (int)iov[i].iov_len;
|
for (i = 0; i < count; ++i){
|
||||||
|
if(iov[i].iov_len>LONG_MAX) return -1;
|
||||||
|
if(bytes>LONG_MAX-(long)iov[i].iov_len) return -1;
|
||||||
|
bytes += (long)iov[i].iov_len;
|
||||||
|
}
|
||||||
lacing_vals=bytes/255+1;
|
lacing_vals=bytes/255+1;
|
||||||
|
|
||||||
if(os->body_returned){
|
if(os->body_returned){
|
||||||
|
@ -512,12 +530,20 @@ static int ogg_stream_flush_i(ogg_stream_state *os,ogg_page *og, int force, int
|
||||||
since ogg_stream_flush will flush the last page in a stream even if
|
since ogg_stream_flush will flush the last page in a stream even if
|
||||||
it's undersized, you almost certainly want to use ogg_stream_pageout
|
it's undersized, you almost certainly want to use ogg_stream_pageout
|
||||||
(and *not* ogg_stream_flush) unless you specifically need to flush
|
(and *not* ogg_stream_flush) unless you specifically need to flush
|
||||||
an page regardless of size in the middle of a stream. */
|
a page regardless of size in the middle of a stream. */
|
||||||
|
|
||||||
int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
|
int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
|
||||||
return ogg_stream_flush_i(os,og,1,4096);
|
return ogg_stream_flush_i(os,og,1,4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Like the above, but an argument is provided to adjust the nominal
|
||||||
|
page size for applications which are smart enough to provide their
|
||||||
|
own delay based flushing */
|
||||||
|
|
||||||
|
int ogg_stream_flush_fill(ogg_stream_state *os,ogg_page *og, int nfill){
|
||||||
|
return ogg_stream_flush_i(os,og,1,nfill);
|
||||||
|
}
|
||||||
|
|
||||||
/* This constructs pages from buffered packet segments. The pointers
|
/* This constructs pages from buffered packet segments. The pointers
|
||||||
returned are to static buffers; do not free. The returned buffers are
|
returned are to static buffers; do not free. The returned buffers are
|
||||||
good only until the next call (using the same ogg_stream_state) */
|
good only until the next call (using the same ogg_stream_state) */
|
||||||
|
@ -2083,7 +2109,3 @@ int main(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
********************************************************************
|
********************************************************************
|
||||||
|
|
||||||
function: toplevel libogg include
|
function: toplevel libogg include
|
||||||
last mod: $Id: ogg.h 17571 2010-10-27 13:28:20Z xiphmont $
|
last mod: $Id: ogg.h 18044 2011-08-01 17:55:20Z gmaxwell $
|
||||||
|
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
#ifndef _OGG_H
|
#ifndef _OGG_H
|
||||||
|
@ -161,6 +161,7 @@ extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
|
||||||
extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
|
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_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill);
|
||||||
extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
|
extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
|
||||||
|
extern int ogg_stream_flush_fill(ogg_stream_state *os, ogg_page *og, int nfill);
|
||||||
|
|
||||||
/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
|
/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
********************************************************************
|
********************************************************************
|
||||||
|
|
||||||
function: #ifdef jail to whip a few platforms into the UNIX ideal.
|
function: #ifdef jail to whip a few platforms into the UNIX ideal.
|
||||||
last mod: $Id: os_types.h 17712 2010-12-03 17:10:02Z xiphmont $
|
last mod: $Id: os_types.h 19098 2014-02-26 19:06:45Z giles $
|
||||||
|
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
#ifndef _OS_TYPES_H
|
#ifndef _OS_TYPES_H
|
||||||
|
|
Loading…
Reference in New Issue