From patchwork Mon Jul 3 19:32:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42414 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589398pzh; Mon, 3 Jul 2023 12:33:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+IujoHfSLph77zkjNTfsWB2J/Xw1bpcLVy+rpmhSJCK++NsLDJm/fu1i8h59HFza3km/K X-Received: by 2002:aa7:d51a:0:b0:51a:4451:564d with SMTP id y26-20020aa7d51a000000b0051a4451564dmr15886047edq.18.1688412834168; Mon, 03 Jul 2023 12:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412834; cv=none; d=google.com; s=arc-20160816; b=pItyyjv2i+JYUgeNfSVBRcl1j6yubyiDA9eRcSxC3VOb0BSaKMY4g/mFcqlpwfcUFU dwGVR5xU6ivicgC4/kb3QYghnAPoSb1/FwCPJMquXJ+u24j8MdseR8UpRdXd+ndTMWlK AkhAiMj6jfGAWpRRQmzlQeYykDLgK+DNhGqJQsZJ5Rz5qlO/VTj0e0KKkPg52WhvgDHq UpVUzUO+oZF/YDke3Z5rF9GQqV1faDLeEktys/p6yFWJQZJknzpmhB3vLX+gnGE3J7Sp uj2o2j2o9UjZAT/Ex4ffL5+/N8Kw8A0agtWsTtvzYewqHfbYnOJl/kZdP3rqGu/Xl63X +W2Q== 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:delivered-to; bh=1V1InUrfMMCrS4SJRJ64GGPPnJEt3ZqFAK4Jm23yXA0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=VdN9RBtrcEZkNdR2noIPI0UfCGHY0F0/S+3lUUiAzpFt8IX8L72H5WUYKb2/tQqTDk 53zSVGndfLadxq4FCtf7BkLcoIS5zRAbwUZTNSzyBTlbkRYfJKJrZFvkU6QNUoyieC/D MsIfP5HlfJdovwvXHFwKYSh0B06XIDteBJ30or0KV0j2RctQNXbN3hpuaKSxO1tVXS/I wmP2zXujcEDnxgKNbiZ4b8joB5JGriTP+3Mk7wXI7ph57kkmz6Cvy4zA8gH7wstAKziz z2aRsovm2su2a7dpc8sQv3kZtSkb0Mdm8DS2JIKPRf/MCMDtLM+uRn3FeXTwRD0rN1tN xssQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f6-20020a056402160600b0051e04eb3321si3034351edv.519.2023.07.03.12.33.53; Mon, 03 Jul 2023 12:33:54 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 428D368C5C4; Mon, 3 Jul 2023 22:33:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDC0868C5B1 for ; Mon, 3 Jul 2023 22:32:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A7F372405B5 for ; Mon, 3 Jul 2023 21:32:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id k-Hn3zxkNHO7 for ; Mon, 3 Jul 2023 21:32:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id DB6C12404F8 for ; Mon, 3 Jul 2023 21:32:51 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9586C3A1267 for ; Mon, 3 Jul 2023 21:32:45 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Jul 2023 21:32:23 +0200 Message-Id: <20230703193229.8593-5-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230703193229.8593-1-anton@khirnov.net> References: <20230703193229.8593-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 04/10] lavc: add generic-decode-layer private data 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: 30sfJGE+v7FJ Move AVCodecInternal.nb_draining_errors to it, should should not be visible outside of decode.c. --- libavcodec/avcodec.c | 4 +++- libavcodec/avcodec_internal.h | 2 ++ libavcodec/decode.c | 21 +++++++++++++++++++-- libavcodec/internal.h | 3 --- libavcodec/pthread_frame.c | 3 ++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c01dac2049..aef2edce32 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -150,7 +150,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); - avci = av_mallocz(sizeof(*avci)); + avci = av_codec_is_decoder(codec) ? + ff_decode_internal_alloc() : + av_mallocz(sizeof(AVCodecInternal)); if (!avci) { ret = AVERROR(ENOMEM); goto end; diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index 6ffe575c3e..f52f91e07c 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -53,4 +53,6 @@ int ff_decode_preinit(struct AVCodecContext *avctx); void ff_decode_flush_buffers(struct AVCodecContext *avctx); void ff_encode_flush_buffers(struct AVCodecContext *avctx); +struct AVCodecInternal *ff_decode_internal_alloc(void); + #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 3115282923..acec9860a5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -50,6 +50,18 @@ #include "internal.h" #include "thread.h" +typedef struct DecodeContext { + AVCodecInternal avci; + + /* to prevent infinite loop on errors when draining */ + int nb_draining_errors; +} DecodeContext; + +static DecodeContext *decode_ctx(AVCodecInternal *avci) +{ + return (DecodeContext *)avci; +} + static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt) { int ret; @@ -439,7 +451,7 @@ FF_ENABLE_DEPRECATION_WARNINGS int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ? avctx->thread_count : 1); - if (avci->nb_draining_errors++ >= nb_errors_max) { + if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) { av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. " "Stop draining and force EOF.\n"); avci->draining_done = 1; @@ -1753,5 +1765,10 @@ void ff_decode_flush_buffers(AVCodecContext *avctx) av_bsf_flush(avci->bsf); - avci->nb_draining_errors = 0; + decode_ctx(avci)->nb_draining_errors = 0; +} + +AVCodecInternal *ff_decode_internal_alloc(void) +{ + return av_mallocz(sizeof(DecodeContext)); } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index dceae182c0..0c1f0b82ea 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -148,9 +148,6 @@ typedef struct AVCodecInternal { AVFrame *buffer_frame; int draining_done; - /* to prevent infinite loop on errors when draining */ - int nb_draining_errors; - /* used when avctx flag AV_CODEC_FLAG_DROPCHANGED is set */ int changed_frames_dropped; int initial_format; diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 008f3da43b..bc305f561f 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -28,6 +28,7 @@ #include #include "avcodec.h" +#include "avcodec_internal.h" #include "codec_internal.h" #include "decode.h" #include "hwconfig.h" @@ -815,7 +816,7 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, p->parent = fctx; p->avctx = copy; - copy->internal = av_mallocz(sizeof(*copy->internal)); + copy->internal = ff_decode_internal_alloc(); if (!copy->internal) return AVERROR(ENOMEM); copy->internal->thread_ctx = p;