avcodec/huffyuv: Inline common alloc/free functions in their callers

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-04-04 05:53:09 +02:00
parent cebf1d59a5
commit eef5d60ac6
4 changed files with 25 additions and 37 deletions

View File

@ -28,12 +28,11 @@
* huffyuv codec for libavcodec. * huffyuv codec for libavcodec.
*/ */
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "libavutil/attributes.h"
#include "libavutil/error.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "libavutil/mem.h" #include "libavutil/macros.h"
#include "huffyuv.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; 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;
}
}

View File

@ -55,8 +55,6 @@ typedef enum Predictor {
MEDIAN, MEDIAN,
} Predictor; } 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); int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n);
#endif /* AVCODEC_HUFFYUV_H */ #endif /* AVCODEC_HUFFYUV_H */

View File

@ -323,7 +323,11 @@ static av_cold int decode_end(AVCodecContext *avctx)
HYuvDecContext *s = avctx->priv_data; HYuvDecContext *s = avctx->priv_data;
int i; 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); av_freep(&s->bitstream_buffer);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
@ -599,8 +603,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if ((ret = ff_huffyuv_alloc_temp(s->temp, s->temp16, avctx->width)) < 0) for (int i = 0; i < 3; i++) {
return ret; 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; return 0;
} }

View File

@ -430,12 +430,15 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->stats[i][j]= 0; 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; 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; return 0;
} }
static int encode_422_bitstream(HYuvEncContext *s, int offset, int count) 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; HYuvEncContext *s = avctx->priv_data;
ff_huffyuv_common_end(s->temp, s->temp16);
av_freep(&avctx->stats_out); av_freep(&avctx->stats_out);
for (int i = 0; i < 3; i++) {
av_freep(&s->temp[i]);
s->temp16[i] = NULL;
}
return 0; return 0;
} }