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 F36BE467E6 for ; Sun, 18 Jun 2023 23:44:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 402A468BF45; Mon, 19 Jun 2023 02:43:54 +0300 (EEST) Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21DD768BF1D for ; Mon, 19 Jun 2023 02:43:48 +0300 (EEST) Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6b46f27f562so410545a34.0 for ; Sun, 18 Jun 2023 16:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687131826; x=1689723826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dUuCE2HCD6Bmk7QMz02iLT1pZMs+Cf6miQLb4EZFRzc=; b=dSd7vtyE96coHJdsPcGz2M3iQW3Q6I9J1N+an2ZXj2cJI/UBAiYqZak3Scrpw1Q3z4 ztZlYEUr5vRo7ZH5UpL9GkYUd6OxOUaNMLeujPJPSCTlJgfD2j7Y5T6wTvSwVTDLmh60 XQjdczTUxKZga0fY+1ECjTenGupP7EdCS046kYPEq69/gH4KkOM5fHfTdkUoipBMUoVg ri20b4Fey4Vu2CwPADhRb6fUojcxpp3WKrwcfq8mONhgBG2szhVS9tY6feaHfJH+hc9B N+D6v39tZ0HZ47XTXqHPXTZrMYE4wKyF/yWCu2Q/iqVta3Iocpdr5BpqQZA5v4U9tVa1 Tk9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687131826; x=1689723826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dUuCE2HCD6Bmk7QMz02iLT1pZMs+Cf6miQLb4EZFRzc=; b=kMlq5CmvU3qxeFx1XXBb0d5u1n6qX5/FvB3xOv18e4fO+XLcnqo2WzfWQOxF7w3Cbs jX2G5BwZ59/H2HcWGZLqxX9WJpfabO/ffR/y+QqDEMnkUoA5jrEecI4fC5Vvdg/PwleW kVct7ZGFsPaiAX522t/dKnWFY2avd1seEOyKnPv7oqEadT9/m+YIz87U70d30oG+aH1p yfgixFe0LZ1+iXzAy3ir2qD3fMjGd5HY8sR9iKvuAR6sg0WnEEDQdFG56DNDjtoMyBst skADZvMqYkqGSC6d213+quH8RBWI8M8n7I9powCTHkOP9W+tMdjZJKIxb2r1U9v2DfVS QpMQ== X-Gm-Message-State: AC+VfDwoQ/tcpMr5RQSi9YaO3Dldh59y1/chEJYND5tKH0K+QvN+Au1b +2rMGKxIf8mI5WbkcpxT645N3DrzXAs= X-Google-Smtp-Source: ACHHUZ628yM6jor9lXRnm4hTYTxJS1n5fN2AUQ9jMDc9dMry4ExFVpkWaZdSRtDYUTtarolnLH/uig== X-Received: by 2002:a05:6808:1145:b0:398:4795:930c with SMTP id u5-20020a056808114500b003984795930cmr6602625oiu.48.1687131826046; Sun, 18 Jun 2023 16:43:46 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id bk36-20020a0568081a2400b0039eb5f4543csm2069664oib.34.2023.06.18.16.43.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jun 2023 16:43:45 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Jun 2023 20:43:27 -0300 Message-ID: <20230618234332.1370-2-jamrial@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230617151848.1378-1-jamrial@gmail.com> References: <20230617151848.1378-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions 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 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: Signed-off-by: James Almer --- libavformat/evcdec.c | 46 ++++---------------------------------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c index 807406885a..0f17edd371 100644 --- a/libavformat/evcdec.c +++ b/libavformat/evcdec.c @@ -20,10 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/get_bits.h" -#include "libavcodec/golomb.h" #include "libavcodec/internal.h" #include "libavcodec/evc.h" +#include "libavcodec/evc_parse.h" #include "libavcodec/bsf.h" #include "libavutil/opt.h" @@ -66,43 +65,6 @@ static const AVClass evc_demuxer_class = { .version = LIBAVUTIL_VERSION_INT, }; -static int get_nalu_type(const uint8_t *bits, int bits_size) -{ - int unit_type_plus1 = 0; - - if (bits_size >= EVC_NALU_HEADER_SIZE) { - unsigned char *p = (unsigned char *)bits; - // forbidden_zero_bit - if ((p[0] & 0x80) != 0) // Cannot get bitstream information. Malformed bitstream. - return -1; - - // nal_unit_type - unit_type_plus1 = (p[0] >> 1) & 0x3F; - } - - return unit_type_plus1 - 1; -} - -static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size) -{ - uint32_t nalu_len = 0; - - if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) { - - int t = 0; - unsigned char *p = (unsigned char *)bits; - - for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++) - t = (t << 8) | p[i]; - - nalu_len = t; - if (nalu_len == 0) // Invalid bitstream size - return 0; - } - - return nalu_len; -} - static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev) { int nalu_type; @@ -112,7 +74,7 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev) while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) { - nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE); + nalu_size = evc_read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE, NULL); if (nalu_size == 0) break; bits += EVC_NALU_LENGTH_PREFIX_SIZE; @@ -120,7 +82,7 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev) if(bytes_to_read < nalu_size) break; - nalu_type = get_nalu_type(bits, bytes_to_read); + nalu_type = evc_get_nalu_type(bits, bytes_to_read, NULL); if (nalu_type == EVC_SPS_NUT) ev->got_sps++; @@ -218,7 +180,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; } - nalu_size = read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE); + nalu_size = evc_read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE, s); if(nalu_size <= 0) { av_packet_unref(pkt); return -1; -- 2.41.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".