Revise log related code
[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         CAM_LOG_ERROR("[%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                         CAM_LOG_WARNING("destroying pipeline now");
203                 } else {
204                         state = RECORDER_STATE_CREATED;
205                         CAM_LOG_WARNING("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                 CAM_LOG_WARNING("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                         CAM_LOG_ERROR("RECORDER_POLICY_SECURITY");
254                 } else if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM) {
255                         policy = RECORDER_POLICY_RESOURCE_CONFLICT;
256                         CAM_LOG_WARNING("RECORDER_POLICY_RESOURCE_CONFLICT");
257                 }
258
259                 if (message != MM_MESSAGE_CAMCORDER_STATE_CHANGED &&
260                         interrupt_state == -1) {
261                         interrupt_state = previous_state;
262                         CAM_LOG_INFO("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                                 CAM_LOG_INFO("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                                         CAM_LOG_WARNING("_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                         CAM_LOG_WARNING("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                         CAM_LOG_ERROR("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                         CAM_LOG_ERROR("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                         CAM_LOG_ERROR("OUT_OF_MEMORY : 0x%x", m->code);
353                         break;
354                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
355                         recorder_error = RECORDER_ERROR_ESD;
356                         CAM_LOG_ERROR("ESD : 0x%x", m->code);
357                         break;
358                 case MM_ERROR_OUT_OF_STORAGE:
359                         recorder_error = RECORDER_ERROR_OUT_OF_STORAGE;
360                         CAM_LOG_ERROR("OUT_OF_STORAGE : 0x%x", m->code);
361                         break;
362                 default:
363                         recorder_error = RECORDER_ERROR_INVALID_OPERATION;
364                         CAM_LOG_ERROR("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                         CAM_LOG_WARNING("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         CAM_LOG_DEBUG("fmt[%d], ch[%d], timestamp[%u], size[%d]",
398                 format, stream->channel, stream->timestamp, stream->length);
399
400         if (handle->user_cb[type]) {
401                 ((recorder_audio_stream_cb)(handle->user_cb[type]))(stream->data, stream->length, format,
402                         stream->channel, stream->timestamp, handle->user_data[type]);
403         } else {
404                 CAM_LOG_WARNING("audio_stream_cb is NULL");
405         }
406
407         return 1;
408 }
409
410
411 static int __mm_muxed_stream_cb(MMCamcorderMuxedStreamDataType *stream, void *user_param)
412 {
413         recorder_s *handle = (recorder_s *)user_param;
414         int type = _RECORDER_EVENT_TYPE_MUXED_STREAM;
415
416         recorder_return_val_if_fail(handle && stream, 0);
417
418         CAM_LOG_DEBUG("size[%d], offset[%llu]", stream->length, stream->offset);
419
420         if (handle->user_cb[type]) {
421                 ((recorder_muxed_stream_cb)(handle->user_cb[type]))(stream->data, stream->length,
422                         stream->offset, handle->user_data[type]);
423         } else {
424                 CAM_LOG_WARNING("muxed_stream_cb is NULL");
425         }
426
427         return 1;
428 }
429
430
431 static int __mm_video_encode_decision_cb(MMCamcorderVideoStreamDataType *stream, void *user_param)
432 {
433         recorder_s *handle = (recorder_s *)user_param;
434         int type = _RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION;
435         bool do_encode = true;
436
437         recorder_return_val_if_fail(handle && stream, 0);
438
439         if (!handle->user_cb[type]) {
440                 CAM_LOG_WARNING("video_encode_decision_cb is NULL");
441                 return true;
442         }
443
444         do_encode = ((recorder_video_encode_decision_cb)(handle->user_cb[type]))(stream, handle->user_data[type]);
445
446         CAM_LOG_DEBUG("do_encode[%d]", do_encode);
447
448         return (int)do_encode;
449 }
450
451
452 static int _recorder_check_and_set_attribute(recorder_h recorder, const char *attribute_name, int set_value)
453 {
454         bool reset_pipeline = false;
455         bool restore_set = false;
456         int ret = MM_ERROR_NONE;
457         int ret2 = MM_ERROR_NONE;
458         int current_value = -1;
459         int current_audio_disable = 0;
460
461         recorder_s *handle = (recorder_s *)recorder;
462         MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
463
464         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
465
466         mm_camcorder_get_state(handle->mm_handle, &mmstate);
467
468         recorder_return_val_if_fail(mmstate < MM_CAMCORDER_STATE_RECORDING, RECORDER_ERROR_INVALID_STATE);
469
470         if (handle->type == _RECORDER_TYPE_AUDIO && mmstate == MM_CAMCORDER_STATE_PREPARE) {
471                 mm_camcorder_get_attributes(handle->mm_handle, NULL,
472                         MMCAM_AUDIO_DISABLE, &current_audio_disable,
473                         attribute_name, &current_value,
474                         NULL);
475
476                 if (current_value != set_value) {
477                         CAM_LOG_INFO("try to reset pipeline");
478
479                         ret = mm_camcorder_stop(handle->mm_handle);
480                         if (ret != MM_ERROR_NONE) {
481                                 CAM_LOG_ERROR("mm_camcorder_stop failed 0x%x", ret);
482                                 return __convert_recorder_error_code(attribute_name, ret);
483                         }
484
485                         ret = mm_camcorder_unrealize(handle->mm_handle);
486                         if (ret != MM_ERROR_NONE) {
487                                 CAM_LOG_ERROR("mm_camcorder_unrealize failed 0x%x", ret);
488                                 mm_camcorder_start(handle->mm_handle);
489                                 return __convert_recorder_error_code(attribute_name, ret);
490                         }
491
492                         reset_pipeline = true;
493                 }
494         }
495
496         if (!strcmp(attribute_name, MMCAM_AUDIO_ENCODER)) {
497                 if (set_value == RECORDER_AUDIO_CODEC_DISABLE) {
498                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
499                                 MMCAM_AUDIO_DISABLE, true,
500                                 NULL);
501                 } else {
502                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
503                                 MMCAM_AUDIO_DISABLE, false,
504                                 MMCAM_AUDIO_ENCODER, set_value,
505                                 NULL);
506                 }
507         } else {
508                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
509                         attribute_name, set_value,
510                         NULL);
511         }
512
513         if (ret != MM_ERROR_NONE)
514                 CAM_LOG_ERROR("set [%s] failed 0x%x", attribute_name, ret);
515
516         if (reset_pipeline) {
517                 ret2 = mm_camcorder_realize(handle->mm_handle);
518                 if (ret2 == MM_ERROR_NONE) {
519                         ret2 = mm_camcorder_start(handle->mm_handle);
520                         if (ret2 == MM_ERROR_NONE) {
521                                 CAM_LOG_WARNING("restart pipeline done.");
522                         } else {
523                                 CAM_LOG_ERROR("mm_camcorder_start failed 0x%x", ret2);
524                                 mm_camcorder_unrealize(handle->mm_handle);
525                         }
526                 } else {
527                         CAM_LOG_ERROR("mm_camcorder_realize failed 0x%x", ret2);
528                 }
529
530                 if (ret2 != MM_ERROR_NONE) {
531                         restore_set = true;
532
533                         /* determine return value */
534                         if (ret == MM_ERROR_NONE)
535                                 ret = ret2;
536                 }
537         }
538
539         if (restore_set) {
540                 ret2 = mm_camcorder_set_attributes(handle->mm_handle, NULL,
541                         MMCAM_AUDIO_DISABLE, current_audio_disable,
542                         attribute_name, current_value,
543                         NULL);
544                 CAM_LOG_WARNING("restore attribute set : 0x%x", ret2);
545
546                 ret2 = mm_camcorder_realize(handle->mm_handle);
547                 CAM_LOG_WARNING("restore mm_camcorder_realize : 0x%x", ret2);
548
549                 ret2 = mm_camcorder_start(handle->mm_handle);
550                 CAM_LOG_WARNING("restore mm_camcorder_realize : 0x%x", ret2);
551                 if (ret2 != MM_ERROR_NONE) {
552                         ret2 = mm_camcorder_unrealize(handle->mm_handle);
553                         CAM_LOG_WARNING("restore mm_camcorder_unrealize : 0x%x", ret2);
554                 }
555         }
556
557         return __convert_recorder_error_code(attribute_name, ret);
558 }
559
560
561 int legacy_recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
562 {
563         int ret = MM_ERROR_NONE;
564         int preview_format = MM_PIXEL_FORMAT_NV12;
565         int camera_device_count = 0;
566         recorder_s *handle = NULL;
567
568         recorder_return_val_if_fail(camera && recorder, RECORDER_ERROR_INVALID_PARAMETER);
569
570         /* Check already used in another recorder */
571         if (legacy_camera_is_used(camera)) {
572                 CAM_LOG_ERROR("[%s] camera is using in another recorder.", __func__);
573                 return RECORDER_ERROR_INVALID_PARAMETER;
574         }
575
576         handle = g_new0(recorder_s, 1);
577
578         handle->src_type = _RECORDER_SOURCE_TYPE_CAMERA;
579         handle->last_max_input_level = LOWSET_DECIBEL;
580         handle->changed_preview_format = -1;
581         handle->mm_source.camera = camera;
582
583         _camera_get_mm_handle(camera, &handle->mm_handle);
584         _camera_set_relay_mm_message_callback(camera, __mm_recorder_msg_cb , (void*)handle);
585         handle->type = _RECORDER_TYPE_VIDEO;
586         legacy_recorder_get_state((recorder_h)handle, (recorder_state_e*)&handle->state);
587
588         mm_camcorder_get_attributes(handle->mm_handle, NULL,
589                 MMCAM_CAMERA_FORMAT, &handle->origin_preview_format,
590                 NULL);
591
592         mm_camcorder_get_attributes(handle->mm_handle, NULL,
593                 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, &preview_format,
594                 NULL);
595
596         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
597                 MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count,
598                 NULL);
599         if (ret != MM_ERROR_NONE) {
600                 g_free(handle);
601                 CAM_LOG_ERROR("get device count error");
602                 return __convert_recorder_error_code(__func__, ret);
603         }
604
605         if (camera_device_count == 0) {
606                 g_free(handle);
607                 CAM_LOG_ERROR("RECORDER_ERROR_NOT_SUPPORTED");
608                 return RECORDER_ERROR_NOT_SUPPORTED;
609         } else {
610                 handle->camera_device_count = camera_device_count;
611         }
612
613         legacy_camera_lock(camera, true);
614         _camera_set_use(camera, true);
615         legacy_camera_lock(camera, false);
616
617         if (handle->state == RECORDER_STATE_CREATED &&
618                 preview_format != handle->origin_preview_format) {
619                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
620                         MMCAM_CAMERA_FORMAT, preview_format,
621                         NULL);
622
623                 if (ret == MM_ERROR_NONE)
624                         handle->changed_preview_format = preview_format;
625         }
626
627         *recorder = (recorder_h)handle;
628
629         return RECORDER_ERROR_NONE;
630 }
631
632
633 int legacy_recorder_create_audiorecorder(recorder_h *recorder)
634 {
635         int ret = MM_ERROR_NONE;
636         int camera_device_count = 0;
637         recorder_s *handle = NULL;
638         MMCamPreset info;
639
640         recorder_return_val_if_fail(recorder, RECORDER_ERROR_INVALID_PARAMETER);
641
642         info.videodev_type = MM_VIDEO_DEVICE_NONE;
643
644         handle = g_new0(recorder_s, 1);
645
646         handle->last_max_input_level = LOWSET_DECIBEL;
647
648         ret = mm_camcorder_create(&handle->mm_handle, &info);
649         if (ret != MM_ERROR_NONE) {
650                 g_free(handle);
651                 CAM_LOG_ERROR("mm_camcorder_create fail");
652                 return __convert_recorder_error_code(__func__, ret);
653         }
654
655         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
656                 MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
657                 NULL);
658         if (ret != MM_ERROR_NONE) {
659                 mm_camcorder_destroy(handle->mm_handle);
660                 g_free(handle);
661                 CAM_LOG_ERROR("AUDIO mode setting fail");
662                 return __convert_recorder_error_code(__func__, ret);
663         }
664
665         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
666                 MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count,
667                 NULL);
668         if (ret != MM_ERROR_NONE) {
669                 mm_camcorder_destroy(handle->mm_handle);
670                 g_free(handle);
671                 CAM_LOG_ERROR("get device count error");
672                 return __convert_recorder_error_code(__func__, ret);
673         } else {
674                 handle->camera_device_count = camera_device_count;
675         }
676         handle->state = RECORDER_STATE_CREATED;
677         handle->mm_source.camera = NULL;
678         handle->type = _RECORDER_TYPE_AUDIO;
679
680         mm_camcorder_set_message_callback(handle->mm_handle, __mm_recorder_msg_cb, (void*)handle);
681
682         *recorder = (recorder_h)handle;
683
684         return RECORDER_ERROR_NONE;
685 }
686
687
688 int legacy_recorder_get_state(recorder_h recorder, recorder_state_e *state)
689 {
690         int ret = MM_ERROR_NONE;
691         recorder_s *handle = (recorder_s *)recorder;
692         MMCamcorderStateType mm_state = MM_CAMCORDER_STATE_NONE;
693         MMCamcorderStateType mm_old_state = MM_CAMCORDER_STATE_NONE;
694
695         recorder_return_val_if_fail(handle && state, RECORDER_ERROR_INVALID_PARAMETER);
696
697         ret = mm_camcorder_get_state2(handle->mm_handle, &mm_state, &mm_old_state);
698         if (ret != MM_ERROR_NONE)
699                 return __convert_recorder_error_code(__func__, ret);
700
701         *state = __recorder_state_convert(mm_state, mm_old_state);
702
703         return RECORDER_ERROR_NONE;
704 }
705
706
707 int legacy_recorder_destroy(recorder_h recorder)
708 {
709         int ret = MM_ERROR_NONE;
710         int preview_format;
711         recorder_s *handle = (recorder_s *)recorder;
712
713         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
714
715         if (handle->type == _RECORDER_TYPE_VIDEO) {
716                 MMCamcorderStateType mm_state = MM_CAMCORDER_STATE_NONE;
717
718                 /* check state */
719                 ret = mm_camcorder_get_state(handle->mm_handle, &mm_state);
720                 if (ret != MM_ERROR_NONE) {
721                         CAM_LOG_ERROR("get state failed 0x%x", ret);
722                         return __convert_recorder_error_code(__func__, ret);
723                 }
724
725                 if (mm_state >= MM_CAMCORDER_STATE_RECORDING) {
726                         CAM_LOG_ERROR("NOW RECORDING[%d], should not destroy", mm_state);
727                         return RECORDER_ERROR_INVALID_STATE;
728                 }
729
730                 /* set to unused */
731                 legacy_camera_lock(handle->mm_source.camera, true);
732
733                 _camera_set_use(handle->mm_source.camera, false);
734
735                 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
736                         MMCAM_CAMERA_FORMAT, &preview_format,
737                         NULL);
738
739                 /* preview format was changed? */
740                 if (ret == MM_ERROR_NONE &&
741                         preview_format == handle->changed_preview_format &&
742                         preview_format != handle->origin_preview_format) {
743                         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
744                                 MMCAM_CAMERA_FORMAT, handle->origin_preview_format,
745                                 NULL);
746                 }
747
748                 if (ret == MM_ERROR_NONE) {
749                         _camera_set_relay_mm_message_callback(handle->mm_source.camera, NULL, NULL);
750                         legacy_camera_send_signal(handle->mm_source.camera);
751                 }
752
753                 legacy_camera_lock(handle->mm_source.camera, false);
754         } else {
755                 ret = mm_camcorder_destroy(handle->mm_handle);
756         }
757
758         if (ret == MM_ERROR_NONE)
759                 g_free(handle);
760
761         return __convert_recorder_error_code(__func__, ret);
762 }
763
764
765 int legacy_recorder_prepare(recorder_h recorder)
766 {
767         int ret = MM_ERROR_NONE;
768         recorder_s *handle = (recorder_s *)recorder;
769         MMCamcorderStateType mmstate;
770
771         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
772
773         if (handle->type == _RECORDER_TYPE_VIDEO)
774                 return __convert_error_code_camera_to_recorder(legacy_camera_start_preview(handle->mm_source.camera));
775
776         ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
777
778         if (ret == MM_ERROR_NONE && mmstate < MM_CAMCORDER_STATE_READY) {
779                 ret = mm_camcorder_realize(handle->mm_handle);
780                 if (ret != MM_ERROR_NONE) {
781                         CAM_LOG_ERROR("mm_camcorder_realize fail");
782                         return __convert_recorder_error_code(__func__, ret);
783                 }
784         }
785
786         ret = mm_camcorder_start(handle->mm_handle);
787         if (ret != MM_ERROR_NONE) {
788                 CAM_LOG_ERROR("mm_camcorder_start fail");
789                 mm_camcorder_unrealize(handle->mm_handle);
790                 return __convert_recorder_error_code(__func__, ret);
791         }
792
793         return RECORDER_ERROR_NONE;
794 }
795
796
797 int legacy_recorder_unprepare(recorder_h recorder)
798 {
799         int ret = MM_ERROR_NONE;
800         recorder_s *handle = (recorder_s *)recorder;
801         MMCamcorderStateType mmstate;
802
803         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
804
805         ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
806         if (ret == MM_ERROR_NONE && mmstate == MM_CAMCORDER_STATE_PREPARE) {
807                 ret = mm_camcorder_stop(handle->mm_handle);
808                 if (ret != MM_ERROR_NONE)
809                         CAM_LOG_ERROR("mm_camcorder_stop fail");
810         }
811
812         if (ret == MM_ERROR_NONE) {
813                 ret = mm_camcorder_unrealize(handle->mm_handle);
814                 if (ret != MM_ERROR_NONE) {
815                         CAM_LOG_ERROR("mm_camcorder_unrealize fail");
816                         mm_camcorder_start(handle->mm_handle);
817                 }
818         }
819
820         return __convert_recorder_error_code(__func__, ret);
821 }
822
823
824 int legacy_recorder_start(recorder_h recorder)
825 {
826         recorder_s *handle = (recorder_s *)recorder;
827
828         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
829
830         return __convert_recorder_error_code(__func__, mm_camcorder_record(handle->mm_handle));
831 }
832
833
834 int legacy_recorder_pause(recorder_h recorder)
835 {
836         recorder_s *handle = (recorder_s *)recorder;
837
838         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
839
840         return __convert_recorder_error_code(__func__, mm_camcorder_pause(handle->mm_handle));
841 }
842
843
844 int legacy_recorder_commit(recorder_h recorder)
845 {
846         recorder_s *handle = (recorder_s *)recorder;
847
848         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
849
850         return __convert_recorder_error_code(__func__, mm_camcorder_commit(handle->mm_handle));
851 }
852
853
854 int legacy_recorder_cancel(recorder_h recorder)
855 {
856         recorder_s *handle = (recorder_s *)recorder;
857
858         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
859
860         return __convert_recorder_error_code(__func__, mm_camcorder_cancel(handle->mm_handle));
861 }
862
863
864 int legacy_recorder_set_video_resolution(recorder_h recorder, int width, int height)
865 {
866         int ret = MM_ERROR_NONE;
867         recorder_s *handle = (recorder_s *)recorder;
868         recorder_state_e state = RECORDER_STATE_NONE;
869
870         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
871         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
872
873         legacy_recorder_get_state(recorder, &state);
874         recorder_return_val_if_fail(state <= RECORDER_STATE_READY, RECORDER_ERROR_INVALID_STATE);
875
876         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
877                 MMCAM_VIDEO_WIDTH, width,
878                 MMCAM_VIDEO_HEIGHT, height,
879                 NULL);
880
881         return __convert_recorder_error_code(__func__, ret);
882 }
883
884
885 int legacy_recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
886 {
887         int ret = MM_ERROR_NONE;
888         recorder_s *handle = (recorder_s *)recorder;
889
890         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
891         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
892         recorder_return_val_if_fail(width && height, RECORDER_ERROR_INVALID_PARAMETER);
893
894         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
895                 MMCAM_VIDEO_WIDTH, width,
896                 MMCAM_VIDEO_HEIGHT, height,
897                 NULL);
898
899         return __convert_recorder_error_code(__func__, ret);
900 }
901
902
903 int legacy_recorder_foreach_supported_video_resolution(recorder_h recorder,
904         recorder_supported_video_resolution_cb foreach_cb, void *user_data)
905 {
906         int i = 0;
907         int ret = MM_ERROR_NONE;
908         recorder_s *handle = (recorder_s *)recorder;
909         MMCamAttrsInfo video_width;
910         MMCamAttrsInfo video_height;
911
912         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
913         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
914         recorder_return_val_if_fail(foreach_cb, RECORDER_ERROR_INVALID_PARAMETER);
915
916         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_WIDTH, &video_width);
917         ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_HEIGHT, &video_height);
918
919         if (ret != MM_ERROR_NONE)
920                 return __convert_recorder_error_code(__func__, ret);
921
922         for (i = 0 ; i < video_width.int_array.count ; i++) {
923                 if (!foreach_cb(video_width.int_array.array[i], video_height.int_array.array[i], user_data))
924                         break;
925         }
926
927         return RECORDER_ERROR_NONE;
928 }
929
930
931 int legacy_recorder_get_audio_level(recorder_h recorder, double *level)
932 {
933         recorder_s *handle = (recorder_s *)recorder;
934         recorder_state_e state;
935
936         recorder_return_val_if_fail(handle && level, RECORDER_ERROR_INVALID_PARAMETER);
937
938         legacy_recorder_get_state(recorder, &state);
939
940         recorder_return_val_if_fail(state >= RECORDER_STATE_RECORDING, RECORDER_ERROR_INVALID_STATE);
941
942         *level = handle->last_max_input_level;
943         handle->last_max_input_level = LOWSET_DECIBEL;
944
945         return RECORDER_ERROR_NONE;
946 }
947
948
949 int legacy_recorder_set_filename(recorder_h recorder,  const char *filename)
950 {
951         int ret = MM_ERROR_NONE;
952         recorder_s *handle = (recorder_s *)recorder;
953         MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
954
955         recorder_return_val_if_fail(handle && filename, RECORDER_ERROR_INVALID_PARAMETER);
956
957         mm_camcorder_get_state(handle->mm_handle, &mmstate);
958
959         recorder_return_val_if_fail(mmstate < MM_CAMCORDER_STATE_RECORDING, RECORDER_ERROR_INVALID_STATE);
960
961         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
962                 MMCAM_TARGET_FILENAME, filename, strlen(filename),
963                 NULL);
964
965         return __convert_recorder_error_code(__func__, ret);
966 }
967
968
969 int legacy_recorder_get_filename(recorder_h recorder,  char **filename)
970 {
971         int ret = MM_ERROR_NONE;
972         char *record_filename = NULL;
973         int record_filename_size;
974         recorder_s *handle = (recorder_s *)recorder;
975
976         recorder_return_val_if_fail(handle && filename, RECORDER_ERROR_INVALID_PARAMETER);
977
978         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
979                 MMCAM_TARGET_FILENAME, &record_filename, &record_filename_size,
980                 NULL);
981         if (ret == MM_ERROR_NONE && record_filename) {
982                 *filename = strdup(record_filename);
983         } else {
984                 CAM_LOG_ERROR("internal return (0x%08x), get filename p:%p", ret, record_filename);
985                 *filename = NULL;
986         }
987
988         return __convert_recorder_error_code(__func__, ret);
989 }
990
991
992 int legacy_recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
993 {
994         int format_table[7] = {
995                 MM_FILE_FORMAT_3GP, /* RECORDER_FILE_FORMAT_3GP */
996                 MM_FILE_FORMAT_MP4, /* RECORDER_FILE_FORMAT_MP4 */
997                 MM_FILE_FORMAT_AMR, /* RECORDER_FILE_FORMAT_AMR */
998                 MM_FILE_FORMAT_AAC, /* RECORDER_FILE_FORMAT_ADTS */
999                 MM_FILE_FORMAT_WAV, /* RECORDER_FILE_FORMAT_WAV */
1000                 MM_FILE_FORMAT_OGG,  /* RECORDER_FILE_FORMAT_OGG */
1001                 MM_FILE_FORMAT_M2TS /* RECORDER_FILE_FORMAT_M2TS */
1002         };
1003
1004         recorder_return_val_if_fail(format <= RECORDER_FILE_FORMAT_M2TS, RECORDER_ERROR_INVALID_PARAMETER);
1005
1006         return _recorder_check_and_set_attribute(recorder, MMCAM_FILE_FORMAT, format_table[format]);
1007 }
1008
1009
1010 int legacy_recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
1011 {
1012         int ret = MM_ERROR_NONE;
1013         recorder_s *handle = (recorder_s *)recorder;
1014         int mm_format;
1015
1016         recorder_return_val_if_fail(handle && format, RECORDER_ERROR_INVALID_PARAMETER);
1017
1018         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1019                 MMCAM_FILE_FORMAT, &mm_format,
1020                 NULL);
1021         if (ret == MM_ERROR_NONE) {
1022                 switch (mm_format) {
1023                 case MM_FILE_FORMAT_3GP:
1024                         *format = RECORDER_FILE_FORMAT_3GP;
1025                         break;
1026                 case MM_FILE_FORMAT_MP4:
1027                         *format = RECORDER_FILE_FORMAT_MP4;
1028                         break;
1029                 case MM_FILE_FORMAT_AMR:
1030                         *format = RECORDER_FILE_FORMAT_AMR;
1031                         break;
1032                 case MM_FILE_FORMAT_AAC:
1033                         *format = RECORDER_FILE_FORMAT_ADTS;
1034                         break;
1035                 case MM_FILE_FORMAT_WAV:
1036                         *format = RECORDER_FILE_FORMAT_WAV;
1037                         break;
1038                 case MM_FILE_FORMAT_OGG:
1039                         *format = RECORDER_FILE_FORMAT_OGG;
1040                         break;
1041                 case MM_FILE_FORMAT_M2TS:
1042                         *format = RECORDER_FILE_FORMAT_M2TS;
1043                         break;
1044                 default:
1045                         ret = MM_ERROR_CAMCORDER_INTERNAL;
1046                         break;
1047                 }
1048         }
1049
1050         return __convert_recorder_error_code(__func__, ret);
1051 }
1052
1053
1054 int legacy_recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
1055 {
1056         recorder_s *handle = (recorder_s *)recorder;
1057
1058         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1059
1060         handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
1061         handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
1062
1063         return RECORDER_ERROR_NONE;
1064 }
1065
1066
1067 int legacy_recorder_unset_state_changed_cb(recorder_h recorder)
1068 {
1069         recorder_s *handle = (recorder_s *)recorder;
1070
1071         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1072
1073         handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1074         handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1075
1076         return RECORDER_ERROR_NONE;
1077 }
1078
1079
1080 int legacy_recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
1081 {
1082         recorder_s *handle = (recorder_s *)recorder;
1083
1084         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1085
1086         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
1087         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
1088
1089         return RECORDER_ERROR_NONE;
1090 }
1091
1092
1093 int legacy_recorder_unset_interrupted_cb(recorder_h recorder)
1094 {
1095         recorder_s *handle = (recorder_s *)recorder;
1096
1097         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1098
1099         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1100         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1101
1102         return RECORDER_ERROR_NONE;
1103 }
1104
1105
1106 int legacy_recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
1107 {
1108         recorder_s *handle = (recorder_s *)recorder;
1109
1110         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1111
1112         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
1113         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
1114
1115         return RECORDER_ERROR_NONE;
1116 }
1117
1118
1119 int legacy_recorder_unset_interrupt_started_cb(recorder_h recorder)
1120 {
1121         recorder_s *handle = (recorder_s *)recorder;
1122
1123         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1124
1125         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
1126         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
1127
1128         return RECORDER_ERROR_NONE;
1129 }
1130
1131
1132 int legacy_recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
1133 {
1134         int ret = MM_ERROR_NONE;
1135         recorder_s *handle = (recorder_s *)recorder;
1136
1137         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1138
1139         ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, __mm_audio_stream_cb, handle);
1140         if (ret == MM_ERROR_NONE) {
1141                 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
1142                 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
1143         }
1144
1145         return __convert_recorder_error_code(__func__, ret);
1146 }
1147
1148
1149 int legacy_recorder_unset_audio_stream_cb(recorder_h recorder)
1150 {
1151         int ret = MM_ERROR_NONE;
1152         recorder_s *handle = (recorder_s *)recorder;
1153
1154         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1155
1156         handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1157         handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1158
1159         ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, NULL, NULL);
1160
1161         return __convert_recorder_error_code(__func__, ret);
1162 }
1163
1164
1165 int legacy_recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void* user_data)
1166 {
1167         int ret = MM_ERROR_NONE;
1168         recorder_s *handle = (recorder_s *)recorder;
1169         recorder_state_e state = RECORDER_STATE_NONE;
1170
1171         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1172
1173         legacy_recorder_get_state(recorder, &state);
1174
1175         recorder_return_val_if_fail(state <= RECORDER_STATE_READY, RECORDER_ERROR_INVALID_STATE);
1176
1177         ret = mm_camcorder_set_muxed_stream_callback(handle->mm_handle, __mm_muxed_stream_cb, handle);
1178         if (ret == MM_ERROR_NONE) {
1179                 handle->user_cb[_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
1180                 handle->user_data[_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
1181         }
1182
1183         return __convert_recorder_error_code(__func__, ret);
1184 }
1185
1186
1187 int legacy_recorder_unset_muxed_stream_cb(recorder_h recorder)
1188 {
1189         int ret = MM_ERROR_NONE;
1190         recorder_s *handle = (recorder_s *)recorder;
1191         recorder_state_e state = RECORDER_STATE_NONE;
1192
1193         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1194
1195         legacy_recorder_get_state(recorder, &state);
1196
1197         recorder_return_val_if_fail(state <= RECORDER_STATE_READY, RECORDER_ERROR_INVALID_STATE);
1198
1199         ret = mm_camcorder_set_muxed_stream_callback(handle->mm_handle, NULL, NULL);
1200         if (ret == MM_ERROR_NONE) {
1201                 handle->user_cb[_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
1202                 handle->user_data[_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
1203         }
1204
1205         return __convert_recorder_error_code(__func__, ret);
1206 }
1207
1208
1209 int legacy_recorder_set_video_encode_decision_cb(recorder_h recorder, recorder_video_encode_decision_cb callback, void *user_data)
1210 {
1211         int ret = MM_ERROR_NONE;
1212         recorder_s *handle = (recorder_s *)recorder;
1213         recorder_state_e state = RECORDER_STATE_NONE;
1214
1215         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1216         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1217
1218         legacy_recorder_get_state(recorder, &state);
1219         recorder_return_val_if_fail(state <= RECORDER_STATE_READY, RECORDER_ERROR_INVALID_STATE);
1220
1221         ret = mm_camcorder_set_video_encode_decision_callback(handle->mm_handle, __mm_video_encode_decision_cb, handle);
1222         if (ret == MM_ERROR_NONE) {
1223                 handle->user_cb[_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = callback;
1224                 handle->user_data[_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = user_data;
1225         }
1226
1227         return __convert_recorder_error_code(__func__, ret);
1228 }
1229
1230
1231 int legacy_recorder_unset_video_encode_decision_cb(recorder_h recorder)
1232 {
1233         int ret = MM_ERROR_NONE;
1234         recorder_s *handle = (recorder_s *)recorder;
1235         recorder_state_e state = RECORDER_STATE_NONE;
1236
1237         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1238         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1239
1240         legacy_recorder_get_state(recorder, &state);
1241         recorder_return_val_if_fail(state <= RECORDER_STATE_READY, RECORDER_ERROR_INVALID_STATE);
1242
1243         ret = mm_camcorder_set_video_encode_decision_callback(handle->mm_handle, NULL, NULL);
1244         if (ret == MM_ERROR_NONE) {
1245                 handle->user_cb[_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = NULL;
1246                 handle->user_data[_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = NULL;
1247         }
1248
1249         return __convert_recorder_error_code(__func__, ret);
1250 }
1251
1252
1253 int legacy_recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
1254 {
1255         recorder_s *handle = (recorder_s *)recorder;
1256
1257         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1258
1259         handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = callback;
1260         handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = user_data;
1261
1262         return RECORDER_ERROR_NONE;
1263 }
1264
1265
1266 int legacy_recorder_unset_error_cb(recorder_h recorder)
1267 {
1268         recorder_s *handle = (recorder_s *)recorder;
1269
1270         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1271
1272         handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1273         handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1274
1275         return RECORDER_ERROR_NONE;
1276 }
1277
1278
1279 int legacy_recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
1280 {
1281         recorder_s *handle = (recorder_s *)recorder;
1282
1283         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1284
1285         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
1286         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
1287
1288         return RECORDER_ERROR_NONE;
1289 }
1290
1291
1292 int legacy_recorder_unset_recording_status_cb(recorder_h recorder)
1293 {
1294         recorder_s *handle = (recorder_s *)recorder;
1295
1296         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1297
1298         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1299         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1300
1301         return RECORDER_ERROR_NONE;
1302 }
1303
1304
1305 int legacy_recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
1306 {
1307         recorder_s *handle = (recorder_s *)recorder;
1308
1309         recorder_return_val_if_fail(handle && callback, RECORDER_ERROR_INVALID_PARAMETER);
1310
1311         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
1312         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
1313
1314         return RECORDER_ERROR_NONE;
1315 }
1316
1317
1318 int legacy_recorder_unset_recording_limit_reached_cb(recorder_h recorder)
1319 {
1320         recorder_s *handle = (recorder_s *)recorder;
1321
1322         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1323
1324         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1325         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1326
1327         return RECORDER_ERROR_NONE;
1328 }
1329
1330
1331 int legacy_recorder_foreach_supported_file_format(recorder_h recorder,
1332         recorder_supported_file_format_cb foreach_cb, const char* codec_type, int codec, void *user_data)
1333 {
1334         int i = 0;
1335         int ret = MM_ERROR_NONE;
1336         recorder_s *handle = (recorder_s *)recorder;
1337         MMCamAttrsInfo info;
1338         int format;
1339
1340         recorder_return_val_if_fail(handle && foreach_cb, RECORDER_ERROR_INVALID_PARAMETER);
1341
1342         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILE_FORMAT, &info);
1343         if (ret != MM_ERROR_NONE) {
1344                 CAM_LOG_ERROR("mm_camcorder_get_attribute_info failed 0x%x", ret);
1345                 return __convert_recorder_error_code(__func__, ret);;
1346         }
1347
1348         for (i = 0 ; i < info.int_array.count ; i++) {
1349                 switch (info.int_array.array[i]) {
1350                 case MM_FILE_FORMAT_3GP:
1351                         format = RECORDER_FILE_FORMAT_3GP;
1352                         break;
1353                 case MM_FILE_FORMAT_MP4:
1354                         format = RECORDER_FILE_FORMAT_MP4;
1355                         break;
1356                 case MM_FILE_FORMAT_AMR:
1357                         format = RECORDER_FILE_FORMAT_AMR;
1358                         break;
1359                 case MM_FILE_FORMAT_AAC:
1360                         format = RECORDER_FILE_FORMAT_ADTS;
1361                         break;
1362                 case MM_FILE_FORMAT_WAV:
1363                         format = RECORDER_FILE_FORMAT_WAV;
1364                         break;
1365                 case MM_FILE_FORMAT_M2TS:
1366                         format = RECORDER_FILE_FORMAT_M2TS;
1367                         break;
1368                 default:
1369                         format = -1;
1370                         break;
1371                 }
1372
1373                 if (codec_type != NULL && format != -1)
1374                         ret = mm_camcorder_check_codec_fileformat_compatibility((const char*)codec_type, codec, format);
1375
1376                 if (ret == MM_ERROR_NONE && format != -1 && !foreach_cb(format, user_data))
1377                         break;
1378         }
1379
1380         return RECORDER_ERROR_NONE;
1381 }
1382
1383
1384 int legacy_recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
1385 {
1386         int ret = MM_ERROR_NONE;
1387         recorder_s *handle = (recorder_s *)recorder;
1388
1389         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1390         recorder_return_val_if_fail(kbyte >= 0, RECORDER_ERROR_INVALID_PARAMETER);
1391
1392         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1393                 MMCAM_TARGET_MAX_SIZE, kbyte,
1394                 NULL);
1395
1396         return __convert_recorder_error_code(__func__, ret);
1397 }
1398
1399
1400 int legacy_recorder_attr_set_time_limit(recorder_h recorder, int second)
1401 {
1402         int ret = MM_ERROR_NONE;
1403         recorder_s *handle = (recorder_s *)recorder;
1404
1405         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1406         recorder_return_val_if_fail(second >= 0, RECORDER_ERROR_INVALID_PARAMETER);
1407
1408         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1409                 MMCAM_TARGET_TIME_LIMIT, second,
1410                 NULL);
1411
1412         return __convert_recorder_error_code(__func__, ret);
1413 }
1414
1415
1416 int legacy_recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
1417 {
1418         recorder_return_val_if_fail(device <= RECORDER_AUDIO_DEVICE_MODEM, RECORDER_ERROR_INVALID_PARAMETER);
1419
1420         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_DEVICE, device);
1421 }
1422
1423
1424 int legacy_recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
1425 {
1426         recorder_s *handle = (recorder_s *)recorder;
1427         int audio_table[5] = {
1428                 MM_AUDIO_CODEC_AMR,     /* RECORDER_AUDIO_CODEC_AMR */
1429                 MM_AUDIO_CODEC_AAC,     /* RECORDER_AUDIO_CODEC_AAC */
1430                 MM_AUDIO_CODEC_VORBIS,  /* RECORDER_AUDIO_CODEC_VORBIS */
1431                 MM_AUDIO_CODEC_WAVE,    /* RECORDER_AUDIO_CODEC_PCM */
1432                 MM_AUDIO_CODEC_MP3      /* RECORDER_AUDIO_CODEC_MP3 */
1433         };
1434
1435         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1436         recorder_return_val_if_fail(codec >= RECORDER_AUDIO_CODEC_DISABLE && \
1437                 codec <= RECORDER_AUDIO_CODEC_MP3, RECORDER_ERROR_INVALID_PARAMETER);
1438         recorder_return_val_if_fail(handle->type != _RECORDER_TYPE_AUDIO || \
1439                 codec != RECORDER_AUDIO_CODEC_DISABLE, RECORDER_ERROR_NOT_SUPPORTED);
1440
1441         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER,
1442                 codec == RECORDER_AUDIO_CODEC_DISABLE ? RECORDER_AUDIO_CODEC_DISABLE : audio_table[codec]);
1443 }
1444
1445
1446 int legacy_recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
1447 {
1448         int ret = MM_ERROR_NONE;
1449         int mm_codec = 0;
1450         int audio_disable = 0;
1451         recorder_s *handle = (recorder_s *)recorder;
1452
1453         recorder_return_val_if_fail(handle && codec, RECORDER_ERROR_INVALID_PARAMETER);
1454
1455         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1456                 MMCAM_AUDIO_ENCODER, &mm_codec,
1457                 MMCAM_AUDIO_DISABLE, &audio_disable,
1458                 NULL);
1459
1460         if (ret == MM_ERROR_NONE && audio_disable == 0) {
1461                 switch (mm_codec) {
1462                 case MM_AUDIO_CODEC_AMR:
1463                         *codec = RECORDER_AUDIO_CODEC_AMR;
1464                         break;
1465                 case MM_AUDIO_CODEC_AAC:
1466                         *codec = RECORDER_AUDIO_CODEC_AAC;
1467                         break;
1468                 case MM_AUDIO_CODEC_VORBIS:
1469                         *codec = RECORDER_AUDIO_CODEC_VORBIS;
1470                         break;
1471                 case MM_AUDIO_CODEC_WAVE:
1472                         *codec = RECORDER_AUDIO_CODEC_PCM;
1473                         break;
1474                 default:
1475                         ret = MM_ERROR_CAMCORDER_INTERNAL;
1476                         break;
1477                 }
1478         } else if (ret == MM_ERROR_NONE && audio_disable) {
1479                 *codec = RECORDER_AUDIO_CODEC_DISABLE;
1480         }
1481
1482         return __convert_recorder_error_code(__func__, ret);
1483 }
1484
1485
1486 int legacy_recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
1487 {
1488         int ret = MM_ERROR_NONE;
1489         int video_table[4] = {
1490                 MM_VIDEO_CODEC_H263,     /* RECORDER_VIDEO_CODEC_H263 */
1491                 MM_VIDEO_CODEC_H264,     /* RECORDER_VIDEO_CODEC_H264 */
1492                 MM_VIDEO_CODEC_MPEG4,    /* RECORDER_VIDEO_CODEC_MPEG4 */
1493                 MM_VIDEO_CODEC_THEORA    /* RECORDER_VIDEO_CODEC_THEORA */
1494         };
1495         recorder_s *handle = (recorder_s *)recorder;
1496         recorder_state_e state = RECORDER_STATE_NONE;
1497
1498         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1499         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1500         recorder_return_val_if_fail(codec <= RECORDER_VIDEO_CODEC_THEORA, RECORDER_ERROR_INVALID_PARAMETER);
1501
1502         legacy_recorder_get_state(recorder, &state);
1503
1504         recorder_return_val_if_fail(state <= RECORDER_STATE_READY, RECORDER_ERROR_INVALID_STATE);
1505
1506         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1507                 MMCAM_VIDEO_ENCODER, video_table[codec],
1508                 NULL);
1509
1510         return __convert_recorder_error_code(__func__, ret);
1511 }
1512
1513
1514 int legacy_recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
1515 {
1516         int ret = MM_ERROR_NONE;
1517         int mm_codec = 0;
1518         recorder_s *handle = (recorder_s *)recorder;
1519
1520         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1521         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1522         recorder_return_val_if_fail(codec, RECORDER_ERROR_INVALID_PARAMETER);
1523
1524         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1525                 MMCAM_VIDEO_ENCODER, &mm_codec,
1526                 NULL);
1527         if (ret == MM_ERROR_NONE) {
1528                 switch (mm_codec) {
1529                 case MM_VIDEO_CODEC_H263:
1530                         *codec = RECORDER_VIDEO_CODEC_H263;
1531                         break;
1532                 case MM_VIDEO_CODEC_H264:
1533                         *codec = RECORDER_VIDEO_CODEC_H264;
1534                         break;
1535                 case MM_VIDEO_CODEC_MPEG4:
1536                         *codec = RECORDER_VIDEO_CODEC_MPEG4;
1537                         break;
1538                 case MM_VIDEO_CODEC_THEORA:
1539                         *codec = RECORDER_VIDEO_CODEC_THEORA;
1540                         break;
1541                 default:
1542                         ret = MM_ERROR_CAMCORDER_INTERNAL;
1543                         break;
1544                 }
1545         }
1546
1547         return __convert_recorder_error_code(__func__, ret);
1548 }
1549
1550
1551 int legacy_recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
1552 {
1553         recorder_return_val_if_fail(samplerate > 0, RECORDER_ERROR_INVALID_PARAMETER);
1554
1555         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_SAMPLERATE, samplerate);
1556 }
1557
1558
1559 int legacy_recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
1560 {
1561         recorder_return_val_if_fail(bitrate > 0, RECORDER_ERROR_INVALID_PARAMETER);
1562
1563         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER_BITRATE, bitrate);
1564 }
1565
1566
1567 int legacy_recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
1568 {
1569         int ret = MM_ERROR_NONE;
1570         recorder_s *handle = (recorder_s *)recorder;
1571
1572         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1573         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1574         recorder_return_val_if_fail(bitrate > 0, RECORDER_ERROR_INVALID_PARAMETER);
1575
1576         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1577                 MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1578                 NULL);
1579
1580         return __convert_recorder_error_code(__func__, ret);
1581 }
1582
1583
1584 int legacy_recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
1585 {
1586         int ret = MM_ERROR_NONE;
1587         recorder_s *handle = (recorder_s *)recorder;
1588
1589         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1590
1591         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1592                 MMCAM_TARGET_MAX_SIZE, kbyte,
1593                 NULL);
1594
1595         return __convert_recorder_error_code(__func__, ret);
1596 }
1597
1598
1599 int legacy_recorder_attr_get_time_limit(recorder_h recorder, int *second)
1600 {
1601         int ret = MM_ERROR_NONE;
1602         recorder_s *handle = (recorder_s *)recorder;
1603
1604         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1605
1606         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1607                 MMCAM_TARGET_TIME_LIMIT, second,
1608                 NULL);
1609
1610         return __convert_recorder_error_code(__func__, ret);
1611 }
1612
1613
1614 int legacy_recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
1615 {
1616         int ret = MM_ERROR_NONE;
1617         recorder_s *handle = (recorder_s *)recorder;
1618
1619         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1620
1621         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1622                 MMCAM_AUDIO_DEVICE, device,
1623                 NULL);
1624
1625         return __convert_recorder_error_code(__func__, ret);
1626 }
1627
1628
1629 int legacy_recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
1630 {
1631         int ret = MM_ERROR_NONE;
1632         recorder_s *handle = (recorder_s *)recorder;
1633
1634         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1635
1636         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1637                 MMCAM_AUDIO_SAMPLERATE, samplerate,
1638                 NULL);
1639
1640         return __convert_recorder_error_code(__func__, ret);
1641 }
1642
1643
1644 int legacy_recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
1645 {
1646         int ret = MM_ERROR_NONE;
1647         recorder_s *handle = (recorder_s *)recorder;
1648
1649         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1650
1651         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1652                 MMCAM_AUDIO_ENCODER_BITRATE, bitrate,
1653                 NULL);
1654
1655         return __convert_recorder_error_code(__func__, ret);
1656 }
1657
1658
1659 int legacy_recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
1660 {
1661         int ret = MM_ERROR_NONE;
1662         recorder_s *handle = (recorder_s *)recorder;
1663
1664         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1665         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1666
1667         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1668                 MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1669                 NULL);
1670
1671         return __convert_recorder_error_code(__func__, ret);
1672 }
1673
1674
1675 int legacy_recorder_foreach_supported_audio_encoder(recorder_h recorder,
1676         recorder_supported_audio_encoder_cb foreach_cb, const char* codec_type, int format, void *user_data)
1677 {
1678         int i = 0;
1679         int ret = MM_ERROR_NONE;
1680         int codec;
1681         recorder_s *handle = (recorder_s *)recorder;
1682         MMCamAttrsInfo info;
1683
1684         recorder_return_val_if_fail(handle && foreach_cb, RECORDER_ERROR_INVALID_PARAMETER);
1685
1686         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_AUDIO_ENCODER, &info);
1687         if (ret != MM_ERROR_NONE)
1688                 return __convert_recorder_error_code(__func__, ret);
1689
1690         for (i = 0 ; i < info.int_array.count ; i++) {
1691                 switch (info.int_array.array[i]) {
1692                 case MM_AUDIO_CODEC_AMR:
1693                         codec = RECORDER_AUDIO_CODEC_AMR;
1694                         break;
1695                 case MM_AUDIO_CODEC_AAC:
1696                         codec = RECORDER_AUDIO_CODEC_AAC;
1697                         break;
1698                 case MM_AUDIO_CODEC_VORBIS:
1699                         codec = RECORDER_AUDIO_CODEC_VORBIS;
1700                         break;
1701                 case MM_AUDIO_CODEC_WAVE:
1702                         codec = RECORDER_AUDIO_CODEC_PCM;
1703                         break;
1704                 default:
1705                         codec = -1;
1706                         break;
1707                 }
1708
1709                 if (codec_type != NULL && codec != -1)
1710                         ret = mm_camcorder_check_codec_fileformat_compatibility((const char*)codec_type, codec, format);
1711
1712                 if (ret == MM_ERROR_NONE && codec != -1 && !foreach_cb(codec, user_data))
1713                         break;
1714         }
1715
1716         return RECORDER_ERROR_NONE;
1717 }
1718
1719
1720 int legacy_recorder_foreach_supported_video_encoder(recorder_h recorder,
1721         recorder_supported_video_encoder_cb foreach_cb, const char* codec_type, int format, void *user_data)
1722 {
1723         int i = 0;
1724         int ret = MM_ERROR_NONE;
1725         int codec;
1726         recorder_s *handle = (recorder_s *)recorder;
1727         MMCamAttrsInfo info;
1728
1729         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1730         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1731         recorder_return_val_if_fail(foreach_cb, RECORDER_ERROR_INVALID_PARAMETER);
1732
1733         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_ENCODER, &info);
1734         if (ret != MM_ERROR_NONE)
1735                 return __convert_recorder_error_code(__func__, ret);
1736
1737         for (i = 0 ; i < info.int_array.count ; i++) {
1738                 switch (info.int_array.array[i]) {
1739                 case MM_VIDEO_CODEC_H263:
1740                         codec = RECORDER_VIDEO_CODEC_H263;
1741                         break;
1742                 case MM_VIDEO_CODEC_H264:
1743                         codec = RECORDER_VIDEO_CODEC_H264;
1744                         break;
1745                 case MM_VIDEO_CODEC_MPEG4:
1746                         codec = RECORDER_VIDEO_CODEC_MPEG4;
1747                         break;
1748                 case MM_VIDEO_CODEC_THEORA:
1749                         codec = RECORDER_VIDEO_CODEC_THEORA;
1750                         break;
1751                 default:
1752                         codec = -1;
1753                         break;
1754                 }
1755
1756                 if (codec_type != NULL && codec != -1)
1757                         ret = mm_camcorder_check_codec_fileformat_compatibility((const char*)codec_type, codec, format);
1758
1759                 if (ret == MM_ERROR_NONE && codec != -1 && !foreach_cb(codec, user_data))
1760                         break;
1761         }
1762
1763         return RECORDER_ERROR_NONE;
1764 }
1765
1766
1767 int legacy_recorder_attr_set_mute(recorder_h recorder, bool enable)
1768 {
1769         int ret = MM_ERROR_NONE;
1770         recorder_s *handle = (recorder_s *)recorder;
1771
1772         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1773
1774         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1775                 MMCAM_AUDIO_VOLUME, enable ? 0.0 : 1.0,
1776                 NULL);
1777
1778         return  __convert_recorder_error_code(__func__, ret);
1779 }
1780
1781
1782 bool legacy_recorder_attr_is_muted(recorder_h recorder)
1783 {
1784         int ret = MM_ERROR_NONE;
1785         double volume = 1.0;
1786         recorder_s *handle = (recorder_s *)recorder;
1787
1788         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1789
1790         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1791                 MMCAM_AUDIO_VOLUME, &volume,
1792                 NULL);
1793
1794         set_last_result(__convert_recorder_error_code(__func__, ret));
1795
1796         if (volume == 0.0)
1797                 return true;
1798         else
1799                 return false;
1800 }
1801
1802
1803 int legacy_recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
1804 {
1805         int ret = MM_ERROR_NONE;
1806         recorder_s *handle = (recorder_s *)recorder;
1807
1808         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1809         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1810         recorder_return_val_if_fail(rate > 0.0, RECORDER_ERROR_INVALID_PARAMETER);
1811
1812         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1813                 MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1814                 NULL);
1815
1816         return  __convert_recorder_error_code(__func__, ret);
1817 }
1818
1819
1820 int legacy_recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
1821 {
1822         int ret = MM_ERROR_NONE;
1823         recorder_s *handle = (recorder_s *)recorder;
1824
1825         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1826         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1827         recorder_return_val_if_fail(rate, RECORDER_ERROR_INVALID_PARAMETER);
1828
1829         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1830                 MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1831                 NULL);
1832
1833         return  __convert_recorder_error_code(__func__, ret);
1834 }
1835
1836
1837 int legacy_recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
1838 {
1839         recorder_return_val_if_fail(channel_count == 1 || channel_count == 2, RECORDER_ERROR_INVALID_PARAMETER);
1840
1841         return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_CHANNEL, channel_count);
1842 }
1843
1844
1845 int legacy_recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
1846 {
1847         int ret = MM_ERROR_NONE;
1848         recorder_s *handle = (recorder_s *)recorder;
1849
1850         recorder_return_val_if_fail(handle && channel_count, RECORDER_ERROR_INVALID_PARAMETER);
1851
1852         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1853                 MMCAM_AUDIO_CHANNEL, channel_count,
1854                 NULL);
1855
1856         return  __convert_recorder_error_code(__func__, ret);
1857 }
1858
1859
1860 int legacy_recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
1861 {
1862         int ret = MM_ERROR_NONE;
1863         recorder_s *handle = (recorder_s *)recorder;
1864
1865         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1866         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1867         recorder_return_val_if_fail(orientation <= RECORDER_ROTATION_270, RECORDER_ERROR_INVALID_PARAMETER);
1868
1869         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1870                 MMCAM_RECORDER_TAG_ENABLE, true,
1871                 MMCAM_TAG_VIDEO_ORIENTATION, orientation,
1872                 NULL);
1873
1874         return __convert_recorder_error_code(__func__, ret);
1875 }
1876
1877
1878 int  legacy_recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
1879 {
1880         int ret = MM_ERROR_NONE;
1881         recorder_s *handle = (recorder_s *)recorder;
1882
1883         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1884         recorder_return_val_if_fail(handle->camera_device_count > 0, RECORDER_ERROR_NOT_SUPPORTED);
1885         recorder_return_val_if_fail(orientation, RECORDER_ERROR_INVALID_PARAMETER);
1886
1887         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1888                 MMCAM_TAG_VIDEO_ORIENTATION, orientation,
1889                 NULL);
1890
1891         return __convert_recorder_error_code(__func__, ret);
1892 }
1893
1894
1895 int legacy_recorder_attr_set_root_directory(recorder_h recorder,  const char *root_directory)
1896 {
1897         int ret = MM_ERROR_NONE;
1898         recorder_s *handle = (recorder_s *)recorder;
1899         MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
1900
1901         recorder_return_val_if_fail(handle && root_directory, RECORDER_ERROR_INVALID_PARAMETER);
1902
1903         mm_camcorder_get_state(handle->mm_handle, &mmstate);
1904
1905         recorder_return_val_if_fail(mmstate < MM_CAMCORDER_STATE_RECORDING, RECORDER_ERROR_INVALID_STATE);
1906
1907         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1908                 MMCAM_ROOT_DIRECTORY, root_directory, strlen(root_directory),
1909                 NULL);
1910
1911         return __convert_recorder_error_code(__func__, ret);
1912 }
1913
1914
1915 int legacy_recorder_set_sound_stream_info(recorder_h recorder, char *stream_type, int stream_index)
1916 {
1917         int ret = MM_ERROR_NONE;
1918         recorder_s *handle = (recorder_s *)recorder;
1919         MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
1920
1921         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1922         recorder_return_val_if_fail(stream_type && stream_index >= 0, RECORDER_ERROR_INVALID_PARAMETER);
1923
1924         mm_camcorder_get_state(handle->mm_handle, &mmstate);
1925
1926         recorder_return_val_if_fail(mmstate < MM_CAMCORDER_STATE_RECORDING, RECORDER_ERROR_INVALID_STATE);
1927
1928         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1929                 MMCAM_SOUND_STREAM_TYPE, stream_type, strlen(stream_type),
1930                 MMCAM_SOUND_STREAM_INDEX, stream_index,
1931                 NULL);
1932
1933         return __convert_recorder_error_code(__func__, ret);
1934 }
1935
1936
1937 int legacy_recorder_manage_external_storage_state(recorder_h recorder, int storage_state)
1938 {
1939         int ret = MM_ERROR_NONE;
1940         recorder_s *handle = (recorder_s *)recorder;
1941
1942         recorder_return_val_if_fail(handle, RECORDER_ERROR_INVALID_PARAMETER);
1943
1944         CAM_LOG_WARNING("storage state %d", storage_state);
1945
1946         ret = mm_camcorder_manage_external_storage_state(handle->mm_handle, storage_state);
1947
1948         return __convert_recorder_error_code(__func__, ret);
1949 }