From patchwork Wed Feb 9 03:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34200 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1371848iov; Tue, 8 Feb 2022 19:30:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFWTqyHGDj4AyEaEEyb8V6jKzSc15F3FQMAj+/l3Rcag7pMdizzBsg0os4XxXE7iyXnAe/ X-Received: by 2002:aa7:c043:: with SMTP id k3mr430500edo.184.1644377416424; Tue, 08 Feb 2022 19:30:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644377416; cv=none; d=google.com; s=arc-20160816; b=Ipe5r+myaBjGnJYF7PAf6SfxRtccxz5TdJ4XXCGu3Hy/U/uCsZQeDZN+YthtDelQRm jQ17qE5YFKwLq2BNMzKA/bp61LqdgSkflTJLSbY1nTKgPLqwPs13tN8wwaMl0iNFerXr EJX9FHbm2O37ZbI7fkHYFcn8SYkm+7Xz5aKk3HMtQsvpKMRoNFOh5ck7CRuQHYeN8bd1 ac/Q7Nft5kLzLyBvbR2jaZXZswyGDn21r42D2EGaknSzZj0gIqWzYXahfMpa8n4GPVcf k0D+FE3iYAwAQ3H5CeCKdKNF+Ty3I1aijWYl4wuXJr9T1Ihwv/rQmq4UwRW+q00DJjec Cn5w== 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=H8gu/ObslYfVJV20H6CWIUScof98vNl2xi0pX/UI9HY=; b=ZvfkDOYzDrcgFF5KtkbhJxpw/W/9o/Mx1Do462hhEL/LWfLO1f20tciri3X2LCLe2L b6zcXnlBXG2z1/5W8fX9qEmjBCnSzIk/Pw8AT4R98hkpr2809bl5Mw2iN7AUzii7sIiY 8T1rDR7QilRSaXN3LCCdZctofis0P0z0oF5JgLv2xNBT+vYsgNCMrXER0AwJlIg4krNU Y67sasFecI8hakNUG7DNJGkGBXIJVbUEs+mTasaEpI8RV4yVYIylSJrLfltZ7np/IKUd 0A4pjUbqfYkpOzAzS8j3B5cD5uMLUhlD2MIV9ZjiCPFtfjoJCkt+lB8dFnZOzLN1F41k uqIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=WW06u4w2; 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 o9si11941992edc.202.2022.02.08.19.30.15; Tue, 08 Feb 2022 19:30:16 -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=WW06u4w2; 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 438A368B19F; Wed, 9 Feb 2022 05:29:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B14868B0C6 for ; Wed, 9 Feb 2022 05:29:27 +0200 (EET) Received: by mail-qt1-f170.google.com with SMTP id p14so887151qtx.0 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=7hyE7DIsE8bBOtIfJHk8YcJcaAH6tcw3TDF4C5w6fCk=; b=WW06u4w2wqkT3eNgIv36TniPGj/P13ozhAaXAPUyuPUSMX+2LuYWSm3Sa8P7bFqJkv a3k1JePdWP6kmXhx2Trbxsv2haifY5khBoDcGQ+cKoZaFwZlfuvZBwQeZyb3YA4mvKZd aoemFOzOCi1iyx1ml5gpeG7uNdatDJR20e+tfHvoSrRBdFZFLEFxvqDnljI0Rl3n2wUc VXNphaOoxCg5BDy9XfafbWC50gkYL3TR3ZU0WjfMp0LdWgGwVs/mzxdqVHNma+PWYGaG 0DIscBbUH/y8U4lg/YrQjfNAujFDG+NNI4W+C3maJrI1J5SrgcagydSE2V8kWm9+y0J0 EQCQ== 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=7hyE7DIsE8bBOtIfJHk8YcJcaAH6tcw3TDF4C5w6fCk=; b=uffq3Nvn3+nqvPMhy9h/Y6vjHgj5tzSS+h+4aNgl+kL1DMvZ0/bEfJxtuwjUHwpszP y+MhH0X413pys7EqJ+oTYseNe3L3T7qcwEuAZU1MElRE3kMd25q1YQCxPPbwq1a4CdQv sI94gbd1K7r0gQxpkDHLLEDZgsLuV5Dj88kIEaIVBpeM+7NIKgY5tHgAihMcfVsVEVkk cpdlnd+pQE3ibbsxvNVBJ9OcI968s3uEqOA/naUeGb31XZ8Z+5eo8R8z27qsuQKexosk dabjSzKOwPji3inQQTxUX4MyfWGnKVYTSt8ND2BFlUwXZ5tFvelwhIZ5QWcsttkt8woc 4jgw== X-Gm-Message-State: AOAM533/c0dT03EehjUGShiNKmrKbAgHOm9V4+2ZS9GtdgBkVYH551ZL efUuTkX5tLmpElNN05b5CYgbhNhkAoTS9w== X-Received: by 2002:a05:622a:22a1:: with SMTP id ay33mr157221qtb.396.1644377365547; Tue, 08 Feb 2022 19:29:25 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id o19sm8452524qta.19.2022.02.08.19.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 19:29:25 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Feb 2022 22:28:50 -0500 Message-Id: <20220209032854.565698-5-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 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: NFUFtgSVhbuy --- libavcodec/utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 5b49657b44..bdafdaa355 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -940,18 +940,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