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