From patchwork Wed Feb 9 03:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34201 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1371942iov; Tue, 8 Feb 2022 19:30:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLR+bxvsUVGVx8fjnUinG9bCRPeHJNArvOswTFhIQX1ATj10GoNt3oTHG0PKqIU4/ckCBp X-Received: by 2002:a17:907:6e8b:: with SMTP id sh11mr212257ejc.376.1644377426151; Tue, 08 Feb 2022 19:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644377426; cv=none; d=google.com; s=arc-20160816; b=FIZ5ChVbboPPNMsjt41pBD62mXtkEikXyXGkZCiYORV3wle1qpZYrGLiPupyWEbSHP GJa9ScZa16nNWGqViblep7yN++QIuhmSr1osPEQjBRHoSOf7OLPOgfBDvyFc/1Ad/sX4 +y1dCqhDZicF458s/rx9nVvYeYLi/Ekhd9uPkhN+HmD2bQAG0qJekHLE861kJIPJRat7 aXXptBj+RwcENs0YeiJRrSbK5Ej3sXpko3UEjNY1bUuIlgFMpCPQAKInteqQjyHOclTK PGC8tMC/fSUTApLfcERNHHtt9RkWZD6C5elC5dzx2mhxTqK29WGxymnSdREE+rpFOnK1 2jXw== 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=jjopCoXZrTBOhSQN2AyPus0ajW9Al7yIRW79TXtPht8=; b=rgzT+zRIk1Zxx9nz0Ts4TxPyONNh5WdLGLnQ8ig5pOvTFb5A5vcH61FZdKe0RxzPU9 /yFH7AZ26q/EGdniuw19trtUBcs4Ja6FSJGkta/EDrQxP8BDV/8Muu7nc0iGREKo+1qU 6rPQF7Wh1aGxea0wI8fd+YX5t/FGQsKpygSZATISznL4SsjZ2EzivKyTG3nftZBdKApF Ow020CQ8He8Tasdna9UU2QLy+z4VipBViKyxj9IJWvi999pakAhwOLfOpgvs/IBhOupK lzzHydaZuFU91ppn6Ka9hOFtn11MNpGMwNdaHpYa90pRPt8IgVjbow3vLQaJ0EkLpMl7 zajA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=m00mCdDF; 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 qw39si1523903ejc.308.2022.02.08.19.30.25; Tue, 08 Feb 2022 19:30:26 -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=m00mCdDF; 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 70B8A68B1A6; Wed, 9 Feb 2022 05:29:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE39968B00F for ; Wed, 9 Feb 2022 05:29:28 +0200 (EET) Received: by mail-qv1-f46.google.com with SMTP id g3so833996qvb.8 for ; Tue, 08 Feb 2022 19:29:28 -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=vOBugMRvj6yc2nVUCqLw4Q1l7m68ZlMjnbD/Pp4jlW0=; b=m00mCdDF4Kc8CFr2jEYR9mRHL8qxVSoSQhd9yQco4trC2DHi4qDuzcQMLmGZ24cnwT iHdDr+ZBvh9plO2NWznkahbG1NnJUInp+wDWfwJx6+aWnBLMcuNrYwniMYpLNS4xoDXD 03VR37ufp/r+F0QmCSjpePOZ93nLPs5VdLMMoQlZ7i33tWUsyzA894//ZHfrgTVOTnXE QRa4e8UJSZLQxEMGGxf4t38LLBUOE0UE6Jd4NEha4PCr0MB31CBqdHeDjJ2DnIIe8OqT m48kS0neP70o4Zwbs2ACAV+JCPhArYixyhJHmUSzhCOB9txq/LKDathMKCmp900YGS5R MHTQ== 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=vOBugMRvj6yc2nVUCqLw4Q1l7m68ZlMjnbD/Pp4jlW0=; b=lNl/7d9QXTzo5ogifJ4t0Qzg+v5X0dRp22B0q3FDojX4q7ZhA/7arw8qfcA1FXaMxN 8/U89SWGTebVl1zmNmEL4ihXTQs1V+EOOGFqhJbjcSJPdeBZA0IaCk7ewzykm/x30/CW xwU3luDl5jNettWVOHEA4Cokl+DgwDpV1yv5QtNnTJYeWdMQ6mCyRkxyQq+gxinfgDY+ +Abb07r6rtQ6hbIGt83zfGN8QrPBYSWmmntaGf+GsmPcq1Z2pNZpIWtPgw6GiD0vQXt/ u9jnMjrb9Oh8ZnNJoCnHgTVH3j097CoLWuHKJ7JO1id0DNPtA00e3QEsN74y0DT3gjgk S/VA== X-Gm-Message-State: AOAM532zKGOwySl5VTo4barVY1QKKveFdzi3x8u8qJXJJ1Vx88mYBNVK L5b7LMjgixPOtNlcq95eC/LMb+7MkBRlNw== X-Received: by 2002:ad4:5ccd:: with SMTP id iu13mr245927qvb.89.1644377366426; Tue, 08 Feb 2022 19:29:26 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id o19sm8452524qta.19.2022.02.08.19.29.25 (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:51 -0500 Message-Id: <20220209032854.565698-6-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 5/8] avpriv_find_start_code(): add doxygen comment and rename a parameter 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: ywVOl5eKRY1h --- libavcodec/startcode.h | 26 +++++++++++++++++++++++++- libavcodec/utils.c | 10 +++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libavcodec/startcode.h b/libavcodec/startcode.h index 833754af09..69389c729c 100644 --- a/libavcodec/startcode.h +++ b/libavcodec/startcode.h @@ -44,9 +44,33 @@ static av_always_inline int start_code_is_valid(uint32_t start_code) { return (start_code & 0xFFFFFF00) == 0x100; } +/** + * @brief Find the first start code in the buffer @p p. + * + * A start code is a sequence of 4 bytes with the hexadecimal value 00 00 01 XX , + * where XX represents any value and memory address increases left to right. + * + * By preserving the @p start_code value between subsequent calls, the caller can + * detect start codes across buffer boundaries. + * + * @param[in] p A pointer to the start of the memory buffer to scan. + * @param[in] end A pointer to the past-the-end memory address for the buffer + * given by @p p. @p p must be ≤ @p end. + * + * @param[in,out] start_code A pointer to a mutable @c uint32_t.
+ * As input: For no history preset to @c ~0 , otherwise preset to the last + * returned start code to enable detecting start codes across + * buffer boundaries.
+ * On output: Set to the found start code if it exists or an invalid + * start code (the 4 bytes prior to the returned value, + * using the input history if @f$ end - p < 4 @f$). + * + * @return A pointer to the memory address following the found start code, or @p end + * if no start code was found. + */ const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, - uint32_t *state); + uint32_t *start_code); int ff_startcode_find_candidate_c(const uint8_t *buf, int size); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index bdafdaa355..68d126acd8 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -938,7 +938,7 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, - uint32_t *av_restrict state) + uint32_t *av_restrict start_code) { av_assert0(p <= end); if (p >= end) @@ -947,10 +947,10 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // 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; + *start_code <<= 8; + *start_code += *p; p++; - if (start_code_is_valid(*state) || p == end) + if (start_code_is_valid(*start_code) || p == end) return p; } // p is now properly incremented for the negative indices in the while loop @@ -983,7 +983,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, if (p > end) p = end; // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} - *state = AV_RB32(p - 4); + *start_code = AV_RB32(p - 4); return p; }