diff options
author | Marton Balint <cus@passwd.hu> | 2025-01-07 00:02:47 +0100 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2025-01-25 20:10:41 +0100 |
commit | 7d9f373984c39fd87a22025efbe2f195e79f9acf (patch) | |
tree | 4081dbf4452054f7b9ea0eea0467a74c5684a3b6 /libavcodec/encode.c | |
parent | a0a89efd0778a8021c2d7077f82531d4f955f459 (diff) | |
download | ffmpeg-7d9f373984c39fd87a22025efbe2f195e79f9acf.tar.gz |
avcodec/mpegvideo_enc: add checks for custom inter/intra/chroma matrices
Make the checker functions available for all codecs.
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavcodec/encode.c')
-rw-r--r-- | libavcodec/encode.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 3baf5b8103..cd10dcf3cd 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -936,3 +936,22 @@ AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx) return props; } + +int ff_check_codec_matrices(AVCodecContext *avctx, unsigned types, uint16_t min, uint16_t max) +{ + uint16_t *matrices[] = {avctx->intra_matrix, avctx->inter_matrix, avctx->chroma_intra_matrix}; + const char *names[] = {"Intra", "Inter", "Chroma Intra"}; + static_assert(FF_ARRAY_ELEMS(matrices) == FF_ARRAY_ELEMS(names), "matrix count mismatch"); + for (int m = 0; m < FF_ARRAY_ELEMS(matrices); m++) { + uint16_t *matrix = matrices[m]; + if (matrix && (types & (1U << m))) { + for (int i = 0; i < 64; i++) { + if (matrix[i] < min || matrix[i] > max) { + av_log(avctx, AV_LOG_ERROR, "%s matrix[%d] is %d which is out of the allowed range [%"PRIu16"-%"PRIu16"].\n", names[m], i, matrix[i], min, max); + return AVERROR(EINVAL); + } + } + } + } + return 0; +} |