display: add support for rotation modes.
[platform/upstream/gstreamer-vaapi.git] / 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  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  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  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 /**
23  * SECTION:gstvaapivalue
24  * @short_description: GValue implementations specific to VA-API
25  */
26
27 #include "sysdeps.h"
28 #include <gobject/gvaluecollector.h>
29 #include "gstvaapivalue.h"
30
31 static GTypeInfo gst_vaapi_type_info = {
32     0,
33     NULL,
34     NULL,
35     NULL,
36     NULL,
37     NULL,
38     0,
39     0,
40     NULL,
41     NULL,
42 };
43
44 static GTypeFundamentalInfo gst_vaapi_type_finfo = {
45     0
46 };
47
48 #define GST_VAAPI_TYPE_DEFINE(type, name)                               \
49 GType gst_vaapi_ ## type ## _get_type(void)                             \
50 {                                                                       \
51     static GType gst_vaapi_ ## type ## _type = 0;                       \
52                                                                         \
53     if (G_UNLIKELY(gst_vaapi_ ## type ## _type == 0)) {                 \
54         gst_vaapi_type_info.value_table =                               \
55             &gst_vaapi_ ## type ## _value_table;                        \
56         gst_vaapi_ ## type ## _type = g_type_register_fundamental(      \
57             g_type_fundamental_next(),                                  \
58             name,                                                       \
59             &gst_vaapi_type_info,                                       \
60             &gst_vaapi_type_finfo,                                      \
61             0                                                           \
62         );                                                              \
63     }                                                                   \
64     return gst_vaapi_ ## type ## _type;                                 \
65 }
66
67 /* --- GstVaapiID --- */
68
69 #if GST_VAAPI_TYPE_ID_SIZE == 4
70 # define GST_VAAPI_VALUE_ID_(cvalue)    ((cvalue).v_int)
71 # define GST_VAAPI_VALUE_ID_CFORMAT     "i"
72 #elif GST_VAAPI_TYPE_ID_SIZE == 8
73 # define GST_VAAPI_VALUE_ID_(cvalue)    ((cvalue).v_int64)
74 # define GST_VAAPI_VALUE_ID_CFORMAT     "q"
75 #else
76 # error "unsupported GstVaapiID size"
77 #endif
78 #define GST_VAAPI_VALUE_ID(value)       GST_VAAPI_VALUE_ID_((value)->data[0])
79
80 static void
81 gst_vaapi_value_id_init(GValue *value)
82 {
83     GST_VAAPI_VALUE_ID(value) = 0;
84 }
85
86 static void
87 gst_vaapi_value_id_copy(const GValue *src_value, GValue *dst_value)
88 {
89     GST_VAAPI_VALUE_ID(dst_value) = GST_VAAPI_VALUE_ID(src_value);
90 }
91
92 static gchar *
93 gst_vaapi_value_id_collect(
94     GValue      *value,
95     guint        n_collect_values,
96     GTypeCValue *collect_values,
97     guint        collect_flags
98 )
99 {
100     GST_VAAPI_VALUE_ID(value) = GST_VAAPI_VALUE_ID_(collect_values[0]);
101
102     return NULL;
103 }
104
105 static gchar *
106 gst_vaapi_value_id_lcopy(
107     const GValue *value,
108     guint         n_collect_values,
109     GTypeCValue  *collect_values,
110     guint         collect_flags
111 )
112 {
113     GstVaapiID *id_p = collect_values[0].v_pointer;
114
115     if (!id_p)
116         return g_strdup_printf("value location for `%s' passed as NULL",
117                                G_VALUE_TYPE_NAME(value));
118
119     *id_p = GST_VAAPI_VALUE_ID(value);
120     return NULL;
121 }
122
123 static const GTypeValueTable gst_vaapi_id_value_table = {
124     gst_vaapi_value_id_init,
125     NULL,
126     gst_vaapi_value_id_copy,
127     NULL,
128     GST_VAAPI_VALUE_ID_CFORMAT,
129     gst_vaapi_value_id_collect,
130     "p",
131     gst_vaapi_value_id_lcopy
132 };
133
134 GST_VAAPI_TYPE_DEFINE(id, "GstVaapiID");
135
136 /**
137  * gst_vaapi_value_get_id:
138  * @value: a GValue initialized to #GstVaapiID
139  *
140  * Gets the integer contained in @value.
141  *
142  * Return value: the integer contained in @value
143  */
144 GstVaapiID
145 gst_vaapi_value_get_id(const GValue *value)
146 {
147     g_return_val_if_fail(GST_VAAPI_VALUE_HOLDS_ID(value), 0);
148
149     return GST_VAAPI_VALUE_ID(value);
150 }
151
152 /**
153  * gst_vaapi_value_set_id:
154  * @value: a GValue initialized to #GstVaapiID
155  * @id: a #GstVaapiID
156  *
157  * Sets the integer contained in @id to @value.
158  */
159 void
160 gst_vaapi_value_set_id(GValue *value, GstVaapiID id)
161 {
162     g_return_if_fail(GST_VAAPI_VALUE_HOLDS_ID(value));
163
164     GST_VAAPI_VALUE_ID(value) = id;
165 }
166
167 /* --- GstVaapiRenderMode --- */
168
169 GType
170 gst_vaapi_render_mode_get_type(void)
171 {
172     static GType render_mode_type = 0;
173
174     static const GEnumValue render_modes[] = {
175         { GST_VAAPI_RENDER_MODE_OVERLAY,
176           "Overlay render mode", "overlay" },
177         { GST_VAAPI_RENDER_MODE_TEXTURE,
178           "Textured-blit render mode", "texture" },
179         { 0, NULL, NULL }
180     };
181
182     if (!render_mode_type) {
183         render_mode_type =
184             g_enum_register_static("GstVaapiRenderMode", render_modes);
185     }
186     return render_mode_type;
187 }
188
189 /* --- GstVaapiRotation --- */
190
191 GType
192 gst_vaapi_rotation_get_type(void)
193 {
194     static GType g_type = 0;
195
196     static const GEnumValue rotation_values[] = {
197         { GST_VAAPI_ROTATION_0,
198           "Unrotated mode", "0" },
199         { GST_VAAPI_ROTATION_90,
200           "Rotated by 90°, clockwise", "90" },
201         { GST_VAAPI_ROTATION_180,
202           "Rotated by 180°, clockwise", "180" },
203         { GST_VAAPI_ROTATION_270,
204           "Rotated by 270°, clockwise", "270" },
205     };
206
207     if (!g_type)
208         g_type = g_enum_register_static("GstVaapiRotation", rotation_values);
209     return g_type;
210 }