From patchwork Thu Feb 11 14:36:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 25571 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6CE04449D93 for ; Thu, 11 Feb 2021 17:06:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F74B68AA97; Thu, 11 Feb 2021 17:06:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B9633689C5C for ; Thu, 11 Feb 2021 17:06:06 +0200 (EET) Received: by mail-pl1-f171.google.com with SMTP id u15so3461999plf.1 for ; Thu, 11 Feb 2021 07:06:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g87clB4shdQ/MOff1dIasZ+/QQH+c4TBKLP3zroABgY=; b=RBNJXgJVTpHbDnNuAfPcO5LHVKk74UbNo6WRwn7K5+2Houq0eek4T2FzustzUhHAbp bbvtgJJ1TjIZU/Yw8DzTtjLeG9R76bZcnDN1G0QMe2kddb1ald9D9bUlNgzKq681HU3u OlK0F2h+it2Qta3w0N6oC57yYUkixyPwkgKJPKfcrDGqLoM6iSH5pujvkpbzsb6/1it3 sJGWV/2M2I6xV6MCu3ITfLWcIIH+xnzm0vYfznLF5oGpx4+xgjNeeYrO7UCzEI9dNzyG M0cVO+wOv1n+VwM8ArLBICwycZGjlcWRPMJPfDFINVwOpDQBfPunZVPiOyTgm7KFmPig pjFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g87clB4shdQ/MOff1dIasZ+/QQH+c4TBKLP3zroABgY=; b=PjwnMp0Dx6NBB4QmkSf9E1BHbzW6m9GYWDPoN/8nidV+XJR+mmBFZ4eJEv151725GR n2ezR/CD6Dr4fqtd5MrWHY0HDDK/2olTXGp7UVU5dajUGaebQeJeNBGovtz+EEa/689e A7wEMcdCzjjpmHVW9IjeyUeo9/ELj9ezubUBUmyBPgQIqOxQzzATzy+RBloEWloj7M9l qjqbJMc0Srd5ifvfwKyIL3oAdrfB4/r5YEjaRiH1fwxk++VjU4U8xyjOTKmxa70YKFhP YvEeYYQd0rUa9sgx7nTFihMkbXTA5NnWORMWk/hrwInhV1BSea/mSAaHZU6fiR7pufef rUIg== X-Gm-Message-State: AOAM533x/MobA0Kkuxxjcn92xh5hWJHkpGILKS9jG7ceN0WKCOdQor47 q6hQFpjEgeMRKO02hr13CcW3NzCmlU4= X-Google-Smtp-Source: ABdhPJxnLy1hTEsMCqzPwdnMgp8bUlkwtaJHXCzP0WmnAco6JgyOW6H46zO4qdwogXWff6W6/tJdvA== X-Received: by 2002:a17:902:bb8c:b029:dc:2e5e:2b2 with SMTP id m12-20020a170902bb8cb02900dc2e5e02b2mr7955627pls.10.1613054214738; Thu, 11 Feb 2021 06:36:54 -0800 (PST) Received: from Nuomi.localdomain (23.83.245.51.16clouds.com. [23.83.245.51]) by smtp.gmail.com with ESMTPSA id p29sm6564587pgm.64.2021.02.11.06.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 06:36:54 -0800 (PST) From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 Feb 2021 22:36:05 +0800 Message-Id: <20210211143611.5663-5-nuomi2021@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211143611.5663-1-nuomi2021@gmail.com> References: <20210125141507.11012-1-nuomi2021@gmail.com> <20210211143611.5663-1-nuomi2021@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 04/10] cbs_h2645: refact, allow INVALID_OFFSET for id_offset and active_offset X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/cbs_h2645.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 36212d1da6..fdc527f8e8 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -664,6 +664,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, static int cbs_h2645_replace_ps(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { + static const size_t INVALID_OFFSET = (size_t)-1; typedef struct { int nal_unit_type; int max_count; @@ -728,8 +729,8 @@ static int cbs_h2645_replace_ps(CodedBitstreamContext *ctx, const PSType *ps_type; AVBufferRef **ref_array; void **ptr_array; - void **active; - int err, id, i, nb_ps_types; + void **active = NULL; + int err, id = 0, i, nb_ps_types; switch (ctx->codec->codec_id) { case AV_CODEC_ID_H264: @@ -751,12 +752,14 @@ static int cbs_h2645_replace_ps(CodedBitstreamContext *ctx, } av_assert0(i < nb_ps_types); - id = *((uint8_t*)unit->content + ps_type->id_offset); + if (ps_type->id_offset != INVALID_OFFSET) { + id = *((uint8_t*)unit->content + ps_type->id_offset); - if (id >= ps_type->max_count) { - av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid %s id: %d.\n", - ps_type->name, id); - return AVERROR_INVALIDDATA; + if (id >= ps_type->max_count) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid %s id: %d.\n", + ps_type->name, id); + return AVERROR_INVALIDDATA; + } } err = ff_cbs_make_unit_refcounted(ctx, unit); @@ -766,9 +769,10 @@ static int cbs_h2645_replace_ps(CodedBitstreamContext *ctx, ref_array = (AVBufferRef**)((uint8_t*)ctx->priv_data + ps_type->ref_array_offset); ptr_array = (void**)((uint8_t*)ctx->priv_data + ps_type->ptr_array_offset); - active = (void**)((uint8_t*)ctx->priv_data + ps_type->active_offset); + if (ps_type->active_offset != INVALID_OFFSET) + active = (void**)((uint8_t*)ctx->priv_data + ps_type->active_offset); - if (ptr_array[id] == *active) { + if (active && ptr_array[id] == *active) { // The old active parameter set is being overwritten, so it can't // be active after this point. *active = NULL;