Tizen 2.1 base
[framework/multimedia/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapiparamspecs.c
1 /*
2  *  gstvaapiparamspecs.c - GParamSpecs for some of our types
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:gstvaapiparamspecs
24  * @short_description: GParamSpecs for some of our types
25  */
26
27 #include "sysdeps.h"
28 #include "gstvaapiparamspecs.h"
29 #include "gstvaapivalue.h"
30
31 /* --- GstVaapiParamSpecID --- */
32
33 static void
34 gst_vaapi_param_id_init(GParamSpec *pspec)
35 {
36     GST_VAAPI_PARAM_SPEC_ID(pspec)->default_value = GST_VAAPI_ID_NONE;
37 }
38
39 static void
40 gst_vaapi_param_id_set_default(GParamSpec *pspec, GValue *value)
41 {
42     gst_vaapi_value_set_id(value, GST_VAAPI_PARAM_SPEC_ID(pspec)->default_value);
43 }
44
45 static gboolean
46 gst_vaapi_param_id_validate(GParamSpec *pspec, GValue *value)
47 {
48     /* Return FALSE if everything is OK, otherwise TRUE */
49     return FALSE;
50 }
51
52 static gint
53 gst_vaapi_param_id_compare(
54     GParamSpec   *pspec,
55     const GValue *value1,
56     const GValue *value2
57 )
58 {
59     const GstVaapiID v1 = gst_vaapi_value_get_id(value1);
60     const GstVaapiID v2 = gst_vaapi_value_get_id(value2);
61
62     return (v1 < v2 ? -1 : (v1 > v2 ? 1 : 0));
63 }
64
65 GType
66 gst_vaapi_param_spec_id_get_type(void)
67 {
68     static GType type;
69
70     if (G_UNLIKELY(type == 0)) {
71         static GParamSpecTypeInfo pspec_info = {
72             sizeof(GstVaapiParamSpecID),        /* instance_size     */
73             0,                                  /* n_preallocs       */
74             gst_vaapi_param_id_init,            /* instance_init     */
75             G_TYPE_INVALID,                     /* value_type        */
76             NULL,                               /* finalize          */
77             gst_vaapi_param_id_set_default,     /* value_set_default */
78             gst_vaapi_param_id_validate,        /* value_validate    */
79             gst_vaapi_param_id_compare,         /* values_cmp        */
80         };
81         pspec_info.value_type = GST_VAAPI_TYPE_ID;
82         type = g_param_type_register_static("GstVaapiParamSpecID", &pspec_info);
83     }
84     return type;
85 }
86
87 /**
88  * gst_vaapi_param_spec_id:
89  * @name: canonical name of the property specified
90  * @nick: nick name for the property specified
91  * @blurb: description of the property specified
92  * @default_value: default value
93  * @flags: flags for the property specified
94  *
95  * This function creates an ID GParamSpec for use by #GstVaapiObject
96  * objects. This function is typically used in connection with
97  * g_object_class_install_property() in a GObjects's instance_init
98  * function.
99  *
100  * Return value: a newly created parameter specification
101  */
102 GParamSpec *
103 gst_vaapi_param_spec_id(
104     const gchar *name,
105     const gchar *nick,
106     const gchar *blurb,
107     GstVaapiID   default_value,
108     GParamFlags  flags
109 )
110 {
111     GstVaapiParamSpecID *ispec;
112     GParamSpec *pspec;
113     GValue value = { 0, };
114
115     ispec = g_param_spec_internal(
116         GST_VAAPI_TYPE_PARAM_ID,
117         name,
118         nick,
119         blurb,
120         flags
121     );
122     if (!ispec)
123         return NULL;
124
125     ispec->default_value = default_value;
126     pspec = G_PARAM_SPEC(ispec);
127
128     /* Validate default value */
129     g_value_init(&value, GST_VAAPI_TYPE_ID);
130     gst_vaapi_value_set_id(&value, default_value);
131     if (gst_vaapi_param_id_validate(pspec, &value)) {
132         g_param_spec_ref(pspec);
133         g_param_spec_sink(pspec);
134         g_param_spec_unref(pspec);
135         pspec = NULL;
136     }
137     g_value_unset(&value);
138
139     return pspec;
140 }