#include "gst/vaapi/sysdeps.h"
#include "gstvaapipluginbase.h"
+#include "gstvaapipluginutil.h"
+/* Default debug category is from the subclass */
#define GST_CAT_DEFAULT (plugin->debug_category)
+static void
+default_display_changed (GstVaapiPluginBase * plugin)
+{
+}
+
void
gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass)
{
+ klass->display_changed = default_display_changed;
}
void
GstDebugCategory * debug_category)
{
plugin->debug_category = debug_category;
+
+ plugin->display_type = GST_VAAPI_DISPLAY_TYPE_ANY;
+ plugin->display_type_req = GST_VAAPI_DISPLAY_TYPE_ANY;
}
void
{
gst_vaapi_display_replace (&plugin->display, NULL);
}
+
+/**
+ * gst_vaapi_plugin_base_set_display_type:
+ * @plugin: a #GstVaapiPluginBase
+ * @display_type: the new request #GstVaapiDisplayType
+ *
+ * Requests a new display type. The change is effective at the next
+ * call to gst_vaapi_plugin_base_ensure_display().
+ */
+void
+gst_vaapi_plugin_base_set_display_type (GstVaapiPluginBase * plugin,
+ GstVaapiDisplayType display_type)
+{
+ plugin->display_type_req = display_type;
+}
+
+/* Checks wether display type 1 is compatible with display type 2 */
+static gboolean
+display_type_is_compatible (GstVaapiDisplayType type1,
+ GstVaapiDisplayType type2)
+{
+ return (type1 == type2 || type2 == GST_VAAPI_DISPLAY_TYPE_ANY);
+}
+
+/**
+ * gst_vaapi_plugin_base_ensure_display:
+ * @plugin: a #GstVaapiPluginBase
+ *
+ * Ensures the display stored in @plugin complies with the requested
+ * display type constraints.
+ *
+ * Returns: %TRUE if the display was created to match the requested
+ * type, %FALSE otherwise.
+ */
+gboolean
+gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin)
+{
+ if (plugin->display && display_type_is_compatible (plugin->display_type,
+ plugin->display_type_req))
+ return TRUE;
+ gst_vaapi_display_replace (&plugin->display, NULL);
+
+ if (!gst_vaapi_ensure_display (plugin, plugin->display_type_req))
+ return FALSE;
+ plugin->display_type = gst_vaapi_display_get_display_type (plugin->display);
+
+ GST_VAAPI_PLUGIN_BASE_GET_CLASS (plugin)->display_changed (plugin);
+ return TRUE;
+}
# include <gst/vaapi/gstvaapidisplay_wayland.h>
#endif
#include "gstvaapipluginutil.h"
+#include "gstvaapipluginbase.h"
/* Preferred first */
static const char *display_types[] = {
};
static GstVaapiDisplay *
-gst_vaapi_create_display(GstVaapiDisplayType *display_type)
+gst_vaapi_create_display(GstVaapiDisplayType display_type)
{
GstVaapiDisplay *display = NULL;
const DisplayMap *m;
for (m = g_display_map; m->type_str != NULL; m++) {
- if (*display_type != GST_VAAPI_DISPLAY_TYPE_ANY &&
- *display_type != m->type)
+ if (display_type != GST_VAAPI_DISPLAY_TYPE_ANY &&
+ display_type != m->type)
continue;
display = m->create_display(NULL);
- if (display) {
- *display_type = m->type;
- break;
- }
-
- if (*display_type != GST_VAAPI_DISPLAY_TYPE_ANY)
+ if (display || display_type != GST_VAAPI_DISPLAY_TYPE_ANY)
break;
}
return display;
}
gboolean
-gst_vaapi_ensure_display(
- gpointer element,
- GstVaapiDisplayType display_type,
- GstVaapiDisplay **display_ptr
-)
+gst_vaapi_ensure_display(gpointer element, GstVaapiDisplayType type)
{
+ GstVaapiPluginBase * const plugin = GST_VAAPI_PLUGIN_BASE(element);
GstVaapiDisplay *display;
GstVideoContext *context;
g_return_val_if_fail(GST_IS_VIDEO_CONTEXT(element), FALSE);
- g_return_val_if_fail(display_ptr != NULL, FALSE);
-
- /* Already exist ? */
- display = *display_ptr;
- if (display)
- return TRUE;
context = GST_VIDEO_CONTEXT(element);
g_return_val_if_fail(context != NULL, FALSE);
gst_vaapi_video_context_prepare(context, display_types);
/* Neighbour found and it updated the display */
- if (*display_ptr)
+ if (plugin->display)
return TRUE;
/* If no neighboor, or application not interested, use system default */
- display = gst_vaapi_create_display(&display_type);
+ display = gst_vaapi_create_display(type);
if (!display)
return FALSE;
gst_vaapi_video_context_propagate(context, display);
- *display_ptr = display;
+ GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(plugin, display);
+ gst_vaapi_display_unref(display);
return TRUE;
}
gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer);
static void
-gst_vaapisink_video_overlay_set_window_handle(GstVideoOverlay *overlay, guintptr window)
+gst_vaapisink_video_overlay_set_window_handle(GstVideoOverlay *overlay,
+ guintptr window)
{
GstVaapiSink * const sink = GST_VAAPISINK(overlay);
+ GstVaapiDisplayType display_type = GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink);
/* Disable GLX rendering when vaapisink is using a foreign X
window. It's pretty much useless */
- if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_GLX)
- sink->display_type = GST_VAAPI_DISPLAY_TYPE_X11;
+ if (display_type == GST_VAAPI_DISPLAY_TYPE_GLX) {
+ display_type = GST_VAAPI_DISPLAY_TYPE_X11;
+ gst_vaapi_plugin_base_set_display_type(GST_VAAPI_PLUGIN_BASE(sink),
+ display_type);
+ }
sink->foreign_window = TRUE;
- switch (sink->display_type) {
+ switch (display_type) {
#if USE_X11
case GST_VAAPI_DISPLAY_TYPE_X11:
gst_vaapisink_ensure_window_xid(sink, window);
static inline gboolean
gst_vaapisink_ensure_display(GstVaapiSink *sink)
{
- GstVaapiDisplayType display_type;
- GstVaapiRenderMode render_mode;
- const gboolean had_display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink) != NULL;
+ return gst_vaapi_plugin_base_ensure_display(GST_VAAPI_PLUGIN_BASE(sink));
+}
- if (!gst_vaapi_ensure_display(sink, sink->display_type, &GST_VAAPI_PLUGIN_BASE_DISPLAY(sink)))
- return FALSE;
+static void
+gst_vaapisink_display_changed(GstVaapiPluginBase *plugin)
+{
+ GstVaapiSink * const sink = GST_VAAPISINK(plugin);
+ GstVaapiRenderMode render_mode;
- display_type = gst_vaapi_display_get_display_type(GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
- if (display_type != sink->display_type || (!had_display && GST_VAAPI_PLUGIN_BASE_DISPLAY(sink))) {
- GST_INFO("created %s %p", get_display_type_name(display_type),
- GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
- sink->display_type = display_type;
+ GST_INFO("created %s %p", get_display_type_name(plugin->display_type),
+ plugin->display);
- sink->use_overlay =
- gst_vaapi_display_get_render_mode(GST_VAAPI_PLUGIN_BASE_DISPLAY(sink), &render_mode) &&
- render_mode == GST_VAAPI_RENDER_MODE_OVERLAY;
- GST_DEBUG("use %s rendering mode", sink->use_overlay ? "overlay" : "texture");
+ sink->use_overlay =
+ gst_vaapi_display_get_render_mode(plugin->display, &render_mode) &&
+ render_mode == GST_VAAPI_RENDER_MODE_OVERLAY;
+ GST_DEBUG("use %s rendering mode",
+ sink->use_overlay ? "overlay" : "texture");
- sink->use_rotation = gst_vaapi_display_has_property(
- GST_VAAPI_PLUGIN_BASE_DISPLAY(sink), GST_VAAPI_DISPLAY_PROP_ROTATION);
- }
- return TRUE;
+ sink->use_rotation = gst_vaapi_display_has_property(plugin->display,
+ GST_VAAPI_DISPLAY_PROP_ROTATION);
}
static gboolean
GstVaapiDisplay * const display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
if (!sink->window) {
- switch (sink->display_type) {
+ const GstVaapiDisplayType display_type =
+ GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink);
+ switch (display_type) {
#if USE_GLX
case GST_VAAPI_DISPLAY_TYPE_GLX:
sink->window = gst_vaapi_window_glx_new(display, width, height);
break;
#endif
default:
- GST_ERROR("unsupported display type %d", sink->display_type);
+ GST_ERROR("unsupported display type %d", display_type);
return FALSE;
}
}
gst_vaapi_window_replace(&sink->window, NULL);
- switch (sink->display_type) {
+ switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
#if USE_GLX
case GST_VAAPI_DISPLAY_TYPE_GLX:
sink->window = gst_vaapi_window_glx_new_with_xid(display, xid);
sink->window = gst_vaapi_window_x11_new_with_xid(display, xid);
break;
default:
- GST_ERROR("unsupported display type %d", sink->display_type);
+ GST_ERROR("unsupported display type %d",
+ GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink));
return FALSE;
}
return sink->window != NULL;
GstVaapiDisplay *display;
guint win_width, win_height;
+ if (!gst_vaapisink_ensure_display(sink))
+ return FALSE;
+ display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
+
#if USE_DRM
- if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_DRM)
+ if (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink) == GST_VAAPI_DISPLAY_TYPE_DRM)
return TRUE;
#endif
gst_caps_replace(&sink->caps, caps);
- if (!gst_vaapisink_ensure_display(sink))
- return FALSE;
- display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
-
#if !GST_CHECK_VERSION(1,0,0)
if (sink->use_video_raw) {
/* Ensure the uploader is set up for upstream allocated buffers */
if (!gst_vaapi_apply_composition(surface, src_buffer))
GST_WARNING("could not update subtitles");
- switch (sink->display_type) {
+ switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
#if USE_DRM
case GST_VAAPI_DISPLAY_TYPE_DRM:
success = TRUE;
break;
#endif
default:
- GST_ERROR("unsupported display type %d", sink->display_type);
+ GST_ERROR("unsupported display type %d",
+ GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink));
success = FALSE;
break;
}
switch (prop_id) {
case PROP_DISPLAY_TYPE:
- sink->display_type = g_value_get_enum(value);
+ gst_vaapi_plugin_base_set_display_type(GST_VAAPI_PLUGIN_BASE(sink),
+ g_value_get_enum(value));
break;
case PROP_FULLSCREEN:
sink->fullscreen = g_value_get_boolean(value);
switch (prop_id) {
case PROP_DISPLAY_TYPE:
- g_value_set_enum(value, sink->display_type);
+ g_value_set_enum(value, GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink));
break;
case PROP_FULLSCREEN:
g_value_set_boolean(value, sink->fullscreen);
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
GstBaseSinkClass * const basesink_class = GST_BASE_SINK_CLASS(klass);
+ GstVaapiPluginBaseClass * const base_plugin_class =
+ GST_VAAPI_PLUGIN_BASE_CLASS(klass);
GstPadTemplate *pad_template;
GST_DEBUG_CATEGORY_INIT(gst_debug_vaapisink,
GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
- gst_vaapi_plugin_base_class_init(GST_VAAPI_PLUGIN_BASE_CLASS(klass));
+ gst_vaapi_plugin_base_class_init(base_plugin_class);
+ base_plugin_class->display_changed = gst_vaapisink_display_changed;
object_class->finalize = gst_vaapisink_finalize;
object_class->set_property = gst_vaapisink_set_property;
static void
gst_vaapisink_init(GstVaapiSink *sink)
{
- gst_vaapi_plugin_base_init(GST_VAAPI_PLUGIN_BASE(sink), GST_CAT_DEFAULT);
+ GstVaapiPluginBase * const plugin = GST_VAAPI_PLUGIN_BASE(sink);
+
+ gst_vaapi_plugin_base_init(plugin, GST_CAT_DEFAULT);
+ gst_vaapi_plugin_base_set_display_type(plugin, DEFAULT_DISPLAY_TYPE);
sink->caps = NULL;
sink->window = NULL;
sink->foreign_window = FALSE;
sink->fullscreen = FALSE;
sink->synchronous = FALSE;
- sink->display_type = DEFAULT_DISPLAY_TYPE;
sink->rotation = DEFAULT_ROTATION;
sink->rotation_req = DEFAULT_ROTATION;
sink->use_reflection = FALSE;