2 * gstvaapisink.c - VA-API video sink
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2011-2014 Intel Corporation
7 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA
26 * SECTION:gstvaapisink
27 * @short_description: A VA-API based videosink
29 * vaapisink renders video frames to a drawable (X #Window) on a local
30 * display using the Video Acceleration (VA) API. The element will
31 * create its own internal window and render into it.
34 #include "gst/vaapi/sysdeps.h"
36 #include <gst/video/video.h>
38 #include <gst/vaapi/gstvaapivalue.h>
40 # include <gst/vaapi/gstvaapidisplay_drm.h>
43 # include <gst/vaapi/gstvaapidisplay_x11.h>
44 # include <gst/vaapi/gstvaapiwindow_x11.h>
47 # include <gst/vaapi/gstvaapidisplay_glx.h>
48 # include <gst/vaapi/gstvaapiwindow_glx.h>
51 # include <gst/vaapi/gstvaapidisplay_wayland.h>
52 # include <gst/vaapi/gstvaapiwindow_wayland.h>
55 /* Supported interfaces */
56 #if GST_CHECK_VERSION(1,0,0)
57 # include <gst/video/videooverlay.h>
59 # include <gst/interfaces/xoverlay.h>
61 # define GST_TYPE_VIDEO_OVERLAY GST_TYPE_X_OVERLAY
62 # define GST_VIDEO_OVERLAY GST_X_OVERLAY
63 # define GstVideoOverlay GstXOverlay
64 # define GstVideoOverlayInterface GstXOverlayClass
66 # define gst_video_overlay_prepare_window_handle(sink) \
67 gst_x_overlay_prepare_xwindow_id(sink)
68 # define gst_video_overlay_got_window_handle(sink, window_handle) \
69 gst_x_overlay_got_window_handle(sink, window_handle)
72 #include "gstvaapisink.h"
73 #include "gstvaapipluginutil.h"
74 #include "gstvaapivideometa.h"
75 #if GST_CHECK_VERSION(1,0,0)
76 #include "gstvaapivideobufferpool.h"
77 #include "gstvaapivideomemory.h"
80 #define GST_PLUGIN_NAME "vaapisink"
81 #define GST_PLUGIN_DESC "A VA-API based videosink"
83 GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapisink);
84 #define GST_CAT_DEFAULT gst_debug_vaapisink
86 /* Default template */
87 static const char gst_vaapisink_sink_caps_str[] =
88 #if GST_CHECK_VERSION(1,1,0)
89 GST_VIDEO_CAPS_MAKE_WITH_FEATURES(
90 GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE, "{ ENCODED, NV12, I420, YV12 }") ";"
91 GST_VIDEO_CAPS_MAKE(GST_VIDEO_FORMATS_ALL);
93 #if GST_CHECK_VERSION(1,0,0)
94 GST_VIDEO_CAPS_MAKE(GST_VIDEO_FORMATS_ALL) "; "
97 "width = (int) [ 1, MAX ], "
98 "height = (int) [ 1, MAX ]; "
100 GST_VAAPI_SURFACE_CAPS;
103 static GstStaticPadTemplate gst_vaapisink_sink_factory =
104 GST_STATIC_PAD_TEMPLATE(
108 GST_STATIC_CAPS(gst_vaapisink_sink_caps_str));
111 gst_vaapisink_has_interface(GstVaapiPluginBase *plugin, GType type)
113 return type == GST_TYPE_VIDEO_OVERLAY;
117 gst_vaapisink_video_overlay_iface_init(GstVideoOverlayInterface *iface);
119 G_DEFINE_TYPE_WITH_CODE(
123 GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES
124 G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_OVERLAY,
125 gst_vaapisink_video_overlay_iface_init))
137 PROP_FORCE_ASPECT_RATIO,
141 #define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_ANY
142 #define DEFAULT_ROTATION GST_VAAPI_ROTATION_0
144 static inline gboolean
145 gst_vaapisink_ensure_display(GstVaapiSink *sink);
147 /* GstVideoOverlay interface */
150 gst_vaapisink_video_overlay_expose(GstVideoOverlay *overlay);
154 gst_vaapisink_ensure_window_xid(GstVaapiSink *sink, guintptr window_id);
158 gst_vaapisink_set_event_handling(GstVideoOverlay *overlay, gboolean handle_events);
161 gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer);
164 gst_vaapisink_ensure_render_rect(GstVaapiSink *sink, guint width, guint height);
167 gst_vaapisink_video_overlay_set_window_handle(GstVideoOverlay *overlay,
170 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
171 GstVaapiDisplayType display_type;
173 if (!gst_vaapisink_ensure_display(sink))
175 display_type = GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink);
177 /* Disable GLX rendering when vaapisink is using a foreign X
178 window. It's pretty much useless */
179 if (display_type == GST_VAAPI_DISPLAY_TYPE_GLX) {
180 display_type = GST_VAAPI_DISPLAY_TYPE_X11;
181 gst_vaapi_plugin_base_set_display_type(GST_VAAPI_PLUGIN_BASE(sink),
185 sink->foreign_window = TRUE;
187 switch (display_type) {
189 case GST_VAAPI_DISPLAY_TYPE_X11:
190 gst_vaapisink_ensure_window_xid(sink, window);
191 gst_vaapisink_set_event_handling(GST_VIDEO_OVERLAY(sink), sink->handle_events);
200 gst_vaapisink_video_overlay_set_render_rectangle(
201 GstVideoOverlay *overlay,
208 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
209 GstVaapiRectangle * const display_rect = &sink->display_rect;
213 display_rect->width = width;
214 display_rect->height = height;
216 GST_DEBUG("render rect (%d,%d):%ux%u",
217 display_rect->x, display_rect->y,
218 display_rect->width, display_rect->height);
222 gst_vaapisink_reconfigure_window(GstVaapiSink * sink)
224 guint win_width, win_height;
226 gst_vaapi_window_reconfigure(sink->window);
227 gst_vaapi_window_get_size(sink->window, &win_width, &win_height);
228 if (win_width != sink->window_width || win_height != sink->window_height) {
229 if (!gst_vaapisink_ensure_render_rect(sink, win_width, win_height))
231 GST_INFO("window was resized from %ux%u to %ux%u",
232 sink->window_width, sink->window_height, win_width, win_height);
233 sink->window_width = win_width;
234 sink->window_height = win_height;
242 gst_vaapisink_event_thread_loop_x11(GstVaapiSink *sink)
244 GstVaapiDisplay * const display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
245 gboolean has_events, do_expose = FALSE;
249 Display * const x11_dpy =
250 gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
252 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window));
254 /* Handle Expose + ConfigureNotify */
255 /* Need to lock whole loop or we corrupt the XEvent queue: */
257 gst_vaapi_display_lock(display);
258 has_events = XCheckWindowEvent(x11_dpy, x11_win,
259 StructureNotifyMask | ExposureMask, &e);
260 gst_vaapi_display_unlock(display);
268 case ConfigureNotify:
269 if (gst_vaapisink_reconfigure_window(sink))
277 gst_vaapisink_video_overlay_expose(GST_VIDEO_OVERLAY(sink));
278 /* FIXME: handle mouse and key events */
284 gst_vaapisink_event_thread_loop_default(GstVaapiSink *sink)
289 gst_vaapisink_event_thread (GstVaapiSink *sink)
291 void (*thread_loop)(GstVaapiSink *sink);
293 switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
295 case GST_VAAPI_DISPLAY_TYPE_X11:
296 case GST_VAAPI_DISPLAY_TYPE_GLX:
297 thread_loop = gst_vaapisink_event_thread_loop_x11;
301 thread_loop = gst_vaapisink_event_thread_loop_default;
305 GST_OBJECT_LOCK(sink);
306 while (!sink->event_thread_cancel) {
307 GST_OBJECT_UNLOCK(sink);
309 g_usleep(G_USEC_PER_SEC / 20);
310 GST_OBJECT_LOCK(sink);
312 GST_OBJECT_UNLOCK(sink);
318 gst_vaapisink_video_overlay_expose(GstVideoOverlay *overlay)
320 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
322 if (sink->video_buffer) {
323 gst_vaapisink_reconfigure_window(sink);
324 gst_vaapisink_show_frame(GST_BASE_SINK_CAST(sink), sink->video_buffer);
329 gst_vaapisink_set_event_handling(GstVideoOverlay *overlay,
330 gboolean handle_events)
332 GThread *thread = NULL;
333 GstVaapiSink * const sink = GST_VAAPISINK(overlay);
335 GstVaapiDisplayX11 * const display =
336 GST_VAAPI_DISPLAY_X11(GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
339 GST_OBJECT_LOCK(sink);
340 sink->handle_events = handle_events;
341 if (handle_events && !sink->event_thread) {
342 /* Setup our event listening thread */
343 GST_DEBUG("starting xevent thread");
344 switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
346 case GST_VAAPI_DISPLAY_TYPE_X11:
347 case GST_VAAPI_DISPLAY_TYPE_GLX:
348 XSelectInput(gst_vaapi_display_x11_get_display(display),
349 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window)),
350 StructureNotifyMask | ExposureMask);
357 sink->event_thread_cancel = FALSE;
358 sink->event_thread = g_thread_try_new("vaapisink-events",
359 (GThreadFunc) gst_vaapisink_event_thread, sink, NULL);
361 else if (!handle_events && sink->event_thread) {
362 GST_DEBUG("stopping xevent thread");
364 switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
366 case GST_VAAPI_DISPLAY_TYPE_X11:
367 case GST_VAAPI_DISPLAY_TYPE_GLX:
368 XSelectInput(gst_vaapi_display_x11_get_display(display),
369 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window)),
378 /* grab thread and mark it as NULL */
379 thread = sink->event_thread;
380 sink->event_thread = NULL;
381 sink->event_thread_cancel = TRUE;
383 GST_OBJECT_UNLOCK(sink);
385 /* Wait for our event thread to finish */
387 g_thread_join(thread);
388 GST_DEBUG("xevent thread stopped");
393 gst_vaapisink_video_overlay_iface_init(GstVideoOverlayInterface *iface)
395 iface->set_window_handle = gst_vaapisink_video_overlay_set_window_handle;
396 iface->set_render_rectangle = gst_vaapisink_video_overlay_set_render_rectangle;
397 iface->expose = gst_vaapisink_video_overlay_expose;
398 iface->handle_events = gst_vaapisink_set_event_handling;
402 gst_vaapisink_destroy(GstVaapiSink *sink)
404 gst_vaapisink_set_event_handling(GST_VIDEO_OVERLAY(sink), FALSE);
406 gst_buffer_replace(&sink->video_buffer, NULL);
408 gst_vaapi_texture_replace(&sink->texture, NULL);
410 gst_caps_replace(&sink->caps, NULL);
414 /* Checks whether a ConfigureNotify event is in the queue */
415 typedef struct _ConfigureNotifyEventPendingArgs ConfigureNotifyEventPendingArgs;
416 struct _ConfigureNotifyEventPendingArgs {
424 configure_notify_event_pending_cb(Display *dpy, XEvent *xev, XPointer arg)
426 ConfigureNotifyEventPendingArgs * const args =
427 (ConfigureNotifyEventPendingArgs *)arg;
429 if (xev->type == ConfigureNotify &&
430 xev->xconfigure.window == args->window &&
431 xev->xconfigure.width == args->width &&
432 xev->xconfigure.height == args->height)
435 /* XXX: this is a hack to traverse the whole queue because we
436 can't use XPeekIfEvent() since it could block */
441 configure_notify_event_pending(
448 GstVaapiDisplayX11 * const display =
449 GST_VAAPI_DISPLAY_X11(GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
450 ConfigureNotifyEventPendingArgs args;
453 args.window = window;
455 args.height = height;
458 /* XXX: don't use XPeekIfEvent() because it might block */
460 gst_vaapi_display_x11_get_display(display),
462 configure_notify_event_pending_cb, (XPointer)&args
469 get_display_type_name(GstVaapiDisplayType display_type)
471 gpointer const klass = g_type_class_peek(GST_VAAPI_TYPE_DISPLAY_TYPE);
472 GEnumValue * const e = g_enum_get_value(klass, display_type);
475 return e->value_name;
476 return "<unknown-type>";
479 static inline gboolean
480 gst_vaapisink_ensure_display(GstVaapiSink *sink)
482 return gst_vaapi_plugin_base_ensure_display(GST_VAAPI_PLUGIN_BASE(sink));
486 gst_vaapisink_display_changed(GstVaapiPluginBase *plugin)
488 GstVaapiSink * const sink = GST_VAAPISINK(plugin);
489 GstVaapiRenderMode render_mode;
491 GST_INFO("created %s %p", get_display_type_name(plugin->display_type),
495 gst_vaapi_display_get_render_mode(plugin->display, &render_mode) &&
496 render_mode == GST_VAAPI_RENDER_MODE_OVERLAY;
497 GST_DEBUG("use %s rendering mode",
498 sink->use_overlay ? "overlay" : "texture");
500 sink->use_rotation = gst_vaapi_display_has_property(plugin->display,
501 GST_VAAPI_DISPLAY_PROP_ROTATION);
505 gst_vaapisink_ensure_uploader(GstVaapiSink *sink)
507 if (!gst_vaapisink_ensure_display(sink))
509 if (!gst_vaapi_plugin_base_ensure_uploader(GST_VAAPI_PLUGIN_BASE(sink)))
515 gst_vaapisink_ensure_render_rect(GstVaapiSink *sink, guint width, guint height)
517 GstVaapiRectangle * const display_rect = &sink->display_rect;
518 guint num, den, display_par_n, display_par_d;
521 /* Return success if caps are not set yet */
525 if (!sink->keep_aspect) {
526 display_rect->width = width;
527 display_rect->height = height;
531 GST_DEBUG("force-aspect-ratio is false; distorting while scaling video");
532 GST_DEBUG("render rect (%d,%d):%ux%u",
533 display_rect->x, display_rect->y,
534 display_rect->width, display_rect->height);
538 GST_DEBUG("ensure render rect within %ux%u bounds", width, height);
540 gst_vaapi_display_get_pixel_aspect_ratio(
541 GST_VAAPI_PLUGIN_BASE_DISPLAY(sink),
542 &display_par_n, &display_par_d
544 GST_DEBUG("display pixel-aspect-ratio %d/%d",
545 display_par_n, display_par_d);
547 success = gst_video_calculate_display_ratio(
549 sink->video_width, sink->video_height,
550 sink->video_par_n, sink->video_par_d,
551 display_par_n, display_par_d
555 GST_DEBUG("video size %dx%d, calculated ratio %d/%d",
556 sink->video_width, sink->video_height, num, den);
558 display_rect->width = gst_util_uint64_scale_int(height, num, den);
559 if (display_rect->width <= width) {
560 GST_DEBUG("keeping window height");
561 display_rect->height = height;
564 GST_DEBUG("keeping window width");
565 display_rect->width = width;
566 display_rect->height =
567 gst_util_uint64_scale_int(width, den, num);
569 GST_DEBUG("scaling video to %ux%u", display_rect->width, display_rect->height);
571 g_assert(display_rect->width <= width);
572 g_assert(display_rect->height <= height);
574 display_rect->x = (width - display_rect->width) / 2;
575 display_rect->y = (height - display_rect->height) / 2;
577 GST_DEBUG("render rect (%d,%d):%ux%u",
578 display_rect->x, display_rect->y,
579 display_rect->width, display_rect->height);
584 gst_vaapisink_ensure_window_size(GstVaapiSink *sink, guint *pwidth, guint *pheight)
586 GstVaapiDisplay * const display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
587 GstVideoRectangle src_rect, dst_rect, out_rect;
588 guint num, den, display_width, display_height, display_par_n, display_par_d;
589 gboolean success, scale;
591 if (sink->foreign_window) {
592 *pwidth = sink->window_width;
593 *pheight = sink->window_height;
597 gst_vaapi_display_get_size(display, &display_width, &display_height);
598 if (sink->fullscreen) {
599 *pwidth = display_width;
600 *pheight = display_height;
604 gst_vaapi_display_get_pixel_aspect_ratio(
606 &display_par_n, &display_par_d
609 success = gst_video_calculate_display_ratio(
611 sink->video_width, sink->video_height,
612 sink->video_par_n, sink->video_par_d,
613 display_par_n, display_par_d
616 num = sink->video_par_n;
617 den = sink->video_par_d;
622 src_rect.w = gst_util_uint64_scale_int(sink->video_height, num, den);
623 src_rect.h = sink->video_height;
626 dst_rect.w = display_width;
627 dst_rect.h = display_height;
628 scale = (src_rect.w > dst_rect.w || src_rect.h > dst_rect.h);
629 gst_video_sink_center_rect(src_rect, dst_rect, &out_rect, scale);
630 *pwidth = out_rect.w;
631 *pheight = out_rect.h;
634 static inline gboolean
635 gst_vaapisink_ensure_window(GstVaapiSink *sink, guint width, guint height)
637 GstVaapiDisplay * const display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
640 const GstVaapiDisplayType display_type =
641 GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink);
642 switch (display_type) {
644 case GST_VAAPI_DISPLAY_TYPE_GLX:
645 sink->window = gst_vaapi_window_glx_new(display, width, height);
646 goto notify_video_overlay_interface;
649 case GST_VAAPI_DISPLAY_TYPE_X11:
650 sink->window = gst_vaapi_window_x11_new(display, width, height);
651 notify_video_overlay_interface:
654 gst_video_overlay_got_window_handle(
655 GST_VIDEO_OVERLAY(sink),
656 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window))
661 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
662 sink->window = gst_vaapi_window_wayland_new(display, width, height);
666 GST_ERROR("unsupported display type %d", display_type);
670 return sink->window != NULL;
675 gst_vaapisink_ensure_window_xid(GstVaapiSink *sink, guintptr window_id)
677 GstVaapiDisplay *display;
679 unsigned int width, height, border_width, depth;
683 if (!gst_vaapisink_ensure_display(sink))
685 display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
687 gst_vaapi_display_lock(display);
689 gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display)),
692 &x, &y, &width, &height, &border_width, &depth
694 gst_vaapi_display_unlock(display);
696 if ((width != sink->window_width || height != sink->window_height) &&
697 !configure_notify_event_pending(sink, xid, width, height)) {
698 if (!gst_vaapisink_ensure_render_rect(sink, width, height))
700 sink->window_width = width;
701 sink->window_height = height;
705 gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window)) == xid)
708 gst_vaapi_window_replace(&sink->window, NULL);
710 switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
712 case GST_VAAPI_DISPLAY_TYPE_GLX:
713 sink->window = gst_vaapi_window_glx_new_with_xid(display, xid);
716 case GST_VAAPI_DISPLAY_TYPE_X11:
717 sink->window = gst_vaapi_window_x11_new_with_xid(display, xid);
720 GST_ERROR("unsupported display type %d",
721 GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink));
724 return sink->window != NULL;
729 gst_vaapisink_ensure_rotation(GstVaapiSink *sink, gboolean recalc_display_rect)
731 GstVaapiDisplay * const display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
732 gboolean success = FALSE;
734 g_return_val_if_fail(display, FALSE);
736 if (sink->rotation == sink->rotation_req)
739 if (!sink->use_rotation) {
740 GST_WARNING("VA display does not support rotation");
744 gst_vaapi_display_lock(display);
745 success = gst_vaapi_display_set_rotation(display, sink->rotation_req);
746 gst_vaapi_display_unlock(display);
748 GST_ERROR("failed to change VA display rotation mode");
752 if (((sink->rotation + sink->rotation_req) % 180) == 90) {
753 /* Orientation changed */
754 G_PRIMITIVE_SWAP(guint, sink->video_width, sink->video_height);
755 G_PRIMITIVE_SWAP(gint, sink->video_par_n, sink->video_par_d);
758 if (recalc_display_rect && !sink->foreign_window)
759 gst_vaapisink_ensure_render_rect(sink, sink->window_width,
760 sink->window_height);
764 sink->rotation = sink->rotation_req;
769 gst_vaapisink_start(GstBaseSink *base_sink)
771 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
773 if (!gst_vaapi_plugin_base_open(GST_VAAPI_PLUGIN_BASE(sink)))
775 return gst_vaapisink_ensure_uploader(sink);
779 gst_vaapisink_stop(GstBaseSink *base_sink)
781 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
783 gst_buffer_replace(&sink->video_buffer, NULL);
784 #if GST_CHECK_VERSION(1,0,0)
785 g_clear_object(&sink->video_buffer_pool);
787 gst_vaapi_window_replace(&sink->window, NULL);
789 gst_vaapi_plugin_base_close(GST_VAAPI_PLUGIN_BASE(sink));
794 gst_vaapisink_get_caps_impl(GstBaseSink *base_sink)
796 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
797 GstCaps *out_caps, *yuv_caps;
799 #if GST_CHECK_VERSION(1,1,0)
800 out_caps = gst_static_pad_template_get_caps(&gst_vaapisink_sink_factory);
802 out_caps = gst_caps_from_string(GST_VAAPI_SURFACE_CAPS);
807 if (gst_vaapisink_ensure_uploader(sink)) {
808 yuv_caps = GST_VAAPI_PLUGIN_BASE_UPLOADER_CAPS(sink);
810 out_caps = gst_caps_make_writable(out_caps);
811 gst_caps_append(out_caps, gst_caps_copy(yuv_caps));
817 #if GST_CHECK_VERSION(1,0,0)
818 static inline GstCaps *
819 gst_vaapisink_get_caps(GstBaseSink *base_sink, GstCaps *filter)
821 GstCaps *caps, *out_caps;
823 caps = gst_vaapisink_get_caps_impl(base_sink);
824 if (caps && filter) {
825 out_caps = gst_caps_intersect_full(caps, filter,
826 GST_CAPS_INTERSECT_FIRST);
827 gst_caps_unref(caps);
834 #define gst_vaapisink_get_caps gst_vaapisink_get_caps_impl
838 update_colorimetry(GstVaapiSink *sink, GstVideoColorimetry *cinfo)
840 #if GST_CHECK_VERSION(1,0,0)
841 if (gst_video_colorimetry_matches(cinfo,
842 GST_VIDEO_COLORIMETRY_BT601))
843 sink->color_standard = GST_VAAPI_COLOR_STANDARD_ITUR_BT_601;
844 else if (gst_video_colorimetry_matches(cinfo,
845 GST_VIDEO_COLORIMETRY_BT709))
846 sink->color_standard = GST_VAAPI_COLOR_STANDARD_ITUR_BT_709;
847 else if (gst_video_colorimetry_matches(cinfo,
848 GST_VIDEO_COLORIMETRY_SMPTE240M))
849 sink->color_standard = GST_VAAPI_COLOR_STANDARD_SMPTE_240M;
851 sink->color_standard = 0;
853 GST_DEBUG("colorimetry %s", gst_video_colorimetry_to_string(cinfo));
858 gst_vaapisink_set_caps(GstBaseSink *base_sink, GstCaps *caps)
860 GstVaapiPluginBase * const plugin = GST_VAAPI_PLUGIN_BASE(base_sink);
861 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
862 GstVideoInfo * const vip = GST_VAAPI_PLUGIN_BASE_SINK_PAD_INFO(sink);
863 GstVaapiDisplay *display;
864 guint win_width, win_height;
866 if (!gst_vaapisink_ensure_display(sink))
868 display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
871 if (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink) == GST_VAAPI_DISPLAY_TYPE_DRM)
875 if (!gst_vaapi_plugin_base_set_caps(plugin, caps, NULL))
878 sink->video_width = GST_VIDEO_INFO_WIDTH(vip);
879 sink->video_height = GST_VIDEO_INFO_HEIGHT(vip);
880 sink->video_par_n = GST_VIDEO_INFO_PAR_N(vip);
881 sink->video_par_d = GST_VIDEO_INFO_PAR_D(vip);
882 GST_DEBUG("video pixel-aspect-ratio %d/%d",
883 sink->video_par_n, sink->video_par_d);
885 update_colorimetry(sink, &vip->colorimetry);
886 gst_caps_replace(&sink->caps, caps);
888 gst_vaapisink_ensure_rotation(sink, FALSE);
890 gst_vaapisink_ensure_window_size(sink, &win_width, &win_height);
892 if (!sink->foreign_window || sink->fullscreen)
893 gst_vaapi_window_set_size(sink->window, win_width, win_height);
896 gst_vaapi_display_lock(display);
897 gst_video_overlay_prepare_window_handle(GST_VIDEO_OVERLAY(sink));
898 gst_vaapi_display_unlock(display);
901 if (!gst_vaapisink_ensure_window(sink, win_width, win_height))
903 gst_vaapi_window_set_fullscreen(sink->window, sink->fullscreen);
904 gst_vaapi_window_show(sink->window);
905 gst_vaapi_window_get_size(sink->window, &win_width, &win_height);
906 gst_vaapisink_set_event_handling(GST_VIDEO_OVERLAY(sink), sink->handle_events);
908 sink->window_width = win_width;
909 sink->window_height = win_height;
910 GST_DEBUG("window size %ux%u", win_width, win_height);
912 return gst_vaapisink_ensure_render_rect(sink, win_width, win_height);
917 render_background(GstVaapiSink *sink)
919 /* Original code from Mirco Muller (MacSlow):
920 <http://cgit.freedesktop.org/~macslow/gl-gst-player/> */
921 GLfloat fStartX = 0.0f;
922 GLfloat fStartY = 0.0f;
923 GLfloat fWidth = (GLfloat)sink->window_width;
924 GLfloat fHeight = (GLfloat)sink->window_height;
926 glClear(GL_COLOR_BUFFER_BIT);
929 /* top third, darker grey to white */
930 glColor3f(0.85f, 0.85f, 0.85f);
931 glVertex3f(fStartX, fStartY, 0.0f);
932 glColor3f(0.85f, 0.85f, 0.85f);
933 glVertex3f(fStartX + fWidth, fStartY, 0.0f);
934 glColor3f(1.0f, 1.0f, 1.0f);
935 glVertex3f(fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
936 glColor3f(1.0f, 1.0f, 1.0f);
937 glVertex3f(fStartX, fStartY + fHeight / 3.0f, 0.0f);
939 /* middle third, just plain white */
940 glColor3f(1.0f, 1.0f, 1.0f);
941 glVertex3f(fStartX, fStartY + fHeight / 3.0f, 0.0f);
942 glVertex3f(fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
943 glVertex3f(fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
944 glVertex3f(fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
946 /* bottom third, white to lighter grey */
947 glColor3f(1.0f, 1.0f, 1.0f);
948 glVertex3f(fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
949 glColor3f(1.0f, 1.0f, 1.0f);
950 glVertex3f(fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
951 glColor3f(0.62f, 0.66f, 0.69f);
952 glVertex3f(fStartX + fWidth, fStartY + fHeight, 0.0f);
953 glColor3f(0.62f, 0.66f, 0.69f);
954 glVertex3f(fStartX, fStartY + fHeight, 0.0f);
960 render_frame(GstVaapiSink *sink, GstVaapiSurface *surface,
961 const GstVaapiRectangle *surface_rect)
963 const guint x1 = sink->display_rect.x;
964 const guint x2 = sink->display_rect.x + sink->display_rect.width;
965 const guint y1 = sink->display_rect.y;
966 const guint y2 = sink->display_rect.y + sink->display_rect.height;
967 gfloat tx1, tx2, ty1, ty2;
971 gst_vaapi_surface_get_size(surface, &width, &height);
972 tx1 = (gfloat)surface_rect->x / width;
973 ty1 = (gfloat)surface_rect->y / height;
974 tx2 = (gfloat)(surface_rect->x + surface_rect->width) / width;
975 ty2 = (gfloat)(surface_rect->y + surface_rect->height) / height;
984 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
987 glTexCoord2f(tx1, ty1); glVertex2i(x1, y1);
988 glTexCoord2f(tx1, ty2); glVertex2i(x1, y2);
989 glTexCoord2f(tx2, ty2); glVertex2i(x2, y2);
990 glTexCoord2f(tx2, ty1); glVertex2i(x2, y1);
996 render_reflection(GstVaapiSink *sink)
998 const guint x1 = sink->display_rect.x;
999 const guint x2 = sink->display_rect.x + sink->display_rect.width;
1000 const guint y1 = sink->display_rect.y;
1001 const guint rh = sink->display_rect.height / 5;
1002 GLfloat ry = 1.0f - (GLfloat)rh / (GLfloat)sink->display_rect.height;
1006 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
1007 glTexCoord2f(0.0f, 1.0f); glVertex2i(x1, y1);
1008 glTexCoord2f(1.0f, 1.0f); glVertex2i(x2, y1);
1010 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
1011 glTexCoord2f(1.0f, ry); glVertex2i(x2, y1 + rh);
1012 glTexCoord2f(0.0f, ry); glVertex2i(x1, y1 + rh);
1018 gst_vaapisink_ensure_texture(GstVaapiSink *sink, GstVaapiSurface *surface)
1020 GstVaapiDisplay * display = GST_VAAPI_PLUGIN_BASE_DISPLAY(sink);
1021 GstVideoRectangle tex_rect, dis_rect, out_rect;
1022 guint width, height;
1027 gst_vaapi_surface_get_size(surface, &width, &height);
1031 tex_rect.h = height;
1033 gst_vaapi_display_get_size(display, &width, &height);
1037 dis_rect.h = height;
1039 gst_video_sink_center_rect(tex_rect, dis_rect, &out_rect, TRUE);
1041 /* XXX: use surface size for now since some VA drivers have issues
1042 with downscaling to the provided texture size. i.e. we should be
1043 using the resulting out_rect size, which preserves the aspect
1044 ratio of the surface */
1046 height = tex_rect.h;
1047 GST_INFO("texture size %ux%u", width, height);
1049 sink->texture = gst_vaapi_texture_new(display,
1050 GL_TEXTURE_2D, GL_BGRA, width, height);
1051 return sink->texture != NULL;
1055 gst_vaapisink_show_frame_glx(
1057 GstVaapiSurface *surface,
1058 const GstVaapiRectangle *surface_rect,
1062 GstVaapiWindowGLX *window;
1068 window = GST_VAAPI_WINDOW_GLX(sink->window);
1070 gst_vaapi_window_glx_make_current(window);
1071 if (!gst_vaapisink_ensure_texture(sink, surface))
1072 goto error_create_texture;
1073 if (!gst_vaapi_texture_put_surface(sink->texture, surface, flags))
1074 goto error_transfer_surface;
1076 target = gst_vaapi_texture_get_target(sink->texture);
1077 texture = gst_vaapi_texture_get_id(sink->texture);
1078 if (target != GL_TEXTURE_2D || !texture)
1081 if (sink->use_reflection)
1082 render_background(sink);
1085 glBindTexture(target, texture);
1087 if (sink->use_reflection) {
1089 glRotatef(20.0f, 0.0f, 1.0f, 0.0f);
1090 glTranslatef(50.0f, 0.0f, 0.0f);
1092 render_frame(sink, surface, surface_rect);
1093 if (sink->use_reflection) {
1095 glTranslatef(0.0, (GLfloat)sink->display_rect.height + 5.0f, 0.0f);
1096 render_reflection(sink);
1101 glBindTexture(target, 0);
1103 gst_vaapi_window_glx_swap_buffers(window);
1107 error_create_texture:
1109 GST_DEBUG("could not create VA/GLX texture");
1112 error_transfer_surface:
1114 GST_DEBUG("could not transfer VA surface to texture");
1120 static inline gboolean
1121 gst_vaapisink_put_surface(
1123 GstVaapiSurface *surface,
1124 const GstVaapiRectangle *surface_rect,
1131 if (!gst_vaapi_window_put_surface(sink->window, surface,
1132 surface_rect, &sink->display_rect, flags)) {
1133 GST_DEBUG("could not render VA surface");
1139 static GstFlowReturn
1140 gst_vaapisink_show_frame_unlocked(GstVaapiSink *sink, GstBuffer *src_buffer)
1142 GstVaapiVideoMeta *meta;
1143 GstVaapiSurfaceProxy *proxy;
1144 GstVaapiSurface *surface;
1148 GstVaapiRectangle *surface_rect = NULL;
1149 #if GST_CHECK_VERSION(1,0,0)
1150 GstVaapiRectangle tmp_rect;
1155 #if GST_CHECK_VERSION(1,0,0)
1156 GstVideoCropMeta * const crop_meta =
1157 gst_buffer_get_video_crop_meta(src_buffer);
1159 surface_rect = &tmp_rect;
1160 surface_rect->x = crop_meta->x;
1161 surface_rect->y = crop_meta->y;
1162 surface_rect->width = crop_meta->width;
1163 surface_rect->height = crop_meta->height;
1167 ret = gst_vaapi_plugin_base_get_input_buffer(GST_VAAPI_PLUGIN_BASE(sink),
1168 src_buffer, &buffer);
1169 if (ret != GST_FLOW_OK && ret != GST_FLOW_NOT_SUPPORTED)
1172 meta = gst_buffer_get_vaapi_video_meta(buffer);
1173 GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(sink,
1174 gst_vaapi_video_meta_get_display(meta));
1176 gst_vaapisink_ensure_rotation(sink, TRUE);
1178 proxy = gst_vaapi_video_meta_get_surface_proxy(meta);
1182 /* Valide view component to display */
1183 view_id = GST_VAAPI_SURFACE_PROXY_VIEW_ID(proxy);
1184 if (G_UNLIKELY(sink->view_id == -1))
1185 sink->view_id = view_id;
1186 else if (sink->view_id != view_id) {
1187 gst_buffer_unref(buffer);
1191 surface = gst_vaapi_video_meta_get_surface(meta);
1195 GST_DEBUG("render surface %" GST_VAAPI_ID_FORMAT,
1196 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
1199 surface_rect = (GstVaapiRectangle *)
1200 gst_vaapi_video_meta_get_render_rect(meta);
1203 GST_DEBUG("render rect (%d,%d), size %ux%u",
1204 surface_rect->x, surface_rect->y,
1205 surface_rect->width, surface_rect->height);
1207 flags = gst_vaapi_video_meta_get_render_flags(meta);
1209 /* Append default color standard obtained from caps if none was
1210 available on a per-buffer basis */
1211 if (!(flags & GST_VAAPI_COLOR_STANDARD_MASK))
1212 flags |= sink->color_standard;
1214 if (!gst_vaapi_apply_composition(surface, src_buffer))
1215 GST_WARNING("could not update subtitles");
1217 switch (GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink)) {
1219 case GST_VAAPI_DISPLAY_TYPE_DRM:
1224 case GST_VAAPI_DISPLAY_TYPE_GLX:
1226 goto put_surface_x11;
1227 success = gst_vaapisink_show_frame_glx(sink, surface, surface_rect,
1232 case GST_VAAPI_DISPLAY_TYPE_X11:
1234 success = gst_vaapisink_put_surface(sink, surface, surface_rect, flags);
1238 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
1239 success = gst_vaapisink_put_surface(sink, surface, surface_rect, flags);
1243 GST_ERROR("unsupported display type %d",
1244 GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink));
1251 /* Retain VA surface until the next one is displayed */
1252 gst_buffer_replace(&sink->video_buffer, buffer);
1253 gst_buffer_unref(buffer);
1257 gst_buffer_unref(buffer);
1258 return GST_FLOW_EOS;
1261 static GstFlowReturn
1262 gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *src_buffer)
1264 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
1267 /* At least we need at least to protect the _set_subpictures_()
1268 * call to prevent a race during subpicture desctruction.
1269 * FIXME: Could use a less coarse grained lock, though: */
1270 gst_vaapi_display_lock(GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
1271 ret = gst_vaapisink_show_frame_unlocked(sink, src_buffer);
1272 gst_vaapi_display_unlock(GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
1276 #if GST_CHECK_VERSION(1,0,0)
1278 gst_vaapisink_propose_allocation(GstBaseSink *base_sink, GstQuery *query)
1280 GstVaapiPluginBase * const plugin = GST_VAAPI_PLUGIN_BASE(base_sink);
1282 if (!gst_vaapi_plugin_base_propose_allocation(plugin, query))
1285 gst_query_add_allocation_meta(query, GST_VIDEO_CROP_META_API_TYPE, NULL);
1286 gst_query_add_allocation_meta(query,
1287 GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, NULL);
1291 static GstFlowReturn
1292 gst_vaapisink_buffer_alloc(GstBaseSink *base_sink, guint64 offset, guint size,
1293 GstCaps *caps, GstBuffer **outbuf_ptr)
1295 return gst_vaapi_plugin_base_allocate_input_buffer(
1296 GST_VAAPI_PLUGIN_BASE(base_sink), caps, outbuf_ptr);
1301 gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query)
1303 GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
1305 GST_INFO_OBJECT(sink, "query type %s", GST_QUERY_TYPE_NAME(query));
1307 if (gst_vaapi_reply_to_query(query, GST_VAAPI_PLUGIN_BASE_DISPLAY(sink))) {
1308 GST_DEBUG("sharing display %p", GST_VAAPI_PLUGIN_BASE_DISPLAY(sink));
1312 return GST_BASE_SINK_CLASS(gst_vaapisink_parent_class)->query(base_sink,
1317 gst_vaapisink_finalize(GObject *object)
1319 gst_vaapisink_destroy(GST_VAAPISINK(object));
1321 gst_vaapi_plugin_base_finalize(GST_VAAPI_PLUGIN_BASE(object));
1322 G_OBJECT_CLASS(gst_vaapisink_parent_class)->finalize(object);
1326 gst_vaapisink_set_property(
1329 const GValue *value,
1333 GstVaapiSink * const sink = GST_VAAPISINK(object);
1336 case PROP_DISPLAY_TYPE:
1337 gst_vaapi_plugin_base_set_display_type(GST_VAAPI_PLUGIN_BASE(sink),
1338 g_value_get_enum(value));
1340 case PROP_DISPLAY_NAME:
1341 gst_vaapi_plugin_base_set_display_name(GST_VAAPI_PLUGIN_BASE(sink),
1342 g_value_get_string(value));
1344 case PROP_FULLSCREEN:
1345 sink->fullscreen = g_value_get_boolean(value);
1347 case PROP_SYNCHRONOUS:
1348 sink->synchronous = g_value_get_boolean(value);
1351 sink->view_id = g_value_get_int(value);
1354 sink->use_glx = g_value_get_boolean(value);
1356 case PROP_USE_REFLECTION:
1357 sink->use_reflection = g_value_get_boolean(value);
1360 sink->rotation_req = g_value_get_enum(value);
1362 case PROP_FORCE_ASPECT_RATIO:
1363 sink->keep_aspect = g_value_get_boolean(value);
1366 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1372 gst_vaapisink_get_property(
1379 GstVaapiSink * const sink = GST_VAAPISINK(object);
1382 case PROP_DISPLAY_TYPE:
1383 g_value_set_enum(value, GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(sink));
1385 case PROP_DISPLAY_NAME:
1386 g_value_set_string(value, GST_VAAPI_PLUGIN_BASE_DISPLAY_NAME(sink));
1388 case PROP_FULLSCREEN:
1389 g_value_set_boolean(value, sink->fullscreen);
1391 case PROP_SYNCHRONOUS:
1392 g_value_set_boolean(value, sink->synchronous);
1395 g_value_set_int(value, sink->view_id);
1398 g_value_set_boolean(value, sink->use_glx);
1400 case PROP_USE_REFLECTION:
1401 g_value_set_boolean(value, sink->use_reflection);
1404 g_value_set_enum(value, sink->rotation);
1406 case PROP_FORCE_ASPECT_RATIO:
1407 g_value_set_boolean(value, sink->keep_aspect);
1410 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1416 gst_vaapisink_set_bus(GstElement *element, GstBus *bus)
1418 /* Make sure to allocate a VA display in the sink element first,
1419 so that upstream elements could query a display that was
1420 allocated here, and that exactly matches what the user
1421 requested through the "display" property */
1422 if (!GST_ELEMENT_BUS(element) && bus)
1423 gst_vaapisink_ensure_display(GST_VAAPISINK(element));
1425 GST_ELEMENT_CLASS(gst_vaapisink_parent_class)->set_bus(element, bus);
1429 gst_vaapisink_class_init(GstVaapiSinkClass *klass)
1431 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
1432 GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
1433 GstBaseSinkClass * const basesink_class = GST_BASE_SINK_CLASS(klass);
1434 GstVaapiPluginBaseClass * const base_plugin_class =
1435 GST_VAAPI_PLUGIN_BASE_CLASS(klass);
1436 GstPadTemplate *pad_template;
1438 GST_DEBUG_CATEGORY_INIT(gst_debug_vaapisink,
1439 GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
1441 gst_vaapi_plugin_base_class_init(base_plugin_class);
1442 base_plugin_class->has_interface = gst_vaapisink_has_interface;
1443 base_plugin_class->display_changed = gst_vaapisink_display_changed;
1445 object_class->finalize = gst_vaapisink_finalize;
1446 object_class->set_property = gst_vaapisink_set_property;
1447 object_class->get_property = gst_vaapisink_get_property;
1449 basesink_class->start = gst_vaapisink_start;
1450 basesink_class->stop = gst_vaapisink_stop;
1451 basesink_class->get_caps = gst_vaapisink_get_caps;
1452 basesink_class->set_caps = gst_vaapisink_set_caps;
1453 basesink_class->preroll = gst_vaapisink_show_frame;
1454 basesink_class->render = gst_vaapisink_show_frame;
1455 basesink_class->query = gst_vaapisink_query;
1456 #if GST_CHECK_VERSION(1,0,0)
1457 basesink_class->propose_allocation = gst_vaapisink_propose_allocation;
1459 basesink_class->buffer_alloc = gst_vaapisink_buffer_alloc;
1462 element_class->set_bus = gst_vaapisink_set_bus;
1463 gst_element_class_set_static_metadata(element_class,
1467 "Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
1469 pad_template = gst_static_pad_template_get(&gst_vaapisink_sink_factory);
1470 gst_element_class_add_pad_template(element_class, pad_template);
1472 g_object_class_install_property
1475 g_param_spec_enum("display",
1477 "display type to use",
1478 GST_VAAPI_TYPE_DISPLAY_TYPE,
1479 GST_VAAPI_DISPLAY_TYPE_ANY,
1480 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1482 g_object_class_install_property
1485 g_param_spec_string("display-name",
1487 "display name to use",
1489 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1492 g_object_class_install_property
1495 g_param_spec_boolean("use-glx",
1497 "Enables OpenGL rendering",
1499 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1501 g_object_class_install_property
1503 PROP_USE_REFLECTION,
1504 g_param_spec_boolean("use-reflection",
1505 "Reflection effect",
1506 "Enables OpenGL reflection effect",
1508 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1511 g_object_class_install_property
1514 g_param_spec_boolean("fullscreen",
1516 "Requests window in fullscreen state",
1518 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1521 * GstVaapiSink:synchronous:
1523 * When enabled, runs the X display in synchronous mode. Note that
1524 * this is used only for debugging.
1526 g_object_class_install_property
1529 g_param_spec_boolean("synchronous",
1531 "Toggles X display synchronous mode",
1533 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1536 * GstVaapiSink:rotation:
1538 * The VA display rotation mode, expressed as a #GstVaapiRotation.
1540 g_object_class_install_property
1543 g_param_spec_enum(GST_VAAPI_DISPLAY_PROP_ROTATION,
1545 "The display rotation mode",
1546 GST_VAAPI_TYPE_ROTATION,
1548 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1551 * GstVaapiSink:force-aspect-ratio:
1553 * When enabled, scaling respects video aspect ratio; when disabled, the
1554 * video is distorted to fit the window.
1556 g_object_class_install_property
1558 PROP_FORCE_ASPECT_RATIO,
1559 g_param_spec_boolean("force-aspect-ratio",
1560 "Force aspect ratio",
1561 "When enabled, scaling will respect original aspect ratio",
1563 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1566 * GstVaapiSink:view-id:
1568 * When not set to -1, the displayed frame will always be the one
1569 * that matches the view-id of the very first displayed frame. Any
1570 * other number will indicate the desire to display the supplied
1573 g_object_class_install_property
1576 g_param_spec_int("view-id",
1578 "ID of the view component of interest to display",
1580 G_PARAM_READWRITE));
1584 gst_vaapisink_init(GstVaapiSink *sink)
1586 GstVaapiPluginBase * const plugin = GST_VAAPI_PLUGIN_BASE(sink);
1588 gst_vaapi_plugin_base_init(plugin, GST_CAT_DEFAULT);
1589 gst_vaapi_plugin_base_set_display_type(plugin, DEFAULT_DISPLAY_TYPE);
1592 sink->window = NULL;
1593 sink->window_width = 0;
1594 sink->window_height = 0;
1595 sink->texture = NULL;
1596 sink->video_buffer = NULL;
1597 sink->video_width = 0;
1598 sink->video_height = 0;
1599 sink->video_par_n = 1;
1600 sink->video_par_d = 1;
1602 sink->handle_events = TRUE;
1603 sink->foreign_window = FALSE;
1604 sink->fullscreen = FALSE;
1605 sink->synchronous = FALSE;
1606 sink->rotation = DEFAULT_ROTATION;
1607 sink->rotation_req = DEFAULT_ROTATION;
1608 sink->use_reflection = FALSE;
1609 sink->use_overlay = FALSE;
1610 sink->use_rotation = FALSE;
1611 sink->keep_aspect = TRUE;
1612 gst_video_info_init(&sink->video_info);