Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avutil/hash: add 16-bit CRC type CCITT_AUG
@ 2025-03-25 14:59 Nuo Mi
  0 siblings, 0 replies; only message in thread
From: Nuo Mi @ 2025-03-25 14:59 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Nuo Mi

It is also referred to as:
    SPI-FUJITSU
    AUG-CCITT
    CRC-CCITT (0x1D0F)
This CRC type used by H.274
---
 libavutil/hash.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavutil/hash.c b/libavutil/hash.c
index fbc24194de..3659c71c7f 100644
--- a/libavutil/hash.c
+++ b/libavutil/hash.c
@@ -55,6 +55,7 @@
     ENTRY(SHA384,     "SHA384",     48) \
     ENTRY(SHA512,     "SHA512",     64) \
     ENTRY(CRC32,      "CRC32",       4) \
+    ENTRY(CCITT_AUG,  "CCITT_AUG",   2) \
     ENTRY(ADLER32,    "adler32",     4) \
 
 enum hashtype {
@@ -138,9 +139,10 @@ int av_hash_alloc(AVHashContext **ctx, const char *name)
     case SHA384:
     case SHA512:  res->ctx = av_sha512_alloc(); break;
     case CRC32:   res->crctab = av_crc_get_table(AV_CRC_32_IEEE_LE); break;
+    case CCITT_AUG:    res->crctab = av_crc_get_table(AV_CRC_16_CCITT); break;
     case ADLER32: break;
     }
-    if (i != ADLER32 && i != CRC32 && !res->ctx) {
+    if (i != ADLER32 && i != CRC32 && i != CCITT_AUG && !res->ctx) {
         av_free(res);
         return AVERROR(ENOMEM);
     }
@@ -165,6 +167,7 @@ void av_hash_init(AVHashContext *ctx)
     case SHA384:  av_sha512_init(ctx->ctx, 384); break;
     case SHA512:  av_sha512_init(ctx->ctx, 512); break;
     case CRC32:   ctx->crc = UINT32_MAX; break;
+    case CCITT_AUG:   ctx->crc = 0x0F1D; break; //Byte swapped value of 0x1D0F
     case ADLER32: ctx->crc = 1; break;
     }
 }
@@ -185,7 +188,8 @@ void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
     case SHA512_256:
     case SHA384:
     case SHA512:  av_sha512_update(ctx->ctx, src, len); break;
-    case CRC32:   ctx->crc = av_crc(ctx->crctab, ctx->crc, src, len); break;
+    case CRC32:
+    case CCITT_AUG: ctx->crc = av_crc(ctx->crctab, ctx->crc, src, len); break;
     case ADLER32: ctx->crc = av_adler32_update(ctx->crc, src, len); break;
     }
 }
@@ -207,6 +211,7 @@ void av_hash_final(AVHashContext *ctx, uint8_t *dst)
     case SHA384:
     case SHA512:  av_sha512_final(ctx->ctx, dst); break;
     case CRC32:   AV_WB32(dst, ctx->crc ^ UINT32_MAX); break;
+    case CCITT_AUG: AV_WB16(dst, ctx->crc); break;
     case ADLER32: AV_WB32(dst, ctx->crc); break;
     }
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-25 14:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-25 14:59 [FFmpeg-devel] [PATCH] avutil/hash: add 16-bit CRC type CCITT_AUG Nuo Mi

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git