plugins: re-indent all GstVaapiVideo* related source code.

This commit is contained in:
Gwenole Beauchesne 2014-08-21 10:45:31 +02:00
parent 97d7f21575
commit 038d56bdca
16 changed files with 1561 additions and 1572 deletions

View file

@ -38,37 +38,40 @@
#if GST_CHECK_VERSION(1,1,0)
static inline GstBuffer *
gst_surface_buffer_new(void)
gst_surface_buffer_new (void)
{
return gst_buffer_new();
return gst_buffer_new ();
}
#elif GST_CHECK_VERSION(1,0,0)
#include <gst/video/gstsurfacemeta.h>
#define GST_VAAPI_SURFACE_META_CAST(obj) \
((GstVaapiSurfaceMeta *)(obj))
((GstVaapiSurfaceMeta *) (obj))
typedef struct _GstVaapiSurfaceMeta GstVaapiSurfaceMeta;
struct _GstVaapiSurfaceMeta {
struct _GstVaapiSurfaceMeta
{
GstSurfaceMeta base;
GstBuffer *buffer;
};
#define GST_VAAPI_SURFACE_META_INFO gst_vaapi_surface_meta_get_info()
static const GstMetaInfo *
gst_vaapi_surface_meta_get_info(void);
#define GST_VAAPI_SURFACE_META_INFO \
gst_vaapi_surface_meta_get_info ()
typedef GstSurfaceConverter *(*GstSurfaceConverterCreateFunc)(
GstSurfaceMeta *meta, const gchar *type, GValue *dest);
static const GstMetaInfo *
gst_vaapi_surface_meta_get_info (void);
typedef GstSurfaceConverter *(*GstSurfaceConverterCreateFunc) (GstSurfaceMeta *
meta, const gchar * type, GValue * dest);
#if USE_X11
static GstSurfaceConverter *
gst_vaapi_surface_create_converter_x11(GstSurfaceMeta *base_meta,
const gchar *type, GValue *dest)
gst_vaapi_surface_create_converter_x11 (GstSurfaceMeta * base_meta,
const gchar * type, GValue * dest)
{
GstVaapiSurfaceMeta * const meta = GST_VAAPI_SURFACE_META_CAST(base_meta);
GstVaapiSurfaceMeta *const meta = GST_VAAPI_SURFACE_META_CAST (base_meta);
return gst_vaapi_video_converter_x11_new(meta->buffer, type, dest);
return gst_vaapi_video_converter_x11_new (meta->buffer, type, dest);
}
#undef gst_vaapi_video_converter_x11_new
@ -78,12 +81,12 @@ gst_vaapi_surface_create_converter_x11(GstSurfaceMeta *base_meta,
#if USE_GLX
static GstSurfaceConverter *
gst_vaapi_surface_create_converter_glx(GstSurfaceMeta *base_meta,
const gchar *type, GValue *dest)
gst_vaapi_surface_create_converter_glx (GstSurfaceMeta * base_meta,
const gchar * type, GValue * dest)
{
GstVaapiSurfaceMeta * const meta = GST_VAAPI_SURFACE_META_CAST(base_meta);
GstVaapiSurfaceMeta *const meta = GST_VAAPI_SURFACE_META_CAST (base_meta);
return gst_vaapi_video_converter_glx_new(meta->buffer, type, dest);
return gst_vaapi_video_converter_glx_new (meta->buffer, type, dest);
}
#undef gst_vaapi_video_converter_glx_new
@ -92,26 +95,26 @@ gst_vaapi_surface_create_converter_glx(GstSurfaceMeta *base_meta,
#endif
static GstSurfaceConverter *
gst_vaapi_surface_create_converter(GstSurfaceMeta *base_meta,
const gchar *type, GValue *dest)
gst_vaapi_surface_create_converter (GstSurfaceMeta * base_meta,
const gchar * type, GValue * dest)
{
GstVaapiSurfaceMeta * const meta = GST_VAAPI_SURFACE_META_CAST(base_meta);
GstVaapiVideoMeta * const vmeta =
gst_buffer_get_vaapi_video_meta(meta->buffer);
GstVaapiSurfaceMeta *const meta = GST_VAAPI_SURFACE_META_CAST (base_meta);
GstVaapiVideoMeta *const vmeta =
gst_buffer_get_vaapi_video_meta (meta->buffer);
GstSurfaceConverterCreateFunc func;
if (G_UNLIKELY(!vmeta))
if (G_UNLIKELY (!vmeta))
return NULL;
func = (GstSurfaceConverterCreateFunc)
gst_vaapi_video_meta_get_surface_converter(vmeta);
gst_vaapi_video_meta_get_surface_converter (vmeta);
return func ? func(base_meta, type, dest) : NULL;
return func ? func (base_meta, type, dest) : NULL;
}
static gboolean
gst_vaapi_surface_meta_init(GstVaapiSurfaceMeta *meta, gpointer params,
GstBuffer *buffer)
gst_vaapi_surface_meta_init (GstVaapiSurfaceMeta * meta, gpointer params,
GstBuffer * buffer)
{
meta->base.create_converter = gst_vaapi_surface_create_converter;
meta->buffer = buffer;
@ -119,81 +122,74 @@ gst_vaapi_surface_meta_init(GstVaapiSurfaceMeta *meta, gpointer params,
}
static void
gst_vaapi_surface_meta_free(GstVaapiSurfaceMeta *meta, GstBuffer *buffer)
gst_vaapi_surface_meta_free (GstVaapiSurfaceMeta * meta, GstBuffer * buffer)
{
}
static gboolean
gst_vaapi_surface_meta_transform(GstBuffer *dst_buffer, GstMeta *meta,
GstBuffer *src_buffer, GQuark type, gpointer data)
gst_vaapi_surface_meta_transform (GstBuffer * dst_buffer, GstMeta * meta,
GstBuffer * src_buffer, GQuark type, gpointer data)
{
GstVaapiVideoMeta * const src_vmeta =
gst_buffer_get_vaapi_video_meta(src_buffer);
GstVaapiVideoMeta *const src_vmeta =
gst_buffer_get_vaapi_video_meta (src_buffer);
if (GST_META_TRANSFORM_IS_COPY(type)) {
GstVaapiSurfaceMeta * const dst_smeta = GST_VAAPI_SURFACE_META_CAST(
gst_buffer_add_meta(dst_buffer, GST_VAAPI_SURFACE_META_INFO, NULL));
if (GST_META_TRANSFORM_IS_COPY (type)) {
GstVaapiSurfaceMeta *const dst_smeta =
GST_VAAPI_SURFACE_META_CAST (gst_buffer_add_meta (dst_buffer,
GST_VAAPI_SURFACE_META_INFO, NULL));
/* Note: avoid meta lookups in gst_vaapi_surface_create_converter()
by directly calling the GstVaapiVideoMeta::surface_converter hook */
dst_smeta->base.create_converter = (GstSurfaceConverterCreateFunc)
gst_vaapi_video_meta_get_surface_converter(src_vmeta);
gst_vaapi_video_meta_get_surface_converter (src_vmeta);
return TRUE;
}
return FALSE;
}
const GstMetaInfo *
gst_vaapi_surface_meta_get_info(void)
gst_vaapi_surface_meta_get_info (void)
{
static gsize g_meta_info;
if (g_once_init_enter(&g_meta_info)) {
gsize meta_info = GPOINTER_TO_SIZE(gst_meta_register(
GST_SURFACE_META_API_TYPE,
"GstVaapiSurfaceMeta", sizeof(GstVaapiSurfaceMeta),
(GstMetaInitFunction)gst_vaapi_surface_meta_init,
(GstMetaFreeFunction)gst_vaapi_surface_meta_free,
(GstMetaTransformFunction)gst_vaapi_surface_meta_transform));
g_once_init_leave(&g_meta_info, meta_info);
if (g_once_init_enter (&g_meta_info)) {
gsize meta_info =
GPOINTER_TO_SIZE (gst_meta_register (GST_SURFACE_META_API_TYPE,
"GstVaapiSurfaceMeta", sizeof (GstVaapiSurfaceMeta),
(GstMetaInitFunction) gst_vaapi_surface_meta_init,
(GstMetaFreeFunction) gst_vaapi_surface_meta_free,
(GstMetaTransformFunction) gst_vaapi_surface_meta_transform));
g_once_init_leave (&g_meta_info, meta_info);
}
return GSIZE_TO_POINTER(g_meta_info);
return GSIZE_TO_POINTER (g_meta_info);
}
static GstBuffer *
gst_surface_buffer_new(void)
gst_surface_buffer_new (void)
{
GstBuffer * const buffer = gst_buffer_new();
GstBuffer *const buffer = gst_buffer_new ();
if (buffer)
gst_buffer_add_meta(buffer, GST_VAAPI_SURFACE_META_INFO, NULL);
gst_buffer_add_meta (buffer, GST_VAAPI_SURFACE_META_INFO, NULL);
return buffer;
}
#else
#include <gst/video/gstsurfacebuffer.h>
#define GST_VAAPI_TYPE_VIDEO_BUFFER \
(gst_vaapi_video_buffer_get_type())
(gst_vaapi_video_buffer_get_type ())
#define GST_VAAPI_VIDEO_BUFFER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBuffer))
#define GST_VAAPI_VIDEO_BUFFER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBufferClass))
#define GST_VAAPI_IS_VIDEO_BUFFER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_BUFFER))
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER))
#define GST_VAAPI_IS_VIDEO_BUFFER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_BUFFER))
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_VIDEO_BUFFER))
#define GST_VAAPI_VIDEO_BUFFER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER, \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER, \
GstVaapiVideoBufferClass))
typedef struct _GstVaapiVideoBufferClass GstVaapiVideoBufferClass;
@ -203,7 +199,8 @@ typedef struct _GstVaapiVideoBufferClass GstVaapiVideoBufferClass;
*
* A #GstBuffer holding video objects (#GstVaapiSurface and #GstVaapiImage).
*/
struct _GstVaapiVideoBuffer {
struct _GstVaapiVideoBuffer
{
/*< private >*/
GstSurfaceBuffer parent_instance;
};
@ -213,72 +210,72 @@ struct _GstVaapiVideoBuffer {
*
* A #GstBuffer holding video objects
*/
struct _GstVaapiVideoBufferClass {
struct _GstVaapiVideoBufferClass
{
/*< private >*/
GstSurfaceBufferClass parent_class;
};
GType
gst_vaapi_video_buffer_get_type(void) G_GNUC_CONST;
gst_vaapi_video_buffer_get_type (void) G_GNUC_CONST;
G_DEFINE_TYPE(GstVaapiVideoBuffer,
gst_vaapi_video_buffer,
GST_TYPE_SURFACE_BUFFER)
G_DEFINE_TYPE (GstVaapiVideoBuffer,
gst_vaapi_video_buffer, GST_TYPE_SURFACE_BUFFER);
typedef GstSurfaceConverter *(*GstSurfaceConverterCreateFunc)(
GstSurfaceBuffer *surface, const gchar *type, GValue *dest);
typedef GstSurfaceConverter *
(*GstSurfaceConverterCreateFunc) (GstSurfaceBuffer * surface,
const gchar * type, GValue * dest);
static GstSurfaceConverter *
gst_vaapi_video_buffer_create_converter(GstSurfaceBuffer *surface,
const gchar *type, GValue *dest)
gst_vaapi_video_buffer_create_converter (GstSurfaceBuffer * surface,
const gchar * type, GValue * dest)
{
GstVaapiVideoMeta * const meta =
gst_buffer_get_vaapi_video_meta(GST_BUFFER(surface));
GstVaapiVideoMeta *const meta =
gst_buffer_get_vaapi_video_meta (GST_BUFFER (surface));
GstSurfaceConverterCreateFunc func;
g_return_val_if_fail(meta != NULL, NULL);
g_return_val_if_fail (meta != NULL, NULL);
func = (GstSurfaceConverterCreateFunc)
gst_vaapi_video_meta_get_surface_converter(meta);
gst_vaapi_video_meta_get_surface_converter (meta);
return func ? func(surface, type, dest) : NULL;
return func ? func (surface, type, dest) : NULL;
}
static void
gst_vaapi_video_buffer_class_init(GstVaapiVideoBufferClass *klass)
gst_vaapi_video_buffer_class_init (GstVaapiVideoBufferClass * klass)
{
GstSurfaceBufferClass * const surface_class =
GST_SURFACE_BUFFER_CLASS(klass);
GstSurfaceBufferClass *const surface_class = GST_SURFACE_BUFFER_CLASS (klass);
surface_class->create_converter = gst_vaapi_video_buffer_create_converter;
}
static void
gst_vaapi_video_buffer_init(GstVaapiVideoBuffer *buffer)
gst_vaapi_video_buffer_init (GstVaapiVideoBuffer * buffer)
{
}
static inline GstBuffer *
gst_surface_buffer_new(void)
gst_surface_buffer_new (void)
{
return GST_BUFFER_CAST(gst_mini_object_new(GST_VAAPI_TYPE_VIDEO_BUFFER));
return GST_BUFFER_CAST (gst_mini_object_new (GST_VAAPI_TYPE_VIDEO_BUFFER));
}
#endif
static GFunc
get_surface_converter(GstVaapiDisplay *display)
get_surface_converter (GstVaapiDisplay * display)
{
GFunc func;
switch (gst_vaapi_display_get_display_type(display)) {
switch (gst_vaapi_display_get_display_type (display)) {
#if USE_X11 && !GST_CHECK_VERSION(1,1,0)
case GST_VAAPI_DISPLAY_TYPE_X11:
func = (GFunc)gst_vaapi_video_converter_x11_new;
func = (GFunc) gst_vaapi_video_converter_x11_new;
break;
#endif
#if USE_GLX && !GST_CHECK_VERSION(1,1,0)
case GST_VAAPI_DISPLAY_TYPE_GLX:
func = (GFunc)gst_vaapi_video_converter_glx_new;
func = (GFunc) gst_vaapi_video_converter_glx_new;
break;
#endif
default:
@ -289,58 +286,58 @@ get_surface_converter(GstVaapiDisplay *display)
}
static GstBuffer *
new_vbuffer(GstVaapiVideoMeta *meta)
new_vbuffer (GstVaapiVideoMeta * meta)
{
GstBuffer *buffer;
g_return_val_if_fail(meta != NULL, NULL);
g_return_val_if_fail (meta != NULL, NULL);
gst_vaapi_video_meta_set_surface_converter(meta,
get_surface_converter(gst_vaapi_video_meta_get_display(meta)));
gst_vaapi_video_meta_set_surface_converter (meta,
get_surface_converter (gst_vaapi_video_meta_get_display (meta)));
buffer = gst_surface_buffer_new();
buffer = gst_surface_buffer_new ();
if (buffer)
gst_buffer_set_vaapi_video_meta(buffer, meta);
gst_vaapi_video_meta_unref(meta);
gst_buffer_set_vaapi_video_meta (buffer, meta);
gst_vaapi_video_meta_unref (meta);
return buffer;
}
GstBuffer *
gst_vaapi_video_buffer_new(GstVaapiVideoMeta *meta)
gst_vaapi_video_buffer_new (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(meta != NULL, NULL);
g_return_val_if_fail (meta != NULL, NULL);
return new_vbuffer(gst_vaapi_video_meta_ref(meta));
return new_vbuffer (gst_vaapi_video_meta_ref (meta));
}
GstBuffer *
gst_vaapi_video_buffer_new_empty(void)
gst_vaapi_video_buffer_new_empty (void)
{
return gst_surface_buffer_new();
return gst_surface_buffer_new ();
}
GstBuffer *
gst_vaapi_video_buffer_new_from_pool(GstVaapiVideoPool *pool)
gst_vaapi_video_buffer_new_from_pool (GstVaapiVideoPool * pool)
{
return new_vbuffer(gst_vaapi_video_meta_new_from_pool(pool));
return new_vbuffer (gst_vaapi_video_meta_new_from_pool (pool));
}
GstBuffer *
gst_vaapi_video_buffer_new_from_buffer(GstBuffer *buffer)
gst_vaapi_video_buffer_new_from_buffer (GstBuffer * buffer)
{
GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
GstVaapiVideoMeta *const meta = gst_buffer_get_vaapi_video_meta (buffer);
return meta ? new_vbuffer(gst_vaapi_video_meta_ref(meta)) : NULL;
return meta ? new_vbuffer (gst_vaapi_video_meta_ref (meta)) : NULL;
}
GstBuffer *
gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image)
gst_vaapi_video_buffer_new_with_image (GstVaapiImage * image)
{
return new_vbuffer(gst_vaapi_video_meta_new_with_image(image));
return new_vbuffer (gst_vaapi_video_meta_new_with_image (image));
}
GstBuffer *
gst_vaapi_video_buffer_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy)
gst_vaapi_video_buffer_new_with_surface_proxy (GstVaapiSurfaceProxy * proxy)
{
return new_vbuffer(gst_vaapi_video_meta_new_with_surface_proxy(proxy));
return new_vbuffer (gst_vaapi_video_meta_new_with_surface_proxy (proxy));
}

View file

@ -33,27 +33,27 @@ typedef struct _GstVaapiVideoBuffer GstVaapiVideoBuffer;
G_GNUC_INTERNAL
GstBuffer *
gst_vaapi_video_buffer_new(GstVaapiVideoMeta *meta);
gst_vaapi_video_buffer_new (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
GstBuffer *
gst_vaapi_video_buffer_new_empty(void);
gst_vaapi_video_buffer_new_empty (void);
G_GNUC_INTERNAL
GstBuffer *
gst_vaapi_video_buffer_new_from_pool(GstVaapiVideoPool *pool);
gst_vaapi_video_buffer_new_from_pool (GstVaapiVideoPool * pool);
G_GNUC_INTERNAL
GstBuffer *
gst_vaapi_video_buffer_new_from_buffer(GstBuffer *buffer);
gst_vaapi_video_buffer_new_from_buffer (GstBuffer * buffer);
G_GNUC_INTERNAL
GstBuffer *
gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image);
gst_vaapi_video_buffer_new_with_image (GstVaapiImage * image);
G_GNUC_INTERNAL
GstBuffer *
gst_vaapi_video_buffer_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy);
gst_vaapi_video_buffer_new_with_surface_proxy (GstVaapiSurfaceProxy * proxy);
G_END_DECLS

View file

@ -28,95 +28,95 @@
#include "gstvaapivideometa_texture.h"
#endif
GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideopool);
GST_DEBUG_CATEGORY_STATIC (gst_debug_vaapivideopool);
#define GST_CAT_DEFAULT gst_debug_vaapivideopool
G_DEFINE_TYPE(GstVaapiVideoBufferPool,
gst_vaapi_video_buffer_pool,
GST_TYPE_BUFFER_POOL)
G_DEFINE_TYPE (GstVaapiVideoBufferPool,
gst_vaapi_video_buffer_pool, GST_TYPE_BUFFER_POOL);
enum {
enum
{
PROP_0,
PROP_DISPLAY,
};
struct _GstVaapiVideoBufferPoolPrivate {
struct _GstVaapiVideoBufferPoolPrivate
{
GstVideoInfo video_info[2];
guint video_info_index;
GstAllocator *allocator;
GstVaapiDisplay *display;
guint has_video_meta : 1;
guint has_video_alignment : 1;
guint has_texture_upload_meta : 1;
guint has_video_meta:1;
guint has_video_alignment:1;
guint has_texture_upload_meta:1;
};
#define GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
GstVaapiVideoBufferPoolPrivate))
static void
gst_vaapi_video_buffer_pool_finalize(GObject *object)
gst_vaapi_video_buffer_pool_finalize (GObject * object)
{
GstVaapiVideoBufferPoolPrivate * const priv =
GST_VAAPI_VIDEO_BUFFER_POOL(object)->priv;
GstVaapiVideoBufferPoolPrivate *const priv =
GST_VAAPI_VIDEO_BUFFER_POOL (object)->priv;
G_OBJECT_CLASS(gst_vaapi_video_buffer_pool_parent_class)->finalize(object);
G_OBJECT_CLASS (gst_vaapi_video_buffer_pool_parent_class)->finalize (object);
gst_vaapi_display_replace(&priv->display, NULL);
g_clear_object(&priv->allocator);
gst_vaapi_display_replace (&priv->display, NULL);
g_clear_object (&priv->allocator);
}
static void
gst_vaapi_video_buffer_pool_set_property(GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
gst_vaapi_video_buffer_pool_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstVaapiVideoBufferPoolPrivate * const priv =
GST_VAAPI_VIDEO_BUFFER_POOL(object)->priv;
GstVaapiVideoBufferPoolPrivate *const priv =
GST_VAAPI_VIDEO_BUFFER_POOL (object)->priv;
switch (prop_id) {
case PROP_DISPLAY:
priv->display = gst_vaapi_display_ref(g_value_get_pointer(value));
priv->display = gst_vaapi_display_ref (g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_vaapi_video_buffer_pool_get_property(GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
gst_vaapi_video_buffer_pool_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstVaapiVideoBufferPoolPrivate * const priv =
GST_VAAPI_VIDEO_BUFFER_POOL(object)->priv;
GstVaapiVideoBufferPoolPrivate *const priv =
GST_VAAPI_VIDEO_BUFFER_POOL (object)->priv;
switch (prop_id) {
case PROP_DISPLAY:
g_value_set_pointer(value, priv->display);
g_value_set_pointer (value, priv->display);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
fill_video_alignment(GstVaapiVideoBufferPool *pool, GstVideoAlignment *align)
fill_video_alignment (GstVaapiVideoBufferPool * pool, GstVideoAlignment * align)
{
GstVideoInfo * const vip =
&GST_VAAPI_VIDEO_ALLOCATOR_CAST(pool->priv->allocator)->image_info;
GstVideoInfo *const vip =
&GST_VAAPI_VIDEO_ALLOCATOR_CAST (pool->priv->allocator)->image_info;
guint i;
gst_video_alignment_reset(align);
for (i = 0; i < GST_VIDEO_INFO_N_PLANES(vip); i++)
gst_video_alignment_reset (align);
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (vip); i++)
align->stride_align[i] =
(1U << g_bit_nth_lsf(GST_VIDEO_INFO_PLANE_STRIDE(vip, i), 0)) - 1;
(1U << g_bit_nth_lsf (GST_VIDEO_INFO_PLANE_STRIDE (vip, i), 0)) - 1;
}
static const gchar **
gst_vaapi_video_buffer_pool_get_options(GstBufferPool *pool)
gst_vaapi_video_buffer_pool_get_options (GstBufferPool * pool)
{
static const gchar *g_options[] = {
GST_BUFFER_POOL_OPTION_VIDEO_META,
@ -125,91 +125,93 @@ gst_vaapi_video_buffer_pool_get_options(GstBufferPool *pool)
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT,
NULL,
};
return g_options;
}
static gboolean
gst_vaapi_video_buffer_pool_set_config(GstBufferPool *pool,
GstStructure *config)
gst_vaapi_video_buffer_pool_set_config (GstBufferPool * pool,
GstStructure * config)
{
GstVaapiVideoBufferPoolPrivate * const priv =
GST_VAAPI_VIDEO_BUFFER_POOL(pool)->priv;
GstVaapiVideoBufferPoolPrivate *const priv =
GST_VAAPI_VIDEO_BUFFER_POOL (pool)->priv;
GstCaps *caps = NULL;
GstVideoInfo * const cur_vip = &priv->video_info[priv->video_info_index];
GstVideoInfo * const new_vip = &priv->video_info[!priv->video_info_index];
GstVideoInfo *const cur_vip = &priv->video_info[priv->video_info_index];
GstVideoInfo *const new_vip = &priv->video_info[!priv->video_info_index];
GstVideoAlignment align;
GstAllocator *allocator;
gboolean changed_caps;
if (!gst_buffer_pool_config_get_params(config, &caps, NULL, NULL, NULL))
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, NULL, NULL))
goto error_invalid_config;
if (!caps || !gst_video_info_from_caps(new_vip, caps))
if (!caps || !gst_video_info_from_caps (new_vip, caps))
goto error_no_caps;
changed_caps = !priv->allocator ||
GST_VIDEO_INFO_FORMAT(cur_vip) != GST_VIDEO_INFO_FORMAT(new_vip) ||
GST_VIDEO_INFO_WIDTH(cur_vip) != GST_VIDEO_INFO_WIDTH(new_vip) ||
GST_VIDEO_INFO_HEIGHT(cur_vip) != GST_VIDEO_INFO_HEIGHT(new_vip);
GST_VIDEO_INFO_FORMAT (cur_vip) != GST_VIDEO_INFO_FORMAT (new_vip) ||
GST_VIDEO_INFO_WIDTH (cur_vip) != GST_VIDEO_INFO_WIDTH (new_vip) ||
GST_VIDEO_INFO_HEIGHT (cur_vip) != GST_VIDEO_INFO_HEIGHT (new_vip);
if (changed_caps) {
allocator = gst_vaapi_video_allocator_new(priv->display, new_vip);
allocator = gst_vaapi_video_allocator_new (priv->display, new_vip);
if (!allocator)
goto error_create_allocator;
gst_object_replace((GstObject **)&priv->allocator,
GST_OBJECT_CAST(allocator));
gst_object_unref(allocator);
gst_object_replace ((GstObject **) & priv->allocator,
GST_OBJECT_CAST (allocator));
gst_object_unref (allocator);
priv->video_info_index ^= 1;
}
if (!gst_buffer_pool_config_has_option(config,
if (!gst_buffer_pool_config_has_option (config,
GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META))
goto error_no_vaapi_video_meta_option;
priv->has_video_meta = gst_buffer_pool_config_has_option(config,
priv->has_video_meta = gst_buffer_pool_config_has_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_META);
priv->has_video_alignment = gst_buffer_pool_config_has_option(config,
priv->has_video_alignment = gst_buffer_pool_config_has_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
if (priv->has_video_alignment) {
fill_video_alignment(GST_VAAPI_VIDEO_BUFFER_POOL(pool), &align);
gst_buffer_pool_config_set_video_alignment(config, &align);
fill_video_alignment (GST_VAAPI_VIDEO_BUFFER_POOL (pool), &align);
gst_buffer_pool_config_set_video_alignment (config, &align);
}
priv->has_texture_upload_meta = gst_buffer_pool_config_has_option(config,
priv->has_texture_upload_meta = gst_buffer_pool_config_has_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META);
return GST_BUFFER_POOL_CLASS(gst_vaapi_video_buffer_pool_parent_class)->
set_config(pool, config);
return
GST_BUFFER_POOL_CLASS
(gst_vaapi_video_buffer_pool_parent_class)->set_config (pool, config);
/* ERRORS */
error_invalid_config:
{
GST_ERROR("invalid config");
GST_ERROR ("invalid config");
return FALSE;
}
error_no_caps:
{
GST_ERROR("no valid caps in config");
GST_ERROR ("no valid caps in config");
return FALSE;
}
error_create_allocator:
{
GST_ERROR("failed to create GstVaapiVideoAllocator object");
GST_ERROR ("failed to create GstVaapiVideoAllocator object");
return FALSE;
}
error_no_vaapi_video_meta_option:
{
GST_ERROR("no GstVaapiVideoMeta option");
GST_ERROR ("no GstVaapiVideoMeta option");
return FALSE;
}
}
static GstFlowReturn
gst_vaapi_video_buffer_pool_alloc_buffer(GstBufferPool *pool,
GstBuffer **out_buffer_ptr, GstBufferPoolAcquireParams *params)
gst_vaapi_video_buffer_pool_alloc_buffer (GstBufferPool * pool,
GstBuffer ** out_buffer_ptr, GstBufferPoolAcquireParams * params)
{
GstVaapiVideoBufferPoolPrivate * const priv =
GST_VAAPI_VIDEO_BUFFER_POOL(pool)->priv;
GstVaapiVideoBufferPoolPrivate *const priv =
GST_VAAPI_VIDEO_BUFFER_POOL (pool)->priv;
GstVaapiVideoMeta *meta;
GstMemory *mem;
GstBuffer *buffer;
@ -217,37 +219,36 @@ gst_vaapi_video_buffer_pool_alloc_buffer(GstBufferPool *pool,
if (!priv->allocator)
goto error_no_allocator;
meta = gst_vaapi_video_meta_new(priv->display);
meta = gst_vaapi_video_meta_new (priv->display);
if (!meta)
goto error_create_meta;
buffer = gst_vaapi_video_buffer_new(meta);
buffer = gst_vaapi_video_buffer_new (meta);
if (!buffer)
goto error_create_buffer;
mem = gst_vaapi_video_memory_new(priv->allocator, meta);
mem = gst_vaapi_video_memory_new (priv->allocator, meta);
if (!mem)
goto error_create_memory;
gst_vaapi_video_meta_unref(meta);
gst_buffer_append_memory(buffer, mem);
gst_vaapi_video_meta_unref (meta);
gst_buffer_append_memory (buffer, mem);
if (priv->has_video_meta) {
GstVideoInfo * const vip =
&GST_VAAPI_VIDEO_ALLOCATOR_CAST(priv->allocator)->image_info;
GstVideoInfo *const vip =
&GST_VAAPI_VIDEO_ALLOCATOR_CAST (priv->allocator)->image_info;
GstVideoMeta *vmeta;
vmeta = gst_buffer_add_video_meta_full(buffer, 0,
GST_VIDEO_INFO_FORMAT(vip), GST_VIDEO_INFO_WIDTH(vip),
GST_VIDEO_INFO_HEIGHT(vip), GST_VIDEO_INFO_N_PLANES(vip),
&GST_VIDEO_INFO_PLANE_OFFSET(vip, 0),
&GST_VIDEO_INFO_PLANE_STRIDE(vip, 0));
vmeta = gst_buffer_add_video_meta_full (buffer, 0,
GST_VIDEO_INFO_FORMAT (vip), GST_VIDEO_INFO_WIDTH (vip),
GST_VIDEO_INFO_HEIGHT (vip), GST_VIDEO_INFO_N_PLANES (vip),
&GST_VIDEO_INFO_PLANE_OFFSET (vip, 0),
&GST_VIDEO_INFO_PLANE_STRIDE (vip, 0));
vmeta->map = gst_video_meta_map_vaapi_memory;
vmeta->unmap = gst_video_meta_unmap_vaapi_memory;
}
#if GST_CHECK_VERSION(1,1,0) && USE_GLX
if (priv->has_texture_upload_meta)
gst_buffer_add_texture_upload_meta(buffer);
gst_buffer_add_texture_upload_meta (buffer);
#endif
*out_buffer_ptr = buffer;
@ -256,51 +257,52 @@ gst_vaapi_video_buffer_pool_alloc_buffer(GstBufferPool *pool,
/* ERRORS */
error_no_allocator:
{
GST_ERROR("no GstAllocator in buffer pool");
GST_ERROR ("no GstAllocator in buffer pool");
return GST_FLOW_ERROR;
}
error_create_meta:
{
GST_ERROR("failed to allocate vaapi video meta");
GST_ERROR ("failed to allocate vaapi video meta");
return GST_FLOW_ERROR;
}
error_create_buffer:
{
GST_ERROR("failed to create video buffer");
gst_vaapi_video_meta_unref(meta);
GST_ERROR ("failed to create video buffer");
gst_vaapi_video_meta_unref (meta);
return GST_FLOW_ERROR;
}
error_create_memory:
{
GST_ERROR("failed to create video memory");
gst_buffer_unref(buffer);
gst_vaapi_video_meta_unref(meta);
GST_ERROR ("failed to create video memory");
gst_buffer_unref (buffer);
gst_vaapi_video_meta_unref (meta);
return GST_FLOW_ERROR;
}
}
static void
gst_vaapi_video_buffer_pool_reset_buffer(GstBufferPool *pool, GstBuffer *buffer)
gst_vaapi_video_buffer_pool_reset_buffer (GstBufferPool * pool,
GstBuffer * buffer)
{
GstMemory * const mem = gst_buffer_peek_memory(buffer, 0);
GstMemory *const mem = gst_buffer_peek_memory (buffer, 0);
/* Release the underlying surface proxy */
gst_vaapi_video_memory_reset_surface(GST_VAAPI_VIDEO_MEMORY_CAST(mem));
gst_vaapi_video_memory_reset_surface (GST_VAAPI_VIDEO_MEMORY_CAST (mem));
GST_BUFFER_POOL_CLASS(gst_vaapi_video_buffer_pool_parent_class)->
reset_buffer(pool, buffer);
GST_BUFFER_POOL_CLASS (gst_vaapi_video_buffer_pool_parent_class)->reset_buffer
(pool, buffer);
}
static void
gst_vaapi_video_buffer_pool_class_init(GstVaapiVideoBufferPoolClass *klass)
gst_vaapi_video_buffer_pool_class_init (GstVaapiVideoBufferPoolClass * klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
GstBufferPoolClass * const pool_class = GST_BUFFER_POOL_CLASS(klass);
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
GstBufferPoolClass *const pool_class = GST_BUFFER_POOL_CLASS (klass);
GST_DEBUG_CATEGORY_INIT(gst_debug_vaapivideopool,
GST_DEBUG_CATEGORY_INIT (gst_debug_vaapivideopool,
"vaapivideopool", 0, "VA-API video pool");
g_type_class_add_private(klass, sizeof(GstVaapiVideoBufferPoolPrivate));
g_type_class_add_private (klass, sizeof (GstVaapiVideoBufferPoolPrivate));
object_class->finalize = gst_vaapi_video_buffer_pool_finalize;
object_class->set_property = gst_vaapi_video_buffer_pool_set_property;
@ -318,27 +320,27 @@ gst_vaapi_video_buffer_pool_class_init(GstVaapiVideoBufferPoolClass *klass)
g_object_class_install_property
(object_class,
PROP_DISPLAY,
g_param_spec_pointer("display",
g_param_spec_pointer ("display",
"Display",
"The GstVaapiDisplay to use for this video pool",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
gst_vaapi_video_buffer_pool_init(GstVaapiVideoBufferPool *pool)
gst_vaapi_video_buffer_pool_init (GstVaapiVideoBufferPool * pool)
{
GstVaapiVideoBufferPoolPrivate * const priv =
GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(pool);
GstVaapiVideoBufferPoolPrivate *const priv =
GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE (pool);
pool->priv = priv;
gst_video_info_init(&priv->video_info[0]);
gst_video_info_init(&priv->video_info[1]);
gst_video_info_init (&priv->video_info[0]);
gst_video_info_init (&priv->video_info[1]);
}
GstBufferPool *
gst_vaapi_video_buffer_pool_new(GstVaapiDisplay *display)
gst_vaapi_video_buffer_pool_new (GstVaapiDisplay * display)
{
return g_object_new(GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,
return g_object_new (GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,
"display", display, NULL);
}

View file

@ -29,23 +29,17 @@
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_VIDEO_BUFFER_POOL \
(gst_vaapi_video_buffer_pool_get_type())
(gst_vaapi_video_buffer_pool_get_type ())
#define GST_VAAPI_VIDEO_BUFFER_POOL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
GstVaapiVideoBufferPool))
#define GST_VAAPI_VIDEO_BUFFER_POOL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
GstVaapiVideoBufferPoolClass))
#define GST_VAAPI_IS_VIDEO_BUFFER_POOL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL))
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL))
#define GST_VAAPI_IS_VIDEO_BUFFER_POOL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL))
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL))
typedef struct _GstVaapiVideoBufferPool GstVaapiVideoBufferPool;
typedef struct _GstVaapiVideoBufferPoolClass GstVaapiVideoBufferPoolClass;
@ -57,7 +51,8 @@ typedef struct _GstVaapiVideoBufferPoolPrivate GstVaapiVideoBufferPoolPrivate;
* An option that can be activated on bufferpool to request vaapi
* video metadata on buffers from the pool.
*/
#define GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META "GstBufferPoolOptionVaapiVideoMeta"
#define GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META \
"GstBufferPoolOptionVaapiVideoMeta"
/**
*
@ -79,7 +74,8 @@ typedef struct _GstVaapiVideoBufferPoolPrivate GstVaapiVideoBufferPoolPrivate;
*
* A VA video buffer pool object.
*/
struct _GstVaapiVideoBufferPool {
struct _GstVaapiVideoBufferPool
{
GstBufferPool parent_instance;
/*< private >*/
@ -91,17 +87,18 @@ struct _GstVaapiVideoBufferPool {
*
* A VA video buffer pool class.
*/
struct _GstVaapiVideoBufferPoolClass {
struct _GstVaapiVideoBufferPoolClass
{
GstBufferPoolClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_video_buffer_pool_get_type(void) G_GNUC_CONST;
gst_vaapi_video_buffer_pool_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstBufferPool *
gst_vaapi_video_buffer_pool_new(GstVaapiDisplay *display) G_GNUC_CONST;
gst_vaapi_video_buffer_pool_new (GstVaapiDisplay * display) G_GNUC_CONST;
G_END_DECLS

View file

@ -31,18 +31,18 @@
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
#define GST_VAAPI_TYPE_DISPLAY \
gst_vaapi_display_get_type()
gst_vaapi_display_get_type ()
GType
gst_vaapi_display_get_type (void)
G_GNUC_CONST;
gst_vaapi_display_get_type (void) G_GNUC_CONST;
G_DEFINE_BOXED_TYPE (GstVaapiDisplay, gst_vaapi_display,
(GBoxedCopyFunc) gst_vaapi_display_ref,
(GBoxedFreeFunc) gst_vaapi_display_unref)
(GBoxedFreeFunc) gst_vaapi_display_unref);
GstContext *gst_vaapi_video_context_new_with_display (GstVaapiDisplay *
display, gboolean persistent)
GstContext *
gst_vaapi_video_context_new_with_display (GstVaapiDisplay * display,
gboolean persistent)
{
GstContext *context;
GstStructure *structure;

View file

@ -34,8 +34,8 @@
#define GST_VAAPI_DISPLAY_CONTEXT_TYPE_NAME "gst.vaapi.Display"
/* Fake GstVideoContext symbols */
#define GST_VIDEO_CONTEXT(obj) (GST_ELEMENT(obj))
#define GST_IS_VIDEO_CONTEXT(obj) (GST_IS_ELEMENT(obj))
#define GST_VIDEO_CONTEXT(obj) (GST_ELEMENT (obj))
#define GST_IS_VIDEO_CONTEXT(obj) (GST_IS_ELEMENT (obj))
#define GstVideoContext GstElement
#define gst_video_context_prepare gst_vaapi_video_context_prepare

View file

@ -30,65 +30,65 @@
#include "gstvaapivideometa.h"
#if GST_CHECK_VERSION(1,0,0)
typedef gboolean (*GstSurfaceUploadFunction)(GstSurfaceConverter *,
typedef gboolean (*GstSurfaceUploadFunction) (GstSurfaceConverter *,
GstBuffer *);
#else
typedef gboolean (*GstSurfaceUploadFunction)(GstSurfaceConverter *,
typedef gboolean (*GstSurfaceUploadFunction) (GstSurfaceConverter *,
GstSurfaceBuffer *);
#endif
static void
gst_vaapi_video_converter_glx_iface_init(GstSurfaceConverterInterface *iface);
gst_vaapi_video_converter_glx_iface_init (GstSurfaceConverterInterface * iface);
G_DEFINE_TYPE_WITH_CODE(
GstVaapiVideoConverterGLX,
G_DEFINE_TYPE_WITH_CODE (GstVaapiVideoConverterGLX,
gst_vaapi_video_converter_glx,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(GST_TYPE_SURFACE_CONVERTER,
gst_vaapi_video_converter_glx_iface_init))
G_IMPLEMENT_INTERFACE (GST_TYPE_SURFACE_CONVERTER,
gst_vaapi_video_converter_glx_iface_init));
#define GST_VAAPI_VIDEO_CONVERTER_GLX_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
GstVaapiVideoConverterGLXPrivate))
struct _GstVaapiVideoConverterGLXPrivate {
struct _GstVaapiVideoConverterGLXPrivate
{
GstVaapiTexture *texture;
};
static gboolean
gst_vaapi_video_converter_glx_upload(GstSurfaceConverter *self,
GstBuffer *buffer);
gst_vaapi_video_converter_glx_upload (GstSurfaceConverter * self,
GstBuffer * buffer);
static void
gst_vaapi_video_converter_glx_dispose(GObject *object)
gst_vaapi_video_converter_glx_dispose (GObject * object)
{
GstVaapiVideoConverterGLXPrivate * const priv =
GST_VAAPI_VIDEO_CONVERTER_GLX(object)->priv;
GstVaapiVideoConverterGLXPrivate *const priv =
GST_VAAPI_VIDEO_CONVERTER_GLX (object)->priv;
gst_vaapi_texture_replace(&priv->texture, NULL);
gst_vaapi_texture_replace (&priv->texture, NULL);
G_OBJECT_CLASS(gst_vaapi_video_converter_glx_parent_class)->dispose(object);
G_OBJECT_CLASS (gst_vaapi_video_converter_glx_parent_class)->dispose (object);
}
static void
gst_vaapi_video_converter_glx_class_init(GstVaapiVideoConverterGLXClass *klass)
gst_vaapi_video_converter_glx_class_init (GstVaapiVideoConverterGLXClass *
klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private(klass, sizeof(GstVaapiVideoConverterGLXPrivate));
g_type_class_add_private (klass, sizeof (GstVaapiVideoConverterGLXPrivate));
object_class->dispose = gst_vaapi_video_converter_glx_dispose;
}
static void
gst_vaapi_video_converter_glx_init(GstVaapiVideoConverterGLX *buffer)
gst_vaapi_video_converter_glx_init (GstVaapiVideoConverterGLX * buffer)
{
buffer->priv = GST_VAAPI_VIDEO_CONVERTER_GLX_GET_PRIVATE(buffer);
buffer->priv = GST_VAAPI_VIDEO_CONVERTER_GLX_GET_PRIVATE (buffer);
}
static void
gst_vaapi_video_converter_glx_iface_init(GstSurfaceConverterInterface *iface)
gst_vaapi_video_converter_glx_iface_init (GstSurfaceConverterInterface * iface)
{
iface->upload = (GstSurfaceUploadFunction)
gst_vaapi_video_converter_glx_upload;
@ -107,53 +107,53 @@ gst_vaapi_video_converter_glx_iface_init(GstSurfaceConverterInterface *iface)
* Return value: the newly allocated #GstBuffer, or %NULL on error
*/
GstSurfaceConverter *
gst_vaapi_video_converter_glx_new(GstBuffer *buffer, const gchar *type,
GValue *dest)
gst_vaapi_video_converter_glx_new (GstBuffer * buffer, const gchar * type,
GValue * dest)
{
GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
GstVaapiVideoMeta *const meta = gst_buffer_get_vaapi_video_meta (buffer);
GstVaapiTexture *texture;
GstVaapiVideoConverterGLX *converter;
/* Check for "opengl" request, or chain up to X11 converter */
if (strcmp(type, "opengl") != 0 || !G_VALUE_HOLDS_UINT(dest))
return gst_vaapi_video_converter_x11_new(buffer, type, dest);
if (strcmp (type, "opengl") != 0 || !G_VALUE_HOLDS_UINT (dest))
return gst_vaapi_video_converter_x11_new (buffer, type, dest);
/* FIXME Should we assume target and format ? */
texture = gst_vaapi_texture_new_with_texture(
gst_vaapi_video_meta_get_display(meta),
g_value_get_uint(dest), GL_TEXTURE_2D, GL_BGRA);
texture =
gst_vaapi_texture_new_with_texture (gst_vaapi_video_meta_get_display
(meta), g_value_get_uint (dest), GL_TEXTURE_2D, GL_BGRA);
if (!texture)
return NULL;
converter = g_object_new(GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, NULL);
converter = g_object_new (GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, NULL);
converter->priv->texture = texture;
return GST_SURFACE_CONVERTER(converter);
return GST_SURFACE_CONVERTER (converter);
}
gboolean
gst_vaapi_video_converter_glx_upload(GstSurfaceConverter *self,
GstBuffer *buffer)
gst_vaapi_video_converter_glx_upload (GstSurfaceConverter * self,
GstBuffer * buffer)
{
GstVaapiVideoConverterGLXPrivate * const priv =
GST_VAAPI_VIDEO_CONVERTER_GLX(self)->priv;
GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
GstVaapiSurface * const surface = gst_vaapi_video_meta_get_surface(meta);
GstVaapiVideoConverterGLXPrivate *const priv =
GST_VAAPI_VIDEO_CONVERTER_GLX (self)->priv;
GstVaapiVideoMeta *const meta = gst_buffer_get_vaapi_video_meta (buffer);
GstVaapiSurface *const surface = gst_vaapi_video_meta_get_surface (meta);
GstVaapiDisplay *new_dpy, *old_dpy;
new_dpy = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
old_dpy = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(priv->texture));
new_dpy = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (surface));
old_dpy = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (priv->texture));
if (old_dpy != new_dpy) {
const guint texture = gst_vaapi_texture_get_id(priv->texture);
const guint texture = gst_vaapi_texture_get_id (priv->texture);
gst_vaapi_texture_replace(&priv->texture, NULL);
priv->texture = gst_vaapi_texture_new_with_texture(new_dpy,
gst_vaapi_texture_replace (&priv->texture, NULL);
priv->texture = gst_vaapi_texture_new_with_texture (new_dpy,
texture, GL_TEXTURE_2D, GL_BGRA);
}
if (!gst_vaapi_apply_composition(surface, buffer))
GST_WARNING("could not update subtitles");
if (!gst_vaapi_apply_composition (surface, buffer))
GST_WARNING ("could not update subtitles");
return gst_vaapi_texture_put_surface(priv->texture, surface,
gst_vaapi_video_meta_get_render_flags(meta));
return gst_vaapi_texture_put_surface (priv->texture, surface,
gst_vaapi_video_meta_get_render_flags (meta));
}

View file

@ -32,30 +32,23 @@ G_BEGIN_DECLS
#define GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX \
(gst_vaapi_video_converter_glx_get_type ())
#define GST_VAAPI_VIDEO_CONVERTER_GLX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
GstVaapiVideoConverterGLX))
#define GST_VAAPI_VIDEO_CONVERTER_GLX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
GstVaapiVideoConverterGLXClass))
#define GST_VAAPI_IS_VIDEO_CONVERTER_GLX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX))
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX))
#define GST_VAAPI_IS_VIDEO_CONVERTER_GLX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX))
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX))
#define GST_VAAPI_VIDEO_CONVERTER_GLX_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \
GstVaapiVideoConverterGLXClass))
typedef struct _GstVaapiVideoConverterGLX GstVaapiVideoConverterGLX;
typedef struct _GstVaapiVideoConverterGLXPrivate GstVaapiVideoConverterGLXPrivate;
typedef struct _GstVaapiVideoConverterGLXPrivate
GstVaapiVideoConverterGLXPrivate;
typedef struct _GstVaapiVideoConverterGLXClass GstVaapiVideoConverterGLXClass;
/**
@ -63,7 +56,8 @@ typedef struct _GstVaapiVideoConverterGLXClass GstVaapiVideoConverterGLXClass;
*
* Converter to transform VA buffers into GL textures.
*/
struct _GstVaapiVideoConverterGLX {
struct _GstVaapiVideoConverterGLX
{
/*< private >*/
GObject parent_instance;
@ -75,19 +69,20 @@ struct _GstVaapiVideoConverterGLX {
*
* Converter class to transform VA buffers into GL textures.
*/
struct _GstVaapiVideoConverterGLXClass {
struct _GstVaapiVideoConverterGLXClass
{
/*< private >*/
GObjectClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_video_converter_glx_get_type(void) G_GNUC_CONST;
gst_vaapi_video_converter_glx_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstSurfaceConverter *
gst_vaapi_video_converter_glx_new(GstBuffer *buffer, const gchar *type,
GValue *dest);
gst_vaapi_video_converter_glx_new (GstBuffer * buffer, const gchar * type,
GValue * dest);
G_END_DECLS

View file

@ -27,84 +27,84 @@
#include "gstvaapivideometa.h"
#if GST_CHECK_VERSION(1,0,0)
typedef gboolean (*GstSurfaceUploadFunction)(GstSurfaceConverter *,
typedef gboolean (*GstSurfaceUploadFunction) (GstSurfaceConverter *,
GstBuffer *);
#else
typedef gboolean (*GstSurfaceUploadFunction)(GstSurfaceConverter *,
typedef gboolean (*GstSurfaceUploadFunction) (GstSurfaceConverter *,
GstSurfaceBuffer *);
#endif
static void
gst_vaapi_video_converter_x11_iface_init(GstSurfaceConverterInterface *iface);
gst_vaapi_video_converter_x11_iface_init (GstSurfaceConverterInterface * iface);
G_DEFINE_TYPE_WITH_CODE(
GstVaapiVideoConverterX11,
G_DEFINE_TYPE_WITH_CODE (GstVaapiVideoConverterX11,
gst_vaapi_video_converter_x11,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(GST_TYPE_SURFACE_CONVERTER,
gst_vaapi_video_converter_x11_iface_init))
G_IMPLEMENT_INTERFACE (GST_TYPE_SURFACE_CONVERTER,
gst_vaapi_video_converter_x11_iface_init));
#define GST_VAAPI_VIDEO_CONVERTER_X11_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
GstVaapiVideoConverterX11Private))
struct _GstVaapiVideoConverterX11Private {
struct _GstVaapiVideoConverterX11Private
{
GstVaapiPixmap *pixmap;
XID pixmap_id;
};
static gboolean
gst_vaapi_video_converter_x11_upload(GstSurfaceConverter *self,
GstBuffer *buffer);
gst_vaapi_video_converter_x11_upload (GstSurfaceConverter * self,
GstBuffer * buffer);
static void
gst_vaapi_video_converter_x11_dispose(GObject *object)
gst_vaapi_video_converter_x11_dispose (GObject * object)
{
GstVaapiVideoConverterX11Private * const priv =
GST_VAAPI_VIDEO_CONVERTER_X11(object)->priv;
GstVaapiVideoConverterX11Private *const priv =
GST_VAAPI_VIDEO_CONVERTER_X11 (object)->priv;
gst_vaapi_pixmap_replace(&priv->pixmap, NULL);
gst_vaapi_pixmap_replace (&priv->pixmap, NULL);
G_OBJECT_CLASS(gst_vaapi_video_converter_x11_parent_class)->dispose(object);
G_OBJECT_CLASS (gst_vaapi_video_converter_x11_parent_class)->dispose (object);
}
static void
gst_vaapi_video_converter_x11_class_init(GstVaapiVideoConverterX11Class *klass)
gst_vaapi_video_converter_x11_class_init (GstVaapiVideoConverterX11Class *
klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private(klass, sizeof(GstVaapiVideoConverterX11Private));
g_type_class_add_private (klass, sizeof (GstVaapiVideoConverterX11Private));
object_class->dispose = gst_vaapi_video_converter_x11_dispose;
}
static void
gst_vaapi_video_converter_x11_init(GstVaapiVideoConverterX11 *buffer)
gst_vaapi_video_converter_x11_init (GstVaapiVideoConverterX11 * buffer)
{
buffer->priv = GST_VAAPI_VIDEO_CONVERTER_X11_GET_PRIVATE(buffer);
buffer->priv = GST_VAAPI_VIDEO_CONVERTER_X11_GET_PRIVATE (buffer);
}
static void
gst_vaapi_video_converter_x11_iface_init(GstSurfaceConverterInterface *iface)
gst_vaapi_video_converter_x11_iface_init (GstSurfaceConverterInterface * iface)
{
iface->upload = (GstSurfaceUploadFunction)
gst_vaapi_video_converter_x11_upload;
}
static gboolean
set_pixmap(GstVaapiVideoConverterX11 *converter, GstVaapiDisplay *display,
set_pixmap (GstVaapiVideoConverterX11 * converter, GstVaapiDisplay * display,
XID pixmap_id)
{
GstVaapiVideoConverterX11Private * const priv = converter->priv;
GstVaapiVideoConverterX11Private *const priv = converter->priv;
GstVaapiPixmap *pixmap;
pixmap = gst_vaapi_pixmap_x11_new_with_xid(display, pixmap_id);
pixmap = gst_vaapi_pixmap_x11_new_with_xid (display, pixmap_id);
if (!pixmap)
return FALSE;
gst_vaapi_pixmap_replace(&priv->pixmap, pixmap);
gst_vaapi_pixmap_unref(pixmap);
gst_vaapi_pixmap_replace (&priv->pixmap, pixmap);
gst_vaapi_pixmap_unref (pixmap);
priv->pixmap_id = pixmap_id;
return TRUE;
}
@ -122,61 +122,61 @@ set_pixmap(GstVaapiVideoConverterX11 *converter, GstVaapiDisplay *display,
* Return value: the newly allocated #GstBuffer, or %NULL on error
*/
GstSurfaceConverter *
gst_vaapi_video_converter_x11_new(GstBuffer *buffer, const gchar *type,
GValue *dest)
gst_vaapi_video_converter_x11_new (GstBuffer * buffer, const gchar * type,
GValue * dest)
{
GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
GstVaapiVideoMeta *const meta = gst_buffer_get_vaapi_video_meta (buffer);
GstVaapiVideoConverterX11 *converter;
/* We only support X11 pixmap conversion */
if (strcmp(type, "x11-pixmap") != 0 || !G_VALUE_HOLDS_UINT(dest))
if (strcmp (type, "x11-pixmap") != 0 || !G_VALUE_HOLDS_UINT (dest))
return NULL;
converter = g_object_new(GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, NULL);
converter = g_object_new (GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, NULL);
if (!converter)
return NULL;
if (!set_pixmap(converter, gst_vaapi_video_meta_get_display(meta),
g_value_get_uint(dest)))
if (!set_pixmap (converter, gst_vaapi_video_meta_get_display (meta),
g_value_get_uint (dest)))
goto error;
return GST_SURFACE_CONVERTER(converter);
return GST_SURFACE_CONVERTER (converter);
error:
g_object_unref(converter);
g_object_unref (converter);
return NULL;
}
gboolean
gst_vaapi_video_converter_x11_upload(GstSurfaceConverter *self,
GstBuffer *buffer)
gst_vaapi_video_converter_x11_upload (GstSurfaceConverter * self,
GstBuffer * buffer)
{
GstVaapiVideoConverterX11 * const converter =
GST_VAAPI_VIDEO_CONVERTER_X11(self);
GstVaapiVideoConverterX11Private * const priv = converter->priv;
GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
GstVaapiVideoConverterX11 *const converter =
GST_VAAPI_VIDEO_CONVERTER_X11 (self);
GstVaapiVideoConverterX11Private *const priv = converter->priv;
GstVaapiVideoMeta *const meta = gst_buffer_get_vaapi_video_meta (buffer);
const GstVaapiRectangle *crop_rect = NULL;
GstVaapiSurface *surface;
GstVaapiDisplay *old_display, *new_display;
g_return_val_if_fail(meta != NULL, FALSE);
g_return_val_if_fail (meta != NULL, FALSE);
surface = gst_vaapi_video_meta_get_surface(meta);
surface = gst_vaapi_video_meta_get_surface (meta);
if (!surface)
return FALSE;
old_display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(priv->pixmap));
new_display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
old_display = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (priv->pixmap));
new_display = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (surface));
if (old_display != new_display) {
if (!set_pixmap(converter, new_display, priv->pixmap_id))
if (!set_pixmap (converter, new_display, priv->pixmap_id))
return FALSE;
}
if (!gst_vaapi_apply_composition(surface, buffer))
GST_WARNING("could not update subtitles");
if (!gst_vaapi_apply_composition (surface, buffer))
GST_WARNING ("could not update subtitles");
#if GST_CHECK_VERSION(1,0,0)
GstVideoCropMeta * const crop_meta = gst_buffer_get_video_crop_meta(buffer);
GstVideoCropMeta *const crop_meta = gst_buffer_get_video_crop_meta (buffer);
if (crop_meta) {
GstVaapiRectangle crop_rect_tmp;
crop_rect = &crop_rect_tmp;
@ -187,8 +187,8 @@ gst_vaapi_video_converter_x11_upload(GstSurfaceConverter *self,
}
#endif
if (!crop_rect)
crop_rect = gst_vaapi_video_meta_get_render_rect(meta);
crop_rect = gst_vaapi_video_meta_get_render_rect (meta);
return gst_vaapi_pixmap_put_surface(priv->pixmap, surface, crop_rect,
gst_vaapi_video_meta_get_render_flags(meta));
return gst_vaapi_pixmap_put_surface (priv->pixmap, surface, crop_rect,
gst_vaapi_video_meta_get_render_flags (meta));
}

View file

@ -30,30 +30,23 @@ G_BEGIN_DECLS
#define GST_VAAPI_TYPE_VIDEO_CONVERTER_X11 \
(gst_vaapi_video_converter_x11_get_type ())
#define GST_VAAPI_VIDEO_CONVERTER_X11(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
GstVaapiVideoConverterX11))
#define GST_VAAPI_VIDEO_CONVERTER_X11_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
GstVaapiVideoConverterX11Class))
#define GST_VAAPI_IS_VIDEO_CONVERTER_X11(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11))
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11))
#define GST_VAAPI_IS_VIDEO_CONVERTER_X11_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11))
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11))
#define GST_VAAPI_VIDEO_CONVERTER_X11_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_X11, \
GstVaapiVideoConverterX11Class))
typedef struct _GstVaapiVideoConverterX11 GstVaapiVideoConverterX11;
typedef struct _GstVaapiVideoConverterX11Private GstVaapiVideoConverterX11Private;
typedef struct _GstVaapiVideoConverterX11Private
GstVaapiVideoConverterX11Private;
typedef struct _GstVaapiVideoConverterX11Class GstVaapiVideoConverterX11Class;
/**
@ -61,7 +54,8 @@ typedef struct _GstVaapiVideoConverterX11Class GstVaapiVideoConverterX11Class;
*
* Converter to transform VA buffers into GL textures.
*/
struct _GstVaapiVideoConverterX11 {
struct _GstVaapiVideoConverterX11
{
/*< private >*/
GObject parent_instance;
@ -73,19 +67,20 @@ struct _GstVaapiVideoConverterX11 {
*
* Converter class to transform VA buffers into GL textures.
*/
struct _GstVaapiVideoConverterX11Class {
struct _GstVaapiVideoConverterX11Class
{
/*< private >*/
GObjectClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_video_converter_x11_get_type(void) G_GNUC_CONST;
gst_vaapi_video_converter_x11_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstSurfaceConverter *
gst_vaapi_video_converter_x11_new(GstBuffer *buffer, const gchar *type,
GValue *dest);
gst_vaapi_video_converter_x11_new (GstBuffer * buffer, const gchar * type,
GValue * dest);
G_END_DECLS

View file

@ -25,12 +25,12 @@
#include <gst/vaapi/gstvaapiimagepool.h>
#include "gstvaapivideomemory.h"
GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideomemory);
GST_DEBUG_CATEGORY_STATIC (gst_debug_vaapivideomemory);
#define GST_CAT_DEFAULT gst_debug_vaapivideomemory
#ifndef GST_VIDEO_INFO_FORMAT_STRING
#define GST_VIDEO_INFO_FORMAT_STRING(vip) \
gst_video_format_to_string(GST_VIDEO_INFO_FORMAT(vip))
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (vip))
#endif
/* Defined if native VA surface formats are preferred over direct rendering */
@ -41,16 +41,16 @@ GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideomemory);
/* ------------------------------------------------------------------------ */
static void
gst_vaapi_video_memory_reset_image(GstVaapiVideoMemory *mem);
gst_vaapi_video_memory_reset_image (GstVaapiVideoMemory * mem);
static guchar *
get_image_data(GstVaapiImage *image)
get_image_data (GstVaapiImage * image)
{
guchar *data;
VAImage va_image;
data = gst_vaapi_image_get_plane(image, 0);
if (!data || !gst_vaapi_image_get_image(image, &va_image))
data = gst_vaapi_image_get_plane (image, 0);
if (!data || !gst_vaapi_image_get_image (image, &va_image))
return NULL;
data -= va_image.offsets[0];
@ -58,114 +58,113 @@ get_image_data(GstVaapiImage *image)
}
static GstVaapiImage *
new_image(GstVaapiDisplay *display, const GstVideoInfo *vip)
new_image (GstVaapiDisplay * display, const GstVideoInfo * vip)
{
return gst_vaapi_image_new(display, GST_VIDEO_INFO_FORMAT(vip),
GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
return gst_vaapi_image_new (display, GST_VIDEO_INFO_FORMAT (vip),
GST_VIDEO_INFO_WIDTH (vip), GST_VIDEO_INFO_HEIGHT (vip));
}
static gboolean
ensure_image(GstVaapiVideoMemory *mem)
ensure_image (GstVaapiVideoMemory * mem)
{
if (!mem->image && mem->use_direct_rendering) {
mem->image = gst_vaapi_surface_derive_image(mem->surface);
mem->image = gst_vaapi_surface_derive_image (mem->surface);
if (!mem->image) {
GST_WARNING("failed to derive image, fallbacking to copy");
GST_WARNING ("failed to derive image, fallbacking to copy");
mem->use_direct_rendering = FALSE;
}
else if (gst_vaapi_surface_get_format(mem->surface) !=
GST_VIDEO_INFO_FORMAT(mem->image_info)) {
gst_vaapi_object_replace(&mem->image, NULL);
} else if (gst_vaapi_surface_get_format (mem->surface) !=
GST_VIDEO_INFO_FORMAT (mem->image_info)) {
gst_vaapi_object_replace (&mem->image, NULL);
mem->use_direct_rendering = FALSE;
}
}
if (!mem->image) {
GstVaapiVideoAllocator * const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST(GST_MEMORY_CAST(mem)->allocator);
GstVaapiVideoAllocator *const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST (GST_MEMORY_CAST (mem)->allocator);
mem->image = gst_vaapi_video_pool_get_object(allocator->image_pool);
mem->image = gst_vaapi_video_pool_get_object (allocator->image_pool);
if (!mem->image)
return FALSE;
}
gst_vaapi_video_meta_set_image(mem->meta, mem->image);
gst_vaapi_video_meta_set_image (mem->meta, mem->image);
return TRUE;
}
static GstVaapiSurface *
new_surface(GstVaapiDisplay *display, const GstVideoInfo *vip)
new_surface (GstVaapiDisplay * display, const GstVideoInfo * vip)
{
GstVaapiSurface *surface;
GstVaapiChromaType chroma_type;
/* Try with explicit format first */
if (!USE_NATIVE_FORMATS &&
GST_VIDEO_INFO_FORMAT(vip) != GST_VIDEO_FORMAT_ENCODED) {
surface = gst_vaapi_surface_new_with_format(display,
GST_VIDEO_INFO_FORMAT(vip), GST_VIDEO_INFO_WIDTH(vip),
GST_VIDEO_INFO_HEIGHT(vip));
GST_VIDEO_INFO_FORMAT (vip) != GST_VIDEO_FORMAT_ENCODED) {
surface = gst_vaapi_surface_new_with_format (display,
GST_VIDEO_INFO_FORMAT (vip), GST_VIDEO_INFO_WIDTH (vip),
GST_VIDEO_INFO_HEIGHT (vip));
if (surface)
return surface;
}
/* Try to pick something compatible, i.e. with same chroma type */
chroma_type = gst_vaapi_video_format_get_chroma_type(
GST_VIDEO_INFO_FORMAT(vip));
chroma_type =
gst_vaapi_video_format_get_chroma_type (GST_VIDEO_INFO_FORMAT (vip));
if (!chroma_type)
return NULL;
return gst_vaapi_surface_new(display, chroma_type,
GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
return gst_vaapi_surface_new (display, chroma_type,
GST_VIDEO_INFO_WIDTH (vip), GST_VIDEO_INFO_HEIGHT (vip));
}
static GstVaapiSurfaceProxy *
new_surface_proxy(GstVaapiVideoMemory *mem)
new_surface_proxy (GstVaapiVideoMemory * mem)
{
GstVaapiVideoAllocator * const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST(GST_MEMORY_CAST(mem)->allocator);
GstVaapiVideoAllocator *const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST (GST_MEMORY_CAST (mem)->allocator);
return gst_vaapi_surface_proxy_new_from_pool(
GST_VAAPI_SURFACE_POOL(allocator->surface_pool));
return
gst_vaapi_surface_proxy_new_from_pool (GST_VAAPI_SURFACE_POOL
(allocator->surface_pool));
}
static gboolean
ensure_surface(GstVaapiVideoMemory *mem)
ensure_surface (GstVaapiVideoMemory * mem)
{
if (!mem->proxy) {
gst_vaapi_surface_proxy_replace(&mem->proxy,
gst_vaapi_video_meta_get_surface_proxy(mem->meta));
gst_vaapi_surface_proxy_replace (&mem->proxy,
gst_vaapi_video_meta_get_surface_proxy (mem->meta));
if (!mem->proxy) {
mem->proxy = new_surface_proxy(mem);
mem->proxy = new_surface_proxy (mem);
if (!mem->proxy)
return FALSE;
gst_vaapi_video_meta_set_surface_proxy(mem->meta, mem->proxy);
gst_vaapi_video_meta_set_surface_proxy (mem->meta, mem->proxy);
}
}
mem->surface = GST_VAAPI_SURFACE_PROXY_SURFACE(mem->proxy);
mem->surface = GST_VAAPI_SURFACE_PROXY_SURFACE (mem->proxy);
return mem->surface != NULL;
}
gboolean
gst_video_meta_map_vaapi_memory(GstVideoMeta *meta, guint plane,
GstMapInfo *info, gpointer *data, gint *stride, GstMapFlags flags)
gst_video_meta_map_vaapi_memory (GstVideoMeta * meta, guint plane,
GstMapInfo * info, gpointer * data, gint * stride, GstMapFlags flags)
{
GstVaapiVideoMemory * const mem =
GST_VAAPI_VIDEO_MEMORY_CAST(gst_buffer_peek_memory(meta->buffer, 0));
GstVaapiVideoMemory *const mem =
GST_VAAPI_VIDEO_MEMORY_CAST (gst_buffer_peek_memory (meta->buffer, 0));
g_return_val_if_fail(mem, FALSE);
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_ALLOCATOR(mem->parent_instance.
g_return_val_if_fail (mem, FALSE);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_ALLOCATOR (mem->parent_instance.
allocator), FALSE);
g_return_val_if_fail(mem->meta, FALSE);
g_return_val_if_fail (mem->meta, FALSE);
if (mem->map_type &&
mem->map_type != GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR)
if (mem->map_type && mem->map_type != GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR)
goto error_incompatible_map;
/* Map for writing */
if (++mem->map_count == 1) {
if (!ensure_surface(mem))
if (!ensure_surface (mem))
goto error_ensure_surface;
if (!ensure_image(mem))
if (!ensure_image (mem))
goto error_ensure_image;
// Check that we can actually map the surface, or image
@ -175,77 +174,77 @@ gst_video_meta_map_vaapi_memory(GstVideoMeta *meta, guint plane,
// Load VA image from surface
if ((flags & GST_MAP_READ) && !mem->use_direct_rendering)
gst_vaapi_surface_get_image(mem->surface, mem->image);
gst_vaapi_surface_get_image (mem->surface, mem->image);
if (!gst_vaapi_image_map(mem->image))
if (!gst_vaapi_image_map (mem->image))
goto error_map_image;
mem->map_type = GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR;
}
*data = gst_vaapi_image_get_plane(mem->image, plane);
*stride = gst_vaapi_image_get_pitch(mem->image, plane);
*data = gst_vaapi_image_get_plane (mem->image, plane);
*stride = gst_vaapi_image_get_pitch (mem->image, plane);
info->flags = flags;
return TRUE;
/* ERRORS */
error_incompatible_map:
{
GST_ERROR("incompatible map type (%d)", mem->map_type);
GST_ERROR ("incompatible map type (%d)", mem->map_type);
return FALSE;
}
error_unsupported_map:
{
GST_ERROR("unsupported map flags (0x%x)", flags);
GST_ERROR ("unsupported map flags (0x%x)", flags);
return FALSE;
}
error_ensure_surface:
{
const GstVideoInfo * const vip = mem->surface_info;
GST_ERROR("failed to create %s surface of size %ux%u",
GST_VIDEO_INFO_FORMAT_STRING(vip),
GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
const GstVideoInfo *const vip = mem->surface_info;
GST_ERROR ("failed to create %s surface of size %ux%u",
GST_VIDEO_INFO_FORMAT_STRING (vip),
GST_VIDEO_INFO_WIDTH (vip), GST_VIDEO_INFO_HEIGHT (vip));
return FALSE;
}
error_ensure_image:
{
const GstVideoInfo * const vip = mem->image_info;
GST_ERROR("failed to create %s image of size %ux%u",
GST_VIDEO_INFO_FORMAT_STRING(vip),
GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
const GstVideoInfo *const vip = mem->image_info;
GST_ERROR ("failed to create %s image of size %ux%u",
GST_VIDEO_INFO_FORMAT_STRING (vip),
GST_VIDEO_INFO_WIDTH (vip), GST_VIDEO_INFO_HEIGHT (vip));
return FALSE;
}
error_map_image:
{
GST_ERROR("failed to map image %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(gst_vaapi_image_get_id(mem->image)));
GST_ERROR ("failed to map image %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS (gst_vaapi_image_get_id (mem->image)));
return FALSE;
}
}
gboolean
gst_video_meta_unmap_vaapi_memory(GstVideoMeta *meta, guint plane,
GstMapInfo *info)
gst_video_meta_unmap_vaapi_memory (GstVideoMeta * meta, guint plane,
GstMapInfo * info)
{
GstVaapiVideoMemory * const mem =
GST_VAAPI_VIDEO_MEMORY_CAST(gst_buffer_peek_memory(meta->buffer, 0));
GstVaapiVideoMemory *const mem =
GST_VAAPI_VIDEO_MEMORY_CAST (gst_buffer_peek_memory (meta->buffer, 0));
g_return_val_if_fail(mem, FALSE);
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_ALLOCATOR(mem->parent_instance.
g_return_val_if_fail (mem, FALSE);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_ALLOCATOR (mem->parent_instance.
allocator), FALSE);
g_return_val_if_fail(mem->meta, FALSE);
g_return_val_if_fail(mem->surface, FALSE);
g_return_val_if_fail(mem->image, FALSE);
g_return_val_if_fail (mem->meta, FALSE);
g_return_val_if_fail (mem->surface, FALSE);
g_return_val_if_fail (mem->image, FALSE);
if (--mem->map_count == 0) {
mem->map_type = 0;
/* Unmap VA image used for read/writes */
if (info->flags & GST_MAP_READWRITE)
gst_vaapi_image_unmap(mem->image);
gst_vaapi_image_unmap (mem->image);
/* Commit VA image to surface */
if ((info->flags & GST_MAP_WRITE) && !mem->use_direct_rendering) {
if (!gst_vaapi_surface_put_image(mem->surface, mem->image))
if (!gst_vaapi_surface_put_image (mem->surface, mem->image))
goto error_upload_image;
}
}
@ -254,77 +253,78 @@ gst_video_meta_unmap_vaapi_memory(GstVideoMeta *meta, guint plane,
/* ERRORS */
error_upload_image:
{
GST_ERROR("failed to upload image");
GST_ERROR ("failed to upload image");
return FALSE;
}
}
GstMemory *
gst_vaapi_video_memory_new(GstAllocator *base_allocator,
GstVaapiVideoMeta *meta)
gst_vaapi_video_memory_new (GstAllocator * base_allocator,
GstVaapiVideoMeta * meta)
{
GstVaapiVideoAllocator * const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST(base_allocator);
GstVaapiVideoAllocator *const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST (base_allocator);
const GstVideoInfo *vip;
GstVaapiVideoMemory *mem;
mem = g_slice_new(GstVaapiVideoMemory);
mem = g_slice_new (GstVaapiVideoMemory);
if (!mem)
return NULL;
vip = &allocator->image_info;
gst_memory_init(&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
gst_object_ref(allocator), NULL, GST_VIDEO_INFO_SIZE(vip), 0,
0, GST_VIDEO_INFO_SIZE(vip));
gst_memory_init (&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
gst_object_ref (allocator), NULL, GST_VIDEO_INFO_SIZE (vip), 0,
0, GST_VIDEO_INFO_SIZE (vip));
mem->proxy = NULL;
mem->surface_info = &allocator->surface_info;
mem->surface = NULL;
mem->image_info = &allocator->image_info;
mem->image = NULL;
mem->meta = gst_vaapi_video_meta_ref(meta);
mem->meta = gst_vaapi_video_meta_ref (meta);
mem->map_type = 0;
mem->map_count = 0;
mem->use_direct_rendering = allocator->has_direct_rendering;
return GST_MEMORY_CAST(mem);
return GST_MEMORY_CAST (mem);
}
static void
gst_vaapi_video_memory_free(GstVaapiVideoMemory *mem)
gst_vaapi_video_memory_free (GstVaapiVideoMemory * mem)
{
mem->surface = NULL;
gst_vaapi_video_memory_reset_image(mem);
gst_vaapi_surface_proxy_replace(&mem->proxy, NULL);
gst_vaapi_video_meta_unref(mem->meta);
gst_object_unref(GST_MEMORY_CAST(mem)->allocator);
g_slice_free(GstVaapiVideoMemory, mem);
gst_vaapi_video_memory_reset_image (mem);
gst_vaapi_surface_proxy_replace (&mem->proxy, NULL);
gst_vaapi_video_meta_unref (mem->meta);
gst_object_unref (GST_MEMORY_CAST (mem)->allocator);
g_slice_free (GstVaapiVideoMemory, mem);
}
void
gst_vaapi_video_memory_reset_image(GstVaapiVideoMemory *mem)
gst_vaapi_video_memory_reset_image (GstVaapiVideoMemory * mem)
{
GstVaapiVideoAllocator * const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST(GST_MEMORY_CAST(mem)->allocator);
GstVaapiVideoAllocator *const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST (GST_MEMORY_CAST (mem)->allocator);
if (mem->use_direct_rendering)
gst_vaapi_object_replace(&mem->image, NULL);
gst_vaapi_object_replace (&mem->image, NULL);
else if (mem->image) {
gst_vaapi_video_pool_put_object(allocator->image_pool, mem->image);
gst_vaapi_video_pool_put_object (allocator->image_pool, mem->image);
mem->image = NULL;
}
}
void
gst_vaapi_video_memory_reset_surface(GstVaapiVideoMemory *mem)
gst_vaapi_video_memory_reset_surface (GstVaapiVideoMemory * mem)
{
mem->surface = NULL;
gst_vaapi_video_memory_reset_image(mem);
gst_vaapi_surface_proxy_replace(&mem->proxy, NULL);
gst_vaapi_video_meta_set_surface_proxy(mem->meta, NULL);
gst_vaapi_video_memory_reset_image (mem);
gst_vaapi_surface_proxy_replace (&mem->proxy, NULL);
gst_vaapi_video_meta_set_surface_proxy (mem->meta, NULL);
}
static gpointer
gst_vaapi_video_memory_map(GstVaapiVideoMemory *mem, gsize maxsize, guint flags)
gst_vaapi_video_memory_map (GstVaapiVideoMemory * mem, gsize maxsize,
guint flags)
{
gpointer data;
@ -332,21 +332,21 @@ gst_vaapi_video_memory_map(GstVaapiVideoMemory *mem, gsize maxsize, guint flags)
switch (flags & GST_MAP_READWRITE) {
case 0:
// No flags set: return a GstVaapiSurfaceProxy
gst_vaapi_surface_proxy_replace(&mem->proxy,
gst_vaapi_video_meta_get_surface_proxy(mem->meta));
gst_vaapi_surface_proxy_replace (&mem->proxy,
gst_vaapi_video_meta_get_surface_proxy (mem->meta));
if (!mem->proxy)
goto error_no_surface_proxy;
mem->map_type = GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE;
break;
case GST_MAP_READ:
// Only read flag set: return raw pixels
if (!ensure_surface(mem))
if (!ensure_surface (mem))
goto error_no_surface;
if (!ensure_image(mem))
if (!ensure_image (mem))
goto error_no_image;
if (!mem->use_direct_rendering)
gst_vaapi_surface_get_image(mem->surface, mem->image);
if (!gst_vaapi_image_map(mem->image))
gst_vaapi_surface_get_image (mem->surface, mem->image);
if (!gst_vaapi_image_map (mem->image))
goto error_map_image;
mem->map_type = GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR;
break;
@ -364,7 +364,7 @@ gst_vaapi_video_memory_map(GstVaapiVideoMemory *mem, gsize maxsize, guint flags)
case GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR:
if (!mem->image)
goto error_no_image;
data = get_image_data(mem->image);
data = get_image_data (mem->image);
break;
default:
goto error_unsupported_map_type;
@ -374,35 +374,35 @@ gst_vaapi_video_memory_map(GstVaapiVideoMemory *mem, gsize maxsize, guint flags)
/* ERRORS */
error_unsupported_map:
GST_ERROR("unsupported map flags (0x%x)", flags);
GST_ERROR ("unsupported map flags (0x%x)", flags);
return NULL;
error_unsupported_map_type:
GST_ERROR("unsupported map type (%d)", mem->map_type);
GST_ERROR ("unsupported map type (%d)", mem->map_type);
return NULL;
error_no_surface_proxy:
GST_ERROR("failed to extract GstVaapiSurfaceProxy from video meta");
GST_ERROR ("failed to extract GstVaapiSurfaceProxy from video meta");
return NULL;
error_no_surface:
GST_ERROR("failed to extract VA surface from video buffer");
GST_ERROR ("failed to extract VA surface from video buffer");
return NULL;
error_no_image:
GST_ERROR("failed to extract VA image from video buffer");
GST_ERROR ("failed to extract VA image from video buffer");
return NULL;
error_map_image:
GST_ERROR("failed to map VA image");
GST_ERROR ("failed to map VA image");
return NULL;
}
static void
gst_vaapi_video_memory_unmap(GstVaapiVideoMemory *mem)
gst_vaapi_video_memory_unmap (GstVaapiVideoMemory * mem)
{
if (mem->map_count == 1) {
switch (mem->map_type) {
case GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE:
gst_vaapi_surface_proxy_replace(&mem->proxy, NULL);
gst_vaapi_surface_proxy_replace (&mem->proxy, NULL);
break;
case GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR:
gst_vaapi_image_unmap(mem->image);
gst_vaapi_image_unmap (mem->image);
break;
default:
goto error_incompatible_map;
@ -414,12 +414,12 @@ gst_vaapi_video_memory_unmap(GstVaapiVideoMemory *mem)
/* ERRORS */
error_incompatible_map:
GST_ERROR("incompatible map type (%d)", mem->map_type);
GST_ERROR ("incompatible map type (%d)", mem->map_type);
return;
}
static GstVaapiVideoMemory *
gst_vaapi_video_memory_copy(GstVaapiVideoMemory *mem,
gst_vaapi_video_memory_copy (GstVaapiVideoMemory * mem,
gssize offset, gssize size)
{
GstVaapiVideoMeta *meta;
@ -428,42 +428,42 @@ gst_vaapi_video_memory_copy(GstVaapiVideoMemory *mem,
/* XXX: this implements a soft-copy, i.e. underlying VA surfaces
are not copied */
(void)gst_memory_get_sizes(GST_MEMORY_CAST(mem), NULL, &maxsize);
if (offset != 0 || (size != -1 && (gsize)size != maxsize))
(void) gst_memory_get_sizes (GST_MEMORY_CAST (mem), NULL, &maxsize);
if (offset != 0 || (size != -1 && (gsize) size != maxsize))
goto error_unsupported;
meta = gst_vaapi_video_meta_copy(mem->meta);
meta = gst_vaapi_video_meta_copy (mem->meta);
if (!meta)
goto error_allocate_memory;
out_mem = gst_vaapi_video_memory_new(GST_MEMORY_CAST(mem)->allocator, meta);
gst_vaapi_video_meta_unref(meta);
out_mem = gst_vaapi_video_memory_new (GST_MEMORY_CAST (mem)->allocator, meta);
gst_vaapi_video_meta_unref (meta);
if (!out_mem)
goto error_allocate_memory;
return GST_VAAPI_VIDEO_MEMORY_CAST(out_mem);
return GST_VAAPI_VIDEO_MEMORY_CAST (out_mem);
/* ERRORS */
error_unsupported:
GST_ERROR("failed to copy partial memory (unsupported operation)");
GST_ERROR ("failed to copy partial memory (unsupported operation)");
return NULL;
error_allocate_memory:
GST_ERROR("failed to allocate GstVaapiVideoMemory copy");
GST_ERROR ("failed to allocate GstVaapiVideoMemory copy");
return NULL;
}
static GstVaapiVideoMemory *
gst_vaapi_video_memory_share(GstVaapiVideoMemory *mem,
gst_vaapi_video_memory_share (GstVaapiVideoMemory * mem,
gssize offset, gssize size)
{
GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_share() hook");
GST_FIXME ("unimplemented GstVaapiVideoAllocator::mem_share() hook");
return NULL;
}
static gboolean
gst_vaapi_video_memory_is_span(GstVaapiVideoMemory *mem1,
GstVaapiVideoMemory *mem2, gsize *offset_ptr)
gst_vaapi_video_memory_is_span (GstVaapiVideoMemory * mem1,
GstVaapiVideoMemory * mem2, gsize * offset_ptr)
{
GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_is_span() hook");
GST_FIXME ("unimplemented GstVaapiVideoAllocator::mem_is_span() hook");
return FALSE;
}
@ -472,52 +472,50 @@ gst_vaapi_video_memory_is_span(GstVaapiVideoMemory *mem1,
/* ------------------------------------------------------------------------ */
#define GST_VAAPI_VIDEO_ALLOCATOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_ALLOCATOR, \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_VIDEO_ALLOCATOR, \
GstVaapiVideoAllocatorClass))
#define GST_VAAPI_IS_VIDEO_ALLOCATOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
G_DEFINE_TYPE(GstVaapiVideoAllocator,
gst_vaapi_video_allocator,
GST_TYPE_ALLOCATOR)
G_DEFINE_TYPE (GstVaapiVideoAllocator,
gst_vaapi_video_allocator, GST_TYPE_ALLOCATOR);
static GstMemory *
gst_vaapi_video_allocator_alloc(GstAllocator *allocator, gsize size,
GstAllocationParams *params)
gst_vaapi_video_allocator_alloc (GstAllocator * allocator, gsize size,
GstAllocationParams * params)
{
g_warning("use gst_vaapi_video_memory_new() to allocate from "
g_warning ("use gst_vaapi_video_memory_new() to allocate from "
"GstVaapiVideoMemory allocator");
return NULL;
}
static void
gst_vaapi_video_allocator_free(GstAllocator *allocator, GstMemory *mem)
gst_vaapi_video_allocator_free (GstAllocator * allocator, GstMemory * mem)
{
gst_vaapi_video_memory_free(GST_VAAPI_VIDEO_MEMORY_CAST(mem));
gst_vaapi_video_memory_free (GST_VAAPI_VIDEO_MEMORY_CAST (mem));
}
static void
gst_vaapi_video_allocator_finalize(GObject *object)
gst_vaapi_video_allocator_finalize (GObject * object)
{
GstVaapiVideoAllocator * const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST(object);
GstVaapiVideoAllocator *const allocator =
GST_VAAPI_VIDEO_ALLOCATOR_CAST (object);
gst_vaapi_video_pool_replace(&allocator->surface_pool, NULL);
gst_vaapi_video_pool_replace(&allocator->image_pool, NULL);
gst_vaapi_video_pool_replace (&allocator->surface_pool, NULL);
gst_vaapi_video_pool_replace (&allocator->image_pool, NULL);
G_OBJECT_CLASS(gst_vaapi_video_allocator_parent_class)->finalize(object);
G_OBJECT_CLASS (gst_vaapi_video_allocator_parent_class)->finalize (object);
}
static void
gst_vaapi_video_allocator_class_init(GstVaapiVideoAllocatorClass *klass)
gst_vaapi_video_allocator_class_init (GstVaapiVideoAllocatorClass * klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
GstAllocatorClass * const allocator_class = GST_ALLOCATOR_CLASS(klass);
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
GstAllocatorClass *const allocator_class = GST_ALLOCATOR_CLASS (klass);
GST_DEBUG_CATEGORY_INIT(gst_debug_vaapivideomemory,
GST_DEBUG_CATEGORY_INIT (gst_debug_vaapivideomemory,
"vaapivideomemory", 0, "VA-API video memory allocator");
object_class->finalize = gst_vaapi_video_allocator_finalize;
@ -526,9 +524,9 @@ gst_vaapi_video_allocator_class_init(GstVaapiVideoAllocatorClass *klass)
}
static void
gst_vaapi_video_allocator_init(GstVaapiVideoAllocator *allocator)
gst_vaapi_video_allocator_init (GstVaapiVideoAllocator * allocator)
{
GstAllocator * const base_allocator = GST_ALLOCATOR_CAST(allocator);
GstAllocator *const base_allocator = GST_ALLOCATOR_CAST (allocator);
base_allocator->mem_type = GST_VAAPI_VIDEO_MEMORY_NAME;
base_allocator->mem_map = (GstMemoryMapFunction)
@ -544,131 +542,131 @@ gst_vaapi_video_allocator_init(GstVaapiVideoAllocator *allocator)
}
static gboolean
gst_video_info_update_from_image(GstVideoInfo *vip, GstVaapiImage *image)
gst_video_info_update_from_image (GstVideoInfo * vip, GstVaapiImage * image)
{
GstVideoFormat format;
const guchar *data;
guint i, num_planes, data_size, width, height;
/* Reset format from image */
format = gst_vaapi_image_get_format(image);
gst_vaapi_image_get_size(image, &width, &height);
gst_video_info_set_format(vip, format, width, height);
format = gst_vaapi_image_get_format (image);
gst_vaapi_image_get_size (image, &width, &height);
gst_video_info_set_format (vip, format, width, height);
num_planes = gst_vaapi_image_get_plane_count(image);
g_return_val_if_fail(num_planes == GST_VIDEO_INFO_N_PLANES(vip), FALSE);
num_planes = gst_vaapi_image_get_plane_count (image);
g_return_val_if_fail (num_planes == GST_VIDEO_INFO_N_PLANES (vip), FALSE);
/* Determine the base data pointer */
data = get_image_data(image);
g_return_val_if_fail(data != NULL, FALSE);
data_size = gst_vaapi_image_get_data_size(image);
data = get_image_data (image);
g_return_val_if_fail (data != NULL, FALSE);
data_size = gst_vaapi_image_get_data_size (image);
/* Check that we don't have disjoint planes */
for (i = 0; i < num_planes; i++) {
const guchar * const plane = gst_vaapi_image_get_plane(image, i);
const guchar *const plane = gst_vaapi_image_get_plane (image, i);
if (plane - data > data_size)
return FALSE;
}
/* Update GstVideoInfo structure */
for (i = 0; i < num_planes; i++) {
const guchar * const plane = gst_vaapi_image_get_plane(image, i);
GST_VIDEO_INFO_PLANE_OFFSET(vip, i) = plane - data;
GST_VIDEO_INFO_PLANE_STRIDE(vip, i) =
gst_vaapi_image_get_pitch(image, i);
const guchar *const plane = gst_vaapi_image_get_plane (image, i);
GST_VIDEO_INFO_PLANE_OFFSET (vip, i) = plane - data;
GST_VIDEO_INFO_PLANE_STRIDE (vip, i) = gst_vaapi_image_get_pitch (image, i);
}
GST_VIDEO_INFO_SIZE(vip) = data_size;
GST_VIDEO_INFO_SIZE (vip) = data_size;
return TRUE;
}
GstAllocator *
gst_vaapi_video_allocator_new(GstVaapiDisplay *display, const GstVideoInfo *vip)
gst_vaapi_video_allocator_new (GstVaapiDisplay * display,
const GstVideoInfo * vip)
{
GstVaapiVideoAllocator *allocator;
GstVaapiSurface *surface;
GstVaapiImage *image;
g_return_val_if_fail(display != NULL, NULL);
g_return_val_if_fail(vip != NULL, NULL);
g_return_val_if_fail (display != NULL, NULL);
g_return_val_if_fail (vip != NULL, NULL);
allocator = g_object_new(GST_VAAPI_TYPE_VIDEO_ALLOCATOR, NULL);
allocator = g_object_new (GST_VAAPI_TYPE_VIDEO_ALLOCATOR, NULL);
if (!allocator)
return NULL;
allocator->video_info = *vip;
gst_video_info_set_format(&allocator->surface_info, GST_VIDEO_FORMAT_NV12,
GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
gst_video_info_set_format (&allocator->surface_info, GST_VIDEO_FORMAT_NV12,
GST_VIDEO_INFO_WIDTH (vip), GST_VIDEO_INFO_HEIGHT (vip));
if (GST_VIDEO_INFO_FORMAT(vip) != GST_VIDEO_FORMAT_ENCODED) {
if (GST_VIDEO_INFO_FORMAT (vip) != GST_VIDEO_FORMAT_ENCODED) {
image = NULL;
do {
surface = new_surface(display, vip);
surface = new_surface (display, vip);
if (!surface)
break;
image = gst_vaapi_surface_derive_image(surface);
image = gst_vaapi_surface_derive_image (surface);
if (!image)
break;
if (!gst_vaapi_image_map(image))
if (!gst_vaapi_image_map (image))
break;
allocator->has_direct_rendering = gst_video_info_update_from_image(
&allocator->surface_info, image);
if (GST_VAAPI_IMAGE_FORMAT(image) != GST_VIDEO_INFO_FORMAT(vip))
allocator->has_direct_rendering =
gst_video_info_update_from_image (&allocator->surface_info, image);
if (GST_VAAPI_IMAGE_FORMAT (image) != GST_VIDEO_INFO_FORMAT (vip))
allocator->has_direct_rendering = FALSE;
if (USE_NATIVE_FORMATS)
allocator->has_direct_rendering = FALSE;
gst_vaapi_image_unmap(image);
GST_INFO("has direct-rendering for %s surfaces: %s",
GST_VIDEO_INFO_FORMAT_STRING(&allocator->surface_info),
gst_vaapi_image_unmap (image);
GST_INFO ("has direct-rendering for %s surfaces: %s",
GST_VIDEO_INFO_FORMAT_STRING (&allocator->surface_info),
allocator->has_direct_rendering ? "yes" : "no");
} while (0);
if (surface)
gst_vaapi_object_unref(surface);
gst_vaapi_object_unref (surface);
if (image)
gst_vaapi_object_unref(image);
gst_vaapi_object_unref (image);
}
allocator->surface_pool = gst_vaapi_surface_pool_new(display,
allocator->surface_pool = gst_vaapi_surface_pool_new (display,
&allocator->surface_info);
if (!allocator->surface_pool)
goto error_create_surface_pool;
allocator->image_info = *vip;
if (GST_VIDEO_INFO_FORMAT(vip) == GST_VIDEO_FORMAT_ENCODED)
gst_video_info_set_format(&allocator->image_info, GST_VIDEO_FORMAT_I420,
GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
if (GST_VIDEO_INFO_FORMAT (vip) == GST_VIDEO_FORMAT_ENCODED)
gst_video_info_set_format (&allocator->image_info, GST_VIDEO_FORMAT_I420,
GST_VIDEO_INFO_WIDTH (vip), GST_VIDEO_INFO_HEIGHT (vip));
if (allocator->has_direct_rendering)
allocator->image_info = allocator->surface_info;
else {
do {
image = new_image(display, &allocator->image_info);
image = new_image (display, &allocator->image_info);
if (!image)
break;
if (!gst_vaapi_image_map(image))
if (!gst_vaapi_image_map (image))
break;
gst_video_info_update_from_image(&allocator->image_info, image);
gst_vaapi_image_unmap(image);
gst_video_info_update_from_image (&allocator->image_info, image);
gst_vaapi_image_unmap (image);
} while (0);
gst_vaapi_object_unref(image);
gst_vaapi_object_unref (image);
}
allocator->image_pool = gst_vaapi_image_pool_new(display,
allocator->image_pool = gst_vaapi_image_pool_new (display,
&allocator->image_info);
if (!allocator->image_pool)
goto error_create_image_pool;
return GST_ALLOCATOR_CAST(allocator);
return GST_ALLOCATOR_CAST (allocator);
/* ERRORS */
error_create_surface_pool:
{
GST_ERROR("failed to allocate VA surface pool");
gst_object_unref(allocator);
GST_ERROR ("failed to allocate VA surface pool");
gst_object_unref (allocator);
return NULL;
}
error_create_image_pool:
{
GST_ERROR("failed to allocate VA image pool");
gst_object_unref(allocator);
GST_ERROR ("failed to allocate VA image pool");
gst_object_unref (allocator);
return NULL;
}
}

View file

@ -40,7 +40,7 @@ typedef struct _GstVaapiVideoAllocatorClass GstVaapiVideoAllocatorClass;
/* ------------------------------------------------------------------------ */
#define GST_VAAPI_VIDEO_MEMORY_CAST(mem) \
((GstVaapiVideoMemory *)(mem))
((GstVaapiVideoMemory *) (mem))
#define GST_VAAPI_VIDEO_MEMORY_NAME "GstVaapiVideoMemory"
@ -59,7 +59,8 @@ typedef struct _GstVaapiVideoAllocatorClass GstVaapiVideoAllocatorClass;
*
* The set of all #GstVaapiVideoMemory map types.
*/
typedef enum {
typedef enum
{
GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE = 1,
GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR,
GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR
@ -71,7 +72,8 @@ typedef enum {
* A VA video memory object holder, including VA surfaces, images and
* proxies.
*/
struct _GstVaapiVideoMemory {
struct _GstVaapiVideoMemory
{
GstMemory parent_instance;
/*< private >*/
@ -88,39 +90,36 @@ struct _GstVaapiVideoMemory {
G_GNUC_INTERNAL
GstMemory *
gst_vaapi_video_memory_new(GstAllocator *allocator, GstVaapiVideoMeta *meta);
gst_vaapi_video_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
gboolean
gst_video_meta_map_vaapi_memory(GstVideoMeta *meta, guint plane,
GstMapInfo *info, gpointer *data, gint *stride, GstMapFlags flags);
gst_video_meta_map_vaapi_memory (GstVideoMeta * meta, guint plane,
GstMapInfo * info, gpointer * data, gint * stride, GstMapFlags flags);
G_GNUC_INTERNAL
gboolean
gst_video_meta_unmap_vaapi_memory(GstVideoMeta *meta, guint plane,
GstMapInfo *info);
gst_video_meta_unmap_vaapi_memory (GstVideoMeta * meta, guint plane,
GstMapInfo * info);
G_GNUC_INTERNAL
void
gst_vaapi_video_memory_reset_surface(GstVaapiVideoMemory *mem);
gst_vaapi_video_memory_reset_surface (GstVaapiVideoMemory * mem);
/* ------------------------------------------------------------------------ */
/* --- GstVaapiVideoAllocator --- */
/* ------------------------------------------------------------------------ */
#define GST_VAAPI_VIDEO_ALLOCATOR_CAST(allocator) \
((GstVaapiVideoAllocator *)(allocator))
((GstVaapiVideoAllocator *) (allocator))
#define GST_VAAPI_TYPE_VIDEO_ALLOCATOR \
(gst_vaapi_video_allocator_get_type())
(gst_vaapi_video_allocator_get_type ())
#define GST_VAAPI_VIDEO_ALLOCATOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_ALLOCATOR, \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR, \
GstVaapiVideoAllocator))
#define GST_VAAPI_IS_VIDEO_ALLOCATOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
#define GST_VAAPI_VIDEO_ALLOCATOR_NAME "GstVaapiVideoAllocator"
@ -129,7 +128,8 @@ gst_vaapi_video_memory_reset_surface(GstVaapiVideoMemory *mem);
*
* A VA video memory allocator object.
*/
struct _GstVaapiVideoAllocator {
struct _GstVaapiVideoAllocator
{
GstAllocator parent_instance;
/*< private >*/
@ -146,18 +146,19 @@ struct _GstVaapiVideoAllocator {
*
* A VA video memory allocator class.
*/
struct _GstVaapiVideoAllocatorClass {
struct _GstVaapiVideoAllocatorClass
{
GstAllocatorClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_video_allocator_get_type(void) G_GNUC_CONST;
gst_vaapi_video_allocator_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstAllocator *
gst_vaapi_video_allocator_new(GstVaapiDisplay *display,
const GstVideoInfo *vip);
gst_vaapi_video_allocator_new (GstVaapiDisplay * display,
const GstVideoInfo * vip);
G_END_DECLS

View file

@ -33,12 +33,12 @@
#include "gstvaapivideometa.h"
#define GST_VAAPI_VIDEO_META(obj) \
((GstVaapiVideoMeta *)(obj))
((GstVaapiVideoMeta *) (obj))
#define GST_VAAPI_IS_VIDEO_META(obj) \
(GST_VAAPI_VIDEO_META(obj) != NULL)
(GST_VAAPI_VIDEO_META (obj) != NULL)
struct _GstVaapiVideoMeta {
struct _GstVaapiVideoMeta
{
gint ref_count;
GstVaapiDisplay *display;
GstVaapiVideoPool *image_pool;
@ -47,111 +47,111 @@ struct _GstVaapiVideoMeta {
GFunc converter;
guint render_flags;
GstVaapiRectangle render_rect;
guint has_render_rect : 1;
guint has_render_rect:1;
};
static inline void
set_display(GstVaapiVideoMeta *meta, GstVaapiDisplay *display)
set_display (GstVaapiVideoMeta * meta, GstVaapiDisplay * display)
{
gst_vaapi_display_replace(&meta->display, display);
gst_vaapi_display_replace (&meta->display, display);
}
static inline void
set_image(GstVaapiVideoMeta *meta, GstVaapiImage *image)
set_image (GstVaapiVideoMeta * meta, GstVaapiImage * image)
{
meta->image = gst_vaapi_object_ref(image);
set_display(meta, gst_vaapi_object_get_display(GST_VAAPI_OBJECT(image)));
meta->image = gst_vaapi_object_ref (image);
set_display (meta, gst_vaapi_object_get_display (GST_VAAPI_OBJECT (image)));
}
static gboolean
set_image_from_pool(GstVaapiVideoMeta *meta, GstVaapiVideoPool *pool)
set_image_from_pool (GstVaapiVideoMeta * meta, GstVaapiVideoPool * pool)
{
GstVaapiImage *image;
image = gst_vaapi_video_pool_get_object(pool);
image = gst_vaapi_video_pool_get_object (pool);
if (!image)
return FALSE;
set_image(meta, image);
meta->image_pool = gst_vaapi_video_pool_ref(pool);
set_image (meta, image);
meta->image_pool = gst_vaapi_video_pool_ref (pool);
return TRUE;
}
static gboolean
set_surface_proxy(GstVaapiVideoMeta *meta, GstVaapiSurfaceProxy *proxy)
set_surface_proxy (GstVaapiVideoMeta * meta, GstVaapiSurfaceProxy * proxy)
{
GstVaapiSurface *surface;
surface = GST_VAAPI_SURFACE_PROXY_SURFACE(proxy);
surface = GST_VAAPI_SURFACE_PROXY_SURFACE (proxy);
if (!surface)
return FALSE;
meta->proxy = gst_vaapi_surface_proxy_ref(proxy);
set_display(meta, gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface)));
meta->proxy = gst_vaapi_surface_proxy_ref (proxy);
set_display (meta, gst_vaapi_object_get_display (GST_VAAPI_OBJECT (surface)));
return TRUE;
}
static gboolean
set_surface_proxy_from_pool(GstVaapiVideoMeta *meta, GstVaapiVideoPool *pool)
set_surface_proxy_from_pool (GstVaapiVideoMeta * meta, GstVaapiVideoPool * pool)
{
GstVaapiSurfaceProxy *proxy;
gboolean success;
proxy = gst_vaapi_surface_proxy_new_from_pool(GST_VAAPI_SURFACE_POOL(pool));
proxy = gst_vaapi_surface_proxy_new_from_pool (GST_VAAPI_SURFACE_POOL (pool));
if (!proxy)
return FALSE;
success = set_surface_proxy(meta, proxy);
gst_vaapi_surface_proxy_unref(proxy);
success = set_surface_proxy (meta, proxy);
gst_vaapi_surface_proxy_unref (proxy);
return success;
}
static void
gst_vaapi_video_meta_destroy_image(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_destroy_image (GstVaapiVideoMeta * meta)
{
if (meta->image) {
if (meta->image_pool)
gst_vaapi_video_pool_put_object(meta->image_pool, meta->image);
gst_vaapi_object_unref(meta->image);
gst_vaapi_video_pool_put_object (meta->image_pool, meta->image);
gst_vaapi_object_unref (meta->image);
meta->image = NULL;
}
gst_vaapi_video_pool_replace(&meta->image_pool, NULL);
gst_vaapi_video_pool_replace (&meta->image_pool, NULL);
}
static inline void
gst_vaapi_video_meta_destroy_proxy(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_destroy_proxy (GstVaapiVideoMeta * meta)
{
gst_vaapi_surface_proxy_replace(&meta->proxy, NULL);
gst_vaapi_surface_proxy_replace (&meta->proxy, NULL);
}
#if !GST_CHECK_VERSION(1,0,0)
#define GST_VAAPI_TYPE_VIDEO_META gst_vaapi_video_meta_get_type()
#define GST_VAAPI_TYPE_VIDEO_META gst_vaapi_video_meta_get_type ()
static GType
gst_vaapi_video_meta_get_type(void)
gst_vaapi_video_meta_get_type (void)
{
static gsize g_type;
if (g_once_init_enter(&g_type)) {
if (g_once_init_enter (&g_type)) {
GType type;
type = g_boxed_type_register_static("GstVaapiVideoMeta",
(GBoxedCopyFunc)gst_vaapi_video_meta_ref,
(GBoxedFreeFunc)gst_vaapi_video_meta_unref);
g_once_init_leave(&g_type, type);
type = g_boxed_type_register_static ("GstVaapiVideoMeta",
(GBoxedCopyFunc) gst_vaapi_video_meta_ref,
(GBoxedFreeFunc) gst_vaapi_video_meta_unref);
g_once_init_leave (&g_type, type);
}
return (GType)g_type;
return (GType) g_type;
}
#endif
static void
gst_vaapi_video_meta_finalize(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_finalize (GstVaapiVideoMeta * meta)
{
gst_vaapi_video_meta_destroy_image(meta);
gst_vaapi_video_meta_destroy_proxy(meta);
gst_vaapi_display_replace(&meta->display, NULL);
gst_vaapi_video_meta_destroy_image (meta);
gst_vaapi_video_meta_destroy_proxy (meta);
gst_vaapi_display_replace (&meta->display, NULL);
}
static void
gst_vaapi_video_meta_init(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_init (GstVaapiVideoMeta * meta)
{
meta->ref_count = 1;
meta->display = NULL;
@ -164,38 +164,38 @@ gst_vaapi_video_meta_init(GstVaapiVideoMeta *meta)
}
static inline GstVaapiVideoMeta *
_gst_vaapi_video_meta_create(void)
_gst_vaapi_video_meta_create (void)
{
return g_slice_new(GstVaapiVideoMeta);
return g_slice_new (GstVaapiVideoMeta);
}
static inline void
_gst_vaapi_video_meta_destroy(GstVaapiVideoMeta *meta)
_gst_vaapi_video_meta_destroy (GstVaapiVideoMeta * meta)
{
g_slice_free1(sizeof(*meta), meta);
g_slice_free1 (sizeof (*meta), meta);
}
static inline GstVaapiVideoMeta *
_gst_vaapi_video_meta_new(void)
_gst_vaapi_video_meta_new (void)
{
GstVaapiVideoMeta *meta;
meta = _gst_vaapi_video_meta_create();
meta = _gst_vaapi_video_meta_create ();
if (!meta)
return NULL;
gst_vaapi_video_meta_init(meta);
gst_vaapi_video_meta_init (meta);
return meta;
}
static inline void
_gst_vaapi_video_meta_free(GstVaapiVideoMeta *meta)
_gst_vaapi_video_meta_free (GstVaapiVideoMeta * meta)
{
g_atomic_int_inc(&meta->ref_count);
g_atomic_int_inc (&meta->ref_count);
gst_vaapi_video_meta_finalize(meta);
gst_vaapi_video_meta_finalize (meta);
if (G_LIKELY(g_atomic_int_dec_and_test(&meta->ref_count)))
_gst_vaapi_video_meta_destroy(meta);
if (G_LIKELY (g_atomic_int_dec_and_test (&meta->ref_count)))
_gst_vaapi_video_meta_destroy (meta);
}
/**
@ -209,25 +209,24 @@ _gst_vaapi_video_meta_free(GstVaapiVideoMeta *meta)
* Return value: the newly allocated #GstVaapiVideoMeta, or %NULL on error
*/
GstVaapiVideoMeta *
gst_vaapi_video_meta_copy(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_copy (GstVaapiVideoMeta * meta)
{
GstVaapiVideoMeta *copy;
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
if (meta->image_pool)
return NULL;
copy = _gst_vaapi_video_meta_create();
copy = _gst_vaapi_video_meta_create ();
if (!copy)
return NULL;
copy->ref_count = 1;
copy->display = gst_vaapi_display_ref(meta->display);
copy->display = gst_vaapi_display_ref (meta->display);
copy->image_pool = NULL;
copy->image = meta->image ? gst_vaapi_object_ref(meta->image) : NULL;
copy->proxy = meta->proxy ?
gst_vaapi_surface_proxy_copy(meta->proxy) : NULL;
copy->image = meta->image ? gst_vaapi_object_ref (meta->image) : NULL;
copy->proxy = meta->proxy ? gst_vaapi_surface_proxy_copy (meta->proxy) : NULL;
copy->converter = meta->converter;
copy->render_flags = meta->render_flags;
@ -251,17 +250,17 @@ gst_vaapi_video_meta_copy(GstVaapiVideoMeta *meta)
* Return value: the newly allocated #GstVaapiVideoMeta, or %NULL or error
*/
GstVaapiVideoMeta *
gst_vaapi_video_meta_new(GstVaapiDisplay *display)
gst_vaapi_video_meta_new (GstVaapiDisplay * display)
{
GstVaapiVideoMeta *meta;
g_return_val_if_fail(display != NULL, NULL);
g_return_val_if_fail (display != NULL, NULL);
meta = _gst_vaapi_video_meta_new();
if (G_UNLIKELY(!meta))
meta = _gst_vaapi_video_meta_new ();
if (G_UNLIKELY (!meta))
return NULL;
set_display(meta, display);
set_display (meta, display);
return meta;
}
@ -279,36 +278,36 @@ gst_vaapi_video_meta_new(GstVaapiDisplay *display)
* Return value: the newly allocated #GstVaapiVideoMeta, or %NULL on error
*/
GstVaapiVideoMeta *
gst_vaapi_video_meta_new_from_pool(GstVaapiVideoPool *pool)
gst_vaapi_video_meta_new_from_pool (GstVaapiVideoPool * pool)
{
GstVaapiVideoMeta *meta;
GstVaapiVideoPoolObjectType object_type;
g_return_val_if_fail(pool != NULL, NULL);
g_return_val_if_fail (pool != NULL, NULL);
meta = _gst_vaapi_video_meta_new();
if (G_UNLIKELY(!meta))
meta = _gst_vaapi_video_meta_new ();
if (G_UNLIKELY (!meta))
return NULL;
object_type = gst_vaapi_video_pool_get_object_type(pool);
object_type = gst_vaapi_video_pool_get_object_type (pool);
switch (object_type) {
case GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE:
if (!set_image_from_pool(meta, pool))
if (!set_image_from_pool (meta, pool))
goto error;
break;
case GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE:
if (!set_surface_proxy_from_pool(meta, pool))
if (!set_surface_proxy_from_pool (meta, pool))
goto error;
break;
default:
GST_ERROR("unsupported video buffer pool of type %d", object_type);
GST_ERROR ("unsupported video buffer pool of type %d", object_type);
goto error;
}
set_display(meta, gst_vaapi_video_pool_get_display(pool));
set_display (meta, gst_vaapi_video_pool_get_display (pool));
return meta;
error:
gst_vaapi_video_meta_unref(meta);
gst_vaapi_video_meta_unref (meta);
return NULL;
}
@ -325,17 +324,17 @@ error:
* Return value: the newly allocated #GstVaapiVideoMeta, or %NULL on error
*/
GstVaapiVideoMeta *
gst_vaapi_video_meta_new_with_image(GstVaapiImage *image)
gst_vaapi_video_meta_new_with_image (GstVaapiImage * image)
{
GstVaapiVideoMeta *meta;
g_return_val_if_fail(image != NULL, NULL);
g_return_val_if_fail (image != NULL, NULL);
meta = _gst_vaapi_video_meta_new();
if (G_UNLIKELY(!meta))
meta = _gst_vaapi_video_meta_new ();
if (G_UNLIKELY (!meta))
return NULL;
gst_vaapi_video_meta_set_image(meta, image);
gst_vaapi_video_meta_set_image (meta, image);
return meta;
}
@ -352,17 +351,17 @@ gst_vaapi_video_meta_new_with_image(GstVaapiImage *image)
* Return value: the newly allocated #GstVaapiVideoMeta, or %NULL on error
*/
GstVaapiVideoMeta *
gst_vaapi_video_meta_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy)
gst_vaapi_video_meta_new_with_surface_proxy (GstVaapiSurfaceProxy * proxy)
{
GstVaapiVideoMeta *meta;
g_return_val_if_fail(proxy != NULL, NULL);
g_return_val_if_fail (proxy != NULL, NULL);
meta = _gst_vaapi_video_meta_new();
if (G_UNLIKELY(!meta))
meta = _gst_vaapi_video_meta_new ();
if (G_UNLIKELY (!meta))
return NULL;
gst_vaapi_video_meta_set_surface_proxy(meta, proxy);
gst_vaapi_video_meta_set_surface_proxy (meta, proxy);
return meta;
}
@ -375,11 +374,11 @@ gst_vaapi_video_meta_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy)
* Returns: The same @meta argument
*/
GstVaapiVideoMeta *
gst_vaapi_video_meta_ref(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_ref (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(meta != NULL, NULL);
g_return_val_if_fail (meta != NULL, NULL);
g_atomic_int_inc(&meta->ref_count);
g_atomic_int_inc (&meta->ref_count);
return meta;
}
@ -391,13 +390,13 @@ gst_vaapi_video_meta_ref(GstVaapiVideoMeta *meta)
* the reference count reaches zero, the object will be free'd.
*/
void
gst_vaapi_video_meta_unref(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_unref (GstVaapiVideoMeta * meta)
{
g_return_if_fail(meta != NULL);
g_return_if_fail(meta->ref_count > 0);
g_return_if_fail (meta != NULL);
g_return_if_fail (meta->ref_count > 0);
if (g_atomic_int_dec_and_test(&meta->ref_count))
_gst_vaapi_video_meta_free(meta);
if (g_atomic_int_dec_and_test (&meta->ref_count))
_gst_vaapi_video_meta_free (meta);
}
/**
@ -410,27 +409,27 @@ gst_vaapi_video_meta_unref(GstVaapiVideoMeta *meta)
* object. However, @new_meta can be NULL.
*/
void
gst_vaapi_video_meta_replace(GstVaapiVideoMeta **old_meta_ptr,
GstVaapiVideoMeta *new_meta)
gst_vaapi_video_meta_replace (GstVaapiVideoMeta ** old_meta_ptr,
GstVaapiVideoMeta * new_meta)
{
GstVaapiVideoMeta *old_meta;
g_return_if_fail(old_meta_ptr != NULL);
g_return_if_fail (old_meta_ptr != NULL);
old_meta = g_atomic_pointer_get((gpointer *)old_meta_ptr);
old_meta = g_atomic_pointer_get ((gpointer *) old_meta_ptr);
if (old_meta == new_meta)
return;
if (new_meta)
gst_vaapi_video_meta_ref(new_meta);
gst_vaapi_video_meta_ref (new_meta);
while (!g_atomic_pointer_compare_and_exchange((gpointer *)old_meta_ptr,
while (!g_atomic_pointer_compare_and_exchange ((gpointer *) old_meta_ptr,
old_meta, new_meta))
old_meta = g_atomic_pointer_get((gpointer *)old_meta_ptr);
old_meta = g_atomic_pointer_get ((gpointer *) old_meta_ptr);
if (old_meta)
gst_vaapi_video_meta_unref(old_meta);
gst_vaapi_video_meta_unref (old_meta);
}
/**
@ -444,9 +443,9 @@ gst_vaapi_video_meta_replace(GstVaapiVideoMeta **old_meta_ptr,
* Return value: the #GstVaapiDisplay the @meta is bound to
*/
GstVaapiDisplay *
gst_vaapi_video_meta_get_display(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_display (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
return meta->display;
}
@ -463,9 +462,9 @@ gst_vaapi_video_meta_get_display(GstVaapiVideoMeta *meta)
* there is none
*/
GstVaapiImage *
gst_vaapi_video_meta_get_image(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_image (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
return meta->image;
}
@ -480,14 +479,14 @@ gst_vaapi_video_meta_get_image(GstVaapiVideoMeta *meta)
* pool and the pool is also released.
*/
void
gst_vaapi_video_meta_set_image(GstVaapiVideoMeta *meta, GstVaapiImage *image)
gst_vaapi_video_meta_set_image (GstVaapiVideoMeta * meta, GstVaapiImage * image)
{
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
gst_vaapi_video_meta_destroy_image(meta);
gst_vaapi_video_meta_destroy_image (meta);
if (image)
set_image(meta, image);
set_image (meta, image);
}
/**
@ -502,17 +501,17 @@ gst_vaapi_video_meta_set_image(GstVaapiVideoMeta *meta, GstVaapiImage *image)
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_video_meta_set_image_from_pool(GstVaapiVideoMeta *meta,
GstVaapiVideoPool *pool)
gst_vaapi_video_meta_set_image_from_pool (GstVaapiVideoMeta * meta,
GstVaapiVideoPool * pool)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), FALSE);
g_return_val_if_fail(pool != NULL, FALSE);
g_return_val_if_fail(gst_vaapi_video_pool_get_object_type(pool) ==
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), FALSE);
g_return_val_if_fail (pool != NULL, FALSE);
g_return_val_if_fail (gst_vaapi_video_pool_get_object_type (pool) ==
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE, FALSE);
gst_vaapi_video_meta_destroy_image(meta);
gst_vaapi_video_meta_destroy_image (meta);
return set_image_from_pool(meta, pool);
return set_image_from_pool (meta, pool);
}
/**
@ -527,11 +526,11 @@ gst_vaapi_video_meta_set_image_from_pool(GstVaapiVideoMeta *meta,
* there is none
*/
GstVaapiSurface *
gst_vaapi_video_meta_get_surface(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_surface (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
return meta->proxy ? GST_VAAPI_SURFACE_PROXY_SURFACE(meta->proxy) : NULL;
return meta->proxy ? GST_VAAPI_SURFACE_PROXY_SURFACE (meta->proxy) : NULL;
}
/**
@ -546,9 +545,9 @@ gst_vaapi_video_meta_get_surface(GstVaapiVideoMeta *meta)
* %NULL if there is none
*/
GstVaapiSurfaceProxy *
gst_vaapi_video_meta_get_surface_proxy(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_surface_proxy (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
return meta->proxy;
}
@ -563,22 +562,22 @@ gst_vaapi_video_meta_get_surface_proxy(GstVaapiVideoMeta *meta)
* parent pool and the pool is also released.
*/
void
gst_vaapi_video_meta_set_surface_proxy(GstVaapiVideoMeta *meta,
GstVaapiSurfaceProxy *proxy)
gst_vaapi_video_meta_set_surface_proxy (GstVaapiVideoMeta * meta,
GstVaapiSurfaceProxy * proxy)
{
const GstVaapiRectangle *crop_rect;
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
gst_vaapi_video_meta_destroy_proxy(meta);
gst_vaapi_video_meta_destroy_proxy (meta);
if (proxy) {
if (!set_surface_proxy(meta, proxy))
if (!set_surface_proxy (meta, proxy))
return;
crop_rect = gst_vaapi_surface_proxy_get_crop_rect(proxy);
crop_rect = gst_vaapi_surface_proxy_get_crop_rect (proxy);
if (crop_rect)
gst_vaapi_video_meta_set_render_rect(meta, crop_rect);
gst_vaapi_video_meta_set_render_rect (meta, crop_rect);
}
}
@ -591,9 +590,9 @@ gst_vaapi_video_meta_set_surface_proxy(GstVaapiVideoMeta *meta,
* Return value: the surface converter associated with the video @meta
*/
GFunc
gst_vaapi_video_meta_get_surface_converter(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_surface_converter (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
return meta->converter;
}
@ -606,9 +605,10 @@ gst_vaapi_video_meta_get_surface_converter(GstVaapiVideoMeta *meta)
* Sets the @meta surface converter function to @func.
*/
void
gst_vaapi_video_meta_set_surface_converter(GstVaapiVideoMeta *meta, GFunc func)
gst_vaapi_video_meta_set_surface_converter (GstVaapiVideoMeta * meta,
GFunc func)
{
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
meta->converter = func;
}
@ -622,10 +622,10 @@ gst_vaapi_video_meta_set_surface_converter(GstVaapiVideoMeta *meta, GFunc func)
* Return value: a combination for #GstVaapiSurfaceRenderFlags
*/
guint
gst_vaapi_video_meta_get_render_flags(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_render_flags (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), 0);
g_return_val_if_fail(meta->proxy != NULL, 0);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), 0);
g_return_val_if_fail (meta->proxy != NULL, 0);
return meta->render_flags;
}
@ -638,10 +638,10 @@ gst_vaapi_video_meta_get_render_flags(GstVaapiVideoMeta *meta)
* Sets #GstVaapiSurfaceRenderFlags to the @meta.
*/
void
gst_vaapi_video_meta_set_render_flags(GstVaapiVideoMeta *meta, guint flags)
gst_vaapi_video_meta_set_render_flags (GstVaapiVideoMeta * meta, guint flags)
{
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail(meta->proxy != NULL);
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
g_return_if_fail (meta->proxy != NULL);
meta->render_flags = flags;
}
@ -655,9 +655,9 @@ gst_vaapi_video_meta_set_render_flags(GstVaapiVideoMeta *meta, guint flags)
* Return value: render rectangle associated with the video meta.
*/
const GstVaapiRectangle *
gst_vaapi_video_meta_get_render_rect(GstVaapiVideoMeta *meta)
gst_vaapi_video_meta_get_render_rect (GstVaapiVideoMeta * meta)
{
g_return_val_if_fail(GST_VAAPI_IS_VIDEO_META(meta), NULL);
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_META (meta), NULL);
if (!meta->has_render_rect)
return NULL;
@ -672,10 +672,10 @@ gst_vaapi_video_meta_get_render_rect(GstVaapiVideoMeta *meta)
* Sets the render rectangle @rect to the @meta.
*/
void
gst_vaapi_video_meta_set_render_rect(GstVaapiVideoMeta *meta,
const GstVaapiRectangle *rect)
gst_vaapi_video_meta_set_render_rect (GstVaapiVideoMeta * meta,
const GstVaapiRectangle * rect)
{
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
meta->has_render_rect = rect != NULL;
if (meta->has_render_rect)
@ -685,158 +685,158 @@ gst_vaapi_video_meta_set_render_rect(GstVaapiVideoMeta *meta,
#if GST_CHECK_VERSION(1,0,0)
#define GST_VAAPI_VIDEO_META_HOLDER(meta) \
((GstVaapiVideoMetaHolder *)(meta))
((GstVaapiVideoMetaHolder *) (meta))
typedef struct _GstVaapiVideoMetaHolder GstVaapiVideoMetaHolder;
struct _GstVaapiVideoMetaHolder {
struct _GstVaapiVideoMetaHolder
{
GstMeta base;
GstVaapiVideoMeta *meta;
};
static gboolean
gst_vaapi_video_meta_holder_init(GstVaapiVideoMetaHolder *meta,
gpointer params, GstBuffer *buffer)
gst_vaapi_video_meta_holder_init (GstVaapiVideoMetaHolder * meta,
gpointer params, GstBuffer * buffer)
{
meta->meta = NULL;
return TRUE;
}
static void
gst_vaapi_video_meta_holder_free(GstVaapiVideoMetaHolder *meta,
GstBuffer *buffer)
gst_vaapi_video_meta_holder_free (GstVaapiVideoMetaHolder * meta,
GstBuffer * buffer)
{
if (meta->meta)
gst_vaapi_video_meta_unref(meta->meta);
gst_vaapi_video_meta_unref (meta->meta);
}
static gboolean
gst_vaapi_video_meta_holder_transform(GstBuffer *dst_buffer, GstMeta *meta,
GstBuffer *src_buffer, GQuark type, gpointer data)
gst_vaapi_video_meta_holder_transform (GstBuffer * dst_buffer, GstMeta * meta,
GstBuffer * src_buffer, GQuark type, gpointer data)
{
GstVaapiVideoMetaHolder * const src_meta =
GST_VAAPI_VIDEO_META_HOLDER(meta);
GstVaapiVideoMetaHolder *const src_meta = GST_VAAPI_VIDEO_META_HOLDER (meta);
if (GST_META_TRANSFORM_IS_COPY(type)) {
GstVaapiVideoMeta * const dst_meta =
gst_vaapi_video_meta_copy(src_meta->meta);
gst_buffer_set_vaapi_video_meta(dst_buffer, dst_meta);
gst_vaapi_video_meta_unref(dst_meta);
if (GST_META_TRANSFORM_IS_COPY (type)) {
GstVaapiVideoMeta *const dst_meta =
gst_vaapi_video_meta_copy (src_meta->meta);
gst_buffer_set_vaapi_video_meta (dst_buffer, dst_meta);
gst_vaapi_video_meta_unref (dst_meta);
return TRUE;
}
return FALSE;
}
GType
gst_vaapi_video_meta_api_get_type(void)
gst_vaapi_video_meta_api_get_type (void)
{
static gsize g_type;
static const gchar *tags[] = { "memory", NULL };
if (g_once_init_enter(&g_type)) {
GType type = gst_meta_api_type_register("GstVaapiVideoMetaAPI", tags);
g_once_init_leave(&g_type, type);
if (g_once_init_enter (&g_type)) {
GType type = gst_meta_api_type_register ("GstVaapiVideoMetaAPI", tags);
g_once_init_leave (&g_type, type);
}
return g_type;
}
#define GST_VAAPI_VIDEO_META_INFO gst_vaapi_video_meta_info_get()
#define GST_VAAPI_VIDEO_META_INFO gst_vaapi_video_meta_info_get ()
static const GstMetaInfo *
gst_vaapi_video_meta_info_get(void)
gst_vaapi_video_meta_info_get (void)
{
static gsize g_meta_info;
if (g_once_init_enter(&g_meta_info)) {
gsize meta_info = GPOINTER_TO_SIZE(gst_meta_register(
GST_VAAPI_VIDEO_META_API_TYPE,
"GstVaapiVideoMeta", sizeof(GstVaapiVideoMetaHolder),
(GstMetaInitFunction)gst_vaapi_video_meta_holder_init,
(GstMetaFreeFunction)gst_vaapi_video_meta_holder_free,
(GstMetaTransformFunction)gst_vaapi_video_meta_holder_transform));
g_once_init_leave(&g_meta_info, meta_info);
if (g_once_init_enter (&g_meta_info)) {
gsize meta_info =
GPOINTER_TO_SIZE (gst_meta_register (GST_VAAPI_VIDEO_META_API_TYPE,
"GstVaapiVideoMeta", sizeof (GstVaapiVideoMetaHolder),
(GstMetaInitFunction) gst_vaapi_video_meta_holder_init,
(GstMetaFreeFunction) gst_vaapi_video_meta_holder_free,
(GstMetaTransformFunction) gst_vaapi_video_meta_holder_transform));
g_once_init_leave (&g_meta_info, meta_info);
}
return GSIZE_TO_POINTER(g_meta_info);
return GSIZE_TO_POINTER (g_meta_info);
}
GstVaapiVideoMeta *
gst_buffer_get_vaapi_video_meta(GstBuffer *buffer)
gst_buffer_get_vaapi_video_meta (GstBuffer * buffer)
{
GstMeta *m;
g_return_val_if_fail(GST_IS_BUFFER(buffer), NULL);
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
m = gst_buffer_get_meta(buffer, GST_VAAPI_VIDEO_META_API_TYPE);
m = gst_buffer_get_meta (buffer, GST_VAAPI_VIDEO_META_API_TYPE);
if (!m)
return NULL;
return GST_VAAPI_VIDEO_META_HOLDER(m)->meta;
return GST_VAAPI_VIDEO_META_HOLDER (m)->meta;
}
void
gst_buffer_set_vaapi_video_meta(GstBuffer *buffer, GstVaapiVideoMeta *meta)
gst_buffer_set_vaapi_video_meta (GstBuffer * buffer, GstVaapiVideoMeta * meta)
{
GstMeta *m;
g_return_if_fail(GST_IS_BUFFER(buffer));
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail (GST_IS_BUFFER (buffer));
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
m = gst_buffer_add_meta(buffer, GST_VAAPI_VIDEO_META_INFO, NULL);
m = gst_buffer_add_meta (buffer, GST_VAAPI_VIDEO_META_INFO, NULL);
if (m)
GST_VAAPI_VIDEO_META_HOLDER(m)->meta = gst_vaapi_video_meta_ref(meta);
GST_VAAPI_VIDEO_META_HOLDER (m)->meta = gst_vaapi_video_meta_ref (meta);
}
#else
#define GST_VAAPI_VIDEO_META_QUARK gst_vaapi_video_meta_quark_get()
#define GST_VAAPI_VIDEO_META_QUARK gst_vaapi_video_meta_quark_get ()
static GQuark
gst_vaapi_video_meta_quark_get(void)
gst_vaapi_video_meta_quark_get (void)
{
static gsize g_quark;
if (g_once_init_enter(&g_quark)) {
gsize quark = (gsize)g_quark_from_static_string("GstVaapiVideoMeta");
g_once_init_leave(&g_quark, quark);
if (g_once_init_enter (&g_quark)) {
gsize quark = (gsize) g_quark_from_static_string ("GstVaapiVideoMeta");
g_once_init_leave (&g_quark, quark);
}
return g_quark;
}
#define META_QUARK meta_quark_get()
#define META_QUARK meta_quark_get ()
static GQuark
meta_quark_get(void)
meta_quark_get (void)
{
static gsize g_quark;
if (g_once_init_enter(&g_quark)) {
gsize quark = (gsize)g_quark_from_static_string("meta");
g_once_init_leave(&g_quark, quark);
if (g_once_init_enter (&g_quark)) {
gsize quark = (gsize) g_quark_from_static_string ("meta");
g_once_init_leave (&g_quark, quark);
}
return g_quark;
}
GstVaapiVideoMeta *
gst_buffer_get_vaapi_video_meta(GstBuffer *buffer)
gst_buffer_get_vaapi_video_meta (GstBuffer * buffer)
{
const GstStructure *structure;
const GValue *value;
g_return_val_if_fail(GST_IS_BUFFER(buffer), NULL);
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
structure = gst_buffer_get_qdata(buffer, GST_VAAPI_VIDEO_META_QUARK);
structure = gst_buffer_get_qdata (buffer, GST_VAAPI_VIDEO_META_QUARK);
if (!structure)
return NULL;
value = gst_structure_id_get_value(structure, META_QUARK);
value = gst_structure_id_get_value (structure, META_QUARK);
if (!value)
return NULL;
return GST_VAAPI_VIDEO_META(g_value_get_boxed(value));
return GST_VAAPI_VIDEO_META (g_value_get_boxed (value));
}
void
gst_buffer_set_vaapi_video_meta(GstBuffer *buffer, GstVaapiVideoMeta *meta)
gst_buffer_set_vaapi_video_meta (GstBuffer * buffer, GstVaapiVideoMeta * meta)
{
g_return_if_fail(GST_IS_BUFFER(buffer));
g_return_if_fail(GST_VAAPI_IS_VIDEO_META(meta));
g_return_if_fail (GST_IS_BUFFER (buffer));
g_return_if_fail (GST_VAAPI_IS_VIDEO_META (meta));
gst_buffer_set_qdata(buffer, GST_VAAPI_VIDEO_META_QUARK,
gst_structure_id_new(GST_VAAPI_VIDEO_META_QUARK,
gst_buffer_set_qdata (buffer, GST_VAAPI_VIDEO_META_QUARK,
gst_structure_id_new (GST_VAAPI_VIDEO_META_QUARK,
META_QUARK, GST_VAAPI_TYPE_VIDEO_META, meta, NULL));
}
#endif

View file

@ -37,108 +37,110 @@ typedef struct _GstVaapiVideoMeta GstVaapiVideoMeta;
#if GST_CHECK_VERSION(1,0,0)
#define GST_VAAPI_VIDEO_META_API_TYPE \
gst_vaapi_video_meta_api_get_type()
gst_vaapi_video_meta_api_get_type ()
G_GNUC_INTERNAL
GType
gst_vaapi_video_meta_api_get_type(void) G_GNUC_CONST;
gst_vaapi_video_meta_api_get_type (void) G_GNUC_CONST;
#endif
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_vaapi_video_meta_copy(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_copy (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_vaapi_video_meta_new(GstVaapiDisplay *display);
gst_vaapi_video_meta_new (GstVaapiDisplay * display);
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_vaapi_video_meta_new_from_pool(GstVaapiVideoPool *pool);
gst_vaapi_video_meta_new_from_pool (GstVaapiVideoPool * pool);
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_vaapi_video_meta_new_with_image(GstVaapiImage *image);
gst_vaapi_video_meta_new_with_image (GstVaapiImage * image);
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_vaapi_video_meta_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy);
gst_vaapi_video_meta_new_with_surface_proxy (GstVaapiSurfaceProxy * proxy);
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_vaapi_video_meta_ref(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_ref (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_unref(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_unref (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_replace(GstVaapiVideoMeta **old_meta_ptr,
GstVaapiVideoMeta *new_meta);
gst_vaapi_video_meta_replace (GstVaapiVideoMeta ** old_meta_ptr,
GstVaapiVideoMeta * new_meta);
G_GNUC_INTERNAL
GstVaapiDisplay *
gst_vaapi_video_meta_get_display(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_display (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
GstVaapiImage *
gst_vaapi_video_meta_get_image(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_image (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_set_image(GstVaapiVideoMeta *meta, GstVaapiImage *image);
gst_vaapi_video_meta_set_image (GstVaapiVideoMeta * meta,
GstVaapiImage * image);
G_GNUC_INTERNAL
gboolean
gst_vaapi_video_meta_set_image_from_pool(GstVaapiVideoMeta *meta,
GstVaapiVideoPool *pool);
gst_vaapi_video_meta_set_image_from_pool (GstVaapiVideoMeta * meta,
GstVaapiVideoPool * pool);
G_GNUC_INTERNAL
GstVaapiSurface *
gst_vaapi_video_meta_get_surface(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_surface (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
GstVaapiSurfaceProxy *
gst_vaapi_video_meta_get_surface_proxy(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_surface_proxy (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_set_surface_proxy(GstVaapiVideoMeta *meta,
GstVaapiSurfaceProxy *proxy);
gst_vaapi_video_meta_set_surface_proxy (GstVaapiVideoMeta * meta,
GstVaapiSurfaceProxy * proxy);
G_GNUC_INTERNAL
GFunc
gst_vaapi_video_meta_get_surface_converter(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_surface_converter (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_set_surface_converter(GstVaapiVideoMeta *meta, GFunc func);
gst_vaapi_video_meta_set_surface_converter (GstVaapiVideoMeta * meta,
GFunc func);
G_GNUC_INTERNAL
guint
gst_vaapi_video_meta_get_render_flags(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_render_flags (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_set_render_flags(GstVaapiVideoMeta *meta, guint flags);
gst_vaapi_video_meta_set_render_flags (GstVaapiVideoMeta * meta, guint flags);
G_GNUC_INTERNAL
const GstVaapiRectangle *
gst_vaapi_video_meta_get_render_rect(GstVaapiVideoMeta *meta);
gst_vaapi_video_meta_get_render_rect (GstVaapiVideoMeta * meta);
G_GNUC_INTERNAL
void
gst_vaapi_video_meta_set_render_rect(GstVaapiVideoMeta *meta,
const GstVaapiRectangle *rect);
gst_vaapi_video_meta_set_render_rect (GstVaapiVideoMeta * meta,
const GstVaapiRectangle * rect);
G_GNUC_INTERNAL
GstVaapiVideoMeta *
gst_buffer_get_vaapi_video_meta(GstBuffer *buffer);
gst_buffer_get_vaapi_video_meta (GstBuffer * buffer);
G_GNUC_INTERNAL
void
gst_buffer_set_vaapi_video_meta(GstBuffer *buffer, GstVaapiVideoMeta *meta);
gst_buffer_set_vaapi_video_meta (GstBuffer * buffer, GstVaapiVideoMeta * meta);
G_END_DECLS

View file

@ -30,26 +30,27 @@
#include "gstvaapipluginutil.h"
#if GST_CHECK_VERSION(1,1,0) && USE_GLX
struct _GstVaapiVideoMetaTexture {
struct _GstVaapiVideoMetaTexture
{
GstVaapiTexture *texture;
};
static void
meta_texture_free(GstVaapiVideoMetaTexture *meta)
meta_texture_free (GstVaapiVideoMetaTexture * meta)
{
if (G_UNLIKELY(!meta))
if (G_UNLIKELY (!meta))
return;
gst_vaapi_texture_replace(&meta->texture, NULL);
g_slice_free(GstVaapiVideoMetaTexture, meta);
gst_vaapi_texture_replace (&meta->texture, NULL);
g_slice_free (GstVaapiVideoMetaTexture, meta);
}
static GstVaapiVideoMetaTexture *
meta_texture_new(void)
meta_texture_new (void)
{
GstVaapiVideoMetaTexture *meta;
meta = g_slice_new(GstVaapiVideoMetaTexture);
meta = g_slice_new (GstVaapiVideoMetaTexture);
if (!meta)
return NULL;
@ -58,50 +59,51 @@ meta_texture_new(void)
}
static GstVaapiVideoMetaTexture *
meta_texture_copy(GstVaapiVideoMetaTexture *meta)
meta_texture_copy (GstVaapiVideoMetaTexture * meta)
{
GstVaapiVideoMetaTexture *copy;
copy = meta_texture_new();
copy = meta_texture_new ();
if (!copy)
return NULL;
gst_vaapi_texture_replace(&copy->texture, meta->texture);
gst_vaapi_texture_replace (&copy->texture, meta->texture);
return copy;
}
static gboolean
gst_vaapi_texture_upload(GstVideoGLTextureUploadMeta *meta, guint texture_id[4])
gst_vaapi_texture_upload (GstVideoGLTextureUploadMeta * meta,
guint texture_id[4])
{
GstVaapiVideoMeta * const vmeta =
gst_buffer_get_vaapi_video_meta(meta->buffer);
GstVaapiVideoMetaTexture * const meta_texture = meta->user_data;
GstVaapiSurface * const surface = gst_vaapi_video_meta_get_surface(vmeta);
GstVaapiDisplay * const dpy = GST_VAAPI_OBJECT_DISPLAY(surface);
GstVaapiVideoMeta *const vmeta =
gst_buffer_get_vaapi_video_meta (meta->buffer);
GstVaapiVideoMetaTexture *const meta_texture = meta->user_data;
GstVaapiSurface *const surface = gst_vaapi_video_meta_get_surface (vmeta);
GstVaapiDisplay *const dpy = GST_VAAPI_OBJECT_DISPLAY (surface);
if (gst_vaapi_display_get_display_type(dpy) != GST_VAAPI_DISPLAY_TYPE_GLX)
if (gst_vaapi_display_get_display_type (dpy) != GST_VAAPI_DISPLAY_TYPE_GLX)
return FALSE;
if (!meta_texture->texture ||
/* Check whether VA display changed */
GST_VAAPI_OBJECT_DISPLAY(meta_texture->texture) != dpy ||
GST_VAAPI_OBJECT_DISPLAY (meta_texture->texture) != dpy ||
/* Check whether texture id changed */
gst_vaapi_texture_get_id(meta_texture->texture) != texture_id[0]) {
gst_vaapi_texture_get_id (meta_texture->texture) != texture_id[0]) {
/* FIXME: should we assume target? */
GstVaapiTexture * const texture =
gst_vaapi_texture_new_with_texture(dpy, texture_id[0],
GstVaapiTexture *const texture =
gst_vaapi_texture_new_with_texture (dpy, texture_id[0],
GL_TEXTURE_2D, GL_RGBA);
gst_vaapi_texture_replace(&meta_texture->texture, texture);
gst_vaapi_texture_replace (&meta_texture->texture, texture);
if (!texture)
return FALSE;
gst_vaapi_texture_unref(texture);
gst_vaapi_texture_unref (texture);
}
return gst_vaapi_texture_put_surface(meta_texture->texture, surface,
gst_vaapi_video_meta_get_render_flags(vmeta));
return gst_vaapi_texture_put_surface (meta_texture->texture, surface,
gst_vaapi_video_meta_get_render_flags (vmeta));
}
gboolean
gst_buffer_add_texture_upload_meta(GstBuffer *buffer)
gst_buffer_add_texture_upload_meta (GstBuffer * buffer)
{
GstVideoGLTextureUploadMeta *meta = NULL;
GstVideoGLTextureType tex_type[] = { GST_VIDEO_GL_TEXTURE_TYPE_RGBA };
@ -110,28 +112,28 @@ gst_buffer_add_texture_upload_meta(GstBuffer *buffer)
if (!buffer)
return FALSE;
meta_texture = meta_texture_new();
meta_texture = meta_texture_new ();
if (!meta_texture)
return FALSE;
meta = gst_buffer_add_video_gl_texture_upload_meta(buffer,
meta = gst_buffer_add_video_gl_texture_upload_meta (buffer,
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL,
1, tex_type, gst_vaapi_texture_upload,
meta_texture, (GBoxedCopyFunc)meta_texture_copy,
(GBoxedFreeFunc)meta_texture_free);
meta_texture, (GBoxedCopyFunc) meta_texture_copy,
(GBoxedFreeFunc) meta_texture_free);
if (!meta)
goto error;
return TRUE;
error:
meta_texture_free(meta_texture);
meta_texture_free (meta_texture);
return FALSE;
}
gboolean
gst_buffer_ensure_texture_upload_meta(GstBuffer *buffer)
gst_buffer_ensure_texture_upload_meta (GstBuffer * buffer)
{
return gst_buffer_get_video_gl_texture_upload_meta(buffer) ||
gst_buffer_add_texture_upload_meta(buffer);
return gst_buffer_get_video_gl_texture_upload_meta (buffer) ||
gst_buffer_add_texture_upload_meta (buffer);
}
#endif

View file

@ -35,11 +35,11 @@ typedef struct _GstVaapiVideoMetaTexture GstVaapiVideoMetaTexture;
G_GNUC_INTERNAL
gboolean
gst_buffer_add_texture_upload_meta(GstBuffer *buffer);
gst_buffer_add_texture_upload_meta (GstBuffer * buffer);
G_GNUC_INTERNAL
gboolean
gst_buffer_ensure_texture_upload_meta(GstBuffer *buffer);
gst_buffer_ensure_texture_upload_meta (GstBuffer * buffer);
G_END_DECLS