[xiph-cvs] cvs commit: ogg/src framing.c
Monty
xiphmont at xiph.org
Mon Oct 30 00:03:36 PST 2000
xiphmont 00/10/30 00:03:35
Modified: include/ogg Tag: branch_beta3 ogg.h
src Tag: branch_beta3 framing.c
Log:
Modification to ogg framing abstraction so that the page sequence
number a packet was extracted from (completed from) is passed in the
packet struct. Vorbis needs this to do offset inference correctly.
ogg_page_pageno now returns long (just in case we end up on a platform
with 16 bit ints)
Monty
Revision Changes Path
No revision
No revision
1.6.2.1 +17 -14 ogg/include/ogg/ogg.h
Index: ogg.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/include/ogg/ogg.h,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -r1.6 -r1.6.2.1
--- ogg.h 2000/10/10 05:42:34 1.6
+++ ogg.h 2000/10/30 08:03:34 1.6.2.1
@@ -35,10 +35,11 @@
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 */
+ int *lacing_vals; /* The values that will go to the segment table */
+ long *page_vals; /* track the pages packets come from */
+ 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;
@@ -51,8 +52,8 @@
logical bitstream */
int b_o_s; /* set after we've written the initial page
of a logical bitstream */
- long serialno;
- int pageno;
+ 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
@@ -72,12 +73,14 @@
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 */
-
+
+ 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 */
+ long pageno; /* Sequence number of the page this
+ packet completed on. */
} ogg_packet;
typedef struct {
@@ -144,8 +147,8 @@
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 int ogg_page_pageno(ogg_page *og);
- extern int ogg_page_packets(ogg_page *og);
+extern long ogg_page_pageno(ogg_page *og);
+extern int ogg_page_packets(ogg_page *og);
#ifdef __cplusplus
No revision
No revision
1.6.2.1 +55 -22 ogg/src/framing.c
Index: framing.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/framing.c,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -r1.6 -r1.6.2.1
--- framing.c 2000/10/10 05:46:06 1.6
+++ framing.c 2000/10/30 08:03:35 1.6.2.1
@@ -13,7 +13,7 @@
function: code raw [Vorbis] packets into framed OggSquish stream and
decode Ogg streams back into raw packets
- last mod: $Id: framing.c,v 1.6 2000/10/10 05:46:06 xiphmont Exp $
+ last mod: $Id: framing.c,v 1.6.2.1 2000/10/30 08:03:35 xiphmont Exp $
note: The CRC code is directly derived from public domain code by
Ross Williams (ross at guest.adelaide.edu.au). See docs/framing.html
@@ -63,7 +63,7 @@
(og->header[17]<<24));
}
-int ogg_page_pageno(ogg_page *og){
+long ogg_page_pageno(ogg_page *og){
return(og->header[18] |
(og->header[19]<<8) |
(og->header[20]<<16) |
@@ -158,6 +158,7 @@
if(os){
if(os->body_data)free(os->body_data);
if(os->lacing_vals)free(os->lacing_vals);
+ if(os->page_vals)free(os->page_vals);
if(os->granule_vals)free(os->granule_vals);
memset(os,0,sizeof(ogg_stream_state));
@@ -183,7 +184,7 @@
}
}
-static void _os_lacing_expand(ogg_stream_state *os,int needed){
+static void _os_lacing_expand_en(ogg_stream_state *os,int needed){
if(os->lacing_storage<=os->lacing_fill+needed){
os->lacing_storage+=(needed+32);
os->lacing_vals=realloc(os->lacing_vals,os->lacing_storage*sizeof(int));
@@ -191,6 +192,23 @@
}
}
+static void _os_lacing_expand_de(ogg_stream_state *os,int needed){
+ if(os->lacing_storage<=os->lacing_fill+needed){
+ os->lacing_storage+=(needed+32);
+ os->lacing_vals=realloc(os->lacing_vals,os->lacing_storage*sizeof(int));
+
+ if(!os->page_vals)
+ os->page_vals=malloc(os->lacing_storage*sizeof(long));
+ else
+ os->page_vals=realloc(os->page_vals,os->lacing_storage*sizeof(long));
+
+ os->granule_vals=realloc(os->granule_vals,os->lacing_storage*sizeof(ogg_int64_t));
+ }else{
+ if(!os->page_vals)
+ os->page_vals=malloc(os->lacing_storage*sizeof(long));
+ }
+}
+
/* checksum the page */
/* Direct table CRC; note that this will be faster in the future if we
perform the checksum silmultaneously with other copies */
@@ -228,7 +246,7 @@
/* make sure we have the buffer storage */
_os_body_expand(os,op->bytes);
- _os_lacing_expand(os,lacing_vals);
+ _os_lacing_expand_en(os,lacing_vals);
/* Copy in the submitted packet. Yes, the copy is a waste; this is
the liability of overly clean abstraction for the time being. It
@@ -627,7 +645,7 @@
int eos=ogg_page_eos(og);
ogg_int64_t granulepos=ogg_page_granulepos(og);
int serialno=ogg_page_serialno(og);
- int pageno=ogg_page_pageno(og);
+ long pageno=ogg_page_pageno(og);
int segments=header[26];
/* clean up 'returned data' */
@@ -648,6 +666,8 @@
if(os->lacing_fill-lr){
memmove(os->lacing_vals,os->lacing_vals+lr,
(os->lacing_fill-lr)*sizeof(int));
+ memmove(os->page_vals,os->page_vals+lr,
+ (os->lacing_fill-lr)*sizeof(long));
memmove(os->granule_vals,os->granule_vals+lr,
(os->lacing_fill-lr)*sizeof(ogg_int64_t));
}
@@ -661,7 +681,7 @@
if(serialno!=os->serialno)return(-1);
if(version>0)return(-1);
- _os_lacing_expand(os,segments+1);
+ _os_lacing_expand_de(os,segments+1);
/* are we in sequence? */
if(pageno!=os->pageno){
@@ -705,6 +725,7 @@
while(segptr<segments){
int val=header[27+segptr];
os->lacing_vals[os->lacing_fill]=val;
+ os->page_vals[os->lacing_fill]=pageno;
os->granule_vals[os->lacing_fill]=-1;
if(bos){
@@ -805,6 +826,7 @@
}
op->packetno=os->packetno;
+ op->pageno=os->page_vals[ptr];
op->granulepos=os->granule_vals[ptr];
op->bytes=bytes;
@@ -821,7 +843,7 @@
ogg_stream_state os_en, os_de;
ogg_sync_state oy;
-void checkpacket(ogg_packet *op,int len, int no, int pos){
+void checkpacket(ogg_packet *op,int len, int no, int pos, int pageno){
long j;
static int sequence=0;
static int lastno=0;
@@ -830,6 +852,10 @@
fprintf(stderr,"incorrect packet length!\n");
exit(1);
}
+ if(op->pageno!=pageno){
+ fprintf(stderr,"incorrect pageno in packet!\n");
+ exit(1);
+ }
if(op->granulepos!=pos){
fprintf(stderr,"incorrect packet position!\n");
exit(1);
@@ -894,12 +920,12 @@
og->header[0],og->header[1],og->header[2],og->header[3],
(int)og->header[4],(int)og->header[5]);
- fprintf(stderr," granulepos: %d serialno: %d pageno: %d\n",
+ fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
(og->header[9]<<24)|(og->header[8]<<16)|
(og->header[7]<<8)|og->header[6],
(og->header[17]<<24)|(og->header[16]<<16)|
(og->header[15]<<8)|og->header[14],
- (og->header[21]<<24)|(og->header[20]<<16)|
+ ((long)(og->header[21])<<24)|(og->header[20]<<16)|
(og->header[19]<<8)|og->header[18]);
fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
@@ -1119,8 +1145,8 @@
long outptr=0;
long deptr=0;
long depacket=0;
- long granule_pos=7;
- int i,j,packets,pageno=0,pageout=0;
+ long granule_pos=7,pageno=0;
+ int i,j,packets,pageout=0;
int eosflag=0;
int bosflag=0;
@@ -1154,7 +1180,7 @@
while(ogg_stream_pageout(&os_en,&og)){
/* We have a page. Check it carefully */
- fprintf(stderr,"%d, ",pageno);
+ fprintf(stderr,"%ld, ",pageno);
if(headers[pageno]==NULL){
fprintf(stderr,"coded too many pages!\n");
@@ -1190,6 +1216,13 @@
while(ogg_stream_packetout(&os_de,&op_de)>0){
/* verify the packet! */
+ /* check page assignment */
+ if(op_de.pageno!=ogg_page_pageno(&og_de)){
+ fprintf(stderr,"packet completion pageno %ld != pageno %ld!\n",
+ op_de.pageno,ogg_page_pageno(&og_de));
+ exit(1);
+ }
+
/* check data */
if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
@@ -1431,19 +1464,19 @@
/* do we get the expected results/packets? */
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,0,0,0);
+ checkpacket(&test,0,0,0,0);
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,100,1,-1);
+ checkpacket(&test,100,1,-1,1);
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,4079,2,3000);
+ checkpacket(&test,4079,2,3000,1);
if(ogg_stream_packetout(&os_de,&test)!=-1){
fprintf(stderr,"Error: loss of page did not return error\n");
exit(1);
}
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,76,5,-1);
+ checkpacket(&test,76,5,-1,3);
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,34,6,-1);
+ checkpacket(&test,34,6,-1,3);
fprintf(stderr,"ok.\n");
}
@@ -1478,19 +1511,19 @@
/* do we get the expected results/packets? */
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,0,0,0);
+ checkpacket(&test,0,0,0,0);
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,100,1,-1);
+ checkpacket(&test,100,1,-1,1);
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,4079,2,3000);
+ checkpacket(&test,4079,2,3000,1);
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,2956,3,4000);
+ checkpacket(&test,2956,3,4000,2);
if(ogg_stream_packetout(&os_de,&test)!=-1){
fprintf(stderr,"Error: loss of page did not return error\n");
exit(1);
}
if(ogg_stream_packetout(&os_de,&test)!=1)error();
- checkpacket(&test,300,13,14000);
+ checkpacket(&test,300,13,14000,4);
fprintf(stderr,"ok.\n");
}
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list