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