1. Code clean up
[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(0x%08x) : core frameworks error code(0x%08x)", errorstr, ret, code);
198         }
199
200         return ret;
201 }
202
203
204 static gboolean __mm_videostream_callback(MMCamcorderVideoStreamDataType *stream, void *user_data)
205 {
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         mm_camcorder_get_fps_list_by_resolution(handle->mm_handle, width, height, &info);
1577
1578         for (i = 0 ; i < info.int_array.count ; i++) {
1579                 if (info.int_array.array[i] == mm_fps) {
1580                         break;
1581                 }
1582                 if (i == info.int_array.count - 1) {
1583                         LOGE("Not supported resolution: Current set Resolution's FPS is not supported in wanted resolution.");
1584                         return CAMERA_ERROR_NOT_SUPPORTED;
1585                 }
1586         }
1587
1588         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1589                                           MMCAM_CAMERA_WIDTH, width,
1590                                           MMCAM_CAMERA_HEIGHT, height,
1591                                           NULL);
1592
1593         return __convert_camera_error_code(__func__, ret);
1594 }
1595
1596
1597 int camera_set_capture_resolution(camera_h camera,  int width, int height)
1598 {
1599         if (camera == NULL) {
1600                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1601                 return CAMERA_ERROR_INVALID_PARAMETER;
1602         }
1603
1604         int ret = MM_ERROR_NONE;
1605         camera_s *handle = (camera_s *)camera;
1606
1607         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1608                                           MMCAM_CAPTURE_WIDTH, width,
1609                                           MMCAM_CAPTURE_HEIGHT, height,
1610                                           NULL);
1611         if (ret == MM_ERROR_NONE) {
1612                 handle->capture_width = width;
1613                 handle->capture_height = height;
1614         }
1615
1616         return __convert_camera_error_code(__func__, ret);
1617 }
1618
1619
1620 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
1621 {
1622         if (camera == NULL) {
1623                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1624                 return CAMERA_ERROR_INVALID_PARAMETER;
1625         }
1626
1627         int ret = MM_ERROR_NONE;
1628         camera_s *handle = (camera_s *)camera;
1629
1630         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1631                                           MMCAM_CAPTURE_FORMAT, format,
1632                                           NULL);
1633
1634         return __convert_camera_error_code(__func__, ret);
1635 }
1636
1637
1638 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
1639 {
1640         if (camera == NULL) {
1641                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1642                 return CAMERA_ERROR_INVALID_PARAMETER;
1643         }
1644
1645         int i = 0;
1646         int ret = MM_ERROR_NONE;
1647         camera_s *handle = (camera_s *)camera;
1648
1649         if (format == CAMERA_PIXEL_FORMAT_UYVY) {
1650                 bool supported_ITLV_UYVY = false;
1651                 MMCamAttrsInfo supported_format;
1652                 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT , &supported_format);
1653                 for (i = 0 ; i < supported_format.int_array.count ; i++) {
1654                         if (supported_format.int_array.array[i] == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
1655                                 supported_ITLV_UYVY = true;
1656                         }
1657                 }
1658                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1659                                                   MMCAM_CAMERA_FORMAT, supported_ITLV_UYVY ? MM_PIXEL_FORMAT_ITLV_JPEG_UYVY : MM_PIXEL_FORMAT_UYVY,
1660                                                   NULL);
1661         } else {
1662                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1663                                                   MMCAM_CAMERA_FORMAT, format,
1664                                                   NULL);
1665         }
1666
1667         return __convert_camera_error_code(__func__, ret);
1668 }
1669
1670
1671 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
1672 {
1673         if (camera == NULL || width == NULL || height == NULL) {
1674                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1675                 return CAMERA_ERROR_INVALID_PARAMETER;
1676         }
1677
1678         int ret = MM_ERROR_NONE;
1679         camera_s *handle = (camera_s *)camera;
1680
1681         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1682                                           MMCAM_CAMERA_WIDTH, width,
1683                                           MMCAM_CAMERA_HEIGHT, height,
1684                                           NULL);
1685
1686         return __convert_camera_error_code(__func__, ret);
1687 }
1688
1689
1690 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
1691 {
1692         if (camera == NULL) {
1693                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1694                 return CAMERA_ERROR_INVALID_PARAMETER;
1695         }
1696
1697         if (rotation > CAMERA_ROTATION_270) {
1698                 return CAMERA_ERROR_INVALID_PARAMETER;
1699         }
1700
1701         int ret = MM_ERROR_NONE;
1702         camera_s *handle = (camera_s *)camera;
1703
1704         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1705                                           MMCAM_DISPLAY_ROTATION, rotation,
1706                                           NULL);
1707
1708         return __convert_camera_error_code(__func__, ret);
1709 }
1710
1711
1712 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
1713 {
1714         if (camera == NULL || rotation == NULL) {
1715                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1716                 return CAMERA_ERROR_INVALID_PARAMETER;
1717         }
1718
1719         int ret = MM_ERROR_NONE;
1720         camera_s *handle = (camera_s *)camera;
1721
1722         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1723                                           MMCAM_DISPLAY_ROTATION, rotation,
1724                                           NULL);
1725
1726         return __convert_camera_error_code(__func__, ret);
1727 }
1728
1729
1730 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
1731 {
1732         if (camera == NULL) {
1733                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1734                 return CAMERA_ERROR_INVALID_PARAMETER;
1735         }
1736
1737         if (flip > CAMERA_FLIP_BOTH) {
1738                 return CAMERA_ERROR_INVALID_PARAMETER;
1739         }
1740
1741         int ret = MM_ERROR_NONE;
1742         camera_s *handle = (camera_s *)camera;
1743
1744         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1745                                           MMCAM_DISPLAY_FLIP, flip,
1746                                           NULL);
1747
1748         return __convert_camera_error_code(__func__, ret);
1749 }
1750
1751
1752 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
1753 {
1754         if (camera == NULL || flip == NULL) {
1755                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1756                 return CAMERA_ERROR_INVALID_PARAMETER;
1757         }
1758
1759         int ret = MM_ERROR_NONE;
1760         camera_s *handle = (camera_s *)camera;
1761
1762         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1763                                           MMCAM_DISPLAY_FLIP, flip,
1764                                           NULL);
1765
1766         return __convert_camera_error_code(__func__, ret);
1767 }
1768
1769
1770 int camera_set_display_visible(camera_h camera, bool visible)
1771 {
1772         if (camera == NULL) {
1773                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1774                 return CAMERA_ERROR_INVALID_PARAMETER;
1775         }
1776
1777         int ret = MM_ERROR_NONE;
1778         camera_s *handle = (camera_s *)camera;
1779
1780         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1781                                           MMCAM_DISPLAY_VISIBLE, visible,
1782                                           NULL);
1783
1784         return __convert_camera_error_code(__func__, ret);
1785 }
1786
1787
1788 int camera_is_display_visible(camera_h camera, bool* visible)
1789 {
1790         if (camera == NULL || visible == NULL) {
1791                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1792                 return CAMERA_ERROR_INVALID_PARAMETER;
1793         }
1794
1795         int ret = MM_ERROR_NONE;
1796         int result = false;
1797         camera_s *handle = (camera_s *)camera;
1798
1799         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1800                                           MMCAM_DISPLAY_VISIBLE, &result,
1801                                           NULL);
1802
1803         if (ret == MM_ERROR_NONE) {
1804                 *visible = result;
1805         }
1806
1807         return __convert_camera_error_code(__func__, ret);
1808 }
1809
1810
1811 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
1812 {
1813         if (camera == NULL) {
1814                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1815                 return CAMERA_ERROR_INVALID_PARAMETER;
1816         }
1817
1818         if (mode > CAMERA_DISPLAY_MODE_CROPPED_FULL) {
1819                 return CAMERA_ERROR_INVALID_PARAMETER;
1820         }
1821
1822         int ret = MM_ERROR_NONE;
1823         camera_s *handle = (camera_s *)camera;
1824
1825         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1826                                           MMCAM_DISPLAY_GEOMETRY_METHOD, mode,
1827                                           NULL);
1828
1829         return __convert_camera_error_code(__func__, ret);
1830 }
1831
1832
1833 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
1834 {
1835         if (camera == NULL || mode == NULL) {
1836                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1837                 return CAMERA_ERROR_INVALID_PARAMETER;
1838         }
1839
1840         int ret = MM_ERROR_NONE;
1841         camera_s *handle = (camera_s *)camera;
1842
1843         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1844                                           MMCAM_DISPLAY_GEOMETRY_METHOD, mode,
1845                                           NULL);
1846
1847         return __convert_camera_error_code(__func__, ret);
1848 }
1849
1850
1851 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
1852 {
1853         if (camera == NULL || width == NULL || height == NULL) {
1854                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1855                 return CAMERA_ERROR_INVALID_PARAMETER;
1856         }
1857
1858         camera_s *handle = (camera_s *)camera;
1859
1860         *width = handle->capture_width;
1861         *height = handle->capture_height;
1862
1863         return CAMERA_ERROR_NONE;
1864 }
1865
1866
1867 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
1868 {
1869         if (camera == NULL || format == NULL) {
1870                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1871                 return CAMERA_ERROR_INVALID_PARAMETER;
1872         }
1873
1874         int ret = MM_ERROR_NONE;
1875         camera_s *handle = (camera_s *)camera;
1876
1877         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1878                                           MMCAM_CAPTURE_FORMAT, format,
1879                                           NULL);
1880
1881         return __convert_camera_error_code(__func__, ret);
1882 }
1883
1884
1885 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
1886 {
1887         if (camera == NULL || format == NULL) {
1888                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1889                 return CAMERA_ERROR_INVALID_PARAMETER;
1890         }
1891
1892         int ret = MM_ERROR_NONE;
1893         camera_s *handle = (camera_s *)camera;
1894
1895         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1896                                           MMCAM_CAMERA_FORMAT, format,
1897                                           NULL);
1898
1899         if ((MMPixelFormatType)*format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
1900                 *format = CAMERA_PIXEL_FORMAT_UYVY;
1901         }
1902
1903         return __convert_camera_error_code(__func__, ret);
1904 }
1905
1906
1907 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
1908 {
1909         if (camera == NULL || callback == NULL) {
1910                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1911                 return CAMERA_ERROR_INVALID_PARAMETER;
1912         }
1913
1914         camera_s *handle = (camera_s *)camera;
1915         handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)callback;
1916         handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)user_data;
1917
1918         mm_camcorder_set_video_stream_callback(handle->mm_handle,
1919                                                (mm_camcorder_video_stream_callback)__mm_videostream_callback,
1920                                                (void *)handle);
1921
1922         return CAMERA_ERROR_NONE;
1923 }
1924
1925
1926 int camera_unset_preview_cb(camera_h camera)
1927 {
1928         if (camera == NULL) {
1929                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1930                 return CAMERA_ERROR_INVALID_PARAMETER;
1931         }
1932
1933         camera_s *handle = (camera_s *)camera;
1934
1935         if (handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] == NULL) {
1936                 mm_camcorder_set_video_stream_callback(handle->mm_handle,
1937                                                        (mm_camcorder_video_stream_callback)NULL,
1938                                                        (void *)NULL);
1939         }
1940
1941         handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)NULL;
1942         handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)NULL;
1943
1944         return CAMERA_ERROR_NONE;
1945 }
1946
1947
1948 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
1949 {
1950         if (camera == NULL) {
1951                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
1952                 return CAMERA_ERROR_INVALID_PARAMETER;
1953         }
1954
1955         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
1956                 LOGE("NOT SUPPORTED");
1957                 return CAMERA_ERROR_NOT_SUPPORTED;
1958         }
1959
1960         if (callback == NULL) {
1961                 LOGE("INVALID_PARAMETER(0x%08x) - callback", CAMERA_ERROR_INVALID_PARAMETER);
1962                 return CAMERA_ERROR_INVALID_PARAMETER;
1963         }
1964
1965         camera_s *handle = (camera_s *)camera;
1966         handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)callback;
1967         handle->user_data[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)user_data;
1968
1969         mm_camcorder_set_video_stream_callback(handle->mm_handle,
1970                                                (mm_camcorder_video_stream_callback)__mm_videostream_callback,
1971                                                (void *)handle);
1972
1973         return CAMERA_ERROR_NONE;
1974 }
1975
1976
1977 int camera_unset_media_packet_preview_cb(camera_h camera)
1978 {
1979         if (camera == NULL) {
1980                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
1981                 return CAMERA_ERROR_INVALID_PARAMETER;
1982         }
1983
1984         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
1985                 LOGE("NOT SUPPORTED");
1986                 return CAMERA_ERROR_NOT_SUPPORTED;
1987         }
1988
1989         camera_s *handle = (camera_s *)camera;
1990
1991         if (handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] == NULL) {
1992                 mm_camcorder_set_video_stream_callback(handle->mm_handle,
1993                                                        (mm_camcorder_video_stream_callback)NULL,
1994                                                        (void *)NULL);
1995         }
1996
1997         handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)NULL;
1998         handle->user_data[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)NULL;
1999
2000         return CAMERA_ERROR_NONE;
2001 }
2002
2003
2004 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
2005 {
2006         if (camera == NULL || callback == NULL) {
2007                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2008                 return CAMERA_ERROR_INVALID_PARAMETER;
2009         }
2010
2011         camera_s *handle = (camera_s *)camera;
2012         handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)callback;
2013         handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)user_data;
2014
2015         return CAMERA_ERROR_NONE;
2016 }
2017
2018
2019 int camera_unset_state_changed_cb(camera_h camera)
2020 {
2021         if (camera == NULL) {
2022                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2023                 return CAMERA_ERROR_INVALID_PARAMETER;
2024         }
2025
2026         camera_s *handle = (camera_s *)camera;
2027         handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)NULL;
2028         handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)NULL;
2029
2030         return CAMERA_ERROR_NONE;
2031 }
2032
2033
2034 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
2035 {
2036         if (camera == NULL || callback == NULL) {
2037                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2038                 return CAMERA_ERROR_INVALID_PARAMETER;
2039         }
2040
2041         camera_s *handle = (camera_s *)camera;
2042         handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)callback;
2043         handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)user_data;
2044
2045         return CAMERA_ERROR_NONE;
2046 }
2047
2048
2049 int camera_unset_interrupted_cb(camera_h camera)
2050 {
2051         if (camera == NULL) {
2052                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2053                 return CAMERA_ERROR_INVALID_PARAMETER;
2054         }
2055
2056         camera_s *handle = (camera_s *)camera;
2057
2058         handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)NULL;
2059         handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)NULL;
2060
2061         return CAMERA_ERROR_NONE;
2062 }
2063
2064
2065 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
2066 {
2067         if (camera == NULL || callback == NULL) {
2068                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2069                 return CAMERA_ERROR_INVALID_PARAMETER;
2070         }
2071
2072         camera_s *handle = (camera_s *)camera;
2073
2074         handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)callback;
2075         handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)user_data;
2076
2077         return CAMERA_ERROR_NONE;
2078 }
2079
2080
2081 int camera_unset_focus_changed_cb(camera_h camera)
2082 {
2083         if (camera == NULL) {
2084                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2085                 return CAMERA_ERROR_INVALID_PARAMETER;
2086         }
2087
2088         camera_s *handle = (camera_s *)camera;
2089
2090         handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)NULL;
2091         handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)NULL;
2092
2093         return CAMERA_ERROR_NONE;
2094 }
2095
2096
2097 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
2098 {
2099         if (camera == NULL || callback == NULL) {
2100                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2101                 return CAMERA_ERROR_INVALID_PARAMETER;
2102         }
2103
2104         camera_s *handle = (camera_s *)camera;
2105
2106         handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void *)callback;
2107         handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void *)user_data;
2108
2109         return CAMERA_ERROR_NONE;
2110 }
2111
2112
2113 int camera_unset_error_cb(camera_h camera)
2114 {
2115         if (camera == NULL) {
2116                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2117                 return CAMERA_ERROR_INVALID_PARAMETER;
2118         }
2119
2120         camera_s *handle = (camera_s *)camera;
2121
2122         handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void *)NULL;
2123         handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void *)NULL;
2124
2125         return CAMERA_ERROR_NONE;
2126 }
2127
2128
2129 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
2130 {
2131         if (camera == NULL || foreach_cb == NULL) {
2132                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2133                 return CAMERA_ERROR_INVALID_PARAMETER;
2134         }
2135
2136         int i = 0;
2137         int ret = MM_ERROR_NONE;
2138         camera_s *handle = (camera_s *)camera;
2139         MMCamAttrsInfo preview_width;
2140         MMCamAttrsInfo preview_height;
2141
2142         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WIDTH, &preview_width);
2143         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HEIGHT, &preview_height);
2144         if (ret != CAMERA_ERROR_NONE) {
2145                 return __convert_camera_error_code(__func__, ret);
2146         }
2147
2148         for (i = 0 ; i < preview_width.int_array.count ; i++) {
2149                 if (!foreach_cb(preview_width.int_array.array[i], preview_height.int_array.array[i], user_data)) {
2150                         break;
2151                 }
2152         }
2153
2154         return CAMERA_ERROR_NONE;
2155 }
2156
2157
2158 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
2159 {
2160         if (camera == NULL || foreach_cb == NULL) {
2161                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2162                 return CAMERA_ERROR_INVALID_PARAMETER;
2163         }
2164
2165         int i = 0;
2166         int ret = MM_ERROR_NONE;
2167         camera_s *handle = (camera_s *)camera;
2168         MMCamAttrsInfo capture_width;
2169         MMCamAttrsInfo capture_height;
2170
2171         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_WIDTH, &capture_width);
2172         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_HEIGHT, &capture_height);
2173         if (ret != CAMERA_ERROR_NONE) {
2174                 return __convert_camera_error_code(__func__, ret);
2175         }
2176
2177         for (i = 0 ; i < capture_width.int_array.count ; i++) {
2178                 if (!foreach_cb(capture_width.int_array.array[i], capture_height.int_array.array[i], user_data)) {
2179                         break;
2180                 }
2181         }
2182
2183         return CAMERA_ERROR_NONE;
2184 }
2185
2186
2187 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
2188 {
2189         if (camera == NULL || foreach_cb == NULL) {
2190                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2191                 return CAMERA_ERROR_INVALID_PARAMETER;
2192         }
2193
2194         int i = 0;
2195         int ret = MM_ERROR_NONE;
2196         camera_s *handle = (camera_s *)camera;
2197         MMCamAttrsInfo format;
2198
2199         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_FORMAT, &format);
2200         if (ret != CAMERA_ERROR_NONE) {
2201                 return __convert_camera_error_code(__func__, ret);
2202         }
2203
2204         for (i = 0 ; i < format.int_array.count ; i++) {
2205                 if (format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2206                         if (!foreach_cb(format.int_array.array[i], user_data)) {
2207                                 break;
2208                         }
2209                 }
2210         }
2211
2212         return CAMERA_ERROR_NONE;
2213 }
2214
2215
2216 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
2217 {
2218         if (camera == NULL || foreach_cb == NULL) {
2219                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2220                 return CAMERA_ERROR_INVALID_PARAMETER;
2221         }
2222
2223         int i = 0;
2224         int ret = MM_ERROR_NONE;
2225         camera_s *handle = (camera_s *)camera;
2226         MMCamAttrsInfo format;
2227
2228         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT, &format);
2229         if (ret != CAMERA_ERROR_NONE) {
2230                 return __convert_camera_error_code(__func__, ret);
2231         }
2232
2233         for (i = 0 ; i < format.int_array.count ; i++) {
2234                 if (format.int_array.array[i] != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2235                         if (!foreach_cb(format.int_array.array[i], user_data)) {
2236                                 break;
2237                         }
2238                 }
2239         }
2240
2241         return CAMERA_ERROR_NONE;
2242 }
2243
2244
2245 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
2246 {
2247         if (camera == NULL || width == NULL || height == NULL) {
2248                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2249                 return CAMERA_ERROR_INVALID_PARAMETER;
2250         }
2251
2252         enum MMCamcorderPreviewType wide = MM_CAMCORDER_PREVIEW_TYPE_NORMAL;
2253         int capture_w = 0;
2254         int capture_h = 0;
2255         double ratio = 0.0;
2256         int ret = MM_ERROR_NONE;
2257         camera_s *handle = (camera_s *)camera;
2258         MMCamAttrsInfo width_info;
2259         MMCamAttrsInfo height_info;
2260
2261         camera_get_capture_resolution(camera, &capture_w, &capture_h);
2262         ratio = (double)capture_w / (double)capture_h;
2263         if (ratio > 1.5) {
2264                 wide = MM_CAMCORDER_PREVIEW_TYPE_WIDE;
2265         } else if (ratio == 1.0) {
2266                 wide = MM_CAMCORDER_PREVIEW_TYPE_SQUARE;
2267         } else {
2268                 wide = MM_CAMCORDER_PREVIEW_TYPE_NORMAL;
2269         }
2270
2271         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_RECOMMEND_CAMERA_WIDTH, &width_info);
2272         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_RECOMMEND_CAMERA_HEIGHT, &height_info);
2273         if (ret != MM_ERROR_NONE) {
2274                 return __convert_camera_error_code(__func__, ret);
2275         }
2276
2277         if (width && (unsigned int)width_info.int_array.count > wide) {
2278                 *width = width_info.int_array.array[wide];
2279         } else {
2280                 LOGE("there is no width value for resolution %dx%d type %d", capture_w, capture_h, wide);
2281                 return CAMERA_ERROR_INVALID_OPERATION;
2282         }
2283
2284         if (height && (unsigned int)height_info.int_array.count > wide) {
2285                 *height = height_info.int_array.array[wide];
2286         } else {
2287                 LOGE("there is no height value for resolution %dx%d type %d", capture_w, capture_h, wide);
2288                 return CAMERA_ERROR_INVALID_OPERATION;
2289         }
2290
2291         LOGI("recommend resolution %dx%d, type %d", *width, *height, wide);
2292
2293         return CAMERA_ERROR_NONE;
2294 }
2295
2296
2297 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
2298 {
2299         if (camera == NULL || angle == NULL) {
2300                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2301                 return CAMERA_ERROR_INVALID_PARAMETER;
2302         }
2303
2304         int ret = MM_ERROR_NONE;
2305         camera_s *handle = (camera_s *)camera;
2306         int rotation = MM_DISPLAY_ROTATION_NONE;
2307
2308         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2309                                           MMCAM_RECOMMEND_DISPLAY_ROTATION, &rotation,
2310                                           NULL);
2311
2312         if (ret == MM_ERROR_NONE) {
2313                 switch (rotation) {
2314                 case MM_DISPLAY_ROTATION_NONE:
2315                         *angle = 0;
2316                         break;
2317                 case MM_DISPLAY_ROTATION_90:
2318                         *angle = 270;
2319                         break;
2320                 case MM_DISPLAY_ROTATION_180:
2321                         *angle = 180;
2322                         break;
2323                 case MM_DISPLAY_ROTATION_270:
2324                         *angle = 90;
2325                         break;
2326                 default :
2327                         *angle = 0;
2328                         break;
2329                 }
2330         }
2331
2332         return __convert_camera_error_code(__func__, ret);
2333 }
2334
2335
2336 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
2337 {
2338         if (camera == NULL) {
2339                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2340                 return CAMERA_ERROR_INVALID_PARAMETER;
2341         }
2342
2343         int ret = MM_ERROR_NONE;
2344         camera_s *handle = (camera_s *)camera;
2345
2346         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2347                                           MMCAM_DISPLAY_MODE, mode,
2348                                           NULL);
2349
2350         return __convert_camera_error_code(__func__, ret);
2351 }
2352
2353
2354 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
2355 {
2356         if (camera == NULL || mode == NULL) {
2357                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2358                 return CAMERA_ERROR_INVALID_PARAMETER;
2359         }
2360
2361         int ret = MM_ERROR_NONE;
2362         camera_s *handle = (camera_s *)camera;
2363
2364         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2365                                           MMCAM_DISPLAY_MODE, mode,
2366                                           NULL);
2367
2368         return __convert_camera_error_code(__func__, ret);
2369 }
2370
2371
2372 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
2373 {
2374         if (camera == NULL || foreach_cb == NULL) {
2375                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2376                 return CAMERA_ERROR_INVALID_PARAMETER;
2377         }
2378
2379         int i = 0;
2380         int ret = MM_ERROR_NONE;
2381         camera_s *handle = (camera_s *)camera;
2382         MMCamAttrsInfo info;
2383
2384         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_DISPLAY_MODE, &info);
2385         if (ret != CAMERA_ERROR_NONE) {
2386                 return __convert_camera_error_code(__func__, ret);
2387         }
2388
2389         for (i = 0 ; i < info.int_array.count ; i++) {
2390                 if (!foreach_cb(info.int_array.array[i], user_data)) {
2391                         break;
2392                 }
2393         }
2394
2395         return CAMERA_ERROR_NONE;
2396 }
2397
2398
2399 int camera_attr_set_preview_fps(camera_h camera,  camera_attr_fps_e fps)
2400 {
2401         if (camera == NULL) {
2402                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2403                 return CAMERA_ERROR_INVALID_PARAMETER;
2404         }
2405
2406         int ret = MM_ERROR_NONE;
2407         camera_s *handle = (camera_s *)camera;
2408
2409         if (fps == CAMERA_ATTR_FPS_AUTO) {
2410                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2411                                                   MMCAM_CAMERA_FPS_AUTO, true,
2412                                                   NULL);
2413         } else {
2414                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2415                                                   MMCAM_CAMERA_FPS_AUTO, false,
2416                                                   MMCAM_CAMERA_FPS, fps,
2417                                                   NULL);
2418         }
2419
2420         return __convert_camera_error_code(__func__, ret);
2421 }
2422
2423
2424 int camera_attr_set_image_quality(camera_h camera, int quality)
2425 {
2426         if (camera == NULL) {
2427                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2428                 return CAMERA_ERROR_INVALID_PARAMETER;
2429         }
2430
2431         int ret = MM_ERROR_NONE;
2432         camera_s *handle = (camera_s *)camera;
2433
2434         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2435                                           MMCAM_IMAGE_ENCODER_QUALITY, quality,
2436                                           NULL);
2437
2438         return __convert_camera_error_code(__func__, ret);
2439 }
2440
2441
2442 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
2443 {
2444         if (camera == NULL || fps == NULL) {
2445                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2446                 return CAMERA_ERROR_INVALID_PARAMETER;
2447         }
2448
2449         int ret = MM_ERROR_NONE;
2450         int mm_fps = 0;
2451         int is_auto = false;
2452         camera_s *handle = (camera_s *)camera;
2453
2454         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2455                                           MMCAM_CAMERA_FPS, &mm_fps,
2456                                           MMCAM_CAMERA_FPS_AUTO, &is_auto,
2457                                           NULL);
2458         if (ret == MM_ERROR_NONE) {
2459                 if (is_auto) {
2460                         *fps = CAMERA_ATTR_FPS_AUTO;
2461                 } else {
2462                         *fps = mm_fps;
2463                 }
2464         }
2465
2466         return __convert_camera_error_code(__func__, ret);
2467 }
2468
2469
2470 int camera_attr_get_image_quality(camera_h camera, int *quality)
2471 {
2472         if (camera == NULL || quality == NULL) {
2473                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2474                 return CAMERA_ERROR_INVALID_PARAMETER;
2475         }
2476
2477         int ret = MM_ERROR_NONE;
2478         camera_s *handle = (camera_s *)camera;
2479
2480         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2481                                           MMCAM_IMAGE_ENCODER_QUALITY, quality,
2482                                           NULL);
2483
2484         return __convert_camera_error_code(__func__, ret);
2485 }
2486
2487
2488 int camera_attr_set_zoom(camera_h camera, int zoom)
2489 {
2490         if (camera == NULL) {
2491                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2492                 return CAMERA_ERROR_INVALID_PARAMETER;
2493         }
2494
2495         int ret = MM_ERROR_NONE;
2496         camera_s *handle = (camera_s *)camera;
2497
2498         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2499                                           MMCAM_CAMERA_DIGITAL_ZOOM, zoom,
2500                                           NULL);
2501
2502         return __convert_camera_error_code(__func__, ret);
2503 }
2504
2505
2506 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
2507 {
2508         if (camera == NULL) {
2509                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2510                 return CAMERA_ERROR_INVALID_PARAMETER;
2511         }
2512
2513         int ret = MM_ERROR_NONE;
2514         camera_s *handle = (camera_s *)camera;
2515         int focus_mode;
2516         bool should_change_focus_mode = false;
2517
2518         mm_camcorder_get_attributes(handle->mm_handle, NULL,
2519                                     MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2520                                     NULL);
2521
2522         if (focus_mode != MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO &&
2523             focus_mode != MM_CAMCORDER_FOCUS_MODE_CONTINUOUS &&
2524             focus_mode != MM_CAMCORDER_FOCUS_MODE_AUTO) {
2525                 should_change_focus_mode = true;
2526         }
2527
2528         if (mode != CAMERA_ATTR_AF_NONE &&
2529             focus_mode == MM_CAMCORDER_FOCUS_MODE_CONTINUOUS &&
2530             !handle->on_continuous_focusing) {
2531                 handle->cached_focus_mode = mode;
2532                 LOGD("af mode will be set actually start focusing");
2533                 return __convert_camera_error_code(__func__, MM_ERROR_NONE);
2534         } else {
2535                 handle->cached_focus_mode = -1;
2536         }
2537
2538         if (mode != CAMERA_ATTR_AF_NONE && should_change_focus_mode) {
2539                 mm_camcorder_set_attributes(handle->mm_handle, NULL,
2540                                             MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_AUTO,
2541                                             NULL);
2542         }
2543
2544         switch (mode) {
2545         case CAMERA_ATTR_AF_NONE:
2546                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2547                                                   MMCAM_CAMERA_FOCUS_MODE, MM_CAMCORDER_FOCUS_MODE_NONE,
2548                                                   MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_NONE,
2549                                                   NULL);
2550                 break;
2551         case CAMERA_ATTR_AF_NORMAL:
2552                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2553                                                   MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_NORMAL,
2554                                                   NULL);
2555                 break;
2556         case CAMERA_ATTR_AF_MACRO:
2557                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2558                                                   MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_MACRO,
2559                                                   NULL);
2560                 break;
2561         case CAMERA_ATTR_AF_FULL:
2562                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2563                                                   MMCAM_CAMERA_AF_SCAN_RANGE, MM_CAMCORDER_AUTO_FOCUS_FULL,
2564                                                   NULL);
2565                 break;
2566         default:
2567                 LOGE("invalid mode %d", mode);
2568                 return CAMERA_ERROR_INVALID_PARAMETER;
2569         }
2570
2571         return __convert_camera_error_code(__func__, ret);
2572 }
2573
2574
2575 int camera_attr_set_af_area(camera_h camera, int x, int y)
2576 {
2577         if (camera == NULL) {
2578                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2579                 return CAMERA_ERROR_INVALID_PARAMETER;
2580         }
2581
2582         int ret = MM_ERROR_NONE;
2583         camera_s *handle = (camera_s *)camera;
2584         camera_attr_af_mode_e mode;
2585
2586         camera_attr_get_af_mode(camera, &mode);
2587         if (mode == CAMERA_ATTR_AF_NONE) {
2588                 LOGE("INVALID_OPERATION(0x%08x) AF mode is CAMERA_ATTR_AF_NONE", CAMERA_ERROR_INVALID_OPERATION);
2589                 return CAMERA_ERROR_INVALID_OPERATION;
2590         }
2591
2592         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2593                                           MMCAM_CAMERA_AF_TOUCH_X, x,
2594                                           MMCAM_CAMERA_AF_TOUCH_Y, y,
2595                                           NULL);
2596         if (ret == MM_ERROR_NONE) {
2597                 handle->focus_area_valid = true;
2598         }
2599
2600         return __convert_camera_error_code(__func__, ret);
2601 }
2602
2603
2604 int camera_attr_clear_af_area(camera_h camera)
2605 {
2606         if (camera == NULL) {
2607                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2608                 return CAMERA_ERROR_INVALID_PARAMETER;
2609         }
2610
2611         camera_s *handle = (camera_s *)camera;
2612
2613         handle->focus_area_valid = false;
2614
2615         return 0;
2616 }
2617
2618
2619 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
2620 {
2621         if (camera == NULL) {
2622                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2623                 return CAMERA_ERROR_INVALID_PARAMETER;
2624         }
2625
2626         int maptable[] = {MM_CAMCORDER_AUTO_EXPOSURE_OFF,       /* CAMERA_ATTR_EXPOSURE_MODE_OFF */
2627                           MM_CAMCORDER_AUTO_EXPOSURE_ALL,       /* CAMERA_ATTR_EXPOSURE_MODE_ALL */
2628                           MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1,  /* CAMERA_ATTR_EXPOSURE_MODE_CENTER */
2629                           MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1,    /* CAMERA_ATTR_EXPOSURE_MODE_SPOT */
2630                           MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1,  /* CAMERA_ATTR_EXPOSURE_MODE_CUSTOM */
2631                          };
2632
2633         int ret = MM_ERROR_NONE;
2634         camera_s *handle = (camera_s *)camera;
2635
2636         if (mode < CAMERA_ATTR_EXPOSURE_MODE_OFF || mode > CAMERA_ATTR_EXPOSURE_MODE_CUSTOM) {
2637                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2638                 return CAMERA_ERROR_INVALID_PARAMETER;
2639         }
2640
2641         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2642                                           MMCAM_CAMERA_EXPOSURE_MODE, maptable[mode],
2643                                           NULL);
2644
2645         return __convert_camera_error_code(__func__, ret);
2646 }
2647
2648
2649 int camera_attr_set_exposure(camera_h camera, int value)
2650 {
2651         if (camera == NULL) {
2652                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2653                 return CAMERA_ERROR_INVALID_PARAMETER;
2654         }
2655
2656         int ret = MM_ERROR_NONE;
2657         camera_s *handle = (camera_s *)camera;
2658
2659         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2660                                           MMCAM_CAMERA_EXPOSURE_VALUE, value,
2661                                           NULL);
2662
2663         return __convert_camera_error_code(__func__, ret);
2664 }
2665
2666
2667 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
2668 {
2669         if (camera == NULL) {
2670                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2671                 return CAMERA_ERROR_INVALID_PARAMETER;
2672         }
2673
2674         int ret = MM_ERROR_NONE;
2675         camera_s *handle = (camera_s*)camera;
2676
2677         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2678                                           MMCAM_CAMERA_ISO, iso,
2679                                           NULL);
2680
2681         return __convert_camera_error_code(__func__, ret);
2682 }
2683
2684
2685 int camera_attr_set_brightness(camera_h camera, int level)
2686 {
2687         if (camera == NULL) {
2688                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2689                 return CAMERA_ERROR_INVALID_PARAMETER;
2690         }
2691
2692         int ret = MM_ERROR_NONE;
2693         camera_s *handle = (camera_s *)camera;
2694
2695         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2696                                           MMCAM_FILTER_BRIGHTNESS, level,
2697                                           NULL);
2698
2699         return __convert_camera_error_code(__func__, ret);
2700 }
2701
2702
2703 int camera_attr_set_contrast(camera_h camera, int level)
2704 {
2705         if (camera == NULL) {
2706                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2707                 return CAMERA_ERROR_INVALID_PARAMETER;
2708         }
2709
2710         int ret = MM_ERROR_NONE;
2711         camera_s *handle = (camera_s *)camera;
2712
2713         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2714                                           MMCAM_FILTER_CONTRAST, level,
2715                                           NULL);
2716
2717         return __convert_camera_error_code(__func__, ret);
2718 }
2719
2720
2721 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
2722 {
2723         if (camera == NULL) {
2724                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2725                 return CAMERA_ERROR_INVALID_PARAMETER;
2726         }
2727
2728         int ret = MM_ERROR_NONE;
2729         camera_s *handle = (camera_s *)camera;
2730
2731         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2732                                           MMCAM_FILTER_WB, wb,
2733                                           NULL);
2734
2735         return __convert_camera_error_code(__func__, ret);
2736 }
2737
2738
2739 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
2740 {
2741         if (camera == NULL) {
2742                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2743                 return CAMERA_ERROR_INVALID_PARAMETER;
2744         }
2745
2746         int ret = MM_ERROR_NONE;
2747         camera_s *handle = (camera_s *)camera;
2748
2749         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2750                                           MMCAM_FILTER_COLOR_TONE, effect,
2751                                           NULL);
2752
2753         return __convert_camera_error_code(__func__, ret);
2754 }
2755
2756
2757 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
2758 {
2759         if (camera == NULL) {
2760                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2761                 return CAMERA_ERROR_INVALID_PARAMETER;
2762         }
2763
2764         int ret = MM_ERROR_NONE;
2765         camera_s *handle = (camera_s *)camera;
2766
2767         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2768                                           MMCAM_FILTER_SCENE_MODE, mode,
2769                                           NULL);
2770
2771         return __convert_camera_error_code(__func__, ret);
2772 }
2773
2774
2775 int camera_attr_enable_tag(camera_h camera, bool enable)
2776 {
2777         if (camera == NULL) {
2778                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2779                 return CAMERA_ERROR_INVALID_PARAMETER;
2780         }
2781
2782         int ret = MM_ERROR_NONE;
2783         camera_s *handle = (camera_s *)camera;
2784
2785         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2786                                           MMCAM_TAG_ENABLE, enable,
2787                                           NULL);
2788
2789         return __convert_camera_error_code(__func__, ret);
2790 }
2791
2792
2793 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
2794 {
2795         if (camera == NULL) {
2796                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2797                 return CAMERA_ERROR_INVALID_PARAMETER;
2798         }
2799
2800         int ret = MM_ERROR_NONE;
2801         camera_s *handle = (camera_s *)camera;
2802
2803         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2804                                           MMCAM_TAG_IMAGE_DESCRIPTION, description, strlen(description),
2805                                           NULL);
2806
2807         return __convert_camera_error_code(__func__, ret);
2808 }
2809
2810
2811 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
2812 {
2813         if (camera == NULL) {
2814                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2815                 return CAMERA_ERROR_INVALID_PARAMETER;
2816         }
2817
2818         int ret = MM_ERROR_NONE;
2819         camera_s *handle = (camera_s *)camera;
2820
2821         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2822                                           MMCAM_TAG_ORIENTATION, orientation,
2823                                           NULL);
2824
2825         return __convert_camera_error_code(__func__, ret);
2826 }
2827
2828
2829 int camera_attr_set_tag_software(camera_h camera, const char *software)
2830 {
2831         if (camera == NULL) {
2832                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2833                 return CAMERA_ERROR_INVALID_PARAMETER;
2834         }
2835
2836         int ret = MM_ERROR_NONE;
2837         camera_s *handle = (camera_s *)camera;
2838
2839         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2840                                           MMCAM_TAG_SOFTWARE, software, strlen(software),
2841                                           NULL);
2842
2843         return __convert_camera_error_code(__func__, ret);
2844 }
2845
2846
2847 int camera_attr_set_geotag(camera_h camera, double latitude , double longitude, double altitude)
2848 {
2849         if (camera == NULL) {
2850                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2851                 return CAMERA_ERROR_INVALID_PARAMETER;
2852         }
2853
2854         int ret = MM_ERROR_NONE;
2855         camera_s *handle = (camera_s *)camera;
2856
2857         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2858                                           MMCAM_TAG_GPS_ENABLE, true,
2859                                           MMCAM_TAG_LATITUDE, latitude,
2860                                           MMCAM_TAG_LONGITUDE, longitude,
2861                                           MMCAM_TAG_ALTITUDE, altitude,
2862                                           NULL);
2863
2864         return __convert_camera_error_code(__func__, ret);
2865 }
2866
2867
2868 int camera_attr_remove_geotag(camera_h camera)
2869 {
2870         if (camera == NULL) {
2871                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2872                 return CAMERA_ERROR_INVALID_PARAMETER;
2873         }
2874
2875         int ret = MM_ERROR_NONE;
2876         camera_s *handle = (camera_s *)camera;
2877
2878         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2879                                           MMCAM_TAG_GPS_ENABLE, false,
2880                                           NULL);
2881
2882         return __convert_camera_error_code(__func__, ret);
2883 }
2884
2885
2886 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
2887 {
2888         if (camera == NULL) {
2889                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2890                 return CAMERA_ERROR_INVALID_PARAMETER;
2891         }
2892
2893         int ret = MM_ERROR_NONE;
2894         camera_s *handle = (camera_s *)camera;
2895
2896         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2897                                           MMCAM_STROBE_MODE, mode,
2898                                           NULL);
2899
2900         return __convert_camera_error_code(__func__, ret);
2901 }
2902
2903
2904 int camera_attr_get_zoom(camera_h camera, int *zoom)
2905 {
2906         if (camera == NULL || zoom == NULL) {
2907                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2908                 return CAMERA_ERROR_INVALID_PARAMETER;
2909         }
2910
2911         int ret = MM_ERROR_NONE;
2912         camera_s *handle = (camera_s *)camera;
2913
2914         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2915                                           MMCAM_CAMERA_DIGITAL_ZOOM, zoom,
2916                                           NULL);
2917
2918         return __convert_camera_error_code(__func__, ret);
2919 }
2920
2921
2922 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
2923 {
2924         if (camera == NULL || min == NULL || max == NULL) {
2925                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2926                 return CAMERA_ERROR_INVALID_PARAMETER;
2927         }
2928
2929         int ret = MM_ERROR_NONE;
2930         camera_s *handle = (camera_s *)camera;
2931         MMCamAttrsInfo ainfo;
2932
2933         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_DIGITAL_ZOOM, &ainfo);
2934         if (ret == MM_ERROR_NONE) {
2935                 *min = ainfo.int_range.min;
2936                 *max = ainfo.int_range.max;
2937         }
2938
2939         return __convert_camera_error_code(__func__, ret);
2940 }
2941
2942
2943 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
2944 {
2945         if (camera == NULL || mode == NULL) {
2946                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
2947                 return CAMERA_ERROR_INVALID_PARAMETER;
2948         }
2949
2950         int ret = MM_ERROR_NONE;
2951         int focus_mode;
2952         int af_range;
2953         int detect_mode;
2954         camera_s *handle = (camera_s *)camera;
2955
2956         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2957                                           MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2958                                           MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2959                                           MMCAM_DETECT_MODE, &detect_mode,
2960                                           NULL);
2961         if (ret == MM_ERROR_NONE) {
2962                 switch (focus_mode) {
2963                 case MM_CAMCORDER_FOCUS_MODE_NONE:
2964                 case MM_CAMCORDER_FOCUS_MODE_PAN:
2965                 case MM_CAMCORDER_FOCUS_MODE_MANUAL:
2966                         *mode = CAMERA_ATTR_AF_NONE;
2967                         break;
2968                 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2969                 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2970                 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2971                         switch (af_range) {
2972                         case MM_CAMCORDER_AUTO_FOCUS_NONE:
2973                                 *mode = CAMERA_ATTR_AF_NORMAL;
2974                                 break;
2975                         case MM_CAMCORDER_AUTO_FOCUS_NORMAL:
2976                                 *mode = CAMERA_ATTR_AF_NORMAL;
2977                                 break;
2978                         case MM_CAMCORDER_AUTO_FOCUS_MACRO:
2979                                 *mode = CAMERA_ATTR_AF_MACRO;
2980                                 break;
2981                         case MM_CAMCORDER_AUTO_FOCUS_FULL:
2982                                 *mode = CAMERA_ATTR_AF_FULL;
2983                                 break;
2984                         default :
2985                                 *mode = CAMERA_ATTR_AF_NORMAL;
2986                                 break;
2987                         }
2988                         break;
2989                 default:
2990                         *mode = CAMERA_ATTR_AF_NONE;
2991                         break;
2992                 }
2993         }
2994
2995         return __convert_camera_error_code(__func__, ret);
2996 }
2997
2998
2999 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
3000 {
3001         if (camera == NULL || mode == NULL) {
3002                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3003                 return CAMERA_ERROR_INVALID_PARAMETER;
3004         }
3005
3006         int maptable[] = {CAMERA_ATTR_EXPOSURE_MODE_OFF,        /* MM_CAMCORDER_AUTO_EXPOSURE_OFF */
3007                           CAMERA_ATTR_EXPOSURE_MODE_ALL,        /* MM_CAMCORDER_AUTO_EXPOSURE_ALL */
3008                           CAMERA_ATTR_EXPOSURE_MODE_CENTER,     /* MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1 */
3009                           CAMERA_ATTR_EXPOSURE_MODE_CENTER,     /* MM_CAMCORDER_AUTO_EXPOSURE_CENTER_2 */
3010                           CAMERA_ATTR_EXPOSURE_MODE_CENTER,     /* MM_CAMCORDER_AUTO_EXPOSURE_CENTER_3 */
3011                           CAMERA_ATTR_EXPOSURE_MODE_SPOT,       /* MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1 */
3012                           CAMERA_ATTR_EXPOSURE_MODE_SPOT,       /* MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2 */
3013                           CAMERA_ATTR_EXPOSURE_MODE_CUSTOM,     /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1 */
3014                           CAMERA_ATTR_EXPOSURE_MODE_CUSTOM      /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2 */
3015                          };
3016         int ret = MM_ERROR_NONE;
3017         int exposure_mode;
3018         camera_s *handle = (camera_s *)camera;
3019
3020         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3021                                           MMCAM_CAMERA_EXPOSURE_MODE, &exposure_mode,
3022                                           NULL);
3023
3024         if (ret == CAMERA_ERROR_NONE) {
3025                 *mode = maptable[abs(exposure_mode%9)];
3026         }
3027
3028         return __convert_camera_error_code(__func__, ret);
3029 }
3030
3031
3032 int camera_attr_get_exposure(camera_h camera, int *value)
3033 {
3034         if (camera == NULL || value == NULL) {
3035                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3036                 return CAMERA_ERROR_INVALID_PARAMETER;
3037         }
3038
3039         int ret = MM_ERROR_NONE;
3040         camera_s *handle = (camera_s *)camera;
3041
3042         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3043                                           MMCAM_CAMERA_EXPOSURE_VALUE, value,
3044                                           NULL);
3045
3046         return __convert_camera_error_code(__func__, ret);
3047 }
3048
3049
3050 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
3051 {
3052         if (camera == NULL || min == NULL || max == NULL) {
3053                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3054                 return CAMERA_ERROR_INVALID_PARAMETER;
3055         }
3056
3057         int ret = MM_ERROR_NONE;
3058         camera_s *handle = (camera_s *)camera;
3059         MMCamAttrsInfo ainfo;
3060
3061         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_VALUE, &ainfo);
3062         if (ret == MM_ERROR_NONE) {
3063                 *min = ainfo.int_range.min;
3064                 *max = ainfo.int_range.max;
3065         }
3066
3067         return __convert_camera_error_code(__func__, ret);
3068 }
3069
3070
3071 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
3072 {
3073         if (camera == NULL || iso == NULL) {
3074                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3075                 return CAMERA_ERROR_INVALID_PARAMETER;
3076         }
3077
3078         int ret = MM_ERROR_NONE;
3079         camera_s *handle = (camera_s *)camera;
3080
3081         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3082                                           MMCAM_CAMERA_ISO, iso,
3083                                           NULL);
3084
3085         return __convert_camera_error_code(__func__, ret);
3086 }
3087
3088
3089 int camera_attr_get_brightness(camera_h camera, int *level)
3090 {
3091         if (camera == NULL || level == NULL) {
3092                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3093                 return CAMERA_ERROR_INVALID_PARAMETER;
3094         }
3095
3096         int ret = MM_ERROR_NONE;
3097         camera_s *handle = (camera_s *)camera;
3098
3099         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3100                                           MMCAM_FILTER_BRIGHTNESS, level,
3101                                           NULL);
3102
3103         return __convert_camera_error_code(__func__, ret);
3104 }
3105
3106
3107 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
3108 {
3109         if (camera == NULL || min == NULL || max == NULL) {
3110                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3111                 return CAMERA_ERROR_INVALID_PARAMETER;
3112         }
3113
3114         int ret = MM_ERROR_NONE;
3115         camera_s *handle = (camera_s *)camera;
3116         MMCamAttrsInfo ainfo;
3117
3118         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_BRIGHTNESS, &ainfo);
3119         if (ret == MM_ERROR_NONE) {
3120                 *min = ainfo.int_range.min;
3121                 *max = ainfo.int_range.max;
3122         }
3123
3124         return __convert_camera_error_code(__func__, ret);
3125 }
3126
3127
3128 int camera_attr_get_contrast(camera_h camera, int *level)
3129 {
3130         if (camera == NULL || level == NULL) {
3131                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3132                 return CAMERA_ERROR_INVALID_PARAMETER;
3133         }
3134
3135         int ret = MM_ERROR_NONE;
3136         camera_s *handle = (camera_s *)camera;
3137
3138         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3139                                           MMCAM_FILTER_CONTRAST, level,
3140                                           NULL);
3141
3142         return __convert_camera_error_code(__func__, ret);
3143 }
3144
3145
3146 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
3147 {
3148         if (camera == NULL || min == NULL || max == NULL) {
3149                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3150                 return CAMERA_ERROR_INVALID_PARAMETER;
3151         }
3152
3153         int ret = MM_ERROR_NONE;
3154         camera_s *handle = (camera_s *)camera;
3155         MMCamAttrsInfo ainfo;
3156
3157         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_CONTRAST, &ainfo);
3158         if (ret == MM_ERROR_NONE) {
3159                 *min = ainfo.int_range.min;
3160                 *max = ainfo.int_range.max;
3161         }
3162
3163         return __convert_camera_error_code(__func__, ret);
3164 }
3165
3166
3167 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
3168 {
3169         if (camera == NULL || wb == NULL) {
3170                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3171                 return CAMERA_ERROR_INVALID_PARAMETER;
3172         }
3173
3174         int ret = MM_ERROR_NONE;
3175         camera_s *handle = (camera_s *)camera;
3176
3177         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3178                                           MMCAM_FILTER_WB, wb,
3179                                           NULL);
3180
3181         return __convert_camera_error_code(__func__, ret);
3182 }
3183
3184
3185 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
3186 {
3187         if (camera == NULL || effect == NULL) {
3188                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3189                 return CAMERA_ERROR_INVALID_PARAMETER;
3190         }
3191
3192         int ret = MM_ERROR_NONE;
3193         camera_s *handle = (camera_s *)camera;
3194
3195         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3196                                           MMCAM_FILTER_COLOR_TONE, effect,
3197                                           NULL);
3198
3199         return __convert_camera_error_code(__func__, ret);
3200 }
3201
3202
3203 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
3204 {
3205         if (camera == NULL || mode == NULL) {
3206                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3207                 return CAMERA_ERROR_INVALID_PARAMETER;
3208         }
3209
3210         int ret = MM_ERROR_NONE;
3211         camera_s *handle = (camera_s *)camera;
3212
3213         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3214                                           MMCAM_FILTER_SCENE_MODE, mode,
3215                                           NULL);
3216
3217         return __convert_camera_error_code(__func__, ret);
3218 }
3219
3220
3221 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
3222 {
3223         if (camera == NULL || enable == NULL) {
3224                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3225                 return CAMERA_ERROR_INVALID_PARAMETER;
3226         }
3227
3228         int ret = MM_ERROR_NONE;
3229         camera_s *handle = (camera_s *)camera;
3230
3231         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3232                                           MMCAM_TAG_ENABLE, enable,
3233                                           NULL);
3234
3235         return __convert_camera_error_code(__func__, ret);
3236 }
3237
3238
3239 int camera_attr_get_tag_image_description(camera_h camera, char **description)
3240 {
3241         if (camera == NULL || description == NULL) {
3242                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3243                 return CAMERA_ERROR_INVALID_PARAMETER;
3244         }
3245
3246         int ret = MM_ERROR_NONE;
3247         camera_s *handle = (camera_s *)camera;
3248         char *ndescription = NULL;
3249         int desc_size;
3250
3251         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3252                                           MMCAM_TAG_IMAGE_DESCRIPTION, &ndescription, &desc_size,
3253                                           NULL);
3254         if (ret == MM_ERROR_NONE) {
3255                 if (ndescription != NULL) {
3256                         *description = strdup(ndescription);
3257                 } else {
3258                         *description = strdup("");
3259                 }
3260         }
3261
3262         return __convert_camera_error_code(__func__, ret);
3263 }
3264
3265
3266 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
3267 {
3268         if (camera == NULL || orientation == NULL) {
3269                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3270                 return CAMERA_ERROR_INVALID_PARAMETER;
3271         }
3272
3273         int ret = MM_ERROR_NONE;
3274         camera_s *handle = (camera_s *)camera;
3275
3276         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3277                                           MMCAM_TAG_ORIENTATION, orientation,
3278                                           NULL);
3279
3280         return __convert_camera_error_code(__func__, ret);
3281 }
3282
3283
3284 int camera_attr_get_tag_software(camera_h camera, char **software)
3285 {
3286         if (camera == NULL || software == NULL) {
3287                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3288                 return CAMERA_ERROR_INVALID_PARAMETER;
3289         }
3290
3291         int ret = MM_ERROR_NONE;
3292         camera_s *handle = (camera_s *)camera;
3293         char *soft = NULL;
3294         int soft_size;
3295
3296         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3297                                           MMCAM_TAG_SOFTWARE, &soft, &soft_size,
3298                                           NULL);
3299         if (ret == MM_ERROR_NONE) {
3300                 if (soft != NULL) {
3301                         *software = strdup(soft);
3302                 } else {
3303                         *software = strdup("");
3304                 }
3305         }
3306
3307         return __convert_camera_error_code(__func__, ret);
3308 }
3309
3310
3311 int camera_attr_get_geotag(camera_h camera, double *latitude , double *longitude, double *altitude)
3312 {
3313         if (camera == NULL || latitude == NULL || longitude == NULL || altitude == NULL) {
3314                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3315                 return CAMERA_ERROR_INVALID_PARAMETER;
3316         }
3317
3318         int ret = MM_ERROR_NONE;
3319         camera_s *handle = (camera_s *)camera;
3320
3321         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3322                                           MMCAM_TAG_LATITUDE, latitude,
3323                                           MMCAM_TAG_LONGITUDE, longitude,
3324                                           MMCAM_TAG_ALTITUDE, altitude,
3325                                           NULL);
3326
3327         return __convert_camera_error_code(__func__, ret);
3328 }
3329
3330
3331 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
3332 {
3333         if (camera == NULL || mode == NULL) {
3334                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3335                 return CAMERA_ERROR_INVALID_PARAMETER;
3336         }
3337
3338         int ret = MM_ERROR_NONE;
3339         camera_s *handle = (camera_s *)camera;
3340
3341         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3342                                           MMCAM_STROBE_MODE, mode,
3343                                           NULL);
3344
3345         return __convert_camera_error_code(__func__, ret);
3346 }
3347
3348
3349 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
3350 {
3351         if (camera == NULL || foreach_cb == NULL) {
3352                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3353                 return CAMERA_ERROR_INVALID_PARAMETER;
3354         }
3355
3356         int ret = MM_ERROR_NONE;
3357         int i = 0;
3358         camera_s *handle = (camera_s *)camera;
3359         MMCamAttrsInfo af_range;
3360         MMCamAttrsInfo focus_mode;
3361
3362         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_AF_SCAN_RANGE, &af_range);
3363         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FOCUS_MODE, &focus_mode);
3364         if (ret != MM_ERROR_NONE) {
3365                 return __convert_camera_error_code(__func__, ret);
3366         }
3367
3368         for (i = 0 ; i < af_range.int_array.count ; i++) {
3369                 if (!foreach_cb(af_range.int_array.array[i], user_data)) {
3370                         break;;
3371                 }
3372         }
3373
3374         return CAMERA_ERROR_NONE;
3375 }
3376
3377
3378 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
3379 {
3380         if (camera == NULL || foreach_cb == NULL) {
3381                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3382                 return CAMERA_ERROR_INVALID_PARAMETER;
3383         }
3384
3385         int maptable[] = {CAMERA_ATTR_EXPOSURE_MODE_OFF,        /* MM_CAMCORDER_AUTO_EXPOSURE_OFF */
3386                           CAMERA_ATTR_EXPOSURE_MODE_ALL,        /* MM_CAMCORDER_AUTO_EXPOSURE_ALL */
3387                           CAMERA_ATTR_EXPOSURE_MODE_CENTER,     /* MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1 */
3388                           -1,                                   /* MM_CAMCORDER_AUTO_EXPOSURE_CENTER_2 */
3389                           -1,                                   /* MM_CAMCORDER_AUTO_EXPOSURE_CENTER_3 */
3390                           CAMERA_ATTR_EXPOSURE_MODE_SPOT,       /* MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1 */
3391                           -1,                                   /* MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2 */
3392                           CAMERA_ATTR_EXPOSURE_MODE_CUSTOM,     /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1 */
3393                           -1                                    /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2 */
3394                          };
3395         int i = 0;
3396         int ret = MM_ERROR_NONE;
3397         camera_s *handle = (camera_s *)camera;
3398         MMCamAttrsInfo info;
3399
3400         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_MODE, &info);
3401         if (ret != MM_ERROR_NONE) {
3402                 return __convert_camera_error_code(__func__, ret);
3403         }
3404
3405         for (i = 0 ; i < info.int_array.count ; i++) {
3406                 if (info.int_array.array[i] >= MM_CAMCORDER_AUTO_EXPOSURE_OFF &&
3407                     info.int_array.array[i] <= MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2) {
3408                         if (maptable[info.int_array.array[i]] != -1) {
3409                                 if (!foreach_cb(maptable[info.int_array.array[i]], user_data)) {
3410                                         break;
3411                                 }
3412                         }
3413                 } else {
3414                         LOGW("unknown value %d", info.int_array.array[i]);
3415                 }
3416         }
3417
3418         return CAMERA_ERROR_NONE;
3419 }
3420
3421
3422 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
3423 {
3424         if (camera == NULL || foreach_cb == NULL) {
3425                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3426                 return CAMERA_ERROR_INVALID_PARAMETER;
3427         }
3428
3429         int i = 0;
3430         int ret = MM_ERROR_NONE;
3431         camera_s *handle = (camera_s *)camera;
3432         MMCamAttrsInfo info;
3433
3434         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ISO, &info);
3435         if (ret != MM_ERROR_NONE) {
3436                 return __convert_camera_error_code(__func__, ret);
3437         }
3438
3439         for (i = 0 ; i < info.int_array.count ; i++) {
3440                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3441                         break;
3442                 }
3443         }
3444
3445         return CAMERA_ERROR_NONE;
3446 }
3447
3448
3449 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
3450 {
3451         if (camera == NULL || foreach_cb == NULL) {
3452                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3453                 return CAMERA_ERROR_INVALID_PARAMETER;
3454         }
3455
3456         int i = 0;
3457         int ret = MM_ERROR_NONE;
3458         camera_s *handle = (camera_s *)camera;
3459         MMCamAttrsInfo info;
3460
3461         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_WB, &info);
3462         if (ret != MM_ERROR_NONE) {
3463                 return __convert_camera_error_code(__func__, ret);
3464         }
3465
3466         for (i = 0 ; i < info.int_array.count ; i++) {
3467                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3468                         break;
3469                 }
3470         }
3471
3472         return CAMERA_ERROR_NONE;
3473 }
3474
3475
3476 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
3477 {
3478         if (camera == NULL || foreach_cb == NULL) {
3479                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3480                 return CAMERA_ERROR_INVALID_PARAMETER;
3481         }
3482
3483         int i = 0;
3484         int ret = MM_ERROR_NONE;
3485         camera_s *handle = (camera_s *)camera;
3486         MMCamAttrsInfo info;
3487
3488         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_COLOR_TONE, &info);
3489         if (ret != MM_ERROR_NONE) {
3490                 return __convert_camera_error_code(__func__, ret);
3491         }
3492
3493         for (i = 0 ; i < info.int_array.count ; i++) {
3494                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3495                         break;
3496                 }
3497         }
3498
3499         return CAMERA_ERROR_NONE;
3500 }
3501
3502
3503 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
3504 {
3505         if (camera == NULL || foreach_cb == NULL) {
3506                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3507                 return CAMERA_ERROR_INVALID_PARAMETER;
3508         }
3509
3510         int i = 0;
3511         int ret = MM_ERROR_NONE;
3512         camera_s *handle = (camera_s *)camera;
3513         MMCamAttrsInfo info;
3514
3515         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_SCENE_MODE, &info);
3516         if (ret != MM_ERROR_NONE) {
3517                 return __convert_camera_error_code(__func__, ret);
3518         }
3519
3520         for (i = 0 ; i < info.int_array.count ; i++) {
3521                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3522                         break;
3523                 }
3524         }
3525
3526         return CAMERA_ERROR_NONE;
3527 }
3528
3529
3530 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
3531 {
3532         if (camera == NULL || foreach_cb == NULL) {
3533                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3534                 return CAMERA_ERROR_INVALID_PARAMETER;
3535         }
3536
3537         int i = 0;
3538         int ret = MM_ERROR_NONE;
3539         camera_s *handle = (camera_s *)camera;
3540         MMCamAttrsInfo info;
3541
3542         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_STROBE_MODE, &info);
3543         if (ret != MM_ERROR_NONE) {
3544                 return __convert_camera_error_code(__func__, ret);
3545         }
3546
3547         for (i = 0 ; i < info.int_array.count ; i++) {
3548                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3549                         break;
3550                 }
3551         }
3552
3553         return CAMERA_ERROR_NONE;
3554 }
3555
3556
3557 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
3558 {
3559         if (camera == NULL || foreach_cb == NULL) {
3560                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3561                 return CAMERA_ERROR_INVALID_PARAMETER;
3562         }
3563
3564         int ret = MM_ERROR_NONE;
3565         camera_s *handle = (camera_s *)camera;
3566         MMCamAttrsInfo info;
3567         int width = 0;
3568         int height = 0;
3569         int i = 0;
3570
3571         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3572                                           MMCAM_CAMERA_WIDTH, &width,
3573                                           MMCAM_CAMERA_HEIGHT, &height,
3574                                           NULL);
3575         if (ret != MM_ERROR_NONE) {
3576                 return __convert_camera_error_code(__func__, ret);
3577         }
3578
3579         ret = mm_camcorder_get_fps_list_by_resolution(handle->mm_handle, width, height, &info);
3580         if (ret != MM_ERROR_NONE) {
3581                 return __convert_camera_error_code(__func__, ret);
3582         }
3583
3584         for (i = 0 ; i < info.int_array.count ; i++) {
3585                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3586                         break;
3587                 }
3588         }
3589
3590         return CAMERA_ERROR_NONE;
3591 }
3592
3593
3594 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)
3595 {
3596         if (camera == NULL || foreach_cb == NULL) {
3597                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3598                 return CAMERA_ERROR_INVALID_PARAMETER;
3599         }
3600
3601         int ret = MM_ERROR_NONE;
3602         camera_s *handle = (camera_s *)camera;
3603         MMCamAttrsInfo info;
3604         int i = 0;
3605
3606         ret = mm_camcorder_get_fps_list_by_resolution(handle->mm_handle, width, height, &info);
3607         if (ret != MM_ERROR_NONE) {
3608                 return __convert_camera_error_code(__func__, ret);
3609         }
3610
3611         for (i = 0 ; i < info.int_array.count ; i++) {
3612                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3613                         break;
3614                 }
3615         }
3616
3617         return CAMERA_ERROR_NONE;
3618 }
3619
3620
3621 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
3622 {
3623         if (camera == NULL || foreach_cb == NULL) {
3624                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3625                 return CAMERA_ERROR_INVALID_PARAMETER;
3626         }
3627
3628         int i = 0;
3629         int ret = MM_ERROR_NONE;
3630         camera_s *handle = (camera_s *)camera;
3631         MMCamAttrsInfo info;
3632
3633         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FLIP, &info);
3634         if (ret != MM_ERROR_NONE) {
3635                 return __convert_camera_error_code(__func__, ret);
3636         }
3637
3638         for (i = 0 ; i < info.int_array.count ; i++) {
3639                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3640                         break;
3641                 }
3642         }
3643
3644         return CAMERA_ERROR_NONE;
3645 }
3646
3647
3648 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
3649 {
3650         if (camera == NULL || foreach_cb == NULL) {
3651                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3652                 return CAMERA_ERROR_INVALID_PARAMETER;
3653         }
3654
3655         int i = 0;
3656         int ret = MM_ERROR_NONE;
3657         camera_s *handle = (camera_s *)camera;
3658         MMCamAttrsInfo info;
3659
3660         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ROTATION, &info);
3661         if (ret != MM_ERROR_NONE) {
3662                 return __convert_camera_error_code(__func__, ret);
3663         }
3664
3665         for (i = 0 ; i < info.int_array.count ; i++) {
3666                 if (!foreach_cb(info.int_array.array[i], user_data)) {
3667                         break;
3668                 }
3669         }
3670
3671         return CAMERA_ERROR_NONE;
3672 }
3673
3674
3675 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
3676 {
3677         if (camera == NULL) {
3678                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3679                 return CAMERA_ERROR_INVALID_PARAMETER;
3680         }
3681
3682         if (rotation < CAMERA_ROTATION_NONE || rotation > CAMERA_ROTATION_270) {
3683                 LOGE("INVALID_PARAMETER - %d", rotation);
3684                 return CAMERA_ERROR_INVALID_PARAMETER;
3685         }
3686
3687         int ret = MM_ERROR_NONE;
3688         camera_s *handle = (camera_s *)camera;
3689
3690         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
3691                                           MMCAM_CAMERA_ROTATION, rotation,
3692                                           NULL);
3693
3694         return __convert_camera_error_code(__func__, ret);
3695 }
3696
3697
3698 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
3699 {
3700         if (camera == NULL || rotation == NULL) {
3701                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3702                 return CAMERA_ERROR_INVALID_PARAMETER;
3703         }
3704
3705         int ret = MM_ERROR_NONE;
3706         camera_s *handle = (camera_s *)camera;
3707
3708         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3709                                           MMCAM_CAMERA_ROTATION, rotation,
3710                                           NULL);
3711
3712         return __convert_camera_error_code(__func__, ret);
3713 }
3714
3715
3716 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
3717 {
3718         if (camera == NULL) {
3719                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3720                 return CAMERA_ERROR_INVALID_PARAMETER;
3721         }
3722
3723         if (flip < CAMERA_FLIP_NONE || flip > CAMERA_FLIP_BOTH) {
3724                 LOGE("INVALID_PARAMETER - %d", flip);
3725                 return CAMERA_ERROR_INVALID_PARAMETER;
3726         }
3727
3728         int ret = MM_ERROR_NONE;
3729         camera_s *handle = (camera_s *)camera;
3730
3731         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
3732                                           MMCAM_CAMERA_FLIP, flip,
3733                                           NULL);
3734
3735         return __convert_camera_error_code(__func__, ret);
3736 }
3737
3738
3739 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
3740 {
3741         if (camera == NULL || flip == NULL) {
3742                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3743                 return CAMERA_ERROR_INVALID_PARAMETER;
3744         }
3745
3746         int ret = MM_ERROR_NONE;
3747         camera_s *handle = (camera_s *)camera;
3748
3749         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
3750                                           MMCAM_CAMERA_FLIP, flip,
3751                                           NULL);
3752
3753         return __convert_camera_error_code(__func__, ret);
3754 }
3755
3756
3757 int _camera_set_use(camera_h camera, bool used)
3758 {
3759         camera_s *handle = (camera_s *)camera;
3760
3761         if (handle == NULL) {
3762                 LOGE("handle is NULL");
3763                 return CAMERA_ERROR_INVALID_PARAMETER;
3764         }
3765
3766         handle->is_used_in_recorder = used;
3767
3768         return CAMERA_ERROR_NONE;
3769 }
3770
3771
3772 bool _camera_is_used(camera_h camera)
3773 {
3774         camera_s *handle = (camera_s *)camera;
3775
3776         if (handle == NULL) {
3777                 LOGE("handle is NULL");
3778                 return false;
3779         }
3780
3781         return handle->is_used_in_recorder;
3782 }
3783
3784
3785 int _camera_get_mm_handle(camera_h camera, MMHandleType *handle)
3786 {
3787         if (camera == NULL || handle == NULL) {
3788                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3789                 return CAMERA_ERROR_INVALID_PARAMETER;
3790         }
3791
3792         camera_s *camera_handle = (camera_s*)camera;
3793
3794         *handle =  camera_handle->mm_handle;
3795
3796         return CAMERA_ERROR_NONE;
3797 }
3798
3799
3800 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data)
3801 {
3802         if( camera == NULL ){
3803                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3804                 return CAMERA_ERROR_INVALID_PARAMETER;
3805         }
3806
3807         camera_s *handle = (camera_s *)camera;
3808         handle->relay_message_callback = callback;
3809         handle->relay_user_data = user_data;
3810
3811         return CAMERA_ERROR_NONE;
3812 }
3813
3814
3815 int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format)
3816 {
3817         if (in_format <= MM_PIXEL_FORMAT_INVALID ||
3818             in_format >= MM_PIXEL_FORMAT_NUM ||
3819             out_format == NULL) {
3820                 LOGE("INVALID_PARAMETER : in_format %d, out_format ptr %p", in_format, out_format);
3821                 return CAMERA_ERROR_INVALID_PARAMETER;
3822         }
3823
3824         switch (in_format) {
3825         case MM_PIXEL_FORMAT_NV12:
3826         case MM_PIXEL_FORMAT_NV12T:
3827                 *out_format = TBM_FORMAT_NV12;
3828                 break;
3829         case MM_PIXEL_FORMAT_NV16:
3830                 *out_format = TBM_FORMAT_NV16;
3831                 break;
3832         case MM_PIXEL_FORMAT_NV21:
3833                 *out_format = TBM_FORMAT_NV21;
3834                 break;
3835         case MM_PIXEL_FORMAT_YUYV:
3836                 *out_format = TBM_FORMAT_YUYV;
3837                 break;
3838         case MM_PIXEL_FORMAT_UYVY:
3839         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
3840                 *out_format = TBM_FORMAT_UYVY;
3841                 break;
3842         case MM_PIXEL_FORMAT_422P:
3843                 *out_format = TBM_FORMAT_YUV422;
3844                 break;
3845         case MM_PIXEL_FORMAT_I420:
3846                 *out_format = TBM_FORMAT_YUV420;
3847                 break;
3848         case MM_PIXEL_FORMAT_YV12:
3849                 *out_format = TBM_FORMAT_YVU420;
3850                 break;
3851         case MM_PIXEL_FORMAT_RGB565:
3852                 *out_format = TBM_FORMAT_RGB565;
3853                 break;
3854         case MM_PIXEL_FORMAT_RGB888:
3855                 *out_format = TBM_FORMAT_RGB888;
3856                 break;
3857         case MM_PIXEL_FORMAT_RGBA:
3858                 *out_format = TBM_FORMAT_RGBA8888;
3859                 break;
3860         case MM_PIXEL_FORMAT_ARGB:
3861                 *out_format = TBM_FORMAT_ARGB8888;
3862                 break;
3863         default:
3864                 LOGE("invalid in_format %d", in_format);
3865                 return CAMERA_ERROR_INVALID_PARAMETER;
3866         }
3867
3868         return CAMERA_ERROR_NONE;
3869 }
3870
3871
3872 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype)
3873 {
3874         if (in_format <= MM_PIXEL_FORMAT_INVALID ||
3875             in_format >= MM_PIXEL_FORMAT_NUM ||
3876             mimetype == NULL) {
3877                 LOGE("INVALID_PARAMETER : in_format %d, mimetype ptr %p", in_format, mimetype);
3878                 return CAMERA_ERROR_INVALID_PARAMETER;
3879         }
3880
3881         switch (in_format) {
3882         case MM_PIXEL_FORMAT_NV12:
3883         case MM_PIXEL_FORMAT_NV12T:
3884                 *mimetype = MEDIA_FORMAT_NV12;
3885                 break;
3886         case MM_PIXEL_FORMAT_NV16:
3887                 *mimetype = MEDIA_FORMAT_NV16;
3888                 break;
3889         case MM_PIXEL_FORMAT_NV21:
3890                 *mimetype = MEDIA_FORMAT_NV21;
3891                 break;
3892         case MM_PIXEL_FORMAT_YUYV:
3893                 *mimetype = MEDIA_FORMAT_YUYV;
3894                 break;
3895         case MM_PIXEL_FORMAT_UYVY:
3896         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
3897                 *mimetype = MEDIA_FORMAT_UYVY;
3898                 break;
3899         case MM_PIXEL_FORMAT_422P:
3900                 *mimetype = MEDIA_FORMAT_422P;
3901                 break;
3902         case MM_PIXEL_FORMAT_I420:
3903                 *mimetype = MEDIA_FORMAT_I420;
3904                 break;
3905         case MM_PIXEL_FORMAT_YV12:
3906                 *mimetype = MEDIA_FORMAT_YV12;
3907                 break;
3908         case MM_PIXEL_FORMAT_RGB565:
3909                 *mimetype = MEDIA_FORMAT_RGB565;
3910                 break;
3911         case MM_PIXEL_FORMAT_RGB888:
3912                 *mimetype = MEDIA_FORMAT_RGB888;
3913                 break;
3914         case MM_PIXEL_FORMAT_RGBA:
3915                 *mimetype = MEDIA_FORMAT_RGBA;
3916                 break;
3917         case MM_PIXEL_FORMAT_ARGB:
3918                 *mimetype = MEDIA_FORMAT_ARGB;
3919                 break;
3920         default:
3921                 LOGE("invalid in_format %d", in_format);
3922                 return CAMERA_ERROR_INVALID_PARAMETER;
3923         }
3924
3925         return CAMERA_ERROR_NONE;
3926 }
3927
3928
3929 int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
3930 {
3931         int ret = 0;
3932         void *internal_buffer = NULL;
3933         tbm_surface_h tsurf = NULL;
3934
3935         if (pkt == NULL || user_data == NULL) {
3936                 LOGE("invalid parameter buffer %p, user_data %p", pkt, user_data);
3937                 return MEDIA_PACKET_FINALIZE;
3938         }
3939
3940         ret = media_packet_get_extra(pkt, &internal_buffer);
3941         if (ret != MEDIA_PACKET_ERROR_NONE) {
3942                 LOGE("media_packet_get_extra failed 0x%x", ret);
3943                 return MEDIA_PACKET_FINALIZE;
3944         }
3945
3946         /*LOGD("pointer gst buffer %p, ret 0x%x", internal_buffer, ret);*/
3947
3948         if (internal_buffer) {
3949                 gst_buffer_unref((GstBuffer *)internal_buffer);
3950                 internal_buffer = NULL;
3951         }
3952
3953         ret = media_packet_get_tbm_surface(pkt, &tsurf);
3954         if (ret != MEDIA_PACKET_ERROR_NONE) {
3955                 LOGE("media_packet_get_tbm_surface failed 0x%x", ret);
3956                 return MEDIA_PACKET_FINALIZE;
3957         }
3958
3959         if (tsurf) {
3960                 tbm_surface_destroy(tsurf);
3961                 tsurf = NULL;
3962         }
3963
3964         return MEDIA_PACKET_FINALIZE;
3965 }
3966
3967
3968 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
3969 {
3970         if (camera == NULL) {
3971                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
3972                 return CAMERA_ERROR_INVALID_PARAMETER;
3973         }
3974
3975         if (camera_attr_is_supported_hdr_capture(camera) == false) {
3976                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
3977                 return CAMERA_ERROR_NOT_SUPPORTED;
3978         }
3979
3980         int ret = MM_ERROR_NONE;
3981         camera_s *handle = (camera_s *)camera;
3982
3983         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
3984                                           MMCAM_CAMERA_HDR_CAPTURE, mode,
3985                                           NULL);
3986
3987         if (ret == MM_ERROR_NONE) {
3988                 if (mode == CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL) {
3989                         handle->hdr_keep_mode = true;
3990                 } else {
3991                         handle->hdr_keep_mode = false;
3992                 }
3993         }
3994
3995         return __convert_camera_error_code(__func__, ret);
3996 }
3997
3998
3999 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
4000 {
4001         if (camera == NULL) {
4002                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
4003                 return CAMERA_ERROR_INVALID_PARAMETER;
4004         }
4005
4006         if (camera_attr_is_supported_hdr_capture(camera) == false) {
4007                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4008                 return CAMERA_ERROR_NOT_SUPPORTED;
4009         }
4010
4011         if (mode == NULL) {
4012                 LOGE("INVALID_PARAMETER(0x%08x) - mode", CAMERA_ERROR_INVALID_PARAMETER);
4013                 return CAMERA_ERROR_INVALID_PARAMETER;
4014         }
4015
4016         int ret = MM_ERROR_NONE;
4017         camera_s *handle = (camera_s *)camera;
4018
4019         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
4020                                           MMCAM_CAMERA_HDR_CAPTURE, mode,
4021                                           NULL);
4022
4023         return __convert_camera_error_code(__func__, ret);
4024 }
4025
4026
4027 bool camera_attr_is_supported_hdr_capture(camera_h camera)
4028 {
4029         if (camera == NULL) {
4030                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4031                 return false;
4032         }
4033
4034         int ret = MM_ERROR_NONE;
4035         int i = 0;
4036         camera_s *handle = (camera_s *)camera;
4037         MMCamAttrsInfo hdr_info;
4038
4039         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HDR_CAPTURE, &hdr_info);
4040         set_last_result(__convert_camera_error_code(__func__, ret));
4041         if (ret != MM_ERROR_NONE) {
4042                 LOGE("MMCAM_CAMERA_HDR_CAPTURE get attr info failed");
4043                 return false;
4044         }
4045
4046         for (i = 0; i < hdr_info.int_array.count ; i++) {
4047                 if (hdr_info.int_array.array[i] >= MM_CAMCORDER_HDR_ON) {
4048                         LOGD("HDR capture supported");
4049                         return true;
4050                 }
4051         }
4052
4053         LOGD("HDR capture NOT supported");
4054
4055         return false;
4056 }
4057
4058
4059 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
4060 {
4061         if (camera == NULL) {
4062                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
4063                 return CAMERA_ERROR_INVALID_PARAMETER;
4064         }
4065
4066         if (camera_attr_is_supported_hdr_capture(camera) == false) {
4067                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4068                 return CAMERA_ERROR_NOT_SUPPORTED;
4069         }
4070
4071         if (callback == NULL) {
4072                 LOGE("INVALID_PARAMETER(0x%08x) - callback", CAMERA_ERROR_INVALID_PARAMETER);
4073                 return CAMERA_ERROR_INVALID_PARAMETER;
4074         }
4075
4076         camera_s *handle = (camera_s *)camera;
4077
4078         handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)callback;
4079         handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)user_data;
4080
4081         return CAMERA_ERROR_NONE;
4082 }
4083
4084
4085 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
4086 {
4087         if (camera == NULL) {
4088                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4089                 return CAMERA_ERROR_INVALID_PARAMETER;
4090         }
4091
4092         if (camera_attr_is_supported_hdr_capture(camera) == false) {
4093                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4094                 return CAMERA_ERROR_NOT_SUPPORTED;
4095         }
4096
4097         camera_s *handle = (camera_s *)camera;
4098
4099         handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)NULL;
4100         handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)NULL;
4101
4102         return CAMERA_ERROR_NONE;
4103 }
4104
4105
4106 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
4107 {
4108         if (camera == NULL) {
4109                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4110                 return CAMERA_ERROR_INVALID_PARAMETER;
4111         }
4112
4113         if (camera_attr_is_supported_anti_shake(camera) == false) {
4114                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4115                 return CAMERA_ERROR_NOT_SUPPORTED;
4116         }
4117
4118         int ret = MM_ERROR_NONE;
4119         int mode = MM_CAMCORDER_AHS_OFF;
4120         camera_s *handle = (camera_s *)camera;
4121
4122         if (enable) {
4123                 mode = MM_CAMCORDER_AHS_ON;
4124         }
4125
4126         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
4127                                           MMCAM_CAMERA_ANTI_HANDSHAKE, mode,
4128                                           NULL);
4129
4130         return __convert_camera_error_code(__func__, ret);
4131 }
4132
4133
4134 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
4135 {
4136         if (camera == NULL) {
4137                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
4138                 return CAMERA_ERROR_INVALID_PARAMETER;
4139         }
4140
4141         if (camera_attr_is_supported_anti_shake(camera) == false) {
4142                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4143                 return CAMERA_ERROR_NOT_SUPPORTED;
4144         }
4145
4146         if (enabled == NULL) {
4147                 LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER);
4148                 return CAMERA_ERROR_INVALID_PARAMETER;
4149         }
4150
4151         int ret = MM_ERROR_NONE;
4152         camera_s *handle = (camera_s *)camera;
4153
4154         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
4155                                           MMCAM_CAMERA_ANTI_HANDSHAKE, enabled,
4156                                           NULL);
4157
4158         return __convert_camera_error_code(__func__, ret);
4159 }
4160
4161
4162 bool camera_attr_is_supported_anti_shake(camera_h camera)
4163 {
4164         if (camera == NULL) {
4165                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4166                 return false;
4167         }
4168
4169         int i = 0;
4170         int ret = MM_ERROR_NONE;
4171         camera_s *handle = (camera_s *)camera;
4172         MMCamAttrsInfo ash_info;
4173
4174         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ANTI_HANDSHAKE, &ash_info);
4175         set_last_result(__convert_camera_error_code(__func__, ret));
4176         if (ret != MM_ERROR_NONE) {
4177                 LOGE("MMCAM_CAMERA_ANTI_HANDSHAKE get attr info failed");
4178                 return false;
4179         }
4180
4181         for (i = 0 ; i < ash_info.int_array.count ; i++) {
4182                 if (ash_info.int_array.array[i] == MM_CAMCORDER_AHS_ON) {
4183                         return true;
4184                 }
4185         }
4186
4187         return false;
4188 }
4189
4190
4191 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
4192 {
4193         if (camera == NULL) {
4194                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4195                 return CAMERA_ERROR_INVALID_PARAMETER;
4196         }
4197
4198         if (camera_attr_is_supported_video_stabilization(camera) == false) {
4199                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4200                 return CAMERA_ERROR_NOT_SUPPORTED;
4201         }
4202
4203         int ret = MM_ERROR_NONE;
4204         int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF;
4205         camera_s *handle = (camera_s*)camera;
4206
4207         if (enable) {
4208                 mode = MM_CAMCORDER_VIDEO_STABILIZATION_ON;
4209         }
4210
4211         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
4212                                           MMCAM_CAMERA_VIDEO_STABILIZATION, mode,
4213                                           NULL);
4214
4215         return __convert_camera_error_code(__func__, ret);
4216 }
4217
4218
4219 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
4220 {
4221         if (camera == NULL) {
4222                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
4223                 return CAMERA_ERROR_INVALID_PARAMETER;
4224         }
4225
4226         if (camera_attr_is_supported_video_stabilization(camera) == false) {
4227                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4228                 return CAMERA_ERROR_NOT_SUPPORTED;
4229         }
4230
4231         if (enabled == NULL) {
4232                 LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER);
4233                 return CAMERA_ERROR_INVALID_PARAMETER;
4234         }
4235
4236         int ret = MM_ERROR_NONE;
4237         int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF;
4238         camera_s *handle = (camera_s *)camera;
4239
4240         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
4241                                           MMCAM_CAMERA_VIDEO_STABILIZATION, &mode,
4242                                           NULL);
4243         if (ret == MM_ERROR_NONE) {
4244                 *enabled = (mode == MM_CAMCORDER_VIDEO_STABILIZATION_ON);
4245         }
4246
4247         return __convert_camera_error_code(__func__, ret);
4248 }
4249
4250
4251 bool camera_attr_is_supported_video_stabilization(camera_h camera)
4252 {
4253         if (camera == NULL) {
4254                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4255                 return false;
4256         }
4257
4258         int i = 0;
4259         int ret = MM_ERROR_NONE;
4260         camera_s *handle = (camera_s *)camera;
4261         MMCamAttrsInfo vs_info;
4262
4263         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_VIDEO_STABILIZATION, &vs_info);
4264         set_last_result(__convert_camera_error_code(__func__, ret));
4265         if (ret != MM_ERROR_NONE) {
4266                 LOGE("MMCAM_CAMERA_VIDEO_STABILIZATION get attr info failed");
4267                 return false;
4268         }
4269
4270         for (i = 0 ; i < vs_info.int_array.count ; i++) {
4271                 if (vs_info.int_array.array[i] == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
4272                         return true;
4273                 }
4274         }
4275
4276         return false;
4277 }
4278
4279
4280 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
4281 {
4282         if (camera == NULL) {
4283                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4284                 return CAMERA_ERROR_INVALID_PARAMETER;
4285         }
4286
4287         if (camera_attr_is_supported_auto_contrast(camera) == false) {
4288                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4289                 return CAMERA_ERROR_NOT_SUPPORTED;
4290         }
4291
4292         int ret = MM_ERROR_NONE;
4293         int mode = MM_CAMCORDER_WDR_OFF;
4294         camera_s *handle = (camera_s *)camera;
4295
4296         if (enable) {
4297                 mode = MM_CAMCORDER_WDR_ON;
4298         }
4299
4300         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
4301                                           MMCAM_CAMERA_WDR, mode,
4302                                           NULL);
4303
4304         return __convert_camera_error_code(__func__, ret);
4305 }
4306
4307
4308 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
4309 {
4310         if (camera == NULL) {
4311                 LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER);
4312                 return CAMERA_ERROR_INVALID_PARAMETER;
4313         }
4314
4315         if (camera_attr_is_supported_auto_contrast(camera) == false) {
4316                 LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED);
4317                 return CAMERA_ERROR_NOT_SUPPORTED;
4318         }
4319
4320         if (enabled == NULL) {
4321                 LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER);
4322                 return CAMERA_ERROR_INVALID_PARAMETER;
4323         }
4324
4325         int ret = MM_ERROR_NONE;
4326         int mode = MM_CAMCORDER_WDR_OFF;
4327         camera_s *handle = (camera_s *)camera;
4328
4329         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
4330                                           MMCAM_CAMERA_WDR, &mode,
4331                                           NULL);
4332
4333         if (ret == MM_ERROR_NONE) {
4334                 *enabled = mode;
4335         }
4336
4337         return __convert_camera_error_code(__func__, ret);
4338 }
4339
4340
4341 bool camera_attr_is_supported_auto_contrast(camera_h camera)
4342 {
4343         if (camera == NULL) {
4344                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4345                 return false;
4346         }
4347
4348         int i = 0;
4349         int ret = MM_ERROR_NONE;
4350         camera_s *handle = (camera_s *)camera;
4351         MMCamAttrsInfo info;
4352
4353         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WDR, &info);
4354         set_last_result(__convert_camera_error_code(__func__, ret));
4355         if (ret != MM_ERROR_NONE) {
4356                 LOGE("MMCAM_CAMERA_WDR get attr info failed");
4357                 return false;
4358         }
4359
4360         for (i = 0 ; i < info.int_array.count ; i++) {
4361                 if (info.int_array.array[i] == MM_CAMCORDER_WDR_ON) {
4362                         return true;
4363                 }
4364         }
4365
4366         return false;
4367 }
4368
4369
4370 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
4371 {
4372         if (camera == NULL) {
4373                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
4374                 return CAMERA_ERROR_INVALID_PARAMETER;
4375         }
4376
4377         int ret = MM_ERROR_NONE;
4378         camera_s *handle = (camera_s *)camera;
4379
4380         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
4381                                           "capture-sound-enable", !disable,
4382                                           NULL);
4383         if (ret != MM_ERROR_NONE) {
4384                 LOGE("CAMERA_ERROR_INVALID_OPERATION : not permitted disable shutter sound");
4385                 return CAMERA_ERROR_INVALID_OPERATION;
4386         }
4387
4388         return CAMERA_ERROR_NONE;
4389 }