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 9E64740963 for ; Tue, 1 Feb 2022 21:21:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5D4D68AFEF; Tue, 1 Feb 2022 23:21:15 +0200 (EET) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2377868AF51 for ; Tue, 1 Feb 2022 23:21:09 +0200 (EET) Received: by mail-qt1-f179.google.com with SMTP id r14so15641757qtt.5 for ; Tue, 01 Feb 2022 13:21:09 -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=MYRFh3Do6ITTaR9nSjPNKOI/Rvooyr5jCtxMJSTvGl4=; b=Fec50Poo5cJ2hOQ/gcHnPhd0gvhgnT0VIv2J42Kg6OGHB4cZd2IQ7HJmlbwe5/y/ac EsBI9E2CatfAiTPQaiuXhofxobxXP2LmQWaInN1lfd1bupf8456Cq82rizmJbGGtip8o CYR5A6A5qe0YJ7twyZS9u9wMNwaECafzXs4SMoVVu9oZAxPisTdr+VBYsQGMhzPUCgwW GKgG/+5aUKidJdLX0B4ZJEespZwKm+VZjXAq7v0dLYNHhtMXUux8tgCgoaRE9XWONy1v GiEeTpOxx3E2fuLTSJ11+6IEjRVpOxpjV69Loi9ERnx1hEWmOOO1mX2Tnu/D5s5EhemS N0jQ== 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=MYRFh3Do6ITTaR9nSjPNKOI/Rvooyr5jCtxMJSTvGl4=; b=hEITZjN5Y8tP1HNzKS17aCuH3s/NwmOe8sTBFrJocISc3Ch7gvjkFLO83mYm0qnK+r uXg6n7JLGTKHaiybQZDtUOSipOm+quiybhBkw3kibsw/mRuLTx4ShNebCdaI8Lk/2KB4 9TaqKqqVd9iwVxcmiXZ2ma2WU8EnY893hOEpUyI3uRGjXg7MRdrPw3G4jgMU23MydJxr e8ZEPe2dIEbcMxWjVUNAYzKl12dnz37h2VuDGHHuyVdqL4yMi1DYMdMIK6vM03M433ua e/qt8a7L4zF8QXidZlo/B9uj7THWTj2yQtmCmAfedYZnomoeuQLEuDIyTJuzi0hssBfe 4M5w== X-Gm-Message-State: AOAM532iJamKI5xnm+gksyd2rHZwntcZ0Ybcc/yqNfZpNvuBrB/vRrI+ 4K68gWEhhNcfAq/F2bqOKuMBgsetaZ/ZrQ== X-Google-Smtp-Source: ABdhPJzJlVYiGFlY8TZOzroYLu9tzYq0/YFB6dxFc1KSjsaLYIYE+CMg89EcQ5LTUK3PNZffIatuRA== X-Received: by 2002:a05:622a:199e:: with SMTP id u30mr15386582qtc.564.1643750467576; Tue, 01 Feb 2022 13:21:07 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id ay18sm2928225qkb.8.2022.02.01.13.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 13:21:07 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 16:20:50 -0500 Message-Id: <20220201212056.29712-3-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220201212056.29712-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] avpriv_find_start_code(): rewrite while loop and add comments for clarity 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. No functional change, but now much clearer. --- libavcodec/utils.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cb4437edc2..882f90be79 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -957,12 +957,26 @@ 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++; + // 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 + // this should be one comparison against 1 since p is unsigned, + // i.e. p[-1] == 0 is equivalent to p[-1] < 1 + + // UU UU 01 + else if (p[-2] != 0) p += 2; // we have UU YY 01, so increment by 2 + // to start check over with 3 new bytes + // UU 00 01 + else if (p[-3] != 0) p += 3; // we have YY 00 01, so increment by 3 + // to start check over with 3 new bytes + // 00 00 01 else { - p++; + p++; // p now points at the address following the start code value XX break; } } @@ -972,7 +986,8 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // this will cause the last 4 bytes before end to be read, // i.e. no out of bounds memory access occurs - *state = AV_RB32(p - 4); // read the previous 4 bytes + *state = AV_RB32(p - 4); + // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} return p; } -- 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".