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