.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;
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 */
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)
}
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;