Nathan Caldwell <[email protected]> writes:
> Macroify sanity checks and check return value of allocs.
> ---
> libavcodec/aacenc.c | 37 ++++++++++++++++++-------------------
> 1 files changed, 18 insertions(+), 19 deletions(-)
>
> diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
> index b112fa8..4f80609 100644
> --- a/libavcodec/aacenc.c
> +++ b/libavcodec/aacenc.c
> @@ -46,6 +46,12 @@
>
> #define AAC_MAX_CHANNELS 6
>
> +#define RETURN_ON_ERROR( cond, ... ) \
^
Watch your whitespace -----+
> +if (cond) { \
> + av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
> + return AVERROR(EINVAL); \
> +}
Please consider making this a do { } while (0). Also indent the macro body.
Finally, I think something like ERROR_IF would be a better name.
> + RETURN_ON_ERROR(i == 16, "Unsupported sample rate %d\n",
> avctx->sample_rate);
> + RETURN_ON_ERROR(avctx->channels > AAC_MAX_CHANNELS, "Unsupported number
> of channels: %d\n", avctx->channels);
> + RETURN_ON_ERROR(avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile
> != FF_PROFILE_AAC_LOW, "Unsupported profile %d\n", avctx->profile);
> + RETURN_ON_ERROR(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 *
> avctx->channels, "Too many bits per frame requested\n");
> +
These could all use some nicer formatting.
> @@ -201,9 +197,10 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
> ff_init_ff_sine_windows(7);
>
> s->chan_map = aac_chan_configs[avctx->channels-1];
> - s->samples = av_malloc(2 * 1024 * avctx->channels *
> sizeof(s->samples[0]));
> - s->cpe = av_mallocz(sizeof(ChannelElement) *
> s->chan_map[0]);
> - avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE);
> + FF_ALLOC_OR_GOTO (avctx, s->samples, 2 * 1024 * avctx->channels *
> sizeof(s->samples[0]), fail);
> + FF_ALLOCZ_OR_GOTO(avctx, s->cpe, sizeof(ChannelElement) *
> s->chan_map[0], fail);
> + FF_ALLOCZ_OR_GOTO(avctx, avctx->extradata, 5 +
> FF_INPUT_BUFFER_PADDING_SIZE, fail);
Any of these which succeed need to be freed on error.
--
Måns Rullgård
[email protected]
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel