Commit 1ba2d089 authored by Stefan Westerfeld's avatar Stefan Westerfeld

avfilter/asubprocess: maintain a list of unused buffers

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent dbed10fb
......@@ -39,6 +39,7 @@ typedef struct SP
int input_pipe;
int output_pipe;
SPB *out_buffers;
SPB *unused_buffers;
int pid;
size_t input_count;
bool done;
......@@ -68,10 +69,16 @@ typedef struct AndioWMarkContext {
FFFrameQueue frame_queue;
} ASubProcessContext;
// =============================================
static SPB *spb_new(void)
static SPB *spb_new(AVFilterContext *ctx)
{
SPB *spb = av_malloc(sizeof(SPB));
ASubProcessContext *s = ctx->priv;
SPB *spb = s->sp->unused_buffers;
if (spb) {
s->sp->unused_buffers = spb->next;
}
else {
spb = av_malloc(sizeof(SPB));
}
spb->next = NULL;
spb->offset = 0;
......@@ -178,7 +185,8 @@ sp_read(SP *sp, char *buffer, int count)
return;
sp->out_buffers = spb->next;
av_free(spb);
spb->next = sp->unused_buffers;
sp->unused_buffers = spb;
spb = sp->out_buffers;
}
}
......@@ -306,14 +314,14 @@ sp_write(AVFilterContext *ctx, char *buffer, int count)
int rc, ret;
if (!sp->out_buffers)
sp->out_buffers = spb_new();
sp->out_buffers = spb_new(ctx);
last = sp->out_buffers;
while (last->next)
last = last->next;
if (last->count == sizeof(last->data)) {
last->next = spb_new();
last->next = spb_new(ctx);
last = last->next;
}
rc = read(sp->output_pipe, last->data + last->count, sizeof(last->data) - last->count);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment