[FFmpeg-devel] [PATCH 1/3] avcodec: add avpriv_dca_compute_crc()

James Almer jamrial at gmail.com
Mon May 2 22:51:35 CEST 2016


On 5/2/2016 5:47 PM, foo86 wrote:
> ---
>  libavcodec/dca.c     | 18 ++++++++++++++++++
>  libavcodec/dca.h     |  5 +++++
>  libavcodec/dcadec.c  | 20 +-------------------
>  libavcodec/version.h |  2 +-
>  4 files changed, 25 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/dca.c b/libavcodec/dca.c
> index 714509b..be89d0d 100644
> --- a/libavcodec/dca.c
> +++ b/libavcodec/dca.c
> @@ -71,3 +71,21 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
>          return AVERROR_INVALIDDATA;
>      }
>  }
> +
> +int avpriv_dca_compute_crc(const uint8_t *data, int size)
> +{
> +    static const uint16_t crctab[16] = {
> +        0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
> +        0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
> +    };
> +
> +    uint16_t res = 0xffff;
> +    int i;
> +
> +    for (i = 0; i < size; i++) {
> +        res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)];
> +        res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)];
> +    }
> +
> +    return res;
> +}

Use AVCRC instead, with the AV_CRC_16_CCITT table. See libavutil/crc.h

I planned to replace the current usage with it some time ago, but decided against
it since it would be potentially more overhead for only some header checks. Now
however it makes sense to use it.


More information about the ffmpeg-devel mailing list