[FFmpeg-devel] [PATCH] lavfi: add helper macro for OpenCL error handling.

Ruiling Song ruiling.song at intel.com
Tue Jun 12 10:20:32 EEST 2018


Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
I am not sure whether do you think this would be useful?
the main purpose is to make OpenCL error check code simpler.
If we think this is good, I can go to replace current
OpenCL filters to use this macro.

for example:
        if (cle != CL_SUCCESS) {
            av_log(avctx, AV_LOG_ERROR, "Failed to enqueue kernel: %d.\n",
                   cle);
            err = AVERROR(EIO);
            goto fail;
        }
can be replaced with:
OCL_FAIL_ON_ERR(avctx, cle, AVERROR(EIO), "Failed to enqueue kernel: %d.\n", cle);

Thanks!
Ruiling
 libavfilter/opencl.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/libavfilter/opencl.h b/libavfilter/opencl.h
index c0a4519..c33df1c 100644
--- a/libavfilter/opencl.h
+++ b/libavfilter/opencl.h
@@ -97,5 +97,16 @@ int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx,
                                           size_t *work_size,
                                           AVFrame *frame, int plane,
                                           int block_alignment);
+/**
+ * A helper macro to handle OpenCL error. It will assign errcode to
+ * variable err, log error msg, and jump to fail label on error.
+ */
+#define OCL_FAIL_ON_ERR(logctx, cle, errcode, ...) do {\
+    if (cle != CL_SUCCESS) {\
+        av_log(logctx, AV_LOG_ERROR, __VA_ARGS__);\
+        err = errcode;\
+        goto fail;\
+    }\
+} while(0)
 
 #endif /* AVFILTER_OPENCL_H */
-- 
2.7.4



More information about the ffmpeg-devel mailing list