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/gstvaapivideobuffer.h>
38 # include <gst/vaapi/gstvaapidisplay_drm.h>
41 # include <gst/vaapi/gstvaapidisplay_x11.h>
42 # include <gst/vaapi/gstvaapiwindow_x11.h>
45 # include <gst/vaapi/gstvaapidisplay_glx.h>
46 # include <gst/vaapi/gstvaapiwindow_glx.h>
49 # include <gst/vaapi/gstvaapidisplay_wayland.h>
50 # include <gst/vaapi/gstvaapiwindow_wayland.h>
53 /* Supported interfaces */
54 #include <gst/interfaces/xoverlay.h>
56 #include "gstvaapisink.h"
57 #include "gstvaapipluginutil.h"
59 #define GST_PLUGIN_NAME "vaapisink"
60 #define GST_PLUGIN_DESC "A VA-API based videosink"
62 GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapisink);
63 #define GST_CAT_DEFAULT gst_debug_vaapisink
65 /* ElementFactory information */
66 static const GstElementDetails gst_vaapisink_details =
71 "Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
73 /* Default template */
74 static GstStaticPadTemplate gst_vaapisink_sink_factory =
75 GST_STATIC_PAD_TEMPLATE(
79 GST_STATIC_CAPS(GST_VAAPI_SURFACE_CAPS));
82 gst_vaapisink_implements_iface_init(GstImplementsInterfaceClass *iface);
85 gst_vaapisink_video_context_iface_init(GstVideoContextInterface *iface);
88 gst_vaapisink_xoverlay_iface_init(GstXOverlayClass *iface);
90 G_DEFINE_TYPE_WITH_CODE(
94 G_IMPLEMENT_INTERFACE(GST_TYPE_IMPLEMENTS_INTERFACE,
95 gst_vaapisink_implements_iface_init);
96 G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT,
97 gst_vaapisink_video_context_iface_init);
98 G_IMPLEMENT_INTERFACE(GST_TYPE_X_OVERLAY,
99 gst_vaapisink_xoverlay_iface_init));
110 #define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_ANY
112 /* GstImplementsInterface interface */
115 gst_vaapisink_implements_interface_supported(
116 GstImplementsInterface *iface,
120 return (type == GST_TYPE_VIDEO_CONTEXT ||
121 type == GST_TYPE_X_OVERLAY);
125 gst_vaapisink_implements_iface_init(GstImplementsInterfaceClass *iface)
127 iface->supported = gst_vaapisink_implements_interface_supported;
130 /* GstVideoContext interface */
133 gst_vaapisink_set_video_context(GstVideoContext *context, const gchar *type,
136 GstVaapiSink *sink = GST_VAAPISINK (context);
137 gst_vaapi_set_display (type, value, &sink->display);
141 gst_vaapisink_video_context_iface_init(GstVideoContextInterface *iface)
143 iface->set_context = gst_vaapisink_set_video_context;
146 /* GstXOverlay interface */
150 gst_vaapisink_ensure_window_xid(GstVaapiSink *sink, guintptr window_id);
154 gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer);
157 gst_vaapisink_xoverlay_set_window_handle(GstXOverlay *overlay, guintptr window)
159 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
161 /* Disable GLX rendering when vaapisink is using a foreign X
162 window. It's pretty much useless */
163 if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_GLX)
164 sink->display_type = GST_VAAPI_DISPLAY_TYPE_X11;
166 sink->foreign_window = TRUE;
168 switch (sink->display_type) {
170 case GST_VAAPI_DISPLAY_TYPE_X11:
171 gst_vaapisink_ensure_window_xid(sink, window);
180 gst_vaapisink_xoverlay_set_render_rectangle(
181 GstXOverlay *overlay,
188 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
189 GstVaapiRectangle * const display_rect = &sink->display_rect;
193 display_rect->width = width;
194 display_rect->height = height;
196 GST_DEBUG("render rect (%d,%d):%ux%u",
197 display_rect->x, display_rect->y,
198 display_rect->width, display_rect->height);
202 gst_vaapisink_xoverlay_expose(GstXOverlay *overlay)
204 GstBaseSink * const base_sink = GST_BASE_SINK(overlay);
207 buffer = gst_base_sink_get_last_buffer(base_sink);
209 gst_vaapisink_show_frame(base_sink, buffer);
210 gst_buffer_unref(buffer);
215 gst_vaapisink_xoverlay_iface_init(GstXOverlayClass *iface)
217 iface->set_window_handle = gst_vaapisink_xoverlay_set_window_handle;
218 iface->set_render_rectangle = gst_vaapisink_xoverlay_set_render_rectangle;
219 iface->expose = gst_vaapisink_xoverlay_expose;
223 gst_vaapisink_destroy(GstVaapiSink *sink)
225 gst_buffer_replace(&sink->video_buffer, NULL);
226 g_clear_object(&sink->texture);
227 g_clear_object(&sink->display);
229 gst_caps_replace(&sink->caps, NULL);
233 /* Checks whether a ConfigureNotify event is in the queue */
234 typedef struct _ConfigureNotifyEventPendingArgs ConfigureNotifyEventPendingArgs;
235 struct _ConfigureNotifyEventPendingArgs {
243 configure_notify_event_pending_cb(Display *dpy, XEvent *xev, XPointer arg)
245 ConfigureNotifyEventPendingArgs * const args =
246 (ConfigureNotifyEventPendingArgs *)arg;
248 if (xev->type == ConfigureNotify &&
249 xev->xconfigure.window == args->window &&
250 xev->xconfigure.width == args->width &&
251 xev->xconfigure.height == args->height)
254 /* XXX: this is a hack to traverse the whole queue because we
255 can't use XPeekIfEvent() since it could block */
260 configure_notify_event_pending(
267 ConfigureNotifyEventPendingArgs args;
270 args.window = window;
272 args.height = height;
275 /* XXX: don't use XPeekIfEvent() because it might block */
277 gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(sink->display)),
279 configure_notify_event_pending_cb, (XPointer)&args
286 get_display_type_name(GstVaapiDisplayType display_type)
288 gpointer const klass = g_type_class_peek(GST_VAAPI_TYPE_DISPLAY_TYPE);
289 GEnumValue * const e = g_enum_get_value(klass, display_type);
292 return e->value_name;
293 return "<unknown-type>";
296 static inline gboolean
297 gst_vaapisink_ensure_display(GstVaapiSink *sink)
299 GstVaapiDisplayType display_type;
300 GstVaapiRenderMode render_mode;
302 if (!gst_vaapi_ensure_display(sink, sink->display_type, &sink->display))
305 display_type = gst_vaapi_display_get_display_type(sink->display);
306 if (display_type != sink->display_type) {
307 GST_INFO("created %s %p", get_display_type_name(display_type),
309 sink->display_type = display_type;
312 gst_vaapi_display_get_render_mode(sink->display, &render_mode) &&
313 render_mode == GST_VAAPI_RENDER_MODE_OVERLAY;
314 GST_DEBUG("use %s rendering mode", sink->use_overlay ? "overlay" : "texture");
320 gst_vaapisink_ensure_render_rect(GstVaapiSink *sink, guint width, guint height)
322 GstVaapiRectangle * const display_rect = &sink->display_rect;
323 guint num, den, display_par_n, display_par_d;
326 /* Return success if caps are not set yet */
330 GST_DEBUG("ensure render rect within %ux%u bounds", width, height);
332 gst_vaapi_display_get_pixel_aspect_ratio(
334 &display_par_n, &display_par_d
336 GST_DEBUG("display pixel-aspect-ratio %d/%d",
337 display_par_n, display_par_d);
339 success = gst_video_calculate_display_ratio(
341 sink->video_width, sink->video_height,
342 sink->video_par_n, sink->video_par_d,
343 display_par_n, display_par_d
347 GST_DEBUG("video size %dx%d, calculated ratio %d/%d",
348 sink->video_width, sink->video_height, num, den);
350 display_rect->width = gst_util_uint64_scale_int(height, num, den);
351 if (display_rect->width <= width) {
352 GST_DEBUG("keeping window height");
353 display_rect->height = height;
356 GST_DEBUG("keeping window width");
357 display_rect->width = width;
358 display_rect->height =
359 gst_util_uint64_scale_int(width, den, num);
361 GST_DEBUG("scaling video to %ux%u", display_rect->width, display_rect->height);
363 g_assert(display_rect->width <= width);
364 g_assert(display_rect->height <= height);
366 display_rect->x = (width - display_rect->width) / 2;
367 display_rect->y = (height - display_rect->height) / 2;
369 GST_DEBUG("render rect (%d,%d):%ux%u",
370 display_rect->x, display_rect->y,
371 display_rect->width, display_rect->height);
375 static inline gboolean
376 gst_vaapisink_ensure_window(GstVaapiSink *sink, guint width, guint height)
378 GstVaapiDisplay * const display = sink->display;
381 switch (sink->display_type) {
383 case GST_VAAPI_DISPLAY_TYPE_GLX:
384 sink->window = gst_vaapi_window_glx_new(display, width, height);
385 goto notify_xoverlay_interface;
388 case GST_VAAPI_DISPLAY_TYPE_X11:
389 sink->window = gst_vaapi_window_x11_new(display, width, height);
390 notify_xoverlay_interface:
393 gst_x_overlay_got_window_handle(
395 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window))
400 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
401 sink->window = gst_vaapi_window_wayland_new(display, width, height);
405 GST_ERROR("unsupported display type %d", sink->display_type);
409 return sink->window != NULL;
414 gst_vaapisink_ensure_window_xid(GstVaapiSink *sink, guintptr window_id)
417 unsigned int width, height, border_width, depth;
421 if (!gst_vaapisink_ensure_display(sink))
424 gst_vaapi_display_lock(sink->display);
426 gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(sink->display)),
429 &x, &y, &width, &height, &border_width, &depth
431 gst_vaapi_display_unlock(sink->display);
433 if ((width != sink->window_width || height != sink->window_height) &&
434 !configure_notify_event_pending(sink, xid, width, height)) {
435 if (!gst_vaapisink_ensure_render_rect(sink, width, height))
437 sink->window_width = width;
438 sink->window_height = height;
442 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window)) == xid)
445 g_clear_object(&sink->window);
447 switch (sink->display_type) {
449 case GST_VAAPI_DISPLAY_TYPE_GLX:
450 sink->window = gst_vaapi_window_glx_new_with_xid(sink->display, xid);
453 case GST_VAAPI_DISPLAY_TYPE_X11:
454 sink->window = gst_vaapi_window_x11_new_with_xid(sink->display, xid);
457 GST_ERROR("unsupported display type %d", sink->display_type);
460 return sink->window != NULL;
465 gst_vaapisink_start(GstBaseSink *base_sink)
467 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
469 return gst_vaapisink_ensure_display(sink);
473 gst_vaapisink_stop(GstBaseSink *base_sink)
475 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
477 gst_buffer_replace(&sink->video_buffer, NULL);
478 g_clear_object(&sink->window);
479 g_clear_object(&sink->display);
485 gst_vaapisink_set_caps(GstBaseSink *base_sink, GstCaps *caps)
487 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
488 GstStructure * const structure = gst_caps_get_structure(caps, 0);
489 guint win_width, win_height, display_width, display_height;
490 gint video_width, video_height, video_par_n = 1, video_par_d = 1;
493 if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_DRM)
499 if (!gst_structure_get_int(structure, "width", &video_width))
501 if (!gst_structure_get_int(structure, "height", &video_height))
503 sink->video_width = video_width;
504 sink->video_height = video_height;
506 gst_video_parse_caps_pixel_aspect_ratio(caps, &video_par_n, &video_par_d);
507 sink->video_par_n = video_par_n;
508 sink->video_par_d = video_par_d;
509 GST_DEBUG("video pixel-aspect-ratio %d/%d", video_par_n, video_par_d);
511 gst_caps_replace(&sink->caps, caps);
513 if (!gst_vaapisink_ensure_display(sink))
516 gst_vaapi_display_get_size(sink->display, &display_width, &display_height);
517 if (sink->foreign_window) {
518 win_width = sink->window_width;
519 win_height = sink->window_height;
521 else if (sink->fullscreen ||
522 video_width > display_width || video_height > display_height) {
523 win_width = display_width;
524 win_height = display_height;
527 win_width = video_width;
528 win_height = video_height;
532 if (!sink->foreign_window || sink->fullscreen)
533 gst_vaapi_window_set_size(sink->window, win_width, win_height);
536 gst_vaapi_display_lock(sink->display);
537 gst_x_overlay_prepare_xwindow_id(GST_X_OVERLAY(sink));
538 gst_vaapi_display_unlock(sink->display);
541 if (!gst_vaapisink_ensure_window(sink, win_width, win_height))
543 gst_vaapi_window_set_fullscreen(sink->window, sink->fullscreen);
544 gst_vaapi_window_show(sink->window);
545 gst_vaapi_window_get_size(sink->window, &win_width, &win_height);
547 sink->window_width = win_width;
548 sink->window_height = win_height;
549 GST_DEBUG("window size %ux%u", win_width, win_height);
551 return gst_vaapisink_ensure_render_rect(sink, win_width, win_height);
556 render_background(GstVaapiSink *sink)
558 /* Original code from Mirco Muller (MacSlow):
559 <http://cgit.freedesktop.org/~macslow/gl-gst-player/> */
560 GLfloat fStartX = 0.0f;
561 GLfloat fStartY = 0.0f;
562 GLfloat fWidth = (GLfloat)sink->window_width;
563 GLfloat fHeight = (GLfloat)sink->window_height;
565 glClear(GL_COLOR_BUFFER_BIT);
568 /* top third, darker grey to white */
569 glColor3f(0.85f, 0.85f, 0.85f);
570 glVertex3f(fStartX, fStartY, 0.0f);
571 glColor3f(0.85f, 0.85f, 0.85f);
572 glVertex3f(fStartX + fWidth, fStartY, 0.0f);
573 glColor3f(1.0f, 1.0f, 1.0f);
574 glVertex3f(fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
575 glColor3f(1.0f, 1.0f, 1.0f);
576 glVertex3f(fStartX, fStartY + fHeight / 3.0f, 0.0f);
578 /* middle third, just plain white */
579 glColor3f(1.0f, 1.0f, 1.0f);
580 glVertex3f(fStartX, fStartY + fHeight / 3.0f, 0.0f);
581 glVertex3f(fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
582 glVertex3f(fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
583 glVertex3f(fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
585 /* bottom third, white to lighter grey */
586 glColor3f(1.0f, 1.0f, 1.0f);
587 glVertex3f(fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
588 glColor3f(1.0f, 1.0f, 1.0f);
589 glVertex3f(fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
590 glColor3f(0.62f, 0.66f, 0.69f);
591 glVertex3f(fStartX + fWidth, fStartY + fHeight, 0.0f);
592 glColor3f(0.62f, 0.66f, 0.69f);
593 glVertex3f(fStartX, fStartY + fHeight, 0.0f);
599 render_frame(GstVaapiSink *sink)
601 const guint x1 = sink->display_rect.x;
602 const guint x2 = sink->display_rect.x + sink->display_rect.width;
603 const guint y1 = sink->display_rect.y;
604 const guint y2 = sink->display_rect.y + sink->display_rect.height;
606 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
609 glTexCoord2f(0.0f, 0.0f); glVertex2i(x1, y1);
610 glTexCoord2f(0.0f, 1.0f); glVertex2i(x1, y2);
611 glTexCoord2f(1.0f, 1.0f); glVertex2i(x2, y2);
612 glTexCoord2f(1.0f, 0.0f); glVertex2i(x2, y1);
618 render_reflection(GstVaapiSink *sink)
620 const guint x1 = sink->display_rect.x;
621 const guint x2 = sink->display_rect.x + sink->display_rect.width;
622 const guint y1 = sink->display_rect.y;
623 const guint rh = sink->display_rect.height / 5;
624 GLfloat ry = 1.0f - (GLfloat)rh / (GLfloat)sink->display_rect.height;
628 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
629 glTexCoord2f(0.0f, 1.0f); glVertex2i(x1, y1);
630 glTexCoord2f(1.0f, 1.0f); glVertex2i(x2, y1);
632 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
633 glTexCoord2f(1.0f, ry); glVertex2i(x2, y1 + rh);
634 glTexCoord2f(0.0f, ry); glVertex2i(x1, y1 + rh);
640 gst_vaapisink_show_frame_glx(
642 GstVaapiSurface *surface,
646 GstVaapiWindowGLX * const window = GST_VAAPI_WINDOW_GLX(sink->window);
650 gst_vaapi_window_glx_make_current(window);
651 if (!sink->texture) {
652 sink->texture = gst_vaapi_texture_new(
660 goto error_create_texture;
662 if (!gst_vaapi_texture_put_surface(sink->texture, surface, flags))
663 goto error_transfer_surface;
665 target = gst_vaapi_texture_get_target(sink->texture);
666 texture = gst_vaapi_texture_get_id(sink->texture);
667 if (target != GL_TEXTURE_2D || !texture)
670 if (sink->use_reflection)
671 render_background(sink);
674 glBindTexture(target, texture);
676 if (sink->use_reflection) {
678 glRotatef(20.0f, 0.0f, 1.0f, 0.0f);
679 glTranslatef(50.0f, 0.0f, 0.0f);
682 if (sink->use_reflection) {
684 glTranslatef(0.0, (GLfloat)sink->display_rect.height + 5.0f, 0.0f);
685 render_reflection(sink);
690 glBindTexture(target, 0);
692 gst_vaapi_window_glx_swap_buffers(window);
696 error_create_texture:
698 GST_DEBUG("could not create VA/GLX texture");
701 error_transfer_surface:
703 GST_DEBUG("could not transfer VA surface to texture");
709 static inline gboolean
710 gst_vaapisink_put_surface(
712 GstVaapiSurface *surface,
716 if (!gst_vaapi_window_put_surface(sink->window, surface,
717 NULL, &sink->display_rect, flags)) {
718 GST_DEBUG("could not render VA surface");
725 gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer)
727 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
728 GstVaapiVideoBuffer * const vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
729 GstVaapiSurface *surface;
732 GstVideoOverlayComposition * const composition =
733 gst_video_buffer_get_overlay_composition(buffer);
735 if (sink->display != gst_vaapi_video_buffer_get_display (vbuffer)) {
736 g_clear_object(&sink->display);
737 sink->display = g_object_ref (gst_vaapi_video_buffer_get_display (vbuffer));
741 return GST_FLOW_UNEXPECTED;
743 surface = gst_vaapi_video_buffer_get_surface(vbuffer);
745 return GST_FLOW_UNEXPECTED;
747 GST_DEBUG("render surface %" GST_VAAPI_ID_FORMAT,
748 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
750 flags = gst_vaapi_video_buffer_get_render_flags(vbuffer);
752 if (!gst_vaapi_surface_set_subpictures_from_composition(surface,
754 GST_WARNING("could not update subtitles");
756 switch (sink->display_type) {
758 case GST_VAAPI_DISPLAY_TYPE_GLX:
759 success = gst_vaapisink_show_frame_glx(sink, surface, flags);
763 case GST_VAAPI_DISPLAY_TYPE_DRM:
768 case GST_VAAPI_DISPLAY_TYPE_X11:
769 success = gst_vaapisink_put_surface(sink, surface, flags);
773 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
774 success = gst_vaapisink_put_surface(sink, surface, flags);
778 GST_ERROR("unsupported display type %d", sink->display_type);
783 return GST_FLOW_UNEXPECTED;
785 /* Retain VA surface until the next one is displayed */
786 if (sink->use_overlay)
787 gst_buffer_replace(&sink->video_buffer, buffer);
792 gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query)
794 GstVaapiSink *sink = GST_VAAPISINK(base_sink);
795 GST_DEBUG ("sharing display %p", sink->display);
796 return gst_vaapi_reply_to_query (query, sink->display);
800 gst_vaapisink_finalize(GObject *object)
802 gst_vaapisink_destroy(GST_VAAPISINK(object));
804 G_OBJECT_CLASS(gst_vaapisink_parent_class)->finalize(object);
808 gst_vaapisink_set_property(
815 GstVaapiSink * const sink = GST_VAAPISINK(object);
818 case PROP_DISPLAY_TYPE:
819 sink->display_type = g_value_get_enum(value);
821 case PROP_FULLSCREEN:
822 sink->fullscreen = g_value_get_boolean(value);
824 case PROP_SYNCHRONOUS:
825 sink->synchronous = g_value_get_boolean(value);
827 case PROP_USE_REFLECTION:
828 sink->use_reflection = g_value_get_boolean(value);
831 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
837 gst_vaapisink_get_property(
844 GstVaapiSink * const sink = GST_VAAPISINK(object);
847 case PROP_DISPLAY_TYPE:
848 g_value_set_enum(value, sink->display_type);
850 case PROP_FULLSCREEN:
851 g_value_set_boolean(value, sink->fullscreen);
853 case PROP_SYNCHRONOUS:
854 g_value_set_boolean(value, sink->synchronous);
856 case PROP_USE_REFLECTION:
857 g_value_set_boolean(value, sink->use_reflection);
860 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
866 gst_vaapisink_class_init(GstVaapiSinkClass *klass)
868 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
869 GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
870 GstBaseSinkClass * const basesink_class = GST_BASE_SINK_CLASS(klass);
871 GstPadTemplate *pad_template;
873 GST_DEBUG_CATEGORY_INIT(gst_debug_vaapisink,
874 GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
876 object_class->finalize = gst_vaapisink_finalize;
877 object_class->set_property = gst_vaapisink_set_property;
878 object_class->get_property = gst_vaapisink_get_property;
880 basesink_class->start = gst_vaapisink_start;
881 basesink_class->stop = gst_vaapisink_stop;
882 basesink_class->set_caps = gst_vaapisink_set_caps;
883 basesink_class->preroll = gst_vaapisink_show_frame;
884 basesink_class->render = gst_vaapisink_show_frame;
885 basesink_class->query = gst_vaapisink_query;
887 gst_element_class_set_details_simple(
889 gst_vaapisink_details.longname,
890 gst_vaapisink_details.klass,
891 gst_vaapisink_details.description,
892 gst_vaapisink_details.author
895 pad_template = gst_static_pad_template_get(&gst_vaapisink_sink_factory);
896 gst_element_class_add_pad_template(element_class, pad_template);
897 gst_object_unref(pad_template);
899 g_object_class_install_property
902 g_param_spec_enum("display",
904 "display type to use",
905 GST_VAAPI_TYPE_DISPLAY_TYPE,
906 GST_VAAPI_DISPLAY_TYPE_ANY,
907 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
910 g_object_class_install_property
913 g_param_spec_boolean("use-reflection",
915 "Enables OpenGL reflection effect",
920 g_object_class_install_property
923 g_param_spec_boolean("fullscreen",
925 "Requests window in fullscreen state",
930 * GstVaapiSink:synchronous:
932 * When enabled, runs the X display in synchronous mode. Note that
933 * this is used only for debugging.
935 g_object_class_install_property
938 g_param_spec_boolean("synchronous",
940 "Toggles X display synchronous mode",
946 gst_vaapisink_init(GstVaapiSink *sink)
949 sink->display = NULL;
951 sink->window_width = 0;
952 sink->window_height = 0;
953 sink->texture = NULL;
954 sink->video_buffer = NULL;
955 sink->video_width = 0;
956 sink->video_height = 0;
957 sink->video_par_n = 1;
958 sink->video_par_d = 1;
959 sink->foreign_window = FALSE;
960 sink->fullscreen = FALSE;
961 sink->synchronous = FALSE;
962 sink->display_type = DEFAULT_DISPLAY_TYPE;
963 sink->use_reflection = FALSE;
964 sink->use_overlay = FALSE;