[FFmpeg-devel,4/6] hwcontext_vaapi: Set message callbacks on internally-created devices

Submitted by Mark Thompson on Oct. 8, 2017, 3:11 p.m.

Details

Message ID 20171008151146.13505-4-sw@jkqxz.net
State New
Headers show

Commit Message

Mark Thompson Oct. 8, 2017, 3:11 p.m.
The message callbacks are library-safe in libva2, so we can now use
them.  Also factorise out the common connection code to avoid
duplicating this change.
---
 libavutil/hwcontext_vaapi.c | 74 +++++++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 29 deletions(-)

Comments

Derek Buitenhuis Oct. 8, 2017, 3:51 p.m.
On 10/8/2017 4:11 PM, Mark Thompson wrote:
> The message callbacks are library-safe in libva2, so we can now use
> them.  Also factorise out the common connection code to avoid
> duplicating this change.
> ---
>  libavutil/hwcontext_vaapi.c | 74 +++++++++++++++++++++++++++------------------
>  1 file changed, 45 insertions(+), 29 deletions(-)

Would have preferred these be two separate patches, but I also don't
have strong feelings about it.

Looks OK, assuming libva2 guarantees NULL-termination of the message.

- Derek
Mark Thompson Oct. 8, 2017, 4 p.m.
On 08/10/17 16:51, Derek Buitenhuis wrote:
> On 10/8/2017 4:11 PM, Mark Thompson wrote:
>> The message callbacks are library-safe in libva2, so we can now use
>> them.  Also factorise out the common connection code to avoid
>> duplicating this change.
>> ---
>>  libavutil/hwcontext_vaapi.c | 74 +++++++++++++++++++++++++++------------------
>>  1 file changed, 45 insertions(+), 29 deletions(-)
> 
> Would have preferred these be two separate patches, but I also don't
> have strong feelings about it.

Easy enough to do.

Split as:

"""
hwcontext_vaapi: Factorise out common connection code

This was duplicated between normal device creation and creation by
derivation from a DRM device.
"""

and

"""
hwcontext_vaapi: Set message callbacks on internally-created devices

The message callbacks are library-safe in libva2, so we can now use
them.
"""

with the obvious change.

Thanks,

- Mark
Derek Buitenhuis Oct. 8, 2017, 4:04 p.m.
On 10/8/2017 5:00 PM, Mark Thompson wrote:
> Easy enough to do.
> 
> Split as:
> 
> """
> hwcontext_vaapi: Factorise out common connection code
> 
> This was duplicated between normal device creation and creation by
> derivation from a DRM device.
> """
> 
> and
> 
> """
> hwcontext_vaapi: Set message callbacks on internally-created devices
> 
> The message callbacks are library-safe in libva2, so we can now use
> them.
> """
> 
> with the obvious change.

Sounds good.

- Derek

Patch hide | download patch | download mbox

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 9214dc6e50..b2f2e376d8 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1094,14 +1094,53 @@  static void vaapi_device_free(AVHWDeviceContext *ctx)
     av_freep(&priv);
 }
 
+#if CONFIG_VAAPI_1
+static void vaapi_device_log_error(void *context, const char *message)
+{
+    AVHWDeviceContext *ctx = context;
+
+    av_log(ctx, AV_LOG_ERROR, "libva: %s", message);
+}
+
+static void vaapi_device_log_info(void *context, const char *message)
+{
+    AVHWDeviceContext *ctx = context;
+
+    av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
+}
+#endif
+
+static int vaapi_device_connect(AVHWDeviceContext *ctx,
+                                VADisplay display)
+{
+    AVVAAPIDeviceContext *hwctx = ctx->hwctx;
+    int major, minor;
+    VAStatus vas;
+
+#if CONFIG_VAAPI_1
+    vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
+    vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
+#endif
+
+    hwctx->display = display;
+
+    vas = vaInitialize(display, &major, &minor);
+    if (vas != VA_STATUS_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
+               "connection: %d (%s).\n", vas, vaErrorStr(vas));
+        return AVERROR(EIO);
+    }
+    av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
+           "version %d.%d\n", major, minor);
+
+    return 0;
+}
+
 static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
                                AVDictionary *opts, int flags)
 {
-    AVVAAPIDeviceContext *hwctx = ctx->hwctx;
     VAAPIDevicePriv *priv;
-    VADisplay display = 0;
-    VAStatus vas;
-    int major, minor;
+    VADisplay display = NULL;
 
     priv = av_mallocz(sizeof(*priv));
     if (!priv)
@@ -1163,18 +1202,7 @@  static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
         return AVERROR(EINVAL);
     }
 
-    hwctx->display = display;
-
-    vas = vaInitialize(display, &major, &minor);
-    if (vas != VA_STATUS_SUCCESS) {
-        av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
-               "connection: %d (%s).\n", vas, vaErrorStr(vas));
-        return AVERROR(EIO);
-    }
-    av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
-           "version %d.%d\n", major, minor);
-
-    return 0;
+    return vaapi_device_connect(ctx, display);
 }
 
 static int vaapi_device_derive(AVHWDeviceContext *ctx,
@@ -1183,11 +1211,8 @@  static int vaapi_device_derive(AVHWDeviceContext *ctx,
 #if CONFIG_LIBDRM
     if (src_ctx->type == AV_HWDEVICE_TYPE_DRM) {
         AVDRMDeviceContext *src_hwctx = src_ctx->hwctx;
-        AVVAAPIDeviceContext   *hwctx = ctx->hwctx;
         VADisplay *display;
-        VAStatus vas;
         VAAPIDevicePriv *priv;
-        int major, minor;
 
         if (src_hwctx->fd < 0) {
             av_log(ctx, AV_LOG_ERROR, "DRM instance requires an associated "
@@ -1212,16 +1237,7 @@  static int vaapi_device_derive(AVHWDeviceContext *ctx,
             return AVERROR(EIO);
         }
 
-        hwctx->display = display;
-
-        vas = vaInitialize(display, &major, &minor);
-        if (vas != VA_STATUS_SUCCESS) {
-            av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
-                   "connection: %d (%s).\n", vas, vaErrorStr(vas));
-            return AVERROR(EIO);
-        }
-
-        return 0;
+        return vaapi_device_connect(ctx, display);
     }
 #endif
     return AVERROR(ENOSYS);