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