[tizencamerasrc] Support Next camera HAL for tizen 6.5
[platform/upstream/gst-plugins-tizen.git] / tizencamerasrc / src / gsttizencamerasrccolorbalance.c
1 /*
2  * gsttizencamerasrccolorbalance.c
3  *
4  * Copyright (c) 2018 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 "gsttizencamerasrccolorbalance.h"
30
31 G_DEFINE_TYPE(GstTizenCameraSrcColorBalanceChannel,
32   gst_tizencamerasrc_color_balance_channel,
33   GST_TYPE_COLOR_BALANCE_CHANNEL);
34
35 #ifndef GST_CAT_DEFAULT
36 GST_DEBUG_CATEGORY_EXTERN(camerasrc_debug);
37 #define GST_CAT_DEFAULT camerasrc_debug
38 #endif /* GST_CAT_DEFAULT */
39
40
41 static void gst_tizencamerasrc_color_balance_channel_class_init(GstTizenCameraSrcColorBalanceChannelClass *klass)
42 {
43 }
44
45 static void gst_tizencamerasrc_color_balance_channel_init(GstTizenCameraSrcColorBalanceChannel *camerasrc_color_channel)
46 {
47   camerasrc_color_channel->id = (guint32) - 1;
48 }
49
50 static G_GNUC_UNUSED gboolean gst_tizencamerasrc_color_balance_contains_channel(GstTizenCameraSrc *camerasrc, GstTizenCameraSrcColorBalanceChannel *camerasrc_color_channel)
51 {
52   const GList *item = NULL;
53
54   for (item = camerasrc->colors ; item != NULL ; item = item->next) {
55     if (item->data == camerasrc_color_channel)
56       return TRUE;
57   }
58
59   return FALSE;
60 }
61
62 const GList *gst_tizencamerasrc_color_balance_list_channels(GstTizenCameraSrc *camerasrc)
63 {
64   return camerasrc->colors;
65 }
66
67 void gst_tizencamerasrc_color_balance_set_value(GstTizenCameraSrc *camerasrc, GstColorBalanceChannel *color_channel, gint value)
68 {
69   GstTizenCameraSrcColorBalanceChannel *camerasrc_color_channel = GST_TIZENCAMERASRC_COLOR_BALANCE_CHANNEL(color_channel);
70   int ret = CAMERA_ERROR_NONE;
71
72   /* assert that we're opened and that we're using a known item */
73   g_return_if_fail(camerasrc);
74   g_return_if_fail(gst_tizencamerasrc_color_balance_contains_channel(camerasrc, camerasrc_color_channel));
75
76   ret = hal_camera_set_command(camerasrc->hal_handle, camerasrc_color_channel->id, (void *)&value);
77   if (ret != CAMERA_ERROR_NONE)
78     GST_ERROR_OBJECT(camerasrc, "Failed to set command (color balance) 0x%x value[%d]", ret, value);
79
80   return;
81 }
82
83 gint gst_tizencamerasrc_color_balance_get_value(GstTizenCameraSrc *camerasrc, GstColorBalanceChannel *color_channel)
84 {
85   int value = 0;
86   GstTizenCameraSrcColorBalanceChannel *camerasrc_color_channel = GST_TIZENCAMERASRC_COLOR_BALANCE_CHANNEL(color_channel);
87   int ret = CAMERA_ERROR_NONE;
88
89   /* assert that we're opened and that we're using a known item */
90   g_return_val_if_fail(camerasrc, FALSE);
91   g_return_val_if_fail(gst_tizencamerasrc_color_balance_contains_channel(camerasrc, camerasrc_color_channel), FALSE);
92
93   ret = hal_camera_get_command(camerasrc->hal_handle, camerasrc_color_channel->id, (void **)&value);
94   if (ret != CAMERA_ERROR_NONE)
95     GST_ERROR_OBJECT(camerasrc, "Failed to get command (color balance) 0x%x", ret);
96
97   return value;
98 }