Commit b7bbc07e authored by Stefan Westerfeld's avatar Stefan Westerfeld

avfilter/asubprocess: report errors from sp_write, fix 24/8 bit output

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 2f635b09
......@@ -137,7 +137,7 @@ sp_read (SP *sp, char *buffer, int count)
}
static int
sp_write (SP *sp, char *buffer, int count)
sp_write(AVFilterContext *ctx, SP *sp, char *buffer, int count)
{
int offset = 0;
if (count == 0 && sp->input_pipe >= 0) // eof
......@@ -164,8 +164,9 @@ sp_write (SP *sp, char *buffer, int count)
}
else if (rc < 0 && errno != EAGAIN && errno != EINTR)
{
perror ("write to subprocess failed");
return AVERROR_EXTERNAL;
int ret = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "Write to subprocess failed: %s.\n", strerror(errno));
return ret;
}
}
if (fds[1].revents & (POLLIN | POLLHUP))
......@@ -202,8 +203,9 @@ sp_write (SP *sp, char *buffer, int count)
}
else if (errno != EAGAIN && errno != EINTR)
{
perror ("read from subprocess failed");
return AVERROR_EXTERNAL;
int ret = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "Read from subprocess failed: %s.\n", strerror(errno));
return ret;
}
}
} while (count);
......@@ -279,7 +281,7 @@ static av_cold void uninit(AVFilterContext *ctx)
#define NB_BUFFER_SAMPLES 4096
static int write_wav_header(ASubProcessContext *s, int nb_channels, int sample_rate)
static int write_wav_header(AVFilterContext *ctx, ASubProcessContext *s, int nb_channels, int sample_rate)
{
int bit_depth = s->in_bit_depth;
AVIOContext *wav_header = NULL;
......@@ -305,7 +307,7 @@ static int write_wav_header(ASubProcessContext *s, int nb_channels, int sample_r
ffio_wfourcc(wav_header, "data");
avio_wl32(wav_header, -1);
size = avio_close_dyn_buf(wav_header, &buffer);
ret = sp_write(s->sp, buffer, size);
ret = sp_write(ctx, s->sp, buffer, size);
av_free(buffer);
return ret;
}
......@@ -315,7 +317,7 @@ static int config_input(AVFilterLink *inlink)
AVFilterContext *ctx = inlink->dst;
ASubProcessContext *s = ctx->priv;
s->sp = sp_new (s->command);
write_wav_header(s, inlink->ch_layout.nb_channels, inlink->sample_rate);
write_wav_header(ctx, s, inlink->ch_layout.nb_channels, inlink->sample_rate);
#if 0
int opts = s->transients|s->detector|s->phase|s->window|
......@@ -338,7 +340,7 @@ static int config_input(AVFilterLink *inlink)
static void read_samples(ASubProcessContext *s, int32_t *data, int count)
{
int sample_size = s->in_bit_depth / 8;
int sample_size = s->out_bit_depth / 8;
#if !HAVE_BIGENDIAN
if (s->out_bit_depth == 32)
{
......@@ -377,7 +379,7 @@ static void read_samples(ASubProcessContext *s, int32_t *data, int count)
}
}
static int write_samples(ASubProcessContext *s, int32_t *data, int count)
static int write_samples(AVFilterContext *ctx, ASubProcessContext *s, int32_t *data, int count)
{
int sample_size = s->in_bit_depth / 8;
......@@ -385,7 +387,7 @@ static int write_samples(ASubProcessContext *s, int32_t *data, int count)
if (s->in_bit_depth == 32)
{
/* optimized case: on little endian systems we don't need any conversion */
return sp_write(s->sp, (char *)data, sample_size * count);
return sp_write(ctx, s->sp, (char *)data, sample_size * count);
}
#endif
if (s->in_bit_depth == 16)
......@@ -409,15 +411,15 @@ static int write_samples(ASubProcessContext *s, int32_t *data, int count)
for (int k = 0; k < count; k++)
AV_WL32(out + k, data[k]);
}
return sp_write(s->sp, s->sample_buffer, sample_size * count);
return sp_write(ctx, s->sp, s->sample_buffer, sample_size * count);
}
static int write_frame(ASubProcessContext *s, AVFilterLink *inlink, AVFrame *in)
static int write_frame(AVFilterContext *ctx, ASubProcessContext *s, AVFilterLink *inlink, AVFrame *in)
{
int ret = 0;
av_assert0(in->nb_samples <= NB_BUFFER_SAMPLES);
ret = write_samples(s, (int32_t *)in->data[0], in->nb_samples * inlink->ch_layout.nb_channels);
ret = write_samples(ctx, s, (int32_t *)in->data[0], in->nb_samples * inlink->ch_layout.nb_channels);
av_frame_free(&in);
return ret;
}
......@@ -511,7 +513,7 @@ static int activate(AVFilterContext *ctx)
if (ret < 0)
return ret;
if (ret > 0) {
ret = write_frame(s, inlink, in);
ret = write_frame(ctx, s, inlink, in);
if (ff_inlink_queued_samples(inlink) >= 0)
ff_filter_set_ready(ctx, 100);
......@@ -522,7 +524,7 @@ static int activate(AVFilterContext *ctx)
if (s->eof && !sp_done (s->sp))
{
while (!sp_done (s->sp))
sp_write (s->sp, 0, 0);
sp_write (ctx, s->sp, 0, 0);
printf ("eof\n");
}
ret = try_read_frame(s, outlink);
......
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