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 C8D6640E51 for ; Wed, 9 Feb 2022 03:30:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 207F768B13C; Wed, 9 Feb 2022 05:29:35 +0200 (EET) Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3988D68B0A7 for ; Wed, 9 Feb 2022 05:29:26 +0200 (EET) Received: by mail-qk1-f171.google.com with SMTP id g145so683383qke.3 for ; Tue, 08 Feb 2022 19:29:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l3rEMpzdVAawVdf28yY7DNWLv6onDcGfeh3/qWeXGCs=; b=aeWM5IACfDlTbIKHgFg3mJ6LU2xDzVdtGFZ/MIyP3R86U2Dd4oskz8Fh/XoItNgyRT dNLR1ZXzUHXyAVRK2hAsv7yjnFylk2oMEqjCecF71KP6YECHQGeuaLu1nj61gljMeXI4 MHIvgS4JbBwDLIeIVzNamJi0rZeo8g9D519gjP379UI0gSCebUHb7Km2EgQVyMSsjWLK u31GFEEQ2ovYpgbad5CfdvxFoIwvh0qHmyUZltUWZzzSdDWvO43v04iZ8ovdSQMjjIBg qCShLD6G6oicEc5rks2nxldkkeALhdMc+HC55iUPiv9hhCeVokPLqg+Yl+q28O4T7JY9 Qqcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l3rEMpzdVAawVdf28yY7DNWLv6onDcGfeh3/qWeXGCs=; b=11TJDEzylG8QLr+l2KOxoUOziwfS7tVwalyfC8zoGieEWooJLZHji9a5ybUVgHKFwR 9Ro5GeWArB2AoqcmRLelhQPNYDoba98yDF61GiCOTC73M8YhBoMbtj2fo8MPPX9qiGol nx9M+kskTQp3lMvu7sfuPhClhte6Kc8e0e0/NKtFaDd36kGTNMRWvs2F2gwhaOY1F40R LpMFF+GGXCIbkYAdVC7FkbQrPp0s9E84or7pJhCjxw/F+37qOE/A2avtufC0m7pPLMXg teEsJub9iTuuR/gIp7R0y4M994Dv5XKUgQ4oz+7AZ33elqHSZImpQw86pa+EKNSrD8aR Yv1Q== X-Gm-Message-State: AOAM530j+/6R8UFC//igwK7CSuLvPLpEUU2jQizjeTti2YBY2+gfDb8r lRvCqH458AClTeZcZnrpQlg9XjMLOutPSw== X-Google-Smtp-Source: ABdhPJzioo6sFPVLSmh0XIBs35HM8ux8UKLKIPgjKOYiFwD+ZnMM+jwkYrGR54659YdC87oK1m/ZWw== X-Received: by 2002:a05:620a:15e8:: with SMTP id p8mr148258qkm.215.1644377364761; Tue, 08 Feb 2022 19:29:24 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id o19sm8452524qta.19.2022.02.08.19.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 19:29:24 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Feb 2022 22:28:49 -0500 Message-Id: <20220209032854.565698-4-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220209032854.565698-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220209032854.565698-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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. The comparisons (p[-1] > 1) and (p[-1] == 0) should be one comparison against 1 since p is unsigned, which makes (p[-1] == 0) equivalent to (p[-1] < 1) No other observable change. --- libavcodec/utils.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 42a1885d61..5b49657b44 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -953,12 +953,27 @@ 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 { + // UU UU UU + if (p[-1] > 1) { + p += 3; + // start check over with 3 new bytes + } + else if (p[-1] == 0) { + p++; + // could be in a start code, so check next byte + } + else if (/* UU UU 01 */ p[-2] != 0 || + /* UU 00 01 */ p[-3] != 0) { + p += 3; + } + else { /* 00 00 01 */ p++; + // p now points at the address following the start code value XX break; } } -- 2.32.0 _______________________________________________ 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".