gui: Use variable-sized input buffer for the audiod pipe.
[paraslash.git] / filter_common.c
index ebda1ee74ad265275017d9ebe6eaf137de317fcb..1b02e1cdfbd1c106ae8ec69125af108ae24b8d8f 100644 (file)
@@ -99,7 +99,7 @@ static void call_callbacks(struct filter_node *fn, char *inbuf, size_t inlen,
  * there is input available for the filter node in question. If the convert
  * function consumed some or all of its input data, all registered input
  * callbacks are called.  Similarly, if a convert function produced output, all
  * there is input available for the filter node in question. If the convert
  * function consumed some or all of its input data, all registered input
  * callbacks are called.  Similarly, if a convert function produced output, all
- * registerd output callbacks get called.
+ * registered output callbacks get called.
  *
  * On errors a (negative) error code is stored in t->error.
  *
  *
  * On errors a (negative) error code is stored in t->error.
  *
@@ -125,8 +125,6 @@ again:
                struct filter *f = filters + fn->filter_num;
                if (fn->loaded < fn->bufsize) {
                        size_t size, old_fn_loaded = fn->loaded;
                struct filter *f = filters + fn->filter_num;
                if (fn->loaded < fn->bufsize) {
                        size_t size, old_fn_loaded = fn->loaded;
-//                     PARA_DEBUG_LOG("fc %p loaded: %zd, calling %s convert\n",
-//                             fc, *loaded, fn->filter->name);
                        t->error = f->convert(ib, *loaded, fn);
                        if (t->error < 0)
                                return;
                        t->error = f->convert(ib, *loaded, fn);
                        if (t->error < 0)
                                return;
@@ -134,24 +132,29 @@ again:
                        call_callbacks(fn, ib, size, fn->buf + old_fn_loaded,
                                fn->loaded - old_fn_loaded);
                        *loaded -= size;
                        call_callbacks(fn, ib, size, fn->buf + old_fn_loaded,
                                fn->loaded - old_fn_loaded);
                        *loaded -= size;
-                       conv += size;
-                       if (*loaded && size) {
-//                             PARA_DEBUG_LOG("moving %zd bytes in input "
-//                                     "buffer for %s filter\n",
-//                                     *loaded,  fn->filter->name);
+                       conv += size + fn->loaded - old_fn_loaded;
+                       if (*loaded && size)
                                memmove(ib, ib + size, *loaded);
                                memmove(ib, ib + size, *loaded);
-                       }
                }
                ib = fn->buf;
                loaded = &fn->loaded;
        }
        conv_total += conv;
                }
                ib = fn->buf;
                loaded = &fn->loaded;
        }
        conv_total += conv;
-//     PARA_DEBUG_LOG("eof (in/out/fc): %d/%d/%d out_loaded: %zd, "
-//             "conv: %d, conv_total: %d\n", *fc->input_eof,
-//             fc->output_eof? *fc->output_eof : -42,
-//             fc->eof, *fc->out_loaded, conv, conv_total);
        if (conv)
                goto again;
        if (conv)
                goto again;
+       if (conv_total) {
+               /*
+                * Other pre_select functions might have already been called by
+                * now and decided to do nothing, e.g. because their output
+                * buffer was full or the input buffer was empty. We just
+                * converted something which caused these buffers to change but
+                * we can't make the other tasks reconsider their decision at
+                * this point.  So force a minimal timeout for the next select
+                * call to avoid unnecessary delays.
+                */
+               s->timeout.tv_sec = 0;
+               s->timeout.tv_usec = 1;
+       }
        if (*fc->input_error >= 0)
                return;
        if (*fc->out_loaded)
        if (*fc->input_error >= 0)
                return;
        if (*fc->out_loaded)