From patchwork Fri Sep 16 18:19:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37962 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139596pzh; Fri, 16 Sep 2022 11:20:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GVeKMR4TUYLDQ4wBRBbC+B1GZpGtpANLFK2qeRBCPaRU/xO/3KOcEM1t0HH0+MiKHUA3K X-Received: by 2002:a05:6402:d05:b0:425:b7ab:776e with SMTP id eb5-20020a0564020d0500b00425b7ab776emr5222266edb.142.1663352444685; Fri, 16 Sep 2022 11:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352444; cv=none; d=google.com; s=arc-20160816; b=B5R51xOm5zfH6h4emDxHXnXW3bIhI0ijiK3FORn09sUcSkDxMNBgWvBCPf1L/ita3/ RYOFqppjwaY+7PbRoQ/lHGFv1EnIxiFw6TUMa9EpRMh8powL5wVd4LNgU7BNliiX1gbQ K/IDvYufKTIzoSoRA8WYWkpWIVVv+SUqdbuoEgNUVvSM9YP+afPkupLyVS95PYW1QSzO 37XJ8GbP06+NBGIVYHdGU0zV6r3zMzqf1Ls0XNR/ycCF8F0tKjtoAzZj7YmHOa+rmI7h IK+PiZZ3PH+fJEgV0kArAZfDx77hv67yi6/8p3iKfXfkGHlKlza+h9nkmoM0NHIfbzuu a+LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=qIauUZRix8RS0hgyayuP8bVkYeZs+DR4cD0GHP1l2cQ=; b=z3fRxLn/1xDHJTbMjQJUFODQ5dlL+XfqzJIfpqEl2eOzlGbF+P7j0UKmiOqtudsnER j5crX7wiX+fWZ0mGMDSgKJKXh439EHmlXd3CphyMzWBolumrr/2mqT/AdE1S3Fr8ux0F D/Y+IGj3JXrV7Fdc2hJ7QyYLwuWxZphRdj4g2cyE/8ty8BgqbBDP7Hu6t8LnTMuzsbV+ adQ03P/rHHUqe2yWMnZsLTbrfGpGIOVlVQynjdXzSs47pLEz/Ye4F4zOfvv8MHZPnPaR vr9SAJmXCjlBVGwQ5o4hijbpQNf7s/1Avef1ZG4ZSH9LGzYBUHi+6YAR4hB9493TVK6m kYbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HJOnKK0r; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id nc13-20020a1709071c0d00b0077e6bd32780si12719529ejc.779.2022.09.16.11.20.44; Fri, 16 Sep 2022 11:20:44 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HJOnKK0r; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2CDAC68BC45; Fri, 16 Sep 2022 21:20:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 744CA68BBF4 for ; Fri, 16 Sep 2022 21:20:12 +0300 (EEST) Received: by mail-qv1-f53.google.com with SMTP id c6so17239380qvn.6 for ; Fri, 16 Sep 2022 11:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=kIWquZzIEQsa9jU4vI/flF82u8sxxCq/p+lt+JlRtoo=; b=HJOnKK0rL1O0a4c2G4JX2j6dlxzDxFr+p2P7e3/d8rZDbZD41fjULWecge2k2xVgJN nSR3m9O1A3N8uCBGUZ/qOhDlUDcY8MC1OSLaHjod8YJF0s/gxLnc7pHRzK1U0vaKEPf8 mv9fRYTstj0OH/b9we2t/jHr5GZfzKV+y1ZcR2oqFwBAB8dChHQhzkcZWRlI64gWM+bA JQitR899BerrKhq25LgyBwIPdA7p+7g7c7196ORrWJ2YhrTUzKIyCFSNywE+Kv88/O/j i6tRM0950+DYuFX7DOr1jrcbnEO3n6U6LjwiCLeYNLedGsSSBolNH8X8So9R0J7DPheG gmFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=kIWquZzIEQsa9jU4vI/flF82u8sxxCq/p+lt+JlRtoo=; b=mOXxoFZiW7hluMpR02xfCS0+qfKIVu768Wc+VhdsYOgDUQrc8AWM/eiWb+R78wS+h3 SoArF8gg6JLhoVzzs5BjC/agablVQqHXRBDASbuvusZ/PnfBfU+rqBnnKg2vJbzWHBSo Bn4nBw5qhLhOdz6u7TUPLLP3op0f/aRtFSWhPtuOS6H+oNsfD7SUORHkvrIhZK/7kxfQ yNIXIbzB5Wwi5y0ts/Lk1vZy8oj8I3+HBbLLaVAyR8kXryCjKu0zLUdcVMGDDUyYsTYS Grx++23jizEu1D3JNDwqlyF85aLWKBW7Kn3bBpWHxAt/BZJmxsnsKb6cUlR+zj4JHn54 FXWA== X-Gm-Message-State: ACrzQf1BXw9tUewBGCnDGt/OCp0y7aIL0A4pXxzEatxI0uWTUGUj2KIE vlIqKw7PaIJXzjvFWGfL8bue9hyaU9s= X-Received: by 2002:a05:6214:5298:b0:4ac:c9f9:9091 with SMTP id kj24-20020a056214529800b004acc9f99091mr5529980qvb.25.1663352410973; Fri, 16 Sep 2022 11:20:10 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:09 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:57 -0400 Message-Id: <20220916182002.122699-4-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/8] avpriv_find_start_code(): rewrite while loop X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Scott Theisen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Fg0yeLEl6YAl The expected number of iterations may increase by one for an input of alternating 0 and 1 bytes. Instead of incrementing by 2 everytime, it now alternates between incrementing by 1 and by 3. For the check p[-2] != 0: This slightly reduces the number of iterations by starting with three new bytes on the next iteration, instead of keeping byte p[-3] which is invalid, since it is now known to be 01 when it must be 00. No other observable change. --- libavcodec/utils.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index d6ab21b1a0..fc8cd87366 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -996,12 +996,24 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, return p; } + /* with memory address increasing left to right, we are looking for (in hexadecimal): + * 00 00 01 XX + * p points at the address which should have the value of XX + */ while (p < end) { - if (p[-1] > 1 ) p += 3; - else if (p[-2] ) p += 2; - else if (p[-3]|(p[-1]-1)) p++; - else { + if (/* UU UU UU */ p[-1] < 1) { // equivalently p[-1] == 0 p++; + // could be in a start code, so check next byte + } + else if (/* UU UU UN */ p[-1] > 1 || + /* UU UU 01 */ p[-2] != 0 || + /* UU 00 01 */ p[-3] != 0) { + // start check over with 3 new bytes + p += 3; + } + else { /* 00 00 01 */ + p++; + // p now points at the address following the start code value XX break; } }