gstvaapiobject.c 6.71 KB
Newer Older
1 2 3
/*
 *  gstvaapiobject.c - Base VA object
 *
4
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5
 *
6 7 8 9
 *  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.
10
 *
11
 *  This library is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
15
 *
16 17 18 19
 *  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
20 21
 */

gb's avatar
gb committed
22 23 24 25 26
/**
 * SECTION:gstvaapiobject
 * @short_description: Base VA object
 */

27
#include "sysdeps.h"
28
#include "gstvaapiobject.h"
29
#include "gstvaapi_priv.h"
30
#include "gstvaapiparamspecs.h"
31
#include "gstvaapivalue.h"
gb's avatar
gb committed
32
#include "gstvaapimarshal.h"
33 34 35 36 37 38 39 40 41 42

#define DEBUG 1
#include "gstvaapidebug.h"

G_DEFINE_TYPE(GstVaapiObject, gst_vaapi_object, G_TYPE_OBJECT);

enum {
    PROP_0,

    PROP_DISPLAY,
43
    PROP_ID
44 45
};

gb's avatar
gb committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
enum {
    DESTROY,

    LAST_SIGNAL
};

static guint object_signals[LAST_SIGNAL] = { 0, };

static void
gst_vaapi_object_dispose(GObject *object)
{
    GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv;

    if (!priv->is_destroying) {
        priv->is_destroying = TRUE;
        g_signal_emit(object, object_signals[DESTROY], 0);
        priv->is_destroying = FALSE;
    }

    G_OBJECT_CLASS(gst_vaapi_object_parent_class)->dispose(object);
}

68 69 70 71 72
static void
gst_vaapi_object_finalize(GObject *object)
{
    GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv;

73
    priv->id = GST_VAAPI_ID_NONE;
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    if (priv->display) {
        g_object_unref(priv->display);
        priv->display = NULL;
    }

    G_OBJECT_CLASS(gst_vaapi_object_parent_class)->finalize(object);
}

static void
gst_vaapi_object_set_property(
    GObject      *gobject,
    guint         prop_id,
    const GValue *value,
    GParamSpec   *pspec
)
{
    GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);

    switch (prop_id) {
    case PROP_DISPLAY:
        object->priv->display = g_object_ref(g_value_get_object(value));
        break;
97 98 99
    case PROP_ID:
        object->priv->id = gst_vaapi_value_get_id(value);
        break;
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
        break;
    }
}

static void
gst_vaapi_object_get_property(
    GObject    *gobject,
    guint       prop_id,
    GValue     *value,
    GParamSpec *pspec
)
{
    GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);

    switch (prop_id) {
    case PROP_DISPLAY:
        g_value_set_object(value, gst_vaapi_object_get_display(object));
        break;
120 121 122
    case PROP_ID:
        gst_vaapi_value_set_id(value, gst_vaapi_object_get_id(object));
        break;
123 124 125 126 127 128 129 130 131 132 133 134 135
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
        break;
    }
}

static void
gst_vaapi_object_class_init(GstVaapiObjectClass *klass)
{
    GObjectClass * const object_class = G_OBJECT_CLASS(klass);

    g_type_class_add_private(klass, sizeof(GstVaapiObjectPrivate));

gb's avatar
gb committed
136
    object_class->dispose      = gst_vaapi_object_dispose;
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    object_class->finalize     = gst_vaapi_object_finalize;
    object_class->set_property = gst_vaapi_object_set_property;
    object_class->get_property = gst_vaapi_object_get_property;

    /**
     * GstVaapiObject:display:
     *
     * The #GstVaapiDisplay this object is bound to.
     */
    g_object_class_install_property
        (object_class,
         PROP_DISPLAY,
         g_param_spec_object("display",
                             "Display",
                             "The GstVaapiDisplay this object is bound to",
                             GST_VAAPI_TYPE_DISPLAY,
                             G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
gb's avatar
gb committed
154

155 156 157 158 159 160 161 162 163 164 165
    /**
     * GstVaapiObject:id:
     *
     * The #GstVaapiID contained in this object.
     */
    g_object_class_install_property
        (object_class,
         PROP_ID,
         gst_vaapi_param_spec_id("id",
                                 "ID",
                                 "The GstVaapiID contained in this object",
166
                                 GST_VAAPI_ID_NONE,
167 168
                                 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));

gb's avatar
gb committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    /**
     * GstVaapiObject::destroy:
     * @object: the object which received the signal
     *
     * The ::destroy signal is emitted when an object is destroyed,
     * when the user released the last reference to @object.
     */
    object_signals[DESTROY] = g_signal_new(
        "destroy",
        G_TYPE_FROM_CLASS(object_class),
        G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
        G_STRUCT_OFFSET(GstVaapiObjectClass, destroy),
        NULL, NULL,
        gst_vaapi_marshal_VOID__VOID,
        G_TYPE_NONE, 0
    );
185 186 187 188 189 190 191
}

static void
gst_vaapi_object_init(GstVaapiObject *object)
{
    GstVaapiObjectPrivate *priv = GST_VAAPI_OBJECT_GET_PRIVATE(object);

gb's avatar
gb committed
192 193
    object->priv        = priv;
    priv->display       = NULL;
194
    priv->id            = GST_VAAPI_ID_NONE;
gb's avatar
gb committed
195
    priv->is_destroying = FALSE;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
}

/**
 * gst_vaapi_object_get_display:
 * @object: a #GstVaapiObject
 *
 * Returns the #GstVaapiDisplay this @object is bound to.
 *
 * Return value: the parent #GstVaapiDisplay object
 */
GstVaapiDisplay *
gst_vaapi_object_get_display(GstVaapiObject *object)
{
    g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL);

    return object->priv->display;
}
213

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/**
 * gst_vaapi_object_lock_display:
 * @object: a #GstVaapiObject
 *
 * Locks @object parent display. If display is already locked by
 * another thread, the current thread will block until display is
 * unlocked by the other thread.
 */
void
gst_vaapi_object_lock_display(GstVaapiObject *object)
{
    g_return_if_fail(GST_VAAPI_IS_OBJECT(object));

    GST_VAAPI_OBJECT_LOCK_DISPLAY(object);
}

/**
 * gst_vaapi_object_unlock_display:
 * @object: a #GstVaapiObject
 *
 * Unlocks @object parent display. If another thread is blocked in a
 * gst_vaapi_object_lock_display() call, it will be woken and can lock
 * display itself.
 */
void
gst_vaapi_object_unlock_display(GstVaapiObject *object)
{
    g_return_if_fail(GST_VAAPI_IS_OBJECT(object));

    GST_VAAPI_OBJECT_UNLOCK_DISPLAY(object);
}

246 247 248 249 250 251 252 253 254 255 256
/**
 * gst_vaapi_object_get_id:
 * @object: a #GstVaapiObject
 *
 * Returns the #GstVaapiID contained in the @object.
 *
 * Return value: the #GstVaapiID of the @object
 */
GstVaapiID
gst_vaapi_object_get_id(GstVaapiObject *object)
{
257
    g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), GST_VAAPI_ID_NONE);
258 259 260

    return object->priv->id;
}