diff --git a/docs/reference/libs/libs-sections.txt b/docs/reference/libs/libs-sections.txt index 9ab6b92e08..6de29292aa 100644 --- a/docs/reference/libs/libs-sections.txt +++ b/docs/reference/libs/libs-sections.txt @@ -133,6 +133,8 @@ GstVaapiDisplayClass gst_vaapi_display_new_with_display gst_vaapi_display_lock gst_vaapi_display_unlock +gst_vaapi_display_sync +gst_vaapi_display_flush gst_vaapi_display_get_display gst_vaapi_display_get_width gst_vaapi_display_get_height diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c index 314bf38af3..f015620c22 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay.c @@ -48,10 +48,10 @@ struct _GstVaapiDisplayPrivate { guint height_mm; guint par_n; guint par_d; - gboolean create_display; GArray *profiles; GArray *image_formats; GArray *subpicture_formats; + guint create_display : 1; }; enum { @@ -504,10 +504,10 @@ gst_vaapi_display_init(GstVaapiDisplay *display) priv->height_mm = 0; priv->par_n = 1; priv->par_d = 1; - priv->create_display = TRUE; priv->profiles = NULL; priv->image_formats = NULL; priv->subpicture_formats = NULL; + priv->create_display = TRUE; g_static_mutex_init(&priv->mutex); } @@ -569,6 +569,52 @@ gst_vaapi_display_unlock(GstVaapiDisplay *display) klass->unlock(display); } +/** + * gst_vaapi_display_sync: + * @display: a #GstVaapiDisplay + * + * Flushes any requests queued for the windowing system and waits until + * all requests have been handled. This is often used for making sure + * that the display is synchronized with the current state of the program. + * + * This is most useful for X11. On windowing systems where requests are + * handled synchronously, this function will do nothing. + */ +void +gst_vaapi_display_sync(GstVaapiDisplay *display) +{ + GstVaapiDisplayClass *klass; + + g_return_if_fail(GST_VAAPI_IS_DISPLAY(display)); + + klass = GST_VAAPI_DISPLAY_GET_CLASS(display); + if (klass->sync) + klass->sync(display); + else if (klass->flush) + klass->flush(display); +} + +/** + * gst_vaapi_display_sync: + * @display: a #GstVaapiDisplay + * + * Flushes any requests queued for the windowing system. + * + * This is most useful for X11. On windowing systems where requests + * are handled synchronously, this function will do nothing. + */ +void +gst_vaapi_display_flush(GstVaapiDisplay *display) +{ + GstVaapiDisplayClass *klass; + + g_return_if_fail(GST_VAAPI_IS_DISPLAY(display)); + + klass = GST_VAAPI_DISPLAY_GET_CLASS(display); + if (klass->flush) + klass->flush(display); +} + /** * gst_vaapi_display_get_display: * @display: a #GstVaapiDisplay diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.h b/gst-libs/gst/vaapi/gstvaapidisplay.h index 1147d00b33..e654be63ee 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay.h +++ b/gst-libs/gst/vaapi/gstvaapidisplay.h @@ -103,8 +103,10 @@ struct _GstVaapiDisplay { * GstVaapiDisplayClass: * @open_display: virtual function to open a display * @close_display: virtual function to close a display - * @lock: virtual function to lock a display - * @unlock: virtual function to unlock a display + * @lock: (optional) virtual function to lock a display + * @unlock: (optional) virtual function to unlock a display + * @sync: (optional) virtual function to sync a display + * @flush: (optional) virtual function to flush pending requests of a display * @get_display: virtual function to retrieve the #VADisplay * @get_size: virtual function to retrieve the display dimensions, in pixels * @get_size_mm: virtual function to retrieve the display dimensions, in millimeters @@ -120,6 +122,8 @@ struct _GstVaapiDisplayClass { void (*close_display) (GstVaapiDisplay *display); void (*lock) (GstVaapiDisplay *display); void (*unlock) (GstVaapiDisplay *display); + void (*sync) (GstVaapiDisplay *display); + void (*flush) (GstVaapiDisplay *display); VADisplay (*get_display) (GstVaapiDisplay *display); void (*get_size) (GstVaapiDisplay *display, guint *pwidth, guint *pheight); @@ -139,6 +143,12 @@ gst_vaapi_display_lock(GstVaapiDisplay *display); void gst_vaapi_display_unlock(GstVaapiDisplay *display); +void +gst_vaapi_display_sync(GstVaapiDisplay *display); + +void +gst_vaapi_display_flush(GstVaapiDisplay *display); + VADisplay gst_vaapi_display_get_display(GstVaapiDisplay *display); diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c index 9f4349e13b..705051b142 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c @@ -192,6 +192,26 @@ gst_vaapi_display_x11_close_display(GstVaapiDisplay *display) } } +static void +gst_vaapi_display_x11_sync(GstVaapiDisplay *display) +{ + GstVaapiDisplayX11Private * const priv = + GST_VAAPI_DISPLAY_X11(display)->priv; + + if (priv->x11_display) + XSync(priv->x11_display, False); +} + +static void +gst_vaapi_display_x11_flush(GstVaapiDisplay *display) +{ + GstVaapiDisplayX11Private * const priv = + GST_VAAPI_DISPLAY_X11(display)->priv; + + if (priv->x11_display) + XFlush(priv->x11_display); +} + static VADisplay gst_vaapi_display_x11_get_va_display(GstVaapiDisplay *display) { @@ -253,6 +273,8 @@ gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass) dpy_class->open_display = gst_vaapi_display_x11_open_display; dpy_class->close_display = gst_vaapi_display_x11_close_display; + dpy_class->sync = gst_vaapi_display_x11_sync; + dpy_class->flush = gst_vaapi_display_x11_flush; dpy_class->get_display = gst_vaapi_display_x11_get_va_display; dpy_class->get_size = gst_vaapi_display_x11_get_size; dpy_class->get_size_mm = gst_vaapi_display_x11_get_size_mm;