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