Initial release
[adaptation/ap_samsung/gst-plugins-s5pc2xx.git] / camerasrc / src / gstcamerasrccolorbalance.c
1 /*
2  * camerasrc
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jeongmo Yang <jm80.yang@samsung.com>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at your option)
11  * any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc., 51
20  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29 #include "gstcamerasrccolorbalance.h"
30
31 GST_BOILERPLATE( GstCameraSrcColorBalanceChannel,
32                  gst_camerasrc_color_balance_channel,
33                  GstColorBalanceChannel,
34                  GST_TYPE_COLOR_BALANCE_CHANNEL );
35
36 #ifndef GST_CAT_DEFAULT
37 GST_DEBUG_CATEGORY_EXTERN(camerasrc_debug);
38 #define GST_CAT_DEFAULT camerasrc_debug
39 #endif /* GST_CAT_DEFAULT */
40
41 static void
42 gst_camerasrc_color_balance_channel_base_init( gpointer g_class )
43 {
44 }
45
46 static void
47 gst_camerasrc_color_balance_channel_class_init( GstCameraSrcColorBalanceChannelClass* klass )
48 {
49 }
50
51 static void
52 gst_camerasrc_color_balance_channel_init( GstCameraSrcColorBalanceChannel* camerasrc_color_channel, GstCameraSrcColorBalanceChannelClass* klass )
53 {
54         camerasrc_color_channel->id = (guint32) - 1;
55 }
56
57 static G_GNUC_UNUSED gboolean
58 gst_camerasrc_color_balance_contains_channel( GstCameraSrc* camerasrc, GstCameraSrcColorBalanceChannel* camerasrc_color_channel )
59 {
60         const GList *item;
61
62         for( item = camerasrc->colors ; item != NULL ; item = item->next )
63         {
64                 if (item->data == camerasrc_color_channel)
65                         return TRUE;
66         }
67
68         return FALSE;
69 }
70
71 const GList *
72 gst_camerasrc_color_balance_list_channels( GstCameraSrc* camerasrc )
73 {
74   return camerasrc->colors;
75 }
76
77 void
78 gst_camerasrc_color_balance_set_value( GstCameraSrc* camerasrc, GstColorBalanceChannel* color_channel, gint value )
79 {
80         int error = CAMERASRC_ERR_UNKNOWN;
81
82         GstCameraSrcColorBalanceChannel *camerasrc_color_channel = GST_CAMERASRC_COLOR_BALANCE_CHANNEL( color_channel );
83
84         /* assert that we're opened and that we're using a known item */
85         g_return_if_fail( camerasrc );
86         g_return_if_fail( gst_camerasrc_color_balance_contains_channel( camerasrc, camerasrc_color_channel ) );
87
88         error = camerasrc_set_control( camerasrc->v4l2_handle, camerasrc_color_channel->id, value );
89
90         if( error != CAMERASRC_SUCCESS )
91         {
92                 GST_WARNING("Failed to Set ColorBalance[%s],value[%d]", camerasrc_color_channel->parent.label, value);
93         }
94 }
95
96 gint
97 gst_camerasrc_color_balance_get_value( GstCameraSrc* camerasrc, GstColorBalanceChannel* color_channel )
98 {
99         int error, value;
100         GstCameraSrcColorBalanceChannel *camerasrc_color_channel = GST_CAMERASRC_COLOR_BALANCE_CHANNEL( color_channel );
101
102         /* assert that we're opened and that we're using a known item */
103         g_return_val_if_fail( camerasrc, FALSE );
104         g_return_val_if_fail( gst_camerasrc_color_balance_contains_channel( camerasrc, camerasrc_color_channel ), FALSE );
105
106         error = camerasrc_get_control( camerasrc->v4l2_handle, camerasrc_color_channel->id, &value );
107
108         if( error != CAMERASRC_SUCCESS )
109         {
110                 GST_WARNING("Failed to Get ColorBalance[%s].", camerasrc_color_channel->parent.label);
111                 return FALSE;
112         }
113
114         return value;
115 }
116
117