From 753a56e9a15964df7b4658bba8ad041a7f1fac76 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Mon, 23 Jul 2012 18:37:38 +0200 Subject: [PATCH] pluginutils: improve automatic display type selection. --- gst/vaapi/gstvaapidecode.c | 4 +-- gst/vaapi/gstvaapidownload.c | 4 +-- gst/vaapi/gstvaapipluginutil.c | 69 +++++++++++++++++++++++++++++++++--------- gst/vaapi/gstvaapipluginutil.h | 6 +++- gst/vaapi/gstvaapipostproc.c | 4 +-- gst/vaapi/gstvaapisink.c | 4 +-- gst/vaapi/gstvaapiupload.c | 2 +- 7 files changed, 69 insertions(+), 24 deletions(-) diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 1680b00..b2f3113 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -298,7 +298,7 @@ gst_vaapidecode_create(GstVaapiDecode *decode, GstCaps *caps) GstStructure *structure; int version; - if (!gst_vaapi_ensure_display(decode, &decode->display)) + if (!gst_vaapi_ensure_display(decode, &decode->display, NULL)) return FALSE; dpy = decode->display; @@ -531,7 +531,7 @@ gst_vaapidecode_ensure_allowed_caps(GstVaapiDecode *decode) if (decode->allowed_caps) return TRUE; - if (!gst_vaapi_ensure_display(decode, &decode->display)) + if (!gst_vaapi_ensure_display(decode, &decode->display, NULL)) goto error_no_display; decode_caps = gst_vaapi_display_get_decode_caps(decode->display); diff --git a/gst/vaapi/gstvaapidownload.c b/gst/vaapi/gstvaapidownload.c index 7fdcbe6..4908e52 100644 --- a/gst/vaapi/gstvaapidownload.c +++ b/gst/vaapi/gstvaapidownload.c @@ -302,7 +302,7 @@ gst_vaapidownload_start(GstBaseTransform *trans) { GstVaapiDownload * const download = GST_VAAPIDOWNLOAD(trans); - if (!gst_vaapi_ensure_display(download, &download->display)) + if (!gst_vaapi_ensure_display(download, &download->display, NULL)) return FALSE; return TRUE; } @@ -455,7 +455,7 @@ gst_vaapidownload_transform_caps( if (direction == GST_PAD_SINK) { if (!gst_structure_has_name(structure, GST_VAAPI_SURFACE_CAPS_NAME)) return NULL; - if (!gst_vaapi_ensure_display(download, &download->display)) + if (!gst_vaapi_ensure_display(download, &download->display, NULL)) return NULL; out_caps = gst_caps_from_string(gst_vaapidownload_yuv_caps_str); diff --git a/gst/vaapi/gstvaapipluginutil.c b/gst/vaapi/gstvaapipluginutil.c index ce16a43..a092134 100644 --- a/gst/vaapi/gstvaapipluginutil.c +++ b/gst/vaapi/gstvaapipluginutil.c @@ -43,35 +43,76 @@ static const char *display_types[] = { NULL }; +typedef struct { + const gchar *type_str; + GstVaapiDisplayType type; + GstVaapiDisplay * (*create_display)(const gchar *); +} DisplayMap; + +static const DisplayMap g_display_map[] = { +#if USE_GLX + { "glx", + GST_VAAPI_DISPLAY_TYPE_GLX, + gst_vaapi_display_glx_new }, +#endif +#if USE_X11 + { "x11", + GST_VAAPI_DISPLAY_TYPE_X11, + gst_vaapi_display_x11_new }, +#endif + { NULL, } +}; + gboolean -gst_vaapi_ensure_display(gpointer element, GstVaapiDisplay **display) +gst_vaapi_ensure_display( + gpointer element, + GstVaapiDisplay **display_ptr, + GstVaapiDisplayType *display_type_ptr +) { + GstVaapiDisplayType display_type = + display_type_ptr ? *display_type_ptr : GST_VAAPI_DISPLAY_TYPE_AUTO; + GstVaapiDisplay *display; GstVideoContext *context; + const DisplayMap *m; g_return_val_if_fail(GST_IS_VIDEO_CONTEXT(element), FALSE); - g_return_val_if_fail(display != NULL, FALSE); + g_return_val_if_fail(display_ptr != NULL, FALSE); /* Already exist ? */ - if (*display) + display = *display_ptr; + if (display) return TRUE; context = GST_VIDEO_CONTEXT(element); gst_video_context_prepare(context, display_types); /* If no neighboor, or application not interested, use system default */ -#if USE_GLX - if (!*display) - *display = gst_vaapi_display_glx_new(NULL); -#endif - if (!*display) - *display = gst_vaapi_display_x11_new(NULL); + for (m = g_display_map; m->type_str != NULL; m++) { + if (display_type != GST_VAAPI_DISPLAY_TYPE_AUTO && + display_type != m->type) + continue; - /* FIXME allocator should return NULL in case of failure */ - if (*display && !gst_vaapi_display_get_display(*display)) { - g_object_unref(*display); - *display = NULL; + display = m->create_display(NULL); + if (display) { + /* FIXME: allocator should return NULL if an error occurred */ + if (gst_vaapi_display_get_display(display)) { + display_type = m->type; + break; + } + g_object_unref(display); + display = NULL; + } + + if (display_type != GST_VAAPI_DISPLAY_TYPE_AUTO) + break; } - return (*display != NULL); + + if (display_ptr) + *display_ptr = display; + if (display_type_ptr) + *display_type_ptr = display_type; + return display != NULL; } void diff --git a/gst/vaapi/gstvaapipluginutil.h b/gst/vaapi/gstvaapipluginutil.h index 9c3812f..ac24873 100644 --- a/gst/vaapi/gstvaapipluginutil.h +++ b/gst/vaapi/gstvaapipluginutil.h @@ -46,7 +46,11 @@ GType gst_vaapi_display_type_get_type(void) G_GNUC_CONST; gboolean -gst_vaapi_ensure_display(gpointer element, GstVaapiDisplay **display); +gst_vaapi_ensure_display( + gpointer element, + GstVaapiDisplay **display, + GstVaapiDisplayType *display_type_ptr +); void gst_vaapi_set_display( diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index 3b81830..bfd18c0 100644 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -201,7 +201,7 @@ gst_video_context_interface_init(GstVideoContextInterface *iface) static gboolean gst_vaapipostproc_create(GstVaapiPostproc *postproc, GstCaps *caps) { - if (!gst_vaapi_ensure_display(postproc, &postproc->display)) + if (!gst_vaapi_ensure_display(postproc, &postproc->display, NULL)) return FALSE; gst_caps_replace(&postproc->postproc_caps, caps); @@ -230,7 +230,7 @@ gst_vaapipostproc_reset(GstVaapiPostproc *postproc, GstCaps *caps) static gboolean gst_vaapipostproc_start(GstVaapiPostproc *postproc) { - if (!gst_vaapi_ensure_display(postproc, &postproc->display)) + if (!gst_vaapi_ensure_display(postproc, &postproc->display, NULL)) return FALSE; return TRUE; } diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c index 7fcf372..7a99219 100644 --- a/gst/vaapi/gstvaapisink.c +++ b/gst/vaapi/gstvaapisink.c @@ -99,7 +99,7 @@ enum { PROP_USE_REFLECTION }; -#define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_X11 +#define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_AUTO /* GstImplementsInterface interface */ @@ -263,7 +263,7 @@ configure_notify_event_pending( static inline gboolean gst_vaapisink_ensure_display(GstVaapiSink *sink) { - return gst_vaapi_ensure_display(sink, &sink->display); + return gst_vaapi_ensure_display(sink, &sink->display, &sink->display_type); } static gboolean diff --git a/gst/vaapi/gstvaapiupload.c b/gst/vaapi/gstvaapiupload.c index 9e5d513..fac9a7d 100644 --- a/gst/vaapi/gstvaapiupload.c +++ b/gst/vaapi/gstvaapiupload.c @@ -372,7 +372,7 @@ gst_vaapiupload_start(GstBaseTransform *trans) { GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans); - if (!gst_vaapi_ensure_display(upload, &upload->display)) + if (!gst_vaapi_ensure_display(upload, &upload->display, NULL)) return FALSE; return TRUE; -- 2.7.4