From patchwork Tue Sep 17 19:19:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 51635 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d32e:0:b0:48e:c0f8:d0de with SMTP id cf14csp472267vqb; Tue, 17 Sep 2024 12:19:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUL0ZktM+ZpS1lx7bjJj9Nte+iWp7JvaqcafmKbeIZnb5mXwfjzd6GvEZWv9kUkjMdvJ5KmZMcNBW95PeJOikOq@gmail.com X-Google-Smtp-Source: AGHT+IGWG+DseI6+g/DZjT7o6AsSK9Ghma0bZKVfhDyqLCYG0muSgrvHXGSZjQoyDFfeWyTQFXjm X-Received: by 2002:a17:906:bc11:b0:a86:68a1:6a08 with SMTP id a640c23a62f3a-a902948e84amr2008151166b.29.1726600760338; Tue, 17 Sep 2024 12:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726600760; cv=none; d=google.com; s=arc-20240605; b=dLUIvmlOuJqxb1plZif2qh3jtt8LGPUKk3dziuhiFVFvQVGSTcjRmNIM9s0ARZlt0A +3T7dOzto2T/cDxPJ3YMbKqe1UrxYcLjQqVe9xyBoj38wITnyQrx8l5J3D3X+yQ+aNHx XdTZsyvko1d/aO8pek9lV1E/CoS5u642y/WezuY0//rqKX12zJvDxo/yCTfPaTXQwFwa tj60Q+oNKWE/iE82s6dLZf0YwqBsdawQkBKr+JBhwWd6NhBHw3cwswjQunMEdbl4i3HL i/DkYvj4Kd01y862Li6J040ZJJDfl0ZQO7SzdUGfFxwBbeheOor2DNrUjnRt7FAfAi0k sErg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:message-id:date:to:from :dkim-signature:delivered-to; bh=HquxVnheCH0vAnQqM4tf/jp7ZtX+sX/2+bX7SqYUSOc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=deosvJvWSXgAID8plcUIuiO72iC0JZJgZTwP3rszQM3elojxJ+8vkO9by2xVUWD5zj nQZJn07UGGzFbH5JrGYgMVG0esZQbQndbDcvlECHTysjS0ztkZrkw6s4Kmm6xzzHZkHR R5yxrVuDUbs0Nk3u3zERki6QHKM6t4nOPCMpWJnQwWRTAUrOxk2GxSq4MNuDeNmpepVk fNhX2g23InegfLmkeNs3VYnUn0mFGMdoUgAmRaVdk2l8nHxMx1yqqVM7LJlU50KdlGIZ cseLxwzPZqXtuYLLhxiTJUCZeJeOBBZhDQ2+1Zjryt2CjsrIzXCxv78qEGkE0WFjMpG5 y4yg==; 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=N6k4x7Xj; 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; dara=fail header.i=@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-a9061336402si547433166b.741.2024.09.17.12.19.19; Tue, 17 Sep 2024 12:19:20 -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=N6k4x7Xj; 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; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 83A8768D10F; Tue, 17 Sep 2024 22:19:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F32F8689E58 for ; Tue, 17 Sep 2024 22:19:08 +0300 (EEST) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-206b9455460so511435ad.0 for ; Tue, 17 Sep 2024 12:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726600747; x=1727205547; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=RkSN7HR3o7irXOfQmPA/ZbrdaOMcJLjxc6Spb35vX3Y=; b=N6k4x7Xj5sjWdVsS57S0r04wK3Eyt61sKuwcCUiQvGheO5386XO/6ehxxAZwexan7P o6rIaVM1EqgH1mg2npn7K+O0uaLMVJO0z+novTw7TCmERUBACLeZPWIGm1H/gu1OduJ+ a/fDiG4DP3WS8nnAPXBtYvlexRikJ8862H2T+4esZbLFMVFM7YN/sElRP3GtGiWsWBnO g9n5n1DW8ub0Ejkhqdw8OUJq2P6zDxRlgumCINYUTZQIu46H1qxQS6OVL4UnDesXBZTi qd5zmUt6dv++VakKqmgu+gWsFTSLneXjLakVadvGMWLmdCUrNoiw8APXILHnoK71YhpS bdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726600747; x=1727205547; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RkSN7HR3o7irXOfQmPA/ZbrdaOMcJLjxc6Spb35vX3Y=; b=MjsjqIuIyOwXsZPx1LM0A3BijzpLL2B170an5A09XpdG8r1RgPiJqVi8Va63lslQia mdQkhMYwnJhQ96aWgL8ZfrYv+/ROjAn5O3cu5Ibfrsrocc5aUocZtawZcFDPDIk/nfTq FijHvn2x6899SGI9KVoyTCQ17CIV3c80IELiRBcP4icPqGzyJ/seep67sQujaz9XceN+ +CShKAXs0FFJbP58qHOthPVuceRYOp9Bvyr70PfV5VHgjlff8BkKCcMkejmuutiNVIlt NWchTavspLqj1kupzNuBzidl/6aJMWPp3ohnB1ZSuZPUyPfhF2sl0ER0ZJ6L6ealcEyd v9ug== X-Gm-Message-State: AOJu0Yxk5ZMxUNFo8oFmJhqXbKwJDzsldUNODzmIkMEohJjR4y9Abb15 pVTtGuzB6MQOlU1aT8G312Cvv8jYZ1ZNZZcsP1lPISY1J0xCXkcE6aoZiw== X-Received: by 2002:a17:902:e745:b0:207:6eb:e33d with SMTP id d9443c01a7336-2074c6dcc48mr423621745ad.23.1726600746493; Tue, 17 Sep 2024 12:19:06 -0700 (PDT) Received: from localhost.localdomain ([181.92.233.116]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207946d4e04sm53060535ad.125.2024.09.17.12.19.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 12:19:05 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Sep 2024 16:19:16 -0300 Message-ID: <20240917191916.7896-1-jamrial@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/h2645_parse: add a flag to store skipped byte positions 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: UckVk+Qu4GP7 This is only used by two out of several modules, so it's a waste of resources for the rest. Signed-off-by: James Almer --- libavcodec/cbs_h2645.c | 6 ++++-- libavcodec/h2645_parse.c | 10 ++++++---- libavcodec/h2645_parse.h | 1 + libavcodec/hevc/hevcdec.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 4abd9e0c2e..75c1d1c4cf 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -725,7 +725,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, ctx->log_ctx, 2, AV_CODEC_ID_VVC, - H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF); + H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | + H2645_FLAG_USE_REF | H2645_FLAG_SKIPPED_BYTES); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "VVCC array %d (%d NAL units of type %d).\n", @@ -737,7 +738,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, return err; } } else { - int flags = (H2645_FLAG_IS_NALFF * !!priv->mp4) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF; + int flags = (H2645_FLAG_IS_NALFF * !!priv->mp4) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF | + (H2645_FLAG_SKIPPED_BYTES * (codec_id == AV_CODEC_ID_VVC)); // Annex B, or later MP4 with already-known parameters. err = ff_h2645_packet_split(&priv->read_packet, diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 7b48fcae17..f8eb301680 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -540,10 +540,12 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, memset(pkt->nals + pkt->nals_allocated, 0, sizeof(*pkt->nals)); nal = &pkt->nals[pkt->nb_nals]; - nal->skipped_bytes_pos_size = FFMIN(1024, extract_length/3+1); // initial buffer size - nal->skipped_bytes_pos = av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos)); - if (!nal->skipped_bytes_pos) - return AVERROR(ENOMEM); + if (flags & H2645_FLAG_SKIPPED_BYTES) { + nal->skipped_bytes_pos_size = FFMIN(1024, extract_length/3+1); // initial buffer size + nal->skipped_bytes_pos = av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos)); + if (!nal->skipped_bytes_pos) + return AVERROR(ENOMEM); + } pkt->nals_allocated = new_size; } diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h index e27ccf7523..975000aeb7 100644 --- a/libavcodec/h2645_parse.h +++ b/libavcodec/h2645_parse.h @@ -97,6 +97,7 @@ enum { H2645_FLAG_IS_NALFF = (1 << 0), H2645_FLAG_SMALL_PADDING = (1 << 1), H2645_FLAG_USE_REF = (1 << 2), + H2645_FLAG_SKIPPED_BYTES = (1 << 3), }; /** diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index d915d74d22..8e2d52c51a 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3321,7 +3321,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) { int i, ret = 0; int eos_at_start = 1; - int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING; + int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_SKIPPED_BYTES; s->cur_frame = s->collocated_ref = NULL; s->last_eos = s->eos;