Commit 4874e76c authored by Stefan Westerfeld's avatar Stefan Westerfeld

avfilter/asubprocess: handle subprocess write errors

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 1bb6f13f
......@@ -137,7 +137,7 @@ sp_read (SP *sp, char *buffer, int count)
}
}
static void
static int
sp_write (SP *sp, char *buffer, int count)
{
int offset = 0;
......@@ -146,6 +146,8 @@ sp_write (SP *sp, char *buffer, int count)
close (sp->input_pipe);
sp->input_pipe = -1;
}
if (count && sp->done)
return AVERROR_EXTERNAL;
do
{
struct pollfd fds[2] = {
......@@ -185,10 +187,13 @@ sp_write (SP *sp, char *buffer, int count)
waitpid (sp->pid, &status, 0);
printf ("wstatus=%d\n", WEXITSTATUS (status));
sp->done = true;
return;
if (count)
return AVERROR_EXTERNAL;
return 0;
}
}
} while (count);
return 0;
}
static bool
......@@ -260,12 +265,13 @@ static av_cold void uninit(AVFilterContext *ctx)
#define NB_BUFFER_SAMPLES 4096
static void write_wav_header (ASubProcessContext *s, int nb_channels, int sample_rate)
static int write_wav_header (ASubProcessContext *s, int nb_channels, int sample_rate)
{
int bit_depth = s->in_bit_depth;
AVIOContext *wav_header = NULL;
uint8_t *buffer = NULL;
int size;
int ret;
avio_open_dyn_buf (&wav_header);
ffio_wfourcc(wav_header, "RIFF");
......@@ -285,8 +291,9 @@ static void write_wav_header (ASubProcessContext *s, int nb_channels, int sample
ffio_wfourcc (wav_header, "data");
avio_wl32 (wav_header, -1);
size = avio_close_dyn_buf (wav_header, &buffer);
sp_write (s->sp, buffer, size);
ret = sp_write (s->sp, buffer, size);
av_free (buffer);
return ret;
}
static int config_input(AVFilterLink *inlink)
......@@ -356,7 +363,7 @@ static void read_samples(ASubProcessContext *s, int32_t *data, int count)
}
}
static void write_samples(ASubProcessContext *s, int32_t *data, int count)
static int write_samples(ASubProcessContext *s, int32_t *data, int count)
{
int sample_size = s->in_bit_depth / 8;
......@@ -364,8 +371,7 @@ static void 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 */
sp_write(s->sp, (char *)data, sample_size * count);
return;
return sp_write(s->sp, (char *)data, sample_size * count);
}
#endif
if (s->in_bit_depth == 16)
......@@ -389,7 +395,7 @@ static void write_samples(ASubProcessContext *s, int32_t *data, int count)
for (int k = 0; k < count; k++)
AV_WL32(out + k, data[k]);
}
sp_write(s->sp, s->sample_buffer, sample_size * count);
return sp_write(s->sp, s->sample_buffer, sample_size * count);
}
static int write_frame(ASubProcessContext *s, AVFilterLink *inlink, AVFrame *in)
......@@ -397,7 +403,7 @@ static int write_frame(ASubProcessContext *s, AVFilterLink *inlink, AVFrame *in)
int ret = 0;
av_assert0(in->nb_samples <= NB_BUFFER_SAMPLES);
write_samples(s, (int32_t *)in->data[0], in->nb_samples * inlink->ch_layout.nb_channels);
ret = write_samples(s, (int32_t *)in->data[0], in->nb_samples * inlink->ch_layout.nb_channels);
av_frame_free(&in);
return ret;
}
......
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