diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c index aaba313bf1..723ab6b92b 100644 --- a/libavcodec/huffyuv.c +++ b/libavcodec/huffyuv.c @@ -28,12 +28,11 @@ * huffyuv codec for libavcodec. */ +#include #include -#include "libavutil/attributes.h" -#include "libavutil/error.h" #include "libavutil/log.h" -#include "libavutil/mem.h" +#include "libavutil/macros.h" #include "huffyuv.h" @@ -59,26 +58,3 @@ int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int } return 0; } - -av_cold int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width) -{ - int i; - - for (i=0; i<3; i++) { - temp[i] = av_malloc(4 * width + 16); - if (!temp[i]) - return AVERROR(ENOMEM); - temp16[i] = (uint16_t*)temp[i]; - } - return 0; -} - -av_cold void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3]) -{ - int i; - - for(i = 0; i < 3; i++) { - av_freep(&temp[i]); - temp16[i] = NULL; - } -} diff --git a/libavcodec/huffyuv.h b/libavcodec/huffyuv.h index 22a766611e..62866b7a48 100644 --- a/libavcodec/huffyuv.h +++ b/libavcodec/huffyuv.h @@ -55,8 +55,6 @@ typedef enum Predictor { MEDIAN, } Predictor; -void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3]); -int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width); int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n); #endif /* AVCODEC_HUFFYUV_H */ diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index 29e5419d91..e390380867 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -323,7 +323,11 @@ static av_cold int decode_end(AVCodecContext *avctx) HYuvDecContext *s = avctx->priv_data; int i; - ff_huffyuv_common_end(s->temp, s->temp16); + for (int i = 0; i < 3; i++) { + av_freep(&s->temp[i]); + s->temp16[i] = NULL; + } + av_freep(&s->bitstream_buffer); for (i = 0; i < 8; i++) @@ -599,8 +603,12 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - if ((ret = ff_huffyuv_alloc_temp(s->temp, s->temp16, avctx->width)) < 0) - return ret; + for (int i = 0; i < 3; i++) { + s->temp[i] = av_malloc(4 * avctx->width + 16); + if (!s->temp[i]) + return AVERROR(ENOMEM); + s->temp16[i] = (uint16_t*)s->temp[i]; + } return 0; } diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index 0222565245..8329666fc0 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -430,12 +430,15 @@ static av_cold int encode_init(AVCodecContext *avctx) s->stats[i][j]= 0; } - ret = ff_huffyuv_alloc_temp(s->temp, s->temp16, avctx->width); - if (ret < 0) - return ret; - s->picture_number=0; + for (int i = 0; i < 3; i++) { + s->temp[i] = av_malloc(4 * avctx->width + 16); + if (!s->temp[i]) + return AVERROR(ENOMEM); + s->temp16[i] = (uint16_t*)s->temp[i]; + } + return 0; } static int encode_422_bitstream(HYuvEncContext *s, int offset, int count) @@ -1035,10 +1038,13 @@ static av_cold int encode_end(AVCodecContext *avctx) { HYuvEncContext *s = avctx->priv_data; - ff_huffyuv_common_end(s->temp, s->temp16); - av_freep(&avctx->stats_out); + for (int i = 0; i < 3; i++) { + av_freep(&s->temp[i]); + s->temp16[i] = NULL; + } + return 0; }