Clean up the Makefiles, Add some descriptions
[platform/core/multimedia/mmsvc-recorder.git] / legacy / src / legacy_recorder.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
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mm.h>
23 #include <audio-session-manager-types.h>
24 #include <mm_camcorder.h>
25 #include <mm_types.h>
26 #include <math.h>
27 #include <legacy_camera.h>
28 #include <legacy_recorder_private.h>
29 #include <dlog.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <fcntl.h>
33
34 #ifdef LOG_TAG
35 #undef LOG_TAG
36 #endif
37 #define LOG_TAG "TIZEN_N_RECORDER"
38
39 #define LOWSET_DECIBEL -300.0
40 #define RECORDER_PATH_RECORDER_RESOURCE    "/usr/share/sounds/mm-camcorder/recorder_resource"
41
42
43 /*
44  * camera_private function
45 */
46 int _camera_get_mm_handle(camera_h camera , MMHandleType *handle);
47 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data);
48 int _camera_set_use(camera_h camera, bool used);
49 bool _camera_is_used(camera_h camera);
50 /*
51  * end of camera_private function
52  */
53
54 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param);
55 static int __mm_recorder_msg_cb(int message, void *param, void *user_data);
56
57
58 static int __convert_error_code_camera_to_recorder(int code)
59 {
60         int new_code = code;
61
62         switch (code) {
63         case CAMERA_ERROR_INVALID_STATE :
64                 new_code = RECORDER_ERROR_INVALID_STATE;
65                 break;
66         case CAMERA_ERROR_DEVICE:
67                 new_code = RECORDER_ERROR_DEVICE;
68                 break;
69         case CAMERA_ERROR_SOUND_POLICY:
70                 new_code = RECORDER_ERROR_SOUND_POLICY;
71                 break;
72         case CAMERA_ERROR_SECURITY_RESTRICTED:
73                 new_code = RECORDER_ERROR_SECURITY_RESTRICTED;
74                 break;
75         default:
76                 break;
77         }
78
79         return new_code;
80 }
81
82
83 int __convert_recorder_error_code(const char *func, int code)
84 {
85         int ret = RECORDER_ERROR_INVALID_OPERATION;
86         const char *errorstr = NULL;
87
88         switch (code) {
89         case RECORDER_ERROR_INVALID_PARAMETER:
90                 ret = RECORDER_ERROR_INVALID_PARAMETER;
91                 errorstr = "INVALID_PARAMETER";
92                 break;
93         case MM_ERROR_NONE:
94                 ret = RECORDER_ERROR_NONE;
95                 errorstr = "ERROR_NONE";
96                 break;
97         case MM_ERROR_CAMCORDER_INVALID_ARGUMENT :
98         case MM_ERROR_COMMON_INVALID_ATTRTYPE :
99                 ret = RECORDER_ERROR_INVALID_PARAMETER;
100                 errorstr = "INVALID_PARAMETER";
101                 break;
102         case MM_ERROR_COMMON_INVALID_PERMISSION :
103                 ret = RECORDER_ERROR_PERMISSION_DENIED;
104                 errorstr = "ERROR_PERMISSION_DENIED";
105                 break;
106         case MM_ERROR_CAMCORDER_NOT_INITIALIZED :
107         case MM_ERROR_CAMCORDER_INVALID_STATE :
108                 ret = RECORDER_ERROR_INVALID_STATE;
109                 errorstr = "INVALID_STATE";
110                 break;
111         case MM_ERROR_CAMCORDER_DEVICE :
112         case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND :
113         case MM_ERROR_CAMCORDER_DEVICE_BUSY :
114         case MM_ERROR_CAMCORDER_DEVICE_OPEN :
115         case MM_ERROR_CAMCORDER_DEVICE_IO :
116         case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT :
117         case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG :
118         case MM_ERROR_CAMCORDER_DEVICE_LACK_BUFFER :
119                 ret = RECORDER_ERROR_DEVICE;
120                 errorstr = "ERROR_DEVICE";
121                 break;
122         case MM_ERROR_CAMCORDER_GST_CORE :
123         case MM_ERROR_CAMCORDER_GST_LIBRARY :
124         case MM_ERROR_CAMCORDER_GST_RESOURCE :
125         case MM_ERROR_CAMCORDER_GST_STREAM :
126         case MM_ERROR_CAMCORDER_GST_STATECHANGE :
127         case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
128         case MM_ERROR_CAMCORDER_GST_LINK :
129         case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
130         case MM_ERROR_CAMCORDER_ENCODER :
131         case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
132         case MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE :
133         case MM_ERROR_CAMCORDER_ENCODER_WORKING :
134         case MM_ERROR_CAMCORDER_INTERNAL :
135         case MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT :
136         case MM_ERROR_CAMCORDER_CMD_IS_RUNNING :
137         case MM_ERROR_CAMCORDER_DSP_FAIL :
138         case MM_ERROR_CAMCORDER_AUDIO_EMPTY :
139         case MM_ERROR_CAMCORDER_CREATE_CONFIGURE :
140         case MM_ERROR_CAMCORDER_FILE_SIZE_OVER :
141         case MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF :
142         case MM_ERROR_CAMCORDER_INVALID_CONDITION :
143                 ret = RECORDER_ERROR_INVALID_OPERATION;
144                 errorstr = "INVALID_OPERATION";
145                 break;
146         case MM_ERROR_CAMCORDER_RESOURCE_CREATION :
147         case MM_ERROR_COMMON_OUT_OF_MEMORY:
148                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
149                 errorstr = "OUT_OF_MEMORY";
150                 break;
151         case MM_ERROR_POLICY_BLOCKED:
152                 ret = RECORDER_ERROR_SOUND_POLICY;
153                 errorstr = "ERROR_SOUND_POLICY";
154                 break;
155         case MM_ERROR_POLICY_BLOCKED_BY_CALL:
156                 ret = RECORDER_ERROR_SOUND_POLICY_BY_CALL;
157                 errorstr = "ERROR_SOUND_POLICY_BY_CALL";
158                 break;
159         case MM_ERROR_POLICY_BLOCKED_BY_ALARM:
160                 ret = RECORDER_ERROR_SOUND_POLICY_BY_ALARM;
161                 errorstr = "ERROR_SOUND_POLICY_BY_ALARM";
162                 break;
163         case MM_ERROR_POLICY_RESTRICTED:
164                 ret = RECORDER_ERROR_SECURITY_RESTRICTED;
165                 errorstr = "ERROR_RESTRICTED";
166                 break;
167         case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
168                 ret = RECORDER_ERROR_ESD;
169                 errorstr = "ERROR_ESD";
170                 break;
171         case MM_ERROR_OUT_OF_STORAGE:
172                 ret = RECORDER_ERROR_OUT_OF_STORAGE;
173                 errorstr = "OUT_OF_STORAGE";
174                 break;
175         case MM_ERROR_COMMON_OUT_OF_ARRAY:
176         case MM_ERROR_COMMON_OUT_OF_RANGE:
177         case MM_ERROR_COMMON_ATTR_NOT_EXIST:
178         case MM_ERROR_CAMCORDER_NOT_SUPPORTED:
179                 ret = RECORDER_ERROR_NOT_SUPPORTED;
180                 errorstr = "NOT_SUPPORTED";
181                 break;
182         default:
183                 ret = RECORDER_ERROR_INVALID_OPERATION;
184                 errorstr = "INVALID_OPERATION";
185                 break;
186         }
187
188         LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code);
189
190         return ret;
191 }
192
193
194 static recorder_state_e __recorder_state_convert(MMCamcorderStateType mm_state)
195 {
196         recorder_state_e state = RECORDER_STATE_NONE;
197         switch (mm_state) {
198         case MM_CAMCORDER_STATE_NONE:
199                 state = RECORDER_STATE_NONE;
200                 break;
201         case MM_CAMCORDER_STATE_NULL:
202                 state = RECORDER_STATE_CREATED;
203                 break;
204         case MM_CAMCORDER_STATE_READY:
205                 state = RECORDER_STATE_CREATED;
206                 break;
207         case MM_CAMCORDER_STATE_PREPARE:
208                 state = RECORDER_STATE_READY;
209                 break;
210         case MM_CAMCORDER_STATE_CAPTURING:
211                 state = RECORDER_STATE_READY;
212                 break;
213         case MM_CAMCORDER_STATE_RECORDING:
214                 state = RECORDER_STATE_RECORDING;
215                 break;
216         case MM_CAMCORDER_STATE_PAUSED:
217                 state = RECORDER_STATE_PAUSED;
218                 break;
219         default:
220                 state = RECORDER_STATE_NONE;
221                 break;
222         }
223
224         return state;
225 }
226
227
228 static int __mm_recorder_msg_cb(int message, void *param, void *user_data)
229 {
230         recorder_s * handle = (recorder_s *)user_data;
231         MMMessageParamType *m = (MMMessageParamType *)param;
232         recorder_state_e previous_state;
233         recorder_recording_limit_type_e type;
234         int recorder_error = 0;
235
236         switch (message) {
237         case MM_MESSAGE_READY_TO_RESUME:
238                 LOGW("not supported message");
239                 break;
240         case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
241         case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
242         case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY:
243                 previous_state = handle->state;
244                 handle->state = __recorder_state_convert(m->state.current);
245                 recorder_policy_e policy = RECORDER_POLICY_NONE;
246                 if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM) {
247                         switch (m->state.code) {
248                         case ASM_EVENT_SOURCE_CALL_START:
249                         case ASM_EVENT_SOURCE_CALL_END:
250                                 policy = RECORDER_POLICY_SOUND_BY_CALL;
251                                 LOGE("RECORDER_POLICY_SOUND_BY_CALL");
252                                 break;
253                         case ASM_EVENT_SOURCE_ALARM_START:
254                         case ASM_EVENT_SOURCE_ALARM_END:
255                                 policy = RECORDER_POLICY_SOUND_BY_ALARM;
256                                 LOGE("RECORDER_POLICY_SOUND_BY_ALARM");
257                                 break;
258                         default:
259                                 policy = RECORDER_POLICY_SOUND;
260                                 LOGE("RECORDER_POLICY_SOUND");
261                                 break;
262                         }
263                 } else if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY) {
264                         policy = RECORDER_POLICY_SECURITY;
265                         LOGE("RECORDER_POLICY_SECURITY");
266                 }
267
268                 if (previous_state != handle->state && handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE]) {
269                         ((recorder_state_changed_cb)handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state, policy, handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE]);
270                 }
271
272                 /* should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state */
273                 if (policy != RECORDER_POLICY_NONE &&
274                     (m->state.current == MM_CAMCORDER_STATE_PAUSED || m->state.current == MM_CAMCORDER_STATE_NULL)) {
275                         if (handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED]) {
276                                 ((recorder_interrupted_cb)handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED]);
277                         } else {
278                                 LOGW("_RECORDER_EVENT_TYPE_INTERRUPTED cb is NULL");
279                         }
280                 }
281                 break;
282         case MM_MESSAGE_CAMCORDER_MAX_SIZE:
283         case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
284         case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
285                 if (MM_MESSAGE_CAMCORDER_MAX_SIZE == message) {
286                         type = RECORDER_RECORDING_LIMIT_SIZE;
287                 } else if (MM_MESSAGE_CAMCORDER_NO_FREE_SPACE == message) {
288                         type = RECORDER_RECORDING_LIMIT_FREE_SPACE;
289                 } else {
290                         type = RECORDER_RECORDING_LIMIT_TIME;
291                 }
292                 if (handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]) {
293                         ((recorder_recording_limit_reached_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED])(type, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
294                 }
295                 break;
296         case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
297                 if (handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS]) {
298                         ((recorder_recording_status_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS])(m->recording_status.elapsed, m->recording_status.filesize, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
299                 }
300                 break;
301         case MM_MESSAGE_CAMCORDER_ERROR:
302                 switch (m->code) {
303                 case MM_ERROR_CAMCORDER_DEVICE:
304                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT:
305                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG:
306                         recorder_error = RECORDER_ERROR_DEVICE;
307                         break;
308                 case MM_ERROR_CAMCORDER_GST_CORE:
309                 case MM_ERROR_CAMCORDER_GST_LIBRARY:
310                 case MM_ERROR_CAMCORDER_GST_RESOURCE:
311                 case MM_ERROR_CAMCORDER_GST_STREAM:
312                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION:
313                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR:
314                 case MM_ERROR_CAMCORDER_ENCODER:
315                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER:
316                 case MM_ERROR_CAMCORDER_ENCODER_WORKING:
317                 case MM_ERROR_CAMCORDER_MNOTE_CREATION:
318                 case MM_ERROR_CAMCORDER_MNOTE_ADD_ENTRY:
319                 case MM_ERROR_CAMCORDER_INTERNAL:
320                 case MM_ERROR_FILE_NOT_FOUND:
321                 case MM_ERROR_FILE_READ:
322                         recorder_error = RECORDER_ERROR_INVALID_OPERATION;
323                         break;
324                 case MM_ERROR_CAMCORDER_LOW_MEMORY:
325                 case MM_ERROR_CAMCORDER_MNOTE_MALLOC:
326                         recorder_error = RECORDER_ERROR_OUT_OF_MEMORY;
327                         break;
328                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
329                         recorder_error = RECORDER_ERROR_ESD;
330                         break;
331                 case MM_ERROR_OUT_OF_STORAGE:
332                         recorder_error = RECORDER_ERROR_OUT_OF_STORAGE;
333                         break;
334                 default:
335                         recorder_error = RECORDER_ERROR_INVALID_OPERATION;
336                         break;
337                 }
338
339                 if (recorder_error != 0 && handle->user_cb[_RECORDER_EVENT_TYPE_ERROR]) {
340                         ((recorder_error_cb)handle->user_cb[_RECORDER_EVENT_TYPE_ERROR])(recorder_error, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_ERROR]);
341                 }
342                 break;
343         case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
344                 if (handle->last_max_input_level < m->rec_volume_dB) {
345                         handle->last_max_input_level = m->rec_volume_dB;
346                 }
347                 break;
348         default:
349                 break;
350         }
351
352         return 1;
353 }
354
355
356 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param)
357 {
358         if (user_param == NULL || stream == NULL) {
359                 return 0;
360         }
361
362         recorder_s *handle = (recorder_s *)user_param;
363         audio_sample_type_e format = AUDIO_SAMPLE_TYPE_U8;
364
365         if (stream->format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
366                 format = AUDIO_SAMPLE_TYPE_S16_LE;
367         }
368
369         if( handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] ){
370                 ((recorder_audio_stream_cb)(handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM]))(stream->data, stream->length, format,
371                                                                                                  stream->channel, stream->timestamp,
372                                                                                                  handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
373         }
374
375         return 1;
376 }
377
378
379 static int _recorder_check_and_set_attribute(recorder_h recorder, const char *attribute_name, int set_value)
380 {
381         bool reset_pipeline = false;
382         bool restore_set = false;
383         int ret = MM_ERROR_NONE;
384         int ret2 = MM_ERROR_NONE;
385         int current_value = -1;
386         int current_audio_disable = 0;
387
388         recorder_s *handle = (recorder_s *)recorder;
389         MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
390
391         if (recorder == NULL) {
392                 LOGE("handle is NULL");
393                 return RECORDER_ERROR_INVALID_PARAMETER;
394         }
395
396         mm_camcorder_get_state(handle->mm_handle, &mmstate);
397         if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
398                 LOGE("invalid state %d", mmstate);
399                 return RECORDER_ERROR_INVALID_STATE;
400         }
401
402         if (handle->type == _RECORDER_TYPE_AUDIO && mmstate == MM_CAMCORDER_STATE_PREPARE) {
403                 mm_camcorder_get_attributes(handle->mm_handle, NULL,
404                                             MMCAM_AUDIO_DISABLE, &current_audio_disable,
405                                             attribute_name, &current_value,
406                                             NULL);
407
408                 if (current_value != set_value) {
409                         LOGD("try to reset pipeline");
410
411                         ret = mm_camcorder_stop(handle->mm_handle);
412                         if (ret != MM_ERROR_NONE) {
413                                 LOGE("mm_camcorder_stop failed 0x%x", ret);
414                                 return __convert_recorder_error_code(attribute_name, ret);
415                         }
416
417                         ret = mm_camcorder_unrealize(handle->mm_handle);
418                         if (ret != MM_ERROR_NONE) {
419                                 LOGE("mm_camcorder_unrealize failed 0x%x", ret);
420                                 mm_camcorder_start(handle->mm_handle);
421                                 return __convert_recorder_error_code(attribute_name, ret);
422                         }
423
424                         reset_pipeline = true;
425                 }
426         }
427
428         if (!strcmp(attribute_name, MMCAM_AUDIO_ENCODER)) {
429                 if (set_value == RECORDER_AUDIO_CODEC_DISABLE) {
430                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
431                                                           MMCAM_AUDIO_DISABLE, true,
432                                                           NULL);
433                 } else {
434                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
435                                                           MMCAM_AUDIO_DISABLE, false,
436                                                           MMCAM_AUDIO_ENCODER, set_value,
437                                                           NULL);
438                 }
439         } else {
440                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
441                                                   attribute_name, set_value,
442                                                   NULL);
443         }
444
445         if (ret != MM_ERROR_NONE) {
446                 LOGE("set [%s] failed 0x%x", attribute_name, ret);
447         }
448
449         if (reset_pipeline) {
450                 ret2 = mm_camcorder_realize(handle->mm_handle);
451                 if (ret2 == MM_ERROR_NONE) {
452                         ret2 = mm_camcorder_start(handle->mm_handle);
453                         if (ret2 == MM_ERROR_NONE) {
454                                 LOGW("restart pipeline done.");
455                         } else {
456                                 LOGE("mm_camcorder_start failed 0x%x", ret2);
457                                 mm_camcorder_unrealize(handle->mm_handle);
458                         }
459                 } else {
460                         LOGE("mm_camcorder_realize failed 0x%x", ret2);
461                 }
462
463                 if (ret2 != MM_ERROR_NONE) {
464                         restore_set = true;
465                         /* determine return value */
466                         if (ret == MM_ERROR_NONE) {
467                                 ret = ret2;
468                         }
469                 }
470         }
471
472         if (restore_set) {
473                 ret2 = mm_camcorder_set_attributes(handle->mm_handle, NULL,
474                                                    MMCAM_AUDIO_DISABLE, current_audio_disable,
475                                                    attribute_name, current_value,
476                                                    NULL);
477                 LOGW("restore attribute set : 0x%x", ret2);
478
479                 ret2 = mm_camcorder_realize(handle->mm_handle);
480                 LOGW("restore mm_camcorder_realize : 0x%x", ret2);
481
482                 ret2 = mm_camcorder_start(handle->mm_handle);
483                 LOGW("restore mm_camcorder_realize : 0x%x", ret2);
484                 if (ret2 != MM_ERROR_NONE) {
485                         ret2 = mm_camcorder_unrealize(handle->mm_handle);
486                         LOGW("restore mm_camcorder_unrealize : 0x%x", ret2);
487                 }
488         }
489
490         return __convert_recorder_error_code(attribute_name, ret);
491 }
492
493
494 int legacy_recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
495 {
496         int ret = MM_ERROR_NONE;
497         int resource_fd = -1;
498         recorder_s *handle = NULL;
499         int preview_format = MM_PIXEL_FORMAT_NV12;
500         int camera_device_count = 0;
501
502         if (camera == NULL) {
503                 LOGE("NULL pointer camera handle");
504                 return RECORDER_ERROR_INVALID_PARAMETER;
505         }
506         if (recorder == NULL) {
507                 LOGE("NULL pointer recorder handle");
508                 return RECORDER_ERROR_INVALID_PARAMETER;
509         }
510
511         /* Check already used in another recorder */
512         if (_camera_is_used(camera)) {
513                 LOGE("[%s] camera is using in another recorder.", __func__);
514                 return RECORDER_ERROR_INVALID_PARAMETER;
515         }
516
517         resource_fd = open(RECORDER_PATH_RECORDER_RESOURCE, O_RDONLY);
518         if (resource_fd < 0) {
519                 LOGE("failed to open recorder resource : errno [%d]", errno);
520                 if (errno == EPERM || errno == EACCES) {
521                         LOGE("permission denied");
522                         return RECORDER_ERROR_PERMISSION_DENIED;
523                 } else {
524                         LOGE("invalid operation");
525                         return RECORDER_ERROR_INVALID_OPERATION;
526                 }
527         }
528
529         close(resource_fd);
530         resource_fd = -1;
531
532         LOGW("permission check done");
533
534         handle = (recorder_s*)malloc( sizeof(recorder_s) );
535         if(handle == NULL){
536                 LOGE("[%s] malloc error", __func__);
537                 return RECORDER_ERROR_OUT_OF_MEMORY;
538         }
539
540         memset(handle, 0 , sizeof(recorder_s));
541         handle->src_type = _RECORDER_SOURCE_TYPE_CAMERA;
542         handle->last_max_input_level = LOWSET_DECIBEL;
543         handle->changed_preview_format = -1;
544         handle->mm_source.camera = camera;
545
546         _camera_get_mm_handle(camera, &handle->mm_handle);
547         _camera_set_relay_mm_message_callback(camera, __mm_recorder_msg_cb , (void*)handle);
548         handle->type = _RECORDER_TYPE_VIDEO;
549         legacy_recorder_get_state((recorder_h)handle, (recorder_state_e*)&handle->state);
550
551         mm_camcorder_get_attributes(handle->mm_handle, NULL,
552                                     MMCAM_CAMERA_FORMAT, &preview_format,
553                                     NULL);
554         handle->origin_preview_format = preview_format;
555         mm_camcorder_get_attributes(handle->mm_handle, NULL,
556                                     MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, &preview_format,
557                                     NULL);
558         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL,
559                                     MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count,
560                                     NULL);
561         if (ret != MM_ERROR_NONE) {
562                 free(handle);
563                 handle = NULL;
564                 LOGE("get device count error");
565                 return __convert_recorder_error_code(__func__, ret);
566         }
567         if (camera_device_count == 0) {
568                 free(handle);
569                 handle = NULL;
570                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
571                 return RECORDER_ERROR_NOT_SUPPORTED;
572         } else {
573                 handle->camera_device_count = camera_device_count;
574         }
575
576         _camera_set_use(camera, true);
577         if (handle->state == RECORDER_STATE_CREATED) {
578                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
579                                                   MMCAM_CAMERA_FORMAT, preview_format,
580                                                   NULL);
581                 if (ret == MM_ERROR_NONE) {
582                         handle->changed_preview_format = preview_format;
583                 }
584         }
585         *recorder = (recorder_h)handle;
586
587         return RECORDER_ERROR_NONE;
588 }
589
590
591 int legacy_recorder_create_audiorecorder(recorder_h *recorder)
592 {
593         int ret = MM_ERROR_NONE;
594         recorder_s *handle = NULL;
595         MMCamPreset info;
596         int camera_device_count = 0;
597
598         if (recorder == NULL) {
599                 LOGE("NULL pointer handle");
600                 return RECORDER_ERROR_INVALID_PARAMETER;
601         }
602
603         info.videodev_type = MM_VIDEO_DEVICE_NONE;
604
605         handle = (recorder_s *)malloc(sizeof(recorder_s));
606         if (handle == NULL) {
607                 LOGE("OUT_OF_MEMORY(0x%08x)", RECORDER_ERROR_OUT_OF_MEMORY);
608                 return RECORDER_ERROR_OUT_OF_MEMORY;
609         }
610
611         memset(handle, 0, sizeof(recorder_s));
612
613         handle->last_max_input_level = LOWSET_DECIBEL;
614
615         ret = mm_camcorder_create(&handle->mm_handle, &info);
616         if (ret != MM_ERROR_NONE) {
617                 free(handle);
618                 handle = NULL;
619                 LOGE("mm_camcorder_create fail");
620                 return __convert_recorder_error_code(__func__, ret);
621         }
622
623         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
624                                           MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
625                                           NULL);
626
627         if (ret != MM_ERROR_NONE) {
628                 mm_camcorder_destroy(handle->mm_handle);
629                 free(handle);
630                 handle = NULL;
631                 LOGE("AUDIO mode setting fail");
632                 return __convert_recorder_error_code(__func__, ret);
633         }
634         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL,
635                                     MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count, NULL);
636         if (ret != MM_ERROR_NONE) {
637                 mm_camcorder_destroy(handle->mm_handle);
638                 free(handle);
639                 handle = NULL;
640                 LOGE("get device count error");
641                 return __convert_recorder_error_code(__func__, ret);
642         } else {
643                 handle->camera_device_count = camera_device_count;
644         }
645         handle->state = RECORDER_STATE_CREATED;
646         handle->mm_source.camera = NULL;
647         handle->type = _RECORDER_TYPE_AUDIO;
648
649         mm_camcorder_set_message_callback(handle->mm_handle, __mm_recorder_msg_cb, (void*)handle);
650
651         *recorder = (recorder_h)handle;
652
653         return RECORDER_ERROR_NONE;
654 }
655
656
657 int legacy_recorder_get_state(recorder_h recorder, recorder_state_e *state)
658 {
659         int ret = MM_ERROR_NONE;
660         MMCamcorderStateType mmstate;
661
662         if (recorder == NULL) {
663                 LOGE("NULL pointer handle");
664                 return RECORDER_ERROR_INVALID_PARAMETER;
665         }
666         if (state == NULL) {
667                 LOGE("NULL pointer state");
668                 return RECORDER_ERROR_INVALID_PARAMETER;
669         }
670
671         recorder_s *handle = (recorder_s*)recorder;
672
673         ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
674         if (ret != MM_ERROR_NONE) {
675                 return __convert_recorder_error_code(__func__, ret);
676         }
677
678         *state = __recorder_state_convert(mmstate);
679
680         return RECORDER_ERROR_NONE;
681 }
682
683
684 int legacy_recorder_destroy(recorder_h recorder)
685 {
686         recorder_s *handle = NULL;
687         int ret = MM_ERROR_NONE;
688         int preview_format;
689
690         if (recorder == NULL) {
691                 LOGE("NULL pointer handle");
692                 return RECORDER_ERROR_INVALID_PARAMETER;
693         }
694
695         handle = (recorder_s *)recorder;
696
697         if (handle->type == _RECORDER_TYPE_VIDEO) {
698                 /* set to unsed */
699                 _camera_set_use(handle->mm_source.camera, false);
700                 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
701                                                   MMCAM_CAMERA_FORMAT, &preview_format,
702                                                   NULL);
703
704                 /* preview format was changed? */
705                 if (ret == MM_ERROR_NONE && preview_format == handle->changed_preview_format) {
706                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
707                                                           MMCAM_CAMERA_FORMAT, handle->origin_preview_format,
708                                                           NULL);
709                 }
710
711                 if (ret == MM_ERROR_NONE) {
712                         _camera_set_relay_mm_message_callback(handle->mm_source.camera, NULL, NULL);
713                 }
714         } else {
715                 ret = mm_camcorder_destroy(handle->mm_handle);
716         }
717
718         if (ret == MM_ERROR_NONE) {
719                 free(handle);
720         }
721
722         return __convert_recorder_error_code(__func__, ret);
723 }
724
725
726 int legacy_recorder_prepare(recorder_h recorder)
727 {
728         int ret = MM_ERROR_NONE;
729         recorder_s *handle = (recorder_s *)recorder;
730         MMCamcorderStateType mmstate;
731
732         if (recorder == NULL) {
733                 LOGE("NULL pointer handle");
734                 return RECORDER_ERROR_INVALID_PARAMETER;
735         }
736
737         if (handle->type == _RECORDER_TYPE_VIDEO) {
738                 return __convert_error_code_camera_to_recorder(legacy_camera_start_preview(handle->mm_source.camera));
739         }
740
741         ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
742
743         if (ret == MM_ERROR_NONE && mmstate < MM_CAMCORDER_STATE_READY) {
744                 ret = mm_camcorder_realize(handle->mm_handle);
745                 if (ret != MM_ERROR_NONE) {
746                         LOGE("mm_camcorder_realize fail");
747                         return __convert_recorder_error_code(__func__, ret);
748                 }
749         }
750
751         ret = mm_camcorder_start(handle->mm_handle);
752         if (ret != MM_ERROR_NONE) {
753                 LOGE("mm_camcorder_start fail");
754                 mm_camcorder_unrealize(handle->mm_handle);
755                 return __convert_recorder_error_code(__func__, ret);
756         }
757
758         return RECORDER_ERROR_NONE;
759 }
760
761
762 int legacy_recorder_unprepare(recorder_h recorder)
763 {
764         int ret = MM_ERROR_NONE;
765         recorder_s *handle = (recorder_s *)recorder;
766         MMCamcorderStateType mmstate;
767
768         if (recorder == NULL) {
769                 LOGE("NULL pointer handle");
770                 return RECORDER_ERROR_INVALID_PARAMETER;
771         }
772
773         ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
774         if (ret == MM_ERROR_NONE && mmstate == MM_CAMCORDER_STATE_PREPARE) {
775                 ret = mm_camcorder_stop(handle->mm_handle);
776                 if( ret != MM_ERROR_NONE){
777                         LOGE("mm_camcorder_stop fail");
778                 }
779         }
780
781         if (ret == MM_ERROR_NONE) {
782                 ret = mm_camcorder_unrealize(handle->mm_handle);
783                 if (ret != MM_ERROR_NONE) {
784                         LOGE("mm_camcorder_unrealize fail");
785                         mm_camcorder_start(handle->mm_handle);
786                 }
787         }
788
789         return __convert_recorder_error_code(__func__, ret);
790 }
791
792
793 int legacy_recorder_start(recorder_h recorder)
794 {
795         recorder_s *handle = (recorder_s *)recorder;
796
797         if (recorder == NULL) {
798                 LOGE("NULL pointer handle");
799                 return RECORDER_ERROR_INVALID_PARAMETER;
800         }
801
802         return __convert_recorder_error_code(__func__, mm_camcorder_record(handle->mm_handle));
803 }
804
805
806 int legacy_recorder_pause(recorder_h recorder)
807 {
808         recorder_s *handle = (recorder_s *)recorder;
809
810         if (recorder == NULL) {
811                 LOGE("NULL pointer handle");
812                 return RECORDER_ERROR_INVALID_PARAMETER;
813         }
814
815         return __convert_recorder_error_code(__func__, mm_camcorder_pause(handle->mm_handle));
816 }
817
818
819 int legacy_recorder_commit(recorder_h recorder)
820 {
821         recorder_s *handle = (recorder_s *)recorder;
822
823         if (recorder == NULL) {
824                 LOGE("NULL pointer handle");
825                 return RECORDER_ERROR_INVALID_PARAMETER;
826         }
827
828         return __convert_recorder_error_code(__func__, mm_camcorder_commit(handle->mm_handle));
829 }
830
831
832 int legacy_recorder_cancel(recorder_h recorder)
833 {
834         recorder_s *handle = (recorder_s *)recorder;
835
836         if (recorder == NULL) {
837                 LOGE("NULL pointer handle");
838                 return RECORDER_ERROR_INVALID_PARAMETER;
839         }
840
841         return __convert_recorder_error_code(__func__, mm_camcorder_cancel(handle->mm_handle));
842 }
843
844
845 int legacy_recorder_set_video_resolution(recorder_h recorder, int width, int height)
846 {
847         int ret = MM_ERROR_NONE;
848         recorder_s *handle = (recorder_s*)recorder;
849         recorder_state_e state;
850
851         if (handle == NULL) {
852                 LOGE("NULL pointer handle");
853                 return RECORDER_ERROR_INVALID_PARAMETER;
854         }
855         if (handle->camera_device_count == 0) {
856                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
857                 return RECORDER_ERROR_NOT_SUPPORTED;
858         }
859         legacy_recorder_get_state(recorder, &state);
860         if (state > RECORDER_STATE_READY) {
861                 LOGE("RECORDER_ERROR_INVALID_STATE (state:%d)", state);
862                 return RECORDER_ERROR_INVALID_STATE;
863         }
864
865         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
866                                           MMCAM_VIDEO_WIDTH, width,
867                                           MMCAM_VIDEO_HEIGHT, height,
868                                           NULL);
869
870         return __convert_recorder_error_code(__func__, ret);
871 }
872
873
874 int legacy_recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
875 {
876         int ret = MM_ERROR_NONE;
877         recorder_s *handle = (recorder_s*)recorder;
878
879         if (!handle) {
880                 LOGE("NULL pointer handle");
881                 return RECORDER_ERROR_INVALID_PARAMETER;
882         }
883
884         if (handle->camera_device_count == 0) {
885                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
886                 return RECORDER_ERROR_NOT_SUPPORTED;
887         }
888
889         if (!width || !height) {
890                 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
891                 return RECORDER_ERROR_INVALID_PARAMETER;
892         }
893
894         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
895                                           MMCAM_VIDEO_WIDTH, width,
896                                           MMCAM_VIDEO_HEIGHT, height,
897                                           NULL);
898
899         return __convert_recorder_error_code(__func__, ret);
900 }
901
902
903 int legacy_recorder_foreach_supported_video_resolution(recorder_h recorder,
904                                                 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
905 {
906         int i = 0;
907         int ret = MM_ERROR_NONE;
908         recorder_s * handle = (recorder_s*)recorder;
909         MMCamAttrsInfo video_width;
910         MMCamAttrsInfo video_height;
911
912         if (!handle) {
913                 LOGE("NULL pointer handle");
914                 return RECORDER_ERROR_INVALID_PARAMETER;
915         }
916
917         if (handle->camera_device_count == 0) {
918                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
919                 return RECORDER_ERROR_NOT_SUPPORTED;
920         }
921
922         if (!foreach_cb) {
923                 LOGE("NULL pointer callback");
924                 return RECORDER_ERROR_INVALID_PARAMETER;
925         }
926
927         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_WIDTH, &video_width);
928         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_HEIGHT, &video_height);
929
930         if (ret != MM_ERROR_NONE ) {
931                 return __convert_recorder_error_code(__func__, ret);
932         }
933
934         for (i = 0 ; i < video_width.int_array.count ; i++) {
935                 if (!foreach_cb(video_width.int_array.array[i], video_height.int_array.array[i], user_data)) {
936                         break;
937                 }
938         }
939
940         return RECORDER_ERROR_NONE;
941 }
942
943
944 int legacy_recorder_get_audio_level(recorder_h recorder, double *level)
945 {
946         recorder_s *handle = (recorder_s *)recorder;
947         recorder_state_e state;
948
949         if (recorder == NULL || level == NULL) {
950                 LOGE("NULL pointer %p %p", recorder, level);
951                 return RECORDER_ERROR_INVALID_PARAMETER;
952         }
953
954         legacy_recorder_get_state(recorder, &state);
955         if (state < RECORDER_STATE_RECORDING) {
956                 LOGE("RECORDER_ERROR_INVALID_STATE(0x%08x)", RECORDER_ERROR_INVALID_STATE);
957                 return RECORDER_ERROR_INVALID_STATE;
958         }
959
960         *level = handle->last_max_input_level;
961         handle->last_max_input_level = LOWSET_DECIBEL;
962
963         return RECORDER_ERROR_NONE;
964 }
965
966
967 int legacy_recorder_set_filename(recorder_h recorder,  const char *filename)
968 {
969         int ret = MM_ERROR_NONE;
970         recorder_s *handle = (recorder_s *)recorder;
971         MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
972
973         if (recorder == NULL) {
974                 LOGE("handle is NULL");
975                 return RECORDER_ERROR_INVALID_PARAMETER;
976         }
977
978         if (filename == NULL) {
979                 LOGE("filename is NULL");
980                 return RECORDER_ERROR_INVALID_PARAMETER;
981         }
982
983         mm_camcorder_get_state(handle->mm_handle, &mmstate);
984         if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
985                 LOGE("invalid state %d", mmstate);
986                 return RECORDER_ERROR_INVALID_STATE;
987         }
988
989         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
990                                           MMCAM_TARGET_FILENAME, filename, strlen(filename),
991                                           NULL);
992
993         return __convert_recorder_error_code(__func__, ret);
994 }
995
996
997 int legacy_recorder_get_filename(recorder_h recorder,  char **filename)
998 {
999         int ret = MM_ERROR_NONE;
1000         char *record_filename = NULL;
1001         int record_filename_size;
1002         recorder_s *handle = (recorder_s *)recorder;
1003
1004         if (recorder == NULL) {
1005                 LOGE("handle is NULL");
1006                 return RECORDER_ERROR_INVALID_PARAMETER;
1007         }
1008
1009         if (filename == NULL) {
1010                 LOGE("filename is NULL");
1011                 return RECORDER_ERROR_INVALID_PARAMETER;
1012         }
1013
1014         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1015                                           MMCAM_TARGET_FILENAME, &record_filename, &record_filename_size,
1016                                           NULL);
1017         if (ret == MM_ERROR_NONE && record_filename) {
1018                 *filename = strdup(record_filename);
1019         } else {
1020                 LOGE("internal return (0x%08x), get filename p:%p", ret, record_filename);
1021                 *filename = NULL;
1022         }
1023
1024         return __convert_recorder_error_code(__func__, ret);
1025 }
1026
1027
1028 int legacy_recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
1029 {
1030         int format_table[6] = { MM_FILE_FORMAT_3GP, /* RECORDER_FILE_FORMAT_3GP */
1031                                 MM_FILE_FORMAT_MP4, /* RECORDER_FILE_FORMAT_MP4 */
1032                                 MM_FILE_FORMAT_AMR, /* RECORDER_FILE_FORMAT_AMR */
1033                                 MM_FILE_FORMAT_AAC, /* RECORDER_FILE_FORMAT_ADTS */
1034                                 MM_FILE_FORMAT_WAV, /* RECORDER_FILE_FORMAT_WAV */
1035                                 MM_FILE_FORMAT_OGG  /* RECORDER_FILE_FORMAT_OGG */
1036         };
1037
1038         if (format < RECORDER_FILE_FORMAT_3GP || format > RECORDER_FILE_FORMAT_OGG) {
1039                 LOGE("invalid format %d", format);
1040                 return RECORDER_ERROR_INVALID_PARAMETER;
1041         }
1042
1043         return _recorder_check_and_set_attribute(recorder, MMCAM_FILE_FORMAT, format_table[format]);
1044 }
1045
1046
1047 int legacy_recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
1048 {
1049         int ret = MM_ERROR_NONE;
1050         recorder_s *handle = (recorder_s *)recorder;
1051         int mm_format;
1052
1053         if (recorder == NULL) {
1054                 LOGE("handle is NULL");
1055                 return RECORDER_ERROR_INVALID_PARAMETER;
1056         }
1057
1058         if (format == NULL) {
1059                 LOGE("format is NULL");
1060                 return RECORDER_ERROR_INVALID_PARAMETER;
1061         }
1062
1063         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1064                                           MMCAM_FILE_FORMAT, &mm_format,
1065                                           NULL);
1066         if (ret == MM_ERROR_NONE) {
1067                 switch (mm_format) {
1068                 case MM_FILE_FORMAT_3GP:
1069                         *format = RECORDER_FILE_FORMAT_3GP;
1070                         break;
1071                 case MM_FILE_FORMAT_MP4 :
1072                         *format = RECORDER_FILE_FORMAT_MP4;
1073                         break;
1074                 case MM_FILE_FORMAT_AMR :
1075                         *format = RECORDER_FILE_FORMAT_AMR;
1076                         break;
1077                 case MM_FILE_FORMAT_AAC :
1078                         *format = RECORDER_FILE_FORMAT_ADTS;
1079                         break;
1080                 case MM_FILE_FORMAT_WAV:
1081                         *format = RECORDER_FILE_FORMAT_WAV;
1082                         break;
1083                 case MM_FILE_FORMAT_OGG:
1084                         *format = RECORDER_FILE_FORMAT_OGG;
1085                         break;
1086                 default :
1087                         ret = MM_ERROR_CAMCORDER_INTERNAL;
1088                         break;
1089                 }
1090         }
1091
1092         return __convert_recorder_error_code(__func__, ret);
1093 }
1094
1095
1096 int legacy_recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
1097 {
1098         recorder_s *handle = (recorder_s *)recorder;
1099
1100         if (recorder == NULL) {
1101                 LOGE("NULL pointer handle");
1102                 return RECORDER_ERROR_INVALID_PARAMETER;
1103         }
1104
1105         if (callback == NULL) {
1106                 LOGE("NULL pointer callback");
1107                 return RECORDER_ERROR_INVALID_PARAMETER;
1108         }
1109
1110         handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
1111         handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
1112
1113         return RECORDER_ERROR_NONE;
1114 }
1115
1116
1117 int legacy_recorder_unset_state_changed_cb(recorder_h recorder)
1118 {
1119         recorder_s *handle = (recorder_s *)recorder;
1120
1121         if (recorder == NULL) {
1122                 LOGE("NULL pointer handle");
1123                 return RECORDER_ERROR_INVALID_PARAMETER;
1124         }
1125
1126         handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1127         handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1128
1129         return RECORDER_ERROR_NONE;
1130 }
1131
1132
1133 int legacy_recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
1134 {
1135         recorder_s *handle = (recorder_s *)recorder;
1136
1137         if (recorder == NULL) {
1138                 LOGE("NULL pointer handle");
1139                 return RECORDER_ERROR_INVALID_PARAMETER;
1140         }
1141         if (callback == NULL) {
1142                 LOGE("NULL pointer callback");
1143                 return RECORDER_ERROR_INVALID_PARAMETER;
1144         }
1145
1146         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
1147         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
1148
1149         return RECORDER_ERROR_NONE;
1150 }
1151
1152
1153 int legacy_recorder_unset_interrupted_cb(recorder_h recorder)
1154 {
1155         recorder_s *handle = (recorder_s *)recorder;
1156
1157         if (recorder == NULL) {
1158                 LOGE("NULL pointer handle");
1159                 return RECORDER_ERROR_INVALID_PARAMETER;
1160         }
1161
1162         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1163         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1164
1165         return RECORDER_ERROR_NONE;
1166 }
1167
1168
1169 int legacy_recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
1170 {
1171         int ret = MM_ERROR_NONE;
1172         recorder_s *handle = (recorder_s *)recorder;
1173
1174         if (recorder == NULL) {
1175                 LOGE("NULL pointer handle");
1176                 return RECORDER_ERROR_INVALID_PARAMETER;
1177         }
1178         if (callback == NULL) {
1179                 LOGE("NULL pointer callback");
1180                 return RECORDER_ERROR_INVALID_PARAMETER;
1181         }
1182
1183         ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, __mm_audio_stream_cb, handle);
1184         if (ret == MM_ERROR_NONE){
1185                 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
1186                 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
1187         }
1188
1189         return __convert_recorder_error_code(__func__, ret);
1190 }
1191
1192
1193 int legacy_recorder_unset_audio_stream_cb(recorder_h recorder)
1194 {
1195         int ret = MM_ERROR_NONE;
1196         recorder_s *handle = (recorder_s *)recorder;
1197
1198         if (recorder == NULL) {
1199                 LOGE("NULL pointer handle");
1200                 return RECORDER_ERROR_INVALID_PARAMETER;
1201         }
1202
1203         handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1204         handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1205
1206         ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, NULL, NULL);
1207
1208         return __convert_recorder_error_code(__func__, ret);
1209 }
1210
1211
1212 int legacy_recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
1213 {
1214         recorder_s *handle = (recorder_s *)recorder;
1215
1216         if (recorder == NULL) {
1217                 LOGE("NULL pointer handle");
1218                 return RECORDER_ERROR_INVALID_PARAMETER;
1219         }
1220         if (callback == NULL) {
1221                 LOGE("NULL pointer callback");
1222                 return RECORDER_ERROR_INVALID_PARAMETER;
1223         }
1224
1225         handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = callback;
1226         handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = user_data;
1227
1228         return RECORDER_ERROR_NONE;
1229 }
1230
1231
1232 int legacy_recorder_unset_error_cb(recorder_h recorder)
1233 {
1234         recorder_s *handle = (recorder_s *)recorder;
1235
1236         if (recorder == NULL) {
1237                 LOGE("NULL pointer handle");
1238                 return RECORDER_ERROR_INVALID_PARAMETER;
1239         }
1240
1241         handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1242         handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1243
1244         return RECORDER_ERROR_NONE;
1245 }
1246
1247
1248 int legacy_recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
1249 {
1250         recorder_s *handle = (recorder_s *)recorder;
1251
1252         if (recorder == NULL) {
1253                 LOGE("NULL pointer handle");
1254                 return RECORDER_ERROR_INVALID_PARAMETER;
1255         }
1256         if (callback == NULL) {
1257                 LOGE("NULL pointer callback");
1258                 return RECORDER_ERROR_INVALID_PARAMETER;
1259         }
1260
1261         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
1262         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
1263
1264         return RECORDER_ERROR_NONE;
1265 }
1266
1267
1268 int legacy_recorder_unset_recording_status_cb(recorder_h recorder)
1269 {
1270         recorder_s *handle = (recorder_s *)recorder;
1271
1272         if (recorder == NULL) {
1273                 LOGE("NULL pointer handle");
1274                 return RECORDER_ERROR_INVALID_PARAMETER;
1275         }
1276
1277         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1278         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1279
1280         return RECORDER_ERROR_NONE;
1281 }
1282
1283
1284 int legacy_recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
1285 {
1286         recorder_s *handle = (recorder_s *)recorder;
1287
1288         if (recorder == NULL) {
1289                 LOGE("NULL pointer handle");
1290                 return RECORDER_ERROR_INVALID_PARAMETER;
1291         }
1292         if (callback == NULL) {
1293                 LOGE("NULL pointer callback");
1294                 return RECORDER_ERROR_INVALID_PARAMETER;
1295         }
1296
1297         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
1298         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
1299
1300         return RECORDER_ERROR_NONE;
1301 }
1302
1303
1304 int legacy_recorder_unset_recording_limit_reached_cb(recorder_h recorder)
1305 {
1306         recorder_s *handle = (recorder_s *)recorder;
1307
1308         if (recorder == NULL) {
1309                 LOGE("NULL pointer handle");
1310                 return RECORDER_ERROR_INVALID_PARAMETER;
1311         }
1312
1313         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1314         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1315
1316         return RECORDER_ERROR_NONE;
1317 }
1318
1319
1320 int legacy_recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
1321 {
1322         int i = 0;
1323         int ret = MM_ERROR_NONE;
1324         recorder_s *handle = (recorder_s *)recorder;
1325         MMCamAttrsInfo info;
1326         int format;
1327
1328         if (recorder == NULL) {
1329                 LOGE("NULL pointer handle");
1330                 return RECORDER_ERROR_INVALID_PARAMETER;
1331         }
1332         if (foreach_cb == NULL) {
1333                 LOGE("NULL pointer foreach_cb");
1334                 return RECORDER_ERROR_INVALID_PARAMETER;
1335         }
1336
1337         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILE_FORMAT, &info);
1338         if (ret != MM_ERROR_NONE) {
1339                 LOGE("mm_camcorder_get_attribute_info failed 0x%x", ret);
1340                 return __convert_recorder_error_code(__func__, ret);;
1341         }
1342
1343         for (i = 0 ; i < info.int_array.count ; i++) {
1344                 switch (info.int_array.array[i]) {
1345                 case MM_FILE_FORMAT_3GP:
1346                         format = RECORDER_FILE_FORMAT_3GP;
1347                         break;
1348                 case MM_FILE_FORMAT_MP4 :
1349                         format = RECORDER_FILE_FORMAT_MP4;
1350                         break;
1351                 case MM_FILE_FORMAT_AMR :
1352                         format = RECORDER_FILE_FORMAT_AMR;
1353                         break;
1354                 case MM_FILE_FORMAT_AAC:
1355                         format = RECORDER_FILE_FORMAT_ADTS;
1356                         break;
1357                 case MM_FILE_FORMAT_WAV:
1358                         format = RECORDER_FILE_FORMAT_WAV;
1359                         break;
1360                 default :
1361                         format = -1;
1362                         break;
1363                 }
1364
1365                 if (format != -1 && !foreach_cb(format,user_data)) {
1366                         break;
1367                 }
1368         }
1369
1370         return RECORDER_ERROR_NONE;
1371 }
1372
1373
1374 int legacy_recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
1375 {
1376         int ret = MM_ERROR_NONE;
1377         recorder_s *handle = (recorder_s *)recorder;
1378
1379         if (recorder == NULL) {
1380                 LOGE("NULL pointer handle");
1381                 return RECORDER_ERROR_INVALID_PARAMETER;
1382         }
1383
1384         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1385                                           MMCAM_TARGET_MAX_SIZE, kbyte,
1386                                           NULL);
1387
1388         return __convert_recorder_error_code(__func__, ret);
1389 }
1390
1391
1392 int legacy_recorder_attr_set_time_limit(recorder_h recorder, int second)
1393 {
1394         int ret = MM_ERROR_NONE;
1395         recorder_s *handle = (recorder_s *)recorder;
1396
1397         if (recorder == NULL) {
1398                 LOGE("NULL pointer handle");
1399                 return RECORDER_ERROR_INVALID_PARAMETER;
1400         }
1401
1402         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1403                                           MMCAM_TARGET_TIME_LIMIT, second,
1404                                           NULL);
1405
1406         return __convert_recorder_error_code(__func__, ret);
1407 }
1408
1409
1410 int legacy_recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
1411 {
1412         if (device < RECORDER_AUDIO_DEVICE_MIC || device > RECORDER_AUDIO_DEVICE_MODEM) {
1413                 LOGE("invalid device %d", device);
1414                 return RECORDER_ERROR_INVALID_PARAMETER;
1415         }
1416
1417         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_DEVICE, device);
1418 }
1419
1420
1421 int legacy_recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
1422 {
1423         recorder_s *handle = (recorder_s *)recorder;
1424         int audio_table[4] = { MM_AUDIO_CODEC_AMR,      /* RECORDER_AUDIO_CODEC_AMR */
1425                                MM_AUDIO_CODEC_AAC,      /* RECORDER_AUDIO_CODEC_AAC */
1426                                MM_AUDIO_CODEC_VORBIS,   /* RECORDER_AUDIO_CODEC_VORBIS */
1427                                MM_AUDIO_CODEC_WAVE      /* RECORDER_AUDIO_CODEC_PCM */
1428         };
1429
1430         if (recorder == NULL) {
1431                 LOGE("handle is NULL");
1432                 return RECORDER_ERROR_INVALID_PARAMETER;
1433         }
1434
1435         if (codec != RECORDER_AUDIO_CODEC_DISABLE &&
1436             (codec < RECORDER_AUDIO_CODEC_AMR || codec > RECORDER_AUDIO_CODEC_PCM)) {
1437                 LOGE("invalid parameter : codec %d", codec);
1438                 return RECORDER_ERROR_INVALID_PARAMETER;
1439         }
1440
1441         if (handle->type == _RECORDER_TYPE_AUDIO && codec == RECORDER_AUDIO_CODEC_DISABLE) {
1442                 LOGE("AUDIO_CODEC_DISABLE is not supported in audio mode");
1443                 return RECORDER_ERROR_NOT_SUPPORTED;
1444         }
1445
1446         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER, codec == RECORDER_AUDIO_CODEC_DISABLE ? RECORDER_AUDIO_CODEC_DISABLE : audio_table[codec]);
1447 }
1448
1449
1450 int legacy_recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
1451 {
1452         int ret = MM_ERROR_NONE;
1453         int mm_codec = 0;
1454         int audio_disable = 0;
1455         recorder_s *handle = (recorder_s *)recorder;
1456
1457         if (recorder == NULL) {
1458                 LOGE("handle is NULL");
1459                 return RECORDER_ERROR_INVALID_PARAMETER;
1460         }
1461
1462         if (codec == NULL) {
1463                 LOGE("codec is NULL");
1464                 return RECORDER_ERROR_INVALID_PARAMETER;
1465         }
1466
1467         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1468                                           MMCAM_AUDIO_ENCODER, &mm_codec,
1469                                           MMCAM_AUDIO_DISABLE, &audio_disable,
1470                                           NULL);
1471
1472         if (ret == MM_ERROR_NONE && audio_disable == 0) {
1473                 switch (mm_codec) {
1474                 case MM_AUDIO_CODEC_AMR :
1475                         *codec = RECORDER_AUDIO_CODEC_AMR;
1476                         break;
1477                 case MM_AUDIO_CODEC_AAC :
1478                         *codec = RECORDER_AUDIO_CODEC_AAC;
1479                         break;
1480                 case MM_AUDIO_CODEC_VORBIS:
1481                         *codec = RECORDER_AUDIO_CODEC_VORBIS;
1482                         break;
1483                 case MM_AUDIO_CODEC_WAVE:
1484                         *codec = RECORDER_AUDIO_CODEC_PCM;
1485                         break;
1486                 default :
1487                         ret = MM_ERROR_CAMCORDER_INTERNAL;
1488                         break;
1489                 }
1490         } else if (ret == MM_ERROR_NONE && audio_disable) {
1491                 *codec = RECORDER_AUDIO_CODEC_DISABLE;
1492         }
1493
1494         return __convert_recorder_error_code(__func__, ret);
1495 }
1496
1497
1498 int legacy_recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
1499 {
1500         int ret = MM_ERROR_NONE;
1501         int video_table[4] = { MM_VIDEO_CODEC_H263,     /* RECORDER_VIDEO_CODEC_H263 */
1502                                MM_VIDEO_CODEC_H264,     /* RECORDER_VIDEO_CODEC_H264 */
1503                                MM_VIDEO_CODEC_MPEG4,    /* RECORDER_VIDEO_CODEC_MPEG4 */
1504                                MM_VIDEO_CODEC_THEORA    /* RECORDER_VIDEO_CODEC_THEORA */
1505         };
1506         recorder_s *handle = (recorder_s *)recorder;
1507
1508         if (handle == NULL) {
1509                 LOGE("handle is NULL");
1510                 return RECORDER_ERROR_INVALID_PARAMETER;
1511         }
1512
1513         if (handle->camera_device_count == 0) {
1514                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1515                 return RECORDER_ERROR_NOT_SUPPORTED;
1516         }
1517
1518         if (codec < RECORDER_VIDEO_CODEC_H263 || codec > RECORDER_VIDEO_CODEC_THEORA) {
1519                 LOGE("invalid codec %d", codec);
1520                 return RECORDER_ERROR_INVALID_PARAMETER;
1521         }
1522
1523         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1524                                           MMCAM_VIDEO_ENCODER, video_table[codec],
1525                                           NULL);
1526
1527         return __convert_recorder_error_code(__func__, ret);
1528 }
1529
1530
1531 int legacy_recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
1532 {
1533         int ret = MM_ERROR_NONE;
1534         int mm_codec = 0;
1535         recorder_s *handle = (recorder_s *)recorder;
1536
1537         if (handle == NULL) {
1538                 LOGE("handle is NULL");
1539                 return RECORDER_ERROR_INVALID_PARAMETER;
1540         }
1541         if (handle->camera_device_count == 0) {
1542                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1543                 return RECORDER_ERROR_NOT_SUPPORTED;
1544         }
1545         if (codec == NULL) {
1546                 LOGE("codec is NULL");
1547                 return RECORDER_ERROR_INVALID_PARAMETER;
1548         }
1549
1550         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1551                                           MMCAM_VIDEO_ENCODER, &mm_codec,
1552                                           NULL);
1553         if (ret == MM_ERROR_NONE) {
1554                 switch(mm_codec) {
1555                 case MM_VIDEO_CODEC_H263 :
1556                         *codec = RECORDER_VIDEO_CODEC_H263;
1557                         break;
1558                 case MM_VIDEO_CODEC_H264 :
1559                         *codec = RECORDER_VIDEO_CODEC_H264;
1560                         break;
1561                 case MM_VIDEO_CODEC_MPEG4 :
1562                         *codec = RECORDER_VIDEO_CODEC_MPEG4;
1563                         break;
1564                 case MM_VIDEO_CODEC_THEORA:
1565                         *codec = RECORDER_VIDEO_CODEC_THEORA;
1566                         break;
1567                 default :
1568                         ret = MM_ERROR_CAMCORDER_INTERNAL;
1569                         break;
1570                 }
1571         }
1572
1573         return __convert_recorder_error_code(__func__, ret);
1574 }
1575
1576
1577 int legacy_recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
1578 {
1579         if (samplerate < 1) {
1580                 LOGE("invalid samplerate %d", samplerate);
1581                 return RECORDER_ERROR_INVALID_PARAMETER;
1582         }
1583
1584         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_SAMPLERATE, samplerate);
1585 }
1586
1587
1588 int legacy_recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
1589 {
1590         if (bitrate < 1) {
1591                 LOGE("invalid bitrate %d", bitrate);
1592                 return RECORDER_ERROR_INVALID_PARAMETER;
1593         }
1594
1595         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER_BITRATE, bitrate);
1596 }
1597
1598
1599 int legacy_recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
1600 {
1601         int ret = MM_ERROR_NONE;
1602         recorder_s *handle = (recorder_s *)recorder;
1603
1604         if (handle == NULL) {
1605                 LOGE("handle is NULL");
1606                 return RECORDER_ERROR_INVALID_PARAMETER;
1607         }
1608         if (handle->camera_device_count == 0) {
1609                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1610                 return RECORDER_ERROR_NOT_SUPPORTED;
1611         }
1612
1613         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1614                                           MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1615                                           NULL);
1616
1617         return __convert_recorder_error_code(__func__, ret);
1618 }
1619
1620
1621 int legacy_recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
1622 {
1623         int ret = MM_ERROR_NONE;
1624         recorder_s *handle = (recorder_s *)recorder;
1625
1626         if (recorder == NULL) {
1627                 LOGE("handle is NULL");
1628                 return RECORDER_ERROR_INVALID_PARAMETER;
1629         }
1630
1631         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1632                                           MMCAM_TARGET_MAX_SIZE, kbyte,
1633                                           NULL);
1634
1635         return __convert_recorder_error_code(__func__, ret);
1636 }
1637
1638
1639 int legacy_recorder_attr_get_time_limit(recorder_h recorder, int *second)
1640 {
1641         int ret = MM_ERROR_NONE;
1642         recorder_s *handle = (recorder_s *)recorder;
1643
1644         if (recorder == NULL) {
1645                 LOGE("handle is NULL");
1646                 return RECORDER_ERROR_INVALID_PARAMETER;
1647         }
1648
1649         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1650                                           MMCAM_TARGET_TIME_LIMIT, second,
1651                                           NULL);
1652
1653         return __convert_recorder_error_code(__func__, ret);
1654 }
1655
1656
1657 int legacy_recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
1658 {
1659         int ret = MM_ERROR_NONE;
1660         recorder_s *handle = (recorder_s *)recorder;
1661
1662         if (recorder == NULL) {
1663                 LOGE("handle is NULL");
1664                 return RECORDER_ERROR_INVALID_PARAMETER;
1665         }
1666
1667         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1668                                           MMCAM_AUDIO_DEVICE, device,
1669                                           NULL);
1670
1671         return __convert_recorder_error_code(__func__, ret);
1672 }
1673
1674
1675 int legacy_recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
1676 {
1677         int ret = MM_ERROR_NONE;
1678         recorder_s *handle = (recorder_s *)recorder;
1679
1680         if (recorder == NULL) {
1681                 LOGE("handle is NULL");
1682                 return RECORDER_ERROR_INVALID_PARAMETER;
1683         }
1684
1685         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1686                                           MMCAM_AUDIO_SAMPLERATE, samplerate,
1687                                           NULL);
1688
1689         return __convert_recorder_error_code(__func__, ret);
1690 }
1691
1692
1693 int legacy_recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
1694 {
1695         int ret = MM_ERROR_NONE;
1696         recorder_s *handle = (recorder_s *)recorder;
1697
1698         if (recorder == NULL) {
1699                 LOGE("handle is NULL");
1700                 return RECORDER_ERROR_INVALID_PARAMETER;
1701         }
1702
1703         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1704                                           MMCAM_AUDIO_ENCODER_BITRATE, bitrate,
1705                                           NULL);
1706
1707         return __convert_recorder_error_code(__func__, ret);
1708 }
1709
1710
1711 int legacy_recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
1712 {
1713         int ret = MM_ERROR_NONE;
1714         recorder_s *handle = (recorder_s *)recorder;
1715
1716         if (handle == NULL) {
1717                 LOGE("handle is NULL");
1718                 return RECORDER_ERROR_INVALID_PARAMETER;
1719         }
1720         if (handle->camera_device_count == 0) {
1721                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1722                 return RECORDER_ERROR_NOT_SUPPORTED;
1723         }
1724         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1725                                           MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1726                                           NULL);
1727
1728         return __convert_recorder_error_code(__func__, ret);
1729 }
1730
1731
1732 int legacy_recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
1733 {
1734         int i = 0;
1735         int ret = MM_ERROR_NONE;
1736         int codec;
1737         recorder_s *handle = (recorder_s *)recorder;
1738         MMCamAttrsInfo info;
1739
1740         if (recorder == NULL) {
1741                 LOGE("handle is NULL");
1742                 return RECORDER_ERROR_INVALID_PARAMETER;
1743         }
1744         if (foreach_cb == NULL) {
1745                 LOGE("foreach_cb is NULL");
1746                 return RECORDER_ERROR_INVALID_PARAMETER;
1747         }
1748
1749         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_AUDIO_ENCODER, &info);
1750         if (ret != MM_ERROR_NONE) {
1751                 return __convert_recorder_error_code(__func__, ret);
1752         }
1753
1754         for (i = 0 ; i < info.int_array.count ; i++) {
1755                 switch (info.int_array.array[i]) {
1756                 case MM_AUDIO_CODEC_AMR:
1757                         codec = RECORDER_AUDIO_CODEC_AMR;
1758                         break;
1759                 case MM_AUDIO_CODEC_AAC :
1760                         codec = RECORDER_AUDIO_CODEC_AAC;
1761                         break;
1762                 case MM_AUDIO_CODEC_VORBIS:
1763                         codec = RECORDER_AUDIO_CODEC_VORBIS;
1764                         break;
1765                 case MM_AUDIO_CODEC_WAVE:
1766                         codec = RECORDER_AUDIO_CODEC_PCM;
1767                         break;
1768                 default :
1769                         codec = -1;
1770                         break;
1771                 }
1772                 if (codec != -1 && !foreach_cb(codec,user_data)) {
1773                         break;
1774                 }
1775         }
1776
1777         return RECORDER_ERROR_NONE;
1778 }
1779
1780
1781 int legacy_recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
1782 {
1783         int i = 0;
1784         int ret = MM_ERROR_NONE;
1785         int codec;
1786         recorder_s *handle = (recorder_s *)recorder;
1787         MMCamAttrsInfo info;
1788
1789         if (handle == NULL) {
1790                 LOGE("handle is NULL");
1791                 return RECORDER_ERROR_INVALID_PARAMETER;
1792         }
1793         if (handle->camera_device_count == 0) {
1794                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1795                 return RECORDER_ERROR_NOT_SUPPORTED;
1796         }
1797         if (foreach_cb == NULL) {
1798                 LOGE("foreach_cb is NULL");
1799                 return RECORDER_ERROR_INVALID_PARAMETER;
1800         }
1801
1802         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_ENCODER, &info);
1803         if (ret != MM_ERROR_NONE) {
1804                 return __convert_recorder_error_code(__func__, ret);
1805         }
1806
1807         for (i = 0 ; i < info.int_array.count ; i++) {
1808                 switch (info.int_array.array[i]){
1809                 case MM_VIDEO_CODEC_H263 :
1810                         codec = RECORDER_VIDEO_CODEC_H263;
1811                         break;
1812                 case MM_VIDEO_CODEC_H264 :
1813                         codec = RECORDER_VIDEO_CODEC_H264;
1814                         break;
1815                 case MM_VIDEO_CODEC_MPEG4 :
1816                         codec = RECORDER_VIDEO_CODEC_MPEG4;
1817                         break;
1818                 case MM_VIDEO_CODEC_THEORA :
1819                         codec = RECORDER_VIDEO_CODEC_THEORA;
1820                         break;
1821                 default :
1822                         codec = -1;
1823                         break;
1824                 }
1825
1826                 if (codec != -1 && !foreach_cb(codec,user_data)) {
1827                         break;
1828                 }
1829         }
1830
1831         return RECORDER_ERROR_NONE;
1832 }
1833
1834
1835 int legacy_recorder_attr_set_mute(recorder_h recorder, bool enable)
1836 {
1837         int ret = MM_ERROR_NONE;
1838         recorder_s *handle = (recorder_s *)recorder;
1839
1840         if (recorder == NULL) {
1841                 LOGE("handle is NULL");
1842                 return RECORDER_ERROR_INVALID_PARAMETER;
1843         }
1844
1845         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1846                                           MMCAM_AUDIO_VOLUME, enable ? 0.0 : 1.0,
1847                                           NULL);
1848
1849         return  __convert_recorder_error_code(__func__, ret);
1850 }
1851
1852
1853 bool legacy_recorder_attr_is_muted(recorder_h recorder)
1854 {
1855         int ret = MM_ERROR_NONE;
1856         double volume = 1.0;
1857         recorder_s *handle = (recorder_s *)recorder;
1858
1859         if (recorder == NULL) {
1860                 LOGE("handle is NULL");
1861                 return false;
1862         }
1863
1864         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1865                                           MMCAM_AUDIO_VOLUME, &volume,
1866                                           NULL);
1867
1868         set_last_result(__convert_recorder_error_code(__func__, ret));
1869
1870         if (volume == 0.0) {
1871                 return true;
1872         } else {
1873                 return false;
1874         }
1875 }
1876
1877
1878 int legacy_recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
1879 {
1880         int ret = MM_ERROR_NONE;
1881         recorder_s *handle = (recorder_s *)recorder;
1882
1883         if (handle == NULL) {
1884                 LOGE("handle is NULL");
1885                 return RECORDER_ERROR_INVALID_PARAMETER;
1886         }
1887         if (handle->camera_device_count == 0) {
1888                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1889                 return RECORDER_ERROR_NOT_SUPPORTED;
1890         }
1891         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1892                                           MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1893                                           NULL);
1894
1895         return  __convert_recorder_error_code(__func__, ret);
1896 }
1897
1898
1899 int legacy_recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
1900 {
1901         int ret = MM_ERROR_NONE;
1902         recorder_s *handle = (recorder_s *)recorder;
1903
1904         if (handle == NULL) {
1905                 LOGE("handle is NULL");
1906                 return RECORDER_ERROR_INVALID_PARAMETER;
1907         }
1908         if (handle->camera_device_count == 0) {
1909                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1910                 return RECORDER_ERROR_NOT_SUPPORTED;
1911         }
1912         if (rate == NULL) {
1913                 LOGE("rate is NULL");
1914                 return RECORDER_ERROR_INVALID_PARAMETER;
1915         }
1916
1917         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1918                                           MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1919                                           NULL);
1920
1921         return  __convert_recorder_error_code(__func__, ret);
1922 }
1923
1924
1925 int legacy_recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
1926 {
1927         if (channel_count < 1) {
1928                 LOGE("invalid channel %d", channel_count);
1929                 return RECORDER_ERROR_INVALID_PARAMETER;
1930         }
1931
1932         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_CHANNEL, channel_count);
1933 }
1934
1935
1936 int legacy_recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
1937 {
1938         int ret = MM_ERROR_NONE;
1939         recorder_s *handle = (recorder_s *)recorder;
1940
1941         if (recorder == NULL) {
1942                 LOGE("handle is NULL");
1943                 return RECORDER_ERROR_INVALID_PARAMETER;
1944         }
1945         if (channel_count == NULL) {
1946                 LOGE("channel_count is NULL");
1947                 return RECORDER_ERROR_INVALID_PARAMETER;
1948         }
1949
1950         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1951                                           MMCAM_AUDIO_CHANNEL, channel_count,
1952                                           NULL);
1953
1954         return  __convert_recorder_error_code(__func__, ret);
1955 }
1956
1957
1958 int legacy_recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
1959 {
1960         int ret = MM_ERROR_NONE;
1961         recorder_s *handle = (recorder_s *)recorder;
1962
1963         if (handle == NULL) {
1964                 LOGE("handle is NULL");
1965                 return RECORDER_ERROR_INVALID_PARAMETER;
1966         }
1967         if (handle->camera_device_count == 0) {
1968                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1969                 return RECORDER_ERROR_NOT_SUPPORTED;
1970         }
1971         if (orientation > RECORDER_ROTATION_270) {
1972                 LOGE("invalid orientation %d", orientation);
1973                 return RECORDER_ERROR_INVALID_PARAMETER;
1974         }
1975
1976         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1977                                           MMCAM_RECORDER_TAG_ENABLE, true,
1978                                           MMCAM_TAG_VIDEO_ORIENTATION, orientation,
1979                                           NULL);
1980
1981         return __convert_recorder_error_code(__func__, ret);
1982 }
1983
1984
1985 int  legacy_recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
1986 {
1987         int ret = MM_ERROR_NONE;
1988         recorder_s *handle = (recorder_s *)recorder;
1989
1990         if (handle == NULL) {
1991                 LOGE("handle is NULL");
1992                 return RECORDER_ERROR_INVALID_PARAMETER;
1993         }
1994         if (handle->camera_device_count == 0) {
1995                 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1996                 return RECORDER_ERROR_NOT_SUPPORTED;
1997         }
1998         if (orientation == NULL) {
1999                 LOGE("orientation is NULL");
2000                 return RECORDER_ERROR_INVALID_PARAMETER;
2001         }
2002
2003         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2004                                           MMCAM_TAG_VIDEO_ORIENTATION, orientation,
2005                                           NULL);
2006
2007         return __convert_recorder_error_code(__func__, ret);
2008 }