Commit 2f635b09 authored by Stefan Westerfeld's avatar Stefan Westerfeld

avfilter/asubprocess: improve buffering code

Rather than allocating a new sub buffer for every read, fill up remaining
space of the last subbuffer if available.
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 4f3c079f
......@@ -27,7 +27,7 @@
#include <stdbool.h>
#include <string.h>
#define BUFFER_SIZE 4096
#define BUFFER_SIZE 1024 * 128
typedef struct SPB
{
......@@ -162,23 +162,33 @@ sp_write (SP *sp, char *buffer, int count)
offset += rc;
count -= rc;
}
else if (rc < 0 && errno != EAGAIN && errno != EINTR)
{
perror ("write to subprocess failed");
return AVERROR_EXTERNAL;
}
}
if (fds[1].revents & (POLLIN | POLLHUP))
{
SPB *spb = spb_new();
int rc = read(sp->output_pipe, spb->data, sizeof (spb->data));
SPB *last;
int rc;
if (!sp->out_buffers)
sp->out_buffers = spb_new();
last = sp->out_buffers;
while (last->next)
last = last->next;
if (last->count == sizeof (last->data))
{
last->next = spb_new();
last = last->next;
}
rc = read(sp->output_pipe, last->data + last->count, sizeof (last->data) - last->count);
if (rc > 0)
{
spb->count = rc;
if (!sp->out_buffers)
sp->out_buffers = spb;
else
{
SPB *last = sp->out_buffers;
while (last->next)
last = last->next;
last->next = spb;
}
last->count += rc;
}
else if (rc == 0)
{
......@@ -190,6 +200,11 @@ sp_write (SP *sp, char *buffer, int count)
return AVERROR_EXTERNAL;
return 0;
}
else if (errno != EAGAIN && errno != EINTR)
{
perror ("read from subprocess failed");
return AVERROR_EXTERNAL;
}
}
} while (count);
return 0;
......
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