surface: record parent context.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 13 Dec 2011 15:53:15 +0000 (16:53 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 13 Dec 2011 15:53:15 +0000 (16:53 +0100)
docs/reference/libs/libs-sections.txt
gst-libs/gst/vaapi/Makefile.am
gst-libs/gst/vaapi/gstvaapicontext.c
gst-libs/gst/vaapi/gstvaapisurface.c
gst-libs/gst/vaapi/gstvaapisurface.h
gst-libs/gst/vaapi/gstvaapisurface_priv.h [new file with mode: 0644]

index d271a26..48a928e 100644 (file)
@@ -332,6 +332,7 @@ gst_vaapi_surface_get_chroma_type
 gst_vaapi_surface_get_width
 gst_vaapi_surface_get_height
 gst_vaapi_surface_get_size
+gst_vaapi_surface_get_parent_context
 gst_vaapi_surface_derive_image
 gst_vaapi_surface_get_image
 gst_vaapi_surface_put_image
index 7677174..6361cc1 100644 (file)
@@ -75,6 +75,7 @@ libgstvaapi_source_priv_h =                   \
        gstvaapidecoder_priv.h                  \
        gstvaapidisplay_priv.h                  \
        gstvaapiobject_priv.h                   \
+       gstvaapisurface_priv.h                  \
        gstvaapiutils.h                         \
        gstvaapivideobuffer_priv.h              \
        $(libgst_vaapi_ffmpeg_source_priv_h)    \
index 2ab62bb..63a8c74 100644 (file)
@@ -28,6 +28,8 @@
 #include <assert.h>
 #include "gstvaapicompat.h"
 #include "gstvaapicontext.h"
+#include "gstvaapisurface.h"
+#include "gstvaapisurface_priv.h"
 #include "gstvaapisurfacepool.h"
 #include "gstvaapiutils.h"
 #include "gstvaapi_priv.h"
@@ -66,7 +68,10 @@ enum {
 static void
 unref_surface_cb(gpointer data, gpointer user_data)
 {
-    g_object_unref(GST_VAAPI_SURFACE(data));
+    GstVaapiSurface * const surface = GST_VAAPI_SURFACE(data);
+
+    gst_vaapi_surface_set_parent_context(surface, NULL);
+    g_object_unref(surface);
 }
 
 static void
@@ -178,6 +183,7 @@ gst_vaapi_context_create_surfaces(GstVaapiContext *context)
         g_ptr_array_add(priv->surfaces, surface);
         if (!gst_vaapi_video_pool_add_object(priv->surfaces_pool, surface))
             return FALSE;
+        gst_vaapi_surface_set_parent_context(surface, context);
     }
     return TRUE;
 }
index 50215e8..c6dcf78 100644 (file)
@@ -28,6 +28,8 @@
 #include "gstvaapicompat.h"
 #include "gstvaapiutils.h"
 #include "gstvaapisurface.h"
+#include "gstvaapisurface_priv.h"
+#include "gstvaapicontext.h"
 #include "gstvaapiimage.h"
 #include "gstvaapi_priv.h"
 
