From patchwork Mon Aug 19 16:58:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 51082 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a52a:0:b0:48e:c0f8:d0de with SMTP id e10csp42255vqs; Mon, 19 Aug 2024 09:58:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWp5qkGKvCsdFHaAzGy8R8ZW7u4lcH1iIyTFkoP6MAdOm8FKG2/XexK1b1eN/VMksaNy3A+WvEqK13uYt1yJfW4JBImORdllLI+bw== X-Google-Smtp-Source: AGHT+IGN66md3l9fVg1GK1mNtow+PiVJ05Q4XgsLT0MhcRsMXVgrjcvjkdRemLRLPMbqhoMaaVwN X-Received: by 2002:a05:6402:51c9:b0:5be:d91c:f959 with SMTP id 4fb4d7f45d1cf-5bedb756490mr4953552a12.33.1724086688190; Mon, 19 Aug 2024 09:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724086688; cv=none; d=google.com; s=arc-20160816; b=PtrqPsROoXd4SRYRNXr2TZo9TQKztfqE+8mAOf5EengG4OkTXiDlkP37u7rSpmb7XI RL4RJvCy3AOaOTOJjELy4uDo+8eCRyMicKIFNdi0HL2FoIOPFQKBHB0uwiLTxVHVlt8c Up2LNDrC4m9ydRdWGlqfIAFFnC2B9T6nd4ICwvM8h2MIKVmqjuphUusodoPnuFDy0JU7 1oqrp5NllUJeL8Ko/ipMy3Pfi2FsuDV52FgQ2yV39c+TUhezt01ml0UgLN+Q1MhTLyPg ma6KonJLC4dLvqSpPgTLrY0y4Rk7qg/h2EGSbvt3LmijHDCHUyw/lmooRNWhyPiMxrnY nNkw== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=cdedBgACOO/KXqa+Y6wEkZVajnI/G6SOePoCghWeamw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Cp6+votMgcrdvRxupA7j/FTl4/KzjI0ATQYAY29w2pKXdO2EIIhG9GlSMxtu+BwKPr cefQmhBHaHHycPvkbZZfuOInLMZQq4/KYgpZcVC3emSFJv9FoozR7FtaPzhVTaejtbf9 UcXpGUoX9tqFkBWiVEQEGhqpUxHvvGswFvs0cApUdwqqhV1ryPYR3Y1Z2jZYVu0CmiDC eZH7T07W/XRe46QVh9p1tiVnNh0TXRFpuJTlTmLTOczwfxo3Q3JFxTZdsTgvLwrjJ4gm f5IeanHFVW/m5kA2xZ3DxszrN2CSnm1J3pBgpcWtT38xZbn3hc9mnYzc/njG1wjkDSu3 kkHg==; 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=npKmkr8d; 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 4fb4d7f45d1cf-5bed96c3565si4195908a12.640.2024.08.19.09.58.07; Mon, 19 Aug 2024 09:58:08 -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=npKmkr8d; 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 0A9D368DCCB; Mon, 19 Aug 2024 19:58:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F52C68DBFA for ; Mon, 19 Aug 2024 19:57:57 +0300 (EEST) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-713edc53429so1073162b3a.2 for ; Mon, 19 Aug 2024 09:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086675; x=1724691475; 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=wh7jUtYHfwR4Cw5Op7Hy2rjH1ohLUxMMzbeASxhlD8c=; b=npKmkr8dnpPSqFb4Vr1M0D++Qaop9e6X77Q/1bhkCBjgpCd7P1z5rKm6Okqs6njS04 eIsDBYVGOhUZS9HqPO4Noigq/9737PWhOseuBC1mu41gyoF6CCaC9eczlAMRA0TxJvpB Fiy2/GPgY5j4JVduFk9nCvjm0z2azE+GyBXNJPCL2aFdEEZV7usHQUEFQWxo0nhnfuLz nJkiC79QXGF2BCSDTbVTa9MVeXLJc68b/Zh/5Aijt6prDX2dCNHYNpwLW2vWaHncKJ5m fa1yggnEAR6+o27X+0tLvy/D6gDU+7JhRYfJ90ucnqCfSlofv7WuYVjObwjb0ntDmq83 Md1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086675; x=1724691475; 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=wh7jUtYHfwR4Cw5Op7Hy2rjH1ohLUxMMzbeASxhlD8c=; b=V92b+yckL9ImQo6RE2dWyVc19bqEF/j4flYZnVgdenLhvhQuSnVFSX0clk8w7l6Ye0 T+9YnopDSxSO0U6qWjzpYCVXngrG8mCsWk2EtwnROZTET3Nlyfwe58FTMVM8VnrDIJ6k VKHiFVrc9E861+8fAlCAXmWjkAEjYihbvLYN6CPIt69kNhBR4m18qTNLLnKaV13byz2n 4r1CIqVaTYqT3bbCYkFu2AvhAHNn00y8KoSxy/YB0vdWM9PonDpxpCwriNEO8TXkD8hR 8HrzVPC8oLsmzsQ+6eL62WfLDdeCrERzVhNRc08p91rE+9O5r9mAVqFhn+oPcvG1pcVY YY0Q== X-Gm-Message-State: AOJu0YzjKkussJ6T4jLsi+B4vkm14y3dioZgM7PRygOaXglhaJ5HK6zc L5hHgLYzoPlDbVYApPRDnvfU+lhhrzdoS5YTShL7n9H6XHq4UsdIwB1N2A== X-Received: by 2002:a05:6a00:10d5:b0:70d:2a4d:2edc with SMTP id d2e1a72fcca58-713c4ecfa42mr11365224b3a.20.1724086674281; Mon, 19 Aug 2024 09:57:54 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af160c1sm7013832b3a.142.2024.08.19.09.57.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:57:53 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Aug 2024 13:58:11 -0300 Message-ID: <20240819165811.346-1-jamrial@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/h2645_parse: replace three bool arguments in ff_h2645_packet_split with a single flags one 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: PVJr4/pERfld Signed-off-by: James Almer --- libavcodec/bsf/extract_extradata.c | 2 +- libavcodec/cbs_h2645.c | 17 +++++++++++------ libavcodec/h2645_parse.c | 15 ++++++++------- libavcodec/h2645_parse.h | 15 ++++++++++----- libavcodec/h264_parse.c | 3 ++- libavcodec/h264dec.c | 4 ++-- libavcodec/hevc/hevcdec.c | 5 +++-- libavcodec/hevc/parse.c | 5 +++-- libavcodec/hevc/parser.c | 5 +++-- 9 files changed, 43 insertions(+), 28 deletions(-) diff --git a/libavcodec/bsf/extract_extradata.c b/libavcodec/bsf/extract_extradata.c index b037990562..43f4d62855 100644 --- a/libavcodec/bsf/extract_extradata.c +++ b/libavcodec/bsf/extract_extradata.c @@ -193,7 +193,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, } ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size, - ctx, 0, 0, ctx->par_in->codec_id, 1, 0); + ctx, 0, ctx->par_in->codec_id, H2645_FLAG_SMALL_PADDING); if (ret < 0) return ret; diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index d73d77a985..4abd9e0c2e 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -573,7 +573,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, 1, 2, AV_CODEC_ID_H264, 1, 1); + ctx->log_ctx, 2, AV_CODEC_ID_H264, + H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); return err; @@ -597,7 +598,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, 1, 2, AV_CODEC_ID_H264, 1, 1); + ctx->log_ctx, 2, AV_CODEC_ID_H264, + H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); return err; @@ -651,7 +653,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, 1, 2, AV_CODEC_ID_HEVC, 1, 1); + ctx->log_ctx, 2, AV_CODEC_ID_HEVC, + H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "HVCC array %d (%d NAL units of type %d).\n", @@ -721,7 +724,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, 1, 2, AV_CODEC_ID_VVC, 1, 1); + ctx->log_ctx, 2, AV_CODEC_ID_VVC, + H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "VVCC array %d (%d NAL units of type %d).\n", @@ -733,13 +737,14 @@ 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; // Annex B, or later MP4 with already-known parameters. err = ff_h2645_packet_split(&priv->read_packet, frag->data, frag->data_size, ctx->log_ctx, - priv->mp4, priv->nal_length_size, - codec_id, 1, 1); + priv->nal_length_size, + codec_id, flags); if (err < 0) return err; diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 2341f0e0a7..4cb90ac0d0 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -463,16 +463,16 @@ fail: } int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, - void *logctx, int is_nalff, int nal_length_size, - enum AVCodecID codec_id, int small_padding, int use_ref) + void *logctx, int nal_length_size, + enum AVCodecID codec_id, int flags) { GetByteContext bc; int consumed, ret = 0; - int next_avc = is_nalff ? 0 : length; - int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE; + int next_avc = (flags & H2645_FLAG_IS_NALFF) ? 0 : length; + int64_t padding = (flags & H2645_FLAG_SMALL_PADDING) ? 0 : MAX_MBPAIR_SIZE; bytestream2_init(&bc, buf, length); - alloc_rbsp_buffer(&pkt->rbsp, length + padding, use_ref); + alloc_rbsp_buffer(&pkt->rbsp, length + padding, !!(flags & H2645_FLAG_USE_REF)); if (!pkt->rbsp.rbsp_buffer) return AVERROR(ENOMEM); @@ -549,11 +549,12 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, } nal = &pkt->nals[pkt->nb_nals]; - consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, &pkt->rbsp, nal, small_padding); + consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, &pkt->rbsp, nal, + !!(flags & H2645_FLAG_SMALL_PADDING)); if (consumed < 0) return consumed; - if (is_nalff && (extract_length != consumed) && extract_length) + if ((flags & H2645_FLAG_IS_NALFF) && extract_length && (extract_length != consumed)) av_log(logctx, AV_LOG_DEBUG, "NALFF: Consumed only %d bytes instead of %d\n", consumed, extract_length); diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h index 128dea09ef..849e772115 100644 --- a/libavcodec/h2645_parse.h +++ b/libavcodec/h2645_parse.h @@ -93,6 +93,10 @@ typedef struct H2645Packet { int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp, H2645NAL *nal, int small_padding); +#define H2645_FLAG_IS_NALFF (1 << 0) +#define H2645_FLAG_SMALL_PADDING (1 << 1) +#define H2645_FLAG_USE_REF (1 << 2) + /** * Split an input packet into NAL units. * @@ -103,13 +107,14 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp, * packet's H2645RBSP. * * If the packet's rbsp_buffer_ref is not NULL, the underlying AVBuffer must - * own rbsp_buffer. If not and rbsp_buffer is not NULL, use_ref must be 0. - * If use_ref is set, rbsp_buffer will be reference-counted and owned by - * the underlying AVBuffer of rbsp_buffer_ref. + * own rbsp_buffer. If not and rbsp_buffer is not NULL, H2645_FLAG_USE_REF + * must not be set in flags. + * If H2645_FLAG_USE_REF is set in flags, rbsp_buffer will be reference-counted and + * owned by the underlying AVBuffer of rbsp_buffer_ref. */ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, - void *logctx, int is_nalff, int nal_length_size, - enum AVCodecID codec_id, int small_padding, int use_ref); + void *logctx, int nal_length_size, + enum AVCodecID codec_id, int flags); /** * Free all the allocated memory in the packet. diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index c13bc860ef..c6f9b3cea7 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -368,9 +368,10 @@ static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets *ps, int is_avc, void *logctx) { H2645Packet pkt = { 0 }; + int flags = (H2645_FLAG_IS_NALFF * !!is_avc) | H2645_FLAG_SMALL_PADDING; int i, ret = 0; - ret = ff_h2645_packet_split(&pkt, data, size, logctx, is_avc, 2, AV_CODEC_ID_H264, 1, 0); + ret = ff_h2645_packet_split(&pkt, data, size, logctx, 2, AV_CODEC_ID_H264, flags); if (ret < 0) { ret = 0; goto fail; diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index c77d8f42db..0154fe17b6 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -612,8 +612,8 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) h->is_avc = 1; } - ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc, h->nal_length_size, - avctx->codec_id, 0, 0); + ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->nal_length_size, + avctx->codec_id, !!h->is_avc * H2645_FLAG_IS_NALFF); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error splitting the input into NAL units.\n"); diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 193d624fc9..45e20fc86a 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3289,6 +3289,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; s->cur_frame = s->collocated_ref = NULL; s->last_eos = s->eos; @@ -3297,8 +3298,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) /* split the input packet into NAL units, so we know the upper bound on the * number of slices in the frame */ - ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, s->is_nalff, - s->nal_length_size, s->avctx->codec_id, 1, 0); + ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, + s->nal_length_size, s->avctx->codec_id, flags); if (ret < 0) { av_log(s->avctx, AV_LOG_ERROR, "Error splitting the input into NAL units.\n"); diff --git a/libavcodec/hevc/parse.c b/libavcodec/hevc/parse.c index 53b040d964..ec8d1aeacf 100644 --- a/libavcodec/hevc/parse.c +++ b/libavcodec/hevc/parse.c @@ -27,10 +27,11 @@ static int hevc_decode_nal_units(const uint8_t *buf, int buf_size, HEVCParamSets { int i; int ret = 0; + int flags = (H2645_FLAG_IS_NALFF * !!is_nalff) | H2645_FLAG_SMALL_PADDING; H2645Packet pkt = { 0 }; - ret = ff_h2645_packet_split(&pkt, buf, buf_size, logctx, is_nalff, - nal_length_size, AV_CODEC_ID_HEVC, 1, 0); + ret = ff_h2645_packet_split(&pkt, buf, buf_size, logctx, + nal_length_size, AV_CODEC_ID_HEVC, flags); if (ret < 0) { goto done; } diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c index f4e6e3c36d..8db56e259e 100644 --- a/libavcodec/hevc/parser.c +++ b/libavcodec/hevc/parser.c @@ -182,6 +182,7 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, HEVCParserContext *ctx = s->priv_data; HEVCParamSets *ps = &ctx->ps; HEVCSEI *sei = &ctx->sei; + int flags = (H2645_FLAG_IS_NALFF * !!ctx->is_avc) | H2645_FLAG_SMALL_PADDING; int ret, i; /* set some sane default values */ @@ -191,8 +192,8 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, ff_hevc_reset_sei(sei); - ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, ctx->is_avc, - ctx->nal_length_size, AV_CODEC_ID_HEVC, 1, 0); + ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, + ctx->nal_length_size, AV_CODEC_ID_HEVC, flags); if (ret < 0) return ret;