From patchwork Wed Feb 9 03:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34199 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1371782iov; Tue, 8 Feb 2022 19:30:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoTE7qq7/8MNHXopJ3d8Z0cCVRW0pELII8iBt7mTVAjzxCjMejO1EKQqk1k7of1bBvw455 X-Received: by 2002:a50:fc0d:: with SMTP id i13mr435581edr.180.1644377405911; Tue, 08 Feb 2022 19:30:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644377405; cv=none; d=google.com; s=arc-20160816; b=SuD9R2LaS7iiiv8a73x7zpnMWmYK2/Vsc0mb/JXlcBDGWqQWxG3ePNDVqyYuRM21Sh 1hw/57XoLVnS/LIyTBu2BiLi3Ok120/4rUaqRfflmJSblv2brwKtxBuRQT69j7rGShbt ChmloWGSo72Kh3JCxdSh101GdYLGNnmh4qYoZDZRpDkWNZCkZxFV2Px/L9iGIpq7tMtO DFzCnO47HlsTmz1GDLTcNvBLLZT0qRqjzR/vQaVwoCgUcIQaPOrJ2m16v+aaZcohuofM g9bXL5gY/FpwbqvqXxeYLIkrnoklymxnrW025cREffplLI3ZeFEtQz6SOc9Hw/n7a4Ud LRgQ== 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=vLCjw8NZ9UsMLOk/vT1h+KpSXIXKXLF3WOKGxSdYyEg=; b=OKBsI+97W/JP6PnvFFOfo79GZhJvDxQCbIAKI5v8Iz+xj5CDUM1uRraC/AhYSuNLEb wSlaWw6ilvUbtOOq5cF5DAEO3yg+NCK0tBYRA5EO6KLr8xcEMvjH/g44pqGSZrfPPKlx w8wqeQikua0lOotjFzIAlVS0CmU8czqj9z3Le79v6C6l3ZAFQ0V7JY96Shc7yORyXqYj GuQauawqOsYRulrEN90kXY2AKPMqp8i6+PqE54TUtdnlNW4iCR5XAZavWLFYc8+6FbSy B60SeM5YOJnLOSJbyvCLTiFiT5BFsAyskYFMhjHa8VCOaM1/OhRXaSH+EiY1P01dU1Nq DMFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=aeWM5IAC; 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 m21si9283865eda.471.2022.02.08.19.30.05; Tue, 08 Feb 2022 19:30:05 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=aeWM5IAC; 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 5871568B17E; Wed, 9 Feb 2022 05:29:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: d3shr+Dt9og/ 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; } }