Support waylandsink
[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 <audio-session-manager-types.h>
23 #include <mm_camcorder.h>
24 #include <mm_types.h>
25 #include <math.h>
26 #include <camera.h>
27 #include <camera_private.h>
28 #include <glib.h>
29 #include <dlog.h>
30 #include <gst/gst.h>
31 #include <tbm_bufmgr.h>
32 #include <tbm_surface_internal.h>
33 #include <Evas.h>
34 #include <Ecore.h>
35 #include <Elementary.h>
36
37 #ifdef LOG_TAG
38 #undef LOG_TAG
39 #endif
40 #define LOG_TAG "TIZEN_N_CAMERA"
41
42 static gboolean __mm_videostream_callback(MMCamcorderVideoStreamDataType * stream, void *user_data);
43 static gboolean __mm_capture_callback(MMCamcorderCaptureDataType *frame, MMCamcorderCaptureDataType *thumbnail, void *user_data);
44
45 void _camera_remove_cb_message(camera_s *handle){
46         int ret = 0;
47         GList *list = NULL;
48         camera_cb_data *cb_data = NULL;
49
50         if( handle == NULL ){
51                 LOGE("handle is NULL");
52                 return;
53         }
54
55         LOGI("start");
56
57         g_mutex_lock(&handle->idle_cb_lock);
58
59         if( handle->cb_data_list ){
60                 list = handle->cb_data_list;
61
62                 while( list ){
63                         cb_data = list->data;
64                         list =  g_list_next(list);
65
66                         if( !cb_data ){
67                                 LOGW("cb_data is NULL");
68                         } else {
69                                 ret = g_idle_remove_by_data (cb_data);
70                                 LOGW("Remove cb_data[%p]. ret[%d]", cb_data, ret);
71
72                                 handle->cb_data_list = g_list_remove(handle->cb_data_list, cb_data);
73                                 free(cb_data);
74                                 cb_data = NULL;
75                         }
76                 }
77
78                 g_list_free(handle->cb_data_list);
79                 handle->cb_data_list = NULL;
80         } else {
81                 LOGW("There is no remained callback");
82         }
83
84         g_mutex_unlock(&handle->idle_cb_lock);
85
86         LOGI("done");
87
88         return;
89 }
90
91
92 int __convert_camera_error_code(const char* func, int code){
93         int ret = CAMERA_ERROR_NONE;
94         const char *errorstr = NULL;
95
96         switch( code ){
97                 case MM_ERROR_NONE:
98                         ret = CAMERA_ERROR_NONE;
99                         errorstr = "ERROR_NONE";
100                         break;
101                 case MM_ERROR_CAMCORDER_INVALID_ARGUMENT:
102                 case MM_ERROR_COMMON_INVALID_ATTRTYPE:
103                         ret = CAMERA_ERROR_INVALID_PARAMETER;
104                         errorstr = "INVALID_PARAMETER";
105                         break;
106                 case MM_ERROR_CAMCORDER_NOT_INITIALIZED:
107                 case MM_ERROR_CAMCORDER_INVALID_STATE:
108                         ret = CAMERA_ERROR_INVALID_STATE;
109                         errorstr = "INVALID_STATE";
110                         break;
111                 case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND:
112                         ret = CAMERA_ERROR_DEVICE_NOT_FOUND;
113                         errorstr = "DEVICE_NOT_FOUND";
114                         break;
115                 case MM_ERROR_CAMCORDER_DEVICE_BUSY:
116                 case MM_ERROR_CAMCORDER_DEVICE_OPEN:
117                 case MM_ERROR_CAMCORDER_CMD_IS_RUNNING:
118                         ret = CAMERA_ERROR_DEVICE_BUSY;
119                         errorstr = "DEVICE_BUSY";
120                         break;
121                 case MM_ERROR_CAMCORDER_DEVICE:
122                 case MM_ERROR_CAMCORDER_DEVICE_IO:
123                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT:
124                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG:
125                 case MM_ERROR_CAMCORDER_DEVICE_LACK_BUFFER:
126                         ret = CAMERA_ERROR_DEVICE;
127                         errorstr = "ERROR_DEVICE";
128                         break;
129
130                 case MM_ERROR_CAMCORDER_GST_CORE:
131                 case MM_ERROR_CAMCORDER_GST_LIBRARY:
132                 case MM_ERROR_CAMCORDER_GST_RESOURCE:
133                 case MM_ERROR_CAMCORDER_GST_STREAM:
134                 case MM_ERROR_CAMCORDER_GST_STATECHANGE:
135                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION:
136                 case MM_ERROR_CAMCORDER_GST_LINK:
137                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR:
138                 case MM_ERROR_CAMCORDER_ENCODER:
139                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER:
140                 case MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE:
141                 case MM_ERROR_CAMCORDER_ENCODER_WORKING:
142                 case MM_ERROR_CAMCORDER_INTERNAL:
143                 case MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT:
144                 case MM_ERROR_CAMCORDER_DSP_FAIL:
145                 case MM_ERROR_CAMCORDER_AUDIO_EMPTY:
146                 case MM_ERROR_CAMCORDER_CREATE_CONFIGURE:
147                 case MM_ERROR_CAMCORDER_FILE_SIZE_OVER:
148                 case MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF:
149                 case MM_ERROR_CAMCORDER_INVALID_CONDITION:
150                         ret = CAMERA_ERROR_INVALID_OPERATION;
151                         errorstr = "INVALID_OPERATION";
152                         break;
153
154                 case MM_ERROR_CAMCORDER_RESOURCE_CREATION:
155                 case MM_ERROR_COMMON_OUT_OF_MEMORY:
156                         ret = CAMERA_ERROR_OUT_OF_MEMORY;
157                         errorstr = "OUT_OF_MEMORY";
158                         break;
159
160                 case MM_ERROR_POLICY_BLOCKED:
161                         ret = CAMERA_ERROR_SOUND_POLICY;
162                         errorstr = "ERROR_SOUND_POLICY";
163                         break;
164                 case MM_ERROR_POLICY_BLOCKED_BY_CALL:
165                         ret = CAMERA_ERROR_SOUND_POLICY_BY_CALL;
166                         errorstr = "ERROR_SOUND_POLICY_BY_CALL";
167                         break;
168                 case MM_ERROR_POLICY_BLOCKED_BY_ALARM:
169                         ret = CAMERA_ERROR_SOUND_POLICY_BY_ALARM;
170                         errorstr = "ERROR_SOUND_POLICY_BY_ALARM";
171                         break;
172                 case MM_ERROR_POLICY_RESTRICTED:
173                         ret = CAMERA_ERROR_SECURITY_RESTRICTED;
174                         errorstr = "ERROR_RESTRICTED";
175                         break;
176                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
177                         ret = CAMERA_ERROR_ESD;
178                         errorstr = "ERROR_ESD";
179                         break;
180                 case MM_ERROR_COMMON_INVALID_PERMISSION:
181                         ret = CAMERA_ERROR_PERMISSION_DENIED;
182                         errorstr = "ERROR_PERMISSION_DENIED";
183                         break;
184                 case MM_ERROR_COMMON_OUT_OF_ARRAY:
185                 case MM_ERROR_COMMON_OUT_OF_RANGE:
186                 case MM_ERROR_COMMON_ATTR_NOT_EXIST:
187                 case MM_ERROR_CAMCORDER_NOT_SUPPORTED:
188                         ret = CAMERA_ERROR_NOT_SUPPORTED;
189                         errorstr = "ERROR_NOT_SUPPORTED";
190                         break;
191                 default:
192                         ret = CAMERA_ERROR_INVALID_OPERATION;
193                         errorstr = "INVALID_OPERATION";
194         }
195
196         if( code != MM_ERROR_NONE ){
197                 LOGE("%s(0x%08x) : core frameworks error code(0x%08x)", errorstr, ret, code);
198         }
199
200         return ret;
201 }
202
203
204 static gboolean __mm_videostream_callback(MMCamcorderVideoStreamDataType * stream, void *user_data){
205         if( user_data == NULL || stream == NULL)
206                 return 0;
207
208         camera_s * handle = (camera_s*)user_data;
209         if( handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] ){
210                 camera_preview_data_s frame;
211                 frame.format = stream->format;
212                 if( frame.format  == (camera_pixel_format_e)MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
213                         frame.format  = MM_PIXEL_FORMAT_UYVY;
214                 frame.width = stream->width;
215                 frame.height = stream->height;
216                 frame.timestamp = stream->timestamp;
217                 frame.num_of_planes = stream->num_planes;
218                 switch( stream->data_type ){
219                         case MM_CAM_STREAM_DATA_YUV420 :
220                                 frame.data.single_plane.yuv = stream->data.yuv420.yuv;
221                                 frame.data.single_plane.size = stream->data.yuv420.length_yuv;
222                                 break;
223                         case MM_CAM_STREAM_DATA_YUV422:
224                                 frame.data.single_plane.yuv = stream->data.yuv422.yuv;
225                                 frame.data.single_plane.size = stream->data.yuv422.length_yuv;
226                                 break;
227                         case MM_CAM_STREAM_DATA_YUV420SP:
228                                 frame.data.double_plane.y = stream->data.yuv420sp.y;
229                                 frame.data.double_plane.uv = stream->data.yuv420sp.uv;
230                                 frame.data.double_plane.y_size = stream->data.yuv420sp.length_y;
231                                 frame.data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
232                                 break;
233                         case MM_CAM_STREAM_DATA_YUV420P:
234                                 frame.data.triple_plane.y = stream->data.yuv420p.y;
235                                 frame.data.triple_plane.u = stream->data.yuv420p.u;
236                                 frame.data.triple_plane.v = stream->data.yuv420p.v;
237                                 frame.data.triple_plane.y_size = stream->data.yuv420p.length_y;
238                                 frame.data.triple_plane.u_size = stream->data.yuv420p.length_u;
239                                 frame.data.triple_plane.v_size = stream->data.yuv420p.length_v;
240                                 break;
241                         case MM_CAM_STREAM_DATA_YUV422P:
242                                 frame.data.triple_plane.y = stream->data.yuv422p.y;
243                                 frame.data.triple_plane.u = stream->data.yuv422p.u;
244                                 frame.data.triple_plane.v = stream->data.yuv422p.v;
245                                 frame.data.triple_plane.y_size = stream->data.yuv422p.length_y;
246                                 frame.data.triple_plane.u_size = stream->data.yuv422p.length_u;
247                                 frame.data.triple_plane.v_size = stream->data.yuv422p.length_v;
248                                 break;
249                         default :
250                                 break;
251                 }
252                 ((camera_preview_cb)handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW])(&frame, handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW]);
253         }
254
255         if( handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] ){
256                 media_packet_h pkt = NULL;
257                 tbm_surface_h tsurf = NULL;
258                 uint32_t bo_format = 0;
259                 int i;
260                 int bo_num;
261                 int ret = 0;
262                 media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
263                 bool make_pkt_fmt = false;
264
265                 /* create tbm surface */
266                 for( i = 0, bo_num = 0 ; i < BUFFER_MAX_PLANE_NUM ; i++ ){
267                         if( stream->bo[i] ){
268                                 bo_num++;
269                         }
270                 }
271
272                 /* get tbm surface format */
273                 ret = _camera_get_tbm_surface_format(stream->format, &bo_format);
274                 ret |= _camera_get_media_packet_mimetype(stream->format, &mimetype);
275
276                 if( bo_num > 0 && ret == CAMERA_ERROR_NONE ){
277                         tsurf = tbm_surface_internal_create_with_bos(stream->width, stream->height, bo_format, (tbm_bo *)stream->bo, bo_num);
278                         /*LOGD("tbm surface %p", tsurf);*/
279                 }
280
281                 if( tsurf ){
282                         /* check media packet format */
283                         if( handle->pkt_fmt ){
284                                 int pkt_fmt_width = 0;
285                                 int pkt_fmt_height = 0;
286                                 media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
287
288                                 media_format_get_video_info(handle->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
289                                 if( pkt_fmt_mimetype != mimetype ||
290                                     pkt_fmt_width != stream->width ||
291                                     pkt_fmt_height != stream->height ){
292                                         LOGW("different format. current 0x%x, %dx%d, new 0x%x, %dx%d",
293                                              pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height, mimetype, stream->width, stream->height);
294                                         media_format_unref(handle->pkt_fmt);
295                                         handle->pkt_fmt = NULL;
296                                         make_pkt_fmt = true;
297                                 }
298                         } else {
299                                 make_pkt_fmt = true;
300                         }
301
302                         /* create packet format */
303                         if( make_pkt_fmt ){
304                                 LOGW("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, stream->width, stream->height);
305                                 ret = media_format_create(&handle->pkt_fmt);
306                                 if (ret == MEDIA_FORMAT_ERROR_NONE) {
307                                         ret = media_format_set_video_mime(handle->pkt_fmt, mimetype);
308                                         ret |= media_format_set_video_width(handle->pkt_fmt, stream->width);
309                                         ret |= media_format_set_video_height(handle->pkt_fmt, stream->height);
310                                         LOGW("media_format_set_video_mime,width,height ret : 0x%x", ret);
311                                 } else {
312                                         LOGW("media_format_create failed");
313                                 }
314                         }
315
316                         /* create media packet */
317                         ret = media_packet_create_from_tbm_surface(handle->pkt_fmt, tsurf, (media_packet_finalize_cb)_camera_media_packet_finalize, (void *)handle, &pkt);
318                         if( ret != MEDIA_PACKET_ERROR_NONE ){
319                                 LOGE("media_packet_create_from_tbm_surface failed");
320
321                                 tbm_surface_destroy(tsurf);
322                                 tsurf = NULL;
323                         }
324                 } else {
325                         LOGE("failed to create tbm surface %dx%d, format %d, bo_num %d", stream->width, stream->height, stream->format, bo_num);
326                 }
327
328                 if( pkt ){
329                         /*LOGD("media packet %p, internal buffer %p", pkt, stream->internal_buffer);*/
330
331                         /* set internal buffer */
332                         ret = media_packet_set_extra(pkt, stream->internal_buffer);
333                         if( ret != MEDIA_PACKET_ERROR_NONE ){
334                                 LOGE("media_packet_set_extra failed");
335
336                                 media_packet_destroy(pkt);
337                                 pkt = NULL;
338                         } else {
339                                 /* set timestamp : msec -> nsec */
340                                 if( media_packet_set_pts(pkt, (uint64_t)(stream->timestamp) * 1000000) != MEDIA_PACKET_ERROR_NONE ){
341                                         LOGW("media_packet_set_pts failed");
342                                 }
343
344                                 /* increase ref count of gst buffer */
345                                 gst_buffer_ref((GstBuffer *)stream->internal_buffer);
346
347                                 /* call media packet callback */
348                                 ((camera_media_packet_preview_cb)handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW])(pkt, handle->user_data[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
349                         }
350                 }
351         }
352
353         return 1;
354 }
355
356 static gboolean __mm_capture_callback(MMCamcorderCaptureDataType *frame, MMCamcorderCaptureDataType *thumbnail, void *user_data){
357         if( user_data == NULL || frame == NULL)
358                 return 0;
359
360         camera_s * handle = (camera_s*)user_data;
361         handle->current_capture_count++;
362         if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] ){
363                 MMCamcorderCaptureDataType *scrnl = NULL;
364                 int size = 0;
365                 camera_image_data_s image = { NULL, 0, 0, 0, 0, NULL, 0 };
366                 camera_image_data_s thumb = { NULL, 0, 0, 0, 0, NULL, 0 };
367                 camera_image_data_s postview = { NULL, 0, 0, 0, 0, NULL, 0 };
368                 if( frame ){
369                         int ret;
370                         unsigned char *exif;
371                         int exif_size;
372                         image.data = frame->data;
373                         image.size = frame->length;
374                         image.width = frame->width;
375                         image.height = frame->height;
376                         image.format = frame->format;
377                         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, "captured-exif-raw-data", &exif, &exif_size, NULL);
378                         if( ret == MM_ERROR_NONE ){
379                                 image.exif = exif;
380                                 image.exif_size = exif_size;
381                         }
382                 }
383
384                 if( thumbnail ){
385                         thumb.data = thumbnail->data;
386                         thumb.size = thumbnail->length;
387                         thumb.width = thumbnail->width;
388                         thumb.height = thumbnail->height;
389                         thumb.format = thumbnail->format;
390                 }
391                 mm_camcorder_get_attributes( handle->mm_handle, NULL, "captured-screennail", &scrnl, &size,NULL );
392                 if( scrnl ){
393                         postview.data = scrnl->data;
394                         postview.size = scrnl->length;
395                         postview.width = scrnl->width;
396                         postview.height = scrnl->height;
397                         postview.format = scrnl->format;
398                 }
399
400                 ((camera_capturing_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE])(&image, scrnl ? &postview : NULL, thumbnail ? &thumb : NULL, handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE]);
401         }
402         // update captured state
403         if( handle->capture_count == 1 && handle->hdr_keep_mode ){
404                 if( handle->current_capture_count == 2 ){
405                         handle->is_capture_completed = true;
406                 }
407         } else if( handle->capture_count == handle->current_capture_count || handle->is_continuous_shot_break){
408                 handle->is_capture_completed = true;
409         }
410
411         return 1;
412 }
413
414 static camera_state_e __camera_state_convert(MMCamcorderStateType mm_state){
415         camera_state_e state = CAMERA_STATE_NONE;
416
417         switch( mm_state ){
418                 case MM_CAMCORDER_STATE_NONE:
419                         state = CAMERA_STATE_NONE;
420                         break;
421                 case MM_CAMCORDER_STATE_NULL:
422                         state = CAMERA_STATE_CREATED;
423                         break;
424                 case MM_CAMCORDER_STATE_READY:
425                         state = CAMERA_STATE_CREATED;
426                         break;
427                 case MM_CAMCORDER_STATE_PREPARE:
428                         state = CAMERA_STATE_PREVIEW;
429                         break;
430                 case MM_CAMCORDER_STATE_CAPTURING:
431                         state = CAMERA_STATE_CAPTURING;
432                         break;
433                 case MM_CAMCORDER_STATE_RECORDING:
434                         state = CAMERA_STATE_PREVIEW;
435                         break;
436                 case MM_CAMCORDER_STATE_PAUSED:
437                         state = CAMERA_STATE_PREVIEW;
438                         break;
439                 default:
440                         state = CAMERA_STATE_NONE;
441                         break;
442         }
443
444         return state;
445 }
446
447
448 static int __mm_camera_message_callback(int message, void *param, void *user_data){
449         if( user_data == NULL || param == NULL )
450                 return 0;
451
452         camera_s * handle = (camera_s*)user_data;
453
454         if( handle->relay_message_callback )
455                 handle->relay_message_callback(message, param, handle->relay_user_data);
456
457         MMMessageParamType *m = (MMMessageParamType*)param;
458         camera_state_e previous_state;
459
460
461         switch(message){
462                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
463                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
464                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY:
465                         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) ){
466                                 LOGI( "Invalid state changed message");
467                                 break;
468                         }
469
470                         previous_state = handle->state;
471                         handle->state = __camera_state_convert(m->state.current );
472                         camera_policy_e policy = CAMERA_POLICY_NONE;
473                         if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM) {
474                                 switch (m->state.code) {
475                                 case ASM_EVENT_SOURCE_CALL_START:
476                                         policy = CAMERA_POLICY_SOUND_BY_CALL;
477                                         LOGW("CAMERA_POLICY_SOUND_BY_CALL");
478                                         break;
479                                 case ASM_EVENT_SOURCE_ALARM_START:
480                                 case ASM_EVENT_SOURCE_ALARM_END:
481                                         policy = CAMERA_POLICY_SOUND_BY_ALARM;
482                                         LOGW("CAMERA_POLICY_SOUND_BY_ALARM");
483                                         break;
484                                 default:
485                                         policy = CAMERA_POLICY_SOUND;
486                                         LOGW("CAMERA_POLICY_SOUND");
487                                         break;
488                                 }
489                         } else if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY) {
490                                 policy = CAMERA_POLICY_SECURITY;
491                                 LOGW("CAMERA_POLICY_SECURITY");
492                         }
493
494                         if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] ){
495                                 ((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]);
496                         }
497
498                         // should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state
499                         if( policy != CAMERA_POLICY_NONE &&
500                             m->state.current == MM_CAMCORDER_STATE_NULL ){
501                                 if( handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED]){
502                                         ((camera_interrupted_cb)handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED]);
503                                 } else {
504                                         LOGW("_CAMERA_EVENT_TYPE_INTERRUPTED cb is NULL");
505                                 }
506                         }
507
508                         break;
509                 case MM_MESSAGE_CAMCORDER_FOCUS_CHANGED :
510                         if( handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] ){
511                                 ((camera_focus_changed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE])( m->code, handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
512                         }
513                         break;
514                 case MM_MESSAGE_CAMCORDER_CAPTURED:
515                 {
516                         handle->current_capture_complete_count = m->code;
517                         if( handle->capture_count == 1 || m->code == handle->capture_count ||(handle->is_continuous_shot_break && handle->state == CAMERA_STATE_CAPTURING) ){
518                                 //pseudo state change
519                                 previous_state = handle->state ;
520                                 handle->state = CAMERA_STATE_CAPTURED;
521                                 if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] ){
522                                         ((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]);
523                                 }
524                                 if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] ){
525                                         ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]);
526                                 }
527                         }
528                         break;
529                 }
530                 case MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED:
531                 case MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED:
532                 {
533                         MMCamRecordingReport *report = (MMCamRecordingReport *)m ->data;
534                         if( report != NULL && report->recording_filename ){
535                                 free(report->recording_filename );
536                                 report->recording_filename = NULL;
537                         }
538                         if( report ){
539                                 free(report);
540                                 report = NULL;
541                         }
542                         break;
543                 }
544                 case MM_MESSAGE_CAMCORDER_VIDEO_SNAPSHOT_CAPTURED:
545                 {
546                         if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] ){
547                                 ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]);
548                         }
549                         break;
550                 }
551                 case MM_MESSAGE_CAMCORDER_ERROR:
552                 {
553                         int errorcode = m->code;
554                         int camera_error = 0;
555                         switch( errorcode ){
556                                 case MM_ERROR_CAMCORDER_DEVICE :
557                                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT:
558                                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG:
559                                         camera_error = CAMERA_ERROR_DEVICE;
560                                         break;
561                                 case MM_ERROR_CAMCORDER_GST_CORE:
562                                 case MM_ERROR_CAMCORDER_GST_LIBRARY:
563                                 case MM_ERROR_CAMCORDER_GST_RESOURCE:
564                                 case MM_ERROR_CAMCORDER_GST_STREAM:
565                                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION:
566                                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR:
567                                 case MM_ERROR_CAMCORDER_ENCODER:
568                                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER:
569                                 case MM_ERROR_CAMCORDER_ENCODER_WORKING:
570                                 case MM_ERROR_CAMCORDER_MNOTE_CREATION:
571                                 case MM_ERROR_CAMCORDER_MNOTE_ADD_ENTRY:
572                                 case MM_ERROR_CAMCORDER_INTERNAL:
573                                 case MM_ERROR_FILE_NOT_FOUND:
574                                 case MM_ERROR_FILE_READ:
575                                         camera_error = CAMERA_ERROR_INVALID_OPERATION;
576                                         break;
577                                 case MM_ERROR_CAMCORDER_LOW_MEMORY:
578                                 case MM_ERROR_CAMCORDER_MNOTE_MALLOC:
579                                         camera_error = CAMERA_ERROR_OUT_OF_MEMORY;
580                                         break;
581                                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
582                                         camera_error = CAMERA_ERROR_ESD;
583                                         break;
584                                 default :
585                                         camera_error = CAMERA_ERROR_INVALID_OPERATION;
586                                         break;
587                         }
588
589                         /* set capture completed flag as true to release camera handle */
590                         handle->is_capture_completed = true;
591
592                         if( camera_error != 0 && handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] )
593                                 ((camera_error_cb)handle->user_cb[_CAMERA_EVENT_TYPE_ERROR])(camera_error, handle->state , handle->user_data[_CAMERA_EVENT_TYPE_ERROR]);
594
595                         break;
596                 }
597                 case MM_MESSAGE_CAMCORDER_HDR_PROGRESS:
598                 {
599                         int percent = m->code;
600                         if( handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] )
601                                 ((camera_attr_hdr_progress_cb)handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS])(percent, handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
602                         break;
603                 }
604                 case MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO:
605                 {
606                         MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)(m->data);
607                         if ( cam_fd_info ) {
608                                 camera_detected_face_s faces[cam_fd_info->num_of_faces];
609                                 handle->num_of_faces = cam_fd_info->num_of_faces > MAX_DETECTED_FACE ? MAX_DETECTED_FACE : cam_fd_info->num_of_faces;
610                                 int i;
611                                 for(i=0; i < handle->num_of_faces ; i++){
612                                         faces[i].id = cam_fd_info->face_info[i].id;
613                                         faces[i].score = cam_fd_info->face_info[i].score;
614                                         faces[i].x = cam_fd_info->face_info[i].rect.x;
615                                         faces[i].y = cam_fd_info->face_info[i].rect.y;
616                                         faces[i].width = cam_fd_info->face_info[i].rect.width;
617                                         faces[i].height = cam_fd_info->face_info[i].rect.height;
618                                         handle->faceinfo[i] = faces[i]; //cache face coordinate
619                                 }
620                                 if( handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION] )
621                                         ((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]);
622                         }else{
623                                 handle->num_of_faces = 0;
624                         }
625                         break;
626                 }
627                 default:
628                         break;
629         }
630
631         return 1;
632 }
633
634 static int __capture_completed_event_cb(void *data){
635         camera_s *handle = (camera_s*)data;
636         if( handle->current_capture_count > 0 && handle->current_capture_count == handle->current_capture_complete_count && handle->state == CAMERA_STATE_CAPTURING ){
637                 //pseudo state change
638                 camera_state_e previous_state = handle->state;
639                 handle->state = CAMERA_STATE_CAPTURED;
640                 if( previous_state != handle->state && handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] ){
641                         ((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]);
642                 }
643                 if( handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] ){
644                         ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]);
645                 }
646         }
647         return false;
648 }
649
650 int camera_create(camera_device_e device, camera_h* camera){
651
652         if( camera == NULL ){
653                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
654                 return CAMERA_ERROR_INVALID_PARAMETER;
655         }
656
657         int ret;
658         MMCamPreset info;
659         int preview_format;
660         int rotation;
661
662         LOGW("device name = [%d]",device);
663
664         info.videodev_type = device;
665
666         camera_s* handle = (camera_s*)malloc( sizeof(camera_s) );
667         if( handle==NULL ){
668                 LOGE("malloc fail");
669                 return CAMERA_ERROR_OUT_OF_MEMORY;
670         }
671         memset(handle, 0 , sizeof(camera_s));
672
673         ret = mm_camcorder_create(&handle->mm_handle, &info);
674         if( ret != MM_ERROR_NONE ){
675                 free(handle);
676                 return __convert_camera_error_code(__func__,ret);
677         }
678
679         preview_format = MM_PIXEL_FORMAT_YUYV;
680         rotation = MM_DISPLAY_ROTATION_NONE;
681         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
682                                           MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, &preview_format,
683                                           MMCAM_RECOMMEND_DISPLAY_ROTATION, &rotation,
684                                           MMCAM_CAPTURE_WIDTH, &handle->capture_width,
685                                           MMCAM_CAPTURE_HEIGHT, &handle->capture_height,
686                                           NULL);
687
688         char *error;
689         ret = mm_camcorder_set_attributes(handle->mm_handle, &error,
690                                           MMCAM_MODE , MM_CAMCORDER_MODE_VIDEO_CAPTURE,
691                                           MMCAM_CAMERA_FORMAT,  preview_format,
692                                           MMCAM_IMAGE_ENCODER , MM_IMAGE_CODEC_JPEG,
693                                           MMCAM_CAPTURE_FORMAT,  MM_PIXEL_FORMAT_ENCODED,
694                                           MMCAM_DISPLAY_SURFACE, MM_DISPLAY_SURFACE_NULL,
695                                           MMCAM_DISPLAY_ROTATION, rotation,
696                                           MMCAM_CAPTURE_COUNT, 1,
697                                           (void*)NULL);
698
699         handle->display_type = CAMERA_DISPLAY_TYPE_NONE;
700
701         if( ret != MM_ERROR_NONE ){
702                 LOGE("mm_camcorder_set_attributes fail(%x, %s)", ret, error);
703                 mm_camcorder_destroy(handle->mm_handle);
704                 free(error);
705                 free(handle);
706                 return __convert_camera_error_code(__func__, ret);
707         }
708
709         handle->state = CAMERA_STATE_CREATED;
710         handle->relay_message_callback = NULL;
711         handle->relay_user_data = NULL;
712         handle->capture_resolution_modified = false;
713         handle->hdr_keep_mode = false;
714         handle->focus_area_valid = false;
715         handle->is_used_in_recorder = false;
716         handle->on_continuous_focusing = false;
717         handle->cached_focus_mode = -1;
718         g_mutex_init(&handle->idle_cb_lock);
719         mm_camcorder_set_message_callback(handle->mm_handle, __mm_camera_message_callback, (void*)handle);
720
721         LOGW("camera handle %p", handle);
722
723         *camera = (camera_h)handle;
724         return __convert_camera_error_code(__func__, ret);
725 }
726
727  int camera_destroy(camera_h camera)
728 {
729         if( camera == NULL ){
730                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
731                 return CAMERA_ERROR_INVALID_PARAMETER;
732         }
733
734         int ret;
735         camera_s *handle = (camera_s*)camera;
736         if( handle->is_used_in_recorder ){
737                 LOGE("camera is using in another recorder.");
738                 return CAMERA_ERROR_INVALID_OPERATION;
739         }
740
741         LOGW("camera handle %p", handle);
742
743         ret = mm_camcorder_destroy(handle->mm_handle);
744
745         if( handle->pkt_fmt ){
746                 media_format_unref(handle->pkt_fmt);
747                 handle->pkt_fmt = NULL;
748         }
749
750         if( ret == MM_ERROR_NONE ){
751                 _camera_remove_cb_message(handle);
752                 g_mutex_clear(&handle->idle_cb_lock);
753 #ifdef HAVE_WAYLAND
754                 if (handle->wl_info) {
755                         free(handle->wl_info);
756                         handle->wl_info = NULL;
757                 }
758 #endif /* HAVE_WAYLAND */
759                 free(handle);
760         }
761
762         return __convert_camera_error_code(__func__, ret);
763 }
764
765 int camera_start_preview(camera_h camera){
766         LOGW("start");
767         if( camera == NULL ){
768                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
769                 return CAMERA_ERROR_INVALID_PARAMETER;
770         }
771
772         int ret;
773         camera_s *handle = (camera_s*)camera;
774         camera_state_e capi_state;
775         camera_get_state(camera, &capi_state);
776
777         if( capi_state == CAMERA_STATE_CAPTURED ){
778                 ret = mm_camcorder_capture_stop(handle->mm_handle);
779                 return __convert_camera_error_code(__func__, ret);
780         }
781
782         /*for receving MM_MESSAGE_CAMCORDER_CAPTURED evnet must be seted capture callback*/
783         mm_camcorder_set_video_capture_callback( handle->mm_handle, (mm_camcorder_video_capture_callback)__mm_capture_callback, (void*)handle);
784
785         MMCamcorderStateType state;
786         mm_camcorder_get_state(handle->mm_handle, &state);
787         if( state != MM_CAMCORDER_STATE_READY ){
788                 ret = mm_camcorder_realize(handle->mm_handle);
789                 if( ret != MM_ERROR_NONE ){
790                         return __convert_camera_error_code(__func__, ret);
791                 }
792         }
793
794         ret = mm_camcorder_start(handle->mm_handle);
795         if( ret != MM_ERROR_NONE ){
796                 /*start fail */
797                 mm_camcorder_unrealize(handle->mm_handle);
798         }
799
800         return __convert_camera_error_code(__func__, ret);
801 }
802
803 int camera_stop_preview(camera_h camera){
804         if( camera == NULL ){
805                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
806                 return CAMERA_ERROR_INVALID_PARAMETER;
807         }
808
809         int ret;
810         camera_s *handle = (camera_s*)camera;
811         MMCamcorderStateType state ;
812         mm_camcorder_get_state(handle->mm_handle, &state);
813
814         if( state == MM_CAMCORDER_STATE_PREPARE ){
815                 ret = mm_camcorder_stop(handle->mm_handle);
816                 if( ret != MM_ERROR_NONE ){
817                         return __convert_camera_error_code(__func__, ret);
818                 }
819         }
820
821         camera_stop_face_detection(camera);
822
823         ret = mm_camcorder_unrealize(handle->mm_handle);
824
825         return __convert_camera_error_code(__func__, ret);
826 }
827
828 int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb , camera_capture_completed_cb completed_cb , void *user_data){
829         if( camera == NULL ){
830                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
831                 return CAMERA_ERROR_INVALID_PARAMETER;
832         }
833
834         camera_s * handle = (camera_s*)camera;
835         int ret;
836         MMCamcorderStateType state;
837         mm_camcorder_get_state(handle->mm_handle, &state);
838         if( state != MM_CAMCORDER_STATE_PREPARE &&
839             state != MM_CAMCORDER_STATE_RECORDING &&
840             state != MM_CAMCORDER_STATE_PAUSED ){
841                 LOGE("INVALID_STATE(0x%08x)",CAMERA_ERROR_INVALID_STATE);
842                 return CAMERA_ERROR_INVALID_STATE;
843         }
844
845         if( handle->capture_resolution_modified ){
846                 mm_camcorder_set_attributes(handle->mm_handle, NULL,
847                                             MMCAM_CAPTURE_WIDTH, handle->capture_width,
848                                             MMCAM_CAPTURE_HEIGHT, handle->capture_height,
849                                             NULL);
850                 handle->capture_resolution_modified = false;
851         }
852         mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAPTURE_COUNT , 1,NULL);
853
854         handle->capture_count = 1;
855         handle->is_continuous_shot_break = false;
856         handle->current_capture_count = 0;
857         handle->current_capture_complete_count = 0;
858         handle->is_capture_completed = false;
859
860         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)capturing_cb;
861         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)user_data;
862         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)completed_cb;
863         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)user_data;
864         ret = mm_camcorder_capture_start(handle->mm_handle);
865         if( ret != 0 ){
866                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
867                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
868                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
869                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
870         }
871
872         return __convert_camera_error_code(__func__, ret);
873 }
874
875 bool camera_is_supported_continuous_capture(camera_h camera){
876         if( camera == NULL ){
877                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
878                 return false;
879         }
880
881         int ret = MM_ERROR_NONE;
882         camera_s * handle = (camera_s*)camera;
883         MMCamAttrsInfo info;
884         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_COUNT , &info);
885         set_last_result(__convert_camera_error_code(__func__, ret));
886         if( ret != MM_ERROR_NONE ){
887                 return false;
888         }
889         if( info.int_range.max > 1){
890                 return true;
891         } else {
892                 return false;
893         }
894 }
895
896 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){
897         if( camera == NULL ){
898                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
899                 return CAMERA_ERROR_INVALID_PARAMETER;
900         }
901
902         if( camera_is_supported_continuous_capture(camera) == false ){
903                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
904                 return CAMERA_ERROR_NOT_SUPPORTED;
905         }
906
907         if( count < 2 || interval < 0 ){
908                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
909                 return CAMERA_ERROR_INVALID_PARAMETER;
910         }
911
912         camera_s * handle = (camera_s*)camera;
913
914         MMCamcorderStateType state;
915         mm_camcorder_get_state(handle->mm_handle, &state);
916         if( state != MM_CAMCORDER_STATE_PREPARE ){
917                 LOGE("INVALID_STATE(0x%08x)",CAMERA_ERROR_INVALID_STATE);
918                 return CAMERA_ERROR_INVALID_STATE;
919         }
920
921         int supported_zsl = FALSE;
922
923         int ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
924                                               MMCAM_CAPTURE_COUNT, count,
925                                               MMCAM_CAPTURE_INTERVAL, interval,
926                                               NULL);
927         if( ret != 0 ){
928                 LOGE("(%x) error set continuous shot attribute", ret);
929                 return __convert_camera_error_code(__func__, ret);
930         }
931
932         handle->capture_count = count;
933         handle->is_continuous_shot_break = false;
934         handle->current_capture_count = 0;
935         handle->current_capture_complete_count = 0;
936         handle->is_capture_completed = false;
937
938         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_SUPPORT_ZSL_CAPTURE, &supported_zsl, NULL);
939         if( ret != 0 ){
940                 LOGE("(%x) error get continuous shot attribute", ret);
941         }
942
943         if( !supported_zsl ){
944                 int preview_width;
945                 int preview_height;
946                 int capture_width;
947                 int capture_height;
948
949                 mm_camcorder_get_attributes(handle->mm_handle, NULL,
950                                             MMCAM_CAMERA_WIDTH, &preview_width,
951                                             MMCAM_CAMERA_HEIGHT, &preview_height,
952                                             MMCAM_CAPTURE_WIDTH, &capture_width,
953                                             MMCAM_CAPTURE_HEIGHT, &capture_height,
954                                             NULL);
955                 if( preview_width != capture_width || preview_height != capture_height ){
956                         mm_camcorder_set_attributes(handle->mm_handle, NULL,
957                                                     MMCAM_CAPTURE_WIDTH, preview_width,
958                                                     MMCAM_CAPTURE_HEIGHT, preview_height,
959                                                     NULL);
960                         handle->capture_resolution_modified = true;
961                 }
962         }
963
964         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)capturing_cb;
965         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = (void*)user_data;
966         handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)completed_cb;
967         handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = (void*)user_data;
968
969         ret = mm_camcorder_capture_start(handle->mm_handle);
970         if( ret != 0 ){
971                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
972                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE] = NULL;
973                 handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
974                 handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = NULL;
975         }
976
977         return __convert_camera_error_code(__func__,ret);
978
979 }
980
981 int camera_stop_continuous_capture(camera_h camera){
982         if( camera == NULL ){
983                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
984                 return CAMERA_ERROR_INVALID_PARAMETER;
985         }
986
987         if( camera_is_supported_continuous_capture(camera) == false ){
988                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
989                 return CAMERA_ERROR_NOT_SUPPORTED;
990         }
991
992         camera_s *handle = (camera_s*)camera;
993
994         int ret;
995         camera_state_e state;
996         camera_get_state(camera, &state);
997
998         if( state != CAMERA_STATE_CAPTURING && handle->capture_count > 1 ){
999                 LOGE("INVALID_STATE(0x%08x)",CAMERA_ERROR_INVALID_STATE);
1000                 return CAMERA_ERROR_INVALID_STATE;
1001         }
1002
1003         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, "capture-break-cont-shot", 1, NULL);
1004         if( ret == MM_ERROR_NONE ){
1005                 handle->is_continuous_shot_break = true;
1006                 if( handle->current_capture_count > 0 ){
1007                         handle->is_capture_completed = true;
1008                 }
1009                 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __capture_completed_event_cb, handle, NULL);
1010         }
1011
1012         return __convert_camera_error_code(__func__,ret);
1013 }
1014
1015 bool camera_is_supported_face_detection(camera_h camera){
1016         if (camera == NULL) {
1017                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1018                 return false;
1019         }
1020
1021         int i = 0;
1022         int ret = MM_ERROR_NONE;
1023         camera_s *handle = (camera_s *)camera;
1024         MMCamAttrsInfo info;
1025
1026         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_DETECT_MODE , &info);
1027         set_last_result(__convert_camera_error_code(__func__, ret));
1028         if( ret != MM_ERROR_NONE ){
1029                 LOGE("MMCAM_DETECT_MODE get attr info failed");
1030                 return false;
1031         }
1032
1033         if( info.validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY ){
1034                 for( i = 0 ; i < info.int_array.count ; i++ ){
1035                         if( info.int_array.array[i] == MM_CAMCORDER_DETECT_MODE_ON ){
1036                                 LOGD("face detection supported");
1037                                 return true;
1038                         }
1039                 }
1040         }
1041
1042         LOGD("face detection NOT supported");
1043
1044         return false;
1045 }
1046
1047 bool camera_is_supported_zero_shutter_lag(camera_h camera){
1048         int ret = MM_ERROR_NONE;
1049         int supported_zsl = false;
1050         camera_s *handle = (camera_s *)camera;
1051
1052         if( camera == NULL ){
1053                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1054                 return false;
1055         }
1056
1057         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_SUPPORT_ZSL_CAPTURE, &supported_zsl, NULL);
1058         set_last_result(__convert_camera_error_code(__func__, ret));
1059         if( ret != MM_ERROR_NONE ){
1060                 LOGE("MMCAM_SUPPORT_ZSL_CAPTURE get failed");
1061                 return false;
1062         }
1063
1064         LOGD("support zero shutter lag : %d", supported_zsl);
1065
1066         return supported_zsl;
1067 }
1068
1069 bool camera_is_supported_media_packet_preview_cb(camera_h camera){
1070         int ret = MM_ERROR_NONE;
1071         int supported = false;
1072         camera_s *handle = (camera_s *)camera;
1073
1074         if( camera == NULL ){
1075                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1076                 return false;
1077         }
1078
1079         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1080                                           MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, &supported,
1081                                           NULL);
1082         set_last_result(__convert_camera_error_code(__func__, ret));
1083         if( ret != MM_ERROR_NONE ){
1084                 LOGE("MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB get failed");
1085                 return false;
1086         }
1087
1088         LOGD("support media packet preview callback : %d", supported);
1089
1090         return supported;
1091 }
1092
1093 int camera_get_device_count(camera_h camera, int *device_count){
1094         int ret = MM_ERROR_NONE;
1095         camera_s *handle = (camera_s *)camera;
1096
1097         if( camera == NULL || device_count == NULL ){
1098                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1099                 return CAMERA_ERROR_INVALID_PARAMETER;
1100         }
1101
1102         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1103                                           MMCAM_CAMERA_DEVICE_COUNT, device_count,
1104                                           NULL);
1105
1106         return __convert_camera_error_code(__func__, ret);
1107 }
1108
1109 int camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void * user_data){
1110         if( camera == NULL ){
1111                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1112                 return CAMERA_ERROR_INVALID_PARAMETER;
1113         }
1114
1115         if( camera_is_supported_face_detection(camera) == false ){
1116                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
1117                 return CAMERA_ERROR_NOT_SUPPORTED;
1118         }
1119
1120         camera_s * handle = (camera_s*)camera;
1121         camera_state_e state = CAMERA_STATE_NONE;
1122         int ret;
1123         camera_get_state(camera, &state);
1124         if( state != CAMERA_STATE_PREVIEW ){
1125                 LOGE("INVALID_STATE(0x%08x)",CAMERA_ERROR_INVALID_STATE);
1126                 return CAMERA_ERROR_INVALID_STATE;
1127         }
1128
1129         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1130                                           MMCAM_DETECT_MODE, MM_CAMCORDER_DETECT_MODE_ON,
1131                                           NULL);
1132         if( ret == MM_ERROR_NONE ){
1133                 handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION] = (void*)callback;
1134                 handle->user_data[_CAMERA_EVENT_TYPE_FACE_DETECTION] = (void*)user_data;
1135                 handle->num_of_faces = 0;
1136         }
1137
1138         return __convert_camera_error_code(__func__,ret);
1139 }
1140
1141 int camera_stop_face_detection(camera_h camera){
1142         if( camera == NULL ){
1143                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1144                 return CAMERA_ERROR_INVALID_PARAMETER;
1145         }
1146         camera_s * handle = (camera_s*)camera;
1147         int ret;
1148
1149         if( camera_is_supported_face_detection(camera) == false ){
1150                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
1151                 return CAMERA_ERROR_NOT_SUPPORTED;
1152         }
1153
1154         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DETECT_MODE, MM_CAMCORDER_DETECT_MODE_OFF, NULL);
1155         handle->user_cb[_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
1156         handle->user_data[_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
1157         handle->num_of_faces = 0;
1158         return __convert_camera_error_code(__func__,ret);
1159 }
1160
1161 int camera_get_state(camera_h camera, camera_state_e * state){
1162         if( camera == NULL || state == NULL ){
1163                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1164                 return CAMERA_ERROR_INVALID_PARAMETER;
1165         }
1166
1167         camera_s *handle = (camera_s*)camera;
1168         camera_state_e capi_state;
1169         MMCamcorderStateType mmstate ;
1170         mm_camcorder_get_state(handle->mm_handle, &mmstate);
1171
1172         capi_state = __camera_state_convert(mmstate);
1173
1174         if( (handle->state == CAMERA_STATE_CAPTURED || handle->is_capture_completed) && (handle->current_capture_count > 0 || handle->is_capture_completed) && mmstate == MM_CAMCORDER_STATE_CAPTURING ){
1175                 capi_state = CAMERA_STATE_CAPTURED;
1176         }
1177
1178         *state = capi_state;
1179         return CAMERA_ERROR_NONE;
1180 }
1181
1182 int camera_start_focusing( camera_h camera, bool continuous ){
1183         if( camera == NULL ){
1184                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1185                 return CAMERA_ERROR_INVALID_PARAMETER;
1186         }
1187         camera_s *handle = (camera_s*)camera;
1188
1189         if( handle->cached_focus_mode != -1 ){
1190                 LOGD("apply cached focus mode %d", handle->cached_focus_mode);
1191                 mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_AF_SCAN_RANGE  , handle->cached_focus_mode, NULL);
1192                 handle->cached_focus_mode = -1;
1193         }
1194
1195         if( continuous )
1196                 return __camera_start_continuous_focusing(camera);
1197         else{
1198                 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);
1199                 return __convert_camera_error_code(__func__, mm_camcorder_start_focusing(((camera_s*)camera)->mm_handle));
1200         }
1201 }
1202
1203 int __camera_start_continuous_focusing(camera_h camera){
1204         if( camera == NULL ){
1205                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1206                 return CAMERA_ERROR_INVALID_PARAMETER;
1207         }
1208
1209         camera_s *handle = (camera_s*)camera;
1210         int ret;
1211         int mode;
1212         handle->on_continuous_focusing = true;
1213         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FOCUS_MODE , &mode, NULL);
1214
1215         if( mode == MM_CAMCORDER_FOCUS_MODE_CONTINUOUS )
1216                 ret = mm_camcorder_start_focusing(handle->mm_handle);
1217         else
1218                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_CONTINUOUS, NULL);
1219         return __convert_camera_error_code(__func__, ret);
1220 }
1221
1222 int camera_cancel_focusing(camera_h camera){
1223         if( camera == NULL ){
1224                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1225                 return CAMERA_ERROR_INVALID_PARAMETER;
1226         }
1227         camera_s *handle = (camera_s*)camera;
1228         handle->on_continuous_focusing = false;
1229         return __convert_camera_error_code(__func__, mm_camcorder_stop_focusing(handle->mm_handle));
1230 }
1231
1232 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display)
1233 {
1234         int ret = MM_ERROR_NONE;
1235         int set_surface = MM_DISPLAY_SURFACE_X;
1236         void *set_handle = NULL;
1237         camera_s *handle = NULL;
1238
1239         Evas_Object *obj = NULL;
1240         const char *object_type = NULL;
1241
1242         if( camera == NULL ){
1243                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1244                 return CAMERA_ERROR_INVALID_PARAMETER;
1245         }
1246
1247         if( type != CAMERA_DISPLAY_TYPE_NONE && display == NULL ){
1248                 LOGE("display type[%d] is not NONE, but display handle is NULL", type);
1249                 return CAMERA_ERROR_INVALID_PARAMETER;
1250         }
1251
1252         handle = (camera_s *)camera;
1253         handle->display_type = type;
1254
1255         if( type == CAMERA_DISPLAY_TYPE_NONE ){
1256                 /* NULL surface */
1257                 set_surface = MM_DISPLAY_SURFACE_NULL;
1258                 handle->display_handle = 0;
1259
1260                 LOGD("display type NONE");
1261         } else {
1262                 obj = (Evas_Object *)display;
1263                 object_type = evas_object_type_get(obj);
1264                 if( object_type ){
1265                         if( type == CAMERA_DISPLAY_TYPE_OVERLAY && !strcmp(object_type, "elm_win") ){
1266 #ifdef HAVE_WAYLAND
1267                                 MMCamWaylandInfo *wl_info = (MMCamWaylandInfo *)malloc(sizeof(MMCamWaylandInfo));
1268
1269                                 if (wl_info == NULL) {
1270                                         LOGE("wl_info alloc failed : %d", sizeof(MMCamWaylandInfo));
1271                                         return __convert_camera_error_code(__func__, MM_ERROR_CAMCORDER_LOW_MEMORY);
1272                                 }
1273
1274                                 memset(wl_info, 0x0, sizeof(MMCamWaylandInfo));
1275
1276                                 wl_info->evas_obj = (void *)obj;
1277                                 wl_info->window = (void *)elm_win_wl_window_get(obj);
1278                                 wl_info->surface = (void *)ecore_wl_window_surface_get(wl_info->window);
1279                                 wl_info->display = (void *)ecore_wl_display_get();
1280
1281                                 if (wl_info->window == NULL || wl_info->surface == NULL || wl_info->display == NULL) {
1282                                         LOGE("something is NULL %p, %p, %p", wl_info->window, wl_info->surface, wl_info->display);
1283                                         free(wl_info);
1284                                         return __convert_camera_error_code(__func__, MM_ERROR_CAMCORDER_INTERNAL);
1285                                 }
1286
1287                                 evas_object_geometry_get(obj, &wl_info->window_x, &wl_info->window_y,
1288                                                               &wl_info->window_width, &wl_info->window_height);
1289
1290                                 if (handle->wl_info) {
1291                                         free(handle->wl_info);
1292                                         handle->wl_info = NULL;
1293                                 }
1294
1295                                 /* set wayland info */
1296                                 handle->wl_info = (void *)wl_info;
1297                                 set_surface = MM_DISPLAY_SURFACE_X;
1298                                 set_handle = (void *)wl_info;
1299
1300                                 LOGD("wayland obj %p, window %p, surface %p, display %p, size %d,%d,%dx%d",
1301                                      wl_info->evas_obj, wl_info->window, wl_info->surface, wl_info->display,
1302                                      wl_info->window_x, wl_info->window_y, wl_info->window_width, wl_info->window_height);
1303 #else /* HAVE_WAYLAND */
1304                                 /* x window overlay surface */
1305                                 handle->display_handle = (void *)elm_win_xwindow_get(obj);
1306                                 set_surface = MM_DISPLAY_SURFACE_X;
1307                                 set_handle = &(handle->display_handle);
1308
1309                                 LOGD("display type OVERLAY : handle %p, %d", set_handle, (int)handle->display_handle);
1310 #endif /* HAVE_WAYLAND */
1311                         } else if( type == CAMERA_DISPLAY_TYPE_EVAS && !strcmp(object_type, "image") ) {
1312                                 /* evas object surface */
1313                                 handle->display_handle = display;
1314                                 set_surface = MM_DISPLAY_SURFACE_EVAS;
1315                                 set_handle = display;
1316
1317                                 LOGD("display type EVAS : handle %p", set_handle);
1318                         } else {
1319                                 LOGE("unknown evas object [%p,%s] or type [%d] mismatch", obj, object_type, type);
1320                                 return CAMERA_ERROR_INVALID_PARAMETER;
1321                         }
1322                 } else {
1323                         LOGE("failed to get evas object type from %p", obj);
1324                         return CAMERA_ERROR_INVALID_PARAMETER;
1325                 }
1326         }
1327
1328         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1329                                           MMCAM_DISPLAY_DEVICE, MM_DISPLAY_DEVICE_MAINLCD,
1330                                           MMCAM_DISPLAY_SURFACE, set_surface,
1331                                           NULL);
1332
1333         if( ret == MM_ERROR_NONE && type != CAMERA_DISPLAY_TYPE_NONE ){
1334                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_HANDLE, set_handle, sizeof(void *), NULL);
1335         }
1336
1337         return __convert_camera_error_code(__func__, ret);
1338 }
1339
1340 int camera_set_preview_resolution(camera_h camera,  int width, int height){
1341         if( camera == NULL ){
1342                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1343                 return CAMERA_ERROR_INVALID_PARAMETER;
1344         }
1345         int ret;
1346         camera_s * handle = (camera_s*)camera;
1347         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_WIDTH  , width ,MMCAM_CAMERA_HEIGHT ,height,  NULL);
1348         return __convert_camera_error_code(__func__, ret);
1349 }
1350
1351 int camera_set_capture_resolution(camera_h camera,  int width, int height){
1352         if( camera == NULL ){
1353                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1354                 return CAMERA_ERROR_INVALID_PARAMETER;
1355         }
1356
1357         int ret;
1358         camera_s * handle = (camera_s*)camera;
1359         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAPTURE_WIDTH, width  ,MMCAM_CAPTURE_HEIGHT , height, NULL);
1360
1361         if( ret == MM_ERROR_NONE ){
1362                 handle->capture_width = width;
1363                 handle->capture_height = height;
1364         }
1365
1366         return __convert_camera_error_code(__func__, ret);
1367 }
1368
1369 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format){
1370         if( camera == NULL ){
1371                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1372                 return CAMERA_ERROR_INVALID_PARAMETER;
1373         }
1374
1375         int ret;
1376         camera_s * handle = (camera_s*)camera;
1377         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAPTURE_FORMAT, format , NULL);
1378
1379         return __convert_camera_error_code(__func__, ret);
1380 }
1381
1382 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format){
1383         if( camera == NULL ){
1384                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1385                 return CAMERA_ERROR_INVALID_PARAMETER;
1386         }
1387
1388         int ret;
1389         camera_s * handle = (camera_s*)camera;
1390
1391         if( format == CAMERA_PIXEL_FORMAT_UYVY ){
1392                 bool supported_ITLV_UYVY = false;
1393                 MMCamAttrsInfo supported_format;
1394                 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT , &supported_format);
1395                 int i;
1396                 for( i=0 ; i < supported_format.int_array.count ; i++ ){
1397                         if( supported_format.int_array.array[i] == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
1398                                 supported_ITLV_UYVY = true;
1399                 }
1400                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1401                                                   MMCAM_CAMERA_FORMAT, supported_ITLV_UYVY ? MM_PIXEL_FORMAT_ITLV_JPEG_UYVY : MM_PIXEL_FORMAT_UYVY,
1402                                                   NULL);
1403         } else {
1404                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FORMAT, format , NULL);
1405         }
1406
1407         return __convert_camera_error_code(__func__, ret);
1408 }
1409
1410 int camera_get_preview_resolution(camera_h camera,  int *width, int *height){
1411         if( camera == NULL || width == NULL || height == NULL ){
1412                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1413                 return CAMERA_ERROR_INVALID_PARAMETER;
1414         }
1415
1416         int ret;
1417         camera_s * handle = (camera_s*)camera;
1418         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1419                                           MMCAM_CAMERA_WIDTH, width,
1420                                           MMCAM_CAMERA_HEIGHT, height,
1421                                           NULL);
1422
1423         return __convert_camera_error_code(__func__, ret);
1424 }
1425
1426 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation){
1427         if( camera == NULL ){
1428                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1429                 return CAMERA_ERROR_INVALID_PARAMETER;
1430         }
1431
1432         if( rotation > CAMERA_ROTATION_270 )
1433                 return CAMERA_ERROR_INVALID_PARAMETER;
1434
1435         int ret;
1436         camera_s * handle = (camera_s*)camera;
1437
1438         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1439                                           MMCAM_DISPLAY_ROTATION, rotation,
1440                                           NULL);
1441
1442         return __convert_camera_error_code(__func__, ret);
1443 }
1444
1445 int camera_get_display_rotation( camera_h camera,  camera_rotation_e *rotation){
1446         if( camera == NULL || rotation == NULL ){
1447                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1448                 return CAMERA_ERROR_INVALID_PARAMETER;
1449         }
1450
1451         int ret;
1452         camera_s * handle = (camera_s*)camera;
1453
1454         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_ROTATION , rotation, NULL);
1455         return __convert_camera_error_code(__func__, ret);
1456 }
1457
1458 int camera_set_display_flip(camera_h camera, camera_flip_e flip){
1459         if( camera == NULL ){
1460                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1461                 return CAMERA_ERROR_INVALID_PARAMETER;
1462         }
1463
1464         if( flip > CAMERA_FLIP_BOTH )
1465                 return CAMERA_ERROR_INVALID_PARAMETER;
1466
1467         int ret;
1468         camera_s * handle = (camera_s*)camera;
1469
1470         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1471                                           MMCAM_DISPLAY_FLIP, flip,
1472                                           NULL);
1473
1474         return __convert_camera_error_code(__func__, ret);
1475 }
1476
1477 int camera_get_display_flip(camera_h camera, camera_flip_e *flip){
1478         if( camera == NULL || flip == NULL ){
1479                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1480                 return CAMERA_ERROR_INVALID_PARAMETER;
1481         }
1482
1483         int ret;
1484         camera_s * handle = (camera_s*)camera;
1485
1486         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1487                                           MMCAM_DISPLAY_FLIP, flip,
1488                                           NULL);
1489
1490         return __convert_camera_error_code(__func__, ret);
1491 }
1492
1493 int camera_set_display_visible(camera_h camera, bool visible){
1494         if( camera == NULL ){
1495                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1496                 return CAMERA_ERROR_INVALID_PARAMETER;
1497         }
1498
1499         int ret;
1500         camera_s * handle = (camera_s*)camera;
1501
1502         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1503                                           MMCAM_DISPLAY_VISIBLE, visible,
1504                                           NULL);
1505
1506         return __convert_camera_error_code(__func__, ret);
1507 }
1508
1509 int camera_is_display_visible(camera_h camera, bool* visible){
1510         if( camera == NULL || visible == NULL ){
1511                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1512                 return CAMERA_ERROR_INVALID_PARAMETER;
1513         }
1514
1515         int ret;
1516         int result;
1517         camera_s * handle = (camera_s*)camera;
1518
1519         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1520                                           MMCAM_DISPLAY_VISIBLE, &result,
1521                                           NULL);
1522
1523         if( ret == MM_ERROR_NONE)
1524                 *visible = result;
1525
1526         return __convert_camera_error_code(__func__, ret);
1527 }
1528
1529 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode){
1530         if( camera == NULL ){
1531                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1532                 return CAMERA_ERROR_INVALID_PARAMETER;
1533         }
1534
1535         if( mode > CAMERA_DISPLAY_MODE_CROPPED_FULL )
1536                 return CAMERA_ERROR_INVALID_PARAMETER;
1537
1538         int ret;
1539         camera_s * handle = (camera_s*)camera;
1540
1541         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1542                                           MMCAM_DISPLAY_GEOMETRY_METHOD, mode,
1543                                           NULL);
1544
1545         return __convert_camera_error_code(__func__, ret);
1546 }
1547
1548 int camera_get_display_mode(camera_h camera, camera_display_mode_e* mode){
1549         if( camera == NULL || mode == NULL ){
1550                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1551                 return CAMERA_ERROR_INVALID_PARAMETER;
1552         }
1553
1554         int ret;
1555         camera_s * handle = (camera_s*)camera;
1556
1557         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1558                                           MMCAM_DISPLAY_GEOMETRY_METHOD, mode,
1559                                           NULL);
1560
1561         return __convert_camera_error_code(__func__, ret);
1562 }
1563
1564 int camera_get_capture_resolution(camera_h camera, int *width, int *height){
1565         if( camera == NULL || width== NULL || height == NULL){
1566                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1567                 return CAMERA_ERROR_INVALID_PARAMETER;
1568         }
1569
1570         camera_s * handle = (camera_s*)camera;
1571         *width = handle->capture_width;
1572         *height = handle->capture_height;
1573
1574         return CAMERA_ERROR_NONE;
1575 }
1576
1577 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format){
1578         if( camera == NULL || format == NULL ){
1579                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1580                 return CAMERA_ERROR_INVALID_PARAMETER;
1581         }
1582
1583         int ret;
1584         camera_s * handle = (camera_s*)camera;
1585
1586         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1587                                           MMCAM_CAPTURE_FORMAT, format,
1588                                           NULL);
1589
1590         return __convert_camera_error_code(__func__, ret);
1591 }
1592
1593 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format){
1594         if( camera == NULL || format == NULL ){
1595                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1596                 return CAMERA_ERROR_INVALID_PARAMETER;
1597         }
1598
1599         int ret;
1600         camera_s * handle = (camera_s*)camera;
1601
1602         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1603                                           MMCAM_CAMERA_FORMAT, format,
1604                                           NULL);
1605
1606         if( (MMPixelFormatType)*format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
1607                 *format = CAMERA_PIXEL_FORMAT_UYVY;
1608
1609         return __convert_camera_error_code(__func__, ret);
1610 }
1611
1612 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void* user_data){
1613         if( camera == NULL || callback == NULL ){
1614                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1615                 return CAMERA_ERROR_INVALID_PARAMETER;
1616         }
1617
1618         camera_s *handle = (camera_s *)camera;
1619         handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void*)callback;
1620         handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void*)user_data;
1621
1622         mm_camcorder_set_video_stream_callback(handle->mm_handle,
1623                                                (mm_camcorder_video_stream_callback)__mm_videostream_callback,
1624                                                (void *)handle);
1625
1626         return CAMERA_ERROR_NONE;
1627 }
1628
1629 int camera_unset_preview_cb( camera_h camera){
1630         if( camera == NULL ){
1631                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1632                 return CAMERA_ERROR_INVALID_PARAMETER;
1633         }
1634
1635         camera_s *handle = (camera_s *)camera;
1636
1637         if( handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] == NULL ){
1638                 mm_camcorder_set_video_stream_callback(handle->mm_handle,
1639                                                        (mm_camcorder_video_stream_callback)NULL,
1640                                                        (void *)NULL);
1641         }
1642
1643         handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)NULL;
1644         handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)NULL;
1645
1646         return CAMERA_ERROR_NONE;
1647 }
1648
1649 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void* user_data){
1650         if( camera == NULL ){
1651                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
1652                 return CAMERA_ERROR_INVALID_PARAMETER;
1653         }
1654
1655         if( camera_is_supported_media_packet_preview_cb(camera) == false ){
1656                 LOGE("NOT SUPPORTED");
1657                 return CAMERA_ERROR_NOT_SUPPORTED;
1658         }
1659
1660         if( callback == NULL ){
1661                 LOGE("INVALID_PARAMETER(0x%08x) - callback", CAMERA_ERROR_INVALID_PARAMETER);
1662                 return CAMERA_ERROR_INVALID_PARAMETER;
1663         }
1664
1665         camera_s *handle = (camera_s *)camera;
1666         handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)callback;
1667         handle->user_data[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)user_data;
1668
1669         mm_camcorder_set_video_stream_callback(handle->mm_handle,
1670                                                (mm_camcorder_video_stream_callback)__mm_videostream_callback,
1671                                                (void *)handle);
1672
1673         return CAMERA_ERROR_NONE;
1674 }
1675
1676 int camera_unset_media_packet_preview_cb(camera_h camera){
1677         if( camera == NULL ){
1678                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1679                 return CAMERA_ERROR_INVALID_PARAMETER;
1680         }
1681
1682         if( camera_is_supported_media_packet_preview_cb(camera) == false ){
1683                 LOGE("NOT SUPPORTED");
1684                 return CAMERA_ERROR_NOT_SUPPORTED;
1685         }
1686
1687         camera_s *handle = (camera_s *)camera;
1688
1689         if( handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] == NULL ){
1690                 mm_camcorder_set_video_stream_callback(handle->mm_handle,
1691                                                        (mm_camcorder_video_stream_callback)NULL,
1692                                                        (void*)NULL);
1693         }
1694
1695         handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void*)NULL;
1696         handle->user_data[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void*)NULL;
1697
1698         return CAMERA_ERROR_NONE;
1699 }
1700
1701 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void* user_data){
1702         if( camera == NULL || callback == NULL ){
1703                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1704                 return CAMERA_ERROR_INVALID_PARAMETER;
1705         }
1706
1707         camera_s * handle = (camera_s*)camera;
1708         handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)callback;
1709         handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)user_data;
1710
1711         return CAMERA_ERROR_NONE;
1712 }
1713 int camera_unset_state_changed_cb(camera_h camera){
1714         if( camera == NULL ){
1715                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1716                 return CAMERA_ERROR_INVALID_PARAMETER;
1717         }
1718
1719         camera_s * handle = (camera_s*)camera;
1720         handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)NULL;
1721         handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void*)NULL;
1722
1723         return CAMERA_ERROR_NONE;
1724 }
1725
1726 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data){
1727         if( camera == NULL || callback == NULL ){
1728                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1729                 return CAMERA_ERROR_INVALID_PARAMETER;
1730         }
1731
1732         camera_s * handle = (camera_s*)camera;
1733         handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)callback;
1734         handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)user_data;
1735
1736         return CAMERA_ERROR_NONE;
1737 }
1738
1739 int camera_unset_interrupted_cb(camera_h camera){
1740         if( camera == NULL ){
1741                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1742                 return CAMERA_ERROR_INVALID_PARAMETER;
1743         }
1744
1745         camera_s * handle = (camera_s*)camera;
1746         handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)NULL;
1747         handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void*)NULL;
1748
1749         return CAMERA_ERROR_NONE;
1750 }
1751
1752 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void* user_data){
1753         if( camera == NULL || callback == NULL ){
1754                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1755                 return CAMERA_ERROR_INVALID_PARAMETER;
1756         }
1757
1758         camera_s * handle = (camera_s*)camera;
1759         handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)callback;
1760         handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)user_data;
1761
1762         return CAMERA_ERROR_NONE;
1763 }
1764 int camera_unset_focus_changed_cb(camera_h camera){
1765         if( camera == NULL ){
1766                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1767                 return CAMERA_ERROR_INVALID_PARAMETER;
1768         }
1769
1770         camera_s * handle = (camera_s*)camera;
1771         handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)NULL;
1772         handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void*)NULL;
1773
1774         return CAMERA_ERROR_NONE;
1775 }
1776
1777 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data){
1778         if( camera == NULL || callback == NULL ){
1779                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1780                 return CAMERA_ERROR_INVALID_PARAMETER;
1781         }
1782
1783         camera_s * handle = (camera_s*)camera;
1784         handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void*)callback;
1785         handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void*)user_data;
1786
1787         return CAMERA_ERROR_NONE;
1788 }
1789
1790 int camera_unset_error_cb(camera_h camera){
1791         if( camera == NULL ){
1792                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1793                 return CAMERA_ERROR_INVALID_PARAMETER;
1794         }
1795
1796         camera_s * handle = (camera_s*)camera;
1797         handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void*)NULL;
1798         handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void*)NULL;
1799
1800         return CAMERA_ERROR_NONE;
1801 }
1802
1803 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb , void *user_data){
1804         if( camera == NULL || foreach_cb == NULL ){
1805                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1806                 return CAMERA_ERROR_INVALID_PARAMETER;
1807         }
1808
1809         int ret;
1810         camera_s * handle = (camera_s*)camera;
1811         MMCamAttrsInfo preview_width;
1812         MMCamAttrsInfo preview_height;
1813         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WIDTH , &preview_width);
1814         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HEIGHT , &preview_height);
1815
1816         if( ret != CAMERA_ERROR_NONE )
1817                 return __convert_camera_error_code(__func__, ret);
1818
1819         int i;
1820         for( i=0 ; i < preview_width.int_array.count ; i++ ){
1821                 if( !foreach_cb(preview_width.int_array.array[i], preview_height.int_array.array[i],user_data) )
1822                         break;
1823         }
1824
1825         return CAMERA_ERROR_NONE;
1826 }
1827
1828 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb , void *user_data){
1829         if( camera == NULL || foreach_cb == NULL){
1830                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1831                 return CAMERA_ERROR_INVALID_PARAMETER;
1832         }
1833         int ret;
1834         camera_s * handle = (camera_s*)camera;
1835         MMCamAttrsInfo capture_width;
1836         MMCamAttrsInfo capture_height;
1837         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_WIDTH , &capture_width);
1838         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_HEIGHT , &capture_height);
1839
1840         if( ret != CAMERA_ERROR_NONE )
1841                 return __convert_camera_error_code(__func__, ret);
1842
1843         int i;
1844         for( i=0 ; i < capture_width.int_array.count ; i++)
1845         {
1846                 if ( !foreach_cb(capture_width.int_array.array[i], capture_height.int_array.array[i],user_data) )
1847                         break;
1848         }
1849         return CAMERA_ERROR_NONE;
1850 }
1851
1852 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb , void *user_data){
1853         if( camera == NULL || foreach_cb == NULL){
1854                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1855                 return CAMERA_ERROR_INVALID_PARAMETER;
1856         }
1857
1858         int ret;
1859         camera_s * handle = (camera_s*)camera;
1860         MMCamAttrsInfo format;
1861         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_FORMAT , &format);
1862
1863         if( ret != CAMERA_ERROR_NONE )
1864                 return __convert_camera_error_code(__func__, ret);
1865
1866         int i;
1867         for( i=0 ; i < format.int_array.count ; i++ ){
1868                 if( format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY )
1869                         if ( !foreach_cb(format.int_array.array[i], user_data) )
1870                                 break;
1871         }
1872
1873         return CAMERA_ERROR_NONE;
1874 }
1875
1876 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb , void *user_data){
1877         if( camera == NULL || foreach_cb == NULL ){
1878                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1879                 return CAMERA_ERROR_INVALID_PARAMETER;
1880         }
1881
1882         int ret;
1883         camera_s * handle = (camera_s*)camera;
1884         MMCamAttrsInfo format;
1885         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT , &format);
1886
1887         if( ret != CAMERA_ERROR_NONE )
1888                 return __convert_camera_error_code(__func__, ret);
1889
1890         int i;
1891         for( i=0 ; i < format.int_array.count ; i++ ){
1892                 if( format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY /* || format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_NV12 */)
1893                         if ( !foreach_cb(format.int_array.array[i], user_data) )
1894                                 break;
1895         }
1896
1897         return CAMERA_ERROR_NONE;
1898 }
1899
1900 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height){
1901         if( camera == NULL || width == NULL || height == NULL ){
1902                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1903                 return CAMERA_ERROR_INVALID_PARAMETER;
1904         }
1905
1906         enum MMCamcorderPreviewType wide;
1907         int capture_w, capture_h;
1908         double ratio;
1909         int ret;
1910         camera_s * handle = (camera_s*)camera;
1911
1912         camera_get_capture_resolution(camera, &capture_w, &capture_h);
1913         ratio = (double)capture_w/(double)capture_h;
1914         if( ratio > 1.5 ){
1915                 wide = MM_CAMCORDER_PREVIEW_TYPE_WIDE;
1916         } else if( ratio == 1.0 ){
1917                 wide = MM_CAMCORDER_PREVIEW_TYPE_SQUARE;
1918         } else {
1919                 wide = MM_CAMCORDER_PREVIEW_TYPE_NORMAL;
1920         }
1921
1922         MMCamAttrsInfo width_info, height_info;
1923         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_RECOMMEND_CAMERA_WIDTH , &width_info);
1924         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_RECOMMEND_CAMERA_HEIGHT, &height_info);
1925
1926         if( ret != 0 )
1927                 return __convert_camera_error_code(__func__, ret);
1928
1929         if( width && (unsigned int)width_info.int_array.count > wide ){
1930                 *width = width_info.int_array.array[wide];
1931         } else {
1932                 LOGE("there is no width value for resolution %dx%d type %d", capture_w, capture_h, wide);
1933                 return CAMERA_ERROR_INVALID_OPERATION;
1934         }
1935
1936         if( height && (unsigned int)height_info.int_array.count > wide ){
1937                 *height = height_info.int_array.array[wide];
1938         } else {
1939                 LOGE("there is no height value for resolution %dx%d type %d", capture_w, capture_h, wide);
1940                 return CAMERA_ERROR_INVALID_OPERATION;
1941         }
1942
1943         LOGI("recommend resolution %dx%d, type %d", *width, *height, wide);
1944
1945         return CAMERA_ERROR_NONE;
1946 }
1947
1948 int camera_attr_get_lens_orientation(camera_h camera, int *angle){
1949         if( camera == NULL || angle == NULL ){
1950                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1951                 return CAMERA_ERROR_INVALID_PARAMETER;
1952         }
1953
1954         int ret;
1955         camera_s * handle = (camera_s*)camera;
1956         int rotation;
1957         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_RECOMMEND_DISPLAY_ROTATION, &rotation , NULL);
1958
1959         switch( rotation ){
1960                 case MM_DISPLAY_ROTATION_NONE:
1961                         *angle = 0;
1962                         break;
1963                 case MM_DISPLAY_ROTATION_90:
1964                         *angle = 270;
1965                         break;
1966                 case MM_DISPLAY_ROTATION_180:
1967                         *angle = 180;
1968                         break;
1969                 case MM_DISPLAY_ROTATION_270:
1970                         *angle = 90;
1971                         break;
1972                 default :
1973                         *angle = 0;
1974                         break;
1975         }
1976
1977         return __convert_camera_error_code(__func__, ret);
1978 }
1979
1980 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode){
1981         if( camera == NULL ){
1982                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1983                 return CAMERA_ERROR_INVALID_PARAMETER;
1984         }
1985
1986         int ret;
1987         camera_s * handle = (camera_s*)camera;
1988         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_MODE, mode, NULL);
1989
1990         return __convert_camera_error_code(__func__, ret);
1991 }
1992
1993 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode){
1994         if( camera == NULL || mode == NULL ){
1995                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
1996                 return CAMERA_ERROR_INVALID_PARAMETER;
1997         }
1998
1999         int ret;
2000         camera_s * handle = (camera_s*)camera;
2001         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_DISPLAY_MODE , mode, NULL);
2002
2003         return __convert_camera_error_code(__func__, ret);
2004 }
2005
2006 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data){
2007         if( camera == NULL || foreach_cb == NULL ){
2008                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2009                 return CAMERA_ERROR_INVALID_PARAMETER;
2010         }
2011
2012         int ret;
2013         camera_s * handle = (camera_s*)camera;
2014         MMCamAttrsInfo info;
2015         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_DISPLAY_MODE , &info);
2016
2017         if( ret != CAMERA_ERROR_NONE )
2018                 return __convert_camera_error_code(__func__, ret);
2019
2020         int i;
2021         for (i=0 ; i < info.int_array.count ; i++ ){
2022                 if ( !foreach_cb(info.int_array.array[i],user_data) )
2023                         break;
2024         }
2025
2026         return CAMERA_ERROR_NONE;
2027 }
2028
2029 int camera_attr_set_preview_fps(camera_h camera,  camera_attr_fps_e fps){
2030         if( camera == NULL ){
2031                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2032                 return CAMERA_ERROR_INVALID_PARAMETER;
2033         }
2034
2035         int ret;
2036         camera_s * handle = (camera_s*)camera;
2037
2038         if( fps == CAMERA_ATTR_FPS_AUTO ){
2039                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2040                                                   MMCAM_CAMERA_FPS_AUTO, 1,
2041                                                   NULL);
2042         } else {
2043                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2044                                                   MMCAM_CAMERA_FPS_AUTO, 0,
2045                                                   MMCAM_CAMERA_FPS, fps,
2046                                                   NULL);
2047         }
2048
2049         return __convert_camera_error_code(__func__, ret);
2050 }
2051
2052 int camera_attr_set_image_quality(camera_h camera,  int quality){
2053         if( camera == NULL ){
2054                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2055                 return CAMERA_ERROR_INVALID_PARAMETER;
2056         }
2057
2058         int ret;
2059         camera_s * handle = (camera_s*)camera;
2060         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_IMAGE_ENCODER_QUALITY , quality, NULL);
2061
2062         return __convert_camera_error_code(__func__, ret);
2063 }
2064
2065 int camera_attr_get_preview_fps(camera_h camera,  camera_attr_fps_e *fps){
2066         if( camera == NULL || fps == NULL ){
2067                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2068                 return CAMERA_ERROR_INVALID_PARAMETER;
2069         }
2070
2071         int ret;
2072         int mm_fps;
2073         int is_auto;
2074         camera_s * handle = (camera_s*)camera;
2075
2076         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_FPS , &mm_fps, MMCAM_CAMERA_FPS_AUTO , &is_auto, NULL);
2077
2078         if( is_auto )
2079                 *fps = CAMERA_ATTR_FPS_AUTO;
2080         else
2081                 *fps = mm_fps;
2082
2083         return __convert_camera_error_code(__func__, ret);
2084 }
2085
2086 int camera_attr_get_image_quality(camera_h camera,  int *quality){
2087         if( camera == NULL || quality == NULL ){
2088                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2089                 return CAMERA_ERROR_INVALID_PARAMETER;
2090         }
2091
2092         int ret;
2093         camera_s * handle = (camera_s*)camera;
2094         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_IMAGE_ENCODER_QUALITY   , quality, NULL);
2095
2096         return __convert_camera_error_code(__func__, ret);
2097 }
2098
2099 int camera_attr_set_zoom(camera_h camera,  int zoom){
2100         if( camera == NULL ){
2101                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2102                 return CAMERA_ERROR_INVALID_PARAMETER;
2103         }
2104
2105         int ret;
2106         camera_s * handle = (camera_s*)camera;
2107         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_DIGITAL_ZOOM  , zoom, NULL);
2108
2109         return __convert_camera_error_code(__func__, ret);
2110 }
2111
2112 int camera_attr_set_af_mode(camera_h camera,  camera_attr_af_mode_e mode){
2113         if( camera == NULL ){
2114                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2115                 return CAMERA_ERROR_INVALID_PARAMETER;
2116         }
2117
2118         int ret = CAMERA_ERROR_INVALID_PARAMETER;
2119         camera_s * handle = (camera_s*)camera;
2120
2121         int focus_mode;
2122         bool should_change_focus_mode = false;
2123         mm_camcorder_get_attributes(handle->mm_handle, NULL,
2124                                     MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2125                                     NULL);
2126
2127         if( focus_mode != MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO && focus_mode != MM_CAMCORDER_FOCUS_MODE_CONTINUOUS && focus_mode != MM_CAMCORDER_FOCUS_MODE_AUTO )
2128                 should_change_focus_mode = true;
2129
2130         if( mode != CAMERA_ATTR_AF_NONE && focus_mode == MM_CAMCORDER_FOCUS_MODE_CONTINUOUS && !handle->on_continuous_focusing ){
2131                 handle->cached_focus_mode = mode;
2132                 LOGD("af mode will be set actually start focusing");
2133                 return __convert_camera_error_code(__func__, 0);
2134         } else {
2135                 handle->cached_focus_mode = -1;
2136         }
2137
2138         if( mode != CAMERA_ATTR_AF_NONE && should_change_focus_mode ){
2139                 mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_AUTO, NULL);
2140         }
2141
2142         switch( mode ){
2143                 case CAMERA_ATTR_AF_NONE:
2144                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2145                                                           MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_NONE,
2146                                                           MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_NONE,
2147                                                           NULL);
2148                         break;
2149                 case CAMERA_ATTR_AF_NORMAL:
2150                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2151                                                           MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_NORMAL,
2152                                                           NULL);
2153                         break;
2154                 case CAMERA_ATTR_AF_MACRO:
2155                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2156                                                           MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_MACRO,
2157                                                           NULL);
2158                         break;
2159                 case CAMERA_ATTR_AF_FULL:
2160                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2161                                                           MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_FULL,
2162                                                           NULL);
2163                         break;
2164                 default:
2165                         return ret;
2166         }
2167
2168         return __convert_camera_error_code(__func__, ret);
2169 }
2170
2171 int camera_attr_set_af_area(camera_h camera, int x, int y){
2172         if( camera == NULL ){
2173                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2174                 return CAMERA_ERROR_INVALID_PARAMETER;
2175         }
2176
2177         int ret = CAMERA_ERROR_INVALID_PARAMETER;
2178         camera_s * handle = (camera_s*)camera;
2179         camera_attr_af_mode_e mode;
2180         camera_attr_get_af_mode(camera, &mode);
2181
2182         if( mode == CAMERA_ATTR_AF_NONE ){
2183                 LOGE("INVALID_OPERATION(0x%08x) AF mode is CAMERA_ATTR_AF_NONE",CAMERA_ERROR_INVALID_OPERATION);
2184                 return CAMERA_ERROR_INVALID_OPERATION;
2185         }
2186
2187         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2188                                           MMCAM_CAMERA_AF_TOUCH_X, x,
2189                                           MMCAM_CAMERA_AF_TOUCH_Y, y,
2190                                           NULL);
2191
2192         if( ret == MM_ERROR_NONE )
2193                 handle->focus_area_valid = true;
2194
2195         return __convert_camera_error_code(__func__, ret);
2196 }
2197
2198 int camera_attr_clear_af_area(camera_h camera){
2199         if( camera == NULL ){
2200                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2201                 return CAMERA_ERROR_INVALID_PARAMETER;
2202         }
2203
2204         camera_s * handle = (camera_s*)camera;
2205         handle->focus_area_valid = false;
2206
2207         return CAMERA_ERROR_NONE;
2208 }
2209
2210 int camera_attr_set_exposure_mode(camera_h camera,  camera_attr_exposure_mode_e mode){
2211         if( camera == NULL ){
2212                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2213                 return CAMERA_ERROR_INVALID_PARAMETER;
2214         }
2215
2216         int maptable[] = {MM_CAMCORDER_AUTO_EXPOSURE_OFF, //CAMCORDER_EXPOSURE_MODE_OFF
2217                                                                         MM_CAMCORDER_AUTO_EXPOSURE_ALL, //CAMCORDER_EXPOSURE_MODE_ALL
2218                                                                         MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1, //CAMCORDER_EXPOSURE_MODE_CENTER
2219                                                                         MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1, //CAMCORDER_EXPOSURE_MODE_SPOT
2220                                                                         MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1,//CAMCORDER_EXPOSURE_MODE_CUSTOM
2221                 };
2222
2223         int ret;
2224         camera_s * handle = (camera_s*)camera;
2225         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2226                                           MMCAM_CAMERA_EXPOSURE_MODE, maptable[abs(mode%5)],
2227                                           NULL);
2228
2229         return __convert_camera_error_code(__func__, ret);
2230 }
2231
2232 int camera_attr_set_exposure(camera_h camera, int value){
2233         if( camera == NULL ){
2234                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2235                 return CAMERA_ERROR_INVALID_PARAMETER;
2236         }
2237
2238         int ret;
2239         camera_s * handle = (camera_s*)camera;
2240         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2241                                           MMCAM_CAMERA_EXPOSURE_VALUE, value,
2242                                           NULL);
2243
2244         return __convert_camera_error_code(__func__, ret);
2245 }
2246
2247 int camera_attr_set_iso(camera_h camera,  camera_attr_iso_e iso){
2248         if( camera == NULL ){
2249                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2250                 return CAMERA_ERROR_INVALID_PARAMETER;
2251         }
2252
2253         int ret;
2254         camera_s * handle = (camera_s*)camera;
2255         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2256                                           MMCAM_CAMERA_ISO, iso,
2257                                           NULL);
2258
2259         return __convert_camera_error_code(__func__, ret);
2260 }
2261
2262 int camera_attr_set_brightness(camera_h camera, int level){
2263         if( camera == NULL ){
2264                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2265                 return CAMERA_ERROR_INVALID_PARAMETER;
2266         }
2267
2268         int ret;
2269         camera_s * handle = (camera_s*)camera;
2270         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2271                                           MMCAM_FILTER_BRIGHTNESS, level,
2272                                           NULL);
2273
2274         return __convert_camera_error_code(__func__, ret);
2275 }
2276
2277 int camera_attr_set_contrast(camera_h camera, int level){
2278         if( camera == NULL ){
2279                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2280                 return CAMERA_ERROR_INVALID_PARAMETER;
2281         }
2282
2283         int ret;
2284         camera_s * handle = (camera_s*)camera;
2285         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2286                                           MMCAM_FILTER_CONTRAST, level,
2287                                           NULL);
2288
2289         return __convert_camera_error_code(__func__, ret);
2290 }
2291
2292 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb){
2293         if( camera == NULL ){
2294                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2295                 return CAMERA_ERROR_INVALID_PARAMETER;
2296         }
2297
2298         int ret;
2299         camera_s * handle = (camera_s*)camera;
2300         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2301                                           MMCAM_FILTER_WB, wb,
2302                                           NULL);
2303
2304         return __convert_camera_error_code(__func__, ret);
2305 }
2306
2307 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect){
2308         if( camera == NULL ){
2309                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2310                 return CAMERA_ERROR_INVALID_PARAMETER;
2311         }
2312
2313         int ret;
2314         camera_s * handle = (camera_s*)camera;
2315         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2316                                           MMCAM_FILTER_COLOR_TONE, effect,
2317                                           NULL);
2318
2319         return __convert_camera_error_code(__func__, ret);
2320 }
2321
2322 int camera_attr_set_scene_mode(camera_h camera,  camera_attr_scene_mode_e mode){
2323         if( camera == NULL ){
2324                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2325                 return CAMERA_ERROR_INVALID_PARAMETER;
2326         }
2327
2328         int ret;
2329         camera_s * handle = (camera_s*)camera;
2330         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2331                                           MMCAM_FILTER_SCENE_MODE, mode,
2332                                           NULL);
2333
2334         return __convert_camera_error_code(__func__, ret);
2335 }
2336
2337 int camera_attr_enable_tag(camera_h camera,  bool enable){
2338         if( camera == NULL ){
2339                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2340                 return CAMERA_ERROR_INVALID_PARAMETER;
2341         }
2342
2343         int ret;
2344         camera_s * handle = (camera_s*)camera;
2345         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2346                                           MMCAM_TAG_ENABLE, enable,
2347                                           NULL);
2348
2349         return __convert_camera_error_code(__func__, ret);
2350 }
2351
2352 int camera_attr_set_tag_image_description(camera_h camera,  const char *description){
2353         if( camera == NULL ){
2354                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2355                 return CAMERA_ERROR_INVALID_PARAMETER;
2356         }
2357
2358         int ret;
2359         camera_s * handle = (camera_s*)camera;
2360         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2361                                           MMCAM_TAG_IMAGE_DESCRIPTION, description, strlen(description),
2362                                           NULL);
2363
2364         return __convert_camera_error_code(__func__, ret);
2365 }
2366
2367 int camera_attr_set_tag_orientation(camera_h camera,  camera_attr_tag_orientation_e orientation){
2368         if( camera == NULL ){
2369                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2370                 return CAMERA_ERROR_INVALID_PARAMETER;
2371         }
2372
2373         int ret;
2374         camera_s * handle = (camera_s*)camera;
2375         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2376                                           MMCAM_TAG_ORIENTATION, orientation,
2377                                           NULL);
2378
2379         return __convert_camera_error_code(__func__, ret);
2380 }
2381
2382 int camera_attr_set_tag_software(camera_h camera,  const char *software){
2383         if( camera == NULL ){
2384                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2385                 return CAMERA_ERROR_INVALID_PARAMETER;
2386         }
2387
2388         int ret;
2389         camera_s * handle = (camera_s*)camera;
2390         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2391                                           MMCAM_TAG_SOFTWARE, software, strlen(software),
2392                                           NULL);
2393
2394         return __convert_camera_error_code(__func__, ret);
2395 }
2396
2397 int camera_attr_set_geotag(camera_h camera, double latitude , double longitude, double altitude){
2398         if( camera == NULL ){
2399                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2400                 return CAMERA_ERROR_INVALID_PARAMETER;
2401         }
2402
2403         int ret;
2404         camera_s * handle = (camera_s*)camera;
2405         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2406                                           MMCAM_TAG_GPS_ENABLE, 1,
2407                                           MMCAM_TAG_LATITUDE, latitude,
2408                                           MMCAM_TAG_LONGITUDE, longitude,
2409                                           MMCAM_TAG_ALTITUDE, altitude,
2410                                           NULL);
2411
2412         return __convert_camera_error_code(__func__, ret);
2413 }
2414
2415 int camera_attr_remove_geotag(camera_h camera){
2416         if( camera == NULL ){
2417                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2418                 return CAMERA_ERROR_INVALID_PARAMETER;
2419         }
2420
2421         int ret;
2422         camera_s * handle = (camera_s*)camera;
2423         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2424                                           MMCAM_TAG_GPS_ENABLE, 0,
2425                                           NULL);
2426
2427         return __convert_camera_error_code(__func__, ret);
2428 }
2429
2430 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode){
2431         if( camera == NULL ){
2432                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2433                 return CAMERA_ERROR_INVALID_PARAMETER;
2434         }
2435
2436         int ret;
2437         camera_s * handle = (camera_s*)camera;
2438         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2439                                           MMCAM_STROBE_MODE, mode,
2440                                           NULL);
2441
2442         return __convert_camera_error_code(__func__, ret);
2443 }
2444
2445
2446 int camera_attr_get_zoom(camera_h camera, int *zoom){
2447         if( camera == NULL || zoom == NULL ){
2448                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2449                 return CAMERA_ERROR_INVALID_PARAMETER;
2450         }
2451
2452         int ret;
2453         camera_s * handle = (camera_s*)camera;
2454         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2455                                           MMCAM_CAMERA_DIGITAL_ZOOM, zoom,
2456                                           NULL);
2457
2458         return __convert_camera_error_code(__func__, ret);
2459 }
2460
2461 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max){
2462         if( camera == NULL || min == NULL || max == NULL ){
2463                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2464                 return CAMERA_ERROR_INVALID_PARAMETER;
2465         }
2466
2467         int ret;
2468         camera_s * handle = (camera_s*)camera;
2469         MMCamAttrsInfo ainfo;
2470         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_DIGITAL_ZOOM, &ainfo);
2471
2472         if( min )
2473                 *min = ainfo.int_range.min;
2474         if( max )
2475                 *max = ainfo.int_range.max;
2476
2477         return __convert_camera_error_code(__func__, ret);
2478 }
2479
2480 int camera_attr_get_af_mode( camera_h camera,  camera_attr_af_mode_e *mode){
2481         if( camera == NULL || mode == NULL ){
2482                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2483                 return CAMERA_ERROR_INVALID_PARAMETER;
2484         }
2485
2486         int ret;
2487         int focus_mode;
2488         int af_range;
2489         int detect_mode;
2490         camera_s * handle = (camera_s*)camera;
2491         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2492                                           MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2493                                           MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2494                                           MMCAM_DETECT_MODE, &detect_mode,
2495                                           NULL);
2496
2497         if( ret == CAMERA_ERROR_NONE ){
2498                 switch( focus_mode ){
2499                 case MM_CAMCORDER_FOCUS_MODE_NONE :
2500                 case MM_CAMCORDER_FOCUS_MODE_PAN :
2501                 case MM_CAMCORDER_FOCUS_MODE_MANUAL :
2502                         *mode = CAMERA_ATTR_AF_NONE;
2503                         break;
2504                 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2505                 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2506                 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2507                         switch ( af_range ){
2508                         case MM_CAMCORDER_AUTO_FOCUS_NONE :
2509                                 *mode = CAMERA_ATTR_AF_NORMAL;
2510                                 break;
2511                         case MM_CAMCORDER_AUTO_FOCUS_NORMAL:
2512                                 *mode = CAMERA_ATTR_AF_NORMAL;
2513                                 break;
2514                         case MM_CAMCORDER_AUTO_FOCUS_MACRO:
2515                                 *mode = CAMERA_ATTR_AF_MACRO;
2516                                 break;
2517                         case MM_CAMCORDER_AUTO_FOCUS_FULL:
2518                                 *mode = CAMERA_ATTR_AF_FULL;
2519                                 break;
2520                         default :
2521                                 *mode = CAMERA_ATTR_AF_NORMAL;
2522                                 break;
2523                         }
2524                         break;
2525                 default :
2526                         *mode = CAMERA_ATTR_AF_NONE;
2527                         break;
2528                 }
2529         }
2530
2531         return __convert_camera_error_code(__func__, ret);
2532 }
2533
2534 int camera_attr_get_exposure_mode( camera_h camera,  camera_attr_exposure_mode_e *mode){
2535         if( camera == NULL|| mode == NULL){
2536                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2537                 return CAMERA_ERROR_INVALID_PARAMETER;
2538         }
2539
2540         int maptable[] = {
2541                         CAMERA_ATTR_EXPOSURE_MODE_OFF,  //MM_CAMCORDER_AUTO_EXPOSURE_OFF
2542                         CAMERA_ATTR_EXPOSURE_MODE_ALL,  //MM_CAMCORDER_AUTO_EXPOSURE_ALL
2543                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1
2544                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_2
2545                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_3
2546                         CAMERA_ATTR_EXPOSURE_MODE_SPOT, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1
2547                         CAMERA_ATTR_EXPOSURE_MODE_SPOT, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2
2548                         CAMERA_ATTR_EXPOSURE_MODE_CUSTOM,//MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1
2549                         CAMERA_ATTR_EXPOSURE_MODE_CUSTOM //MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2
2550                 };
2551         int ret;
2552         int exposure_mode;
2553         camera_s * handle = (camera_s*)camera;
2554         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_EXPOSURE_MODE, &exposure_mode, NULL);
2555         if( ret == CAMERA_ERROR_NONE ){
2556                 *mode = maptable[abs(exposure_mode%9)];
2557         }
2558
2559         return __convert_camera_error_code(__func__, ret);
2560 }
2561
2562 int camera_attr_get_exposure(camera_h camera, int *value){
2563         if( camera == NULL || value == NULL ){
2564                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2565                 return CAMERA_ERROR_INVALID_PARAMETER;
2566         }
2567
2568         int ret;
2569         camera_s * handle = (camera_s*)camera;
2570         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_EXPOSURE_VALUE, value, NULL);
2571
2572         return __convert_camera_error_code(__func__, ret);
2573 }
2574
2575 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max){
2576         if( camera == NULL || min == NULL || max == NULL ){
2577                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2578                 return CAMERA_ERROR_INVALID_PARAMETER;
2579         }
2580
2581         int ret;
2582         camera_s * handle = (camera_s*)camera;
2583         MMCamAttrsInfo ainfo;
2584         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_VALUE, &ainfo);
2585
2586         if( min )
2587                 *min = ainfo.int_range.min;
2588         if( max )
2589                 *max = ainfo.int_range.max;
2590
2591         return __convert_camera_error_code(__func__, ret);
2592 }
2593
2594 int camera_attr_get_iso( camera_h camera,  camera_attr_iso_e *iso){
2595         if( camera == NULL || iso == NULL ){
2596                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2597                 return CAMERA_ERROR_INVALID_PARAMETER;
2598         }
2599
2600         int ret;
2601         camera_s * handle = (camera_s*)camera;
2602         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2603                                           MMCAM_CAMERA_ISO, iso,
2604                                           NULL);
2605
2606         return __convert_camera_error_code(__func__, ret);
2607 }
2608
2609 int camera_attr_get_brightness(camera_h camera,  int *level){
2610         if( camera == NULL || level == NULL ){
2611                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2612                 return CAMERA_ERROR_INVALID_PARAMETER;
2613         }
2614
2615         int ret;
2616         camera_s * handle = (camera_s*)camera;
2617         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2618                                           MMCAM_FILTER_BRIGHTNESS, level,
2619                                           NULL);
2620
2621         return __convert_camera_error_code(__func__, ret);
2622 }
2623
2624 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max){
2625         if( camera == NULL || min == NULL || max == NULL ){
2626                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2627                 return CAMERA_ERROR_INVALID_PARAMETER;
2628         }
2629
2630         int ret;
2631         camera_s * handle = (camera_s*)camera;
2632         MMCamAttrsInfo ainfo;
2633         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_BRIGHTNESS, &ainfo);
2634
2635         if( min )
2636                 *min = ainfo.int_range.min;
2637         if( max )
2638                 *max = ainfo.int_range.max;
2639
2640         return __convert_camera_error_code(__func__, ret);
2641 }
2642
2643 int camera_attr_get_contrast(camera_h camera,  int *level){
2644         if( camera == NULL || level == NULL ){
2645                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2646                 return CAMERA_ERROR_INVALID_PARAMETER;
2647         }
2648
2649         int ret;
2650         camera_s * handle = (camera_s*)camera;
2651         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2652                                           MMCAM_FILTER_CONTRAST, level,
2653                                           NULL);
2654
2655         return __convert_camera_error_code(__func__, ret);
2656 }
2657
2658 int camera_attr_get_contrast_range(camera_h camera, int *min , int *max){
2659         if( camera == NULL || min == NULL || max == NULL ){
2660                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2661                 return CAMERA_ERROR_INVALID_PARAMETER;
2662         }
2663
2664         int ret;
2665         camera_s * handle = (camera_s*)camera;
2666         MMCamAttrsInfo ainfo;
2667         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_CONTRAST, &ainfo);
2668
2669         if( min )
2670                 *min = ainfo.int_range.min;
2671         if( max )
2672                 *max = ainfo.int_range.max;
2673
2674         return __convert_camera_error_code(__func__, ret);
2675 }
2676
2677 int camera_attr_get_whitebalance(camera_h camera,  camera_attr_whitebalance_e *wb){
2678         if( camera == NULL || wb == NULL ){
2679                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2680                 return CAMERA_ERROR_INVALID_PARAMETER;
2681         }
2682
2683         int ret;
2684         camera_s * handle = (camera_s*)camera;
2685         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2686                                           MMCAM_FILTER_WB, wb,
2687                                           NULL);
2688
2689         return __convert_camera_error_code(__func__, ret);
2690 }
2691
2692 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect){
2693         if( camera == NULL || effect == NULL ){
2694                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2695                 return CAMERA_ERROR_INVALID_PARAMETER;
2696         }
2697
2698         int ret;
2699         camera_s * handle = (camera_s*)camera;
2700         int tone;
2701         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2702                                           MMCAM_FILTER_COLOR_TONE, &tone,
2703                                           NULL);
2704
2705         if( ret != CAMERA_ERROR_NONE )
2706                 return __convert_camera_error_code(__func__, ret);
2707
2708         *effect = (camera_attr_effect_mode_e)tone;
2709
2710         return __convert_camera_error_code(__func__, ret);
2711 }
2712
2713 int camera_attr_get_scene_mode(camera_h camera,  camera_attr_scene_mode_e *mode){
2714         if( camera == NULL || mode == NULL ){
2715                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2716                 return CAMERA_ERROR_INVALID_PARAMETER;
2717         }
2718
2719         int ret;
2720         camera_s * handle = (camera_s*)camera;
2721         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2722                                           MMCAM_FILTER_SCENE_MODE, mode,
2723                                           NULL);
2724
2725         return __convert_camera_error_code(__func__, ret);
2726 }
2727
2728 int camera_attr_is_enabled_tag(camera_h camera,  bool *enable){
2729         if( camera == NULL || enable == NULL ){
2730                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2731                 return CAMERA_ERROR_INVALID_PARAMETER;
2732         }
2733
2734         int ret;
2735         camera_s * handle = (camera_s*)camera;
2736
2737         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2738                                           MMCAM_TAG_ENABLE, enable,
2739                                           NULL);
2740
2741         return __convert_camera_error_code(__func__, ret);
2742 }
2743
2744 int camera_attr_get_tag_image_description(camera_h camera,  char **description){
2745         if( camera == NULL || description == NULL ){
2746                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2747                 return CAMERA_ERROR_INVALID_PARAMETER;
2748         }
2749
2750         int ret;
2751         camera_s * handle = (camera_s*)camera;
2752         char *ndescription = NULL;
2753         int desc_size;
2754         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_IMAGE_DESCRIPTION, &ndescription, &desc_size, NULL);
2755
2756         if( ret == CAMERA_ERROR_NONE ){
2757                 if( ndescription != NULL )
2758                         *description = strdup(ndescription);
2759                 else
2760                         *description = strdup("");
2761         }
2762
2763         return __convert_camera_error_code(__func__, ret);
2764 }
2765
2766 int camera_attr_get_tag_orientation(camera_h camera,  camera_attr_tag_orientation_e *orientation){
2767         if( camera == NULL || orientation == NULL ){
2768                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2769                 return CAMERA_ERROR_INVALID_PARAMETER;
2770         }
2771
2772         int ret;
2773         camera_s * handle = (camera_s*)camera;
2774         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2775                                           MMCAM_TAG_ORIENTATION, orientation,
2776                                           NULL);
2777
2778         return __convert_camera_error_code(__func__, ret);
2779 }
2780
2781 int camera_attr_get_tag_software(camera_h camera,  char **software){
2782         if( camera == NULL || software == NULL ){
2783                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2784                 return CAMERA_ERROR_INVALID_PARAMETER;
2785         }
2786
2787         int ret;
2788         camera_s * handle = (camera_s*)camera;
2789         char *soft;
2790         int soft_size;
2791
2792         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_SOFTWARE, &soft, &soft_size, NULL);
2793
2794         if( ret == CAMERA_ERROR_NONE ){
2795                 if( soft != NULL )
2796                         *software = strdup(soft);
2797                 else
2798                         *software = strdup("");
2799         }
2800
2801         return __convert_camera_error_code(__func__, ret);
2802 }
2803
2804 int camera_attr_get_geotag(camera_h camera, double *latitude , double *longitude, double *altitude){
2805         if( camera == NULL || latitude == NULL || longitude == NULL || altitude == NULL ){
2806                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2807                 return CAMERA_ERROR_INVALID_PARAMETER;
2808         }
2809
2810         int ret;
2811         camera_s * handle = (camera_s*)camera;
2812         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2813                                           MMCAM_TAG_LATITUDE, latitude,
2814                                           MMCAM_TAG_LONGITUDE, longitude,
2815                                           MMCAM_TAG_ALTITUDE, altitude,
2816                                           NULL);
2817
2818         return __convert_camera_error_code(__func__, ret);
2819 }
2820
2821 int camera_attr_get_flash_mode(camera_h camera,  camera_attr_flash_mode_e *mode){
2822         if( camera == NULL || mode == NULL ){
2823                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2824                 return CAMERA_ERROR_INVALID_PARAMETER;
2825         }
2826
2827         int ret;
2828         camera_s * handle = (camera_s*)camera;
2829         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2830                                           MMCAM_STROBE_MODE, mode,
2831                                           NULL);
2832
2833         return __convert_camera_error_code(__func__, ret);
2834 }
2835
2836 int camera_attr_foreach_supported_af_mode( camera_h camera, camera_attr_supported_af_mode_cb foreach_cb , void *user_data){
2837         if( camera == NULL || foreach_cb == NULL ){
2838                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2839                 return CAMERA_ERROR_INVALID_PARAMETER;
2840         }
2841
2842         int ret;
2843         int i;
2844         camera_s * handle = (camera_s*)camera;
2845         MMCamAttrsInfo af_range;
2846         MMCamAttrsInfo focus_mode;
2847
2848         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_AF_SCAN_RANGE, &af_range);
2849         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FOCUS_MODE, &focus_mode);
2850
2851         if( ret != CAMERA_ERROR_NONE )
2852                 return __convert_camera_error_code(__func__, ret);
2853
2854         for( i=0 ; i < af_range.int_array.count ; i++ ) {
2855                 if( !foreach_cb(af_range.int_array.array[i],user_data) )
2856                         goto ENDCALLBACK;
2857         }
2858
2859         ENDCALLBACK:
2860
2861         return CAMERA_ERROR_NONE;
2862 }
2863
2864 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb , void *user_data){
2865         if( camera == NULL || foreach_cb == NULL ){
2866                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2867                 return CAMERA_ERROR_INVALID_PARAMETER;
2868         }
2869
2870         int maptable[] = {
2871                         CAMERA_ATTR_EXPOSURE_MODE_OFF,  //MM_CAMCORDER_AUTO_EXPOSURE_OFF
2872                         CAMERA_ATTR_EXPOSURE_MODE_ALL,  //MM_CAMCORDER_AUTO_EXPOSURE_ALL
2873                         CAMERA_ATTR_EXPOSURE_MODE_CENTER, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1
2874                         -1, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_2
2875                         -1, //MM_CAMCORDER_AUTO_EXPOSURE_CENTER_3
2876                         CAMERA_ATTR_EXPOSURE_MODE_SPOT, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1
2877                         -1, //MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2
2878                         CAMERA_ATTR_EXPOSURE_MODE_CUSTOM,//MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1
2879                         -1//MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2
2880                 };
2881         int ret;
2882         camera_s * handle = (camera_s*)camera;
2883         MMCamAttrsInfo info;
2884         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_MODE , &info);
2885
2886         if( ret != CAMERA_ERROR_NONE )
2887                 return __convert_camera_error_code(__func__, ret);
2888
2889         int i;
2890         for( i=0 ; i < info.int_array.count ; i++ ){
2891                 if( maptable[info.int_array.array[i]] != -1 ){
2892                         if ( !foreach_cb(maptable[info.int_array.array[i]],user_data) )
2893                                 break;
2894                 }
2895         }
2896
2897         return CAMERA_ERROR_NONE;
2898 }
2899
2900 int camera_attr_foreach_supported_iso( camera_h camera, camera_attr_supported_iso_cb foreach_cb , void *user_data){
2901         if( camera == NULL || foreach_cb == NULL ){
2902                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2903                 return CAMERA_ERROR_INVALID_PARAMETER;
2904         }
2905
2906         int ret;
2907         camera_s * handle = (camera_s*)camera;
2908         MMCamAttrsInfo info;
2909         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ISO , &info);
2910
2911         if( ret != CAMERA_ERROR_NONE )
2912                 return __convert_camera_error_code(__func__, ret);
2913
2914         int i;
2915         for( i=0 ; i < info.int_array.count ; i++ ){
2916                 if( !foreach_cb(info.int_array.array[i],user_data) )
2917                         break;
2918         }
2919
2920         return CAMERA_ERROR_NONE;
2921 }
2922
2923 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb , void *user_data){
2924         if( camera == NULL || foreach_cb == NULL ){
2925                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2926                 return CAMERA_ERROR_INVALID_PARAMETER;
2927         }
2928
2929         int ret;
2930         camera_s * handle = (camera_s*)camera;
2931         MMCamAttrsInfo info;
2932         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_WB, &info);
2933
2934         if( ret != CAMERA_ERROR_NONE )
2935                 return __convert_camera_error_code(__func__, ret);
2936
2937         int i;
2938         for( i=0 ; i < info.int_array.count ; i++ ){
2939                 if ( !foreach_cb(info.int_array.array[i],user_data)  )
2940                         break;
2941         }
2942
2943         return CAMERA_ERROR_NONE;
2944 }
2945
2946 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb , void *user_data){
2947         if( camera == NULL || foreach_cb == NULL ){
2948                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2949                 return CAMERA_ERROR_INVALID_PARAMETER;
2950         }
2951
2952         int ret;
2953         camera_s * handle = (camera_s*)camera;
2954         MMCamAttrsInfo info;
2955         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_COLOR_TONE , &info);
2956
2957         if( ret != CAMERA_ERROR_NONE )
2958                 return __convert_camera_error_code(__func__, ret);
2959
2960         int i;
2961         for( i=0 ; i < info.int_array.count ; i++){
2962                 int effect = info.int_array.array[i];
2963                 if( !foreach_cb(effect,user_data) )
2964                                 break;
2965         }
2966
2967         return CAMERA_ERROR_NONE;
2968 }
2969
2970 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb , void *user_data){
2971         if( camera == NULL || foreach_cb == NULL ){
2972                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2973                 return CAMERA_ERROR_INVALID_PARAMETER;
2974         }
2975
2976         int ret;
2977         camera_s * handle = (camera_s*)camera;
2978         MMCamAttrsInfo info;
2979         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_SCENE_MODE  , &info);
2980
2981         if( ret != CAMERA_ERROR_NONE )
2982                 return __convert_camera_error_code(__func__, ret);
2983
2984         int i;
2985         for( i=0 ; i < info.int_array.count ; i++){
2986                 if ( !foreach_cb(info.int_array.array[i],user_data) )
2987                         break;
2988         }
2989
2990         return CAMERA_ERROR_NONE;
2991 }
2992
2993 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb , void *user_data){
2994         if( camera == NULL || foreach_cb == NULL){
2995                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
2996                 return CAMERA_ERROR_INVALID_PARAMETER;
2997         }
2998
2999         int ret;
3000         camera_s * handle = (camera_s*)camera;
3001         MMCamAttrsInfo info;
3002         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_STROBE_MODE  , &info);
3003
3004         if( ret != CAMERA_ERROR_NONE )
3005                 return __convert_camera_error_code(__func__, ret);
3006
3007         int i;
3008         for( i=0 ; i < info.int_array.count ; i++){
3009                 if( !foreach_cb(info.int_array.array[i],user_data) )
3010                         break;
3011         }
3012
3013         return CAMERA_ERROR_NONE;
3014 }
3015
3016 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb , void *user_data){
3017         if( camera == NULL || foreach_cb == NULL ){
3018                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3019                 return CAMERA_ERROR_INVALID_PARAMETER;
3020         }
3021
3022         int ret;
3023         camera_s * handle = (camera_s*)camera;
3024         MMCamAttrsInfo info;
3025         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FPS , &info);
3026
3027         if( ret != CAMERA_ERROR_NONE )
3028                 return __convert_camera_error_code(__func__, ret);
3029
3030         int i;
3031         for( i=0 ; i < info.int_array.count ; i++){
3032                 if( !foreach_cb(info.int_array.array[i],user_data) )
3033                         break;
3034         }
3035
3036         return CAMERA_ERROR_NONE;
3037 }
3038
3039 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data){
3040         if( camera == NULL || foreach_cb == NULL ){
3041                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3042                 return CAMERA_ERROR_INVALID_PARAMETER;
3043         }
3044
3045         int ret;
3046         camera_s * handle = (camera_s*)camera;
3047         MMCamAttrsInfo info;
3048         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FLIP , &info);
3049
3050         if( ret != CAMERA_ERROR_NONE )
3051                 return __convert_camera_error_code(__func__, ret);
3052
3053         int i;
3054         for( i=0 ; i < info.int_array.count ; i++){
3055                 if( !foreach_cb(info.int_array.array[i], user_data) )
3056                         break;
3057         }
3058
3059         return CAMERA_ERROR_NONE;
3060 }
3061
3062 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data){
3063         if( camera == NULL || foreach_cb == NULL ){
3064                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3065                 return CAMERA_ERROR_INVALID_PARAMETER;
3066         }
3067
3068         int ret;
3069         camera_s * handle = (camera_s*)camera;
3070         MMCamAttrsInfo info;
3071         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ROTATION , &info);
3072
3073         if( ret != CAMERA_ERROR_NONE )
3074                 return __convert_camera_error_code(__func__, ret);
3075
3076         int i;
3077         for( i=0 ; i < info.int_array.count ; i++ ){
3078                 if( !foreach_cb(info.int_array.array[i], user_data) )
3079                         break;
3080         }
3081
3082         return CAMERA_ERROR_NONE;
3083 }
3084
3085 int camera_attr_set_stream_rotation(camera_h camera , camera_rotation_e rotation){
3086         if( camera == NULL){
3087                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3088                 return CAMERA_ERROR_INVALID_PARAMETER;
3089         }
3090
3091         if( rotation > CAMERA_ROTATION_270 )
3092                 return CAMERA_ERROR_INVALID_PARAMETER;
3093
3094         int ret;
3095         camera_s * handle = (camera_s*)camera;
3096
3097         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ROTATION, rotation, NULL);
3098
3099         return __convert_camera_error_code(__func__, ret);
3100 }
3101
3102 int camera_attr_get_stream_rotation(camera_h camera , camera_rotation_e *rotation){
3103         if( camera == NULL || rotation == NULL ){
3104                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3105                 return CAMERA_ERROR_INVALID_PARAMETER;
3106         }
3107
3108         int ret;
3109         camera_s * handle = (camera_s*)camera;
3110
3111         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ROTATION, rotation, NULL);
3112
3113         return __convert_camera_error_code(__func__, ret);
3114 }
3115
3116 int camera_attr_set_stream_flip(camera_h camera , camera_flip_e flip){
3117         if( camera == NULL ){
3118                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3119                 return CAMERA_ERROR_INVALID_PARAMETER;
3120         }
3121
3122         if( flip > CAMERA_FLIP_BOTH )
3123                 return CAMERA_ERROR_INVALID_PARAMETER;
3124
3125         int ret;
3126         camera_s * handle = (camera_s*)camera;
3127         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
3128                                           MMCAM_CAMERA_FLIP, flip,
3129                                           NULL);
3130
3131         return __convert_camera_error_code(__func__, ret);
3132 }
3133
3134 int camera_attr_get_stream_flip(camera_h camera , camera_flip_e *flip){
3135         if( camera == NULL || flip == NULL ){
3136                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3137                 return CAMERA_ERROR_INVALID_PARAMETER;
3138         }
3139         int ret;
3140         camera_s * handle = (camera_s*)camera;
3141         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FLIP, flip, NULL);
3142
3143         return __convert_camera_error_code(__func__, ret);
3144 }
3145
3146 int _camera_set_use(camera_h camera, bool used){
3147         camera_s * handle = (camera_s*)camera;
3148         handle->is_used_in_recorder = used;
3149         return CAMERA_ERROR_NONE;
3150 }
3151
3152 bool _camera_is_used(camera_h camera){
3153         camera_s * handle = (camera_s*)camera;
3154         return handle->is_used_in_recorder;
3155 }
3156
3157 int _camera_get_mm_handle(camera_h camera , MMHandleType *handle){
3158         if( camera == NULL || handle == NULL ){
3159                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3160                 return CAMERA_ERROR_INVALID_PARAMETER;
3161         }
3162         camera_s *camera_handle = (camera_s*)camera;
3163         *handle =  camera_handle->mm_handle;
3164
3165         return CAMERA_ERROR_NONE;
3166 }
3167
3168 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data){
3169         if( camera == NULL ){
3170                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3171                 return CAMERA_ERROR_INVALID_PARAMETER;
3172         }
3173
3174         camera_s *handle = (camera_s*)camera;
3175         handle->relay_message_callback = callback;
3176         handle->relay_user_data = user_data;
3177
3178         return CAMERA_ERROR_NONE;
3179 }
3180
3181 int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format){
3182         if( in_format <= MM_PIXEL_FORMAT_INVALID ||
3183             in_format >= MM_PIXEL_FORMAT_NUM ||
3184             out_format == NULL ){
3185                 LOGE("INVALID_PARAMETER : in_format %d, out_format ptr %p", in_format, out_format);
3186                 return CAMERA_ERROR_INVALID_PARAMETER;
3187         }
3188
3189         switch( in_format ){
3190         case MM_PIXEL_FORMAT_NV12:
3191         case MM_PIXEL_FORMAT_NV12T:
3192                 *out_format = TBM_FORMAT_NV12;
3193                 break;
3194         case MM_PIXEL_FORMAT_NV16:
3195                 *out_format = TBM_FORMAT_NV16;
3196                 break;
3197         case MM_PIXEL_FORMAT_NV21:
3198                 *out_format = TBM_FORMAT_NV21;
3199                 break;
3200         case MM_PIXEL_FORMAT_YUYV:
3201                 *out_format = TBM_FORMAT_YUYV;
3202                 break;
3203         case MM_PIXEL_FORMAT_UYVY:
3204         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
3205                 *out_format = TBM_FORMAT_UYVY;
3206                 break;
3207         case MM_PIXEL_FORMAT_422P:
3208                 *out_format = TBM_FORMAT_YUV422;
3209                 break;
3210         case MM_PIXEL_FORMAT_I420:
3211                 *out_format = TBM_FORMAT_YUV420;
3212                 break;
3213         case MM_PIXEL_FORMAT_YV12:
3214                 *out_format = TBM_FORMAT_YVU420;
3215                 break;
3216         case MM_PIXEL_FORMAT_RGB565:
3217                 *out_format = TBM_FORMAT_RGB565;
3218                 break;
3219         case MM_PIXEL_FORMAT_RGB888:
3220                 *out_format = TBM_FORMAT_RGB888;
3221                 break;
3222         case MM_PIXEL_FORMAT_RGBA:
3223                 *out_format = TBM_FORMAT_RGBA8888;
3224                 break;
3225         case MM_PIXEL_FORMAT_ARGB:
3226                 *out_format = TBM_FORMAT_ARGB8888;
3227                 break;
3228         default:
3229                 LOGE("invalid in_format %d", in_format);
3230                 return CAMERA_ERROR_INVALID_PARAMETER;
3231         }
3232
3233         return CAMERA_ERROR_NONE;
3234 }
3235
3236 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype){
3237         if( in_format <= MM_PIXEL_FORMAT_INVALID ||
3238             in_format >= MM_PIXEL_FORMAT_NUM ||
3239             mimetype == NULL ){
3240                 LOGE("INVALID_PARAMETER : in_format %d, mimetype ptr %p", in_format, mimetype);
3241                 return CAMERA_ERROR_INVALID_PARAMETER;
3242         }
3243
3244         switch (in_format) {
3245         case MM_PIXEL_FORMAT_NV12:
3246         case MM_PIXEL_FORMAT_NV12T:
3247                 *mimetype = MEDIA_FORMAT_NV12;
3248                 break;
3249         case MM_PIXEL_FORMAT_NV16:
3250                 *mimetype = MEDIA_FORMAT_NV16;
3251                 break;
3252         case MM_PIXEL_FORMAT_NV21:
3253                 *mimetype = MEDIA_FORMAT_NV21;
3254                 break;
3255         case MM_PIXEL_FORMAT_YUYV:
3256                 *mimetype = MEDIA_FORMAT_YUYV;
3257                 break;
3258         case MM_PIXEL_FORMAT_UYVY:
3259         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
3260                 *mimetype = MEDIA_FORMAT_UYVY;
3261                 break;
3262         case MM_PIXEL_FORMAT_422P:
3263                 *mimetype = MEDIA_FORMAT_422P;
3264                 break;
3265         case MM_PIXEL_FORMAT_I420:
3266                 *mimetype = MEDIA_FORMAT_I420;
3267                 break;
3268         case MM_PIXEL_FORMAT_YV12:
3269                 *mimetype = MEDIA_FORMAT_YV12;
3270                 break;
3271         case MM_PIXEL_FORMAT_RGB565:
3272                 *mimetype = MEDIA_FORMAT_RGB565;
3273                 break;
3274         case MM_PIXEL_FORMAT_RGB888:
3275                 *mimetype = MEDIA_FORMAT_RGB888;
3276                 break;
3277         case MM_PIXEL_FORMAT_RGBA:
3278                 *mimetype = MEDIA_FORMAT_RGBA;
3279                 break;
3280         case MM_PIXEL_FORMAT_ARGB:
3281                 *mimetype = MEDIA_FORMAT_ARGB;
3282                 break;
3283         default:
3284                 LOGE("invalid in_format %d", in_format);
3285                 return CAMERA_ERROR_INVALID_PARAMETER;
3286         }
3287
3288         return CAMERA_ERROR_NONE;
3289 }
3290
3291 int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data){
3292         int ret = 0;
3293         void *internal_buffer = NULL;
3294         tbm_surface_h tsurf = NULL;
3295
3296         if( pkt == NULL || user_data == NULL ){
3297                 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
3298                 return MEDIA_PACKET_FINALIZE;
3299         }
3300
3301         ret = media_packet_get_extra(pkt, &internal_buffer);
3302
3303         if( ret != MEDIA_PACKET_ERROR_NONE ){
3304                 LOGE("media_packet_get_extra failed 0x%x", ret);
3305                 return MEDIA_PACKET_FINALIZE;
3306         }
3307
3308         /*LOGD("pointer gst buffer %p, ret 0x%x", internal_buffer, ret);*/
3309
3310         if( internal_buffer ){
3311                 gst_buffer_unref((GstBuffer *)internal_buffer);
3312                 internal_buffer = NULL;
3313         }
3314
3315         ret = media_packet_get_tbm_surface(pkt, &tsurf);
3316         if( ret != MEDIA_PACKET_ERROR_NONE ){
3317                 LOGE("media_packet_get_tbm_surface failed 0x%x", ret);
3318                 return MEDIA_PACKET_FINALIZE;
3319         }
3320
3321         if( tsurf ){
3322                 tbm_surface_destroy(tsurf);
3323                 tsurf = NULL;
3324         }
3325
3326         return MEDIA_PACKET_FINALIZE;
3327 }
3328
3329 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode){
3330         if( camera == NULL ){
3331                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3332                 return CAMERA_ERROR_INVALID_PARAMETER;
3333         }
3334
3335         if( camera_attr_is_supported_hdr_capture(camera) == false ){
3336                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3337                 return CAMERA_ERROR_NOT_SUPPORTED;
3338         }
3339
3340         int ret;
3341         camera_s * handle = (camera_s*)camera;
3342         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_HDR_CAPTURE, mode, NULL);
3343
3344         if( ret == MM_ERROR_NONE ){
3345                 if( mode == CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL )
3346                         handle->hdr_keep_mode = true;
3347                 else
3348                         handle->hdr_keep_mode = false;
3349         }
3350
3351         return __convert_camera_error_code(__func__, ret);
3352 }
3353
3354 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode){
3355         if( camera == NULL ){
3356                 LOGE("INVALID_PARAMETER(0x%08x) - handle",CAMERA_ERROR_INVALID_PARAMETER);
3357                 return CAMERA_ERROR_INVALID_PARAMETER;
3358         }
3359
3360         if(  camera_attr_is_supported_hdr_capture(camera) == false ){
3361                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3362                 return CAMERA_ERROR_NOT_SUPPORTED;
3363         }
3364
3365         if( mode == NULL ){
3366                 LOGE("INVALID_PARAMETER(0x%08x) - mode",CAMERA_ERROR_INVALID_PARAMETER);
3367                 return CAMERA_ERROR_INVALID_PARAMETER;
3368         }
3369
3370         int ret;
3371         int result;
3372         camera_s * handle = (camera_s*)camera;
3373         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_HDR_CAPTURE, &result, NULL);
3374
3375         if( ret == MM_ERROR_NONE ){
3376                 *mode = result;
3377         }
3378
3379         return __convert_camera_error_code(__func__, ret);
3380 }
3381
3382 bool camera_attr_is_supported_hdr_capture(camera_h camera){
3383         if( camera == NULL  ){
3384                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3385                 return false;
3386         }
3387         int ret;
3388         int i;
3389         camera_s * handle = (camera_s*)camera;
3390         MMCamAttrsInfo hdr_info;
3391
3392         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HDR_CAPTURE, &hdr_info);
3393         set_last_result(__convert_camera_error_code(__func__, ret));
3394         if( ret != MM_ERROR_NONE ){
3395                 LOGE("MMCAM_CAMERA_HDR_CAPTURE get attr info failed");
3396                 return false;
3397         }
3398
3399         for( i = 0; i < hdr_info.int_array.count ; i++ ){
3400                 if( hdr_info.int_array.array[i] >= MM_CAMCORDER_HDR_ON  ){
3401                         LOGD("HDR capture supported");
3402                         return true;
3403                 }
3404         }
3405
3406         LOGD("HDR capture NOT supported");
3407
3408         return false;
3409 }
3410
3411 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void* user_data){
3412         if( camera == NULL ){
3413                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
3414                 return CAMERA_ERROR_INVALID_PARAMETER;
3415         }
3416
3417         if( camera_attr_is_supported_hdr_capture(camera) == false ){
3418                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3419                 return CAMERA_ERROR_NOT_SUPPORTED;
3420         }
3421
3422         if( callback == NULL ){
3423                 LOGE("INVALID_PARAMETER(0x%08x) - callback", CAMERA_ERROR_INVALID_PARAMETER);
3424                 return CAMERA_ERROR_INVALID_PARAMETER;
3425         }
3426
3427         camera_s * handle = (camera_s*)camera;
3428         handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)callback;
3429         handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)user_data;
3430         return CAMERA_ERROR_NONE;
3431 }
3432
3433 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera){
3434         if( camera == NULL ){
3435                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3436                 return CAMERA_ERROR_INVALID_PARAMETER;
3437         }
3438
3439         if( camera_attr_is_supported_hdr_capture(camera) == false ){
3440                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3441                 return CAMERA_ERROR_NOT_SUPPORTED;
3442         }
3443
3444         camera_s * handle = (camera_s*)camera;
3445         handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)NULL;
3446         handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void*)NULL;
3447
3448         return CAMERA_ERROR_NONE;
3449 }
3450
3451 int camera_attr_enable_anti_shake(camera_h camera, bool enable){
3452         if( camera == NULL ){
3453                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3454                 return CAMERA_ERROR_INVALID_PARAMETER;
3455         }
3456
3457         if( camera_attr_is_supported_anti_shake(camera) == false ){
3458                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3459                 return CAMERA_ERROR_NOT_SUPPORTED;
3460         }
3461
3462         int ret;
3463         int mode = MM_CAMCORDER_AHS_OFF;
3464
3465         if( enable )
3466                 mode = MM_CAMCORDER_AHS_ON;
3467
3468         camera_s * handle = (camera_s*)camera;
3469         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ANTI_HANDSHAKE, mode, NULL);
3470
3471         return __convert_camera_error_code(__func__, ret);
3472 }
3473
3474 int camera_attr_is_enabled_anti_shake(camera_h camera , bool *enabled){
3475         if( camera == NULL ){
3476                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
3477                 return CAMERA_ERROR_INVALID_PARAMETER;
3478         }
3479
3480         if( camera_attr_is_supported_anti_shake(camera) == false ){
3481                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3482                 return CAMERA_ERROR_NOT_SUPPORTED;
3483         }
3484
3485         if( enabled == NULL ){
3486                 LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER);
3487                 return CAMERA_ERROR_INVALID_PARAMETER;
3488         }
3489
3490         int ret;
3491         int mode = MM_CAMCORDER_AHS_OFF;
3492         camera_s * handle = (camera_s*)camera;
3493         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ANTI_HANDSHAKE, &mode, NULL);
3494
3495         if( ret == MM_ERROR_NONE )
3496                 *enabled = mode;
3497
3498         return __convert_camera_error_code(__func__, ret);
3499 }
3500
3501 bool camera_attr_is_supported_anti_shake(camera_h camera){
3502         if( camera == NULL ){
3503                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3504                 return false;
3505         }
3506
3507         int i;
3508         camera_s * handle = (camera_s*)camera;
3509         MMCamAttrsInfo ash_info;
3510         int ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ANTI_HANDSHAKE , &ash_info);
3511         set_last_result(__convert_camera_error_code(__func__, ret));
3512
3513         for( i=0 ; i < ash_info.int_array.count ; i++ ){
3514                 if( ash_info.int_array.array[i] == MM_CAMCORDER_AHS_ON )
3515                         return true;
3516         }
3517
3518         return false;
3519 }
3520
3521 int camera_attr_enable_video_stabilization(camera_h camera, bool enable){
3522         if( camera == NULL ){
3523                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3524                 return CAMERA_ERROR_INVALID_PARAMETER;
3525         }
3526
3527         if( camera_attr_is_supported_video_stabilization(camera) == false ){
3528                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3529                 return CAMERA_ERROR_NOT_SUPPORTED;
3530         }
3531
3532         int ret;
3533         int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF;
3534
3535         if( enable )
3536                 mode = MM_CAMCORDER_VIDEO_STABILIZATION_ON;
3537
3538         camera_s * handle = (camera_s*)camera;
3539         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_VIDEO_STABILIZATION, mode, NULL);
3540
3541         return __convert_camera_error_code(__func__, ret);
3542 }
3543
3544 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled){
3545         if( camera == NULL ){
3546                 LOGE("INVALID_PARAMETER(0x%08x) - handle",CAMERA_ERROR_INVALID_PARAMETER);
3547                 return CAMERA_ERROR_INVALID_PARAMETER;
3548         }
3549
3550         if( camera_attr_is_supported_video_stabilization(camera) == false ){
3551                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3552                 return CAMERA_ERROR_NOT_SUPPORTED;
3553         }
3554
3555         if( enabled == NULL ){
3556                 LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER);
3557                 return CAMERA_ERROR_INVALID_PARAMETER;
3558         }
3559
3560         int ret;
3561         int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF;
3562         camera_s * handle = (camera_s*)camera;
3563         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_VIDEO_STABILIZATION, &mode, NULL);
3564
3565         if( ret == MM_ERROR_NONE )
3566                 *enabled = (mode == MM_CAMCORDER_VIDEO_STABILIZATION_ON);
3567
3568         return __convert_camera_error_code(__func__, ret);
3569 }
3570
3571 bool camera_attr_is_supported_video_stabilization(camera_h camera){
3572         if( camera == NULL ){
3573                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3574                 return false;
3575         }
3576
3577         int i;
3578         camera_s * handle = (camera_s*)camera;
3579         MMCamAttrsInfo vs_info;
3580         int ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_VIDEO_STABILIZATION , &vs_info);
3581         set_last_result(__convert_camera_error_code(__func__, ret));
3582
3583         for( i=0 ; i < vs_info.int_array.count ; i++ ){
3584                 if( vs_info.int_array.array[i] == MM_CAMCORDER_VIDEO_STABILIZATION_ON )
3585                         return true;
3586         }
3587
3588         return false;
3589 }
3590
3591 int camera_attr_enable_auto_contrast(camera_h camera, bool enable){
3592         if( camera == NULL ){
3593                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3594                 return CAMERA_ERROR_INVALID_PARAMETER;
3595         }
3596
3597         if( camera_attr_is_supported_auto_contrast(camera) == false ){
3598                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3599                 return CAMERA_ERROR_NOT_SUPPORTED;
3600         }
3601
3602         int ret;
3603         int mode = MM_CAMCORDER_WDR_OFF;
3604
3605         if( enable )
3606                 mode = MM_CAMCORDER_WDR_ON;
3607
3608         camera_s * handle = (camera_s*)camera;
3609         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,  MMCAM_CAMERA_WDR, mode, NULL);
3610
3611         return __convert_camera_error_code(__func__, ret);
3612 }
3613
3614 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled){
3615         if( camera == NULL ){
3616                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
3617                 return CAMERA_ERROR_INVALID_PARAMETER;
3618         }
3619
3620         if( camera_attr_is_supported_auto_contrast(camera) == false ){
3621                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3622                 return CAMERA_ERROR_NOT_SUPPORTED;
3623         }
3624
3625         if( enabled == NULL ){
3626                 LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER);
3627                 return CAMERA_ERROR_INVALID_PARAMETER;
3628         }
3629
3630         int ret;
3631         int mode = MM_CAMCORDER_WDR_OFF;
3632         camera_s * handle = (camera_s*)camera;
3633         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_CAMERA_WDR , &mode, NULL);
3634
3635         if( ret == MM_ERROR_NONE )
3636                 *enabled = mode;
3637
3638         return __convert_camera_error_code(__func__, ret);
3639 }
3640
3641 bool camera_attr_is_supported_auto_contrast(camera_h camera) {
3642         if( camera == NULL ){
3643                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3644                 return false;
3645         }
3646
3647         int i;
3648         camera_s * handle = (camera_s*)camera;
3649         MMCamAttrsInfo info;
3650         int ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WDR, &info);
3651         set_last_result(__convert_camera_error_code(__func__, ret));
3652
3653         for( i=0 ; i < info.int_array.count ; i++ )     {
3654                 if( info.int_array.array[i] == MM_CAMCORDER_WDR_ON )
3655                         return true;
3656         }
3657
3658         return false;
3659 }
3660
3661 int camera_attr_disable_shutter_sound(camera_h camera, bool disable){
3662         if (camera == NULL ){
3663                 LOGE("INVALID_PARAMETER(0x%08x)",CAMERA_ERROR_INVALID_PARAMETER);
3664                 return CAMERA_ERROR_INVALID_PARAMETER;
3665         }
3666
3667         int ret;
3668         camera_s * handle = (camera_s*)camera;
3669         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, "capture-sound-enable", !disable, NULL);
3670
3671         if( ret != 0 ){
3672                 LOGE("CAMERA_ERROR_INVALID_OPERATION : not permitted disable shutter sound");
3673                 return CAMERA_ERROR_INVALID_OPERATION;
3674         }
3675
3676         return CAMERA_ERROR_NONE;
3677 }