--- libavutil/crc.c | 20 ++++++++++++++++++++ libavutil/crc.h | 12 ++++++++++++ 2 files changed, 32 insertions(+)
diff --git a/libavutil/crc.c b/libavutil/crc.c index 8e44a76ec8..cb26a09a20 100644 --- a/libavutil/crc.c +++ b/libavutil/crc.c @@ -413,3 +413,23 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc, return crc; } + +uint32_t av_crc_bits(const AVCRC *ctx, uint32_t crc, + const uint8_t *buffer, size_t length) +{ + size_t byte_length = length >> 3; + int bit_length = length & 7; + + crc = av_crc(ctx, crc, buffer, byte_length); + + if (bit_length) { + uint8_t bits = buffer[byte_length]; + while (bit_length--) { + int8_t mask = (bits ^ crc); + crc = (crc << 1) ^ (ctx[1] & (mask >> 7)); + bits <<= 1; + } + } + + return crc; +} diff --git a/libavutil/crc.h b/libavutil/crc.h index e57a1af903..bde31f858a 100644 --- a/libavutil/crc.h +++ b/libavutil/crc.h @@ -86,6 +86,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id); /** * Calculate the CRC of a block. * @param crc CRC of previous blocks if any or initial value for CRC + * @param length number of bytes in the given block * @return CRC updated with the data from the given block * * @see av_crc_init() "le" parameter @@ -93,6 +94,17 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id); uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length) av_pure; +/** + * Calculate the CRC of a block with bits boundary. + * @param crc CRC of previous blocks if any or initial value for CRC + * @param length number of bits in the given block + * @return CRC updated with the data from the given block + * + * @see av_crc_init() "le" parameter + */ +uint32_t av_crc_bits(const AVCRC *ctx, uint32_t crc, + const uint8_t *buffer, size_t length) av_pure; + /** * @} */ -- 2.15.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel