summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapiminiobject.h
blob: 562c5fc47293279d94f77fdcbe080c8eff32623d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 *  gstvaapiminiobject.h - A lightweight reference counted object
 *
 *  Copyright (C) 2012-2014 Intel Corporation
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
 *
 *  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_MINI_OBJECT_H
#define GST_VAAPI_MINI_OBJECT_H

#include <glib.h>
#include "libgstvaapi_priv_check.h"

G_BEGIN_DECLS

typedef struct _GstVaapiMiniObject              GstVaapiMiniObject;
typedef struct _GstVaapiMiniObjectClass         GstVaapiMiniObjectClass;

/**
 * GST_VAAPI_MINI_OBJECT:
 * @object: a #GstVaapiMiniObject
 *
 * Casts the @object to a #GstVaapiMiniObject
 */
#define GST_VAAPI_MINI_OBJECT(object) \
  ((GstVaapiMiniObject *) (object))

/**
 * GST_VAAPI_MINI_OBJECT_PTR:
 * @object_ptr: a pointer #GstVaapiMiniObject
 *
 * Casts the @object_ptr to a pointer to #GstVaapiMiniObject
 */
#define GST_VAAPI_MINI_OBJECT_PTR(object_ptr) \
  ((GstVaapiMiniObject **) (object_ptr))

/**
 * GST_VAAPI_MINI_OBJECT_CLASS:
 * @klass: a #GstVaapiMiniObjectClass
 *
 * Casts the @klass to a #GstVaapiMiniObjectClass
 */
#define GST_VAAPI_MINI_OBJECT_CLASS(klass) \
  ((GstVaapiMiniObjectClass *) (klass))

/**
 * GST_VAAPI_MINI_OBJECT_GET_CLASS:
 * @object: a #GstVaapiMiniObject
 *
 * Retrieves the #GstVaapiMiniObjectClass associated with the @object
 */
#define GST_VAAPI_MINI_OBJECT_GET_CLASS(object) \
  (GST_VAAPI_MINI_OBJECT (object)->object_class)

/**
 * GST_VAAPI_MINI_OBJECT_FLAGS:
 * @object: a #GstVaapiMiniObject
 *
 * The entire set of flags for the @object
 */
#define GST_VAAPI_MINI_OBJECT_FLAGS(object) \
  (GST_VAAPI_MINI_OBJECT (object)->flags)

/**
 * GST_VAAPI_MINI_OBJECT_FLAG_IS_SET:
 * @object: a #GstVaapiMiniObject
 * @flag: a flag to check for
 *
 * Checks whether the given @flag is set
 */
#define GST_VAAPI_MINI_OBJECT_FLAG_IS_SET(object, flag) \
  ((GST_VAAPI_MINI_OBJECT_FLAGS (object) & (flag)) != 0)

/**
 * GST_VAAPI_MINI_OBJECT_FLAG_SET:
 * @object: a #GstVaapiMiniObject
 * @flags: flags to set
 *
 * This macro sets the given bits
 */
#define GST_VAAPI_MINI_OBJECT_FLAG_SET(object, flags) \
  (GST_VAAPI_MINI_OBJECT_FLAGS (object) |= (flags))

/**
 * GST_VAAPI_MINI_OBJECT_FLAG_UNSET:
 * @object: a #GstVaapiMiniObject
 * @flags: flags to unset
 *
 * This macro unsets the given bits.
 */
#define GST_VAAPI_MINI_OBJECT_FLAG_UNSET(object, flags) \
  (GST_VAAPI_MINI_OBJECT_FLAGS (object) &= ~(flags))

/**
 * GstVaapiMiniObject:
 * @object_class: the #GstVaapiMiniObjectClass
 * @ref_count: the object reference count that should be manipulated
 *   through gst_vaapi_mini_object_ref() et al. helpers
 * @flags: set of flags that should be manipulated through
 *   GST_VAAPI_MINI_OBJECT_FLAG_*() functions
 *
 * A #GstVaapiMiniObject represents a minimal reference counted data
 * structure that can hold a set of flags and user-provided data.
 */
struct _GstVaapiMiniObject
{
  /*< private >*/
  gconstpointer object_class;
  volatile gint ref_count;
  guint flags;
};

/**
 * GstVaapiMiniObjectClass:
 * @size: size in bytes of the #GstVaapiMiniObject, plus any
 *   additional data for derived classes
 * @finalize: function called to destroy data in derived classes
 *
 * A #GstVaapiMiniObjectClass represents the base object class that
 * defines the size of the #GstVaapiMiniObject and utility function to
 * dispose child objects
 */
struct _GstVaapiMiniObjectClass
{
  /*< protected >*/
  guint size;
  GDestroyNotify finalize;
};

GstVaapiMiniObject *
gst_vaapi_mini_object_new (const GstVaapiMiniObjectClass * object_class);

GstVaapiMiniObject *
gst_vaapi_mini_object_new0 (const GstVaapiMiniObjectClass * object_class);

GstVaapiMiniObject *
gst_vaapi_mini_object_ref (GstVaapiMiniObject * object);

void
gst_vaapi_mini_object_unref (GstVaapiMiniObject * object);

void
gst_vaapi_mini_object_replace (GstVaapiMiniObject ** old_object_ptr,
    GstVaapiMiniObject * new_object);

#ifdef IN_LIBGSTVAAPI_CORE
#undef  gst_vaapi_mini_object_ref
#define gst_vaapi_mini_object_ref(object) \
  gst_vaapi_mini_object_ref_internal (object)

#undef  gst_vaapi_mini_object_unref
#define gst_vaapi_mini_object_unref(object) \
  gst_vaapi_mini_object_unref_internal (object)

G_GNUC_INTERNAL
void
gst_vaapi_mini_object_free (GstVaapiMiniObject * object);

/**
 * gst_vaapi_mini_object_ref_internal:
 * @object: a #GstVaapiMiniObject
 *
 * Atomically increases the reference count of the given @object by one.
 * This is an internal function that does not do any run-time type check.
 *
 * Returns: The same @object argument
 */
static inline GstVaapiMiniObject *
gst_vaapi_mini_object_ref_internal (GstVaapiMiniObject * object)
{
  g_atomic_int_inc (&object->ref_count);
  return object;
}

/**
 * gst_vaapi_mini_object_unref_internal:
 * @object: a #GstVaapiMiniObject
 *
 * Atomically decreases the reference count of the @object by one. If
 * the reference count reaches zero, the object will be free'd.
 *
 * This is an internal function that does not do any run-time type check.
 */
static inline void
gst_vaapi_mini_object_unref_internal (GstVaapiMiniObject * object)
{
  if (g_atomic_int_dec_and_test (&object->ref_count))
    gst_vaapi_mini_object_free (object);
}
#endif

G_END_DECLS

#endif /* GST_VAAPI_MINI_OBJECT_H */