From patchwork Fri Sep 16 18:19:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37963 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139658pzh; Fri, 16 Sep 2022 11:20:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Gh0/fcSsmW0K0TCyP8thdYEihtRJdXCZp8GZWwPVYzlTgy8hJWb5mpeInkRTRaZRQfp7D X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr4537712ejc.208.1663352452856; Fri, 16 Sep 2022 11:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352452; cv=none; d=google.com; s=arc-20160816; b=X9cC7RjXCm9g4vnyos8Kat/6YzIGhNVA6OMCwwb+Qs0gibK/tcYikYXe/3lzsV7dKA 3YxFP59Rj7ye1qjn074TzGVZQjReFpean6a1gb9Pgzeavv4VfgXElb3QQP3tiHYsHH5h Iqkyy0rzYrJkJC/fXBNK2GplY2mnK7Fh8m4B89pU2Z60q9QaY7Pmc/fgTXQqHVZF8imk 827LU1wzrl9YRZKZ27dWKdQKmNVgZ/JsZhdZ8Gyh2nReHfYArXAwzLKJC032Rs3FAhyJ iD1sxaQiT9i/UbMwka4OIOm7FMirX0YIZ2sJbJ9W09D0zxR4EdGIaBVX9Lleja5On7Dq g3Pg== 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=Wwsk8PkWNAZu1MbnpARYmH5je2mGLCO3xKNHs8/0fho=; b=NeYsjE3ALYMEdpC0kj+ZEGUVbAfw916PktXCS9y8xIqmJhwQqKVcs1FjoT//2Mfxro Iwn+QwrbNa0/R9MKXTu48zTc1+hHuOHKO1kMpmaARqFzpOU1cTb4ct8bxVDPL4Cdfg1K yMIpE+02EO6/M0GCXwsj03AkC6iMkVEJW4+eESj694hPzEWpNLIphy1rk9rWOv8OHwx3 6mK2gpWB0eE6uH7i0+j4Mg1EAURQjkGG7UJY+f9+CFvaUMrHLmO0uVEaspT5Ymtdk8na X9bXFi+gykOzd4v7R3642q2bGBhnzuUf1CfXStHayGD4ozqt6tAOoT3L7OhDeLyhs//o WsJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NMpluhwi; 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 v14-20020a056402348e00b004467fff4228si3139305edc.567.2022.09.16.11.20.52; Fri, 16 Sep 2022 11:20:52 -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=NMpluhwi; 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 3249268BC46; Fri, 16 Sep 2022 21:20:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 69B8C68BC10 for ; Fri, 16 Sep 2022 21:20:13 +0300 (EEST) Received: by mail-qv1-f52.google.com with SMTP id l14so8798443qvq.8 for ; Fri, 16 Sep 2022 11:20:13 -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=pZJvhZtBz1h2InTg2uBeMmZse3v1WPSkmDH2rb8K9jA=; b=NMpluhwiZWZ5KOOpL88P3hUDaqQXgDVpkUWxIxagdgyBBiIdTaW7AKR0c2Ax0Yb49y egWT2i/5n6jpR8oe6dji7koucAZpkK9UVG7zT32/bvI1+1et7MBXL2mJNL5Z1EDzrqo2 4/E5OF1Ez3xfZQt2RHB8njArgYfzGw/hyCEOQZsguFmrXCRUu1I7VRUdI3d8sPOtJOeW B6/4SLWhmVHFooRtNg2x89dXkF7ed+XuGnZOK4LyEgkLBNzIG78X5YNGuN99XBi024Cx 6WwLqdcIjS/w0yVrubQTjdbo8J3yBln4v096O9OIZkDDN+V3zrKYBnQ0vwQfvVd/8S1e UFLQ== 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=pZJvhZtBz1h2InTg2uBeMmZse3v1WPSkmDH2rb8K9jA=; b=iGjQMURL2VID/x8POr5LN4AB13t1SRsA3f9RnK5xG78ANmedKDC7Nq0A2g7uUS5T+a bRZqcYCh8kxzBjCI2bgz4Wpt2w8EayhtYuUfB+fixNFuBIp3T2ZJcv1wuvzeFQCUoLrp qz99SeazXLJpxiPEBaqLJswmbIV18X7+SZ/5Urev8JJjJsoPO4H6+1E87mP1HEnJ8jmV ADq3xA+EJNrPD+p7wnh2W3txPRriFGlJjyseoyJgelkSndviOOtiAKdoT/NrNZH1M/qZ 2i7L6CAagsZiYrQcKcF2cASEtscjoTCWo/wJHrj6H48WYB/9ol7NJOwJlZ3piKgiud+1 6B7w== X-Gm-Message-State: ACrzQf2H35hDin/X7pNm/vTdsO5f9rf/FuCSRi6yHQKos3KqcoN8+ki0 gCSqOqI6HEj8mMHKqYr38hiis1Grqc8= X-Received: by 2002:a0c:dd01:0:b0:4a9:35af:ea49 with SMTP id u1-20020a0cdd01000000b004a935afea49mr5555785qvk.29.1663352411820; Fri, 16 Sep 2022 11:20:11 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:11 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:58 -0400 Message-Id: <20220916182002.122699-5-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 4/8] avpriv_find_start_code(): rewrite for loop 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: parY1DQ+2tR+ --- libavcodec/utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index fc8cd87366..83f7d8a01a 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -983,18 +983,20 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, uint32_t *av_restrict state) { - int i; - av_assert0(p <= end); if (p >= end) return end; - for (i = 0; i < 3; i++) { - uint32_t tmp = *state << 8; - *state = tmp + *(p++); - if (tmp == 0x100 || p == end) + // read up to the first three bytes in p to enable reading a start code across + // two (to four) buffers + for (int i = 0; i < 3; i++) { + *state <<= 8; + *state += *p; + p++; + if (start_code_is_valid(*state) || p == end) return p; } + // p is now properly incremented for the negative indices in the while loop /* with memory address increasing left to right, we are looking for (in hexadecimal): * 00 00 01 XX