2 * gstvaapisink.c - VA-API video sink
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011-2012 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
24 * SECTION:gstvaapisink
25 * @short_description: A VA-API based videosink
27 * vaapisink renders video frames to a drawable (X #Window) on a local
28 * display using the Video Acceleration (VA) API. The element will
29 * create its own internal window and render into it.
34 #include <gst/video/video.h>
35 #include <gst/video/videocontext.h>
36 #include <gst/vaapi/gstvaapivalue.h>
37 #include <gst/vaapi/gstvaapivideobuffer.h>
39 # include <gst/vaapi/gstvaapidisplay_drm.h>
42 # include <gst/vaapi/gstvaapidisplay_x11.h>
43 # include <gst/vaapi/gstvaapiwindow_x11.h>
46 # include <gst/vaapi/gstvaapidisplay_glx.h>
47 # include <gst/vaapi/gstvaapiwindow_glx.h>
50 # include <gst/vaapi/gstvaapidisplay_wayland.h>
51 # include <gst/vaapi/gstvaapiwindow_wayland.h>
54 /* Supported interfaces */
55 #include <gst/interfaces/xoverlay.h>
57 #include "gstvaapisink.h"
58 #include "gstvaapipluginutil.h"
60 #define GST_PLUGIN_NAME "vaapisink"
61 #define GST_PLUGIN_DESC "A VA-API based videosink"
63 GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapisink);
64 #define GST_CAT_DEFAULT gst_debug_vaapisink
66 /* ElementFactory information */
67 static const GstElementDetails gst_vaapisink_details =
72 "Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
74 /* Default template */
75 static GstStaticPadTemplate gst_vaapisink_sink_factory =
76 GST_STATIC_PAD_TEMPLATE(
80 GST_STATIC_CAPS(GST_VAAPI_SURFACE_CAPS));
83 gst_vaapisink_implements_iface_init(GstImplementsInterfaceClass *iface);
86 gst_vaapisink_video_context_iface_init(GstVideoContextInterface *iface);
89 gst_vaapisink_xoverlay_iface_init(GstXOverlayClass *iface);
91 G_DEFINE_TYPE_WITH_CODE(
95 G_IMPLEMENT_INTERFACE(GST_TYPE_IMPLEMENTS_INTERFACE,
96 gst_vaapisink_implements_iface_init);
97 G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT,
98 gst_vaapisink_video_context_iface_init);
99 G_IMPLEMENT_INTERFACE(GST_TYPE_X_OVERLAY,
100 gst_vaapisink_xoverlay_iface_init));
112 #define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_ANY
113 #define DEFAULT_ROTATION GST_VAAPI_ROTATION_0
115 /* GstImplementsInterface interface */
118 gst_vaapisink_implements_interface_supported(
119 GstImplementsInterface *iface,
123 return (type == GST_TYPE_VIDEO_CONTEXT ||
124 type == GST_TYPE_X_OVERLAY);
128 gst_vaapisink_implements_iface_init(GstImplementsInterfaceClass *iface)
130 iface->supported = gst_vaapisink_implements_interface_supported;
133 /* GstVideoContext interface */
136 gst_vaapisink_set_video_context(GstVideoContext *context, const gchar *type,
139 GstVaapiSink *sink = GST_VAAPISINK (context);
140 gst_vaapi_set_display (type, value, &sink->display);
144 gst_vaapisink_video_context_iface_init(GstVideoContextInterface *iface)
146 iface->set_context = gst_vaapisink_set_video_context;
149 /* GstXOverlay interface */
153 gst_vaapisink_ensure_window_xid(GstVaapiSink *sink, guintptr window_id);
157 gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer);
160 gst_vaapisink_xoverlay_set_window_handle(GstXOverlay *overlay, guintptr window)
162 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
164 /* Disable GLX rendering when vaapisink is using a foreign X
165 window. It's pretty much useless */
166 if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_GLX)
167 sink->display_type = GST_VAAPI_DISPLAY_TYPE_X11;
169 sink->foreign_window = TRUE;
171 switch (sink->display_type) {
173 case GST_VAAPI_DISPLAY_TYPE_X11:
174 gst_vaapisink_ensure_window_xid(sink, window);
183 gst_vaapisink_xoverlay_set_render_rectangle(
184 GstXOverlay *overlay,
191 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
192 GstVaapiRectangle * const display_rect = &sink->display_rect;
196 display_rect->width = width;
197 display_rect->height = height;
199 GST_DEBUG("render rect (%d,%d):%ux%u",
200 display_rect->x, display_rect->y,
201 display_rect->width, display_rect->height);
205 gst_vaapisink_xoverlay_expose(GstXOverlay *overlay)
207 GstBaseSink * const base_sink = GST_BASE_SINK(overlay);
210 buffer = gst_base_sink_get_last_buffer(base_sink);
212 gst_vaapisink_show_frame(base_sink, buffer);
213 gst_buffer_unref(buffer);
218 gst_vaapisink_xoverlay_iface_init(GstXOverlayClass *iface)
220 iface->set_window_handle = gst_vaapisink_xoverlay_set_window_handle;
221 iface->set_render_rectangle = gst_vaapisink_xoverlay_set_render_rectangle;
222 iface->expose = gst_vaapisink_xoverlay_expose;
226 gst_vaapisink_destroy(GstVaapiSink *sink)
228 gst_buffer_replace(&sink->video_buffer, NULL);
229 g_clear_object(&sink->texture);
230 g_clear_object(&sink->display);
232 gst_caps_replace(&sink->caps, NULL);
236 /* Checks whether a ConfigureNotify event is in the queue */
237 typedef struct _ConfigureNotifyEventPendingArgs ConfigureNotifyEventPendingArgs;
238 struct _ConfigureNotifyEventPendingArgs {
246 configure_notify_event_pending_cb(Display *dpy, XEvent *xev, XPointer arg)
248 ConfigureNotifyEventPendingArgs * const args =
249 (ConfigureNotifyEventPendingArgs *)arg;
251 if (xev->type == ConfigureNotify &&
252 xev->xconfigure.window == args->window &&
253 xev->xconfigure.width == args->width &&
254 xev->xconfigure.height == args->height)
257 /* XXX: this is a hack to traverse the whole queue because we
258 can't use XPeekIfEvent() since it could block */
263 configure_notify_event_pending(
270 ConfigureNotifyEventPendingArgs args;
273 args.window = window;
275 args.height = height;
278 /* XXX: don't use XPeekIfEvent() because it might block */
280 gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(sink->display)),
282 configure_notify_event_pending_cb, (XPointer)&args
289 get_display_type_name(GstVaapiDisplayType display_type)
291 gpointer const klass = g_type_class_peek(GST_VAAPI_TYPE_DISPLAY_TYPE);
292 GEnumValue * const e = g_enum_get_value(klass, display_type);
295 return e->value_name;
296 return "<unknown-type>";
299 static inline gboolean
300 gst_vaapisink_ensure_display(GstVaapiSink *sink)
302 GstVaapiDisplayType display_type;
303 GstVaapiRenderMode render_mode;
305 if (!gst_vaapi_ensure_display(sink, sink->display_type, &sink->display))
308 display_type = gst_vaapi_display_get_display_type(sink->display);
309 if (display_type != sink->display_type) {
310 GST_INFO("created %s %p", get_display_type_name(display_type),
312 sink->display_type = display_type;
315 gst_vaapi_display_get_render_mode(sink->display, &render_mode) &&
316 render_mode == GST_VAAPI_RENDER_MODE_OVERLAY;
317 GST_DEBUG("use %s rendering mode", sink->use_overlay ? "overlay" : "texture");
319 sink->use_rotation = gst_vaapi_display_has_property(
320 sink->display, GST_VAAPI_DISPLAY_PROP_ROTATION);
326 gst_vaapisink_ensure_render_rect(GstVaapiSink *sink, guint width, guint height)
328 GstVaapiRectangle * const display_rect = &sink->display_rect;
329 guint num, den, display_par_n, display_par_d;
332 /* Return success if caps are not set yet */
336 GST_DEBUG("ensure render rect within %ux%u bounds", width, height);
338 gst_vaapi_display_get_pixel_aspect_ratio(
340 &display_par_n, &display_par_d
342 GST_DEBUG("display pixel-aspect-ratio %d/%d",
343 display_par_n, display_par_d);
345 success = gst_video_calculate_display_ratio(
347 sink->video_width, sink->video_height,
348 sink->video_par_n, sink->video_par_d,
349 display_par_n, display_par_d
353 GST_DEBUG("video size %dx%d, calculated ratio %d/%d",
354 sink->video_width, sink->video_height, num, den);
356 display_rect->width = gst_util_uint64_scale_int(height, num, den);
357 if (display_rect->width <= width) {
358 GST_DEBUG("keeping window height");
359 display_rect->height = height;
362 GST_DEBUG("keeping window width");
363 display_rect->width = width;
364 display_rect->height =
365 gst_util_uint64_scale_int(width, den, num);
367 GST_DEBUG("scaling video to %ux%u", display_rect->width, display_rect->height);
369 g_assert(display_rect->width <= width);
370 g_assert(display_rect->height <= height);
372 display_rect->x = (width - display_rect->width) / 2;
373 display_rect->y = (height - display_rect->height) / 2;
375 GST_DEBUG("render rect (%d,%d):%ux%u",
376 display_rect->x, display_rect->y,
377 display_rect->width, display_rect->height);
382 gst_vaapisink_ensure_window_size(GstVaapiSink *sink, guint *pwidth, guint *pheight)
384 GstVideoRectangle src_rect, dst_rect, out_rect;
385 guint num, den, display_width, display_height, display_par_n, display_par_d;
386 gboolean success, scale;
388 if (sink->foreign_window) {
389 *pwidth = sink->window_width;
390 *pheight = sink->window_height;
394 gst_vaapi_display_get_size(sink->display, &display_width, &display_height);
395 if (sink->fullscreen) {
396 *pwidth = display_width;
397 *pheight = display_height;
401 gst_vaapi_display_get_pixel_aspect_ratio(
403 &display_par_n, &display_par_d
406 success = gst_video_calculate_display_ratio(
408 sink->video_width, sink->video_height,
409 sink->video_par_n, sink->video_par_d,
410 display_par_n, display_par_d
413 num = sink->video_par_n;
414 den = sink->video_par_d;
419 src_rect.w = gst_util_uint64_scale_int(sink->video_height, num, den);
420 src_rect.h = sink->video_height;
423 dst_rect.w = display_width;
424 dst_rect.h = display_height;
425 scale = (src_rect.w > dst_rect.w || src_rect.h > dst_rect.h);
426 gst_video_sink_center_rect(src_rect, dst_rect, &out_rect, scale);
427 *pwidth = out_rect.w;
428 *pheight = out_rect.h;
431 static inline gboolean
432 gst_vaapisink_ensure_window(GstVaapiSink *sink, guint width, guint height)
434 GstVaapiDisplay * const display = sink->display;
437 switch (sink->display_type) {
439 case GST_VAAPI_DISPLAY_TYPE_GLX:
440 sink->window = gst_vaapi_window_glx_new(display, width, height);
441 goto notify_xoverlay_interface;
444 case GST_VAAPI_DISPLAY_TYPE_X11:
445 sink->window = gst_vaapi_window_x11_new(display, width, height);
446 notify_xoverlay_interface:
449 gst_x_overlay_got_window_handle(
451 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window))
456 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
457 sink->window = gst_vaapi_window_wayland_new(display, width, height);
461 GST_ERROR("unsupported display type %d", sink->display_type);
465 return sink->window != NULL;
470 gst_vaapisink_ensure_window_xid(GstVaapiSink *sink, guintptr window_id)
473 unsigned int width, height, border_width, depth;
477 if (!gst_vaapisink_ensure_display(sink))
480 gst_vaapi_display_lock(sink->display);
482 gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(sink->display)),
485 &x, &y, &width, &height, &border_width, &depth
487 gst_vaapi_display_unlock(sink->display);
489 if ((width != sink->window_width || height != sink->window_height) &&
490 !configure_notify_event_pending(sink, xid, width, height)) {
491 if (!gst_vaapisink_ensure_render_rect(sink, width, height))
493 sink->window_width = width;
494 sink->window_height = height;
498 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window)) == xid)
501 g_clear_object(&sink->window);
503 switch (sink->display_type) {
505 case GST_VAAPI_DISPLAY_TYPE_GLX:
506 sink->window = gst_vaapi_window_glx_new_with_xid(sink->display, xid);
509 case GST_VAAPI_DISPLAY_TYPE_X11:
510 sink->window = gst_vaapi_window_x11_new_with_xid(sink->display, xid);
513 GST_ERROR("unsupported display type %d", sink->display_type);
516 return sink->window != NULL;
521 gst_vaapisink_ensure_rotation(GstVaapiSink *sink, gboolean recalc_display_rect)
523 gboolean success = FALSE;
525 g_return_val_if_fail(sink->display, FALSE);
527 if (sink->rotation == sink->rotation_req)
530 if (!sink->use_rotation) {
531 GST_WARNING("VA display does not support rotation");
535 gst_vaapi_display_lock(sink->display);
536 success = gst_vaapi_display_set_rotation(sink->display, sink->rotation_req);
537 gst_vaapi_display_unlock(sink->display);
539 GST_ERROR("failed to change VA display rotation mode");
543 if (((sink->rotation + sink->rotation_req) % 180) == 90) {
544 /* Orientation changed */
545 G_PRIMITIVE_SWAP(guint, sink->video_width, sink->video_height);
546 G_PRIMITIVE_SWAP(gint, sink->video_par_n, sink->video_par_d);
549 if (recalc_display_rect && !sink->foreign_window)
550 gst_vaapisink_ensure_render_rect(sink, sink->window_width,
551 sink->window_height);
555 sink->rotation = sink->rotation_req;
560 gst_vaapisink_start(GstBaseSink *base_sink)
562 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
564 return gst_vaapisink_ensure_display(sink);
568 gst_vaapisink_stop(GstBaseSink *base_sink)
570 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
572 gst_buffer_replace(&sink->video_buffer, NULL);
573 g_clear_object(&sink->window);
574 g_clear_object(&sink->display);
580 gst_vaapisink_set_caps(GstBaseSink *base_sink, GstCaps *caps)
582 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
583 GstStructure * const structure = gst_caps_get_structure(caps, 0);
584 guint win_width, win_height;
585 gint video_width, video_height, video_par_n = 1, video_par_d = 1;
588 if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_DRM)
594 if (!gst_structure_get_int(structure, "width", &video_width))
596 if (!gst_structure_get_int(structure, "height", &video_height))
598 sink->video_width = video_width;
599 sink->video_height = video_height;
601 gst_video_parse_caps_pixel_aspect_ratio(caps, &video_par_n, &video_par_d);
602 sink->video_par_n = video_par_n;
603 sink->video_par_d = video_par_d;
604 GST_DEBUG("video pixel-aspect-ratio %d/%d", video_par_n, video_par_d);
606 gst_caps_replace(&sink->caps, caps);
608 if (!gst_vaapisink_ensure_display(sink))
611 gst_vaapisink_ensure_rotation(sink, FALSE);
613 gst_vaapisink_ensure_window_size(sink, &win_width, &win_height);
615 if (!sink->foreign_window || sink->fullscreen)
616 gst_vaapi_window_set_size(sink->window, win_width, win_height);
619 gst_vaapi_display_lock(sink->display);
620 gst_x_overlay_prepare_xwindow_id(GST_X_OVERLAY(sink));
621 gst_vaapi_display_unlock(sink->display);
624 if (!gst_vaapisink_ensure_window(sink, win_width, win_height))
626 gst_vaapi_window_set_fullscreen(sink->window, sink->fullscreen);
627 gst_vaapi_window_show(sink->window);
628 gst_vaapi_window_get_size(sink->window, &win_width, &win_height);
630 sink->window_width = win_width;
631 sink->window_height = win_height;
632 GST_DEBUG("window size %ux%u", win_width, win_height);
634 return gst_vaapisink_ensure_render_rect(sink, win_width, win_height);
639 render_background(GstVaapiSink *sink)
641 /* Original code from Mirco Muller (MacSlow):
642 <http://cgit.freedesktop.org/~macslow/gl-gst-player/> */
643 GLfloat fStartX = 0.0f;
644 GLfloat fStartY = 0.0f;
645 GLfloat fWidth = (GLfloat)sink->window_width;
646 GLfloat fHeight = (GLfloat)sink->window_height;
648 glClear(GL_COLOR_BUFFER_BIT);
651 /* top third, darker grey to white */
652 glColor3f(0.85f, 0.85f, 0.85f);
653 glVertex3f(fStartX, fStartY, 0.0f);
654 glColor3f(0.85f, 0.85f, 0.85f);
655 glVertex3f(fStartX + fWidth, fStartY, 0.0f);
656 glColor3f(1.0f, 1.0f, 1.0f);
657 glVertex3f(fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
658 glColor3f(1.0f, 1.0f, 1.0f);
659 glVertex3f(fStartX, fStartY + fHeight / 3.0f, 0.0f);
661 /* middle third, just plain white */
662 glColor3f(1.0f, 1.0f, 1.0f);
663 glVertex3f(fStartX, fStartY + fHeight / 3.0f, 0.0f);
664 glVertex3f(fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
665 glVertex3f(fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
666 glVertex3f(fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
668 /* bottom third, white to lighter grey */
669 glColor3f(1.0f, 1.0f, 1.0f);
670 glVertex3f(fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
671 glColor3f(1.0f, 1.0f, 1.0f);
672 glVertex3f(fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
673 glColor3f(0.62f, 0.66f, 0.69f);
674 glVertex3f(fStartX + fWidth, fStartY + fHeight, 0.0f);
675 glColor3f(0.62f, 0.66f, 0.69f);
676 glVertex3f(fStartX, fStartY + fHeight, 0.0f);
682 render_frame(GstVaapiSink *sink)
684 const guint x1 = sink->display_rect.x;
685 const guint x2 = sink->display_rect.x + sink->display_rect.width;
686 const guint y1 = sink->display_rect.y;
687 const guint y2 = sink->display_rect.y + sink->display_rect.height;
689 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
692 glTexCoord2f(0.0f, 0.0f); glVertex2i(x1, y1);
693 glTexCoord2f(0.0f, 1.0f); glVertex2i(x1, y2);
694 glTexCoord2f(1.0f, 1.0f); glVertex2i(x2, y2);
695 glTexCoord2f(1.0f, 0.0f); glVertex2i(x2, y1);
701 render_reflection(GstVaapiSink *sink)
703 const guint x1 = sink->display_rect.x;
704 const guint x2 = sink->display_rect.x + sink->display_rect.width;
705 const guint y1 = sink->display_rect.y;
706 const guint rh = sink->display_rect.height / 5;
707 GLfloat ry = 1.0f - (GLfloat)rh / (GLfloat)sink->display_rect.height;
711 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
712 glTexCoord2f(0.0f, 1.0f); glVertex2i(x1, y1);
713 glTexCoord2f(1.0f, 1.0f); glVertex2i(x2, y1);
715 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
716 glTexCoord2f(1.0f, ry); glVertex2i(x2, y1 + rh);
717 glTexCoord2f(0.0f, ry); glVertex2i(x1, y1 + rh);
723 gst_vaapisink_show_frame_glx(
725 GstVaapiSurface *surface,
729 GstVaapiWindowGLX * const window = GST_VAAPI_WINDOW_GLX(sink->window);
733 gst_vaapi_window_glx_make_current(window);
734 if (!sink->texture) {
735 sink->texture = gst_vaapi_texture_new(
743 goto error_create_texture;
745 if (!gst_vaapi_texture_put_surface(sink->texture, surface, flags))
746 goto error_transfer_surface;
748 target = gst_vaapi_texture_get_target(sink->texture);
749 texture = gst_vaapi_texture_get_id(sink->texture);
750 if (target != GL_TEXTURE_2D || !texture)
753 if (sink->use_reflection)
754 render_background(sink);
757 glBindTexture(target, texture);
759 if (sink->use_reflection) {
761 glRotatef(20.0f, 0.0f, 1.0f, 0.0f);
762 glTranslatef(50.0f, 0.0f, 0.0f);
765 if (sink->use_reflection) {
767 glTranslatef(0.0, (GLfloat)sink->display_rect.height + 5.0f, 0.0f);
768 render_reflection(sink);
773 glBindTexture(target, 0);
775 gst_vaapi_window_glx_swap_buffers(window);
779 error_create_texture:
781 GST_DEBUG("could not create VA/GLX texture");
784 error_transfer_surface:
786 GST_DEBUG("could not transfer VA surface to texture");
792 static inline gboolean
793 gst_vaapisink_put_surface(
795 GstVaapiSurface *surface,
799 if (!gst_vaapi_window_put_surface(sink->window, surface,
800 NULL, &sink->display_rect, flags)) {
801 GST_DEBUG("could not render VA surface");
808 gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer)
810 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
811 GstVaapiVideoBuffer * const vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
812 GstVaapiSurface *surface;
815 GstVideoOverlayComposition * const composition =
816 gst_video_buffer_get_overlay_composition(buffer);
818 if (sink->display != gst_vaapi_video_buffer_get_display (vbuffer)) {
819 g_clear_object(&sink->display);
820 sink->display = g_object_ref (gst_vaapi_video_buffer_get_display (vbuffer));
824 return GST_FLOW_UNEXPECTED;
826 gst_vaapisink_ensure_rotation(sink, TRUE);
828 surface = gst_vaapi_video_buffer_get_surface(vbuffer);
830 return GST_FLOW_UNEXPECTED;
832 GST_DEBUG("render surface %" GST_VAAPI_ID_FORMAT,
833 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
835 flags = gst_vaapi_video_buffer_get_render_flags(vbuffer);
837 if (!gst_vaapi_surface_set_subpictures_from_composition(surface,
839 GST_WARNING("could not update subtitles");
841 switch (sink->display_type) {
843 case GST_VAAPI_DISPLAY_TYPE_GLX:
844 success = gst_vaapisink_show_frame_glx(sink, surface, flags);
848 case GST_VAAPI_DISPLAY_TYPE_DRM:
853 case GST_VAAPI_DISPLAY_TYPE_X11:
854 success = gst_vaapisink_put_surface(sink, surface, flags);
858 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
859 success = gst_vaapisink_put_surface(sink, surface, flags);
863 GST_ERROR("unsupported display type %d", sink->display_type);
868 return GST_FLOW_UNEXPECTED;
870 /* Retain VA surface until the next one is displayed */
871 if (sink->use_overlay)
872 gst_buffer_replace(&sink->video_buffer, buffer);
877 gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query)
879 GstVaapiSink *sink = GST_VAAPISINK(base_sink);
880 GST_DEBUG ("sharing display %p", sink->display);
881 return gst_vaapi_reply_to_query (query, sink->display);
885 gst_vaapisink_finalize(GObject *object)
887 gst_vaapisink_destroy(GST_VAAPISINK(object));
889 G_OBJECT_CLASS(gst_vaapisink_parent_class)->finalize(object);
893 gst_vaapisink_set_property(
900 GstVaapiSink * const sink = GST_VAAPISINK(object);
903 case PROP_DISPLAY_TYPE:
904 sink->display_type = g_value_get_enum(value);
906 case PROP_FULLSCREEN:
907 sink->fullscreen = g_value_get_boolean(value);
909 case PROP_SYNCHRONOUS:
910 sink->synchronous = g_value_get_boolean(value);
912 case PROP_USE_REFLECTION:
913 sink->use_reflection = g_value_get_boolean(value);
916 sink->rotation_req = g_value_get_enum(value);
919 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
925 gst_vaapisink_get_property(
932 GstVaapiSink * const sink = GST_VAAPISINK(object);
935 case PROP_DISPLAY_TYPE:
936 g_value_set_enum(value, sink->display_type);
938 case PROP_FULLSCREEN:
939 g_value_set_boolean(value, sink->fullscreen);
941 case PROP_SYNCHRONOUS:
942 g_value_set_boolean(value, sink->synchronous);
944 case PROP_USE_REFLECTION:
945 g_value_set_boolean(value, sink->use_reflection);
948 g_value_set_enum(value, sink->rotation);
951 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
957 gst_vaapisink_class_init(GstVaapiSinkClass *klass)
959 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
960 GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
961 GstBaseSinkClass * const basesink_class = GST_BASE_SINK_CLASS(klass);
962 GstPadTemplate *pad_template;
964 GST_DEBUG_CATEGORY_INIT(gst_debug_vaapisink,
965 GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
967 object_class->finalize = gst_vaapisink_finalize;
968 object_class->set_property = gst_vaapisink_set_property;
969 object_class->get_property = gst_vaapisink_get_property;
971 basesink_class->start = gst_vaapisink_start;
972 basesink_class->stop = gst_vaapisink_stop;
973 basesink_class->set_caps = gst_vaapisink_set_caps;
974 basesink_class->preroll = gst_vaapisink_show_frame;
975 basesink_class->render = gst_vaapisink_show_frame;
976 basesink_class->query = gst_vaapisink_query;
978 gst_element_class_set_details_simple(
980 gst_vaapisink_details.longname,
981 gst_vaapisink_details.klass,
982 gst_vaapisink_details.description,
983 gst_vaapisink_details.author
986 pad_template = gst_static_pad_template_get(&gst_vaapisink_sink_factory);
987 gst_element_class_add_pad_template(element_class, pad_template);
988 gst_object_unref(pad_template);
990 g_object_class_install_property
993 g_param_spec_enum("display",
995 "display type to use",
996 GST_VAAPI_TYPE_DISPLAY_TYPE,
997 GST_VAAPI_DISPLAY_TYPE_ANY,
998 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1001 g_object_class_install_property
1003 PROP_USE_REFLECTION,
1004 g_param_spec_boolean("use-reflection",
1005 "Reflection effect",
1006 "Enables OpenGL reflection effect",
1008 G_PARAM_READWRITE));
1011 g_object_class_install_property
1014 g_param_spec_boolean("fullscreen",
1016 "Requests window in fullscreen state",
1018 G_PARAM_READWRITE));
1021 * GstVaapiSink:synchronous:
1023 * When enabled, runs the X display in synchronous mode. Note that
1024 * this is used only for debugging.
1026 g_object_class_install_property
1029 g_param_spec_boolean("synchronous",
1031 "Toggles X display synchronous mode",
1033 G_PARAM_READWRITE));
1036 * GstVaapiSink:rotation:
1038 * The VA display rotation mode, expressed as a #GstVaapiRotation.
1040 g_object_class_install_property
1043 g_param_spec_enum(GST_VAAPI_DISPLAY_PROP_ROTATION,
1045 "The display rotation mode",
1046 GST_VAAPI_TYPE_ROTATION,
1048 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1052 gst_vaapisink_init(GstVaapiSink *sink)
1055 sink->display = NULL;
1056 sink->window = NULL;
1057 sink->window_width = 0;
1058 sink->window_height = 0;
1059 sink->texture = NULL;
1060 sink->video_buffer = NULL;
1061 sink->video_width = 0;
1062 sink->video_height = 0;
1063 sink->video_par_n = 1;
1064 sink->video_par_d = 1;
1065 sink->foreign_window = FALSE;
1066 sink->fullscreen = FALSE;
1067 sink->synchronous = FALSE;
1068 sink->display_type = DEFAULT_DISPLAY_TYPE;
1069 sink->rotation = DEFAULT_ROTATION;
1070 sink->rotation_req = DEFAULT_ROTATION;
1071 sink->use_reflection = FALSE;
1072 sink->use_overlay = FALSE;
1073 sink->use_rotation = FALSE;