aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-04-04 05:59:57 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-04-07 21:59:32 +0200
commitcf96c0295ea9c8f58617408ed68dbb1cba8d1682 (patch)
tree1c91f95a8cbde14fbdb21b376a3e32133147e436
parenteef5d60ac6200e0d4790d936c4e57656fe8502cc (diff)
downloadffmpeg-cf96c0295ea9c8f58617408ed68dbb1cba8d1682.tar.gz
avcodec/huffyuv(dec|enc): Use union for temp/temp16
These pointers already point to the same buffers, so using a union is possible and avoids the overhead of syncing the pointers (and saves some memory). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/huffyuvdec.c11
-rw-r--r--libavcodec/huffyuvenc.c11
2 files changed, 10 insertions, 12 deletions
diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index e390380867..12ecfcb933 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -70,8 +70,10 @@ typedef struct HYuvDecContext {
int context;
int last_slice_end;
- uint8_t *temp[3];
- uint16_t *temp16[3]; ///< identical to temp but 16bit type
+ union {
+ uint8_t *temp[3];
+ uint16_t *temp16[3];
+ };
uint8_t len[4][MAX_VLC_N];
uint32_t bits[4][MAX_VLC_N];
uint32_t pix_bgr_map[1<<VLC_BITS];
@@ -323,10 +325,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
HYuvDecContext *s = avctx->priv_data;
int i;
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++)
av_freep(&s->temp[i]);
- s->temp16[i] = NULL;
- }
av_freep(&s->bitstream_buffer);
@@ -607,7 +607,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
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 8329666fc0..4f709143a2 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -65,8 +65,10 @@ typedef struct HYuvEncContext {
int context;
int picture_number;
- uint8_t *temp[3];
- uint16_t *temp16[3]; ///< identical to temp but 16bit type
+ union {
+ uint8_t *temp[3];
+ uint16_t *temp16[3];
+ };
uint64_t stats[4][MAX_VLC_N];
uint8_t len[4][MAX_VLC_N];
uint32_t bits[4][MAX_VLC_N];
@@ -436,7 +438,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
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;
@@ -1040,10 +1041,8 @@ static av_cold int encode_end(AVCodecContext *avctx)
av_freep(&avctx->stats_out);
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++)
av_freep(&s->temp[i]);
- s->temp16[i] = NULL;
- }
return 0;
}