@@ -46,6 +48,7 @@ struct _GstVaapiSurfacePrivate {
     guint               height;
     GstVaapiChromaType  chroma_type;
     GPtrArray          *subpictures;
+    GstVaapiContext    *parent_context;
 };
 
 enum {
@@ -53,7 +56,8 @@ enum {
 
     PROP_WIDTH,
     PROP_HEIGHT,
-    PROP_CHROMA_TYPE
+    PROP_CHROMA_TYPE,
+    PROP_PARENT_CONTEXT
 };
 
 static gboolean
@@ -100,6 +104,7 @@ gst_vaapi_surface_destroy(GstVaapiSurface *surface)
     GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
 
     gst_vaapi_surface_destroy_subpictures(surface);
+    gst_vaapi_surface_set_parent_context(surface, NULL);
   
     if (surface_id != VA_INVALID_SURFACE) {
         GST_VAAPI_DISPLAY_LOCK(display);
@@ -185,6 +190,9 @@ gst_vaapi_surface_set_property(
     case PROP_CHROMA_TYPE:
         priv->chroma_type = g_value_get_uint(value);
         break;
+    case PROP_PARENT_CONTEXT:
+        gst_vaapi_surface_set_parent_context(surface, g_value_get_object(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -211,6 +219,9 @@ gst_vaapi_surface_get_property(
     case PROP_CHROMA_TYPE:
         g_value_set_uint(value, gst_vaapi_surface_get_chroma_type(surface));
         break;
+    case PROP_PARENT_CONTEXT:
+        g_value_set_object(value, gst_vaapi_surface_get_parent_context(surface));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -268,6 +279,15 @@ gst_vaapi_surface_class_init(GstVaapiSurfaceClass *klass)
                            "The chroma type of the surface",
                            0, G_MAXUINT32, 0,
                            G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
+    g_object_class_install_property
+        (object_class,
+         PROP_PARENT_CONTEXT,
+         g_param_spec_object("parent-context",
+                             "Parent Context",
+                             "The parent context, if any",
+                             GST_VAAPI_TYPE_CONTEXT,
+                             G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -275,11 +295,12 @@ gst_vaapi_surface_init(GstVaapiSurface *surface)
 {
     GstVaapiSurfacePrivate *priv = GST_VAAPI_SURFACE_GET_PRIVATE(surface);
 
-    surface->priv       = priv;
-    priv->width         = 0;
-    priv->height        = 0;
-    priv->chroma_type   = 0;
-    priv->subpictures   = NULL;
+    surface->priv        = priv;
+    priv->width          = 0;
+    priv->height         = 0;
+    priv->chroma_type    = 0;
+    priv->subpictures    = NULL;
+    priv->parent_context = NULL;
 }
 
 /**
@@ -402,6 +423,54 @@ gst_vaapi_surface_get_size(
 }
 
 /**
+ * gst_vaapi_surface_set_parent_context:
+ * @surface: a #GstVaapiSurface
+ * @context: a #GstVaapiContext
+ *
+ * Sets new parent context, or clears any parent context if @context
+ * is %NULL. This function owns an extra reference to the context,
+ * which will be released when the surface is destroyed.
+ */
+void
+gst_vaapi_surface_set_parent_context(
+    GstVaapiSurface *surface,
+    GstVaapiContext *context
+)
+{
+    GstVaapiSurfacePrivate *priv;
+
+    g_return_if_fail(GST_VAAPI_IS_SURFACE(surface));
+
+    priv = surface->priv;
+
+    if (priv->parent_context) {
+        g_object_unref(priv->parent_context);
+        priv->parent_context = NULL;
+    }
+
+    if (context)
+        priv->parent_context = g_object_ref(context);
+}
+
+/**
+ * gst_vaapi_surface_get_parent_context:
+ * @surface: a #GstVaapiSurface
+ *
+ * Retrieves the parent #GstVaapiContext, or %NULL if there is
+ * none. The surface shall still own a reference to the context.
+ * i.e. the caller shall not unreference the returned context object.
+ *
+ * Return value: the parent context, if any.
+ */
+GstVaapiContext *
+gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface)
+{
+    g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
+
+    return surface->priv->parent_context;
+}
+
+/**
  * gst_vaapi_surface_derive_image:
  * @surface: a #GstVaapiSurface
  *
index c80c065..0741878 100644 (file)
@@ -35,6 +35,7 @@ G_BEGIN_DECLS
 typedef enum _GstVaapiChromaType                GstVaapiChromaType;
 typedef enum _GstVaapiSurfaceStatus             GstVaapiSurfaceStatus;
 typedef enum _GstVaapiSurfaceRenderFlags        GstVaapiSurfaceRenderFlags;
+typedef struct _GstVaapiContext                 GstVaapiContext;
 
 /**
  * GST_VAAPI_SURFACE_CAPS_NAME:
@@ -197,6 +198,9 @@ gst_vaapi_surface_get_size(
     guint           *pheight
 );
 
+GstVaapiContext *
+gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface);
+
 GstVaapiImage *
 gst_vaapi_surface_derive_image(GstVaapiSurface *surface);
 
diff --git a/gst-libs/gst/vaapi/gstvaapisurface_priv.h b/gst-libs/gst/vaapi/gstvaapisurface_priv.h
new file mode 100644 (file)
index 0000000..7c99c69
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *  gstvaapisurface_priv.h - VA surface abstraction (private data)
+ *
+ *  Copyright (C) 2011 Intel Corporation
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#ifndef GST_VAAPI_SURFACE_PRIV_H
+#define GST_VAAPI_SURFACE_PRIV_H
+
+#include <gst/vaapi/gstvaapisurface.h>
+
+void
+gst_vaapi_surface_set_parent_context(
+    GstVaapiSurface *surface,
+    GstVaapiContext *context
+) attribute_hidden;
+
+#endif /* GST_VAAPI_SURFACE_PRIV_H */