[xiph-cvs] cvs commit: w3d tarkin-io.c tarkin.c tarkin_enc.c wavelet.c
Holger Waechtler
holger at xiph.org
Fri Jun 29 05:21:44 PDT 2001
holger 01/06/29 05:21:44
Modified: . tarkin-io.c tarkin.c tarkin_enc.c wavelet.c
Log:
fixed a serious bug in memory management
Revision Changes Path
1.2 +5 -1 w3d/tarkin-io.c
Index: tarkin-io.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/tarkin-io.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- tarkin-io.c 2001/06/29 09:19:25 1.1
+++ tarkin-io.c 2001/06/29 12:21:43 1.2
@@ -128,6 +128,7 @@
int read_tarkin_bitstream (int fd, uint8_t *bitstream)
{
+ uint32_t bytes = 0;
uint32_t len;
if (read (fd, &len, 4) < 4 || len == 0)
@@ -135,7 +136,10 @@
LE32_TO_CPU(len);
- return read (fd, bitstream, len);
+ while (bytes < len)
+ bytes += read (fd, bitstream + bytes, len - bytes);
+
+ return len;
}
1.3 +9 -15 w3d/tarkin.c
Index: tarkin.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/tarkin.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- tarkin.c 2001/06/29 09:19:25 1.2
+++ tarkin.c 2001/06/29 12:21:43 1.3
@@ -44,13 +44,8 @@
if (s->layer)
free(s->layer);
-/**
- * XXX FIXME HACK Alert: segfault when doin' this right ...
- * somewhere is something really wrong ...
- * perhaps in merge_bitstreams() ???
- */
-// if (s->bitstream);
-// free(s->bitstream);
+ if (s->bitstream);
+ free(s->bitstream);
free(s);
}
@@ -107,10 +102,9 @@
desc[i].frames_per_buf);
layer->bitstream_len = layer->desc.bitrate / (8 * layer->n_comp);
-
- if (layer->bitstream_len > max_bitstream_len)
- max_bitstream_len = layer->bitstream_len;
-
+ max_bitstream_len += layer->bitstream_len * layer->n_comp
+ + 5000
+ + 2 * 9 * sizeof(uint32_t) * layer->n_comp; // truncation tables
}
if ((err = write_tarkin_header(s->fd, s)) != TARKIN_OK)
@@ -139,7 +133,7 @@
wavelet_3d_buf_fwd_xform (layer->waveletbuf[j], 2, 2);
bitstream_len = wavelet_3d_buf_encode_coeff (layer->waveletbuf[j],
s->bitstream,
- layer->desc.bitrate/8);
+ layer->bitstream_len);
write_tarkin_bitstream (s->fd, s->bitstream, bitstream_len);
}
}
@@ -224,9 +218,9 @@
}
layer->bitstream_len = layer->desc.bitrate / (8 * layer->n_comp);
-
- if (layer->bitstream_len > max_bitstream_len)
- max_bitstream_len = layer->bitstream_len;
+ max_bitstream_len += layer->bitstream_len * layer->n_comp
+ + 5000
+ + 2 * 9 * sizeof(uint32_t) * layer->n_comp;
}
s->bitstream = (uint8_t*) malloc (max_bitstream_len);
1.2 +24 -21 w3d/tarkin_enc.c
Index: tarkin_enc.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/tarkin_enc.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- tarkin_enc.c 2001/06/29 09:19:25 1.1
+++ tarkin_enc.c 2001/06/29 12:21:43 1.2
@@ -10,6 +10,22 @@
#include "ppm.h"
+static
+void usage (const char *program_name)
+{
+ printf ("\n"
+ " usage: %s <input filename format string> <bitrate> <a_m> <s_m>\n"
+ "\n"
+ " input ppm filename format: optional, \"%%i.ppm\" by default\n"
+ " bitrate: cut Y/U/V bitstream after limit bits (!!!)/frame\n"
+ " (something like 1228800 makes sense here)\n"
+ " a_m, s_m: number of vanishing moments of the\n"
+ " analysis/synthesis filter, (2,2) by default\n"
+ "\n", program_name);
+ exit (-1);
+}
+
+
int main (int argc, char **argv)
{
@@ -17,35 +33,22 @@
char fname[256];
uint32_t frame = 0;
uint8_t *rgb;
- int ylimit, ulimit, vlimit;
int a_moments, s_moments;
int fd;
TarkinStream *tarkin_stream;
TarkinVideoLayerDesc layer [] = { { 0, 0, 1, 5000, TARKIN_RGB24 } };
if (argc == 1) {
- ylimit = 1000;
- ulimit = 150;
- vlimit = 150;
+ layer[0].bitrate = 1000;
a_moments = 2;
s_moments = 2;
- } else if (argc == 7) {
+ } else if (argc == 5) {
fmt = argv[1];
- ylimit = strtol (argv[2], 0, 0);
- ulimit = strtol (argv[3], 0, 0);
- vlimit = strtol (argv[4], 0, 0);
- a_moments = strtol (argv[5], 0, 0);
- s_moments = strtol (argv[6], 0, 0);
+ layer[0].bitrate = strtol (argv[2], 0, 0);
+ a_moments = strtol (argv[3], 0, 0);
+ s_moments = strtol (argv[4], 0, 0);
} else {
- printf ("\n"
- " usage: %s <input filename format string> <ylimit> <ulimit> <vlimit> <a_m> <s_m>\n"
- "\n"
- " input ppm filename format: optional, \"%%i.ppm\" by default\n"
- " ylimit, ulimit, vlimit: cut Y/U/V bitstream after limit bytes/frame\n"
- " a_m, s_m: number of vanishing moments of the\n"
- " analysis/synthesis filter, (2,2) by default\n"
- "\n", argv[0]);
- exit (-1);
+ usage (argv[0]);
}
snprintf (fname, 256, fmt, 0);
@@ -56,7 +59,7 @@
if ((fd = open ("stream.tarkin", O_CREAT | O_RDWR | O_TRUNC, 0644)) < 0) {
printf ("error opening '%s' for writing !\n", "stream.tarkin");
- exit (-1);
+ usage (argv[0]);
}
tarkin_stream = tarkin_stream_new (fd);
@@ -77,7 +80,7 @@
tarkin_stream_write_frame (tarkin_stream, &rgb);
frame++;
- } while (0);
+ } while (1);
free (rgb);
tarkin_stream_destroy (tarkin_stream);
1.5 +46 -20 w3d/wavelet.c
Index: wavelet.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/wavelet.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- wavelet.c 2001/06/29 09:19:25 1.4
+++ wavelet.c 2001/06/29 12:21:43 1.5
@@ -3,7 +3,6 @@
#include "wavelet.h"
#include "rle.h"
-
/**
* (The transform code is in wavelet_xform.c)
*/
@@ -295,31 +294,57 @@
static
+uint32_t insignificand_truncation_table [9] = {
+ 2, 4, 8, 16, 32, 64, 128, 256, 512
+};
+
+
+static
+uint32_t significand_truncation_table [8] = { 2, 4, 8, 16, 32, 64, 128, 256 };
+
+
+static
uint32_t setup_limittabs (ENTROPY_CODER significand_bitstream [],
ENTROPY_CODER insignificand_bitstream [],
uint32_t significand_limittab [],
- uint32_t insignificand_limittab [])
+ uint32_t insignificand_limittab [],
+ uint32_t limit)
{
uint32_t byte_count = 0;
int i;
- for (i=0; i<9; i++) {
- uint32_t bytes = ENTROPY_ENCODER_FLUSH(&significand_bitstream[i]);
-bytes=i > 3 ? 200 : 20*i;
- significand_limittab[i] = bytes;
- byte_count += bytes;
- }
-
+//printf ("%s: limit == %u\n", __FUNCTION__, limit);
+ limit -= 2 * 9 * sizeof(uint32_t); /* 2 limittabs, coded binary */
+//printf ("%s: rem. limit == %u\n", __FUNCTION__, limit);
+
for (i=0; i<9; i++) {
uint32_t bytes = ENTROPY_ENCODER_FLUSH(&insignificand_bitstream[i]);
-bytes=i > 5 ? 100 : 10*i;
- insignificand_limittab[i] = bytes;
- byte_count += bytes;
+ insignificand_limittab[i] =
+ limit * insignificand_truncation_table[i] / 2048;
+
+ if (bytes < insignificand_limittab[i])
+ insignificand_limittab[i] = bytes;
+//printf ("insignificand_limittab[%i] == %u\n", i, insignificand_limittab[i]);
+ byte_count += insignificand_limittab[i];
+ }
+
+ for (i=8; i>0; i--) {
+ uint32_t bytes = ENTROPY_ENCODER_FLUSH(&significand_bitstream[i]);
+
+ significand_limittab[i] = limit * significand_truncation_table[8-i] / 2048;
+
+ if (bytes < significand_limittab[i])
+ significand_limittab[i] = bytes;
+//printf ("significand_limittab[%i] == %u\n", i, significand_limittab[i]);
+ byte_count += significand_limittab[i];
}
-byte_count += 2 * 9 * sizeof(uint32_t); /* 2 limittabs, coded binary */
+ significand_limittab[i] = limit - byte_count;
+ byte_count += significand_limittab[i];
+//printf ("significand_limittab[%i] == %u\n", i, significand_limittab[i]);
+//printf ("byte_count == %u\n", byte_count);
return byte_count;
}
@@ -381,7 +406,7 @@
{
int i;
- for (i=0; i<9; i++) {
+ for (i=8; i>=0; i--) {
memcpy (bitstream,
ENTROPY_CODER_BITSTREAM(&significand_bitstream[i]),
significand_limittab[i]);
@@ -389,12 +414,12 @@
bitstream += significand_limittab[i];
}
- for (i=0; i<9; i++) {
+ for (i=8; i>=0; i--) {
memcpy (bitstream,
ENTROPY_CODER_BITSTREAM(&insignificand_bitstream[i]),
insignificand_limittab[i]);
- bitstream += significand_limittab[i];
+ bitstream += insignificand_limittab[i];
}
}
@@ -409,14 +434,14 @@
uint32_t byte_count;
int i;
- for (i=0; i<9; i++) {
+ for (i=8; i>=0; i--) {
byte_count = significand_limittab[i];
ENTROPY_DECODER_INIT(&significand_bitstream[i], bitstream, byte_count);
bitstream += byte_count;
}
- for (i=0; i<9; i++) {
- byte_count = significand_limittab[i];
+ for (i=8; i>=0; i--) {
+ byte_count = insignificand_limittab[i];
ENTROPY_DECODER_INIT(&insignificand_bitstream[i], bitstream, byte_count);
bitstream += byte_count;
}
@@ -442,7 +467,8 @@
encode_coefficients (buf, significand_bitstream, insignificand_bitstream);
byte_count = setup_limittabs (significand_bitstream, insignificand_bitstream,
- significand_limittab, insignificand_limittab);
+ significand_limittab, insignificand_limittab,
+ limit);
bitstream = write_limittabs (bitstream,
significand_limittab, insignificand_limittab);
--- >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