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