From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A154744587 for ; Fri, 16 Sep 2022 18:20:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC3EB68BC3F; Fri, 16 Sep 2022 21:20:20 +0300 (EEST) 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-Google-Smtp-Source: AMsMyM5ea1eoMg3b5LUx8S4OeEF95OEGCcOTCmaij/ZsBtoYsWRQ09+iV5N4UvV7xRMV5FqxRgoNrA== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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; } } -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".