[xiph-cvs] cvs commit: w3d info.c tarkin.c tarkin.h tarkin_dec.c
Ralph Giles
giles at xiph.org
Fri Nov 9 20:12:53 PST 2001
giles 01/11/09 20:12:52
Modified: . info.c tarkin.c tarkin.h tarkin_dec.c
Log:
Patch from olivier: fixs a segfault-on-last-frame-decode bug,
some small memory problems, and adds nice debug/info output on the ogg
layer under -DDBG_OGG.
Revision Changes Path
1.2 +40 -9 w3d/info.c
Index: info.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/info.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- info.c 2001/11/07 21:19:02 1.1
+++ info.c 2001/11/10 04:12:51 1.2
@@ -11,7 +11,7 @@
********************************************************************
function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.1 2001/11/07 21:19:02 holger Exp $
+ last mod: $Id: info.c,v 1.2 2001/11/10 04:12:51 giles Exp $
********************************************************************/
@@ -137,7 +137,7 @@
static int _tarkin_unpack_info(TarkinInfo *vi,oggpack_buffer *opb)
{
#ifdef DBG_OGG
- printf("ogg: Decoding Info: ");
+ printf("dbg_ogg: Decoding Info: ");
#endif
vi->version=oggpack_read(opb,32);
if(vi->version!=0)return(-TARKIN_VERSION);
@@ -151,7 +151,7 @@
vi->bitrate_lower=oggpack_read(opb,32);
#ifdef DBG_OGG
- printf("n_layers %d, interleave: %d/%d.",
+ printf(" n_layers %d, interleave: %d/%d, ",
vi->n_layers, vi->inter.numerator, vi->inter.denominator);
#endif
@@ -179,7 +179,7 @@
int vendorlen=oggpack_read(opb,32);
#ifdef DBG_OGG
- printf("ogg: Decoding comment....");
+ printf("dbg_ogg: Decoding comment: ");
#endif
if(vendorlen<0)goto err_out;
vc->vendor=_ogg_calloc(vendorlen+1,1);
@@ -200,7 +200,7 @@
if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
#ifdef DBG_OGG
- printf("Success\n");
+ printf("Success, read %d comments\n", vc->comments);
#endif
return(0);
err_out:
@@ -214,11 +214,11 @@
/* the real encoding details are here, currently TarkinVideoLayerDesc. */
static int _tarkin_unpack_layer_desc(TarkinInfo *vi,oggpack_buffer *opb){
int i,j;
- vi->layer = _ogg_calloc(vi->n_layers, (sizeof(*vi->layer)));
-
+ vi->layer = CALLOC (vi->n_layers, (sizeof(*vi->layer)));
+ memset(vi->layer,0, vi->n_layers * sizeof(*vi->layer));
#ifdef DBG_OGG
- printf("ogg: Decoding layers desc....");
+ printf("ogg: Decoding layers description: ");
#endif
for(i=0;i<vi->n_layers;i++){
TarkinVideoLayer *layer = vi->layer + i;
@@ -271,6 +271,13 @@
vi->max_bitstream_len += layer->desc.bitstream_len
+ 2 * 10 * sizeof(uint32_t) * layer->n_comp; // truncation tables
+
+#ifdef DBG_OGG
+ printf("\n layer%d: size %dx%dx%d, format %d, a_m %d, s_m %d, %d fpb\n",
+ i, layer->desc.width, layer->desc.height, layer->n_comp,
+ layer->desc.format, layer->desc.a_moments, layer->desc.s_moments,
+ layer->desc.frames_per_buf);
+#endif
} /* for each layer */
if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
@@ -369,6 +376,10 @@
oggpack_write(opb,1,1);
+#ifdef DBG_OGG
+ printf("dbg_ogg: Putting out info, inter %d/%d, n_layers %d\n",
+ vi->inter.numerator,vi->inter.denominator,vi->n_layers);
+#endif
return(0);
}
@@ -400,6 +411,10 @@
}
oggpack_write(opb,1,1);
+#ifdef DBG_OGG
+ printf("dbg_ogg: Putting out %d comments\n", vc->comments);
+#endif
+
return(0);
}
@@ -408,6 +423,10 @@
int i;
TarkinVideoLayer *layer;
+#ifdef DBG_OGG
+ printf("dbg_ogg: Putting out layers description:\n");
+#endif
+
oggpack_write(opb,0x05,8);
_v_writestring(opb,"tarkin", 6);
@@ -420,13 +439,25 @@
oggpack_write(opb,layer->desc.frames_per_buf,32);
oggpack_write(opb,layer->desc.bitstream_len,32);
oggpack_write(opb,layer->desc.format,32);
+
+#ifdef DBG_OGG
+ printf(" res. %dx%d, format %d, a_m %d, s_m %d, fpb %d\n",
+ layer->desc.width, layer->desc.height, layer->desc.format,
+ layer->desc.a_moments, layer->desc.s_moments,
+ layer->desc.frames_per_buf);
+#endif
+
}
oggpack_write(opb,1,1);
+#ifdef DBG_OGG
+ printf(" wrote %ld bytes.\n", oggpack_bytes(opb));
+#endif
+
return(0);
}
-int TarkinCommentheader_out(TarkinComment *vc, ogg_packet *op)
+int tarkin_comment_header_out(TarkinComment *vc, ogg_packet *op)
{
oggpack_buffer opb;
1.13 +46 -18 w3d/tarkin.c
Index: tarkin.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/tarkin.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- tarkin.c 2001/11/07 21:19:02 1.12
+++ tarkin.c 2001/11/10 04:12:52 1.13
@@ -47,15 +47,16 @@
if (s->layer)
FREE(s->layer);
- if (s->headers.header);
+ if (s->headers.header)
FREE(s->headers.header);
- if (s->headers.header1);
+ if (s->headers.header1)
FREE(s->headers.header1);
- if (s->headers.header2);
+ if (s->headers.header2)
FREE(s->headers.header2);
+
FREE(s);
}
@@ -86,12 +87,13 @@
s->layer = MALLOC(sizeof(*s->layer));
}
layer = s->layer + s->n_layers;
+ memset(layer,0,sizeof(*s->layer));
memcpy (&layer->desc , tvld, sizeof(TarkinVideoLayerDesc));
s->n_layers++;
s->ti->n_layers = s->n_layers;
s->ti->layer = s->layer;
- printf("n_layers: %d\n",s->n_layers);
+
switch (layer->desc.format) {
case TARKIN_GRAYSCALE:
layer->n_comp = 1;
@@ -116,6 +118,11 @@
default:
return -TARKIN_INVALID_COLOR_FORMAT;
};
+
+#ifdef DBG_OGG
+ printf("dbg_ogg:add_layer %d with %d components\n",
+ s->n_layers, layer->n_comp);
+#endif
layer->waveletbuf = (Wavelet3DBuf**) CALLOC (layer->n_comp,
sizeof(Wavelet3DBuf*));
@@ -161,8 +168,8 @@
op.bytes = oggpack_bytes(&opb)+4;
op.packet = opb.buffer;
#ifdef DBG_OGG
- printf("ogg: writing packet layer %d, comp %d, data_len %d\n",
- layer_id, comp, data_len);
+ printf("dbg_ogg: writing packet layer %d, comp %d, data_len %d %s\n",
+ layer_id, comp, data_len, op.e_o_s?"eos":"");
#endif
s->layer[layer_id].packet[comp].data_len = 0; /* so direct call => eos */
return(s->packet_out(s,&op));
@@ -233,7 +240,14 @@
if (s->current_frame_in_buf == s->frames_per_buf)
_stream_flush (s);
-
+
+#ifdef DBG_OGG
+ printf("dbg_ogg: framein at pos %d/%d, n° %d,%d on layer %d\n",
+ date->numerator, date->denominator,
+ layer->frameno, s->current_frame, layer_id);
+#endif
+
+ layer->frameno++;
return (++s->current_frame);
}
@@ -263,9 +277,6 @@
s->ti = ti;
s->layer = ti->layer; /* It was malloc()ed by headerin() */
s->n_layers = ti->n_layers;
-#ifdef DBG_OGG
- printf("tarkin_synthesis_init\n");
-#endif
return (TARKIN_OK);
}
@@ -277,7 +288,9 @@
oggpack_buffer opb;
TarkinPacket *packet;
#ifdef DBG_OGG
- printf("Reading packet %lld: ", op->packetno);
+ printf("dbg_ogg: Reading packet n° %lld, granulepos %lld, len %ld, %s%s\n",
+ op->packetno, op->granulepos, op->bytes,
+ op->b_o_s?"b_o_s":"", op->e_o_s?"e_o_s":"");
#endif
oggpack_readinit(&opb,op->packet,op->bytes);
flags = oggpack_read(&opb,8);
@@ -286,9 +299,6 @@
* packetno would be enough ?) */
nread = 4;
-#ifdef DBG_OGG
- printf("layer_id %d, comp %d", layer_id, comp);
-#endif
if(flags){ /* This is void "infinite future features" feature ;) */
if(flags & 1<<7){
junk = flags;
@@ -309,10 +319,17 @@
* 31 potentially usefull bits in last chunk. */
}
+ nread = (opb.ptr - opb.buffer);
+ data_len = op->bytes - nread;
+
+#ifdef DBG_OGG
+ printf(" layer_id %d, comp %d, meta-data %dB, w3d data %dB.\n",
+ layer_id, comp,nread, data_len);
+#endif
+
/* We now have for shure our data. */
packet = &s->layer[layer_id].packet[comp];
if(packet->data_len)return(-TARKIN_UNUSED); /* Previous data wasn't used */
- data_len = op->bytes - (opb.ptr - opb.buffer);
if(packet->storage < data_len){
packet->storage = data_len + 255;
@@ -338,7 +355,7 @@
for (j=0; j<layer->n_comp; j++) {
TarkinPacket *packet = layer->packet + j;
- if(packet->data_len == 0) return (TARKIN_NEED_MORE);
+ if(packet->data_len == 0)goto err_out ;
wavelet_3d_buf_decode_coeff (layer->waveletbuf[j], packet->data,
packet->data_len);
@@ -367,14 +384,25 @@
if (s->current_frame_in_buf == s->frames_per_buf)
s->current_frame_in_buf=0;
-
+
+ date->numerator = layer->frameno * s->ti->inter.numerator;
+ date->denominator = s->ti->inter.denominator;
+#ifdef DBG_OGG
+ printf("dbg_ogg: outputting frame pos %d/%d from layer %d.\n",
+ date->numerator, date->denominator, layer_id);
+#endif
+ layer->frameno++;
return (TARKIN_OK);
+err_out:
+ FREE(*frame);
+ return (TARKIN_NEED_MORE);
}
int tarkin_synthesis_freeframe(TarkinStream *s, uint8_t *frame)
{
FREE(frame);
- return(TARKIN_OK);
+
+ return(TARKIN_OK);
}
1.9 +1 -0 w3d/tarkin.h
Index: tarkin.h
===================================================================
RCS file: /usr/local/cvsroot/w3d/tarkin.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- tarkin.h 2001/11/07 21:19:02 1.8
+++ tarkin.h 2001/11/10 04:12:52 1.9
@@ -71,6 +71,7 @@
Wavelet3DBuf **waveletbuf;
TarkinPacket *packet;
uint32_t current_frame_in_buf;
+ uint32_t frameno;
void (*color_fwd_xform) (uint8_t *rgba, Wavelet3DBuf *yuva [], uint32_t count);
void (*color_inv_xform) (Wavelet3DBuf *yuva [], uint8_t *rgba, uint32_t count);
1.5 +5 -2 w3d/tarkin_dec.c
Index: tarkin_dec.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/tarkin_dec.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- tarkin_dec.c 2001/11/07 21:19:03 1.4
+++ tarkin_dec.c 2001/11/10 04:12:52 1.5
@@ -56,12 +56,13 @@
ogg_sync_wrote(&oy, nread);
else{
ogg_sync_wrote(&oy,0);
- break;
}
if(ogg_sync_pageout(&oy,&og)){
ogg_stream_pagein(&os,&og);
while(ogg_stream_packetout(&os,&op)){
- if(nheader<3){
+ if(op.e_o_s)
+ break;
+ if(nheader<3){ /* 3 first packets to headerin */
tarkin_synthesis_headerin(&ti, &tc, &op);
if(nheader == 2){
tarkin_synthesis_init(tarkin_stream, &ti);
@@ -81,6 +82,8 @@
}
}
}
+ if(nread==0)
+ break;
}
tarkin_stream_destroy (tarkin_stream);
close (fd);
--- >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