From patchwork Sat Jul 6 14:18:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13833 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id BF3DB449D3B for ; Sat, 6 Jul 2019 17:25:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 95D1268ACD5; Sat, 6 Jul 2019 17:25:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4083868ACA9 for ; Sat, 6 Jul 2019 17:25:31 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id p74so8680593wme.4 for ; Sat, 06 Jul 2019 07:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x1Z2R3Qo7qtSBaTZT2CKRQ9ikYcl35JTd2eWqCUxmCY=; b=qziYNNE0eRS3zWwBspn3mBlaoM4s9jVRvBYCvePHfdJW4dCRqwTRbVwDQSsEruexju 0DRdkdbfNQrp9W2QY1qYnMYukk3Tmr7jTuAKFA/o3k8d05LM4T8uppLquLjtZERFzeL9 PXt8pTASwrHIryUEbJet/6mIzRA8vscS0shBwIAEVUFaKVoe3MUiijpZG8ViQqbF5fVF d/8V/XoPhPoMcN4uszssRSR5X/vzS9uwppuvtNqdN2Qs3iVV5Y0ZaWj/dRcAezefibCU qakXgyVzsQqmulT+27wvSy8ORVtjahC/z0lKI51vCXIt7s7bnyfgBSZAKJqsxL6KRmil ZuEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x1Z2R3Qo7qtSBaTZT2CKRQ9ikYcl35JTd2eWqCUxmCY=; b=hkslxiY32Md5u36OO8ozHfB8OwEgsLXPAAtqm6PYpMFpIVVsIXjSyfTwLaxVnIIdbZ RlUqYlkLGTZ39RYuHoPZg970Iob/1ku2XlxvboQv2Y4BYByGrxU+nS5gL+fGBJkUh2r1 vuFw5f19KpWafn6QjnwAr0gcUA+ii0515C1NDC7dBVKQHSb1Pjp6Wq4kFmc/4FDRv0Gj hEFPrS6bqcKjG76hftqTKIDF6GruMvUvPKdw+2qXolqyD6XsfZ4ErF5OzGTQd2etrzZX 9Bbt56mHCs5A+Lm/IBoQEGEad7KEy6NYK+eEAAViASPhs11tw0BL3biOsKa1W5eX7sM3 CVAw== X-Gm-Message-State: APjAAAXocc6WKm5+r/yw1jUmetZK0cygrH/h5BAlzQwcgG2T0atxtqpV WkCSbh4C2xbAmOm2NxNNRmw1HclP7fg= X-Google-Smtp-Source: APXvYqwkDjPjHiZ+yrdOg3wacq2u02xjLLca69LX5q+alXS7+K/vhqF5q/O74up8pXpBWj010K3aDw== X-Received: by 2002:a7b:cbc6:: with SMTP id n6mr8640896wmi.14.1562422702114; Sat, 06 Jul 2019 07:18:22 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b8f.dynamic.kabel-deutschland.de. [188.192.139.143]) by smtp.gmail.com with ESMTPSA id z7sm1331566wrh.67.2019.07.06.07.18.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 06 Jul 2019 07:18:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 6 Jul 2019 16:18:03 +0200 Message-Id: <20190706141804.12034-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190706141804.12034-1-andreas.rheinhardt@gmail.com> References: <20190706135911.11986-1-andreas.rheinhardt@gmail.com> <20190706141804.12034-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] truehd_core: Use byte offsets instead of bit offsets 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Words of 16 bit are the unit for TrueHD's size and offset fields; in particular the sizes of the high-level structures of TrueHD are always a multiple of a byte; yet truehd_core unnecessarily used bit offsets at several places. This has been changed. Signed-off-by: Andreas Rheinhardt --- libavcodec/truehd_core_bsf.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 47684235db..8ea80d3015 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -45,7 +45,7 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) int ret, i, last_offset = 0; int in_size, out_size; int have_header = 0; - int substream_bits = 0; + int substream_bytes = 0; int end; ret = ff_bsf_get_packet(ctx, &in); @@ -85,30 +85,32 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) units[i].offset = get_bits(&gbc, 12); if (i < 3) { last_offset = units[i].offset * 2; - substream_bits += 16; + substream_bytes += 2; } if (units[i].bits[0]) { units[i].optional = get_bits(&gbc, 16); if (i < 3) - substream_bits += 16; + substream_bytes += 2; } } - end = get_bits_count(&gbc); + end = get_bits_count(&gbc) >> 3; - out_size = ((end + 7) >> 3) + 4 + last_offset; + out_size = end + 4 + last_offset; if (out_size < in_size) { - int bpos = 0, reduce = (end - have_header * 28 * 8 - substream_bits) >> 4; + int bpos = 0, reduce = end - have_header * 28 - substream_bytes; uint16_t parity_nibble, dts = AV_RB16(in->data + 2); uint16_t auheader; + av_assert1(reduce % 2 == 0); + ret = av_new_packet(out, out_size); if (ret < 0) goto fail; AV_WB16(out->data + 2, dts); parity_nibble = dts; - out->size -= reduce * 2; + out->size -= reduce; parity_nibble ^= out->size / 2; if (have_header) { @@ -146,8 +148,8 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) parity_nibble &= 0xF; memcpy(out->data + have_header * 28 + 4 + bpos, - in->data + 4 + (end >> 3), - out_size - (4 + (end >> 3))); + in->data + 4 + end, + out_size - (4 + end)); auheader = (parity_nibble ^ 0xF) << 12; auheader |= (out->size / 2) & 0x0fff; AV_WB16(out->data, auheader);