pluginutils: improve automatic display type selection.

This commit is contained in:
Gwenole Beauchesne 2012-07-23 18:37:38 +02:00
parent aa64ce0bed
commit 753a56e9a1
7 changed files with 69 additions and 24 deletions

View file

@ -298,7 +298,7 @@ gst_vaapidecode_create(GstVaapiDecode *decode, GstCaps *caps)
GstStructure *structure; GstStructure *structure;
int version; int version;
if (!gst_vaapi_ensure_display(decode, &decode->display)) if (!gst_vaapi_ensure_display(decode, &decode->display, NULL))
return FALSE; return FALSE;
dpy = decode->display; dpy = decode->display;
@ -531,7 +531,7 @@ gst_vaapidecode_ensure_allowed_caps(GstVaapiDecode *decode)
if (decode->allowed_caps) if (decode->allowed_caps)
return TRUE; return TRUE;
if (!gst_vaapi_ensure_display(decode, &decode->display)) if (!gst_vaapi_ensure_display(decode, &decode->display, NULL))
goto error_no_display; goto error_no_display;
decode_caps = gst_vaapi_display_get_decode_caps(decode->display); decode_caps = gst_vaapi_display_get_decode_caps(decode->display);

View file

@ -302,7 +302,7 @@ gst_vaapidownload_start(GstBaseTransform *trans)
{ {
GstVaapiDownload * const download = GST_VAAPIDOWNLOAD(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 FALSE;
return TRUE; return TRUE;
} }
@ -455,7 +455,7 @@ gst_vaapidownload_transform_caps(
if (direction == GST_PAD_SINK) { if (direction == GST_PAD_SINK) {
if (!gst_structure_has_name(structure, GST_VAAPI_SURFACE_CAPS_NAME)) if (!gst_structure_has_name(structure, GST_VAAPI_SURFACE_CAPS_NAME))
return NULL; return NULL;
if (!gst_vaapi_ensure_display(download, &download->display)) if (!gst_vaapi_ensure_display(download, &download->display, NULL))
return NULL; return NULL;
out_caps = gst_caps_from_string(gst_vaapidownload_yuv_caps_str); out_caps = gst_caps_from_string(gst_vaapidownload_yuv_caps_str);

View file

@ -43,35 +43,76 @@ static const char *display_types[] = {
NULL 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 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; GstVideoContext *context;
const DisplayMap *m;
g_return_val_if_fail(GST_IS_VIDEO_CONTEXT(element), FALSE); 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 ? */ /* Already exist ? */
if (*display) display = *display_ptr;
if (display)
return TRUE; return TRUE;
context = GST_VIDEO_CONTEXT(element); context = GST_VIDEO_CONTEXT(element);
gst_video_context_prepare(context, display_types); gst_video_context_prepare(context, display_types);
/* If no neighboor, or application not interested, use system default */ /* If no neighboor, or application not interested, use system default */
#if USE_GLX for (m = g_display_map; m->type_str != NULL; m++) {
if (!*display) if (display_type != GST_VAAPI_DISPLAY_TYPE_AUTO &&
*display = gst_vaapi_display_glx_new(NULL); display_type != m->type)
#endif continue;
if (!*display)
*display = gst_vaapi_display_x11_new(NULL);
/* FIXME allocator should return NULL in case of failure */ display = m->create_display(NULL);
if (*display && !gst_vaapi_display_get_display(*display)) { if (display) {
g_object_unref(*display); /* FIXME: allocator should return NULL if an error occurred */
*display = NULL; 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 void

View file

@ -46,7 +46,11 @@ GType
gst_vaapi_display_type_get_type(void) G_GNUC_CONST; gst_vaapi_display_type_get_type(void) G_GNUC_CONST;
gboolean gboolean
gst_vaapi_ensure_display(gpointer element, GstVaapiDisplay **display); gst_vaapi_ensure_display(
gpointer element,
GstVaapiDisplay **display,
GstVaapiDisplayType *display_type_ptr
);
void void
gst_vaapi_set_display( gst_vaapi_set_display(

View file

@ -201,7 +201,7 @@ gst_video_context_interface_init(GstVideoContextInterface *iface)
static gboolean static gboolean
gst_vaapipostproc_create(GstVaapiPostproc *postproc, GstCaps *caps) 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; return FALSE;
gst_caps_replace(&postproc->postproc_caps, caps); gst_caps_replace(&postproc->postproc_caps, caps);
@ -230,7 +230,7 @@ gst_vaapipostproc_reset(GstVaapiPostproc *postproc, GstCaps *caps)
static gboolean static gboolean
gst_vaapipostproc_start(GstVaapiPostproc *postproc) 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 FALSE;
return TRUE; return TRUE;
} }

View file

@ -99,7 +99,7 @@ enum {
PROP_USE_REFLECTION PROP_USE_REFLECTION
}; };
#define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_X11 #define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_AUTO
/* GstImplementsInterface interface */ /* GstImplementsInterface interface */
@ -263,7 +263,7 @@ configure_notify_event_pending(
static inline gboolean static inline gboolean
gst_vaapisink_ensure_display(GstVaapiSink *sink) 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 static gboolean

View file

@ -372,7 +372,7 @@ gst_vaapiupload_start(GstBaseTransform *trans)
{ {
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(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 FALSE;
return TRUE; return TRUE;