0fd18677f6d57be3e4bbc683d9c1d5c773f44a99
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2colorbalance.c
1 /* GStreamer Color Balance interface implementation
2  * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  *
4  * gstv4l2colorbalance.c: color balance interface implementation for V4L2
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <gst/gst.h>
27 #include "gstv4l2colorbalance.h"
28 #include "gstv4l2element.h"
29
30 static void
31 gst_v4l2_color_balance_channel_class_init(GstV4l2ColorBalanceChannelClass *klass);
32 static void
33 gst_v4l2_color_balance_channel_init     (GstV4l2ColorBalanceChannel *channel);
34
35 static const GList *
36 gst_v4l2_color_balance_list_channels    (GstColorBalance        *balance);
37 static void
38 gst_v4l2_color_balance_set_value        (GstColorBalance        *balance,
39                                          GstColorBalanceChannel *channel,
40                                          gint                    value);
41 static gint
42 gst_v4l2_color_balance_get_value        (GstColorBalance        *balance,
43                                          GstColorBalanceChannel *channel);
44
45 static GstColorBalanceChannelClass *parent_class = NULL;
46
47 GType
48 gst_v4l2_color_balance_channel_get_type (void)
49 {
50   static GType gst_v4l2_color_balance_channel_type = 0;
51
52   if (!gst_v4l2_color_balance_channel_type) {
53     static const GTypeInfo v4l2_tuner_channel_info = {
54       sizeof (GstV4l2ColorBalanceChannelClass),
55       NULL,
56       NULL,
57       (GClassInitFunc) gst_v4l2_color_balance_channel_class_init,
58       NULL,
59       NULL,
60       sizeof (GstV4l2ColorBalanceChannel),
61       0,
62       (GInstanceInitFunc) gst_v4l2_color_balance_channel_init,
63       NULL
64     };
65
66     gst_v4l2_color_balance_channel_type =
67         g_type_register_static (GST_TYPE_COLOR_BALANCE_CHANNEL,
68                                 "GstV4l2ColorBalanceChannel",
69                                 &v4l2_tuner_channel_info, 0);
70   }
71
72   return gst_v4l2_color_balance_channel_type;
73 }
74
75 static void
76 gst_v4l2_color_balance_channel_class_init (GstV4l2ColorBalanceChannelClass *klass)
77 {
78   parent_class = g_type_class_ref (GST_TYPE_COLOR_BALANCE_CHANNEL);
79 }
80
81 static void
82 gst_v4l2_color_balance_channel_init (GstV4l2ColorBalanceChannel *channel)
83 {
84   channel->index = 0;
85 }
86
87 void
88 gst_v4l2_color_balance_interface_init (GstColorBalanceClass *klass)
89 {
90   GST_COLOR_BALANCE_TYPE (klass) = GST_COLOR_BALANCE_HARDWARE;
91   
92   /* default virtual functions */
93   klass->list_channels = gst_v4l2_color_balance_list_channels;
94   klass->set_value = gst_v4l2_color_balance_set_value;
95   klass->get_value = gst_v4l2_color_balance_get_value;
96 }
97
98 static gboolean
99 gst_v4l2_color_balance_contains_channel (GstV4l2Element             *v4l2element,
100                                          GstV4l2ColorBalanceChannel *v4l2channel)
101 {
102   const GList *item;
103
104   for (item = v4l2element->colors; item != NULL; item = item->next)
105     if (item->data == v4l2channel)
106       return TRUE;
107
108   return FALSE;
109 }
110
111 static const GList *
112 gst_v4l2_color_balance_list_channels (GstColorBalance *balance)
113 {
114   return GST_V4L2ELEMENT (balance)->colors;
115 }
116
117 static void
118 gst_v4l2_color_balance_set_value (GstColorBalance        *balance,
119                                   GstColorBalanceChannel *channel,
120                                   gint                    value)
121 {
122   GstV4l2Element *v4l2element = GST_V4L2ELEMENT (balance);
123   GstV4l2ColorBalanceChannel *v4l2channel =
124         GST_V4L2_COLOR_BALANCE_CHANNEL (channel);
125
126   /* assert that we're opened and that we're using a known item */
127   g_return_if_fail (GST_V4L2_IS_OPEN (v4l2element));
128   g_return_if_fail (gst_v4l2_color_balance_contains_channel (v4l2element,
129                                                              v4l2channel));
130
131   gst_v4l2_set_attribute (v4l2element, v4l2channel->index, value);
132 }
133
134 static gint
135 gst_v4l2_color_balance_get_value (GstColorBalance        *balance,
136                                   GstColorBalanceChannel *channel)
137 {
138   GstV4l2Element *v4l2element = GST_V4L2ELEMENT (balance);
139   GstV4l2ColorBalanceChannel *v4l2channel =
140         GST_V4L2_COLOR_BALANCE_CHANNEL (channel);
141   gint value;
142
143   /* assert that we're opened and that we're using a known item */
144   g_return_val_if_fail (GST_V4L2_IS_OPEN (v4l2element), 0);
145   g_return_val_if_fail (gst_v4l2_color_balance_contains_channel (v4l2element,
146                                                                  v4l2channel),
147                         0);
148
149   if (!gst_v4l2_get_attribute (v4l2element, v4l2channel->index, &value))
150     return 0;
151
152   return value;
153 }