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