From patchwork Wed Dec 20 19:58:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jacobs X-Patchwork-Id: 6871 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp3370781jad; Wed, 20 Dec 2017 11:58:39 -0800 (PST) X-Google-Smtp-Source: ACJfBosMWKBnTCKowTWrUNExEABlS5BAhHKkFoiwTpDMBkI8LrIKIpI2FeGT2TJDRxaEDTJ+n9LN X-Received: by 10.28.107.211 with SMTP id a80mr7386048wmi.71.1513799919214; Wed, 20 Dec 2017 11:58:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513799919; cv=none; d=google.com; s=arc-20160816; b=nBkgRNgDXl7Y3bbpJAq5/zv91OfwAUxHpvXaVFBMABDnp1NjpCe/g1yW6OQKQSHtcd 7Xv52SN5iybN1mCeK1yq52oNGxcurzcLftYyPvNJ2ZFDLdeOPYHs9hszukd+KVV6zgDH C2C+9PmL4IzGXlcqAOLBWxk535nZOkQMtM5eL8s05A/nfn6x6fyiLtRnOP1Ihfq1ZhXe eTEuLz4HZTCli4OhBb/yAt8BV44VMJsn7Eh7T/W44woHbyqh3qoiJ74o3SP8tWpwvKJD 3tT2bVdsUNFJwHvCv3GOsb1ebwXu9zuI5FI4VTiyAqvwq/Lm2FIWVu0B4nIhP7YRuoT/ FcfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=JzfRxCUvQrY3n0Sbb+9q1NCFMiBNZYEYvXJNZEEldKw=; b=fNzwQcXPX5dvsi20/7MrP/5aiqDYBp6JHDs/0r5QX04he1UA8pJGWCwkRPf3DxdceB 28W/hQaigTzY88eQpKP8+IXCODa7fsQY7IniWroIfI2Yz/hCj/ziFQ64FeHKRE0ybOIb 7+pXx8CINIJQq3cbWTRzcjgMKhp0+5s4WlrL/oJ2scSTq5Y38GuVXsKebYn8vT8Z5/6O fybJy06j4rEjptZ7xGqkqGIlhaY6PW8N+sgXIG66A/J6AHHGRHzbBCssxStZR3hE6qAi fetDjJe6GwiXllskU1VmSMOmohtwdVzWklE7wWN9NDRTNMnpq2a26sGXhJIunCE3sxVf NBpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 11si1170253wra.131.2017.12.20.11.58.38; Wed, 20 Dec 2017 11:58:39 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D33026807BF; Wed, 20 Dec 2017 21:58:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 08EC768064D for ; Wed, 20 Dec 2017 21:58:14 +0200 (EET) Received: from marge.gnuage.org (unknown [IPv6:2a01:e35:2e26:9790::10]) by smtp6-g21.free.fr (Postfix) with ESMTPS id 15620780333 for ; Wed, 20 Dec 2017 20:58:25 +0100 (CET) Received: from [2a01:e35:2e26:9790:bc8a:b994:5b68:84cc] (helo=xps) by marge.gnuage.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eRkVU-00072u-At; Wed, 20 Dec 2017 20:58:24 +0100 Received: from aurel by xps with local (Exim 4.90_RC4) (envelope-from ) id 1eRkVU-0004lT-7t; Wed, 20 Dec 2017 20:58:24 +0100 From: Aurelien Jacobs To: FFmpeg development discussions and patches Date: Wed, 20 Dec 2017 20:58:06 +0100 Message-Id: <20171220195814.18269-2-aurel@gnuage.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171220195814.18269-1-aurel@gnuage.org> References: <20171220195814.18269-1-aurel@gnuage.org> X-SA-Exim-Connect-IP: 2a01:e35:2e26:9790:bc8a:b994:5b68:84cc X-SA-Exim-Mail-From: aurel@gnuage.org X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on marge.gnuage.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=3.0 tests=BAYES_00, FSL_HELO_NON_FQDN_1, RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on marge.gnuage.org) Subject: [FFmpeg-devel] [PATCH 02/10] crc: add av_crc_bits() to compute CRC on block with bit boundary X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Aurelien Jacobs MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- 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; + /** * @} */