[FFmpeg-cvslog] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

Mark Thompson git at videolan.org
Mon Mar 25 22:49:50 EET 2024


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Sun Mar 17 20:51:29 2024 +0000| [4743c9e87a629d6af53b508c6a36135590622c16] | committer: Mark Thompson

lavc/get_buffer: Add a warning on failed allocation from a fixed pool

For hardware cases where we are forced to have a fixed pool of frames
allocated up-front (such as array textures on decoder output), suggest
a possible workaround to the user if an allocation fails because the
pool is exhausted.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4743c9e87a629d6af53b508c6a36135590622c16
---

 libavcodec/get_buffer.c | 16 ++++++++++++++++
 libavcodec/internal.h   |  6 ++++++
 2 files changed, 22 insertions(+)

diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c
index 46c20781af..9b35fde7c6 100644
--- a/libavcodec/get_buffer.c
+++ b/libavcodec/get_buffer.c
@@ -257,6 +257,22 @@ int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags
 
     if (avctx->hw_frames_ctx) {
         ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
+        if (ret == AVERROR(ENOMEM)) {
+            AVHWFramesContext *frames_ctx =
+                (AVHWFramesContext*)avctx->hw_frames_ctx->data;
+            if (frames_ctx->initial_pool_size > 0 &&
+                !avctx->internal->warned_on_failed_allocation_from_fixed_pool) {
+                av_log(avctx, AV_LOG_WARNING, "Failed to allocate a %s/%s "
+                       "frame from a fixed pool of hardware frames.\n",
+                       av_get_pix_fmt_name(frames_ctx->format),
+                       av_get_pix_fmt_name(frames_ctx->sw_format));
+                av_log(avctx, AV_LOG_WARNING, "Consider setting "
+                       "extra_hw_frames to a larger value "
+                       "(currently set to %d, giving a pool size of %d).\n",
+                       avctx->extra_hw_frames, frames_ctx->initial_pool_size);
+                avctx->internal->warned_on_failed_allocation_from_fixed_pool = 1;
+            }
+        }
         frame->width  = avctx->coded_width;
         frame->height = avctx->coded_height;
         return ret;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 04f7cebdcb..64fe0122c8 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -144,6 +144,12 @@ typedef struct AVCodecInternal {
 #if CONFIG_LCMS2
     FFIccContext icc; /* used to read and write embedded ICC profiles */
 #endif
+
+    /**
+     * Set when the user has been warned about a failed allocation from
+     * a fixed frame pool.
+     */
+    int warned_on_failed_allocation_from_fixed_pool;
 } AVCodecInternal;
 
 /**



More information about the ffmpeg-cvslog mailing list