[FFmpeg-devel,1/4] hwcontext_opencl: Allocate a test image in frames_init

Submitted by Mark Thompson on May 21, 2018, 10:35 p.m.

Details

Message ID 20180521223511.20395-1-sw@jkqxz.net
State New
Headers show

Commit Message

Mark Thompson May 21, 2018, 10:35 p.m.
This ensures that the format and dimensions are actually valid -
previously this wasn't checked, so we would only fail when the user
actually attempted to allocate an image.
---
 libavutil/hwcontext_opencl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 43b5c5ae0c..c29a521f07 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -1696,11 +1696,23 @@  static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
 static int opencl_frames_init(AVHWFramesContext *hwfc)
 {
     if (!hwfc->pool) {
+        AVBufferRef *test_ref;
+
         hwfc->internal->pool_internal =
             av_buffer_pool_init2(sizeof(cl_mem), hwfc,
                                  &opencl_pool_alloc, NULL);
         if (!hwfc->internal->pool_internal)
             return AVERROR(ENOMEM);
+
+        test_ref = av_buffer_pool_get(hwfc->internal->pool_internal);
+        if (!test_ref) {
+            av_log(hwfc, AV_LOG_ERROR, "Unable to create %dx%d images "
+                   "with format %s.\n", hwfc->width, hwfc->height,
+                   av_get_pix_fmt_name(hwfc->sw_format));
+            return AVERROR(EINVAL);
+        }
+
+        av_buffer_unref(&test_ref);
     }
 
     return opencl_frames_init_command_queue(hwfc);