From 7d9d227a8443626c2525187d37dfe45a99fcbd13 Mon Sep 17 00:00:00 2001 From: James Almer Date: Sun, 6 Jun 2021 14:38:11 -0300 Subject: [PATCH] a52: propagate errors from do_encode() BugLink: https://github.com/alsa-project/alsa-plugins/pull/23 Signed-off-by: James Almer Signed-off-by: Jaroslav Kysela --- a52/pcm_a52.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index 2ccc478..ecf7430 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -111,25 +111,35 @@ static int do_encode(struct a52_ctx *rec) .data = rec->outbuf + 8, .size = rec->outbuf_size - 8 }; - int got_frame; + int ret, got_frame; + + ret = avcodec_encode_audio2(rec->avctx, &pkt, rec->frame, &got_frame); + if (ret < 0) + return -EINVAL; - avcodec_encode_audio2(rec->avctx, &pkt, rec->frame, &got_frame); return pkt.size; } #else static int do_encode(struct a52_ctx *rec) { - return avcodec_encode_audio(rec->avctx, rec->outbuf + 8, + int ret = avcodec_encode_audio(rec->avctx, rec->outbuf + 8, rec->outbuf_size - 8, rec->inbuf); + if (ret < 0) + return -EINVAL; + + return ret; } #endif /* convert the PCM data to A52 stream in IEC958 */ -static void convert_data(struct a52_ctx *rec) +static int convert_data(struct a52_ctx *rec) { int out_bytes = do_encode(rec); + if (out_bytes < 0) + return out_bytes; + rec->outbuf[0] = 0xf8; /* sync words */ rec->outbuf[1] = 0x72; rec->outbuf[2] = 0x4e; @@ -145,6 +155,8 @@ static void convert_data(struct a52_ctx *rec) rec->outbuf_size - 8 - out_bytes); rec->remain = rec->outbuf_size / 4; rec->filled = 0; + + return 0; } /* write pending encoded data to the slave pcm */ @@ -204,7 +216,9 @@ static int a52_drain(snd_pcm_ioplug_t *io) memset(rec->inbuf + rec->filled * io->channels, 0, (rec->avctx->frame_size - rec->filled) * io->channels * 2); } - convert_data(rec); + err = convert_data(rec); + if (err < 0) + return err; } err = write_out_pending(io, rec); if (err < 0) @@ -303,7 +317,9 @@ static int fill_data(snd_pcm_ioplug_t *io, } rec->filled += size; if (rec->filled == rec->avctx->frame_size) { - convert_data(rec); + err = convert_data(rec); + if (err < 0) + return err; write_out_pending(io, rec); } return (int)size; -- 2.47.1