summaryrefslogtreecommitdiffstats
path: root/tremor/framing.c
diff options
context:
space:
mode:
Diffstat (limited to 'tremor/framing.c')
-rw-r--r--tremor/framing.c104
1 files changed, 52 insertions, 52 deletions
diff --git a/tremor/framing.c b/tremor/framing.c
index c0f558ad26..17c28b1111 100644
--- a/tremor/framing.c
+++ b/tremor/framing.c
@@ -61,7 +61,7 @@ int ogg_page_serialno(ogg_page *og){
(og->header[16]<<16) |
(og->header[17]<<24));
}
-
+
long ogg_page_pageno(ogg_page *og){
return(og->header[18] |
(og->header[19]<<8) |
@@ -78,13 +78,13 @@ long ogg_page_pageno(ogg_page *og){
/* NOTE:
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:
- ogg_page_packets(page) ==1,
+ ogg_page_packets(page) ==1,
ogg_page_continued(page) !=0
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
-more page packet), the return will be:
- ogg_page_packets(page) ==0,
+more page packet), the return will be:
+ ogg_page_packets(page) ==0,
ogg_page_continued(page) !=0
*/
@@ -200,7 +200,7 @@ int ogg_stream_init(ogg_stream_state *os,int serialno){
return(0);
}
return(-1);
-}
+}
/* _clear does not free os, only the non-flat storage within */
int ogg_stream_clear(ogg_stream_state *os){
@@ -209,10 +209,10 @@ int ogg_stream_clear(ogg_stream_state *os){
if(os->lacing_vals)_ogg_free(os->lacing_vals);
if(os->granule_vals)_ogg_free(os->granule_vals);
- memset(os,0,sizeof(*os));
+ memset(os,0,sizeof(*os));
}
return(0);
-}
+}
int ogg_stream_destroy(ogg_stream_state *os){
if(os){
@@ -220,7 +220,7 @@ int ogg_stream_destroy(ogg_stream_state *os){
_ogg_free(os);
}
return(0);
-}
+}
/* Helpers for ogg_stream_encode; this keeps the structure and
what's happening fairly clear */
@@ -254,12 +254,12 @@ void ogg_page_checksum_set(ogg_page *og){
og->header[23]=0;
og->header[24]=0;
og->header[25]=0;
-
+
for(i=0;i<og->header_len;i++)
crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
for(i=0;i<og->body_len;i++)
crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
-
+
og->header[22]=(unsigned char)(crc_reg&0xff);
og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
@@ -275,14 +275,14 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
/* advance packet data according to the body_returned pointer. We
had to keep it around to return a pointer into the buffer last
call */
-
+
os->body_fill-=os->body_returned;
if(os->body_fill)
memmove(os->body_data,os->body_data+os->body_returned,
os->body_fill);
os->body_returned=0;
}
-
+
/* make sure we have the buffer storage */
_os_body_expand(os,op->bytes);
_os_lacing_expand(os,lacing_vals);
@@ -327,7 +327,7 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
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
- (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. */
int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
@@ -339,10 +339,10 @@ int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
ogg_int64_t granule_pos=os->granule_vals[0];
if(maxvals==0)return(0);
-
+
/* construct a page */
/* decide how many segments to include */
-
+
/* If this is the initial header case, the first page must only include
the initial header packet */
if(os->b_o_s==0){ /* 'initial header page' case */
@@ -360,13 +360,13 @@ int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
granule_pos=os->granule_vals[vals];
}
}
-
+
/* construct the header in temp storage */
memcpy(os->header,"OggS",4);
-
+
/* stream structure version */
os->header[4]=0x00;
-
+
/* continued packet flag? */
os->header[5]=0x00;
if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
@@ -405,33 +405,33 @@ int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
pageno>>=8;
}
}
-
+
/* zero for computation; filled in later */
os->header[22]=0;
os->header[23]=0;
os->header[24]=0;
os->header[25]=0;
-
+
/* segment table */
os->header[26]=(unsigned char)(vals&0xff);
for(i=0;i<vals;i++)
bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
-
+
/* set pointers in the ogg_page struct */
og->header=os->header;
og->header_len=os->header_fill=vals+27;
og->body=os->body_data+os->body_returned;
og->body_len=bytes;
-
+
/* advance the lacing data and set the body_returned pointer */
-
+
os->lacing_fill-=vals;
memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
os->body_returned+=bytes;
-
+
/* calculate the checksum */
-
+
ogg_page_checksum_set(og);
/* done */
@@ -449,10 +449,10 @@ int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
os->lacing_fill>=255 || /* 'segment table full' case */
(os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
-
+
return(ogg_stream_flush(os,og));
}
-
+
/* not enough data to construct a page and not end of stream */
return(0);
}
@@ -540,61 +540,61 @@ int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
-n) skipped n bytes
0) page not ready; more data (no bytes skipped)
n) page synced at current location; page length n bytes
-
+
*/
long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
unsigned char *page=oy->data+oy->returned;
unsigned char *next;
long bytes=oy->fill-oy->returned;
-
+
if(oy->headerbytes==0){
int headerbytes,i;
if(bytes<27)return(0); /* not enough for a header */
-
+
/* verify capture pattern */
if(memcmp(page,"OggS",4))goto sync_fail;
-
+
headerbytes=page[26]+27;
if(bytes<headerbytes)return(0); /* not enough for header + seg table */
-
+
/* count up body length in the segment table */
-
+
for(i=0;i<page[26];i++)
oy->bodybytes+=page[27+i];
oy->headerbytes=headerbytes;
}
-
+
if(oy->bodybytes+oy->headerbytes>bytes)return(0);
-
+
/* The whole test page is buffered. Verify the checksum */
{
/* Grab the checksum bytes, set the header field to zero */
char chksum[4];
ogg_page log;
-
+
memcpy(chksum,page+22,4);
memset(page+22,0,4);
-
+
/* set up a temp page struct and recompute the checksum */
log.header=page;
log.header_len=oy->headerbytes;
log.body=page+oy->headerbytes;
log.body_len=oy->bodybytes;
ogg_page_checksum_set(&log);
-
+
/* Compare */
if(memcmp(chksum,page+22,4)){
/* D'oh. Mismatch! Corrupt page (or miscapture and not a page
at all) */
/* replace the computed checksum with the one actually read in */
memcpy(page+22,chksum,4);
-
+
/* Bad checksum. Lose sync */
goto sync_fail;
}
}
-
+
/* yes, have a whole page all ready to go */
{
unsigned char *page=oy->data+oy->returned;
@@ -613,12 +613,12 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
oy->bodybytes=0;
return(bytes);
}
-
+
sync_fail:
-
+
oy->headerbytes=0;
oy->bodybytes=0;
-
+
/* search for possible capture */
next=memchr(page+1,'O',bytes-1);
if(!next)
@@ -655,7 +655,7 @@ int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
/* need more data */
return(0);
}
-
+
/* head did not start a synced page... skipped some bytes */
if(!oy->unsynced){
oy->unsynced=1;
@@ -684,7 +684,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
int serialno=ogg_page_serialno(og);
long pageno=ogg_page_pageno(og);
int segments=header[26];
-
+
/* clean up 'returned data' */
{
long lr=os->lacing_returned;
@@ -737,7 +737,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
/* are we a 'continued packet' page? If so, we may need to skip
some segments */
if(continued){
- if(os->lacing_fill<1 ||
+ if(os->lacing_fill<1 ||
os->lacing_vals[os->lacing_fill-1]==0x400){
bos=0;
for(;segptr<segments;segptr++){
@@ -751,7 +751,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
}
}
}
-
+
if(bodysize){
_os_body_expand(os,bodysize);
memcpy(os->body_data+os->body_fill,body,bodysize);
@@ -764,20 +764,20 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
int val=header[27+segptr];
os->lacing_vals[os->lacing_fill]=val;
os->granule_vals[os->lacing_fill]=-1;
-
+
if(bos){
os->lacing_vals[os->lacing_fill]|=0x100;
bos=0;
}
-
+
if(val<255)saved=os->lacing_fill;
-
+
os->lacing_fill++;
segptr++;
-
+
if(val<255)os->lacing_packet=os->lacing_fill;
}
-
+
/* set the granulepos on the last granuleval of the last full packet */
if(saved!=-1){
os->granule_vals[saved]=granulepos;