]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Revert "Auto-adjust fecdec output buffer size."
authorAndre Noll <maan@systemlinux.org>
Sun, 26 Apr 2009 20:35:53 +0000 (22:35 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 26 Apr 2009 20:35:53 +0000 (22:35 +0200)
This reverts commit 35f9051506345255c7ed3c076b7df5f3b7d26039.

Currently, filters must not change their output buffer on the fly
because the writer might already have a reference to the old buffer
and keeps using this buffer.

As dealing with changing output buffers requires much more work,
including changes to the generic filter and writer code, let's defer
this change to post 0.3.4.

fecdec_filter.c

index 30ac818c360873f6aedadd19e55ca7e0f6209550..bc5300627dbdfb7a1ab1bf37f0ac5aa681dbd4a2 100644 (file)
  */
 #define NUM_FEC_GROUPS 3
 
-/** Default size of the output buffer of the fecdec filter. */
-#define FECDEC_DEFAULT_OUTBUF_SIZE (16 * 1024)
-/** Maximal size of the output buffer of the fecdec filter. */
-#define FECDEC_MAX_OUTBUF_SIZE (1024 * 1024)
+/** Size of the output buffer of the fecdec filter. */
+#define FECDEC_OUTBUF_SIZE (1024 * 1024) /* FIXME: This has to depend on the fec params */
 
 /** Data read from the header of a slice. */
 struct fec_header {
@@ -253,7 +251,7 @@ static enum fec_group_usability group_is_usable(struct fecdec_group *fg,
 static int decode_group(struct fecdec_group *fg, struct filter_node *fn)
 {
        int i, ret, sb = fg->h.slice_bytes;
-       size_t written = 0, need;
+       size_t written = 0;
        struct private_fecdec_data *pfd = fn->private_data;
        enum fec_group_usability u = group_is_usable(fg, pfd);
 
@@ -276,18 +274,12 @@ static int decode_group(struct fecdec_group *fg, struct filter_node *fn)
        PARA_DEBUG_LOG("writing group %d (%d/%d decoded data bytes)\n",
                fg->h.group_num, fg->h.group_bytes,
                fg->h.data_slices_per_group * sb);
-       need = fn->loaded + (fg->h.data_slices_per_group - i)* sb;
-       if (need > fn->bufsize) {
-               fn->bufsize = PARA_MAX(fn->bufsize * 2, need);
-               if (fn->bufsize > FECDEC_MAX_OUTBUF_SIZE)
-                       return -E_FECDEC_OVERRUN;
-               PARA_INFO_LOG("increasing fec buf to %zu\n", fn->bufsize);
-               fn->buf = para_realloc(fn->buf, fn->bufsize);
-       }
        for (; i < fg->h.data_slices_per_group; i++) {
                size_t n = sb;
                if (n + written > fg->h.group_bytes)
                        n = fg->h.group_bytes - written;
+               if (fn->loaded + n > fn->bufsize)
+                       return -E_FECDEC_OVERRUN;
                memcpy(fn->buf + fn->loaded, fg->data[i], n);
                fn->loaded += n;
                written += n;
@@ -394,7 +386,7 @@ static void fecdec_close(struct filter_node *fn)
 
 static void fecdec_open(struct filter_node *fn)
 {
-       fn->bufsize = FECDEC_DEFAULT_OUTBUF_SIZE;
+       fn->bufsize = FECDEC_OUTBUF_SIZE;
        fn->buf = para_malloc(fn->bufsize);
        fn->private_data = para_calloc(sizeof(struct private_fecdec_data));
        fn->loaded = 0;