b128fdf5a7c283cf3131eeaddd82d8d0bb10ca29
[platform/core/api/camera.git] / src / camera.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <mm.h>
22 #include <mm_camcorder.h>
23 #include <mm_types.h>
24 #include <math.h>
25 #include <camera.h>
26 #include <camera_private.h>
27 #include <glib.h>
28 #include <dlog.h>
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33 #define LOG_TAG "TIZEN_N_CAMERA"
34
35 static gboolean __mm_videostream_callback(MMCamcorderVideoStreamDataType * stream, void *user_data);
36 static gboolean __mm_capture_callback(MMCamcorderCaptureDataType *frame, MMCamcorderCaptureDataType *thumbnail, void *user_data);
37
38
39 static int __convert_camera_error_code(const char* func, int code){
40         int ret = CAMERA_ERROR_NONE;
41         char *errorstr = NULL;
42         switch(code)
43         {
44                 case MM_ERROR_NONE:
45                         ret = CAMERA_ERROR_NONE;
46                         errorstr = "ERROR_NONE";
47                         break;
48                 case MM_ERROR_CAMCORDER_INVALID_ARGUMENT :
49                 case MM_ERROR_COMMON_INVALID_ATTRTYPE :
50                 case MM_ERROR_COMMON_INVALID_PERMISSION :
51                 case MM_ERROR_COMMON_OUT_OF_ARRAY :
52                 case MM_ERROR_COMMON_OUT_OF_RANGE :
53                 case MM_ERROR_COMMON_ATTR_NOT_EXIST :
54                         ret = CAMERA_ERROR_INVALID_PARAMETER;
55                         errorstr = "INVALID_PARAMETER";
56                         break;
57                 case MM_ERROR_CAMCORDER_NOT_INITIALIZED :
58                 case MM_ERROR_CAMCORDER_INVALID_STATE :
59                         ret = CAMERA_ERROR_INVALID_STATE;
60                         errorstr = "INVALID_STATE";
61                         break;
62                 case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND :
63                         ret = CAMERA_ERROR_DEVICE_NOT_FOUND;
64                         errorstr = "DEVICE_NOT_FOUND";
65                         break;
66                 case MM_ERROR_CAMCORDER_DEVICE_BUSY :
67                 case MM_ERROR_CAMCORDER_DEVICE_OPEN :
68                 case MM_ERROR_CAMCORDER_CMD_IS_RUNNING :
69                         ret = CAMERA_ERROR_DEVICE_BUSY;
70                         errorstr = "DEVICE_BUSY";
71                         break;
72                 case MM_ERROR_CAMCORDER_DEVICE :
73                 case MM_ERROR_CAMCORDER_DEVICE_IO :
74                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT  :
75                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE :
76                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG        :
77                 case MM_ERROR_CAMCORDER_DEVICE_LACK_BUFFER :
78                         ret = CAMERA_ERROR_DEVICE;
79                         errorstr = "ERROR_DEVICE";
80                         break;
81
82                 case MM_ERROR_CAMCORDER_GST_CORE :
83                 case MM_ERROR_CAMCORDER_GST_LIBRARY :
84                 case MM_ERROR_CAMCORDER_GST_RESOURCE :
85                 case MM_ERROR_CAMCORDER_GST_STREAM :
86                 case MM_ERROR_CAMCORDER_GST_STATECHANGE :
87                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
88                 case MM_ERROR_CAMCORDER_GST_LINK :
89                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
90                 case MM_ERROR_CAMCORDER_ENCODER :
91                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
92                 case MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE :
93                 case MM_ERROR_CAMCORDER_ENCODER_WORKING :
94                 case MM_ERROR_CAMCORDER_INTERNAL :
95                 case MM_ERROR_CAMCORDER_NOT_SUPPORTED :
96                 case MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT :
97                 case MM_ERROR_CAMCORDER_DSP_FAIL :
98                 case MM_ERROR_CAMCORDER_AUDIO_EMPTY :
99                 case MM_ERROR_CAMCORDER_CREATE_CONFIGURE :
100                 case MM_ERROR_CAMCORDER_FILE_SIZE_OVER :
101                 case MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF :
102                 case MM_ERROR_CAMCORDER_INVALID_CONDITION :
103                         ret = CAMERA_ERROR_INVALID_OPERATION;
104                         errorstr = "INVALID_OPERATION";
105                         break;
106
107                 case MM_ERROR_CAMCORDER_RESOURCE_CREATION :
108                 case MM_ERROR_COMMON_OUT_OF_MEMORY:
109                         ret = CAMERA_ERROR_OUT_OF_MEMORY;
110                         errorstr = "OUT_OF_MEMORY";
111                         break;
112
113                 case MM_ERROR_POLICY_BLOCKED:
114                         ret = CAMERA_ERROR_SOUND_POLICY;
115                         errorstr = "ERROR_SOUND_POLICY";
116                         break;
117                 case MM_ERROR_POLICY_RESTRICTED:
118                         ret = CAMERA_ERROR_SECURITY_RESTRICTED;
119                         errorstr = "ERROR_RESTRICTED";
120                         break;
121
122                 default:
123                         ret = CAMERA_ERROR_INVALID_OPERATION;
124                         errorstr = "INVALID_OPERATION";
125         }
126         LOGE( "[%s] %s(0x%08x) : core frameworks error code(0x%08x)",func, errorstr, ret, code);
127         return ret;
128 }
129
130
131 static gboolean __mm_videostream_callback(MMCamcorderVideoStreamDataType * stream, void *user_data){
132         if( user_data == NULL || stream == NULL)
133                 return 0;
134
135         camera_s * handle = (camera_s*)user_data;
136         if( handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] ){
137                 camera_preview_data_s frame;
138                 frame.format = stream->format;
139                 if( frame.format  == (camera_pixel_format_e)MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
140                         frame.format  = MM_PIXEL_FORMAT_UYVY;
141                 frame.width = stream->width;
142                 frame.height = stream->height;
143                 frame.timestamp = stream->timestamp;
144                 frame.num_of_planes = stream->num_planes;
145                 switch( stream->data_type ){
146                         case MM_CAM_STREAM_DATA_YUV420 :
147                                 frame.data.single_plane.yuv = stream->data.yuv420.yuv;
148                                 frame.data.single_plane.size = stream->data.yuv420.length_yuv;
149                                 break;
150                         case MM_CAM_STREAM_DATA_YUV422 :
151                                 frame.data.single_plane.yuv = stream->data.yuv422.yuv;
152                                 frame.data.single_plane.size = stream->data.yuv422.length_yuv;
153                                 break;
154                         case MM_CAM_STREAM_DATA_YUV420SP :
155                                 frame.data.double_plane.y = stream->data.yuv420sp.y;
156                                 frame.data.double_plane.uv = stream->data.yuv420sp.uv;
157                                 frame.data.double_plane.y_size = stream->data.yuv420sp.length_y;
158                                 frame.data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
159                                 break;
160                         case MM_CAM_STREAM_DATA_YUV420P :
161                                 frame.data.triple_plane.y = stream->data.yuv420p.y;
162                                 frame.data.triple_plane.u = stream->data.yuv420p.u;
163                                 frame.data.triple_plane.v = stream->data.yuv420p.v;
164                                 frame.data.triple_plane.y_size = stream->data.yuv420p.length_y;
165                                 frame.data.triple_plane.u_size = stream->data.yuv420p.length_u;
166                                 frame.data.triple_plane.v_size = stream->data.yuv420p.length_v;
167                                 break;
168                         case MM_CAM_STREAM_DATA_YUV422P :
169                                 frame.data.triple_plane.y = stream->data.yuv422p.y;
170                                 frame.data.triple_plane.u = stream->data.yuv422p.u;
171                                 frame.data.triple_plane.v = stream->data.yuv422p.v;
172                                 frame.data.triple_plane.y_size = stream->data.yuv422p.length_y;
173                                 frame.data.triple_plane.u_size = stream->data.yuv422p.length_u;
174                                 frame.data.triple_plane.v_size = stream->data.yuv422p.length_v;
175                                 break;
176                 }
177                 ((camera_preview_cb)handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW])(&frame, handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW]);
178         }
179         return 1;
180 }
181 static gboolean __mm_capture_callback(MMCamcorderCaptureDataType *frame, MMCamcorderCaptureDataType *thumbnail, void *user_data){
182         if( user_data == NULL || frame == NULL)
183                 return 0;
184
185         camera_s * handle = (camera_s*)user_data;
186         handle->current_capture_count++;
187         if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] ){
188                 MMCamcorderCaptureDataType *scrnl = NULL;
189                 int size = 0;
190                 camera_image_data_s image = { NULL, 0, 0, 0, 0, NULL, 0 };
191                 camera_image_data_s thumb = { NULL, 0, 0, 0, 0, NULL, 0 };
192                 camera_image_data_s postview = { NULL, 0, 0, 0, 0, NULL, 0 };
193                 if( frame ){
194                         int ret;
195                         unsigned char *exif;
196                         int exif_size;
197                         image.data = frame->data;
198                         image.size = frame->length;
199                         image.width = frame->width;
200                         image.height = frame->height;
201                         image.format = frame->format;
202                         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, "captured-exif-raw-data", &exif, &exif_size, NULL);
203                         if( ret == 0 ){
204                                 image.exif = exif;
205                                 image.exif_size = exif_size;
206                         }
207                 }
208
209                 if( thumbnail ){
210                         thumb.data = thumbnail->data;
211                         thumb.size = thumbnail->length;
212                         thumb.width = thumbnail->width;
213                         thumb.height = thumbnail->height;
214                         thumb.format = thumbnail->format;
215                 }
216                 mm_camcorder_get_attributes( handle->mm_handle, NULL, "captured-screennail", &scrnl, &size,NULL );
217                 if( scrnl ){
218                         postview.data = scrnl->data;
219                         postview.size = scrnl->length;
220                         postview.width = scrnl->width;
221                         postview.height = scrnl->height;
222                         postview.format = scrnl->format;
223                 }
224
225                 ((camera_capturing_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE])(&image, scrnl ? &postview : NULL, thumbnail ? &thumb : NULL, handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE]);
226         }
227         // update captured state
228         if( handle->capture_count == 1 && handle->hdr_keep_mode ){
229                 if( handle->current_capture_count == 2 )
230                         handle->is_capture_completed = true;
231         }else if( handle->capture_count == handle->current_capture_count || handle->is_continuous_shot_break)
232                 handle->is_capture_completed = true;
233         return 1;
234 }
235
236 static camera_state_e __camera_state_convert(MMCamcorderStateType mm_state)
237 {
238         camera_state_e state = CAMERA_STATE_NONE;
239
240         switch( mm_state ){
241                 case MM_CAMCORDER_STATE_NONE:
242                         state = CAMERA_STATE_NONE;
243                         break;
244                 case MM_CAMCORDER_STATE_NULL:
245                         state = CAMERA_STATE_CREATED;
246                         break;
247                 case MM_CAMCORDER_STATE_READY:
248                         state = CAMERA_STATE_CREATED;
249                         break;
250                 case MM_CAMCORDER_STATE_PREPARE:
251                         state = CAMERA_STATE_PREVIEW;
252                         break;
253                 case MM_CAMCORDER_STATE_CAPTURING:
254                         state = CAMERA_STATE_CAPTURING;
255                         break;
256                 case MM_CAMCORDER_STATE_RECORDING:
257                         state = CAMERA_STATE_PREVIEW;
258                         break;
259                 case MM_CAMCORDER_STATE_PAUSED:
260                         state = CAMERA_STATE_PREVIEW;
261                         break;
262                 default:
263                         state = CAMERA_STATE_NONE;
264                         break;
265         }
266
267         return state;
268 }
269
270
271 static int __mm_camera_message_callback(int message, void *param, void *user_data){
272         if( user_data == NULL || param == NULL )
273                 return 0;
274
275         camera_s * handle = (camera_s*)user_data;
276
277         if( handle->relay_message_callback )
278                 handle->relay_message_callback(message, param, handle->relay_user_data);
279
280         MMMessageParamType *m = (MMMessageParamType*)param;
281         camera_state_e previous_state;
282
283
284         switch(message){
285                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
286                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
287                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY:
288                         if( message == MM_MESSAGE_CAMCORDER_STATE_CHANGED && (m->state.previous < MM_CAMCORDER_STATE_NONE ||  m->state.previous > MM_CAMCORDER_STATE_PAUSED || m->state.code != 0) ){
289                                 LOGI( "Invalid state changed message");
290                                 break;
291                         }
292
293                         previous_state = handle->state;
294                         handle->state = __camera_state_convert(m->state.current );
295                         camera_policy_e policy = CAMERA_POLICY_NONE;
296                         if(message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM )
297                                 policy = CAMERA_POLICY_SOUND;
298                         else if( message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY )
299                                 policy = CAMERA_POLICY_SECURITY;
300
301                         if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] ){
302                                 ((camera_state_changed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state, policy, handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE]);
303                         }
304
305                         // should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state
306                         if( policy != CAMERA_POLICY_NONE ){
307                                 if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] )
308                                         ((camera_interrupted_cb)handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED]);
309                                 if( m->state.previous == MM_CAMCORDER_STATE_PREPARE && m->state.current == MM_CAMCORDER_STATE_READY ){
310                                         mm_camcorder_unrealize(handle->mm_handle);
311                                 }
312                         }
313
314                         break;
315                 case MM_MESSAGE_CAMCORDER_FOCUS_CHANGED :
316                         if( handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] ){
317                                 ((camera_focus_changed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE])( m->code, handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
318                         }
319                         break;
320                 case MM_MESSAGE_CAMCORDER_CAPTURED:
321                 {
322                         handle->current_capture_complete_count = m->code;
323                         if(  handle->capture_count == 1 || m->code == handle->capture_count ||(handle->is_continuous_shot_break && handle->state == CAMERA_STATE_CAPTURING) ){
324                                 //pseudo state change
325                                 previous_state = handle->state ;
326                                 handle->state = CAMERA_STATE_CAPTURED;
327                                 if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] ){
328                                         ((camera_state_changed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state,  0 , handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE]);
329                                 }
330                                 if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] ){
331                                         ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]);
332                                 }
333                         }
334                         break;
335                 }
336                 case MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED:
337                 case MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED:
338                 {
339                         MMCamRecordingReport *report = (MMCamRecordingReport *)m ->data;
340                         if( report != NULL && report->recording_filename ){
341                                 free(report->recording_filename );
342                                 report->recording_filename = NULL;
343                         }
344                         if( report ){
345                                 free(report);
346                                 report = NULL;
347                         }
348                         break;
349                 }
350                 case MM_MESSAGE_CAMCORDER_VIDEO_SNAPSHOT_CAPTURED:
351                 {
352                         if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] ){
353                                 ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]);
354                         }
355                         break;
356                 }
357                 case MM_MESSAGE_CAMCORDER_ERROR:
358                 {
359                         int errorcode = m->code;
360                         int camera_error = 0;
361                         switch( errorcode ){
362                                 case MM_ERROR_CAMCORDER_DEVICE :
363                                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT :
364                                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE :
365                                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG :
366                                         camera_error = CAMERA_ERROR_DEVICE;
367                                         break;
368                                 case MM_ERROR_CAMCORDER_GST_CORE :
369                                 case MM_ERROR_CAMCORDER_GST_LIBRARY :
370                                 case MM_ERROR_CAMCORDER_GST_RESOURCE :
371                                 case MM_ERROR_CAMCORDER_GST_STREAM :
372                                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
373                                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
374                                 case MM_ERROR_CAMCORDER_ENCODER :
375                                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
376                                 case MM_ERROR_CAMCORDER_ENCODER_WORKING :
377                                 case MM_ERROR_CAMCORDER_MNOTE_CREATION :
378                                 case MM_ERROR_CAMCORDER_MNOTE_ADD_ENTRY :
379                                 case MM_ERROR_CAMCORDER_INTERNAL :
380                                 case MM_ERROR_FILE_NOT_FOUND:
381                                 case MM_ERROR_FILE_READ:
382                                         camera_error = CAMERA_ERROR_INVALID_OPERATION;
383                                         break;
384                                 case MM_ERROR_CAMCORDER_LOW_MEMORY :
385                                 case MM_ERROR_CAMCORDER_MNOTE_MALLOC :
386                                         camera_error = CAMERA_ERROR_OUT_OF_MEMORY;
387                                         break;
388                         }
389                         if( camera_error != 0 && handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] )
390                                 ((camera_error_cb)handle->user_cb[_CAMERA_EVENT_TYPE_ERROR])(camera_error, handle->state , handle->user_data[_CAMERA_EVENT_TYPE_ERROR]);
391
392                         break;
393                 }
394                 case MM_MESSAGE_CAMCORDER_HDR_PROGRESS:
395                 {
396                         int percent = m->code;
397                         if( handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] )
398                                 ((camera_attr_hdr_progress_cb)handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS])(percent, handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
399                         break;
400                 }
401                 case MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO:
402                 {
403                         MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)(m->data);
404                         if ( cam_fd_info ) {
405                                 camera_detected_face_s faces[cam_fd_info->num_of_faces];
406                                 handle->num_of_faces = cam_fd_info->num_of_faces > MAX_DETECTED_FACE ? MAX_DETECTED_FACE : cam_fd_info->num_of_faces;
407                                 int i;
408                                 for(i=0; i < handle->num_of_faces ; i++){
409                                         faces[i].id = cam_fd_info->face_info[i].id;
410                                         faces[i].score = cam_fd_info->face_info[i].score;
411                                         faces[i].x = cam_fd_info->face_info[i].rect.x;
412                                         faces[i].y = cam_fd_info->face_info[i].rect.y;
413                                         faces[i].width = cam_fd_info->face_info[i].rect.width;
414                                         faces[i].height = cam_fd_info->face_info[i].rect.height;
415                                         handle->faceinfo[i] = faces[i]; //cache face coordinate
416                                 }
417                                 if( handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION] )
418                                         ((camera_face_detected_cb)handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION])(faces, handle->num_of_faces, handle->user_data[_CAMERA_EVENT_TYPE_FACE_DETECTION]);
419                         }else{
420                                 handle->num_of_faces = 0;
421                         }
422                         break;
423                 }
424         }
425
426         return 1;
427 }
428
429 static int __capture_completed_event_cb(void *data){
430         camera_s *handle = (camera_s*)data;
431         if( handle->current_capture_count > 0 && handle->current_capture_count == handle->current_capture_complete_count && handle->state == CAMERA_STATE_CAPTURING ){
432                 //pseudo state change
433                 camera_state_e previous_state = handle->state;
434                 handle->state = CAMERA_STATE_CAPTURED;
435                 if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] ){
436                         ((camera_state_changed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state,  0 , handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE]);
437                 }
438                 if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] ){
439                         ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]);
440                 }
441         }
442         return false;
443 }
444
445 int camera_create( camera_device_e device, camera_h* camera){
446
447         if( camera == NULL){
448                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
449                 return CAMERA_ERROR_INVALID_PARAMETER;
450         }
451
452         int ret;
453         MMCamPreset info;
454         int preview_format;
455         int rotation;
456
457         if( device == CAMERA_DEVICE_CAMERA1 )
458                 info.videodev_type= MM_VIDEO_DEVICE_CAMERA1;
459         else
460                 info.videodev_type= MM_VIDEO_DEVICE_CAMERA0;
461
462         camera_s* handle = (camera_s*)malloc( sizeof(camera_s) );
463         if(handle==NULL){
464                 LOGE("[%s] malloc fail",__func__);
465                 return CAMERA_ERROR_OUT_OF_MEMORY;
466         }
467         memset(handle, 0 , sizeof(camera_s));
468
469         ret = mm_camcorder_create(&handle->mm_handle, &info);
470         if( ret != MM_ERROR_NONE){
471                 free(handle);
472                 return __convert_camera_error_code(__func__,ret);
473         }
474
475         preview_format = MM_PIXEL_FORMAT_YUYV;
476         rotation = MM_DISPLAY_ROTATION_NONE;
477         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
478                                                                                                                                 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, &preview_format,
479                                                                                                                                 MMCAM_RECOMMEND_DISPLAY_ROTATION, &rotation,
480                                                                                                                                 MMCAM_CAPTURE_WIDTH, &handle->capture_width,
481                                                                                                                                 MMCAM_CAPTURE_HEIGHT, &handle->capture_height,
482                                                                                                                                 NULL);
483
484         char *error;
485         ret = mm_camcorder_set_attributes(handle->mm_handle, &error,
486                                                                                                                                 MMCAM_MODE , MM_CAMCORDER_MODE_VIDEO_CAPTURE,
487                                                                                                                                 MMCAM_CAMERA_FORMAT,  preview_format,
488                                                                                                                                 MMCAM_IMAGE_ENCODER , MM_IMAGE_CODEC_JPEG,
489                                                                                                                                 MMCAM_CAPTURE_FORMAT,  MM_PIXEL_FORMAT_ENCODED,
490                                                                                                                                 MMCAM_DISPLAY_SURFACE, MM_DISPLAY_SURFACE_NULL,
491                                                                                                                                 MMCAM_DISPLAY_ROTATION, rotation,
492                                                                                                                                 MMCAM_CAPTURE_COUNT, 1,
493                                                                                                                                 (void*)NULL);
494
495         handle->display_type = CAMERA_DISPLAY_TYPE_NONE;
496
497         if( ret != MM_ERROR_NONE){
498                 LOGE("[%s] mm_camcorder_set_attributes fail(%x, %s)",__func__, ret, error);
499                 mm_camcorder_destroy(handle->mm_handle);
500                 free(error);
501                 free(handle);
502                 return __convert_camera_error_code(__func__, ret);
503         }
504
505         handle->state = CAMERA_STATE_CREATED;
506         handle->relay_message_callback = NULL;
507         handle->relay_user_data = NULL;
508         handle->capture_resolution_modified = false;
509         handle->hdr_keep_mode = false;
510         handle->focus_area_valid = false;
511         handle->is_used_in_recorder = false;
512         handle->on_continuous_focusing = false;
513         handle->cached_focus_mode = -1;
514         mm_camcorder_set_message_callback(handle->mm_handle, __mm_camera_message_callback, (void*)handle);
515
516         *camera = (camera_h)handle;
517         return __convert_camera_error_code(__func__, ret);
518 }
519
520  int camera_destroy(camera_h camera){
521         if( camera == NULL){
522                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
523                 return CAMERA_ERROR_INVALID_PARAMETER;
524         }
525
526         int ret;
527         camera_s *handle = (camera_s*)camera;
528         if( handle->is_used_in_recorder ){
529                 LOGE("[%s] camera is using in another recorder.", __func__);
530                 return CAMERA_ERROR_INVALID_OPERATION;
531         }
532
533         ret = mm_camcorder_destroy(handle->mm_handle);
534
535         if( ret == MM_ERROR_NONE)
536                 free(handle);
537
538         return __convert_camera_error_code(__func__, ret);
539
540 }
541
542 int camera_start_preview(camera_h camera){
543         LOGE("%s - start", __func__);
544         if( camera == NULL){
545                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
546                 return CAMERA_ERROR_INVALID_PARAMETER;
547         }
548
549
550         int ret;
551         camera_s *handle = (camera_s*)camera;
552         camera_state_e capi_state;
553         camera_get_state(camera, &capi_state);
554
555         if( capi_state == CAMERA_STATE_CAPTURED )
556         {
557                 ret = mm_camcorder_capture_stop(handle->mm_handle);
558                 return __convert_camera_error_code(__func__, ret);
559         }
560
561
562
563         //for receving MM_MESSAGE_CAMCORDER_CAPTURED evnet must be seted capture callback
564         mm_camcorder_set_video_capture_callback( handle->mm_handle, (mm_camcorder_video_capture_callback)__mm_capture_callback, (void*)handle);
565
566         MMCamcorderStateType state ;
567         mm_camcorder_get_state(handle->mm_handle, &state);
568         if( state != MM_CAMCORDER_STATE_READY){
569                 ret = mm_camcorder_realize(handle->mm_handle);
570                 if( ret != MM_ERROR_NONE )
571                         return __convert_camera_error_code(__func__, ret);
572         }
573
574         ret = mm_camcorder_start(handle->mm_handle);
575
576         //start fail.
577         if( ret != MM_ERROR_NONE &&  state != MM_CAMCORDER_STATE_READY){
578                 mm_camcorder_unrealize(handle->mm_handle);
579         }
580
581         return __convert_camera_error_code(__func__, ret);
582 }
583
584 int camera_stop_preview(camera_h camera){
585         if( camera == NULL){
586                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
587                 return CAMERA_ERROR_INVALID_PARAMETER;
588         }
589
590
591         int ret;
592         camera_s *handle = (camera_s*)camera;
593         MMCamcorderStateType state ;
594         mm_camcorder_get_state(handle->mm_handle, &state);
595
596         if( state == MM_CAMCORDER_STATE_PREPARE ){
597                 ret = mm_camcorder_stop(handle->mm_handle);
598                 if( ret != MM_ERROR_NONE)
599                         return __convert_camera_error_code(__func__, ret);
600         }
601         camera_stop_face_detection(camera);
602         ret = mm_camcorder_unrealize(handle->mm_handle);
603         return __convert_camera_error_code(__func__, ret);
604 }
605
606 int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb , camera_capture_completed_cb completed_cb , void *user_data){
607         if( camera == NULL){
608                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
609                 return CAMERA_ERROR_INVALID_PARAMETER;
610         }
611
612         camera_s * handle = (camera_s*)camera;
613         int ret;
614         MMCamcorderStateType state;
615         mm_camcorder_get_state(handle->mm_handle, &state);
616         if( state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED){
617                 LOGE( "[%s] INVALID_STATE(0x%08x)",__func__,CAMERA_ERROR_INVALID_STATE);
618                 return CAMERA_ERROR_INVALID_STATE;
619         }
620
621         if( handle->capture_resolution_modified ){
622                 mm_camcorder_set_attributes(handle->mm_handle, NULL,
623                                                                                                                         MMCAM_CAPTURE_WIDTH, handle->capture_width,
624                                                                                                                         MMCAM_CAPTURE_HEIGHT, handle->capture_height,
625                                                                                                                         NULL);
626                 handle->capture_resolution_modified = false;
627         }
628         mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAPTURE_COUNT , 1,NULL);
629
630         handle->capture_count = 1;
631         handle->is_continuous_shot_break = false;
632         handle->current_capture_count = 0;
633         handle->current_capture_complete_count = 0;
634         handle->is_capture_completed = false;
635
636         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)capturing_cb;
637         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)user_data;
638         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)completed_cb;
639         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)user_data;
640         ret = mm_camcorder_capture_start(handle->mm_handle);
641         if( ret != 0 ){
642                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
643                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
644                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
645                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
646         }
647
648         return __convert_camera_error_code(__func__, ret);
649 }
650
651 int camera_start_continuous_capture(camera_h camera, int count, int interval, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb , void *user_data){
652         if( camera == NULL){
653                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
654                 return CAMERA_ERROR_INVALID_PARAMETER;
655         }
656
657         if( count < 2 || interval < 0 ){
658                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
659                 return CAMERA_ERROR_INVALID_PARAMETER;
660         }
661
662         camera_s * handle = (camera_s*)camera;
663
664         MMCamcorderStateType state;
665         mm_camcorder_get_state(handle->mm_handle, &state);
666         if( state != MM_CAMCORDER_STATE_PREPARE ){
667                 LOGE( "[%s] INVALID_STATE(0x%08x)",__func__,CAMERA_ERROR_INVALID_STATE);
668                 return CAMERA_ERROR_INVALID_STATE;
669         }
670
671         int preview_width;
672         int preview_height;
673         int capture_width;
674         int capture_height;
675         int current_preview_format;
676         bool supported_ZSL = false;
677
678         int ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
679                                                                                                                                 MMCAM_CAPTURE_COUNT , count,
680                                                                                                                                 MMCAM_CAPTURE_INTERVAL, interval,
681                                                                                                                                 NULL);
682         if( ret != 0 ){
683                 LOGE("[%s] (%x) error set continuous shot attribute", ret);
684                 return __convert_camera_error_code(__func__, ret);
685         }
686         handle->capture_count = count;
687         handle->is_continuous_shot_break = false;
688         handle->current_capture_count = 0;
689         handle->current_capture_complete_count = 0;
690         handle->is_capture_completed = false;
691
692         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FORMAT, &current_preview_format,NULL);
693         if( current_preview_format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
694                 supported_ZSL = true;
695
696         if( ret != 0 ){
697                 LOGE("[%s] (%x) error get continuous shot attribute", ret);
698         }
699
700         if( !supported_ZSL ){
701                 mm_camcorder_get_attributes(handle->mm_handle, NULL,
702                                                                                                                                         MMCAM_CAMERA_WIDTH, &preview_width,
703                                                                                                                                         MMCAM_CAMERA_HEIGHT, &preview_height,
704                                                                                                                                         MMCAM_CAPTURE_WIDTH, &capture_width,
705                                                                                                                                         MMCAM_CAPTURE_HEIGHT, &capture_height,
706                                                                                                                                         NULL);
707                 if( preview_width != capture_width || preview_height != capture_height ){
708                         mm_camcorder_set_attributes(handle->mm_handle, NULL,
709                                                                                                                                                 MMCAM_CAPTURE_WIDTH, preview_width,
710                                                                                                                                                 MMCAM_CAPTURE_HEIGHT, preview_height,
711                                                                                                                                                 NULL);
712                         handle->capture_resolution_modified = true;
713                 }
714         }
715
716         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)capturing_cb;
717         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)user_data;
718         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)completed_cb;
719         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)user_data;
720
721         ret = mm_camcorder_capture_start(handle->mm_handle);
722         if( ret != 0 ){
723                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
724                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
725                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
726                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
727         }
728
729         return __convert_camera_error_code(__func__,ret);
730
731 }
732
733 int camera_stop_continuous_capture(camera_h camera){
734         if( camera == NULL){
735                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
736                 return CAMERA_ERROR_INVALID_PARAMETER;
737         }
738         camera_s *handle = (camera_s*)camera;
739         int ret;
740         camera_state_e state;
741         camera_get_state(camera, &state);
742         if( state != CAMERA_STATE_CAPTURING && handle->capture_count > 1 ){
743                 LOGE( "[%s] INVALID_STATE(0x%08x)",__func__,CAMERA_ERROR_INVALID_STATE);
744                 return CAMERA_ERROR_INVALID_STATE;
745         }
746
747         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, "capture-break-cont-shot", 1, NULL);
748         if( ret == 0){
749                 handle->is_continuous_shot_break = true;
750                 if( handle->current_capture_count > 0 )
751                         handle->is_capture_completed = true;
752                 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __capture_completed_event_cb, handle, NULL);
753         }
754
755         return __convert_camera_error_code(__func__,ret);
756 }
757
758 bool camera_is_supported_face_detection(camera_h camera){
759         if( camera == NULL){
760                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
761                 return false;
762         }
763         int ret;
764         camera_s * handle = (camera_s*)camera;
765         MMCamAttrsInfo info;
766         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_DETECT_MODE , &info);
767         int i=0;
768         if( info.validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY){
769                 for( i =0; i < info.int_array.count ; i++){
770                         if( info.int_array.array[i] == MM_CAMCORDER_DETECT_MODE_ON )
771                                 return true;
772                 }
773         }
774         return false;
775 }
776
777 bool camera_is_supported_zero_shutter_lag(camera_h camera){
778         if( camera == NULL){
779                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
780                 return false;
781         }
782         int ret;
783         camera_s * handle = (camera_s*)camera;
784         MMCamAttrsInfo info;
785         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT , &info);
786         int i=0;
787         if( info.validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY){
788                 for( i =0; i < info.int_array.count ; i++){
789                         if( info.int_array.array[i] == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
790                                 return true;
791                 }
792         }
793         return false;
794 }
795
796 int camera_get_device_count(camera_h camera, int *device_count) {
797         int ret = MM_ERROR_NONE;
798         camera_s *handle = (camera_s *)camera;
799
800         if (camera == NULL || device_count == NULL) {
801                 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __func__, CAMERA_ERROR_INVALID_PARAMETER);
802                 return CAMERA_ERROR_INVALID_PARAMETER;
803         }
804
805         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
806                                           MMCAM_CAMERA_DEVICE_COUNT, device_count,
807                                           NULL);
808
809         return __convert_camera_error_code(__func__, ret);
810 }
811
812 int camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void * user_data){
813         if( camera == NULL){
814                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
815                 return CAMERA_ERROR_INVALID_PARAMETER;
816         }
817         camera_s * handle = (camera_s*)camera;
818         camera_state_e state = CAMERA_STATE_NONE;
819         int ret;
820         camera_get_state(camera, &state);
821         if( state != CAMERA_STATE_PREVIEW ){
822                 LOGE( "[%s] INVALID_STATE(0x%08x)",__func__,CAMERA_ERROR_INVALID_STATE);
823                 return CAMERA_ERROR_INVALID_STATE;
824         }
825         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DETECT_MODE, MM_CAMCORDER_DETECT_MODE_ON, NULL);
826         if( ret == 0 ){
827                 handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION] = (void*)callback;
828                 handle->user_data[_CAMERA_EVENT_TYPE_FACE_DETECTION] = (void*)user_data;
829                 handle->num_of_faces = 0;
830         }
831         return __convert_camera_error_code(__func__,ret);
832 }
833
834 int camera_stop_face_detection(camera_h camera){
835         if( camera == NULL){
836                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
837                 return CAMERA_ERROR_INVALID_PARAMETER;
838         }
839         camera_s * handle = (camera_s*)camera;
840         int ret;
841         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DETECT_MODE, MM_CAMCORDER_DETECT_MODE_OFF, NULL);
842         handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
843         handle->user_data[_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
844         handle->num_of_faces = 0;
845         return __convert_camera_error_code(__func__,ret);
846 }
847
848 int camera_face_zoom(camera_h camera, int face_id){
849         if( camera == NULL){
850                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
851                 return CAMERA_ERROR_INVALID_PARAMETER;
852         }
853         camera_s * handle = (camera_s*)camera;
854         int ret;
855         int find = -1;
856         int i;
857         int current_mode;
858
859         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FACE_ZOOM_MODE , &current_mode, NULL);
860
861         if( current_mode == MM_CAMCORDER_FACE_ZOOM_MODE_ON )
862                 return CAMERA_ERROR_INVALID_STATE;
863
864         for( i = 0 ; i < handle->num_of_faces ; i++){
865                 if( handle->faceinfo[i].id == face_id ){
866                         find = i;
867                         break;
868                 }
869         }
870         if( find == -1 )
871                 return CAMERA_ERROR_INVALID_PARAMETER;
872         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FACE_ZOOM_MODE, MM_CAMCORDER_FACE_ZOOM_MODE_ON,
873                                  MMCAM_CAMERA_FACE_ZOOM_X, handle->faceinfo[find].x+(handle->faceinfo[find].width>>1),
874                                  MMCAM_CAMERA_FACE_ZOOM_Y, handle->faceinfo[find].y+(handle->faceinfo[find].height>>1),
875                                  NULL);
876
877         return __convert_camera_error_code(__func__,ret);
878 }
879
880 int camera_cancel_face_zoom(camera_h camera){
881         if( camera == NULL){
882                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
883                 return CAMERA_ERROR_INVALID_PARAMETER;
884         }
885         camera_s * handle = (camera_s*)camera;
886         int ret;
887         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FACE_ZOOM_MODE, MM_CAMCORDER_FACE_ZOOM_MODE_OFF, NULL);
888         return __convert_camera_error_code(__func__,ret);
889 }
890
891
892 int camera_get_state(camera_h camera, camera_state_e * state){
893         if( camera == NULL || state == NULL){
894                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
895                 return CAMERA_ERROR_INVALID_PARAMETER;
896         }
897
898         camera_s *handle = (camera_s*)camera;
899         camera_state_e capi_state;
900         MMCamcorderStateType mmstate ;
901         mm_camcorder_get_state(handle->mm_handle, &mmstate);
902
903         capi_state = __camera_state_convert(mmstate);
904
905         if( ( handle->state == CAMERA_STATE_CAPTURED || handle->is_capture_completed ) && mmstate == MM_CAMCORDER_STATE_CAPTURING )
906                 capi_state = CAMERA_STATE_CAPTURED;
907
908         *state = capi_state;
909         return CAMERA_ERROR_NONE;
910 }
911
912 int camera_start_focusing( camera_h camera, bool continuous ){
913         if( camera == NULL){
914                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
915                 return CAMERA_ERROR_INVALID_PARAMETER;
916         }
917         camera_s *handle = (camera_s*)camera;
918
919         if( handle->cached_focus_mode != -1){
920                 LOGD("[%s] apply cached focus mode %d", __func__, handle->cached_focus_mode);
921                 mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_AF_SCAN_RANGE  , handle->cached_focus_mode, NULL);
922                 handle->cached_focus_mode = -1;
923         }
924
925         if( continuous )
926                 return __camera_start_continuous_focusing(camera);
927         else{
928                 mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, handle->focus_area_valid ? MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO : MM_CAMCORDER_FOCUS_MODE_AUTO, NULL);
929                 return __convert_camera_error_code(__func__, mm_camcorder_start_focusing(((camera_s*)camera)->mm_handle));
930         }
931 }
932
933 int __camera_start_continuous_focusing(camera_h camera){
934         if( camera == NULL ){
935                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
936                 return CAMERA_ERROR_INVALID_PARAMETER;
937         }
938         camera_s *handle = (camera_s*)camera;
939         int ret;
940         int mode;
941         handle->on_continuous_focusing = true;
942         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FOCUS_MODE , &mode, NULL);
943         if( mode == MM_CAMCORDER_FOCUS_MODE_CONTINUOUS )
944                 ret = mm_camcorder_start_focusing(handle->mm_handle);
945         else
946                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_CONTINUOUS, NULL);
947         return __convert_camera_error_code(__func__, ret);
948 }
949
950 int camera_cancel_focusing( camera_h camera ){
951         if( camera == NULL){
952                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
953                 return CAMERA_ERROR_INVALID_PARAMETER;
954         }
955         camera_s *handle = (camera_s*)camera;
956         handle->on_continuous_focusing = false;
957         return __convert_camera_error_code(__func__, mm_camcorder_stop_focusing(handle->mm_handle));
958 }
959 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display){
960         if( camera == NULL){
961                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
962                 return CAMERA_ERROR_INVALID_PARAMETER;
963         }
964         int ret;
965         camera_s * handle = (camera_s*)camera;
966         handle->display_handle = display;
967         handle->display_type = type;
968         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL,
969                 MMCAM_DISPLAY_DEVICE, MM_DISPLAY_DEVICE_MAINLCD,
970                 MMCAM_DISPLAY_SURFACE  ,type, NULL );
971         if( ret == 0 && type != CAMERA_DISPLAY_TYPE_NONE)
972                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL,
973                 MMCAM_DISPLAY_HANDLE  , type == CAMERA_DISPLAY_TYPE_X11 ? &handle->display_handle : display , sizeof(display) ,
974                 NULL);
975         return __convert_camera_error_code(__func__, ret);
976 }
977
978 int camera_set_preview_resolution(camera_h camera,  int width, int height){
979         if( camera == NULL){
980                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
981                 return CAMERA_ERROR_INVALID_PARAMETER;
982         }
983         int ret;
984         camera_s * handle = (camera_s*)camera;
985         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_WIDTH  , width ,MMCAM_CAMERA_HEIGHT ,height,  NULL);
986         return __convert_camera_error_code(__func__, ret);
987 }
988 int camera_set_x11_display_rotation(camera_h camera,  camera_rotation_e rotation){
989         if( camera == NULL){
990                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
991                 return CAMERA_ERROR_INVALID_PARAMETER;
992         }
993
994         if( rotation < CAMERA_ROTATION_NONE || rotation > CAMERA_ROTATION_270 )
995                 return CAMERA_ERROR_INVALID_PARAMETER;
996
997         int ret;
998         camera_s * handle = (camera_s*)camera;
999
1000         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_ROTATION , rotation, NULL);
1001         return __convert_camera_error_code(__func__, ret);
1002 }
1003
1004 int camera_set_x11_display_flip(camera_h camera, camera_flip_e flip){
1005         if( camera == NULL){
1006                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1007                 return CAMERA_ERROR_INVALID_PARAMETER;
1008         }
1009
1010         if( flip < CAMERA_FLIP_NONE || flip > CAMERA_FLIP_BOTH )
1011                 return CAMERA_ERROR_INVALID_PARAMETER;
1012
1013         int ret;
1014         camera_s * handle = (camera_s*)camera;
1015         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_FLIP , flip, NULL);
1016         return __convert_camera_error_code(__func__, ret);
1017 }
1018
1019 int camera_get_x11_display_flip(camera_h camera, camera_flip_e *flip){
1020         if( camera == NULL || flip == NULL ){
1021                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1022                 return CAMERA_ERROR_INVALID_PARAMETER;
1023         }
1024
1025         int ret;
1026         camera_s * handle = (camera_s*)camera;
1027
1028         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_FLIP , flip, NULL);
1029         return __convert_camera_error_code(__func__, ret);
1030 }
1031
1032 int camera_set_capture_resolution(camera_h camera,  int width, int height){
1033         if( camera == NULL){
1034                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1035                 return CAMERA_ERROR_INVALID_PARAMETER;
1036         }
1037         int ret;
1038         camera_s * handle = (camera_s*)camera;
1039         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAPTURE_WIDTH, width  ,MMCAM_CAPTURE_HEIGHT , height, NULL);
1040         if( ret == 0 ){
1041                 handle->capture_width = width;
1042                 handle->capture_height = height;
1043         }
1044         return __convert_camera_error_code(__func__, ret);
1045 }
1046
1047 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format){
1048         if( camera == NULL){
1049                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1050                 return CAMERA_ERROR_INVALID_PARAMETER;
1051         }
1052         int ret;
1053         camera_s * handle = (camera_s*)camera;
1054         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAPTURE_FORMAT, format , NULL);
1055         return __convert_camera_error_code(__func__, ret);
1056 }
1057
1058 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format){
1059         if( camera == NULL){
1060                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1061                 return CAMERA_ERROR_INVALID_PARAMETER;
1062         }
1063         int ret;
1064         camera_s * handle = (camera_s*)camera;
1065
1066         if( format == CAMERA_PIXEL_FORMAT_UYVY ){
1067                 bool supported_ITLV_UYVY = false;
1068                 MMCamAttrsInfo supported_format;
1069                 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT , &supported_format);
1070                 int i;
1071                 for( i=0 ; i < supported_format.int_array.count ; i++){
1072                         if( supported_format.int_array.array[i] == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
1073                                 supported_ITLV_UYVY = true;
1074                 }
1075                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FORMAT, supported_ITLV_UYVY ?  MM_PIXEL_FORMAT_ITLV_JPEG_UYVY : MM_PIXEL_FORMAT_UYVY , NULL);
1076         }else
1077                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FORMAT, format , NULL);
1078
1079         return __convert_camera_error_code(__func__, ret);
1080 }
1081
1082 int camera_get_preview_resolution(camera_h camera,  int *width, int *height){
1083         if( camera == NULL || width == NULL || height == NULL){
1084                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1085                 return CAMERA_ERROR_INVALID_PARAMETER;
1086         }
1087
1088         int ret;
1089         camera_s * handle = (camera_s*)camera;
1090         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_WIDTH , width,MMCAM_CAMERA_HEIGHT, height,  NULL);
1091         return __convert_camera_error_code(__func__, ret);
1092
1093 }
1094
1095 int camera_get_x11_display_rotation( camera_h camera,  camera_rotation_e *rotation){
1096         if( camera == NULL || rotation == NULL ){
1097                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1098                 return CAMERA_ERROR_INVALID_PARAMETER;
1099         }
1100
1101         int ret;
1102         camera_s * handle = (camera_s*)camera;
1103
1104         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_ROTATION , rotation, NULL);
1105         return __convert_camera_error_code(__func__, ret);
1106 }
1107
1108 int camera_set_x11_display_visible(camera_h camera, bool visible){
1109         if( camera == NULL){
1110                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1111                 return CAMERA_ERROR_INVALID_PARAMETER;
1112         }
1113         int ret;
1114         camera_s * handle = (camera_s*)camera;
1115
1116         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_VISIBLE , visible, NULL);
1117         return __convert_camera_error_code(__func__, ret);
1118 }
1119
1120 int camera_is_x11_display_visible(camera_h camera, bool* visible){
1121         if( camera == NULL || visible == NULL){
1122                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1123                 return CAMERA_ERROR_INVALID_PARAMETER;
1124         }
1125
1126         int ret;
1127         int result;
1128         camera_s * handle = (camera_s*)camera;
1129
1130         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_VISIBLE , &result, NULL);
1131         if( ret == 0)
1132                 *visible = result;
1133         return __convert_camera_error_code(__func__, ret);
1134 }
1135
1136 int camera_set_x11_display_mode( camera_h camera , camera_display_mode_e ratio){
1137         if( camera == NULL){
1138                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1139                 return CAMERA_ERROR_INVALID_PARAMETER;
1140         }
1141
1142         if( ratio < CAMERA_DISPLAY_MODE_LETTER_BOX || ratio > CAMERA_DISPLAY_MODE_CROPPED_FULL )
1143                 return CAMERA_ERROR_INVALID_PARAMETER;
1144
1145         int ret;
1146         camera_s * handle = (camera_s*)camera;
1147
1148         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_GEOMETRY_METHOD , ratio, NULL);
1149         return __convert_camera_error_code(__func__, ret);
1150 }
1151
1152 int camera_get_x11_display_mode( camera_h camera , camera_display_mode_e* ratio){
1153         if( camera == NULL || ratio == NULL){
1154                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1155                 return CAMERA_ERROR_INVALID_PARAMETER;
1156         }
1157
1158         int ret;
1159         camera_s * handle = (camera_s*)camera;
1160
1161         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_GEOMETRY_METHOD , ratio, NULL);
1162         return __convert_camera_error_code(__func__, ret);
1163 }
1164
1165
1166 int camera_get_capture_resolution(camera_h camera, int *width, int *height){
1167         if( camera == NULL || width== NULL || height == NULL){
1168                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1169                 return CAMERA_ERROR_INVALID_PARAMETER;
1170         }
1171         camera_s * handle = (camera_s*)camera;
1172         *width = handle->capture_width;
1173         *height = handle->capture_height;
1174         return CAMERA_ERROR_NONE;
1175 }
1176
1177 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format){
1178         if( camera == NULL || format == NULL){
1179                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1180                 return CAMERA_ERROR_INVALID_PARAMETER;
1181         }
1182
1183         int ret;
1184         camera_s * handle = (camera_s*)camera;
1185         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAPTURE_FORMAT, format , NULL);
1186         return __convert_camera_error_code(__func__, ret);
1187 }
1188
1189 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format){
1190         if( camera == NULL || format == NULL){
1191                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1192                 return CAMERA_ERROR_INVALID_PARAMETER;
1193         }
1194
1195         int ret;
1196         camera_s * handle = (camera_s*)camera;
1197         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FORMAT, format , NULL);
1198         if( (MMPixelFormatType)*format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
1199                 *format = CAMERA_PIXEL_FORMAT_UYVY;
1200         return __convert_camera_error_code(__func__, ret);
1201 }
1202
1203 int camera_set_preview_cb( camera_h camera, camera_preview_cb callback, void* user_data ){
1204         if( camera == NULL || callback == NULL){
1205                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1206                 return CAMERA_ERROR_INVALID_PARAMETER;
1207         }
1208
1209         camera_s * handle = (camera_s*)camera;
1210         handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void*)callback;
1211         handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void*)user_data;
1212         mm_camcorder_set_video_stream_callback( handle->mm_handle, (mm_camcorder_video_stream_callback)__mm_videostream_callback, (void*)handle);
1213         return CAMERA_ERROR_NONE;
1214 }
1215 int camera_unset_preview_cb( camera_h camera){
1216         if( camera == NULL){
1217                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1218                 return CAMERA_ERROR_INVALID_PARAMETER;
1219         }
1220         camera_s * handle = (camera_s*)camera;
1221         mm_camcorder_set_video_stream_callback( handle->mm_handle, (mm_camcorder_video_stream_callback)NULL, (void*)NULL);
1222         handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void*)NULL;
1223         handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void*)NULL;
1224         return CAMERA_ERROR_NONE;
1225 }
1226
1227 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void* user_data){
1228         if( camera == NULL || callback == NULL){
1229                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1230                 return CAMERA_ERROR_INVALID_PARAMETER;
1231         }
1232
1233         camera_s * handle = (camera_s*)camera;
1234         handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)callback;
1235         handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)user_data;
1236         return CAMERA_ERROR_NONE;
1237 }
1238 int camera_unset_state_changed_cb(camera_h camera){
1239         if( camera == NULL){
1240                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1241                 return CAMERA_ERROR_INVALID_PARAMETER;
1242         }
1243         camera_s * handle = (camera_s*)camera;
1244         handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)NULL;
1245         handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)NULL;
1246         return CAMERA_ERROR_NONE;
1247 }
1248
1249 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data){
1250         if( camera == NULL || callback == NULL){
1251                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1252                 return CAMERA_ERROR_INVALID_PARAMETER;
1253         }
1254
1255         camera_s * handle = (camera_s*)camera;
1256         handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)callback;
1257         handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)user_data;
1258         return CAMERA_ERROR_NONE;
1259 }
1260
1261 int camera_unset_interrupted_cb(camera_h camera){
1262         if( camera == NULL){
1263                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1264                 return CAMERA_ERROR_INVALID_PARAMETER;
1265         }
1266         camera_s * handle = (camera_s*)camera;
1267         handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)NULL;
1268         handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)NULL;
1269         return CAMERA_ERROR_NONE;
1270 }
1271
1272 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void* user_data){
1273         if( camera == NULL || callback == NULL){
1274                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1275                 return CAMERA_ERROR_INVALID_PARAMETER;
1276         }
1277         camera_s * handle = (camera_s*)camera;
1278         handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)callback;
1279         handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)user_data;
1280         return CAMERA_ERROR_NONE;
1281 }
1282 int camera_unset_focus_changed_cb(camera_h camera){
1283         if( camera == NULL){
1284                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1285                 return CAMERA_ERROR_INVALID_PARAMETER;
1286         }
1287         camera_s * handle = (camera_s*)camera;
1288         handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)NULL;
1289         handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)NULL;
1290         return CAMERA_ERROR_NONE;
1291 }
1292
1293 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data){
1294         if( camera == NULL || callback == NULL){
1295                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1296                 return CAMERA_ERROR_INVALID_PARAMETER;
1297         }
1298
1299         camera_s * handle = (camera_s*)camera;
1300         handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void*)callback;
1301         handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void*)user_data;
1302         return CAMERA_ERROR_NONE;
1303 }
1304
1305 int camera_unset_error_cb(camera_h camera){
1306         if( camera == NULL){
1307                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1308                 return CAMERA_ERROR_INVALID_PARAMETER;
1309         }
1310
1311         camera_s * handle = (camera_s*)camera;
1312         handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void*)NULL;
1313         handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void*)NULL;
1314         return CAMERA_ERROR_NONE;
1315 }
1316
1317 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb , void *user_data){
1318         if( camera == NULL || foreach_cb == NULL){
1319                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1320                 return CAMERA_ERROR_INVALID_PARAMETER;
1321         }
1322
1323         int ret;
1324         camera_s * handle = (camera_s*)camera;
1325         MMCamAttrsInfo preview_width;
1326         MMCamAttrsInfo preview_height;
1327         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WIDTH , &preview_width);
1328         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HEIGHT , &preview_height);
1329
1330         if( ret != CAMERA_ERROR_NONE )
1331                 return __convert_camera_error_code(__func__, ret);
1332
1333         int i;
1334         for( i=0 ; i < preview_width.int_array.count ; i++)
1335         {
1336                 if ( !foreach_cb(preview_width.int_array.array[i], preview_height.int_array.array[i],user_data) )
1337                         break;
1338         }
1339         return CAMERA_ERROR_NONE;
1340
1341 }
1342 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb , void *user_data){
1343         if( camera == NULL || foreach_cb == NULL){
1344                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1345                 return CAMERA_ERROR_INVALID_PARAMETER;
1346         }
1347         int ret;
1348         camera_s * handle = (camera_s*)camera;
1349         MMCamAttrsInfo capture_width;
1350         MMCamAttrsInfo capture_height;
1351         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_WIDTH , &capture_width);
1352         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_HEIGHT , &capture_height);
1353
1354         if( ret != CAMERA_ERROR_NONE )
1355                 return __convert_camera_error_code(__func__, ret);
1356
1357         int i;
1358         for( i=0 ; i < capture_width.int_array.count ; i++)
1359         {
1360                 if ( !foreach_cb(capture_width.int_array.array[i], capture_height.int_array.array[i],user_data) )
1361                         break;
1362         }
1363         return CAMERA_ERROR_NONE;
1364 }
1365
1366 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb , void *user_data){
1367         if( camera == NULL || foreach_cb == NULL){
1368                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1369                 return CAMERA_ERROR_INVALID_PARAMETER;
1370         }
1371
1372         int ret;
1373         camera_s * handle = (camera_s*)camera;
1374         MMCamAttrsInfo format;
1375         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_FORMAT , &format);
1376
1377         if( ret != CAMERA_ERROR_NONE )
1378                 return __convert_camera_error_code(__func__, ret);
1379
1380         int i;
1381         for( i=0 ; i < format.int_array.count ; i++)
1382         {
1383                 if( format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
1384                         if ( !foreach_cb(format.int_array.array[i], user_data) )
1385                                 break;
1386         }
1387         return CAMERA_ERROR_NONE;
1388
1389 }
1390
1391
1392 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb , void *user_data){
1393         if( camera == NULL || foreach_cb == NULL){
1394                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1395                 return CAMERA_ERROR_INVALID_PARAMETER;
1396         }
1397         int ret;
1398         camera_s * handle = (camera_s*)camera;
1399         MMCamAttrsInfo format;
1400         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT , &format);
1401
1402         if( ret != CAMERA_ERROR_NONE )
1403                 return __convert_camera_error_code(__func__, ret);
1404
1405         int i;
1406         for( i=0 ; i < format.int_array.count ; i++)
1407         {
1408                 if( format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY /* || format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_NV12 */)
1409                         if ( !foreach_cb(format.int_array.array[i], user_data) )
1410                                 break;
1411         }
1412         return CAMERA_ERROR_NONE;
1413
1414 }
1415
1416
1417 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height){
1418         if( camera == NULL ){
1419                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1420                 return CAMERA_ERROR_INVALID_PARAMETER;
1421         }
1422
1423         enum MMCamcorderPreviewType wide;
1424         int capture_w, capture_h;
1425         double ratio;
1426         int ret;
1427         camera_s * handle = (camera_s*)camera;
1428
1429         camera_get_capture_resolution(camera, &capture_w, &capture_h);
1430         ratio = (double)capture_w/(double)capture_h;
1431         if( ratio > 1.5 )
1432                 wide = MM_CAMCORDER_PREVIEW_TYPE_WIDE;
1433         else
1434                 wide = MM_CAMCORDER_PREVIEW_TYPE_NORMAL;
1435
1436         MMCamAttrsInfo width_info, height_info;
1437         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_RECOMMEND_CAMERA_WIDTH , &width_info);
1438         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_RECOMMEND_CAMERA_HEIGHT, &height_info);
1439         if( ret != 0 )
1440                 return __convert_camera_error_code(__func__, ret);
1441
1442         if( width )
1443                 *width = width_info.int_array.array[wide];
1444
1445         if( height )
1446                 *height = height_info.int_array.array[wide];
1447
1448         return CAMERA_ERROR_NONE;
1449 }
1450
1451
1452
1453 int camera_attr_get_lens_orientation(camera_h camera, int *angle) {
1454         if( camera == NULL || angle == NULL){
1455                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1456                 return CAMERA_ERROR_INVALID_PARAMETER;
1457         }
1458
1459         int ret;
1460         camera_s * handle = (camera_s*)camera;
1461         int rotation;
1462         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_RECOMMEND_DISPLAY_ROTATION, &rotation , NULL);
1463
1464         switch( rotation ) {
1465                 case MM_DISPLAY_ROTATION_NONE:
1466                         *angle = 0;
1467                         break;
1468                 case MM_DISPLAY_ROTATION_90:
1469                         *angle = 270;
1470                         break;
1471                 case MM_DISPLAY_ROTATION_180:
1472                         *angle = 180;
1473                         break;
1474                 case MM_DISPLAY_ROTATION_270:
1475                         *angle = 90;
1476                         break;
1477         }
1478
1479         return __convert_camera_error_code(__func__, ret);
1480 }
1481
1482 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode){
1483         if( camera == NULL){
1484                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1485                 return CAMERA_ERROR_INVALID_PARAMETER;
1486         }
1487         int ret;
1488         camera_s * handle = (camera_s*)camera;
1489         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_MODE, mode, NULL);
1490         return __convert_camera_error_code(__func__, ret);
1491 }
1492
1493 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode){
1494         if( camera == NULL || mode == NULL){
1495                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1496                 return CAMERA_ERROR_INVALID_PARAMETER;
1497         }
1498         int ret;
1499         camera_s * handle = (camera_s*)camera;
1500         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_MODE , mode, NULL);
1501         return __convert_camera_error_code(__func__, ret);
1502 }
1503
1504 int camera_attr_set_preview_fps(camera_h camera,  camera_attr_fps_e fps){
1505         if( camera == NULL){
1506                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1507                 return CAMERA_ERROR_INVALID_PARAMETER;
1508         }
1509         int ret;
1510         camera_s * handle = (camera_s*)camera;
1511
1512         if( fps == CAMERA_ATTR_FPS_AUTO ){
1513                 MMCamAttrsInfo info;
1514                 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FPS , &info);
1515                 int maxfps = 0;
1516                 int i;
1517                 for( i=0 ; i < info.int_array.count ; i++)
1518                 {
1519                         if ( info.int_array.array[i] > maxfps && info.int_array.array[i] <= 60 )
1520                                 maxfps = info.int_array.array[i];
1521                 }
1522                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FPS_AUTO  , 1, MMCAM_CAMERA_FPS, maxfps , NULL);
1523         }
1524         else
1525                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FPS_AUTO  , 0, MMCAM_CAMERA_FPS  , fps, NULL);
1526
1527         return __convert_camera_error_code(__func__, ret);
1528
1529 }
1530
1531
1532 int camera_attr_set_image_quality(camera_h camera,  int quality){
1533
1534         if( camera == NULL){
1535                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1536                 return CAMERA_ERROR_INVALID_PARAMETER;
1537         }
1538
1539         int ret;
1540         camera_s * handle = (camera_s*)camera;
1541         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_IMAGE_ENCODER_QUALITY , quality, NULL);
1542         return __convert_camera_error_code(__func__, ret);
1543
1544 }
1545 int camera_attr_get_preview_fps(camera_h camera,  camera_attr_fps_e *fps){
1546         if( camera == NULL || fps == NULL){
1547                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1548                 return CAMERA_ERROR_INVALID_PARAMETER;
1549         }
1550         int ret;
1551         int mm_fps;
1552         int is_auto;
1553         camera_s * handle = (camera_s*)camera;
1554
1555         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FPS , &mm_fps, MMCAM_CAMERA_FPS_AUTO , &is_auto, NULL);
1556         if( is_auto )
1557                 *fps = CAMERA_ATTR_FPS_AUTO;
1558         else
1559                 *fps = mm_fps;
1560
1561         return __convert_camera_error_code(__func__, ret);
1562
1563 }
1564 int camera_attr_get_image_quality(camera_h camera,  int *quality){
1565         if( camera == NULL || quality == NULL){
1566                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1567                 return CAMERA_ERROR_INVALID_PARAMETER;
1568         }
1569
1570         int ret;
1571         camera_s * handle = (camera_s*)camera;
1572         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_IMAGE_ENCODER_QUALITY   , quality, NULL);
1573         return __convert_camera_error_code(__func__, ret);
1574
1575 }
1576
1577
1578 int camera_attr_set_zoom(camera_h camera,  int zoom){
1579         if( camera == NULL){
1580                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1581                 return CAMERA_ERROR_INVALID_PARAMETER;
1582         }
1583         int ret;
1584         camera_s * handle = (camera_s*)camera;
1585         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_DIGITAL_ZOOM  , zoom, NULL);
1586         return __convert_camera_error_code(__func__, ret);
1587
1588 }
1589
1590 int camera_attr_set_af_mode(camera_h camera,  camera_attr_af_mode_e mode){
1591         if( camera == NULL){
1592                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1593                 return CAMERA_ERROR_INVALID_PARAMETER;
1594         }
1595         int ret = CAMERA_ERROR_INVALID_PARAMETER;
1596         camera_s * handle = (camera_s*)camera;
1597         int focus_mode;
1598         bool should_change_focus_mode = false;
1599         mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FOCUS_MODE, &focus_mode, NULL);
1600         if( focus_mode != MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO && focus_mode != MM_CAMCORDER_FOCUS_MODE_CONTINUOUS && focus_mode != MM_CAMCORDER_FOCUS_MODE_AUTO )
1601                 should_change_focus_mode = true;
1602
1603         if( mode != CAMERA_ATTR_AF_NONE && focus_mode == MM_CAMCORDER_FOCUS_MODE_CONTINUOUS && !handle->on_continuous_focusing){
1604                 handle->cached_focus_mode = mode;
1605                 LOGD("[%s] af mode will be set actually start focusing",__func__);
1606                 return __convert_camera_error_code(__func__, 0);
1607         }else
1608                 handle->cached_focus_mode = -1;
1609
1610         if( mode != CAMERA_ATTR_AF_NONE && should_change_focus_mode ){
1611                 mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_AUTO, NULL);
1612         }
1613
1614         switch(mode){
1615                 case CAMERA_ATTR_AF_NONE:
1616                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_NONE,
1617                                                                                                                                                                                                                                                 MMCAM_CAMERA_AF_SCAN_RANGE  , MM_CAMCORDER_AUTO_FOCUS_NORMAL, NULL);
1618                         break;
1619                 case CAMERA_ATTR_AF_NORMAL:
1620                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_AF_SCAN_RANGE  , MM_CAMCORDER_AUTO_FOCUS_NORMAL, NULL);
1621                         break;
1622                 case CAMERA_ATTR_AF_MACRO:
1623                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_AF_SCAN_RANGE  , MM_CAMCORDER_AUTO_FOCUS_MACRO, NULL);
1624                         break;
1625                 case CAMERA_ATTR_AF_FULL:
1626                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_AF_SCAN_RANGE  , MM_CAMCORDER_AUTO_FOCUS_FULL, NULL);
1627                         break;
1628                 default:
1629                         return ret;
1630         }
1631
1632         return __convert_camera_error_code(__func__, ret);
1633 }
1634
1635 int camera_attr_set_af_area(camera_h camera, int x, int y){
1636         if( camera == NULL){
1637                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1638                 return CAMERA_ERROR_INVALID_PARAMETER;
1639         }
1640         int ret = CAMERA_ERROR_INVALID_PARAMETER;
1641         camera_s * handle = (camera_s*)camera;
1642         camera_attr_af_mode_e mode;
1643         camera_attr_get_af_mode(camera, &mode);
1644         if( mode == CAMERA_ATTR_AF_NONE ){
1645                 LOGE( "[%s] INVALID_OPERATION(0x%08x) AF mode is CAMERA_ATTR_AF_NONE",__func__,CAMERA_ERROR_INVALID_OPERATION);
1646                 return CAMERA_ERROR_INVALID_OPERATION;
1647         }
1648         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1649                                           MMCAM_CAMERA_AF_TOUCH_X, x,
1650                                           MMCAM_CAMERA_AF_TOUCH_Y, y,
1651                                           NULL);
1652         if( ret == 0 )
1653                 handle->focus_area_valid = true;
1654         return __convert_camera_error_code(__func__, ret);
1655 }
1656
1657 int camera_attr_clear_af_area(camera_h camera){
1658         if( camera == NULL){
1659                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__, CAMERA_ERROR_INVALID_PARAMETER);
1660                 return CAMERA_ERROR_INVALID_PARAMETER;
1661         }
1662         camera_s * handle = (camera_s*)camera;
1663         if( !handle->focus_area_valid ){
1664                 LOGE( "[%s] INVALID_OPERATION(0x%08x) AF area was not set",__func__,CAMERA_ERROR_INVALID_OPERATION);
1665                 return CAMERA_ERROR_INVALID_OPERATION;
1666         }
1667         handle->focus_area_valid = false;
1668         return 0;
1669 }
1670
1671 int camera_attr_set_exposure_mode(camera_h camera,  camera_attr_exposure_mode_e mode){
1672         if( camera == NULL){
1673                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1674                 return CAMERA_ERROR_INVALID_PARAMETER;
1675         }
1676         int maptable[] = {MM_CAMCORDER_AUTO_EXPOSURE_OFF, //CAMCORDER_EXPOSURE_MODE_OFF
1677                                                                         MM_CAMCORDER_AUTO_EXPOSURE_ALL, //CAMCORDER_EXPOSURE_MODE_ALL
1678                                                                         MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1, //CAMCORDER_EXPOSURE_MODE_CENTER
1679                                                                         MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1, //CAMCORDER_EXPOSURE_MODE_SPOT
1680                                                                         MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1,//CAMCORDER_EXPOSURE_MODE_CUSTOM
1681                 };
1682
1683         int ret;
1684         camera_s * handle = (camera_s*)camera;
1685         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_EXPOSURE_MODE  , maptable[abs(mode%5)], NULL);
1686         return __convert_camera_error_code(__func__, ret);
1687
1688 }
1689
1690 int camera_attr_set_exposure(camera_h camera, int value){
1691         if( camera == NULL){
1692                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1693                 return CAMERA_ERROR_INVALID_PARAMETER;
1694         }
1695         int ret;
1696
1697         camera_s * handle = (camera_s*)camera;
1698         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_EXPOSURE_VALUE  , value, NULL);
1699         return __convert_camera_error_code(__func__, ret);
1700
1701 }
1702
1703 int camera_attr_set_iso(camera_h camera,  camera_attr_iso_e iso){
1704         if( camera == NULL){
1705                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1706                 return CAMERA_ERROR_INVALID_PARAMETER;
1707         }
1708         int ret;
1709         camera_s * handle = (camera_s*)camera;
1710         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_ISO  , iso, NULL);
1711         return __convert_camera_error_code(__func__, ret);
1712 }
1713 int camera_attr_set_brightness(camera_h camera,  int level){
1714         if( camera == NULL){
1715                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1716                 return CAMERA_ERROR_INVALID_PARAMETER;
1717         }
1718         int ret;
1719
1720         camera_s * handle = (camera_s*)camera;
1721         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_BRIGHTNESS  , level, NULL);
1722         return __convert_camera_error_code(__func__, ret);
1723
1724 }
1725
1726 int camera_attr_set_contrast(camera_h camera,  int level){
1727         if( camera == NULL){
1728                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1729                 return CAMERA_ERROR_INVALID_PARAMETER;
1730         }
1731         int ret;
1732
1733         camera_s * handle = (camera_s*)camera;
1734         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_CONTRAST  , level, NULL);
1735
1736         return __convert_camera_error_code(__func__, ret);
1737
1738 }
1739 int camera_attr_set_whitebalance(camera_h camera,  camera_attr_whitebalance_e wb){
1740         if( camera == NULL){
1741                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1742                 return CAMERA_ERROR_INVALID_PARAMETER;
1743         }
1744         int ret;
1745         camera_s * handle = (camera_s*)camera;
1746         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_WB  , wb, NULL);
1747         return __convert_camera_error_code(__func__, ret);
1748
1749 }
1750
1751 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect){
1752         if( camera == NULL){
1753                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1754                 return CAMERA_ERROR_INVALID_PARAMETER;
1755         }
1756         int ret;
1757         camera_s * handle = (camera_s*)camera;
1758         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_COLOR_TONE , effect, NULL);
1759         return __convert_camera_error_code(__func__, ret);
1760 }
1761 int camera_attr_set_scene_mode(camera_h camera,  camera_attr_scene_mode_e mode){
1762         if( camera == NULL){
1763                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1764                 return CAMERA_ERROR_INVALID_PARAMETER;
1765         }
1766         int ret;
1767         camera_s * handle = (camera_s*)camera;
1768         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_SCENE_MODE  , mode, NULL);
1769         return __convert_camera_error_code(__func__, ret);
1770
1771 }
1772
1773
1774 int camera_attr_enable_tag(camera_h camera,  bool enable){
1775         if( camera == NULL){
1776                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1777                 return CAMERA_ERROR_INVALID_PARAMETER;
1778         }
1779         int ret;
1780         camera_s * handle = (camera_s*)camera;
1781         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TAG_ENABLE  , enable, NULL);
1782         return __convert_camera_error_code(__func__, ret);
1783
1784 }
1785
1786 int camera_attr_set_tag_image_description(camera_h camera,  const char *description){
1787         if( camera == NULL){
1788                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1789                 return CAMERA_ERROR_INVALID_PARAMETER;
1790         }
1791         int ret;
1792         camera_s * handle = (camera_s*)camera;
1793         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TAG_IMAGE_DESCRIPTION    , description, strlen(description), NULL);
1794         return __convert_camera_error_code(__func__, ret);
1795
1796 }
1797
1798 int camera_attr_set_tag_orientation(camera_h camera,  camera_attr_tag_orientation_e orientation){
1799         if( camera == NULL){
1800                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1801                 return CAMERA_ERROR_INVALID_PARAMETER;
1802         }
1803         int ret;
1804         camera_s * handle = (camera_s*)camera;
1805         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TAG_ORIENTATION  , orientation, NULL);
1806         return __convert_camera_error_code(__func__, ret);
1807
1808 }
1809
1810 int camera_attr_set_tag_software(camera_h camera,  const char *software){
1811         if( camera == NULL){
1812                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1813                 return CAMERA_ERROR_INVALID_PARAMETER;
1814         }
1815         int ret;
1816         camera_s * handle = (camera_s*)camera;
1817         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TAG_SOFTWARE   , software, strlen(software), NULL);
1818         return __convert_camera_error_code(__func__, ret);
1819
1820 }
1821
1822 int camera_attr_set_geotag(camera_h camera, double latitude , double longitude, double altitude){
1823         if( camera == NULL){
1824                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1825                 return CAMERA_ERROR_INVALID_PARAMETER;
1826         }
1827         int ret;
1828         camera_s * handle = (camera_s*)camera;
1829         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TAG_GPS_ENABLE, 1,
1830                                                                                                   MMCAM_TAG_LATITUDE, latitude,
1831                                                                                                   MMCAM_TAG_LONGITUDE, longitude,
1832                                                                                                   MMCAM_TAG_ALTITUDE, altitude,
1833                                                                                                   NULL);
1834         return __convert_camera_error_code(__func__, ret);
1835 }
1836
1837 int camera_attr_remove_geotag(camera_h camera){
1838         if( camera == NULL){
1839                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1840                 return CAMERA_ERROR_INVALID_PARAMETER;
1841         }
1842         int ret;
1843         camera_s * handle = (camera_s*)camera;
1844         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TAG_GPS_ENABLE, 0, NULL);
1845         return __convert_camera_error_code(__func__, ret);
1846 }
1847
1848 int camera_attr_set_flash_mode(camera_h camera,  camera_attr_flash_mode_e mode){
1849         if( camera == NULL){
1850                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1851                 return CAMERA_ERROR_INVALID_PARAMETER;
1852         }
1853         int ret;
1854         camera_s * handle = (camera_s*)camera;
1855         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_STROBE_MODE  , mode, NULL);
1856         return __convert_camera_error_code(__func__, ret);
1857 }
1858
1859
1860 int camera_attr_get_zoom(camera_h camera,  int *zoom){
1861         if( camera == NULL || zoom == NULL){
1862                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1863                 return CAMERA_ERROR_INVALID_PARAMETER;
1864         }
1865
1866         int ret;
1867         camera_s * handle = (camera_s*)camera;
1868         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_DIGITAL_ZOOM , zoom, NULL);
1869         return __convert_camera_error_code(__func__, ret);
1870
1871 }
1872
1873 int camera_attr_get_zoom_range(camera_h camera , int *min , int *max){
1874         if( camera == NULL || min == NULL || max == NULL ){
1875                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1876                 return CAMERA_ERROR_INVALID_PARAMETER;
1877         }
1878
1879         int ret;
1880         camera_s * handle = (camera_s*)camera;
1881         MMCamAttrsInfo ainfo;
1882         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_DIGITAL_ZOOM, &ainfo);
1883         if( min )
1884                 *min = ainfo.int_range.min;
1885         if( max )
1886                 *max = ainfo.int_range.max;
1887
1888         return __convert_camera_error_code(__func__, ret);
1889 }
1890
1891
1892 int camera_attr_get_af_mode( camera_h camera,  camera_attr_af_mode_e *mode){
1893         if( camera == NULL || mode == NULL){
1894                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1895                 return CAMERA_ERROR_INVALID_PARAMETER;
1896         }
1897
1898         int ret;
1899         int focus_mode;
1900         int af_range;
1901         int detect_mode;
1902         camera_s * handle = (camera_s*)camera;
1903         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FOCUS_MODE , &focus_mode, MMCAM_CAMERA_AF_SCAN_RANGE , &af_range, MMCAM_DETECT_MODE , &detect_mode, NULL);
1904         if( ret == CAMERA_ERROR_NONE){
1905                 switch( focus_mode ){
1906                         case MM_CAMCORDER_FOCUS_MODE_NONE :
1907                         case MM_CAMCORDER_FOCUS_MODE_PAN :
1908                         case MM_CAMCORDER_FOCUS_MODE_MANUAL :
1909                                 *mode = CAMERA_ATTR_AF_NONE;
1910                                 break;
1911                         case MM_CAMCORDER_FOCUS_MODE_AUTO:
1912                         case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
1913                         case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
1914                                 switch ( af_range ){
1915                                         case MM_CAMCORDER_AUTO_FOCUS_NONE :
1916                                                 *mode = CAMERA_ATTR_AF_NORMAL;
1917                                                 break;
1918                                         case MM_CAMCORDER_AUTO_FOCUS_NORMAL:
1919                                                 *mode = CAMERA_ATTR_AF_NORMAL;
1920                                                 break;
1921                                         case MM_CAMCORDER_AUTO_FOCUS_MACRO:
1922                                                 *mode = CAMERA_ATTR_AF_MACRO;
1923                                                 break;
1924                                         case MM_CAMCORDER_AUTO_FOCUS_FULL:
1925                                                 *mode = CAMERA_ATTR_AF_FULL;
1926                                                 break;
1927                                 }
1928                                 break;
1929                 }
1930
1931         }
1932         return __convert_camera_error_code(__func__, ret);
1933 }
1934
1935 int camera_attr_get_exposure_mode( camera_h camera,  camera_attr_exposure_mode_e *mode){
1936         if( camera == NULL|| mode == NULL){
1937                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1938                 return CAMERA_ERROR_INVALID_PARAMETER;
1939         }
1940
1941         int maptable[] = {
1942                         CAMERA_ATTR_EXPOSURE_MODE_OFF,  //MM_CAMCORDER_AUTO_EXPOSURE_OFF
1943                         CAMERA_ATTR_EXPOSURE_MODE_ALL,  //MM_CAMCORDER_AUTO_EXPOSURE_ALL
1944                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1
1945                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_2
1946                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_3
1947                         CAMERA_ATTR_EXPOSURE_MODE_SPOT, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1
1948                         CAMERA_ATTR_EXPOSURE_MODE_SPOT, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2
1949                         CAMERA_ATTR_EXPOSURE_MODE_CUSTOM,//MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1
1950                         CAMERA_ATTR_EXPOSURE_MODE_CUSTOM //MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2
1951                 };
1952         int ret;
1953         int exposure_mode;
1954         camera_s * handle = (camera_s*)camera;
1955         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_EXPOSURE_MODE , &exposure_mode, NULL);
1956         if( ret == CAMERA_ERROR_NONE ){
1957                 *mode = maptable[abs(exposure_mode%9)];
1958         }
1959         return __convert_camera_error_code(__func__, ret);
1960
1961 }
1962
1963 int camera_attr_get_exposure(camera_h camera, int *value){
1964         if( camera == NULL || value == NULL){
1965                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1966                 return CAMERA_ERROR_INVALID_PARAMETER;
1967         }
1968
1969         int ret;
1970         camera_s * handle = (camera_s*)camera;
1971         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_EXPOSURE_VALUE , value, NULL);
1972         return __convert_camera_error_code(__func__, ret);
1973 }
1974
1975
1976 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max){
1977         if( camera == NULL || min == NULL || max == NULL ){
1978                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1979                 return CAMERA_ERROR_INVALID_PARAMETER;
1980         }
1981
1982         int ret;
1983         camera_s * handle = (camera_s*)camera;
1984         MMCamAttrsInfo ainfo;
1985         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_VALUE, &ainfo);
1986         if( min )
1987                 *min = ainfo.int_range.min;
1988         if( max )
1989                 *max = ainfo.int_range.max;
1990
1991         return __convert_camera_error_code(__func__, ret);
1992 }
1993
1994
1995 int camera_attr_get_iso( camera_h camera,  camera_attr_iso_e *iso){
1996         if( camera == NULL || iso == NULL){
1997                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
1998                 return CAMERA_ERROR_INVALID_PARAMETER;
1999         }
2000
2001         int ret;
2002         camera_s * handle = (camera_s*)camera;
2003         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_ISO , iso, NULL);
2004         return __convert_camera_error_code(__func__, ret);
2005
2006 }
2007
2008 int camera_attr_get_brightness(camera_h camera,  int *level){
2009         if( camera == NULL || level == NULL){
2010                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2011                 return CAMERA_ERROR_INVALID_PARAMETER;
2012         }
2013         int ret;
2014         camera_s * handle = (camera_s*)camera;
2015         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_BRIGHTNESS , level, NULL);
2016         return __convert_camera_error_code(__func__, ret);
2017
2018 }
2019
2020 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max){
2021         if( camera == NULL || min == NULL || max == NULL ){
2022                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2023                 return CAMERA_ERROR_INVALID_PARAMETER;
2024         }
2025
2026         int ret;
2027         camera_s * handle = (camera_s*)camera;
2028         MMCamAttrsInfo ainfo;
2029         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_BRIGHTNESS, &ainfo);
2030         if( min )
2031                 *min = ainfo.int_range.min;
2032         if( max )
2033                 *max = ainfo.int_range.max;
2034
2035         return __convert_camera_error_code(__func__, ret);
2036 }
2037
2038
2039 int camera_attr_get_contrast(camera_h camera,  int *level){
2040         if( camera == NULL || level == NULL){
2041                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2042                 return CAMERA_ERROR_INVALID_PARAMETER;
2043         }
2044
2045
2046         int ret;
2047         camera_s * handle = (camera_s*)camera;
2048         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_CONTRAST , level, NULL);
2049         return __convert_camera_error_code(__func__, ret);
2050 }
2051
2052 int camera_attr_get_contrast_range(camera_h camera, int *min , int *max){
2053         if( camera == NULL || min == NULL || max == NULL ){
2054                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2055                 return CAMERA_ERROR_INVALID_PARAMETER;
2056         }
2057
2058         int ret;
2059         camera_s * handle = (camera_s*)camera;
2060         MMCamAttrsInfo ainfo;
2061         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_CONTRAST, &ainfo);
2062         if( min )
2063                 *min = ainfo.int_range.min;
2064         if( max )
2065                 *max = ainfo.int_range.max;
2066
2067         return __convert_camera_error_code(__func__, ret);
2068 }
2069
2070
2071 int camera_attr_get_whitebalance(camera_h camera,  camera_attr_whitebalance_e *wb){
2072         if( camera == NULL || wb == NULL){
2073                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2074                 return CAMERA_ERROR_INVALID_PARAMETER;
2075         }
2076
2077         int ret;
2078         camera_s * handle = (camera_s*)camera;
2079         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_WB , wb, NULL);
2080         return __convert_camera_error_code(__func__, ret);
2081
2082 }
2083
2084 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect){
2085
2086         if( camera == NULL || effect == NULL ){
2087                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2088                 return CAMERA_ERROR_INVALID_PARAMETER;
2089         }
2090
2091         int ret;
2092         camera_s * handle = (camera_s*)camera;
2093         int tone;
2094         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_COLOR_TONE , &tone, NULL);
2095
2096         if( ret != CAMERA_ERROR_NONE )
2097                 return __convert_camera_error_code(__func__, ret);
2098
2099         *effect = (camera_attr_effect_mode_e)tone;
2100
2101         return __convert_camera_error_code(__func__, ret);
2102 }
2103
2104 int camera_attr_get_scene_mode(camera_h camera,  camera_attr_scene_mode_e *mode){
2105         if( camera == NULL || mode == NULL){
2106                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2107                 return CAMERA_ERROR_INVALID_PARAMETER;
2108         }
2109
2110         int ret;
2111         camera_s * handle = (camera_s*)camera;
2112         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILTER_SCENE_MODE , mode, NULL);
2113         return __convert_camera_error_code(__func__, ret);
2114
2115 }
2116
2117
2118 int camera_attr_is_enabled_tag(camera_h camera,  bool *enable){
2119         if( camera == NULL || enable == NULL){
2120                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2121                 return CAMERA_ERROR_INVALID_PARAMETER;
2122         }
2123
2124         int ret;
2125         camera_s * handle = (camera_s*)camera;
2126
2127         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TAG_ENABLE , enable, NULL);
2128
2129         return __convert_camera_error_code(__func__, ret);
2130
2131 }
2132
2133 int camera_attr_get_tag_image_description(camera_h camera,  char **description){
2134         if( camera == NULL || description == NULL){
2135                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2136                 return CAMERA_ERROR_INVALID_PARAMETER;
2137         }
2138
2139         int ret;
2140         camera_s * handle = (camera_s*)camera;
2141         char *ndescription = NULL;
2142         int desc_size;
2143         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TAG_IMAGE_DESCRIPTION , &ndescription, &desc_size, NULL);
2144         if( ret == CAMERA_ERROR_NONE ){
2145                 if( ndescription != NULL )
2146                         *description = strdup(ndescription);
2147                 else
2148                         *description = strdup("");
2149         }
2150
2151         return __convert_camera_error_code(__func__, ret);
2152
2153 }
2154
2155 int camera_attr_get_tag_orientation(camera_h camera,  camera_attr_tag_orientation_e *orientation){
2156
2157         if( camera == NULL || orientation == NULL){
2158                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2159                 return CAMERA_ERROR_INVALID_PARAMETER;
2160         }
2161
2162         int ret;
2163         camera_s * handle = (camera_s*)camera;
2164         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TAG_ORIENTATION , orientation, NULL);
2165         return __convert_camera_error_code(__func__, ret);
2166
2167 }
2168 int camera_attr_get_tag_software(camera_h camera,  char **software){
2169         if( camera == NULL || software == NULL ){
2170                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2171                 return CAMERA_ERROR_INVALID_PARAMETER;
2172         }
2173
2174         int ret;
2175         camera_s * handle = (camera_s*)camera;
2176         char *soft;
2177         int soft_size;
2178         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TAG_SOFTWARE , &soft, &soft_size, NULL);
2179         if( ret == CAMERA_ERROR_NONE ){
2180                 if( soft != NULL )
2181                         *software = strdup(soft);
2182                 else
2183                         *software = strdup("");
2184         }
2185         return __convert_camera_error_code(__func__, ret);
2186 }
2187
2188 int camera_attr_get_geotag(camera_h camera, double *latitude , double *longitude, double *altitude){
2189         if( camera == NULL || latitude == NULL || longitude == NULL || altitude == NULL){
2190                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2191                 return CAMERA_ERROR_INVALID_PARAMETER;
2192         }
2193         int ret;
2194         camera_s * handle = (camera_s*)camera;
2195         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TAG_LATITUDE , latitude,
2196                                                                                                   MMCAM_TAG_LONGITUDE, longitude,
2197                                                                                                   MMCAM_TAG_ALTITUDE, altitude,
2198                                                                                                   NULL);
2199         return __convert_camera_error_code(__func__, ret);
2200 }
2201
2202 int camera_attr_get_flash_mode(camera_h camera,  camera_attr_flash_mode_e *mode){
2203         if( camera == NULL || mode == NULL){
2204                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2205                 return CAMERA_ERROR_INVALID_PARAMETER;
2206         }
2207
2208         int ret;
2209         camera_s * handle = (camera_s*)camera;
2210         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_STROBE_MODE , mode, NULL);
2211         return __convert_camera_error_code(__func__, ret);
2212 }
2213
2214 int camera_attr_foreach_supported_af_mode( camera_h camera, camera_attr_supported_af_mode_cb foreach_cb , void *user_data){
2215         if( camera == NULL || foreach_cb == NULL){
2216                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2217                 return CAMERA_ERROR_INVALID_PARAMETER;
2218         }
2219
2220
2221         int ret;
2222         int i;
2223         camera_s * handle = (camera_s*)camera;
2224         MMCamAttrsInfo af_range;
2225         MMCamAttrsInfo focus_mode;
2226
2227         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_AF_SCAN_RANGE , &af_range);
2228         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FOCUS_MODE , &focus_mode);
2229
2230         if( ret != CAMERA_ERROR_NONE )
2231                 return __convert_camera_error_code(__func__, ret);
2232
2233         for( i=0 ; i < af_range.int_array.count ; i++)
2234         {
2235                 if ( !foreach_cb(af_range.int_array.array[i],user_data) )
2236                         goto ENDCALLBACK;
2237         }
2238
2239         ENDCALLBACK:
2240
2241         return CAMERA_ERROR_NONE;
2242
2243 }
2244
2245 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb , void *user_data){
2246         if( camera == NULL || foreach_cb == NULL){
2247                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2248                 return CAMERA_ERROR_INVALID_PARAMETER;
2249         }
2250
2251         int maptable[] = {
2252                         CAMERA_ATTR_EXPOSURE_MODE_OFF,  //MM_CAMCORDER_AUTO_EXPOSURE_OFF
2253                         CAMERA_ATTR_EXPOSURE_MODE_ALL,  //MM_CAMCORDER_AUTO_EXPOSURE_ALL
2254                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1
2255                         -1, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_2
2256                         -1, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_3
2257                         CAMERA_ATTR_EXPOSURE_MODE_SPOT, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1
2258                         -1, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2
2259                         CAMERA_ATTR_EXPOSURE_MODE_CUSTOM,//MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1
2260                         -1//MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2
2261                 };
2262         int ret;
2263         camera_s * handle = (camera_s*)camera;
2264         MMCamAttrsInfo info;
2265         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_MODE , &info);
2266         if( ret != CAMERA_ERROR_NONE )
2267                 return __convert_camera_error_code(__func__, ret);
2268
2269         int i;
2270         for( i=0 ; i < info.int_array.count ; i++)
2271         {
2272                 if( maptable[info.int_array.array[i]] != -1){
2273                         if ( !foreach_cb(maptable[info.int_array.array[i]],user_data) )
2274                                 break;
2275                 }
2276         }
2277         return CAMERA_ERROR_NONE;
2278
2279 }
2280 int camera_attr_foreach_supported_iso( camera_h camera, camera_attr_supported_iso_cb foreach_cb , void *user_data){
2281         if( camera == NULL || foreach_cb == NULL){
2282                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2283                 return CAMERA_ERROR_INVALID_PARAMETER;
2284         }
2285         int ret;
2286         camera_s * handle = (camera_s*)camera;
2287         MMCamAttrsInfo info;
2288         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ISO , &info);
2289         if( ret != CAMERA_ERROR_NONE )
2290                 return __convert_camera_error_code(__func__, ret);
2291
2292         int i;
2293         for( i=0 ; i < info.int_array.count ; i++)
2294         {
2295                 if ( !foreach_cb(info.int_array.array[i],user_data) )
2296                         break;
2297         }
2298         return CAMERA_ERROR_NONE;
2299
2300 }
2301
2302 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb , void *user_data){
2303         if( camera == NULL || foreach_cb == NULL){
2304                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2305                 return CAMERA_ERROR_INVALID_PARAMETER;
2306         }
2307         int ret;
2308         camera_s * handle = (camera_s*)camera;
2309         MMCamAttrsInfo info;
2310         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_WB , &info);
2311         if( ret != CAMERA_ERROR_NONE )
2312                 return __convert_camera_error_code(__func__, ret);
2313
2314         int i;
2315         for( i=0 ; i < info.int_array.count ; i++)
2316         {
2317                 if ( !foreach_cb(info.int_array.array[i],user_data)  )
2318                         break;
2319         }
2320         return CAMERA_ERROR_NONE;
2321
2322 }
2323 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb , void *user_data){
2324         if( camera == NULL || foreach_cb == NULL){
2325                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2326                 return CAMERA_ERROR_INVALID_PARAMETER;
2327         }
2328
2329         int ret;
2330         camera_s * handle = (camera_s*)camera;
2331         MMCamAttrsInfo info;
2332         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_COLOR_TONE , &info);
2333         if( ret != CAMERA_ERROR_NONE )
2334                 return __convert_camera_error_code(__func__, ret);
2335
2336         int i;
2337         for( i=0 ; i < info.int_array.count ; i++)
2338         {
2339                 int effect = info.int_array.array[i];
2340                 if ( !foreach_cb(effect,user_data) )
2341                                 break;
2342         }
2343         return CAMERA_ERROR_NONE;
2344
2345 }
2346 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb , void *user_data){
2347         if( camera == NULL || foreach_cb == NULL){
2348                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2349                 return CAMERA_ERROR_INVALID_PARAMETER;
2350         }
2351
2352         int ret;
2353         camera_s * handle = (camera_s*)camera;
2354         MMCamAttrsInfo info;
2355         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_SCENE_MODE  , &info);
2356         if( ret != CAMERA_ERROR_NONE )
2357                 return __convert_camera_error_code(__func__, ret);
2358
2359         int i;
2360         for( i=0 ; i < info.int_array.count ; i++)
2361         {
2362                 if ( !foreach_cb(info.int_array.array[i],user_data) )
2363                         break;
2364         }
2365         return CAMERA_ERROR_NONE;
2366
2367 }
2368
2369 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb , void *user_data){
2370         if( camera == NULL || foreach_cb == NULL){
2371                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2372                 return CAMERA_ERROR_INVALID_PARAMETER;
2373         }
2374         int ret;
2375         camera_s * handle = (camera_s*)camera;
2376         MMCamAttrsInfo info;
2377         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_STROBE_MODE  , &info);
2378         if( ret != CAMERA_ERROR_NONE )
2379                 return __convert_camera_error_code(__func__, ret);
2380
2381         int i;
2382         for( i=0 ; i < info.int_array.count ; i++)
2383         {
2384                 if ( !foreach_cb(info.int_array.array[i],user_data) )
2385                         break;
2386         }
2387         return CAMERA_ERROR_NONE;
2388
2389 }
2390 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb , void *user_data){
2391         if( camera == NULL || foreach_cb == NULL){
2392                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2393                 return CAMERA_ERROR_INVALID_PARAMETER;
2394         }
2395         int ret;
2396         camera_s * handle = (camera_s*)camera;
2397         MMCamAttrsInfo info;
2398         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FPS , &info);
2399         if( ret != CAMERA_ERROR_NONE )
2400                 return __convert_camera_error_code(__func__, ret);
2401
2402         int i;
2403         //if (foreach_cb(CAMERA_ATTR_FPS_AUTO, user_data) < 0 )
2404         //      return CAMERA_ERROR_NONE;
2405         for( i=0 ; i < info.int_array.count ; i++)
2406         {
2407                 if ( !foreach_cb(info.int_array.array[i],user_data) )
2408                         break;
2409         }
2410         return CAMERA_ERROR_NONE;
2411
2412 }
2413
2414 int camera_attr_set_stream_rotation(camera_h camera , camera_rotation_e rotation){
2415         if( camera == NULL){
2416                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2417                 return CAMERA_ERROR_INVALID_PARAMETER;
2418         }
2419
2420         if( rotation < CAMERA_ROTATION_NONE || rotation > CAMERA_ROTATION_270 )
2421                 return CAMERA_ERROR_INVALID_PARAMETER;
2422
2423         int ret;
2424         camera_s * handle = (camera_s*)camera;
2425
2426         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_ROTATION , rotation, NULL);
2427         return __convert_camera_error_code(__func__, ret);
2428 }
2429
2430 int camera_attr_get_stream_rotation(camera_h camera , camera_rotation_e *rotation){
2431         if( camera == NULL || rotation == NULL ){
2432                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2433                 return CAMERA_ERROR_INVALID_PARAMETER;
2434         }
2435
2436         int ret;
2437         camera_s * handle = (camera_s*)camera;
2438
2439         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_ROTATION , rotation, NULL);
2440         return __convert_camera_error_code(__func__, ret);
2441 }
2442
2443 int camera_attr_set_stream_flip(camera_h camera , camera_flip_e flip){
2444         if( camera == NULL){
2445                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2446                 return CAMERA_ERROR_INVALID_PARAMETER;
2447         }
2448
2449         if( flip < CAMERA_FLIP_NONE || flip > CAMERA_FLIP_BOTH )
2450                 return CAMERA_ERROR_INVALID_PARAMETER;
2451
2452         int ret;
2453         camera_s * handle = (camera_s*)camera;
2454         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FLIP , flip , NULL);
2455         return __convert_camera_error_code(__func__, ret);
2456 }
2457
2458 int camera_attr_get_stream_flip(camera_h camera , camera_flip_e *flip){
2459         if( camera == NULL || flip == NULL ){
2460                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2461                 return CAMERA_ERROR_INVALID_PARAMETER;
2462         }
2463         int ret;
2464         camera_s * handle = (camera_s*)camera;
2465         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FLIP , flip , NULL);
2466         return __convert_camera_error_code(__func__, ret);
2467 }
2468
2469 int _camera_set_use(camera_h camera, bool used){
2470         camera_s * handle = (camera_s*)camera;
2471         handle->is_used_in_recorder = used;
2472         return 0;
2473 }
2474
2475 bool _camera_is_used(camera_h camera){
2476         camera_s * handle = (camera_s*)camera;
2477         return handle->is_used_in_recorder;
2478 }
2479
2480
2481 int _camera_get_mm_handle(camera_h camera , MMHandleType *handle){
2482         if( camera == NULL || handle == NULL ){
2483                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2484                 return CAMERA_ERROR_INVALID_PARAMETER;
2485         }
2486         camera_s *camera_handle = (camera_s*)camera;
2487         *handle =  camera_handle->mm_handle;
2488         return CAMERA_ERROR_NONE;
2489 }
2490
2491 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data){
2492         if( camera == NULL ){
2493                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2494                 return CAMERA_ERROR_INVALID_PARAMETER;
2495         }
2496
2497         camera_s *handle = (camera_s*)camera;
2498         handle->relay_message_callback = callback;
2499         handle->relay_user_data = user_data;
2500
2501         return CAMERA_ERROR_NONE;
2502 }
2503
2504 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode){
2505         if( camera == NULL){
2506                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2507                 return CAMERA_ERROR_INVALID_PARAMETER;
2508         }
2509         int ret;
2510         camera_s * handle = (camera_s*)camera;
2511         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_HDR_CAPTURE , mode, NULL);
2512         if( ret == 0 ){
2513                 if( mode == CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL )
2514                         handle->hdr_keep_mode = true;
2515                 else
2516                         handle->hdr_keep_mode = false;
2517         }
2518         return __convert_camera_error_code(__func__, ret);
2519 }
2520
2521 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode){
2522         if( camera == NULL || mode == NULL ){
2523                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2524                 return CAMERA_ERROR_INVALID_PARAMETER;
2525         }
2526         int ret;
2527         int result;
2528         camera_s * handle = (camera_s*)camera;
2529         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_HDR_CAPTURE , &result, NULL);
2530         if( ret == 0 ){
2531                 *mode = result;
2532         }
2533         return __convert_camera_error_code(__func__, ret);
2534 }
2535
2536
2537 int camera_attr_enable_hdr_capture(camera_h camera, bool enable){
2538         if( camera == NULL){
2539                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2540                 return CAMERA_ERROR_INVALID_PARAMETER;
2541         }
2542         int ret;
2543         camera_s * handle = (camera_s*)camera;
2544         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_HDR_CAPTURE , enable, NULL);
2545         return __convert_camera_error_code(__func__, ret);
2546 }
2547
2548 int camera_attr_is_enabled_hdr_capture(camera_h camera, bool *enabled){
2549         if( camera == NULL || enabled == NULL ){
2550                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2551                 return CAMERA_ERROR_INVALID_PARAMETER;
2552         }
2553         int ret;
2554         int result;
2555         camera_s * handle = (camera_s*)camera;
2556         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_HDR_CAPTURE , &result, NULL);
2557         if( ret == 0 ){
2558                 if( result >= MM_CAMCORDER_HDR_ON )
2559                         *enabled = true;
2560                 else
2561                         *enabled = false;
2562         }
2563         return __convert_camera_error_code(__func__, ret);
2564 }
2565
2566 bool camera_attr_is_supported_hdr_capture(camera_h camera){
2567         if( camera == NULL){
2568                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2569                 return false;
2570         }
2571         int ret;
2572         int i;
2573         camera_s * handle = (camera_s*)camera;
2574         MMCamAttrsInfo hdr_info;
2575         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HDR_CAPTURE , &hdr_info);
2576         for (i = 0; i < hdr_info.int_array.count ; i++) {
2577                 if (hdr_info.int_array.array[i] >= MM_CAMCORDER_HDR_ON) {
2578                         return true;
2579                 }
2580         }
2581         return false;
2582 }
2583
2584 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void* user_data){
2585         if( camera == NULL || callback == NULL){
2586                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2587                 return CAMERA_ERROR_INVALID_PARAMETER;
2588         }
2589
2590         camera_s * handle = (camera_s*)camera;
2591         handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)callback;
2592         handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)user_data;
2593         return CAMERA_ERROR_NONE;
2594 }
2595
2596 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera){
2597         if( camera == NULL){
2598                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2599                 return CAMERA_ERROR_INVALID_PARAMETER;
2600         }
2601         camera_s * handle = (camera_s*)camera;
2602         handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)NULL;
2603         handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)NULL;
2604         return CAMERA_ERROR_NONE;
2605 }
2606
2607 int camera_attr_enable_anti_shake(camera_h camera, bool enable){
2608         if( camera == NULL){
2609                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2610                 return CAMERA_ERROR_INVALID_PARAMETER;
2611         }
2612         int ret;
2613         int mode = MM_CAMCORDER_AHS_OFF;
2614         if( enable )
2615                 mode = MM_CAMCORDER_AHS_ON;
2616
2617         camera_s * handle = (camera_s*)camera;
2618         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_ANTI_HANDSHAKE , mode, NULL);
2619         return __convert_camera_error_code(__func__, ret);
2620 }
2621
2622 int camera_attr_is_enabled_anti_shake(camera_h camera , bool *enabled){
2623         if( camera == NULL || enabled == NULL ){
2624                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2625                 return CAMERA_ERROR_INVALID_PARAMETER;
2626         }
2627         int ret;
2628         int mode = MM_CAMCORDER_AHS_OFF;
2629         camera_s * handle = (camera_s*)camera;
2630         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_ANTI_HANDSHAKE , &mode, NULL);
2631         if( ret == 0 )
2632                 *enabled = mode;
2633         return __convert_camera_error_code(__func__, ret);
2634 }
2635
2636 bool camera_attr_is_supported_anti_shake(camera_h camera){
2637         if( camera == NULL){
2638                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2639                 return false;
2640         }
2641         int i;
2642         camera_s * handle = (camera_s*)camera;
2643         MMCamAttrsInfo ash_info;
2644         mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ANTI_HANDSHAKE , &ash_info);
2645
2646         for( i=0 ; i < ash_info.int_array.count ; i++)
2647         {
2648                 if ( ash_info.int_array.array[i] == MM_CAMCORDER_AHS_ON)
2649                         return true;
2650         }
2651         return false;
2652 }
2653
2654 int camera_attr_enable_video_stabilization(camera_h camera, bool enable){
2655         if( camera == NULL){
2656                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2657                 return CAMERA_ERROR_INVALID_PARAMETER;
2658         }
2659         int ret;
2660         int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF;
2661         if( enable )
2662                 mode = MM_CAMCORDER_VIDEO_STABILIZATION_ON;
2663
2664         camera_s * handle = (camera_s*)camera;
2665         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_VIDEO_STABILIZATION , mode, NULL);
2666         return __convert_camera_error_code(__func__, ret);
2667 }
2668
2669 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled){
2670         if( camera == NULL || enabled == NULL ){
2671                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2672                 return CAMERA_ERROR_INVALID_PARAMETER;
2673         }
2674         int ret;
2675         int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF;
2676         camera_s * handle = (camera_s*)camera;
2677         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_VIDEO_STABILIZATION , &mode, NULL);
2678         if( ret == 0 )
2679                 *enabled = (mode == MM_CAMCORDER_VIDEO_STABILIZATION_ON);
2680         return __convert_camera_error_code(__func__, ret);
2681 }
2682
2683 bool camera_attr_is_supported_video_stabilization(camera_h camera){
2684         if( camera == NULL){
2685                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2686                 return false;
2687         }
2688         int i;
2689         camera_s * handle = (camera_s*)camera;
2690         MMCamAttrsInfo vs_info;
2691         mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_VIDEO_STABILIZATION , &vs_info);
2692
2693         for( i=0 ; i < vs_info.int_array.count ; i++)
2694         {
2695                 if ( vs_info.int_array.array[i] == MM_CAMCORDER_VIDEO_STABILIZATION_ON)
2696                         return true;
2697         }
2698         return false;
2699 }
2700
2701
2702
2703 int camera_attr_enable_auto_contrast(camera_h camera, bool enable){
2704         if( camera == NULL){
2705                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2706                 return CAMERA_ERROR_INVALID_PARAMETER;
2707         }
2708         int ret;
2709         int mode = MM_CAMCORDER_WDR_OFF;
2710         if( enable )
2711                 mode = MM_CAMCORDER_WDR_ON;
2712
2713         camera_s * handle = (camera_s*)camera;
2714         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL,  MMCAM_CAMERA_WDR  , mode, NULL);
2715         return __convert_camera_error_code(__func__, ret);
2716 }
2717
2718 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled){
2719         if( camera == NULL || enabled == NULL ){
2720                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2721                 return CAMERA_ERROR_INVALID_PARAMETER;
2722         }
2723         int ret;
2724         int mode = MM_CAMCORDER_WDR_OFF;
2725         camera_s * handle = (camera_s*)camera;
2726         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_WDR , &mode, NULL);
2727         if( ret == 0 )
2728                 *enabled = mode;
2729         return __convert_camera_error_code(__func__, ret);
2730 }
2731
2732 int camera_attr_disable_shutter_sound(camera_h camera, bool disable){
2733         if( camera == NULL){
2734                 LOGE( "[%s] INVALID_PARAMETER(0x%08x)",__func__,CAMERA_ERROR_INVALID_PARAMETER);
2735                 return CAMERA_ERROR_INVALID_PARAMETER;
2736         }
2737         int ret;
2738         camera_s * handle = (camera_s*)camera;
2739         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL,  "capture-sound-enable"  , !disable, NULL);
2740         if( ret != 0 ){
2741                 LOGE("[%s] CAMERA_ERROR_INVALID_OPERATION : not permitted disable shutter sound", __func__);
2742                 return CAMERA_ERROR_INVALID_OPERATION;
2743         }
2744         return CAMERA_ERROR_NONE;
2745 }