From patchwork Wed Jul 3 21:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50309 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp3347342vqv; Wed, 3 Jul 2024 14:27:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXqU6z3WMm07vRk+BCXZKT4i2ZZSkYKFSCCSZ/TRI3rAdlg/v5CkcvtIwvQJlIVaf7PMk09kIDvKSiIIauIL9/3di4A3njYDg+JNw== X-Google-Smtp-Source: AGHT+IGIlBV/lCCvEqnjm1zP9slq+RK2eXTBPGofIY5GAhe4axTheinnsDeD6o2o4Xp9dYwfJnFT X-Received: by 2002:a05:6512:104f:b0:52c:deea:57cb with SMTP id 2adb3069b0e04-52e8264acc1mr11312884e87.3.1720042052997; Wed, 03 Jul 2024 14:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720042052; cv=none; d=google.com; s=arc-20160816; b=okBoc3WLE3Vg0p8dbsJPm+CZCCqPDCJE+XUOlFOZxI1FLNt8qUbJ+SOnuMlCuABcpe ckZM1gZgcusLnfek+H+JWAQGWM63Jpoze6xo4keYGR2hTl1ylcfy+yQhGZ+FvBT1kJ/8 enPl3Rgw1z+f45hw/JkMZ+sBUJgPr/TY8OG5lBmDc8HQQpVUNyv35rwA0fYAJ7Fcet0C oXQ/Iiq6E+U21+74VdpRCM+KN7KENteB5CiFuXGNVHTgLHBnGq5Ql0QmD6a1hze5vSgS bS/R9/T10amMcdWVXQFmlHjyE2PWm8jeSX0sFr3UrYX9fUGsR1JtdAS2kbczWYA+rlKu 2DHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=/lj0SIQVVBsozX8kQGqjEKB77gpRNG6GZjqKKfO3j+k=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=pzPI1rTvULT9Jk4XdUUbi+lrLcFqwjxd32cL3jgKMGpMqXqCq62G0pJjior/3foMw0 dSQVQ9e5si4G4VoTRuTNDpkN9d5Sy9rk+hfTWmQ+z6Jwi5yKe41LKXgGvd/B3iIr+8Iq qorIio396uP0Z6DjR0qg1ckQQ3xM76rG7xd75g1qOf+RYxnrAVlQ6CHkT7k0FOXhPpCk AaJszmAbtEK1LXkt94T+cpnhYB888wDeeTjvxdMxCQNr0dQxEbuHco61sLi57ZI5RhTx vATfe7lOspQLd0DYcO9Eiiau6qtzACwCpD97XUzLcaKDg0ZNn5hcC7BF+fv960Oqx5ae DmlQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=f8vKXRqi; 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 a640c23a62f3a-a72ab075538si595422066b.608.2024.07.03.14.27.32; Wed, 03 Jul 2024 14:27:32 -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=20230601 header.b=f8vKXRqi; 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 99D0D68D9F3; Thu, 4 Jul 2024 00:26:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC32668D9DE for ; Thu, 4 Jul 2024 00:26:42 +0300 (EEST) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2c9785517c0so25634a91.0 for ; Wed, 03 Jul 2024 14:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042000; x=1720646800; darn=ffmpeg.org; 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=V2HXMlWRD1ybNqTLfPl3QMUgh/lmKyf6OlPg/hFHnzM=; b=f8vKXRqi9Yo7+cgkQS25LJDzJ0vxohyqPfKrsfCRWsixKMDBO43+3QLso7bUZrNf/U bKO9Y8hqbZEnXpjFkW8LkmWmIgo4pH9Wl6Y4Y6MUuKLIARGr2eVsgGJVy5I30NeJJGzr +LYLcLYgQVUoz1QU6xYianheRvUTMg1nTurNDGmnAGOibDsCjHwgMchgXHsEbCftGtFw DRPLf3T38K+UQeI1/E4xlYYdyPtLPJCWv/oJ556WVyeMdyaeXV76pFJ7MIQUGkSB7yLu 306r9Rp54suAmgP67bhq5Y5ns60hhNJ/rCMkLX/0VOiyFiPBKFGCiU6LzEd1YN5KsA+8 SYRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042000; x=1720646800; 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=V2HXMlWRD1ybNqTLfPl3QMUgh/lmKyf6OlPg/hFHnzM=; b=AiShEuVEkqGt01q9PwxHlmZE+8uRJkxcH5ho9ro1EUctgAx1yMG9j0+jnutE5mTf/O OZeIquXlN+Rd2BwhCg8rNe1J3adSLr8mJLInXeeWpAldBSxCqGHkYnj0t2/fRg4coFER 3MqMhTY8kzRHYSEwZC6kb8Z99G2YWrQenwo9gTqG7yO6WoY1qQjaQ2MW8LxZZ6Qkln8v KPI7FjjEJd71gGAKkHIG+QcVZQpvudKXlC+WEBaYT/Xw9yDdMneRWjzBmMzCtBqPeBm9 T4ehBQcez96qzeOvNSjnRjCb3QePEZBXX58NKkSu+RVACj9SIpMPUbRlKLyaO7hZzwy8 p/fg== X-Gm-Message-State: AOJu0YxgKce+W7fZHl80qeLw0WmRW7NZciSVmK9JTrhUdGVlAoz0jIHl O57K6hVS2ugUGLAhWAYOJh65g+38dPiAuzz5T0qo9LQAbPh0/DyqZGmKhw== X-Received: by 2002:a17:90a:517:b0:2c3:37e7:aaa8 with SMTP id 98e67ed59e1d1-2c93d785fa1mr7489789a91.46.1720042000019; Wed, 03 Jul 2024 14:26:40 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm11370560a91.24.2024.07.03.14.26.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:26:39 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jul 2024 18:26:41 -0300 Message-ID: <20240703212648.48483-6-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703212648.48483-1-jamrial@gmail.com> References: <20240703212648.48483-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/11] avformat/hevc: use a single array for per-PS NALUs 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vrqcPR6lKKsA Signed-off-by: James Almer --- libavformat/hevc.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/libavformat/hevc.c b/libavformat/hevc.c index 40f46668f9..6fe701032b 100644 --- a/libavformat/hevc.c +++ b/libavformat/hevc.c @@ -40,15 +40,20 @@ enum { NB_ARRAYS }; + #define FLAG_ARRAY_COMPLETENESS (1 << 0) #define FLAG_IS_NALFF (1 << 1) +typedef struct HVCCNALUnit { + uint16_t nalUnitLength; + const uint8_t *nalUnit; +} HVCCNALUnit; + typedef struct HVCCNALUnitArray { uint8_t array_completeness; uint8_t NAL_unit_type; uint16_t numNalus; - uint16_t *nalUnitLength; - const uint8_t **nalUnit; + HVCCNALUnit *nal; } HVCCNALUnitArray; typedef struct HEVCDecoderConfigurationRecord { @@ -674,19 +679,17 @@ static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type, static int hvcc_array_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size, HVCCNALUnitArray *array) { + HVCCNALUnit *nal; int ret; uint16_t numNalus = array->numNalus; - ret = av_reallocp_array(&array->nalUnit, numNalus + 1, sizeof(uint8_t*)); - if (ret < 0) - return ret; - - ret = av_reallocp_array(&array->nalUnitLength, numNalus + 1, sizeof(uint16_t)); + ret = av_reallocp_array(&array->nal, numNalus + 1, sizeof(*array->nal)); if (ret < 0) return ret; - array->nalUnit [numNalus] = nal_buf; - array->nalUnitLength[numNalus] = nal_size; + nal = &array->nal[numNalus]; + nal->nalUnit = nal_buf; + nal->nalUnitLength = nal_size; array->numNalus++; return 0; @@ -785,8 +788,7 @@ static void hvcc_close(HEVCDecoderConfigurationRecord *hvcc) for (unsigned i = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) { HVCCNALUnitArray *const array = &hvcc->arrays[i]; array->numNalus = 0; - av_freep(&array->nalUnit); - av_freep(&array->nalUnitLength); + av_freep(&array->nal); } } @@ -871,7 +873,7 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc) for (unsigned k = 0; k < array->numNalus; k++) av_log(NULL, AV_LOG_TRACE, "nalUnitLength[%u][%u]: %"PRIu16"\n", - j, k, array->nalUnitLength[k]); + j, k, array->nal[k].nalUnitLength); j++; } @@ -972,12 +974,13 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc) avio_wb16(pb, array->numNalus); for (unsigned j = 0; j < array->numNalus; j++) { + HVCCNALUnit *nal = &array->nal[j]; + /* unsigned int(16) nalUnitLength; */ - avio_wb16(pb, array->nalUnitLength[j]); + avio_wb16(pb, nal->nalUnitLength); /* bit(8*nalUnitLength) nalUnit; */ - avio_write(pb, array->nalUnit[j], - array->nalUnitLength[j]); + avio_write(pb, nal->nalUnit, nal->nalUnitLength); } }