[FFmpeg-devel] [PATCH v1 10/19] avcodec/vvcdec: verify picture hash
toqsxw at gmail.com
toqsxw at gmail.com
Tue Apr 1 20:16:07 EEST 2025
From: Wu Jianhua <toqsxw at outlook.com>
Signed-off-by: Wu Jianhua <toqsxw at outlook.com>
---
libavcodec/vvc/dec.c | 16 +++++++++++++++-
libavcodec/vvc/sei.c | 10 ++++++++++
libavcodec/vvc/sei.h | 3 +++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
index 4c0d08440a..6c36eb553e 100644
--- a/libavcodec/vvc/dec.c
+++ b/libavcodec/vvc/dec.c
@@ -1079,7 +1079,21 @@ static int frame_end(VVCContext *s, VVCFrameContext *fc)
}
}
- return ret;
+ if (!s->avctx->hwaccel && s->avctx->err_recognition & AV_EF_CRCCHECK) {
+ VVCSEI *sei = &fc->sei;
+ if (sei->picture_hash.present) {
+ ret = ff_vvc_sei_verify_hash(sei, fc->ref->frame, fc->ps.pps->width, fc->ps.pps->height);
+ if (ret < 0) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Verifying checksum for frame with decoder_order %d: failed\n",
+ (int)fc->decode_order);
+ if (s->avctx->err_recognition & AV_EF_EXPLODE)
+ return ret;
+ }
+ }
+ }
+
+ return 0;
}
static int wait_delayed_frame(VVCContext *s, AVFrame *output, int *got_output)
diff --git a/libavcodec/vvc/sei.c b/libavcodec/vvc/sei.c
index 2d81ae5908..c955d9921f 100644
--- a/libavcodec/vvc/sei.c
+++ b/libavcodec/vvc/sei.c
@@ -136,5 +136,15 @@ int ff_vvc_sei_replace(VVCSEI *dst, const VVCSEI *src)
void ff_vvc_sei_reset(VVCSEI *s)
{
ff_h2645_sei_reset(&s->common);
+ ff_h274_hash_freep(&s->hash_ctx);
s->picture_hash.present = 0;
}
+
+int ff_vvc_sei_verify_hash(VVCSEI *s, const AVFrame *frame, const int coded_width, const int coded_height)
+{
+ const int ret = ff_h274_hash_init(&s->hash_ctx, s->picture_hash.hash_type);
+ if (ret < 0)
+ return ret;
+
+ return ff_h274_hash_verify(s->hash_ctx, &s->picture_hash, frame, coded_width, coded_height);
+}
diff --git a/libavcodec/vvc/sei.h b/libavcodec/vvc/sei.h
index 6e4855bf60..a8aedc2837 100644
--- a/libavcodec/vvc/sei.h
+++ b/libavcodec/vvc/sei.h
@@ -36,6 +36,8 @@
typedef struct VVCSEI {
H2645SEI common;
H274SEIPictureHash picture_hash;
+
+ H274HashContext *hash_ctx;
} VVCSEI;
struct VVCFrameContext;
@@ -43,5 +45,6 @@ struct VVCFrameContext;
int ff_vvc_sei_decode(VVCSEI *s, const H266RawSEI *sei, const struct VVCFrameContext *fc);
int ff_vvc_sei_replace(VVCSEI *dst, const VVCSEI *src);
void ff_vvc_sei_reset(VVCSEI *s);
+int ff_vvc_sei_verify_hash(VVCSEI *s, const AVFrame *frame, int coded_width, int coded_height);
#endif /* AVCODEC_VVC_SEI_H */
--
2.44.0.windows.1
More information about the ffmpeg-devel
mailing list