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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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