Fix `transfer` gobject-introspection annotation typos
[platform/upstream/gstreamer.git] / subprojects / gstreamer-vaapi / gst-libs / gst / vaapi / gstvaapivalue.c
1 /*
2  *  gstvaapivalue.c - GValue implementations specific to VA-API
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6  *  Copyright (C) 2012-2014 Intel Corporation
7  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24
25 /**
26  * SECTION:gstvaapivalue
27  * @short_description: GValue implementations specific to VA-API
28  */
29
30 #include "sysdeps.h"
31 #include <gobject/gvaluecollector.h>
32 #include "gstvaapivalue.h"
33
34 #define DEBUG 1
35 #include "gstvaapidebug.h"
36
37 static gpointer
38 default_copy_func (gpointer data)
39 {
40   return data;
41 }
42
43 static void
44 default_free_func (gpointer data)
45 {
46 }
47
48 /* --- GstVaapiPoint --- */
49
50 GType
51 gst_vaapi_point_get_type (void)
52 {
53   static gsize g_type = 0;
54
55   if (g_once_init_enter (&g_type)) {
56     GType type =
57         g_boxed_type_register_static (g_intern_static_string ("GstVaapiPoint"),
58         default_copy_func, default_free_func);
59     gst_type_mark_as_plugin_api (type, 0);
60     g_once_init_leave (&g_type, type);
61   }
62   return g_type;
63 }
64
65 /* --- GstVaapiRectangle --- */
66
67 GType
68 gst_vaapi_rectangle_get_type (void)
69 {
70   static gsize g_type = 0;
71
72   if (g_once_init_enter (&g_type)) {
73     GType type =
74         g_boxed_type_register_static (g_intern_static_string
75         ("GstVaapiRectangle"),
76         default_copy_func, default_free_func);
77     gst_type_mark_as_plugin_api (type, 0);
78     g_once_init_leave (&g_type, type);
79   }
80   return g_type;
81 }
82
83 /* --- GstVaapiRenderMode --- */
84
85 GType
86 gst_vaapi_render_mode_get_type (void)
87 {
88   static gsize g_type = 0;
89
90   static const GEnumValue render_modes[] = {
91     {GST_VAAPI_RENDER_MODE_OVERLAY,
92         "Overlay render mode", "overlay"},
93     {GST_VAAPI_RENDER_MODE_TEXTURE,
94         "Textured-blit render mode", "texture"},
95     {0, NULL, NULL}
96   };
97
98   if (g_once_init_enter (&g_type)) {
99     GType type = g_enum_register_static ("GstVaapiRenderMode", render_modes);
100     gst_type_mark_as_plugin_api (type, 0);
101     g_once_init_leave (&g_type, type);
102   }
103   return g_type;
104 }
105
106 /* --- GstVaapiRotation --- */
107
108 GType
109 gst_vaapi_rotation_get_type (void)
110 {
111   static gsize g_type = 0;
112
113   static const GEnumValue rotation_values[] = {
114     {GST_VAAPI_ROTATION_0,
115         "Unrotated mode", "0"},
116     {GST_VAAPI_ROTATION_90,
117         "Rotated by 90°, clockwise", "90"},
118     {GST_VAAPI_ROTATION_180,
119         "Rotated by 180°, clockwise", "180"},
120     {GST_VAAPI_ROTATION_270,
121         "Rotated by 270°, clockwise", "270"},
122     {GST_VAAPI_ROTATION_AUTOMATIC,
123         "Rotated by image-orientating tag°", "Automatic"},
124     {0, NULL, NULL},
125   };
126
127   if (g_once_init_enter (&g_type)) {
128     GType type = g_enum_register_static ("GstVaapiRotation", rotation_values);
129     gst_type_mark_as_plugin_api (type, 0);
130     g_once_init_leave (&g_type, type);
131   }
132   return g_type;
133 }
134
135 /* --- GstVaapiRateControl --- */
136
137 GType
138 gst_vaapi_rate_control_get_type (void)
139 {
140   static gsize g_type = 0;
141
142   static const GEnumValue rate_control_values[] = {
143     {GST_VAAPI_RATECONTROL_NONE,
144         "None", "none"},
145     {GST_VAAPI_RATECONTROL_CQP,
146         "Constant QP", "cqp"},
147     {GST_VAAPI_RATECONTROL_CBR,
148         "Constant bitrate", "cbr"},
149     {GST_VAAPI_RATECONTROL_VCM,
150         "Video conference", "vcm"},
151     {GST_VAAPI_RATECONTROL_VBR,
152         "Variable bitrate", "vbr"},
153     {GST_VAAPI_RATECONTROL_VBR_CONSTRAINED,
154         "Variable bitrate - Constrained", "vbr_constrained"},
155     {GST_VAAPI_RATECONTROL_MB,
156         "Macroblock based rate control", "mb"},
157     {GST_VAAPI_RATECONTROL_ICQ,
158         "Constant QP - Intelligent", "icq"},
159     {GST_VAAPI_RATECONTROL_QVBR,
160         "Variable bitrate - Quality defined", "qvbr"},
161     {0, NULL, NULL},
162   };
163
164   if (g_once_init_enter (&g_type)) {
165     GType type = g_enum_register_static ("GstVaapiRateControl",
166         rate_control_values);
167     gst_type_mark_as_plugin_api (type, 0);
168     g_once_init_leave (&g_type, type);
169   }
170   return g_type;
171 }
172
173 static gboolean
174 build_enum_subset_values_from_mask (GstVaapiEnumSubset * subset, guint32 mask)
175 {
176   GEnumClass *enum_class;
177   const GEnumValue *value;
178   guint i, n;
179
180   enum_class = g_type_class_ref (subset->parent_type);
181   if (!enum_class)
182     return FALSE;
183
184   for (i = 0, n = 0; i < 32 && n < subset->num_values; i++) {
185     if (!(mask & (1U << i)))
186       continue;
187     value = g_enum_get_value (enum_class, i);
188     if (!value)
189       continue;
190     subset->values[n++] = *value;
191   }
192   g_type_class_unref (enum_class);
193   if (n != subset->num_values - 1)
194     goto error_invalid_num_values;
195   return TRUE;
196
197   /* ERRORS */
198 error_invalid_num_values:
199   {
200     GST_ERROR ("invalid number of static values for `%s'", subset->type_name);
201     return FALSE;
202   }
203 }
204
205 GType
206 gst_vaapi_type_define_enum_subset_from_mask (GstVaapiEnumSubset * subset,
207     guint32 mask)
208 {
209   if (g_once_init_enter (&subset->type)) {
210     GType type;
211
212     build_enum_subset_values_from_mask (subset, mask);
213     memset (&subset->type_info, 0, sizeof (subset->type_info));
214     g_enum_complete_type_info (subset->parent_type, &subset->type_info,
215         subset->values);
216
217     type = g_type_register_static (G_TYPE_ENUM, subset->type_name,
218         &subset->type_info, 0);
219     g_once_init_leave (&subset->type, type);
220   }
221   return subset->type;
222 }
223
224 /**
225  * gst_vaapi_enum_type_get_nick:
226  * @type: an enum #GType
227  * @value: the value to get its nick
228  *
229  * Returns: (transfer none); the string associated with
230  *   @value. Otherwise "<unknown>"
231  **/
232 const gchar *
233 gst_vaapi_enum_type_get_nick (GType type, gint value)
234 {
235   gpointer const klass = g_type_class_peek (type);
236   GEnumValue *const e = g_enum_get_value (klass, value);
237
238   if (e)
239     return e->value_nick;
240   return "<unknown>";
241 }