From patchwork Fri Sep 16 18:19:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37964 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139731pzh; Fri, 16 Sep 2022 11:21:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NYlcJlLP7PY3Oawqf9Fp5cS91Bpp7GksohXqaKvfRNEll/NUV6Eqi7u4Zjj6hLJA6x6q5 X-Received: by 2002:a05:6402:3603:b0:451:fdda:dddd with SMTP id el3-20020a056402360300b00451fddaddddmr4901515edb.81.1663352461811; Fri, 16 Sep 2022 11:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352461; cv=none; d=google.com; s=arc-20160816; b=QSwIbVJkYC9vf89qFOiHv7QfnVT+ZpRBrHj4EfDOahHg5geCIpxGtlLHMZOh9CIeGk VPjb8f55I8rOydwaXlmiMWoZnn4rnczD40iOSG44wDGMWHhlPea/ZEjtdze7//6alYYw 2Egn0MFIEpuXSQdPqQpvX2YahwKxbX88Y5Dmj0OSusT3Nti2QvOSSMjmtsjwFFDEKBQN nwgMgV/k4Witn8NslKyN2UOnxHVKd3bO6GOTp1/h+K21ee2GHYMGoe0Ve2e3Xu67NcPo lCXYXMO1mm0UzJ5oetRo4asfWaGoYc+oL2YK+RwdDXHehp2ZJMfI71DRIqz53qcnvoFj TfPg== 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=eKJgJR3DwAM2QKxKuVf0TtzRWDRbuidTNY63iGR4NQU=; b=J5K5byIt6B5Hs78+wcqF/qG2HXO5hgfeaHCGcYktyTC5S/sSvm11JQmsa7fe1+5+7F CxMplE0FAYfnfxZ7qDp9VAdEzbpItKoa3DFVl+5TU9xCMoIN9dO5C0o4Vakgt/88dwic /bc21O9dOyfM1n5IQfxGfxOyMRzTNijSkz5v0qC24bDKviX/Jxf+D2GNCFecva9iLD6q sZVS+/EJ4/o/j4yTk2OgvHdnBo8DWrv3nUYY8u6csDHOyv2oKZ/aYeJgMrFO1fA3rGch 6+cRtLComAaGQS43mveN2xweGPZ8oCbH3GZPKynqLzybQ7ZrkW96zdkSHeLUizpgYO+z KcXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nNqsWrzR; 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 o14-20020a170906974e00b0076f0940cb28si18845914ejy.175.2022.09.16.11.21.01; Fri, 16 Sep 2022 11:21:01 -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=nNqsWrzR; 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 2F27F68BC3D; Fri, 16 Sep 2022 21:20:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3464168BC3C for ; Fri, 16 Sep 2022 21:20:14 +0300 (EEST) Received: by mail-qv1-f44.google.com with SMTP id y9so17239401qvo.4 for ; Fri, 16 Sep 2022 11:20:14 -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=uD6/b9tjwEMPSw2SBahE04GAlu08JFfPkFc0VGn1WL0=; b=nNqsWrzRTpQvJgIoGpbdaUgxbJQKDQf73d4vVka+e+3/vptDWMjuCwYnzpu8iJrwWk sM1Vwn/5dMYH5tkXxRyWqsCu5rfPW6/k5QVCedsnVzDs4kQbi5IHsP+f4S6PgkN410ES Km7SkE2oUaZ8UHhfgd77u8aKt/dp/AC/r3uteABS1EXokygbW2hBQmS3QICZdl76tUzi q4eIxHwl8I3cxnou8WY77CfPAlszlO8EzAQF2shBsuFAvEF99wdMBvdkZGHw7oQ3NGwd uQ09IqSpVQn/qseu5D/gtRbHlhKmgjjfEgm9twh6a9uD3uPt0+02fG1L09IQF/suRdrJ N7sA== 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=uD6/b9tjwEMPSw2SBahE04GAlu08JFfPkFc0VGn1WL0=; b=Jrz5FW9dZeqEBli+BGMy/YsDEQc3WZgl+KvuGIkQHDPzmFEou2rBL8aHL860bD3nIY ORtt2Y/GtS8Z66bKXsUr9wDQpW959tXKgSX/T++T3/YJUf4pmifXKe5mupJvj6dUqvG2 1n8LKk9st0DyX3Yk5cP+SBb6TR02vOF31WuewcjDKuz66/PyCQrvOb2QoGRkgK5QMVTC /hKo5ggkBtyJJy5/YEL8gY5pA5mnUG6pP5qjeR7QuVcaOgrLqWhsC+aWzDLY4Yymfpqy XbwXwhGQmnPAo4OrUSsMx+PWq1spYNI0JFOGI8STI4QOUPpnubHbqY/nkHfQtDbT70wr vtzw== X-Gm-Message-State: ACrzQf2TQF2iFm/ljr6supF0YQt96oZcrHvr9uANaoeeXiu5rAQgYNyg ohdr9/cOu6QFPEwTsUj2NB7k6LODaco= X-Received: by 2002:a05:6214:1c88:b0:472:a7e2:bef4 with SMTP id ib8-20020a0562141c8800b00472a7e2bef4mr5411690qvb.32.1663352412672; Fri, 16 Sep 2022 11:20:12 -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:12 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:59 -0400 Message-Id: <20220916182002.122699-6-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 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: gGTbS8ATqICP --- 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 83f7d8a01a..63bf4b8cb7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -981,7 +981,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) @@ -990,10 +990,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 @@ -1023,7 +1023,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; }