From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0ACF249FBF for ; Sun, 17 Mar 2024 20:49:11 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA15568D1C4; Sun, 17 Mar 2024 22:49:08 +0200 (EET) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 919BB68CC9F for ; Sun, 17 Mar 2024 22:49:02 +0200 (EET) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33ececeb19eso1476134f8f.3 for ; Sun, 17 Mar 2024 13:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20230601.gappssmtp.com; s=20230601; t=1710708542; x=1711313342; darn=ffmpeg.org; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=wwjMt6nnn4T8YTIAibm4jXJoTS7Moh284VhVMjp2uy8=; b=mocsdlbpH1x9D0hHQJzgI6tFREyvymb9hv1q/I4cw+DYijB0GnwhwB6p/Va9dC0iV8 fl/hZVs+21jZPdTwc4qzmJqebWLa6viyNzx/BM/3lO0zTSJ1M9kul5uFeQt57VYWPXrM bWBX800b23KIqA0xdDOp5s2b12Pjyn2yayXMHg+MSUqs1wxk+V6znHBlb2bTzHvr9ZX6 wwLjF1o1UAWrTFDAbIWV1j75bZZGOeDMHuF95ZrpQHkmCmV8fYTQxa62Df27nUAINlop XlNLGpbqJzx6WXZQkPzDMjUtXDjdt6bvPa4hvJ7lKvZzrMMqW2CQXymByKXKFVmc67me MW+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710708542; x=1711313342; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=wwjMt6nnn4T8YTIAibm4jXJoTS7Moh284VhVMjp2uy8=; b=VexNEHGU4GwaRKrWEOx1RXsH+AZV98qCnWjagjlrT36KiQxw0K++4AaHivxhERmmmI J/Mh1sO9UJhfwCOUtlU93MT8a3qZrEap8jwI7mC88vjsokHJCkhVSWh5xy8fjCY5WYY3 uX7QqZoVybvHQJB/+QafEat0p6qx1G0GkEAk8QqQiYcN+CVRU5cwBN4zWe/pn1fYO0ZX H06KW7b1rRWFxXT2O54tFIqp2vd8guI/pqTngBnVhnkYKX12B/WrDKfHQi3jCpoMoavo i9B6isRcFXiqnx4UY4EGPuzU867Wb5whb+Wb5MhbjBlbev9ZijNhTHllXicjtqssOEvb CiYQ== X-Gm-Message-State: AOJu0YzwscWc2fT2gQuoKzDOGyOavNlATV0OZ8Ul6T4hUoU7mf8TFWmP rcFNuNWkleCQTvOY6hEnWbHqe1ciwQZya845Rz8PpFOMDdoC6p3agjBr7XJ+bzkZP5htpH4RzTf g X-Google-Smtp-Source: AGHT+IErB+SedxM3/mYZBoN+M1IPURBDrm8XqjC99elS7xaxyieGGvLhsauiZ6tIQ/yfCPkEFNKdiQ== X-Received: by 2002:a05:6000:104d:b0:33e:720e:4a4e with SMTP id c13-20020a056000104d00b0033e720e4a4emr6025852wrx.19.1710708541562; Sun, 17 Mar 2024 13:49:01 -0700 (PDT) Received: from [192.168.0.15] (cpc92302-cmbg19-2-0-cust1183.5-4.cable.virginm.net. [82.1.212.160]) by smtp.gmail.com with ESMTPSA id bj25-20020a0560001e1900b0033e68338fbasm116058wrb.81.2024.03.17.13.49.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Mar 2024 13:49:01 -0700 (PDT) Message-ID: Date: Sun, 17 Mar 2024 20:49:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: FFmpeg development discussions and patches From: Mark Thompson Subject: [FFmpeg-devel] [PATCH v3 1/2] ffmpeg: set extra_hw_frames to account for frames held in queues 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Since e0da916b8f5b079a4865eef7f64863f50785463d the ffmpeg utility has held multiple frames output by the decoder in internal queues without telling the decoder that it is going to do so. When the decoder has a fixed-size pool of frames (common in some hardware APIs where the output frames must be stored as an array texture) this could lead to the pool being exhausted and the decoder getting stuck. Fix this by telling the decoder to allocate additional frames according to the queue size. --- Rebased but otherwise unchanged since previous version. fftools/ffmpeg_dec.c | 13 +++++++++++++ fftools/ffmpeg_sched.c | 16 +++++++++++++++- fftools/ffmpeg_sched.h | 12 ++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index c41c5748e5..ed411b6bf8 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -1207,6 +1207,19 @@ static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, return ret; } + if (dp->dec_ctx->hw_device_ctx) { + // Update decoder extra_hw_frames option to account for the + // frames held in queues inside the ffmpeg utility. This is + // called after avcodec_open2() because the user-set value of + // extra_hw_frames becomes valid in there, and we need to add + // this on top of it. + int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE; + if (dp->dec_ctx->extra_hw_frames >= 0) + dp->dec_ctx->extra_hw_frames += extra_frames; + else + dp->dec_ctx->extra_hw_frames = extra_frames; + } + ret = check_avoptions(*dec_opts); if (ret < 0) return ret; diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index f739066921..ec88017e21 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -365,7 +365,21 @@ static int queue_alloc(ThreadQueue **ptq, unsigned nb_streams, unsigned queue_si ThreadQueue *tq; ObjPool *op; - queue_size = queue_size > 0 ? queue_size : 8; + if (queue_size <= 0) { + if (type == QUEUE_FRAMES) + queue_size = DEFAULT_FRAME_THREAD_QUEUE_SIZE; + else + queue_size = DEFAULT_PACKET_THREAD_QUEUE_SIZE; + } + + if (type == QUEUE_FRAMES) { + // This queue length is used in the decoder code to ensure that + // there are enough entries in fixed-size frame pools to account + // for frames held in queues inside the ffmpeg utility. If this + // can ever dynamically change then the corresponding decode + // code needs to be updated as well. + av_assert0(queue_size == DEFAULT_FRAME_THREAD_QUEUE_SIZE); + } op = (type == QUEUE_PACKETS) ? objpool_alloc_packets() : objpool_alloc_frames(); diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h index a9190bd3d1..e51c26cec9 100644 --- a/fftools/ffmpeg_sched.h +++ b/fftools/ffmpeg_sched.h @@ -233,6 +233,18 @@ int sch_add_filtergraph(Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs, */ int sch_add_mux(Scheduler *sch, SchThreadFunc func, int (*init)(void *), void *ctx, int sdp_auto, unsigned thread_queue_size); + +/** + * Default size of a packet thread queue. For muxing this can be overridden by + * the thread_queue_size option as passed to a call to sch_add_mux(). + */ +#define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8 + +/** + * Default size of a frame thread queue. + */ +#define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8 + /** * Add a muxed stream for a previously added muxer. * -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".