1 /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 #include <stdlib.h>
30 #include <cutils/properties.h>
31 #include <fcntl.h>
32 #include <dlfcn.h>
33 #include <mm_qcamera_app.h>
34 #include "mm_qcamera_commands.h"
35 #include "mm_qcamera_dbg.h"
36 
tuneserver_initialize_prevtuningp(void * ctrl,int pr_client_socket_id,cam_dimension_t dimension,char ** send_buf,uint32_t * send_len)37 int tuneserver_initialize_prevtuningp(void * ctrl,
38   int pr_client_socket_id, cam_dimension_t dimension,
39   char **send_buf, uint32_t *send_len)
40 {
41   int result = 0;
42   mm_camera_lib_handle *lib_handle = (mm_camera_lib_handle *) ctrl;
43   tuningserver_t *tctrl = &lib_handle->tsctrl;
44 
45   CDBG("%s  %d\n", __func__, __LINE__);
46   if (tctrl->tuning_params.func_tbl->prevcommand_process == NULL) {
47       ALOGE("%s  %d\n", __func__, __LINE__);
48       return -1;
49   }
50 
51   result = tctrl->tuning_params.func_tbl->prevcommand_process(
52       NULL, TUNE_PREVCMD_INIT, (void *)&pr_client_socket_id,
53       send_buf, send_len);
54   result = tctrl->tuning_params.func_tbl->prevcommand_process(
55       NULL, TUNE_PREVCMD_SETDIM, (void *)&dimension,
56       send_buf, send_len);
57 
58   mm_camera_lib_set_preview_usercb(lib_handle,
59       (tctrl->tuning_params.func_tbl->prevframe_callback));
60 
61   return result;
62 }
63 
tuneserver_deinitialize_prevtuningp(void * ctrl,char ** send_buf,uint32_t * send_len)64 int tuneserver_deinitialize_prevtuningp(void * ctrl,
65     char **send_buf, uint32_t *send_len)
66 {
67   int result = 0;
68   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
69 
70   CDBG("%s  %d\n", __func__, __LINE__);
71 
72   result = tctrl->tuning_params.func_tbl->prevcommand_process(
73     &tctrl->pr_proto, TUNE_PREVCMD_DEINIT, NULL, send_buf, send_len);
74 
75   return result;
76 }
77 
tuneserver_preview_getinfo(void * ctrl,char ** send_buf,uint32_t * send_len)78 int tuneserver_preview_getinfo(void * ctrl, char **send_buf, uint32_t *send_len)
79 {
80   int result = 0;
81   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
82 
83   CDBG("%s  %d\n", __func__, __LINE__);
84   result = tctrl->tuning_params.func_tbl->prevcommand_process(
85     &tctrl->pr_proto, TUNE_PREVCMD_GETINFO, NULL, send_buf, send_len);
86 
87   return result;
88 }
89 
tuneserver_preview_getchunksize(void * ctrl,char ** send_buf,uint32_t * send_len)90 int tuneserver_preview_getchunksize(void * ctrl,
91   char **send_buf, uint32_t *send_len)
92 {
93   int result = 0;
94   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
95 
96   CDBG("%s  %d\n", __func__, __LINE__);
97   result = tctrl->tuning_params.func_tbl->prevcommand_process(
98     &tctrl->pr_proto, TUNE_PREVCMD_GETCHUNKSIZE,
99     (void *)&tctrl->pr_proto->new_cnk_size, send_buf, send_len);
100 
101   return result;
102 }
103 
tuneserver_preview_getframe(void * ctrl,char ** send_buf,uint32_t * send_len)104 int tuneserver_preview_getframe(void * ctrl,
105   char **send_buf, uint32_t *send_len)
106 {
107   int result = 0;
108   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
109 
110   CDBG("%s  %d\n", __func__, __LINE__);
111   result = tctrl->tuning_params.func_tbl->prevcommand_process(
112     &tctrl->pr_proto, TUNE_PREVCMD_GETFRAME, NULL, send_buf, send_len);
113 
114   return result;
115 }
116 
tuneserver_preview_unsupported(void * ctrl,char ** send_buf,uint32_t * send_len)117 int tuneserver_preview_unsupported(void * ctrl,
118   char **send_buf, uint32_t *send_len)
119 {
120   int result = 0;
121   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
122 
123   CDBG("%s  %d\n", __func__, __LINE__);
124   result = tctrl->tuning_params.func_tbl->prevcommand_process(
125     &tctrl->pr_proto, TUNE_PREVCMD_UNSUPPORTED, NULL, send_buf, send_len);
126 
127   return result;
128 }
129 
tuneserver_initialize_tuningp(void * ctrl,int client_socket_id,char * send_buf,uint32_t send_len)130 int tuneserver_initialize_tuningp(void * ctrl, int client_socket_id,
131   char *send_buf, uint32_t send_len)
132 {
133   int result = 0;
134   mm_camera_lib_handle *lib_handle = (mm_camera_lib_handle *) ctrl;
135   tuningserver_t *tctrl = &lib_handle->tsctrl;
136 
137   CDBG("%s  %d\n", __func__, __LINE__);
138   result = tctrl->tuning_params.func_tbl->command_process(
139     lib_handle, TUNE_CMD_INIT, &client_socket_id, send_buf, send_len);
140 
141   return result;
142 }
143 
tuneserver_deinitialize_tuningp(void * ctrl,int client_socket_id,char * send_buf,uint32_t send_len)144 int tuneserver_deinitialize_tuningp(void * ctrl, int client_socket_id,
145   char *send_buf, uint32_t send_len)
146 {
147   int result = 0;
148   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
149 
150   CDBG("%s  %d\n", __func__, __LINE__);
151 
152   result = tctrl->tuning_params.func_tbl->command_process(
153     NULL, TUNE_CMD_DEINIT, &client_socket_id, send_buf, send_len);
154 
155   return result;
156 }
157 
tuneserver_process_get_list_cmd(void * ctrl,void * recv_cmd,char * send_buf,uint32_t send_len)158 int tuneserver_process_get_list_cmd(void * ctrl, void *recv_cmd,
159   char *send_buf, uint32_t send_len)
160 {
161   int result = 0;
162   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
163 
164   CDBG("%s  %d\n", __func__, __LINE__);
165   result = tctrl->tuning_params.func_tbl->command_process(
166      recv_cmd, TUNE_CMD_GET_LIST, NULL, send_buf, send_len);
167 
168   return result;
169 }
170 
tuneserver_process_get_params_cmd(void * ctrl,void * recv_cmd,char * send_buf,uint32_t send_len)171 int tuneserver_process_get_params_cmd(void * ctrl, void *recv_cmd,
172   char *send_buf, uint32_t send_len)
173 {
174   int result = 0;
175   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
176 
177   CDBG("%s  %d\n", __func__, __LINE__);
178   result = tctrl->tuning_params.func_tbl->command_process
179     (recv_cmd, TUNE_CMD_GET_PARAMS, NULL, send_buf, send_len);
180 
181   return result;
182 }
183 
tuneserver_process_set_params_cmd(void * ctrl,void * recv_cmd,char * send_buf,uint32_t send_len)184 int tuneserver_process_set_params_cmd(void * ctrl, void *recv_cmd,
185   char *send_buf, uint32_t send_len)
186 {
187   int result = 0;
188   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
189 
190   CDBG("%s  %d\n", __func__, __LINE__);
191   result = tctrl->tuning_params.func_tbl->command_process(
192      recv_cmd, TUNE_CMD_SET_PARAMS, NULL, send_buf, send_len);
193 
194   return result;
195 }
196 
tuneserver_process_misc_cmd(void * ctrl,void * recv_cmd,char * send_buf,uint32_t send_len)197 int tuneserver_process_misc_cmd(void * ctrl, void *recv_cmd,
198   char *send_buf, uint32_t send_len)
199 {
200   int result = 0;
201   tuningserver_t *tctrl = (tuningserver_t *) ctrl;
202 
203   CDBG("%s  %d\n", __func__, __LINE__);
204   result = tctrl->tuning_params.func_tbl->command_process(
205      recv_cmd, TUNE_CMD_MISC, NULL, send_buf, send_len);
206 
207   return result;
208 }
209 
210 /** tuneserver_close_cam
211  *    @lib_handle: the camera handle object
212  *
213  *  closes the camera
214  *
215  *  Return: >=0 on success, -1 on failure.
216  **/
tuneserver_close_cam(mm_camera_lib_handle * lib_handle)217 int tuneserver_close_cam(mm_camera_lib_handle *lib_handle)
218 {
219   int result = 0;
220 
221   result = mm_camera_lib_close(lib_handle);
222   if (result < 0) {
223     printf("%s: Camera close failed\n", __func__);
224   } else {
225     printf("Camera is closed \n");
226   }
227   return result;
228 }
229 #if 0
230 /** tuneserver_start_cam
231  *    @lib_handle: the camera handle object
232  *
233  *  starts the camera
234  *
235  *  Return: >=0 on success, -1 on failure.
236  **/
237 static int tuneserver_start_cam(mm_camera_lib_handle *lib_handle)
238 {
239   int result = 0;
240 
241   result = mm_camera_lib_start_stream(lib_handle);
242   if (result < 0) {
243     printf("%s: Camera start failed\n", __func__);
244     goto error1;
245   }
246   return result;
247 error1:
248   mm_camera_lib_close(lib_handle);
249   return result;
250 }
251 #endif
252 
253 /** tuneserver_stop_cam
254  *    @lib_handle: the camera handle object
255  *
256  *  stops the camera
257  *
258  *  Return: >=0 on success, -1 on failure.
259  **/
tuneserver_stop_cam(mm_camera_lib_handle * lib_handle)260 int tuneserver_stop_cam(mm_camera_lib_handle *lib_handle)
261 {
262   int result = 0;
263 
264   result = mm_camera_lib_stop_stream(lib_handle);
265   if (result < 0) {
266     printf("%s: Camera stop failed\n", __func__);
267   }
268 //  result = mm_camera_lib_close(lib_handle);
269   return result;
270 }
271 
272 /** tuneserver_open_cam
273  *    @lib_handle: the camera handle object
274  *
275  *  opens the camera
276  *
277  *  Return: >=0 on success, -1 on failure.
278  **/
279 #if 1
tuneserver_open_cam(mm_camera_lib_handle * lib_handle)280 int tuneserver_open_cam(mm_camera_lib_handle *lib_handle)
281 {
282   int result = 0;
283 
284   CDBG("%s  %d\n", __func__, __LINE__);
285   result = mm_camera_load_tuninglibrary(&lib_handle->tsctrl.tuning_params);
286   if (result < 0) {
287     CDBG_ERROR("%s: tuning library open failed\n", __func__);
288   }
289   return result;
290 }
291 #endif
292