* gstvaapisink.c - VA-API video sink
*
* Copyright (C) 2010-2011 Splitted-Desktop Systems
- * Copyright (C) 2011-2012 Intel Corporation
+ * Copyright (C) 2011-2013 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#include <gst/video/video.h>
#include <gst/video/videocontext.h>
#include <gst/vaapi/gstvaapivalue.h>
-#include <gst/vaapi/gstvaapivideobuffer.h>
#if USE_DRM
# include <gst/vaapi/gstvaapidisplay_drm.h>
#endif
#endif
/* Supported interfaces */
-#include <gst/interfaces/xoverlay.h>
+#if GST_CHECK_VERSION(1,0,0)
+# include <gst/video/videooverlay.h>
+#else
+# include <gst/interfaces/xoverlay.h>
+
+# define GST_TYPE_VIDEO_OVERLAY GST_TYPE_X_OVERLAY
+# define GST_VIDEO_OVERLAY GST_X_OVERLAY
+# define GstVideoOverlay GstXOverlay
+# define GstVideoOverlayInterface GstXOverlayClass
+
+# define gst_video_overlay_prepare_window_handle(sink) \
+ gst_x_overlay_prepare_xwindow_id(sink)
+# define gst_video_overlay_got_window_handle(sink, window_handle) \
+ gst_x_overlay_got_window_handle(sink, window_handle)
+#endif
#include "gstvaapisink.h"
#include "gstvaapipluginutil.h"
+#include "gstvaapivideometa.h"
+#if GST_CHECK_VERSION(1,0,0)
+#include "gstvaapivideobufferpool.h"
+#include "gstvaapivideomemory.h"
+#endif
#define GST_PLUGIN_NAME "vaapisink"
#define GST_PLUGIN_DESC "A VA-API based videosink"
GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapisink);
#define GST_CAT_DEFAULT gst_debug_vaapisink
-/* ElementFactory information */
-static const GstElementDetails gst_vaapisink_details =
- GST_ELEMENT_DETAILS(
- "VA-API sink",
- "Sink/Video",
- GST_PLUGIN_DESC,
- "Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
-
/* Default template */
static const char gst_vaapisink_sink_caps_str[] =
+#if GST_CHECK_VERSION(1,0,0)
+ GST_VIDEO_CAPS_MAKE(GST_VIDEO_FORMATS_ALL) "; "
+#else
"video/x-raw-yuv, "
"width = (int) [ 1, MAX ], "
"height = (int) [ 1, MAX ]; "
+#endif
GST_VAAPI_SURFACE_CAPS;
static GstStaticPadTemplate gst_vaapisink_sink_factory =
GST_PAD_ALWAYS,
GST_STATIC_CAPS(gst_vaapisink_sink_caps_str));
-static void
-gst_vaapisink_implements_iface_init(GstImplementsInterfaceClass *iface);
-
-static void
-gst_vaapisink_video_context_iface_init(GstVideoContextInterface *iface);
-
-static void
-gst_vaapisink_xoverlay_iface_init(GstXOverlayClass *iface);
-
-G_DEFINE_TYPE_WITH_CODE(
- GstVaapiSink,
- gst_vaapisink,
- GST_TYPE_VIDEO_SINK,
- G_IMPLEMENT_INTERFACE(GST_TYPE_IMPLEMENTS_INTERFACE,
- gst_vaapisink_implements_iface_init);
- G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT,
- gst_vaapisink_video_context_iface_init);
- G_IMPLEMENT_INTERFACE(GST_TYPE_X_OVERLAY,
- gst_vaapisink_xoverlay_iface_init))
-
-enum {
- PROP_0,
-
- PROP_DISPLAY_TYPE,
- PROP_FULLSCREEN,
- PROP_SYNCHRONOUS,
- PROP_USE_REFLECTION,
- PROP_ROTATION,
-};
-
-#define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_ANY
-#define DEFAULT_ROTATION GST_VAAPI_ROTATION_0
-
/* GstImplementsInterface interface */
-
+#if !GST_CHECK_VERSION(1,0,0)
static gboolean
gst_vaapisink_implements_interface_supported(
GstImplementsInterface *iface,
)
{
return (type == GST_TYPE_VIDEO_CONTEXT ||
- type == GST_TYPE_X_OVERLAY);
+ type == GST_TYPE_VIDEO_OVERLAY);
}
static void
{
iface->supported = gst_vaapisink_implements_interface_supported;
}
+#endif
/* GstVideoContext interface */
-
static void
gst_vaapisink_set_video_context(GstVideoContext *context, const gchar *type,
const GValue *value)
iface->set_context = gst_vaapisink_set_video_context;
}
-/* GstXOverlay interface */
+static void
+gst_vaapisink_video_overlay_iface_init(GstVideoOverlayInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE(
+ GstVaapiSink,
+ gst_vaapisink,
+ GST_TYPE_VIDEO_SINK,
+#if !GST_CHECK_VERSION(1,0,0)
+ G_IMPLEMENT_INTERFACE(GST_TYPE_IMPLEMENTS_INTERFACE,
+ gst_vaapisink_implements_iface_init);
+#endif
+ G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT,
+ gst_vaapisink_video_context_iface_init);
+ G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_OVERLAY,
+ gst_vaapisink_video_overlay_iface_init))
+
+enum {
+ PROP_0,
+
+ PROP_DISPLAY_TYPE,
+ PROP_FULLSCREEN,
+ PROP_SYNCHRONOUS,
+ PROP_USE_GLX,
+ PROP_USE_REFLECTION,
+ PROP_ROTATION,
+ PROP_FORCE_ASPECT_RATIO,
+};
+
+#define DEFAULT_DISPLAY_TYPE GST_VAAPI_DISPLAY_TYPE_ANY
+#define DEFAULT_ROTATION GST_VAAPI_ROTATION_0
+
+/* GstVideoOverlay interface */
#if USE_X11
static gboolean
gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *buffer);
static void
-gst_vaapisink_xoverlay_set_window_handle(GstXOverlay *overlay, guintptr window)
+gst_vaapisink_video_overlay_set_window_handle(GstVideoOverlay *overlay, guintptr window)
{
GstVaapiSink * const sink = GST_VAAPISINK(overlay);
}
static void
-gst_vaapisink_xoverlay_set_render_rectangle(
- GstXOverlay *overlay,
+gst_vaapisink_video_overlay_set_render_rectangle(
+ GstVideoOverlay *overlay,
gint x,
gint y,
gint width,
}
static void
-gst_vaapisink_xoverlay_expose(GstXOverlay *overlay)
+gst_vaapisink_video_overlay_expose(GstVideoOverlay *overlay)
{
+ GstVaapiSink * const sink = GST_VAAPISINK(overlay);
GstBaseSink * const base_sink = GST_BASE_SINK(overlay);
GstBuffer *buffer;
- buffer = gst_base_sink_get_last_buffer(base_sink);
+ if (sink->use_overlay)
+ buffer = sink->video_buffer ? gst_buffer_ref(sink->video_buffer) : NULL;
+ else {
+#if GST_CHECK_VERSION(1,0,0)
+ GstSample * const sample = gst_base_sink_get_last_sample(base_sink);
+ if (!sample)
+ return;
+ buffer = gst_buffer_ref(gst_sample_get_buffer(sample));
+ gst_sample_unref(sample);
+#else
+ buffer = gst_base_sink_get_last_buffer(base_sink);
+#endif
+ }
if (buffer) {
gst_vaapisink_show_frame(base_sink, buffer);
gst_buffer_unref(buffer);
}
static void
-gst_vaapisink_xoverlay_iface_init(GstXOverlayClass *iface)
+gst_vaapisink_video_overlay_iface_init(GstVideoOverlayInterface *iface)
{
- iface->set_window_handle = gst_vaapisink_xoverlay_set_window_handle;
- iface->set_render_rectangle = gst_vaapisink_xoverlay_set_render_rectangle;
- iface->expose = gst_vaapisink_xoverlay_expose;
+ iface->set_window_handle = gst_vaapisink_video_overlay_set_window_handle;
+ iface->set_render_rectangle = gst_vaapisink_video_overlay_set_render_rectangle;
+ iface->expose = gst_vaapisink_video_overlay_expose;
}
static void
gst_vaapisink_destroy(GstVaapiSink *sink)
{
gst_buffer_replace(&sink->video_buffer, NULL);
- g_clear_object(&sink->texture);
- g_clear_object(&sink->display);
+#if USE_GLX
+ gst_vaapi_texture_replace(&sink->texture, NULL);
+#endif
+ gst_vaapi_display_replace(&sink->display, NULL);
g_clear_object(&sink->uploader);
gst_caps_replace(&sink->caps, NULL);
{
GstVaapiDisplayType display_type;
GstVaapiRenderMode render_mode;
+ const gboolean had_display = sink->display != NULL;
if (!gst_vaapi_ensure_display(sink, sink->display_type, &sink->display))
return FALSE;
display_type = gst_vaapi_display_get_display_type(sink->display);
- if (display_type != sink->display_type) {
+ if (display_type != sink->display_type || (!had_display && sink->display)) {
GST_INFO("created %s %p", get_display_type_name(display_type),
sink->display);
sink->display_type = display_type;
if (!sink->caps)
return TRUE;
+ if (!sink->keep_aspect) {
+ display_rect->width = width;
+ display_rect->height = height;
+ display_rect->x = 0;
+ display_rect->y = 0;
+
+ GST_DEBUG("force-aspect-ratio is false; distorting while scaling video");
+ GST_DEBUG("render rect (%d,%d):%ux%u",
+ display_rect->x, display_rect->y,
+ display_rect->width, display_rect->height);
+ return TRUE;
+ }
+
GST_DEBUG("ensure render rect within %ux%u bounds", width, height);
gst_vaapi_display_get_pixel_aspect_ratio(
#if USE_GLX
case GST_VAAPI_DISPLAY_TYPE_GLX:
sink->window = gst_vaapi_window_glx_new(display, width, height);
- goto notify_xoverlay_interface;
+ goto notify_video_overlay_interface;
#endif
#if USE_X11
case GST_VAAPI_DISPLAY_TYPE_X11:
sink->window = gst_vaapi_window_x11_new(display, width, height);
- notify_xoverlay_interface:
+ notify_video_overlay_interface:
if (!sink->window)
break;
- gst_x_overlay_got_window_handle(
- GST_X_OVERLAY(sink),
+ gst_video_overlay_got_window_handle(
+ GST_VIDEO_OVERLAY(sink),
gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window))
);
break;
gst_vaapi_window_x11_get_xid(GST_VAAPI_WINDOW_X11(sink->window)) == xid)
return TRUE;
- g_clear_object(&sink->window);
+ gst_vaapi_window_replace(&sink->window, NULL);
switch (sink->display_type) {
#if USE_GLX
}
static gboolean
-gst_vaapisink_start(GstBaseSink *base_sink)
+gst_vaapisink_ensure_video_buffer_pool(GstVaapiSink *sink, GstCaps *caps)
{
- GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
+#if GST_CHECK_VERSION(1,0,0)
+ GstBufferPool *pool;
+ GstCaps *pool_caps;
+ GstStructure *config;
+ GstVideoInfo vi;
+ gboolean need_pool;
if (!gst_vaapisink_ensure_display(sink))
return FALSE;
- sink->uploader = gst_vaapi_uploader_new(sink->display);
- if (!sink->uploader)
+ if (sink->video_buffer_pool) {
+ config = gst_buffer_pool_get_config(sink->video_buffer_pool);
+ gst_buffer_pool_config_get_params(config, &pool_caps, NULL, NULL, NULL);
+ need_pool = !gst_caps_is_equal(caps, pool_caps);
+ gst_structure_free(config);
+ if (!need_pool)
+ return TRUE;
+ g_clear_object(&sink->video_buffer_pool);
+ sink->video_buffer_size = 0;
+ }
+
+ pool = gst_vaapi_video_buffer_pool_new(sink->display);
+ if (!pool)
+ goto error_create_pool;
+
+ gst_video_info_init(&vi);
+ gst_video_info_from_caps(&vi, caps);
+ if (GST_VIDEO_INFO_FORMAT(&vi) == GST_VIDEO_FORMAT_ENCODED) {
+ GST_DEBUG("assume video buffer pool format is NV12");
+ gst_video_info_set_format(&vi, GST_VIDEO_FORMAT_NV12,
+ GST_VIDEO_INFO_WIDTH(&vi), GST_VIDEO_INFO_HEIGHT(&vi));
+ }
+ sink->video_buffer_size = vi.size;
+
+ config = gst_buffer_pool_get_config(pool);
+ gst_buffer_pool_config_set_params(config, caps, sink->video_buffer_size,
+ 0, 0);
+ gst_buffer_pool_config_add_option(config,
+ GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META);
+ if (!gst_buffer_pool_set_config(pool, config))
+ goto error_pool_config;
+ sink->video_buffer_pool = pool;
+ return TRUE;
+
+ /* ERRORS */
+error_create_pool:
+ {
+ GST_ERROR("failed to create buffer pool");
return FALSE;
+ }
+error_pool_config:
+ {
+ GST_ERROR("failed to reset buffer pool config");
+ gst_object_unref(pool);
+ return FALSE;
+ }
+#else
return TRUE;
+#endif
+}
+
+static gboolean
+gst_vaapisink_start(GstBaseSink *base_sink)
+{
+ GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
+
+ return gst_vaapisink_ensure_uploader(sink);
}
static gboolean
GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
gst_buffer_replace(&sink->video_buffer, NULL);
- g_clear_object(&sink->window);
- g_clear_object(&sink->display);
+#if GST_CHECK_VERSION(1,0,0)
+ g_clear_object(&sink->video_buffer_pool);
+#endif
+ gst_vaapi_window_replace(&sink->window, NULL);
+ gst_vaapi_display_replace(&sink->display, NULL);
g_clear_object(&sink->uploader);
return TRUE;
}
static GstCaps *
-gst_vaapisink_get_caps(GstBaseSink *base_sink)
+gst_vaapisink_get_caps_impl(GstBaseSink *base_sink)
{
GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
GstCaps *out_caps, *yuv_caps;
return out_caps;
}
+#if GST_CHECK_VERSION(1,0,0)
+static inline GstCaps *
+gst_vaapisink_get_caps(GstBaseSink *base_sink, GstCaps *filter)
+{
+ GstCaps *caps, *out_caps;
+
+ caps = gst_vaapisink_get_caps_impl(base_sink);
+ if (caps && filter) {
+ out_caps = gst_caps_intersect_full(caps, filter,
+ GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref(caps);
+ }
+ else
+ out_caps = caps;
+ return out_caps;
+}
+#else
+#define gst_vaapisink_get_caps gst_vaapisink_get_caps_impl
+#endif
+
static gboolean
gst_vaapisink_set_caps(GstBaseSink *base_sink, GstCaps *caps)
{
GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
- GstStructure * const structure = gst_caps_get_structure(caps, 0);
+ GstVideoInfo vi;
guint win_width, win_height;
- gint video_width, video_height, video_par_n = 1, video_par_d = 1;
#if USE_DRM
if (sink->display_type == GST_VAAPI_DISPLAY_TYPE_DRM)
return TRUE;
#endif
- if (!structure)
- return FALSE;
- if (!gst_structure_get_int(structure, "width", &video_width))
- return FALSE;
- if (!gst_structure_get_int(structure, "height", &video_height))
+ if (!gst_vaapisink_ensure_video_buffer_pool(sink, caps))
return FALSE;
- sink->video_width = video_width;
- sink->video_height = video_height;
- if (gst_structure_has_name(structure, "video/x-raw-yuv"))
- sink->use_video_raw = TRUE;
-
- gst_video_parse_caps_pixel_aspect_ratio(caps, &video_par_n, &video_par_d);
- sink->video_par_n = video_par_n;
- sink->video_par_d = video_par_d;
- GST_DEBUG("video pixel-aspect-ratio %d/%d", video_par_n, video_par_d);
+ if (!gst_video_info_from_caps(&vi, caps))
+ return FALSE;
+ sink->use_video_raw = GST_VIDEO_INFO_IS_YUV(&vi);
+ sink->video_width = GST_VIDEO_INFO_WIDTH(&vi);
+ sink->video_height = GST_VIDEO_INFO_HEIGHT(&vi);
+ sink->video_par_n = GST_VIDEO_INFO_PAR_N(&vi);
+ sink->video_par_d = GST_VIDEO_INFO_PAR_D(&vi);
+ GST_DEBUG("video pixel-aspect-ratio %d/%d",
+ sink->video_par_n, sink->video_par_d);
gst_caps_replace(&sink->caps, caps);
}
else {
gst_vaapi_display_lock(sink->display);
- gst_x_overlay_prepare_xwindow_id(GST_X_OVERLAY(sink));
+ gst_video_overlay_prepare_window_handle(GST_VIDEO_OVERLAY(sink));
gst_vaapi_display_unlock(sink->display);
if (sink->window)
return TRUE;
}
static void
-render_frame(GstVaapiSink *sink)
+render_frame(GstVaapiSink *sink, GstVaapiSurface *surface,
+ const GstVaapiRectangle *surface_rect)
{
const guint x1 = sink->display_rect.x;
const guint x2 = sink->display_rect.x + sink->display_rect.width;
const guint y1 = sink->display_rect.y;
const guint y2 = sink->display_rect.y + sink->display_rect.height;
+ gfloat tx1, tx2, ty1, ty2;
+ guint width, height;
+
+ if (surface_rect) {
+ gst_vaapi_surface_get_size(surface, &width, &height);
+ tx1 = (gfloat)surface_rect->x / width;
+ ty1 = (gfloat)surface_rect->y / height;
+ tx2 = (gfloat)(surface_rect->x + surface_rect->width) / width;
+ ty2 = (gfloat)(surface_rect->y + surface_rect->height) / height;
+ }
+ else {
+ tx1 = 0.0f;
+ ty1 = 0.0f;
+ tx2 = 1.0f;
+ ty2 = 1.0f;
+ }
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
{
- glTexCoord2f(0.0f, 0.0f); glVertex2i(x1, y1);
- glTexCoord2f(0.0f, 1.0f); glVertex2i(x1, y2);
- glTexCoord2f(1.0f, 1.0f); glVertex2i(x2, y2);
- glTexCoord2f(1.0f, 0.0f); glVertex2i(x2, y1);
+ glTexCoord2f(tx1, ty1); glVertex2i(x1, y1);
+ glTexCoord2f(tx1, ty2); glVertex2i(x1, y2);
+ glTexCoord2f(tx2, ty2); glVertex2i(x2, y2);
+ glTexCoord2f(tx2, ty1); glVertex2i(x2, y1);
}
glEnd();
}
}
static gboolean
+gst_vaapisink_ensure_texture(GstVaapiSink *sink, GstVaapiSurface *surface)
+{
+ GstVideoRectangle tex_rect, dis_rect, out_rect;
+ guint width, height;
+
+ if (sink->texture)
+ return TRUE;
+
+ gst_vaapi_surface_get_size(surface, &width, &height);
+ tex_rect.x = 0;
+ tex_rect.y = 0;
+ tex_rect.w = width;
+ tex_rect.h = height;
+
+ gst_vaapi_display_get_size(sink->display, &width, &height);
+ dis_rect.x = 0;
+ dis_rect.y = 0;
+ dis_rect.w = width;
+ dis_rect.h = height;
+
+ gst_video_sink_center_rect(tex_rect, dis_rect, &out_rect, TRUE);
+
+ /* XXX: use surface size for now since some VA drivers have issues
+ with downscaling to the provided texture size. i.e. we should be
+ using the resulting out_rect size, which preserves the aspect
+ ratio of the surface */
+ width = tex_rect.w;
+ height = tex_rect.h;
+ GST_INFO("texture size %ux%u", width, height);
+
+ sink->texture = gst_vaapi_texture_new(sink->display,
+ GL_TEXTURE_2D, GL_BGRA, width, height);
+ return sink->texture != NULL;
+}
+
+static gboolean
gst_vaapisink_show_frame_glx(
- GstVaapiSink *sink,
- GstVaapiSurface *surface,
- guint flags
+ GstVaapiSink *sink,
+ GstVaapiSurface *surface,
+ const GstVaapiRectangle *surface_rect,
+ guint flags
)
{
GstVaapiWindowGLX * const window = GST_VAAPI_WINDOW_GLX(sink->window);
GLuint texture;
gst_vaapi_window_glx_make_current(window);
- if (!sink->texture) {
- sink->texture = gst_vaapi_texture_new(
- sink->display,
- GL_TEXTURE_2D,
- GL_BGRA,
- sink->video_width,
- sink->video_height
- );
- if (!sink->texture)
- goto error_create_texture;
- }
+ if (!gst_vaapisink_ensure_texture(sink, surface))
+ goto error_create_texture;
if (!gst_vaapi_texture_put_surface(sink->texture, surface, flags))
goto error_transfer_surface;
glRotatef(20.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(50.0f, 0.0f, 0.0f);
}
- render_frame(sink);
+ render_frame(sink, surface, surface_rect);
if (sink->use_reflection) {
glPushMatrix();
glTranslatef(0.0, (GLfloat)sink->display_rect.height + 5.0f, 0.0f);
static inline gboolean
gst_vaapisink_put_surface(
- GstVaapiSink *sink,
- GstVaapiSurface *surface,
- guint flags
+ GstVaapiSink *sink,
+ GstVaapiSurface *surface,
+ const GstVaapiRectangle *surface_rect,
+ guint flags
)
{
if (!gst_vaapi_window_put_surface(sink->window, surface,
- NULL, &sink->display_rect, flags)) {
+ surface_rect, &sink->display_rect, flags)) {
GST_DEBUG("could not render VA surface");
return FALSE;
}
gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *src_buffer)
{
GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
- GstVideoOverlayComposition *composition;
- GstVaapiVideoBuffer *vbuffer;
+ GstVaapiVideoMeta *meta;
GstVaapiSurface *surface;
GstBuffer *buffer;
guint flags;
gboolean success;
+ GstVaapiRectangle *surface_rect = NULL;
+#if GST_CHECK_VERSION(1,0,0)
+ GstVaapiRectangle tmp_rect;
+#endif
- if (GST_VAAPI_IS_VIDEO_BUFFER(src_buffer))
+ meta = gst_buffer_get_vaapi_video_meta(src_buffer);
+#if GST_CHECK_VERSION(1,0,0)
+ if (!meta)
+ return GST_FLOW_EOS;
+ buffer = gst_buffer_ref(src_buffer);
+
+ GstVideoCropMeta * const crop_meta =
+ gst_buffer_get_video_crop_meta(buffer);
+ if (crop_meta) {
+ surface_rect = &tmp_rect;
+ surface_rect->x = crop_meta->x;
+ surface_rect->y = crop_meta->y;
+ surface_rect->width = crop_meta->width;
+ surface_rect->height = crop_meta->height;
+ }
+#else
+ if (meta)
buffer = gst_buffer_ref(src_buffer);
- else if (GST_VAAPI_IS_VIDEO_BUFFER(src_buffer->parent))
- buffer = gst_buffer_ref(src_buffer->parent);
- else if (sink->use_video_raw)
+ else if (sink->use_video_raw) {
buffer = gst_vaapi_uploader_get_buffer(sink->uploader);
+ if (!buffer)
+ return GST_FLOW_EOS;
+ meta = gst_buffer_get_vaapi_video_meta(buffer);
+ if (!meta)
+ goto error;
+ }
else
- buffer = NULL;
- if (!buffer)
- return GST_FLOW_UNEXPECTED;
+ return GST_FLOW_EOS;
- if (sink->use_video_raw && !gst_vaapi_uploader_process(sink->uploader,
- src_buffer, buffer))
+ if (sink->use_video_raw &&
+ !gst_vaapi_uploader_process(sink->uploader, src_buffer, buffer)) {
+ GST_WARNING("failed to process raw YUV buffer");
goto error;
-
- vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
- g_return_val_if_fail(vbuffer != NULL, GST_FLOW_UNEXPECTED);
-
- if (sink->display != gst_vaapi_video_buffer_get_display (vbuffer)) {
- g_clear_object(&sink->display);
- sink->display = g_object_ref (gst_vaapi_video_buffer_get_display (vbuffer));
}
+#endif
+
+ if (sink->display != gst_vaapi_video_meta_get_display(meta))
+ gst_vaapi_display_replace(&sink->display,
+ gst_vaapi_video_meta_get_display(meta));
if (!sink->window)
goto error;
gst_vaapisink_ensure_rotation(sink, TRUE);
- surface = gst_vaapi_video_buffer_get_surface(vbuffer);
+ surface = gst_vaapi_video_meta_get_surface(meta);
if (!surface)
goto error;
GST_DEBUG("render surface %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
- flags = gst_vaapi_video_buffer_get_render_flags(vbuffer);
+ if (!surface_rect)
+ surface_rect = (GstVaapiRectangle *)
+ gst_vaapi_video_meta_get_render_rect(meta);
- composition = gst_video_buffer_get_overlay_composition(src_buffer);
- if (!gst_vaapi_surface_set_subpictures_from_composition(surface,
- composition, TRUE))
+ if (surface_rect)
+ GST_DEBUG("render rect (%d,%d), size %ux%u",
+ surface_rect->x, surface_rect->y,
+ surface_rect->width, surface_rect->height);
+
+ flags = gst_vaapi_video_meta_get_render_flags(meta);
+
+ if (!gst_vaapi_apply_composition(surface, src_buffer))
GST_WARNING("could not update subtitles");
switch (sink->display_type) {
-#if USE_GLX
- case GST_VAAPI_DISPLAY_TYPE_GLX:
- success = gst_vaapisink_show_frame_glx(sink, surface, flags);
- break;
-#endif
#if USE_DRM
case GST_VAAPI_DISPLAY_TYPE_DRM:
success = TRUE;
break;
#endif
+#if USE_GLX
+ case GST_VAAPI_DISPLAY_TYPE_GLX:
+ if (!sink->use_glx)
+ goto put_surface_x11;
+ success = gst_vaapisink_show_frame_glx(sink, surface, surface_rect,
+ flags);
+ break;
+#endif
#if USE_X11
case GST_VAAPI_DISPLAY_TYPE_X11:
- success = gst_vaapisink_put_surface(sink, surface, flags);
+ put_surface_x11:
+ success = gst_vaapisink_put_surface(sink, surface, surface_rect, flags);
break;
#endif
#if USE_WAYLAND
case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
- success = gst_vaapisink_put_surface(sink, surface, flags);
+ success = gst_vaapisink_put_surface(sink, surface, surface_rect, flags);
break;
#endif
default:
error:
gst_buffer_unref(buffer);
- return GST_FLOW_UNEXPECTED;
+ return GST_FLOW_EOS;
}
+#if GST_CHECK_VERSION(1,0,0)
+static gboolean
+gst_vaapisink_propose_allocation(GstBaseSink *base_sink, GstQuery *query)
+{
+ GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
+ GstCaps *caps = NULL;
+ gboolean need_pool;
+
+ gst_query_parse_allocation(query, &caps, &need_pool);
+
+ if (need_pool) {
+ if (!caps)
+ goto error_no_caps;
+ if (!gst_vaapisink_ensure_video_buffer_pool(sink, caps))
+ return FALSE;
+ gst_query_add_allocation_pool(query, sink->video_buffer_pool,
+ sink->video_buffer_size, 0, 0);
+ }
+
+ gst_query_add_allocation_meta(query,
+ GST_VAAPI_VIDEO_META_API_TYPE, NULL);
+ gst_query_add_allocation_meta(query,
+ GST_VIDEO_META_API_TYPE, NULL);
+ gst_query_add_allocation_meta(query,
+ GST_VIDEO_CROP_META_API_TYPE, NULL);
+ gst_query_add_allocation_meta(query,
+ GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, NULL);
+ return TRUE;
+
+ /* ERRORS */
+error_no_caps:
+ {
+ GST_ERROR("no caps specified");
+ return FALSE;
+ }
+}
+#else
static GstFlowReturn
gst_vaapisink_buffer_alloc(
GstBaseSink *base_sink,
)
{
GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
- GstStructure *structure;
+ GstVideoInfo vi;
GstBuffer *buf;
*pbuf = NULL;
- structure = gst_caps_get_structure(caps, 0);
- if (!gst_structure_has_name(structure, "video/x-raw-yuv"))
- return GST_FLOW_OK;
+ if (!sink->use_video_raw) {
+ /* Note: this code path is rarely used but for raw YUV formats
+ from custom pipeline. Otherwise, GstBaseSink::set_caps() is
+ called first, and GstBaseSink::buffer_alloc() is not called
+ in VA surface format mode */
+ if (!gst_video_info_from_caps(&vi, caps))
+ return GST_FLOW_NOT_SUPPORTED;
+ if (!GST_VIDEO_INFO_IS_YUV(&vi))
+ return GST_FLOW_OK;
+ }
if (!gst_vaapi_uploader_ensure_display(sink->uploader, sink->display))
return GST_FLOW_NOT_SUPPORTED;
*pbuf = buf;
return GST_FLOW_OK;
}
+#endif
static gboolean
gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query)
{
- GstVaapiSink *sink = GST_VAAPISINK(base_sink);
- GST_DEBUG ("sharing display %p", sink->display);
- return gst_vaapi_reply_to_query (query, sink->display);
+ GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
+
+ if (gst_vaapi_reply_to_query(query, sink->display)) {
+ GST_DEBUG("sharing display %p", sink->display);
+ return TRUE;
+ }
+ return GST_BASE_SINK_CLASS(gst_vaapisink_parent_class)->query(base_sink,
+ query);
}
static void
case PROP_SYNCHRONOUS:
sink->synchronous = g_value_get_boolean(value);
break;
+ case PROP_USE_GLX:
+ sink->use_glx = g_value_get_boolean(value);
+ break;
case PROP_USE_REFLECTION:
sink->use_reflection = g_value_get_boolean(value);
break;
case PROP_ROTATION:
sink->rotation_req = g_value_get_enum(value);
break;
+ case PROP_FORCE_ASPECT_RATIO:
+ sink->keep_aspect = g_value_get_boolean(value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
case PROP_SYNCHRONOUS:
g_value_set_boolean(value, sink->synchronous);
break;
+ case PROP_USE_GLX:
+ g_value_set_boolean(value, sink->use_glx);
+ break;
case PROP_USE_REFLECTION:
g_value_set_boolean(value, sink->use_reflection);
break;
case PROP_ROTATION:
g_value_set_enum(value, sink->rotation);
break;
+ case PROP_FORCE_ASPECT_RATIO:
+ g_value_set_boolean(value, sink->keep_aspect);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
basesink_class->preroll = gst_vaapisink_show_frame;
basesink_class->render = gst_vaapisink_show_frame;
basesink_class->query = gst_vaapisink_query;
+#if GST_CHECK_VERSION(1,0,0)
+ basesink_class->propose_allocation = gst_vaapisink_propose_allocation;
+#else
basesink_class->buffer_alloc = gst_vaapisink_buffer_alloc;
+#endif
- gst_element_class_set_details_simple(
- element_class,
- gst_vaapisink_details.longname,
- gst_vaapisink_details.klass,
- gst_vaapisink_details.description,
- gst_vaapisink_details.author
- );
+ gst_element_class_set_static_metadata(element_class,
+ "VA-API sink",
+ "Sink/Video",
+ GST_PLUGIN_DESC,
+ "Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
pad_template = gst_static_pad_template_get(&gst_vaapisink_sink_factory);
gst_element_class_add_pad_template(element_class, pad_template);
- gst_object_unref(pad_template);
g_object_class_install_property
(object_class,
#if USE_GLX
g_object_class_install_property
(object_class,
+ PROP_USE_GLX,
+ g_param_spec_boolean("use-glx",
+ "OpenGL rendering",
+ "Enables OpenGL rendering",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property
+ (object_class,
PROP_USE_REFLECTION,
g_param_spec_boolean("use-reflection",
"Reflection effect",
GST_VAAPI_TYPE_ROTATION,
DEFAULT_ROTATION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GstVaapiSink:force-aspect-ratio:
+ *
+ * When enabled, scaling respects video aspect ratio; when disabled, the
+ * video is distorted to fit the window.
+ */
+ g_object_class_install_property
+ (object_class,
+ PROP_FORCE_ASPECT_RATIO,
+ g_param_spec_boolean("force-aspect-ratio",
+ "Force aspect ratio",
+ "When enabled, scaling will respect original aspect ratio",
+ TRUE,
+ G_PARAM_READWRITE));
}
static void
sink->use_reflection = FALSE;
sink->use_overlay = FALSE;
sink->use_rotation = FALSE;
+ sink->keep_aspect = TRUE;
}