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