From a1fddf8bcc74aa4394fa3dedef528d23f678f739 Mon Sep 17 00:00:00 2001 From: gb Date: Thu, 29 Apr 2010 15:45:44 +0000 Subject: [PATCH] Add support for GstVaapiSurfaceProxy to GstVaapiVideoBuffer. --- gst-libs/gst/vaapi/gstvaapivideobuffer.c | 85 ++++++++++++++++++++++++++++++-- gst-libs/gst/vaapi/gstvaapivideobuffer.h | 13 +++++ 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapivideobuffer.c b/gst-libs/gst/vaapi/gstvaapivideobuffer.c index d40b9de..fbb4f1f 100644 --- a/gst-libs/gst/vaapi/gstvaapivideobuffer.c +++ b/gst-libs/gst/vaapi/gstvaapivideobuffer.c @@ -39,11 +39,12 @@ G_DEFINE_TYPE(GstVaapiVideoBuffer, gst_vaapi_video_buffer, GST_TYPE_BUFFER); GstVaapiVideoBufferPrivate)) struct _GstVaapiVideoBufferPrivate { - GstVaapiVideoPool *image_pool; - GstVaapiImage *image; - GstVaapiVideoPool *surface_pool; - GstVaapiSurface *surface; - guint flags; + GstVaapiVideoPool *image_pool; + GstVaapiImage *image; + GstVaapiVideoPool *surface_pool; + GstVaapiSurface *surface; + GstVaapiSurfaceProxy *proxy; + guint flags; }; static void @@ -70,6 +71,11 @@ gst_vaapi_video_buffer_destroy_surface(GstVaapiVideoBuffer *buffer) { GstVaapiVideoBufferPrivate * const priv = buffer->priv; + if (priv->proxy) { + g_object_unref(priv->proxy); + priv->proxy = NULL; + } + if (priv->surface) { if (priv->surface_pool) gst_vaapi_video_pool_put_object(priv->surface_pool, priv->surface); @@ -119,6 +125,7 @@ gst_vaapi_video_buffer_init(GstVaapiVideoBuffer *buffer) priv->image = NULL; priv->surface_pool = NULL; priv->surface = NULL; + priv->proxy = NULL; } static inline GstVaapiVideoBuffer * @@ -216,6 +223,28 @@ gst_vaapi_video_buffer_new_with_surface(GstVaapiSurface *surface) } /** + * gst_vaapi_video_buffer_new_with_surface_proxy: + * @proxy: a #GstVaapiSurfaceProxy + * + * Creates a #GstBuffer with the specified surface @proxy. The + * resulting buffer holds an additional reference to the @proxy. + * + * Return value: the newly allocated #GstBuffer, or %NULL on error + */ +GstBuffer * +gst_vaapi_video_buffer_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy) +{ + GstVaapiVideoBuffer *buffer; + + g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL); + + buffer = gst_vaapi_video_buffer_new(); + if (buffer) + gst_vaapi_video_buffer_set_surface_proxy(buffer, proxy); + return GST_BUFFER(buffer); +} + +/** * gst_vaapi_video_buffer_get_image: * @buffer: a #GstVaapiVideoBuffer * @@ -362,3 +391,49 @@ gst_vaapi_video_buffer_set_surface_from_pool( } return TRUE; } + +/** + * gst_vaapi_video_buffer_get_surface_proxy: + * @buffer: a #GstVaapiVideoBuffer + * + * Retrieves the #GstVaapiSurfaceProxy bound to the @buffer. The @buffer + * owns the #GstVaapiSurfaceProxy so the caller is responsible for calling + * g_object_ref() when needed. + * + * Return value: the #GstVaapiSurfaceProxy bound to the @buffer, or + * %NULL if there is none + */ +GstVaapiSurfaceProxy * +gst_vaapi_video_buffer_get_surface_proxy(GstVaapiVideoBuffer *buffer) +{ + g_return_val_if_fail(GST_VAAPI_IS_VIDEO_BUFFER(buffer), NULL); + + return buffer->priv->proxy; +} + +/** + * gst_vaapi_video_buffer_set_surface_proxy: + * @buffer: a #GstVaapiVideoBuffer + * @proxy: a #GstVaapiSurfaceProxy + * + * Binds surface @proxy to the @buffer. If the @buffer contains another + * surface previously allocated from a pool, it's pushed back to its + * parent pool and the pool is also released. + */ +void +gst_vaapi_video_buffer_set_surface_proxy( + GstVaapiVideoBuffer *buffer, + GstVaapiSurfaceProxy *proxy +) +{ + g_return_if_fail(GST_VAAPI_IS_VIDEO_BUFFER(buffer)); + g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy)); + + gst_vaapi_video_buffer_destroy_surface(buffer); + + if (proxy) { + GstVaapiVideoBufferPrivate * const priv = buffer->priv; + priv->proxy = g_object_ref(proxy); + priv->surface = g_object_ref(GST_VAAPI_SURFACE_PROXY_SURFACE(proxy)); + } +} diff --git a/gst-libs/gst/vaapi/gstvaapivideobuffer.h b/gst-libs/gst/vaapi/gstvaapivideobuffer.h index ae737e7..1303df7 100644 --- a/gst-libs/gst/vaapi/gstvaapivideobuffer.h +++ b/gst-libs/gst/vaapi/gstvaapivideobuffer.h @@ -24,6 +24,7 @@ #include #include #include +#include #include G_BEGIN_DECLS @@ -90,6 +91,9 @@ gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image); GstBuffer * gst_vaapi_video_buffer_new_with_surface(GstVaapiSurface *surface); +GstBuffer * +gst_vaapi_video_buffer_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy); + GstVaapiImage * gst_vaapi_video_buffer_get_image(GstVaapiVideoBuffer *buffer); @@ -120,6 +124,15 @@ gst_vaapi_video_buffer_set_surface_from_pool( GstVaapiVideoPool *pool ); +GstVaapiSurfaceProxy * +gst_vaapi_video_buffer_get_surface_proxy(GstVaapiVideoBuffer *buffer); + +void +gst_vaapi_video_buffer_set_surface_proxy( + GstVaapiVideoBuffer *buffer, + GstVaapiSurfaceProxy *proxy +); + G_END_DECLS #endif /* GST_VAAPI_VIDEO_BUFFER_H */ -- 2.7.4