Path: blob/master/dep/ffmpeg/include/libavutil/crc.h
4216 views
/*1* copyright (c) 2006 Michael Niedermayer <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920/**21* @file22* @ingroup lavu_crc3223* Public header for CRC hash function implementation.24*/2526#ifndef AVUTIL_CRC_H27#define AVUTIL_CRC_H2829#include <stdint.h>30#include <stddef.h>31#include "attributes.h"3233/**34* @defgroup lavu_crc32 CRC35* @ingroup lavu_hash36* CRC (Cyclic Redundancy Check) hash function implementation.37*38* This module supports numerous CRC polynomials, in addition to the most39* widely used CRC-32-IEEE. See @ref AVCRCId for a list of available40* polynomials.41*42* @{43*/4445typedef uint32_t AVCRC;4647typedef enum {48AV_CRC_8_ATM,49AV_CRC_16_ANSI,50AV_CRC_16_CCITT,51AV_CRC_32_IEEE,52AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */53AV_CRC_16_ANSI_LE, /*< reversed bitorder version of AV_CRC_16_ANSI */54AV_CRC_24_IEEE,55AV_CRC_8_EBU,56AV_CRC_MAX, /*< Not part of public API! Do not use outside libavutil. */57}AVCRCId;5859/**60* Initialize a CRC table.61* @param ctx must be an array of size sizeof(AVCRC)*257 or sizeof(AVCRC)*102462* @param le If 1, the lowest bit represents the coefficient for the highest63* exponent of the corresponding polynomial (both for poly and64* actual CRC).65* If 0, you must swap the CRC parameter and the result of av_crc66* if you need the standard representation (can be simplified in67* most cases to e.g. bswap16):68* av_bswap32(crc << (32-bits))69* @param bits number of bits for the CRC70* @param poly generator polynomial without the x**bits coefficient, in the71* representation as specified by le72* @param ctx_size size of ctx in bytes73* @return <0 on failure74*/75int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);7677/**78* Get an initialized standard CRC table.79* @param crc_id ID of a standard CRC80* @return a pointer to the CRC table or NULL on failure81*/82const AVCRC *av_crc_get_table(AVCRCId crc_id);8384/**85* Calculate the CRC of a block.86* @param ctx initialized AVCRC array (see av_crc_init())87* @param crc CRC of previous blocks if any or initial value for CRC88* @param buffer buffer whose CRC to calculate89* @param length length of the buffer90* @return CRC updated with the data from the given block91*92* @see av_crc_init() "le" parameter93*/94uint32_t av_crc(const AVCRC *ctx, uint32_t crc,95const uint8_t *buffer, size_t length) av_pure;9697/**98* @}99*/100101#endif /* AVUTIL_CRC_H */102103104