From 568a62ae1e589c04239ab123177eae6d500dcaa5 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Fri, 23 Jan 2015 16:44:34 +0100 Subject: [PATCH] surfaceproxy: add helper to create a wrapped surface object. Add new gst_vaapi_surface_proxy_new() helper to wrap a surface into a proxy. The main use case for that is to convey additional information at the proxy level that would not be suitable to the plain surface. --- gst-libs/gst/vaapi/gstvaapisurfaceproxy.c | 52 ++++++++++++++++++++++++++++--- gst-libs/gst/vaapi/gstvaapisurfaceproxy.h | 3 ++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c index 56e1ea6..96865c7 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c @@ -62,6 +62,51 @@ gst_vaapi_surface_proxy_class (void) return &GstVaapiSurfaceProxyClass; } +static void +gst_vaapi_surface_proxy_init_properties (GstVaapiSurfaceProxy * proxy) +{ + proxy->view_id = 0; + proxy->timestamp = GST_CLOCK_TIME_NONE; + proxy->duration = GST_CLOCK_TIME_NONE; + proxy->has_crop_rect = FALSE; +} + +/** + * gst_vaapi_surface_proxy_new: + * @surface: a #GstVaapiSurface + * + * Creates a new #GstVaapiSurfaceProxy with the specified + * surface. This allows for transporting additional information that + * are not to be attached to the @surface directly. + * + * Return value: the newly allocated #GstVaapiSurfaceProxy object + */ +GstVaapiSurfaceProxy * +gst_vaapi_surface_proxy_new (GstVaapiSurface * surface) +{ + GstVaapiSurfaceProxy *proxy; + + g_return_val_if_fail (surface != NULL, NULL); + + proxy = (GstVaapiSurfaceProxy *) + gst_vaapi_mini_object_new (gst_vaapi_surface_proxy_class ()); + if (!proxy) + return NULL; + + proxy->parent = NULL; + proxy->destroy_func = NULL; + proxy->pool = NULL; + proxy->surface = gst_vaapi_object_ref (surface); + if (!proxy->surface) + goto error; + gst_vaapi_surface_proxy_init_properties (proxy); + return proxy; + +error: + gst_vaapi_surface_proxy_unref (proxy); + return NULL; +} + /** * gst_vaapi_surface_proxy_new_from_pool: * @pool: a #GstVaapiSurfacePool @@ -91,11 +136,8 @@ gst_vaapi_surface_proxy_new_from_pool (GstVaapiSurfacePool * pool) proxy->surface = gst_vaapi_video_pool_get_object (proxy->pool); if (!proxy->surface) goto error; - proxy->view_id = 0; - proxy->timestamp = GST_CLOCK_TIME_NONE; - proxy->duration = GST_CLOCK_TIME_NONE; - proxy->has_crop_rect = FALSE; gst_vaapi_object_ref (proxy->surface); + gst_vaapi_surface_proxy_init_properties (proxy); return proxy; error: @@ -132,7 +174,7 @@ gst_vaapi_surface_proxy_copy (GstVaapiSurfaceProxy * proxy) copy->parent = gst_vaapi_surface_proxy_ref (proxy->parent ? proxy->parent : proxy); - copy->pool = gst_vaapi_video_pool_ref (proxy->pool); + copy->pool = proxy->pool ? gst_vaapi_video_pool_ref (proxy->pool) : NULL; copy->surface = gst_vaapi_object_ref (proxy->surface); copy->view_id = proxy->view_id; copy->timestamp = proxy->timestamp; diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h index 5129dc3..47d3021 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h @@ -102,6 +102,9 @@ typedef enum gst_vaapi_surface_proxy_get_duration (proxy) GstVaapiSurfaceProxy * +gst_vaapi_surface_proxy_new (GstVaapiSurface * surface); + +GstVaapiSurfaceProxy * gst_vaapi_surface_proxy_new_from_pool (GstVaapiSurfacePool * pool); GstVaapiSurfaceProxy * -- 2.7.4