2 * gstvaapipluginutil.h - VA-API plugin helpers
4 * Copyright (C) 2011-2012 Intel Corporation
5 * Copyright (C) 2011 Collabora
6 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA
28 #include <gst/video/videocontext.h>
30 # include <gst/vaapi/gstvaapidisplay_drm.h>
33 # include <gst/vaapi/gstvaapidisplay_x11.h>
36 # include <gst/vaapi/gstvaapidisplay_glx.h>
39 # include <gst/vaapi/gstvaapidisplay_wayland.h>
41 #include "gstvaapipluginutil.h"
44 static const char *display_types[] = {
63 const gchar *type_str;
64 GstVaapiDisplayType type;
65 GstVaapiDisplay * (*create_display)(const gchar *);
68 static const DisplayMap g_display_map[] = {
71 GST_VAAPI_DISPLAY_TYPE_WAYLAND,
72 gst_vaapi_display_wayland_new },
76 GST_VAAPI_DISPLAY_TYPE_X11,
77 gst_vaapi_display_x11_new },
81 GST_VAAPI_DISPLAY_TYPE_GLX,
82 gst_vaapi_display_glx_new },
86 GST_VAAPI_DISPLAY_TYPE_DRM,
87 gst_vaapi_display_drm_new },
93 gst_vaapi_ensure_display(
95 GstVaapiDisplayType display_type,
96 GstVaapiDisplay **display_ptr
99 GstVaapiDisplay *display;
100 GstVideoContext *context;
103 g_return_val_if_fail(GST_IS_VIDEO_CONTEXT(element), FALSE);
104 g_return_val_if_fail(display_ptr != NULL, FALSE);
106 /* Already exist ? */
107 display = *display_ptr;
111 context = GST_VIDEO_CONTEXT(element);
112 g_return_val_if_fail(context != NULL, FALSE);
114 gst_video_context_prepare(context, display_types);
116 /* Neighbour found and it updated the display */
120 /* If no neighboor, or application not interested, use system default */
121 for (m = g_display_map; m->type_str != NULL; m++) {
122 if (display_type != GST_VAAPI_DISPLAY_TYPE_ANY &&
123 display_type != m->type)
126 display = m->create_display(NULL);
128 /* FIXME: allocator should return NULL if an error occurred */
129 if (gst_vaapi_display_get_display(display)) {
130 display_type = m->type;
133 g_object_unref(display);
137 if (display_type != GST_VAAPI_DISPLAY_TYPE_ANY)
142 *display_ptr = display;
143 return display != NULL;
147 gst_vaapi_set_display(
150 GstVaapiDisplay **display
153 GstVaapiDisplay *dpy = NULL;
155 if (!strcmp(type, "vaapi-display")) {
156 g_return_if_fail(G_VALUE_HOLDS_POINTER(value));
157 dpy = gst_vaapi_display_new_with_display(g_value_get_pointer(value));
159 else if (!strcmp(type, "gst-vaapi-display")) {
160 g_return_if_fail(G_VALUE_HOLDS_OBJECT(value));
161 dpy = g_value_dup_object(value);
164 else if (!strcmp(type, "drm-device")) {
166 g_return_if_fail(G_VALUE_HOLDS_INT(value));
167 device = g_value_get_int(value);
168 dpy = gst_vaapi_display_drm_new_with_device(device);
170 else if (!strcmp(type, "drm-device-path")) {
171 const gchar *device_path;
172 g_return_if_fail(G_VALUE_HOLDS_STRING(value));
173 device_path = g_value_get_string(value);
174 dpy = gst_vaapi_display_drm_new(device_path);
178 else if (!strcmp(type, "x11-display-name")) {
179 g_return_if_fail(G_VALUE_HOLDS_STRING(value));
181 dpy = gst_vaapi_display_glx_new(g_value_get_string(value));
184 dpy = gst_vaapi_display_x11_new(g_value_get_string(value));
186 else if (!strcmp(type, "x11-display")) {
187 g_return_if_fail(G_VALUE_HOLDS_POINTER(value));
189 dpy = gst_vaapi_display_glx_new_with_display(g_value_get_pointer(value));
192 dpy = gst_vaapi_display_x11_new_with_display(g_value_get_pointer(value));
196 else if (!strcmp(type, "wl-display")) {
197 struct wl_display *wl_display;
198 g_return_if_fail(G_VALUE_HOLDS_POINTER(value));
199 wl_display = g_value_get_pointer(value);
200 dpy = gst_vaapi_display_wayland_new_with_display(wl_display);
202 else if (!strcmp(type, "wl-display-name")) {
203 const gchar *display_name;
204 g_return_if_fail(G_VALUE_HOLDS_STRING(value));
205 display_name = g_value_get_string(value);
206 dpy = gst_vaapi_display_wayland_new(display_name);
212 g_object_unref(*display);
218 gst_vaapi_reply_to_query(GstQuery *query, GstVaapiDisplay *display)
220 GstVaapiDisplayType display_type;
224 gboolean res = FALSE;
229 types = gst_video_context_query_get_supported_types(query);
234 display_type = gst_vaapi_display_get_display_type(display);
235 for (i = 0; types[i] && !res; i++) {
239 if (!strcmp(type, "gst-vaapi-display")) {
240 gst_video_context_query_set_object(query, type, G_OBJECT(display));
242 else if (!strcmp(type, "vaapi-display")) {
243 VADisplay vadpy = gst_vaapi_display_get_display(display);
244 gst_video_context_query_set_pointer(query, type, vadpy);
247 switch (display_type) {
249 case GST_VAAPI_DISPLAY_TYPE_DRM: {
250 GstVaapiDisplayDRM * const drm_dpy =
251 GST_VAAPI_DISPLAY_DRM(display);
252 if (!strcmp(type, "drm-device-path"))
253 gst_video_context_query_set_string(query, type,
254 gst_vaapi_display_drm_get_device_path(drm_dpy));
256 /* XXX: gst_video_context_query_set_int() does not exist yet */
257 else if (!strcmp(type, "drm-device"))
258 gst_video_context_query_set_int(query, type,
259 gst_vaapi_display_drm_get_device(drm_dpy));
268 case GST_VAAPI_DISPLAY_TYPE_GLX:
270 case GST_VAAPI_DISPLAY_TYPE_X11: {
271 GstVaapiDisplayX11 * const xvadpy =
272 GST_VAAPI_DISPLAY_X11(display);
273 Display * const x11dpy =
274 gst_vaapi_display_x11_get_display(xvadpy);
275 if (!strcmp(type, "x11-display"))
276 gst_video_context_query_set_pointer(query, type, x11dpy);
277 else if (!strcmp(type, "x11-display-name"))
278 gst_video_context_query_set_string(query, type,
279 DisplayString(x11dpy));
286 case GST_VAAPI_DISPLAY_TYPE_WAYLAND: {
287 GstVaapiDisplayWayland * const wlvadpy =
288 GST_VAAPI_DISPLAY_WAYLAND(display);
289 struct wl_display * const wldpy =
290 gst_vaapi_display_wayland_get_display(wlvadpy);
291 if (!strcmp(type, "wl-display"))
292 gst_video_context_query_set_pointer(query, type, wldpy);
308 gst_vaapi_append_surface_caps(GstCaps *out_caps, GstCaps *in_caps)
310 GstStructure *structure;
311 const GValue *v_width, *v_height, *v_framerate, *v_par;
312 guint i, n_structures;
314 structure = gst_caps_get_structure(in_caps, 0);
315 v_width = gst_structure_get_value(structure, "width");
316 v_height = gst_structure_get_value(structure, "height");
317 v_framerate = gst_structure_get_value(structure, "framerate");
318 v_par = gst_structure_get_value(structure, "pixel-aspect-ratio");
319 if (!v_width || !v_height)
322 n_structures = gst_caps_get_size(out_caps);
323 for (i = 0; i < n_structures; i++) {
324 structure = gst_caps_get_structure(out_caps, i);
325 gst_structure_set_value(structure, "width", v_width);
326 gst_structure_set_value(structure, "height", v_height);
328 gst_structure_set_value(structure, "framerate", v_framerate);
330 gst_structure_set_value(structure, "pixel-aspect-ratio", v_par);