2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <audio-session-manager-types.h>
24 #include <mm_camcorder.h>
27 #include <legacy_camera.h>
28 #include <legacy_recorder_private.h>
37 #define LOG_TAG "TIZEN_N_RECORDER"
39 #define LOWSET_DECIBEL -300.0
40 #define RECORDER_PATH_RECORDER_RESOURCE "/usr/share/sounds/mm-camcorder/recorder_resource"
44 * camera_private function
46 int _camera_get_mm_handle(camera_h camera , MMHandleType *handle);
47 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data);
48 int _camera_set_use(camera_h camera, bool used);
49 bool _camera_is_used(camera_h camera);
51 * end of camera_private function
54 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param);
55 static int __mm_recorder_msg_cb(int message, void *param, void *user_data);
58 static int __convert_error_code_camera_to_recorder(int code)
63 case CAMERA_ERROR_INVALID_STATE :
64 new_code = RECORDER_ERROR_INVALID_STATE;
66 case CAMERA_ERROR_DEVICE:
67 new_code = RECORDER_ERROR_DEVICE;
69 case CAMERA_ERROR_SOUND_POLICY:
70 new_code = RECORDER_ERROR_SOUND_POLICY;
72 case CAMERA_ERROR_SECURITY_RESTRICTED:
73 new_code = RECORDER_ERROR_SECURITY_RESTRICTED;
83 int __convert_recorder_error_code(const char *func, int code)
85 int ret = RECORDER_ERROR_INVALID_OPERATION;
86 const char *errorstr = NULL;
89 case RECORDER_ERROR_INVALID_PARAMETER:
90 ret = RECORDER_ERROR_INVALID_PARAMETER;
91 errorstr = "INVALID_PARAMETER";
94 ret = RECORDER_ERROR_NONE;
95 errorstr = "ERROR_NONE";
97 case MM_ERROR_CAMCORDER_INVALID_ARGUMENT :
98 case MM_ERROR_COMMON_INVALID_ATTRTYPE :
99 ret = RECORDER_ERROR_INVALID_PARAMETER;
100 errorstr = "INVALID_PARAMETER";
102 case MM_ERROR_COMMON_INVALID_PERMISSION :
103 ret = RECORDER_ERROR_PERMISSION_DENIED;
104 errorstr = "ERROR_PERMISSION_DENIED";
106 case MM_ERROR_CAMCORDER_NOT_INITIALIZED :
107 case MM_ERROR_CAMCORDER_INVALID_STATE :
108 ret = RECORDER_ERROR_INVALID_STATE;
109 errorstr = "INVALID_STATE";
111 case MM_ERROR_CAMCORDER_DEVICE :
112 case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND :
113 case MM_ERROR_CAMCORDER_DEVICE_BUSY :
114 case MM_ERROR_CAMCORDER_DEVICE_OPEN :
115 case MM_ERROR_CAMCORDER_DEVICE_IO :
116 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT :
117 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG :
118 case MM_ERROR_CAMCORDER_DEVICE_LACK_BUFFER :
119 ret = RECORDER_ERROR_DEVICE;
120 errorstr = "ERROR_DEVICE";
122 case MM_ERROR_CAMCORDER_GST_CORE :
123 case MM_ERROR_CAMCORDER_GST_LIBRARY :
124 case MM_ERROR_CAMCORDER_GST_RESOURCE :
125 case MM_ERROR_CAMCORDER_GST_STREAM :
126 case MM_ERROR_CAMCORDER_GST_STATECHANGE :
127 case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
128 case MM_ERROR_CAMCORDER_GST_LINK :
129 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
130 case MM_ERROR_CAMCORDER_ENCODER :
131 case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
132 case MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE :
133 case MM_ERROR_CAMCORDER_ENCODER_WORKING :
134 case MM_ERROR_CAMCORDER_INTERNAL :
135 case MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT :
136 case MM_ERROR_CAMCORDER_CMD_IS_RUNNING :
137 case MM_ERROR_CAMCORDER_DSP_FAIL :
138 case MM_ERROR_CAMCORDER_AUDIO_EMPTY :
139 case MM_ERROR_CAMCORDER_CREATE_CONFIGURE :
140 case MM_ERROR_CAMCORDER_FILE_SIZE_OVER :
141 case MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF :
142 case MM_ERROR_CAMCORDER_INVALID_CONDITION :
143 ret = RECORDER_ERROR_INVALID_OPERATION;
144 errorstr = "INVALID_OPERATION";
146 case MM_ERROR_CAMCORDER_RESOURCE_CREATION :
147 case MM_ERROR_COMMON_OUT_OF_MEMORY:
148 ret = RECORDER_ERROR_OUT_OF_MEMORY;
149 errorstr = "OUT_OF_MEMORY";
151 case MM_ERROR_POLICY_BLOCKED:
152 ret = RECORDER_ERROR_SOUND_POLICY;
153 errorstr = "ERROR_SOUND_POLICY";
155 case MM_ERROR_POLICY_BLOCKED_BY_CALL:
156 ret = RECORDER_ERROR_SOUND_POLICY_BY_CALL;
157 errorstr = "ERROR_SOUND_POLICY_BY_CALL";
159 case MM_ERROR_POLICY_BLOCKED_BY_ALARM:
160 ret = RECORDER_ERROR_SOUND_POLICY_BY_ALARM;
161 errorstr = "ERROR_SOUND_POLICY_BY_ALARM";
163 case MM_ERROR_POLICY_RESTRICTED:
164 ret = RECORDER_ERROR_SECURITY_RESTRICTED;
165 errorstr = "ERROR_RESTRICTED";
167 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
168 ret = RECORDER_ERROR_ESD;
169 errorstr = "ERROR_ESD";
171 case MM_ERROR_OUT_OF_STORAGE:
172 ret = RECORDER_ERROR_OUT_OF_STORAGE;
173 errorstr = "OUT_OF_STORAGE";
175 case MM_ERROR_COMMON_OUT_OF_ARRAY:
176 case MM_ERROR_COMMON_OUT_OF_RANGE:
177 case MM_ERROR_COMMON_ATTR_NOT_EXIST:
178 case MM_ERROR_CAMCORDER_NOT_SUPPORTED:
179 ret = RECORDER_ERROR_NOT_SUPPORTED;
180 errorstr = "NOT_SUPPORTED";
183 ret = RECORDER_ERROR_INVALID_OPERATION;
184 errorstr = "INVALID_OPERATION";
188 LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code);
194 static recorder_state_e __recorder_state_convert(MMCamcorderStateType mm_state)
196 recorder_state_e state = RECORDER_STATE_NONE;
198 case MM_CAMCORDER_STATE_NONE:
199 state = RECORDER_STATE_NONE;
201 case MM_CAMCORDER_STATE_NULL:
202 state = RECORDER_STATE_CREATED;
204 case MM_CAMCORDER_STATE_READY:
205 state = RECORDER_STATE_CREATED;
207 case MM_CAMCORDER_STATE_PREPARE:
208 state = RECORDER_STATE_READY;
210 case MM_CAMCORDER_STATE_CAPTURING:
211 state = RECORDER_STATE_READY;
213 case MM_CAMCORDER_STATE_RECORDING:
214 state = RECORDER_STATE_RECORDING;
216 case MM_CAMCORDER_STATE_PAUSED:
217 state = RECORDER_STATE_PAUSED;
220 state = RECORDER_STATE_NONE;
228 static int __mm_recorder_msg_cb(int message, void *param, void *user_data)
230 recorder_s * handle = (recorder_s *)user_data;
231 MMMessageParamType *m = (MMMessageParamType *)param;
232 recorder_state_e previous_state;
233 recorder_recording_limit_type_e type;
234 int recorder_error = 0;
237 case MM_MESSAGE_READY_TO_RESUME:
238 LOGW("not supported message");
240 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
241 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
242 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY:
243 previous_state = handle->state;
244 handle->state = __recorder_state_convert(m->state.current);
245 recorder_policy_e policy = RECORDER_POLICY_NONE;
246 if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM) {
247 switch (m->state.code) {
248 case ASM_EVENT_SOURCE_CALL_START:
249 case ASM_EVENT_SOURCE_CALL_END:
250 policy = RECORDER_POLICY_SOUND_BY_CALL;
251 LOGE("RECORDER_POLICY_SOUND_BY_CALL");
253 case ASM_EVENT_SOURCE_ALARM_START:
254 case ASM_EVENT_SOURCE_ALARM_END:
255 policy = RECORDER_POLICY_SOUND_BY_ALARM;
256 LOGE("RECORDER_POLICY_SOUND_BY_ALARM");
259 policy = RECORDER_POLICY_SOUND;
260 LOGE("RECORDER_POLICY_SOUND");
263 } else if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY) {
264 policy = RECORDER_POLICY_SECURITY;
265 LOGE("RECORDER_POLICY_SECURITY");
268 if (previous_state != handle->state && handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE]) {
269 ((recorder_state_changed_cb)handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state, policy, handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE]);
272 /* should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state */
273 if (policy != RECORDER_POLICY_NONE &&
274 (m->state.current == MM_CAMCORDER_STATE_PAUSED || m->state.current == MM_CAMCORDER_STATE_NULL)) {
275 if (handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED]) {
276 ((recorder_interrupted_cb)handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED]);
278 LOGW("_RECORDER_EVENT_TYPE_INTERRUPTED cb is NULL");
282 case MM_MESSAGE_CAMCORDER_MAX_SIZE:
283 case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
284 case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
285 if (MM_MESSAGE_CAMCORDER_MAX_SIZE == message) {
286 type = RECORDER_RECORDING_LIMIT_SIZE;
287 } else if (MM_MESSAGE_CAMCORDER_NO_FREE_SPACE == message) {
288 type = RECORDER_RECORDING_LIMIT_FREE_SPACE;
290 type = RECORDER_RECORDING_LIMIT_TIME;
292 if (handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]) {
293 ((recorder_recording_limit_reached_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED])(type, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
296 case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
297 if (handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS]) {
298 ((recorder_recording_status_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS])(m->recording_status.elapsed, m->recording_status.filesize, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
301 case MM_MESSAGE_CAMCORDER_ERROR:
303 case MM_ERROR_CAMCORDER_DEVICE:
304 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT:
305 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG:
306 recorder_error = RECORDER_ERROR_DEVICE;
308 case MM_ERROR_CAMCORDER_GST_CORE:
309 case MM_ERROR_CAMCORDER_GST_LIBRARY:
310 case MM_ERROR_CAMCORDER_GST_RESOURCE:
311 case MM_ERROR_CAMCORDER_GST_STREAM:
312 case MM_ERROR_CAMCORDER_GST_NEGOTIATION:
313 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR:
314 case MM_ERROR_CAMCORDER_ENCODER:
315 case MM_ERROR_CAMCORDER_ENCODER_BUFFER:
316 case MM_ERROR_CAMCORDER_ENCODER_WORKING:
317 case MM_ERROR_CAMCORDER_MNOTE_CREATION:
318 case MM_ERROR_CAMCORDER_MNOTE_ADD_ENTRY:
319 case MM_ERROR_CAMCORDER_INTERNAL:
320 case MM_ERROR_FILE_NOT_FOUND:
321 case MM_ERROR_FILE_READ:
322 recorder_error = RECORDER_ERROR_INVALID_OPERATION;
324 case MM_ERROR_CAMCORDER_LOW_MEMORY:
325 case MM_ERROR_CAMCORDER_MNOTE_MALLOC:
326 recorder_error = RECORDER_ERROR_OUT_OF_MEMORY;
328 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
329 recorder_error = RECORDER_ERROR_ESD;
331 case MM_ERROR_OUT_OF_STORAGE:
332 recorder_error = RECORDER_ERROR_OUT_OF_STORAGE;
335 recorder_error = RECORDER_ERROR_INVALID_OPERATION;
339 if (recorder_error != 0 && handle->user_cb[_RECORDER_EVENT_TYPE_ERROR]) {
340 ((recorder_error_cb)handle->user_cb[_RECORDER_EVENT_TYPE_ERROR])(recorder_error, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_ERROR]);
343 case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
344 if (handle->last_max_input_level < m->rec_volume_dB) {
345 handle->last_max_input_level = m->rec_volume_dB;
356 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param)
358 if (user_param == NULL || stream == NULL) {
362 recorder_s *handle = (recorder_s *)user_param;
363 audio_sample_type_e format = AUDIO_SAMPLE_TYPE_U8;
365 if (stream->format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
366 format = AUDIO_SAMPLE_TYPE_S16_LE;
369 if( handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] ){
370 ((recorder_audio_stream_cb)(handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM]))(stream->data, stream->length, format,
371 stream->channel, stream->timestamp,
372 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
379 static int _recorder_check_and_set_attribute(recorder_h recorder, const char *attribute_name, int set_value)
381 bool reset_pipeline = false;
382 bool restore_set = false;
383 int ret = MM_ERROR_NONE;
384 int ret2 = MM_ERROR_NONE;
385 int current_value = -1;
386 int current_audio_disable = 0;
388 recorder_s *handle = (recorder_s *)recorder;
389 MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
391 if (recorder == NULL) {
392 LOGE("handle is NULL");
393 return RECORDER_ERROR_INVALID_PARAMETER;
396 mm_camcorder_get_state(handle->mm_handle, &mmstate);
397 if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
398 LOGE("invalid state %d", mmstate);
399 return RECORDER_ERROR_INVALID_STATE;
402 if (handle->type == _RECORDER_TYPE_AUDIO && mmstate == MM_CAMCORDER_STATE_PREPARE) {
403 mm_camcorder_get_attributes(handle->mm_handle, NULL,
404 MMCAM_AUDIO_DISABLE, ¤t_audio_disable,
405 attribute_name, ¤t_value,
408 if (current_value != set_value) {
409 LOGD("try to reset pipeline");
411 ret = mm_camcorder_stop(handle->mm_handle);
412 if (ret != MM_ERROR_NONE) {
413 LOGE("mm_camcorder_stop failed 0x%x", ret);
414 return __convert_recorder_error_code(attribute_name, ret);
417 ret = mm_camcorder_unrealize(handle->mm_handle);
418 if (ret != MM_ERROR_NONE) {
419 LOGE("mm_camcorder_unrealize failed 0x%x", ret);
420 mm_camcorder_start(handle->mm_handle);
421 return __convert_recorder_error_code(attribute_name, ret);
424 reset_pipeline = true;
428 if (!strcmp(attribute_name, MMCAM_AUDIO_ENCODER)) {
429 if (set_value == RECORDER_AUDIO_CODEC_DISABLE) {
430 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
431 MMCAM_AUDIO_DISABLE, true,
434 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
435 MMCAM_AUDIO_DISABLE, false,
436 MMCAM_AUDIO_ENCODER, set_value,
440 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
441 attribute_name, set_value,
445 if (ret != MM_ERROR_NONE) {
446 LOGE("set [%s] failed 0x%x", attribute_name, ret);
449 if (reset_pipeline) {
450 ret2 = mm_camcorder_realize(handle->mm_handle);
451 if (ret2 == MM_ERROR_NONE) {
452 ret2 = mm_camcorder_start(handle->mm_handle);
453 if (ret2 == MM_ERROR_NONE) {
454 LOGW("restart pipeline done.");
456 LOGE("mm_camcorder_start failed 0x%x", ret2);
457 mm_camcorder_unrealize(handle->mm_handle);
460 LOGE("mm_camcorder_realize failed 0x%x", ret2);
463 if (ret2 != MM_ERROR_NONE) {
465 /* determine return value */
466 if (ret == MM_ERROR_NONE) {
473 ret2 = mm_camcorder_set_attributes(handle->mm_handle, NULL,
474 MMCAM_AUDIO_DISABLE, current_audio_disable,
475 attribute_name, current_value,
477 LOGW("restore attribute set : 0x%x", ret2);
479 ret2 = mm_camcorder_realize(handle->mm_handle);
480 LOGW("restore mm_camcorder_realize : 0x%x", ret2);
482 ret2 = mm_camcorder_start(handle->mm_handle);
483 LOGW("restore mm_camcorder_realize : 0x%x", ret2);
484 if (ret2 != MM_ERROR_NONE) {
485 ret2 = mm_camcorder_unrealize(handle->mm_handle);
486 LOGW("restore mm_camcorder_unrealize : 0x%x", ret2);
490 return __convert_recorder_error_code(attribute_name, ret);
494 int legacy_recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
496 int ret = MM_ERROR_NONE;
497 int resource_fd = -1;
498 recorder_s *handle = NULL;
499 int preview_format = MM_PIXEL_FORMAT_NV12;
500 int camera_device_count = 0;
502 if (camera == NULL) {
503 LOGE("NULL pointer camera handle");
504 return RECORDER_ERROR_INVALID_PARAMETER;
506 if (recorder == NULL) {
507 LOGE("NULL pointer recorder handle");
508 return RECORDER_ERROR_INVALID_PARAMETER;
511 /* Check already used in another recorder */
512 if (_camera_is_used(camera)) {
513 LOGE("[%s] camera is using in another recorder.", __func__);
514 return RECORDER_ERROR_INVALID_PARAMETER;
517 resource_fd = open(RECORDER_PATH_RECORDER_RESOURCE, O_RDONLY);
518 if (resource_fd < 0) {
519 LOGE("failed to open recorder resource : errno [%d]", errno);
520 if (errno == EPERM || errno == EACCES) {
521 LOGE("permission denied");
522 return RECORDER_ERROR_PERMISSION_DENIED;
524 LOGE("invalid operation");
525 return RECORDER_ERROR_INVALID_OPERATION;
532 LOGW("permission check done");
534 handle = (recorder_s*)malloc( sizeof(recorder_s) );
536 LOGE("[%s] malloc error", __func__);
537 return RECORDER_ERROR_OUT_OF_MEMORY;
540 memset(handle, 0 , sizeof(recorder_s));
541 handle->src_type = _RECORDER_SOURCE_TYPE_CAMERA;
542 handle->last_max_input_level = LOWSET_DECIBEL;
543 handle->changed_preview_format = -1;
544 handle->mm_source.camera = camera;
546 _camera_get_mm_handle(camera, &handle->mm_handle);
547 _camera_set_relay_mm_message_callback(camera, __mm_recorder_msg_cb , (void*)handle);
548 handle->type = _RECORDER_TYPE_VIDEO;
549 legacy_recorder_get_state((recorder_h)handle, (recorder_state_e*)&handle->state);
551 mm_camcorder_get_attributes(handle->mm_handle, NULL,
552 MMCAM_CAMERA_FORMAT, &preview_format,
554 handle->origin_preview_format = preview_format;
555 mm_camcorder_get_attributes(handle->mm_handle, NULL,
556 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, &preview_format,
558 ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL,
559 MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count,
561 if (ret != MM_ERROR_NONE) {
564 LOGE("get device count error");
565 return __convert_recorder_error_code(__func__, ret);
567 if (camera_device_count == 0) {
570 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
571 return RECORDER_ERROR_NOT_SUPPORTED;
573 handle->camera_device_count = camera_device_count;
576 _camera_set_use(camera, true);
577 if (handle->state == RECORDER_STATE_CREATED) {
578 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
579 MMCAM_CAMERA_FORMAT, preview_format,
581 if (ret == MM_ERROR_NONE) {
582 handle->changed_preview_format = preview_format;
585 *recorder = (recorder_h)handle;
587 return RECORDER_ERROR_NONE;
591 int legacy_recorder_create_audiorecorder(recorder_h *recorder)
593 int ret = MM_ERROR_NONE;
594 recorder_s *handle = NULL;
596 int camera_device_count = 0;
598 if (recorder == NULL) {
599 LOGE("NULL pointer handle");
600 return RECORDER_ERROR_INVALID_PARAMETER;
603 info.videodev_type = MM_VIDEO_DEVICE_NONE;
605 handle = (recorder_s *)malloc(sizeof(recorder_s));
606 if (handle == NULL) {
607 LOGE("OUT_OF_MEMORY(0x%08x)", RECORDER_ERROR_OUT_OF_MEMORY);
608 return RECORDER_ERROR_OUT_OF_MEMORY;
611 memset(handle, 0, sizeof(recorder_s));
613 handle->last_max_input_level = LOWSET_DECIBEL;
615 ret = mm_camcorder_create(&handle->mm_handle, &info);
616 if (ret != MM_ERROR_NONE) {
619 LOGE("mm_camcorder_create fail");
620 return __convert_recorder_error_code(__func__, ret);
623 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
624 MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
627 if (ret != MM_ERROR_NONE) {
628 mm_camcorder_destroy(handle->mm_handle);
631 LOGE("AUDIO mode setting fail");
632 return __convert_recorder_error_code(__func__, ret);
634 ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL,
635 MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count, NULL);
636 if (ret != MM_ERROR_NONE) {
637 mm_camcorder_destroy(handle->mm_handle);
640 LOGE("get device count error");
641 return __convert_recorder_error_code(__func__, ret);
643 handle->camera_device_count = camera_device_count;
645 handle->state = RECORDER_STATE_CREATED;
646 handle->mm_source.camera = NULL;
647 handle->type = _RECORDER_TYPE_AUDIO;
649 mm_camcorder_set_message_callback(handle->mm_handle, __mm_recorder_msg_cb, (void*)handle);
651 *recorder = (recorder_h)handle;
653 return RECORDER_ERROR_NONE;
657 int legacy_recorder_get_state(recorder_h recorder, recorder_state_e *state)
659 int ret = MM_ERROR_NONE;
660 MMCamcorderStateType mmstate;
662 if (recorder == NULL) {
663 LOGE("NULL pointer handle");
664 return RECORDER_ERROR_INVALID_PARAMETER;
667 LOGE("NULL pointer state");
668 return RECORDER_ERROR_INVALID_PARAMETER;
671 recorder_s *handle = (recorder_s*)recorder;
673 ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
674 if (ret != MM_ERROR_NONE) {
675 return __convert_recorder_error_code(__func__, ret);
678 *state = __recorder_state_convert(mmstate);
680 return RECORDER_ERROR_NONE;
684 int legacy_recorder_destroy(recorder_h recorder)
686 recorder_s *handle = NULL;
687 int ret = MM_ERROR_NONE;
690 if (recorder == NULL) {
691 LOGE("NULL pointer handle");
692 return RECORDER_ERROR_INVALID_PARAMETER;
695 handle = (recorder_s *)recorder;
697 if (handle->type == _RECORDER_TYPE_VIDEO) {
699 _camera_set_use(handle->mm_source.camera, false);
700 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
701 MMCAM_CAMERA_FORMAT, &preview_format,
704 /* preview format was changed? */
705 if (ret == MM_ERROR_NONE && preview_format == handle->changed_preview_format) {
706 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
707 MMCAM_CAMERA_FORMAT, handle->origin_preview_format,
711 if (ret == MM_ERROR_NONE) {
712 _camera_set_relay_mm_message_callback(handle->mm_source.camera, NULL, NULL);
715 ret = mm_camcorder_destroy(handle->mm_handle);
718 if (ret == MM_ERROR_NONE) {
722 return __convert_recorder_error_code(__func__, ret);
726 int legacy_recorder_prepare(recorder_h recorder)
728 int ret = MM_ERROR_NONE;
729 recorder_s *handle = (recorder_s *)recorder;
730 MMCamcorderStateType mmstate;
732 if (recorder == NULL) {
733 LOGE("NULL pointer handle");
734 return RECORDER_ERROR_INVALID_PARAMETER;
737 if (handle->type == _RECORDER_TYPE_VIDEO) {
738 return __convert_error_code_camera_to_recorder(legacy_camera_start_preview(handle->mm_source.camera));
741 ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
743 if (ret == MM_ERROR_NONE && mmstate < MM_CAMCORDER_STATE_READY) {
744 ret = mm_camcorder_realize(handle->mm_handle);
745 if (ret != MM_ERROR_NONE) {
746 LOGE("mm_camcorder_realize fail");
747 return __convert_recorder_error_code(__func__, ret);
751 ret = mm_camcorder_start(handle->mm_handle);
752 if (ret != MM_ERROR_NONE) {
753 LOGE("mm_camcorder_start fail");
754 mm_camcorder_unrealize(handle->mm_handle);
755 return __convert_recorder_error_code(__func__, ret);
758 return RECORDER_ERROR_NONE;
762 int legacy_recorder_unprepare(recorder_h recorder)
764 int ret = MM_ERROR_NONE;
765 recorder_s *handle = (recorder_s *)recorder;
766 MMCamcorderStateType mmstate;
768 if (recorder == NULL) {
769 LOGE("NULL pointer handle");
770 return RECORDER_ERROR_INVALID_PARAMETER;
773 ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
774 if (ret == MM_ERROR_NONE && mmstate == MM_CAMCORDER_STATE_PREPARE) {
775 ret = mm_camcorder_stop(handle->mm_handle);
776 if( ret != MM_ERROR_NONE){
777 LOGE("mm_camcorder_stop fail");
781 if (ret == MM_ERROR_NONE) {
782 ret = mm_camcorder_unrealize(handle->mm_handle);
783 if (ret != MM_ERROR_NONE) {
784 LOGE("mm_camcorder_unrealize fail");
785 mm_camcorder_start(handle->mm_handle);
789 return __convert_recorder_error_code(__func__, ret);
793 int legacy_recorder_start(recorder_h recorder)
795 recorder_s *handle = (recorder_s *)recorder;
797 if (recorder == NULL) {
798 LOGE("NULL pointer handle");
799 return RECORDER_ERROR_INVALID_PARAMETER;
802 return __convert_recorder_error_code(__func__, mm_camcorder_record(handle->mm_handle));
806 int legacy_recorder_pause(recorder_h recorder)
808 recorder_s *handle = (recorder_s *)recorder;
810 if (recorder == NULL) {
811 LOGE("NULL pointer handle");
812 return RECORDER_ERROR_INVALID_PARAMETER;
815 return __convert_recorder_error_code(__func__, mm_camcorder_pause(handle->mm_handle));
819 int legacy_recorder_commit(recorder_h recorder)
821 recorder_s *handle = (recorder_s *)recorder;
823 if (recorder == NULL) {
824 LOGE("NULL pointer handle");
825 return RECORDER_ERROR_INVALID_PARAMETER;
828 return __convert_recorder_error_code(__func__, mm_camcorder_commit(handle->mm_handle));
832 int legacy_recorder_cancel(recorder_h recorder)
834 recorder_s *handle = (recorder_s *)recorder;
836 if (recorder == NULL) {
837 LOGE("NULL pointer handle");
838 return RECORDER_ERROR_INVALID_PARAMETER;
841 return __convert_recorder_error_code(__func__, mm_camcorder_cancel(handle->mm_handle));
845 int legacy_recorder_set_video_resolution(recorder_h recorder, int width, int height)
847 int ret = MM_ERROR_NONE;
848 recorder_s *handle = (recorder_s*)recorder;
849 recorder_state_e state;
851 if (handle == NULL) {
852 LOGE("NULL pointer handle");
853 return RECORDER_ERROR_INVALID_PARAMETER;
855 if (handle->camera_device_count == 0) {
856 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
857 return RECORDER_ERROR_NOT_SUPPORTED;
859 legacy_recorder_get_state(recorder, &state);
860 if (state > RECORDER_STATE_READY) {
861 LOGE("RECORDER_ERROR_INVALID_STATE (state:%d)", state);
862 return RECORDER_ERROR_INVALID_STATE;
865 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
866 MMCAM_VIDEO_WIDTH, width,
867 MMCAM_VIDEO_HEIGHT, height,
870 return __convert_recorder_error_code(__func__, ret);
874 int legacy_recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
876 int ret = MM_ERROR_NONE;
877 recorder_s *handle = (recorder_s*)recorder;
880 LOGE("NULL pointer handle");
881 return RECORDER_ERROR_INVALID_PARAMETER;
884 if (handle->camera_device_count == 0) {
885 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
886 return RECORDER_ERROR_NOT_SUPPORTED;
889 if (!width || !height) {
890 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
891 return RECORDER_ERROR_INVALID_PARAMETER;
894 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
895 MMCAM_VIDEO_WIDTH, width,
896 MMCAM_VIDEO_HEIGHT, height,
899 return __convert_recorder_error_code(__func__, ret);
903 int legacy_recorder_foreach_supported_video_resolution(recorder_h recorder,
904 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
907 int ret = MM_ERROR_NONE;
908 recorder_s * handle = (recorder_s*)recorder;
909 MMCamAttrsInfo video_width;
910 MMCamAttrsInfo video_height;
913 LOGE("NULL pointer handle");
914 return RECORDER_ERROR_INVALID_PARAMETER;
917 if (handle->camera_device_count == 0) {
918 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
919 return RECORDER_ERROR_NOT_SUPPORTED;
923 LOGE("NULL pointer callback");
924 return RECORDER_ERROR_INVALID_PARAMETER;
927 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_WIDTH, &video_width);
928 ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_HEIGHT, &video_height);
930 if (ret != MM_ERROR_NONE ) {
931 return __convert_recorder_error_code(__func__, ret);
934 for (i = 0 ; i < video_width.int_array.count ; i++) {
935 if (!foreach_cb(video_width.int_array.array[i], video_height.int_array.array[i], user_data)) {
940 return RECORDER_ERROR_NONE;
944 int legacy_recorder_get_audio_level(recorder_h recorder, double *level)
946 recorder_s *handle = (recorder_s *)recorder;
947 recorder_state_e state;
949 if (recorder == NULL || level == NULL) {
950 LOGE("NULL pointer %p %p", recorder, level);
951 return RECORDER_ERROR_INVALID_PARAMETER;
954 legacy_recorder_get_state(recorder, &state);
955 if (state < RECORDER_STATE_RECORDING) {
956 LOGE("RECORDER_ERROR_INVALID_STATE(0x%08x)", RECORDER_ERROR_INVALID_STATE);
957 return RECORDER_ERROR_INVALID_STATE;
960 *level = handle->last_max_input_level;
961 handle->last_max_input_level = LOWSET_DECIBEL;
963 return RECORDER_ERROR_NONE;
967 int legacy_recorder_set_filename(recorder_h recorder, const char *filename)
969 int ret = MM_ERROR_NONE;
970 recorder_s *handle = (recorder_s *)recorder;
971 MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
973 if (recorder == NULL) {
974 LOGE("handle is NULL");
975 return RECORDER_ERROR_INVALID_PARAMETER;
978 if (filename == NULL) {
979 LOGE("filename is NULL");
980 return RECORDER_ERROR_INVALID_PARAMETER;
983 mm_camcorder_get_state(handle->mm_handle, &mmstate);
984 if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
985 LOGE("invalid state %d", mmstate);
986 return RECORDER_ERROR_INVALID_STATE;
989 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
990 MMCAM_TARGET_FILENAME, filename, strlen(filename),
993 return __convert_recorder_error_code(__func__, ret);
997 int legacy_recorder_get_filename(recorder_h recorder, char **filename)
999 int ret = MM_ERROR_NONE;
1000 char *record_filename = NULL;
1001 int record_filename_size;
1002 recorder_s *handle = (recorder_s *)recorder;
1004 if (recorder == NULL) {
1005 LOGE("handle is NULL");
1006 return RECORDER_ERROR_INVALID_PARAMETER;
1009 if (filename == NULL) {
1010 LOGE("filename is NULL");
1011 return RECORDER_ERROR_INVALID_PARAMETER;
1014 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1015 MMCAM_TARGET_FILENAME, &record_filename, &record_filename_size,
1017 if (ret == MM_ERROR_NONE && record_filename) {
1018 *filename = strdup(record_filename);
1020 LOGE("internal return (0x%08x), get filename p:%p", ret, record_filename);
1024 return __convert_recorder_error_code(__func__, ret);
1028 int legacy_recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
1030 int format_table[6] = { MM_FILE_FORMAT_3GP, /* RECORDER_FILE_FORMAT_3GP */
1031 MM_FILE_FORMAT_MP4, /* RECORDER_FILE_FORMAT_MP4 */
1032 MM_FILE_FORMAT_AMR, /* RECORDER_FILE_FORMAT_AMR */
1033 MM_FILE_FORMAT_AAC, /* RECORDER_FILE_FORMAT_ADTS */
1034 MM_FILE_FORMAT_WAV, /* RECORDER_FILE_FORMAT_WAV */
1035 MM_FILE_FORMAT_OGG /* RECORDER_FILE_FORMAT_OGG */
1038 if (format < RECORDER_FILE_FORMAT_3GP || format > RECORDER_FILE_FORMAT_OGG) {
1039 LOGE("invalid format %d", format);
1040 return RECORDER_ERROR_INVALID_PARAMETER;
1043 return _recorder_check_and_set_attribute(recorder, MMCAM_FILE_FORMAT, format_table[format]);
1047 int legacy_recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
1049 int ret = MM_ERROR_NONE;
1050 recorder_s *handle = (recorder_s *)recorder;
1053 if (recorder == NULL) {
1054 LOGE("handle is NULL");
1055 return RECORDER_ERROR_INVALID_PARAMETER;
1058 if (format == NULL) {
1059 LOGE("format is NULL");
1060 return RECORDER_ERROR_INVALID_PARAMETER;
1063 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1064 MMCAM_FILE_FORMAT, &mm_format,
1066 if (ret == MM_ERROR_NONE) {
1067 switch (mm_format) {
1068 case MM_FILE_FORMAT_3GP:
1069 *format = RECORDER_FILE_FORMAT_3GP;
1071 case MM_FILE_FORMAT_MP4 :
1072 *format = RECORDER_FILE_FORMAT_MP4;
1074 case MM_FILE_FORMAT_AMR :
1075 *format = RECORDER_FILE_FORMAT_AMR;
1077 case MM_FILE_FORMAT_AAC :
1078 *format = RECORDER_FILE_FORMAT_ADTS;
1080 case MM_FILE_FORMAT_WAV:
1081 *format = RECORDER_FILE_FORMAT_WAV;
1083 case MM_FILE_FORMAT_OGG:
1084 *format = RECORDER_FILE_FORMAT_OGG;
1087 ret = MM_ERROR_CAMCORDER_INTERNAL;
1092 return __convert_recorder_error_code(__func__, ret);
1096 int legacy_recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
1098 recorder_s *handle = (recorder_s *)recorder;
1100 if (recorder == NULL) {
1101 LOGE("NULL pointer handle");
1102 return RECORDER_ERROR_INVALID_PARAMETER;
1105 if (callback == NULL) {
1106 LOGE("NULL pointer callback");
1107 return RECORDER_ERROR_INVALID_PARAMETER;
1110 handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
1111 handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
1113 return RECORDER_ERROR_NONE;
1117 int legacy_recorder_unset_state_changed_cb(recorder_h recorder)
1119 recorder_s *handle = (recorder_s *)recorder;
1121 if (recorder == NULL) {
1122 LOGE("NULL pointer handle");
1123 return RECORDER_ERROR_INVALID_PARAMETER;
1126 handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1127 handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1129 return RECORDER_ERROR_NONE;
1133 int legacy_recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
1135 recorder_s *handle = (recorder_s *)recorder;
1137 if (recorder == NULL) {
1138 LOGE("NULL pointer handle");
1139 return RECORDER_ERROR_INVALID_PARAMETER;
1141 if (callback == NULL) {
1142 LOGE("NULL pointer callback");
1143 return RECORDER_ERROR_INVALID_PARAMETER;
1146 handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
1147 handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
1149 return RECORDER_ERROR_NONE;
1153 int legacy_recorder_unset_interrupted_cb(recorder_h recorder)
1155 recorder_s *handle = (recorder_s *)recorder;
1157 if (recorder == NULL) {
1158 LOGE("NULL pointer handle");
1159 return RECORDER_ERROR_INVALID_PARAMETER;
1162 handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1163 handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1165 return RECORDER_ERROR_NONE;
1169 int legacy_recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
1171 int ret = MM_ERROR_NONE;
1172 recorder_s *handle = (recorder_s *)recorder;
1174 if (recorder == NULL) {
1175 LOGE("NULL pointer handle");
1176 return RECORDER_ERROR_INVALID_PARAMETER;
1178 if (callback == NULL) {
1179 LOGE("NULL pointer callback");
1180 return RECORDER_ERROR_INVALID_PARAMETER;
1183 ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, __mm_audio_stream_cb, handle);
1184 if (ret == MM_ERROR_NONE){
1185 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
1186 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
1189 return __convert_recorder_error_code(__func__, ret);
1193 int legacy_recorder_unset_audio_stream_cb(recorder_h recorder)
1195 int ret = MM_ERROR_NONE;
1196 recorder_s *handle = (recorder_s *)recorder;
1198 if (recorder == NULL) {
1199 LOGE("NULL pointer handle");
1200 return RECORDER_ERROR_INVALID_PARAMETER;
1203 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1204 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1206 ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, NULL, NULL);
1208 return __convert_recorder_error_code(__func__, ret);
1212 int legacy_recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
1214 recorder_s *handle = (recorder_s *)recorder;
1216 if (recorder == NULL) {
1217 LOGE("NULL pointer handle");
1218 return RECORDER_ERROR_INVALID_PARAMETER;
1220 if (callback == NULL) {
1221 LOGE("NULL pointer callback");
1222 return RECORDER_ERROR_INVALID_PARAMETER;
1225 handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = callback;
1226 handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = user_data;
1228 return RECORDER_ERROR_NONE;
1232 int legacy_recorder_unset_error_cb(recorder_h recorder)
1234 recorder_s *handle = (recorder_s *)recorder;
1236 if (recorder == NULL) {
1237 LOGE("NULL pointer handle");
1238 return RECORDER_ERROR_INVALID_PARAMETER;
1241 handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1242 handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1244 return RECORDER_ERROR_NONE;
1248 int legacy_recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
1250 recorder_s *handle = (recorder_s *)recorder;
1252 if (recorder == NULL) {
1253 LOGE("NULL pointer handle");
1254 return RECORDER_ERROR_INVALID_PARAMETER;
1256 if (callback == NULL) {
1257 LOGE("NULL pointer callback");
1258 return RECORDER_ERROR_INVALID_PARAMETER;
1261 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
1262 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
1264 return RECORDER_ERROR_NONE;
1268 int legacy_recorder_unset_recording_status_cb(recorder_h recorder)
1270 recorder_s *handle = (recorder_s *)recorder;
1272 if (recorder == NULL) {
1273 LOGE("NULL pointer handle");
1274 return RECORDER_ERROR_INVALID_PARAMETER;
1277 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1278 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1280 return RECORDER_ERROR_NONE;
1284 int legacy_recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
1286 recorder_s *handle = (recorder_s *)recorder;
1288 if (recorder == NULL) {
1289 LOGE("NULL pointer handle");
1290 return RECORDER_ERROR_INVALID_PARAMETER;
1292 if (callback == NULL) {
1293 LOGE("NULL pointer callback");
1294 return RECORDER_ERROR_INVALID_PARAMETER;
1297 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
1298 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
1300 return RECORDER_ERROR_NONE;
1304 int legacy_recorder_unset_recording_limit_reached_cb(recorder_h recorder)
1306 recorder_s *handle = (recorder_s *)recorder;
1308 if (recorder == NULL) {
1309 LOGE("NULL pointer handle");
1310 return RECORDER_ERROR_INVALID_PARAMETER;
1313 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1314 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1316 return RECORDER_ERROR_NONE;
1320 int legacy_recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
1323 int ret = MM_ERROR_NONE;
1324 recorder_s *handle = (recorder_s *)recorder;
1325 MMCamAttrsInfo info;
1328 if (recorder == NULL) {
1329 LOGE("NULL pointer handle");
1330 return RECORDER_ERROR_INVALID_PARAMETER;
1332 if (foreach_cb == NULL) {
1333 LOGE("NULL pointer foreach_cb");
1334 return RECORDER_ERROR_INVALID_PARAMETER;
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);;
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;
1348 case MM_FILE_FORMAT_MP4 :
1349 format = RECORDER_FILE_FORMAT_MP4;
1351 case MM_FILE_FORMAT_AMR :
1352 format = RECORDER_FILE_FORMAT_AMR;
1354 case MM_FILE_FORMAT_AAC:
1355 format = RECORDER_FILE_FORMAT_ADTS;
1357 case MM_FILE_FORMAT_WAV:
1358 format = RECORDER_FILE_FORMAT_WAV;
1365 if (format != -1 && !foreach_cb(format,user_data)) {
1370 return RECORDER_ERROR_NONE;
1374 int legacy_recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
1376 int ret = MM_ERROR_NONE;
1377 recorder_s *handle = (recorder_s *)recorder;
1379 if (recorder == NULL) {
1380 LOGE("NULL pointer handle");
1381 return RECORDER_ERROR_INVALID_PARAMETER;
1384 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1385 MMCAM_TARGET_MAX_SIZE, kbyte,
1388 return __convert_recorder_error_code(__func__, ret);
1392 int legacy_recorder_attr_set_time_limit(recorder_h recorder, int second)
1394 int ret = MM_ERROR_NONE;
1395 recorder_s *handle = (recorder_s *)recorder;
1397 if (recorder == NULL) {
1398 LOGE("NULL pointer handle");
1399 return RECORDER_ERROR_INVALID_PARAMETER;
1402 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1403 MMCAM_TARGET_TIME_LIMIT, second,
1406 return __convert_recorder_error_code(__func__, ret);
1410 int legacy_recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
1412 if (device < RECORDER_AUDIO_DEVICE_MIC || device > RECORDER_AUDIO_DEVICE_MODEM) {
1413 LOGE("invalid device %d", device);
1414 return RECORDER_ERROR_INVALID_PARAMETER;
1417 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_DEVICE, device);
1421 int legacy_recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
1423 recorder_s *handle = (recorder_s *)recorder;
1424 int audio_table[4] = { MM_AUDIO_CODEC_AMR, /* RECORDER_AUDIO_CODEC_AMR */
1425 MM_AUDIO_CODEC_AAC, /* RECORDER_AUDIO_CODEC_AAC */
1426 MM_AUDIO_CODEC_VORBIS, /* RECORDER_AUDIO_CODEC_VORBIS */
1427 MM_AUDIO_CODEC_WAVE /* RECORDER_AUDIO_CODEC_PCM */
1430 if (recorder == NULL) {
1431 LOGE("handle is NULL");
1432 return RECORDER_ERROR_INVALID_PARAMETER;
1435 if (codec != RECORDER_AUDIO_CODEC_DISABLE &&
1436 (codec < RECORDER_AUDIO_CODEC_AMR || codec > RECORDER_AUDIO_CODEC_PCM)) {
1437 LOGE("invalid parameter : codec %d", codec);
1438 return RECORDER_ERROR_INVALID_PARAMETER;
1441 if (handle->type == _RECORDER_TYPE_AUDIO && codec == RECORDER_AUDIO_CODEC_DISABLE) {
1442 LOGE("AUDIO_CODEC_DISABLE is not supported in audio mode");
1443 return RECORDER_ERROR_NOT_SUPPORTED;
1446 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER, codec == RECORDER_AUDIO_CODEC_DISABLE ? RECORDER_AUDIO_CODEC_DISABLE : audio_table[codec]);
1450 int legacy_recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
1452 int ret = MM_ERROR_NONE;
1454 int audio_disable = 0;
1455 recorder_s *handle = (recorder_s *)recorder;
1457 if (recorder == NULL) {
1458 LOGE("handle is NULL");
1459 return RECORDER_ERROR_INVALID_PARAMETER;
1462 if (codec == NULL) {
1463 LOGE("codec is NULL");
1464 return RECORDER_ERROR_INVALID_PARAMETER;
1467 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1468 MMCAM_AUDIO_ENCODER, &mm_codec,
1469 MMCAM_AUDIO_DISABLE, &audio_disable,
1472 if (ret == MM_ERROR_NONE && audio_disable == 0) {
1474 case MM_AUDIO_CODEC_AMR :
1475 *codec = RECORDER_AUDIO_CODEC_AMR;
1477 case MM_AUDIO_CODEC_AAC :
1478 *codec = RECORDER_AUDIO_CODEC_AAC;
1480 case MM_AUDIO_CODEC_VORBIS:
1481 *codec = RECORDER_AUDIO_CODEC_VORBIS;
1483 case MM_AUDIO_CODEC_WAVE:
1484 *codec = RECORDER_AUDIO_CODEC_PCM;
1487 ret = MM_ERROR_CAMCORDER_INTERNAL;
1490 } else if (ret == MM_ERROR_NONE && audio_disable) {
1491 *codec = RECORDER_AUDIO_CODEC_DISABLE;
1494 return __convert_recorder_error_code(__func__, ret);
1498 int legacy_recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
1500 int ret = MM_ERROR_NONE;
1501 int video_table[4] = { MM_VIDEO_CODEC_H263, /* RECORDER_VIDEO_CODEC_H263 */
1502 MM_VIDEO_CODEC_H264, /* RECORDER_VIDEO_CODEC_H264 */
1503 MM_VIDEO_CODEC_MPEG4, /* RECORDER_VIDEO_CODEC_MPEG4 */
1504 MM_VIDEO_CODEC_THEORA /* RECORDER_VIDEO_CODEC_THEORA */
1506 recorder_s *handle = (recorder_s *)recorder;
1508 if (handle == NULL) {
1509 LOGE("handle is NULL");
1510 return RECORDER_ERROR_INVALID_PARAMETER;
1513 if (handle->camera_device_count == 0) {
1514 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1515 return RECORDER_ERROR_NOT_SUPPORTED;
1518 if (codec < RECORDER_VIDEO_CODEC_H263 || codec > RECORDER_VIDEO_CODEC_THEORA) {
1519 LOGE("invalid codec %d", codec);
1520 return RECORDER_ERROR_INVALID_PARAMETER;
1523 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1524 MMCAM_VIDEO_ENCODER, video_table[codec],
1527 return __convert_recorder_error_code(__func__, ret);
1531 int legacy_recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
1533 int ret = MM_ERROR_NONE;
1535 recorder_s *handle = (recorder_s *)recorder;
1537 if (handle == NULL) {
1538 LOGE("handle is NULL");
1539 return RECORDER_ERROR_INVALID_PARAMETER;
1541 if (handle->camera_device_count == 0) {
1542 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1543 return RECORDER_ERROR_NOT_SUPPORTED;
1545 if (codec == NULL) {
1546 LOGE("codec is NULL");
1547 return RECORDER_ERROR_INVALID_PARAMETER;
1550 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1551 MMCAM_VIDEO_ENCODER, &mm_codec,
1553 if (ret == MM_ERROR_NONE) {
1555 case MM_VIDEO_CODEC_H263 :
1556 *codec = RECORDER_VIDEO_CODEC_H263;
1558 case MM_VIDEO_CODEC_H264 :
1559 *codec = RECORDER_VIDEO_CODEC_H264;
1561 case MM_VIDEO_CODEC_MPEG4 :
1562 *codec = RECORDER_VIDEO_CODEC_MPEG4;
1564 case MM_VIDEO_CODEC_THEORA:
1565 *codec = RECORDER_VIDEO_CODEC_THEORA;
1568 ret = MM_ERROR_CAMCORDER_INTERNAL;
1573 return __convert_recorder_error_code(__func__, ret);
1577 int legacy_recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
1579 if (samplerate < 1) {
1580 LOGE("invalid samplerate %d", samplerate);
1581 return RECORDER_ERROR_INVALID_PARAMETER;
1584 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_SAMPLERATE, samplerate);
1588 int legacy_recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
1591 LOGE("invalid bitrate %d", bitrate);
1592 return RECORDER_ERROR_INVALID_PARAMETER;
1595 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER_BITRATE, bitrate);
1599 int legacy_recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
1601 int ret = MM_ERROR_NONE;
1602 recorder_s *handle = (recorder_s *)recorder;
1604 if (handle == NULL) {
1605 LOGE("handle is NULL");
1606 return RECORDER_ERROR_INVALID_PARAMETER;
1608 if (handle->camera_device_count == 0) {
1609 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1610 return RECORDER_ERROR_NOT_SUPPORTED;
1613 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1614 MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1617 return __convert_recorder_error_code(__func__, ret);
1621 int legacy_recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
1623 int ret = MM_ERROR_NONE;
1624 recorder_s *handle = (recorder_s *)recorder;
1626 if (recorder == NULL) {
1627 LOGE("handle is NULL");
1628 return RECORDER_ERROR_INVALID_PARAMETER;
1631 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1632 MMCAM_TARGET_MAX_SIZE, kbyte,
1635 return __convert_recorder_error_code(__func__, ret);
1639 int legacy_recorder_attr_get_time_limit(recorder_h recorder, int *second)
1641 int ret = MM_ERROR_NONE;
1642 recorder_s *handle = (recorder_s *)recorder;
1644 if (recorder == NULL) {
1645 LOGE("handle is NULL");
1646 return RECORDER_ERROR_INVALID_PARAMETER;
1649 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1650 MMCAM_TARGET_TIME_LIMIT, second,
1653 return __convert_recorder_error_code(__func__, ret);
1657 int legacy_recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
1659 int ret = MM_ERROR_NONE;
1660 recorder_s *handle = (recorder_s *)recorder;
1662 if (recorder == NULL) {
1663 LOGE("handle is NULL");
1664 return RECORDER_ERROR_INVALID_PARAMETER;
1667 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1668 MMCAM_AUDIO_DEVICE, device,
1671 return __convert_recorder_error_code(__func__, ret);
1675 int legacy_recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
1677 int ret = MM_ERROR_NONE;
1678 recorder_s *handle = (recorder_s *)recorder;
1680 if (recorder == NULL) {
1681 LOGE("handle is NULL");
1682 return RECORDER_ERROR_INVALID_PARAMETER;
1685 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1686 MMCAM_AUDIO_SAMPLERATE, samplerate,
1689 return __convert_recorder_error_code(__func__, ret);
1693 int legacy_recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
1695 int ret = MM_ERROR_NONE;
1696 recorder_s *handle = (recorder_s *)recorder;
1698 if (recorder == NULL) {
1699 LOGE("handle is NULL");
1700 return RECORDER_ERROR_INVALID_PARAMETER;
1703 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1704 MMCAM_AUDIO_ENCODER_BITRATE, bitrate,
1707 return __convert_recorder_error_code(__func__, ret);
1711 int legacy_recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
1713 int ret = MM_ERROR_NONE;
1714 recorder_s *handle = (recorder_s *)recorder;
1716 if (handle == NULL) {
1717 LOGE("handle is NULL");
1718 return RECORDER_ERROR_INVALID_PARAMETER;
1720 if (handle->camera_device_count == 0) {
1721 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1722 return RECORDER_ERROR_NOT_SUPPORTED;
1724 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1725 MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1728 return __convert_recorder_error_code(__func__, ret);
1732 int legacy_recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
1735 int ret = MM_ERROR_NONE;
1737 recorder_s *handle = (recorder_s *)recorder;
1738 MMCamAttrsInfo info;
1740 if (recorder == NULL) {
1741 LOGE("handle is NULL");
1742 return RECORDER_ERROR_INVALID_PARAMETER;
1744 if (foreach_cb == NULL) {
1745 LOGE("foreach_cb is NULL");
1746 return RECORDER_ERROR_INVALID_PARAMETER;
1749 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_AUDIO_ENCODER, &info);
1750 if (ret != MM_ERROR_NONE) {
1751 return __convert_recorder_error_code(__func__, ret);
1754 for (i = 0 ; i < info.int_array.count ; i++) {
1755 switch (info.int_array.array[i]) {
1756 case MM_AUDIO_CODEC_AMR:
1757 codec = RECORDER_AUDIO_CODEC_AMR;
1759 case MM_AUDIO_CODEC_AAC :
1760 codec = RECORDER_AUDIO_CODEC_AAC;
1762 case MM_AUDIO_CODEC_VORBIS:
1763 codec = RECORDER_AUDIO_CODEC_VORBIS;
1765 case MM_AUDIO_CODEC_WAVE:
1766 codec = RECORDER_AUDIO_CODEC_PCM;
1772 if (codec != -1 && !foreach_cb(codec,user_data)) {
1777 return RECORDER_ERROR_NONE;
1781 int legacy_recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
1784 int ret = MM_ERROR_NONE;
1786 recorder_s *handle = (recorder_s *)recorder;
1787 MMCamAttrsInfo info;
1789 if (handle == NULL) {
1790 LOGE("handle is NULL");
1791 return RECORDER_ERROR_INVALID_PARAMETER;
1793 if (handle->camera_device_count == 0) {
1794 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1795 return RECORDER_ERROR_NOT_SUPPORTED;
1797 if (foreach_cb == NULL) {
1798 LOGE("foreach_cb is NULL");
1799 return RECORDER_ERROR_INVALID_PARAMETER;
1802 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_ENCODER, &info);
1803 if (ret != MM_ERROR_NONE) {
1804 return __convert_recorder_error_code(__func__, ret);
1807 for (i = 0 ; i < info.int_array.count ; i++) {
1808 switch (info.int_array.array[i]){
1809 case MM_VIDEO_CODEC_H263 :
1810 codec = RECORDER_VIDEO_CODEC_H263;
1812 case MM_VIDEO_CODEC_H264 :
1813 codec = RECORDER_VIDEO_CODEC_H264;
1815 case MM_VIDEO_CODEC_MPEG4 :
1816 codec = RECORDER_VIDEO_CODEC_MPEG4;
1818 case MM_VIDEO_CODEC_THEORA :
1819 codec = RECORDER_VIDEO_CODEC_THEORA;
1826 if (codec != -1 && !foreach_cb(codec,user_data)) {
1831 return RECORDER_ERROR_NONE;
1835 int legacy_recorder_attr_set_mute(recorder_h recorder, bool enable)
1837 int ret = MM_ERROR_NONE;
1838 recorder_s *handle = (recorder_s *)recorder;
1840 if (recorder == NULL) {
1841 LOGE("handle is NULL");
1842 return RECORDER_ERROR_INVALID_PARAMETER;
1845 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1846 MMCAM_AUDIO_VOLUME, enable ? 0.0 : 1.0,
1849 return __convert_recorder_error_code(__func__, ret);
1853 bool legacy_recorder_attr_is_muted(recorder_h recorder)
1855 int ret = MM_ERROR_NONE;
1856 double volume = 1.0;
1857 recorder_s *handle = (recorder_s *)recorder;
1859 if (recorder == NULL) {
1860 LOGE("handle is NULL");
1864 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1865 MMCAM_AUDIO_VOLUME, &volume,
1868 set_last_result(__convert_recorder_error_code(__func__, ret));
1870 if (volume == 0.0) {
1878 int legacy_recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
1880 int ret = MM_ERROR_NONE;
1881 recorder_s *handle = (recorder_s *)recorder;
1883 if (handle == NULL) {
1884 LOGE("handle is NULL");
1885 return RECORDER_ERROR_INVALID_PARAMETER;
1887 if (handle->camera_device_count == 0) {
1888 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1889 return RECORDER_ERROR_NOT_SUPPORTED;
1891 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1892 MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1895 return __convert_recorder_error_code(__func__, ret);
1899 int legacy_recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
1901 int ret = MM_ERROR_NONE;
1902 recorder_s *handle = (recorder_s *)recorder;
1904 if (handle == NULL) {
1905 LOGE("handle is NULL");
1906 return RECORDER_ERROR_INVALID_PARAMETER;
1908 if (handle->camera_device_count == 0) {
1909 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1910 return RECORDER_ERROR_NOT_SUPPORTED;
1913 LOGE("rate is NULL");
1914 return RECORDER_ERROR_INVALID_PARAMETER;
1917 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1918 MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1921 return __convert_recorder_error_code(__func__, ret);
1925 int legacy_recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
1927 if (channel_count < 1) {
1928 LOGE("invalid channel %d", channel_count);
1929 return RECORDER_ERROR_INVALID_PARAMETER;
1932 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_CHANNEL, channel_count);
1936 int legacy_recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
1938 int ret = MM_ERROR_NONE;
1939 recorder_s *handle = (recorder_s *)recorder;
1941 if (recorder == NULL) {
1942 LOGE("handle is NULL");
1943 return RECORDER_ERROR_INVALID_PARAMETER;
1945 if (channel_count == NULL) {
1946 LOGE("channel_count is NULL");
1947 return RECORDER_ERROR_INVALID_PARAMETER;
1950 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1951 MMCAM_AUDIO_CHANNEL, channel_count,
1954 return __convert_recorder_error_code(__func__, ret);
1958 int legacy_recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
1960 int ret = MM_ERROR_NONE;
1961 recorder_s *handle = (recorder_s *)recorder;
1963 if (handle == NULL) {
1964 LOGE("handle is NULL");
1965 return RECORDER_ERROR_INVALID_PARAMETER;
1967 if (handle->camera_device_count == 0) {
1968 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1969 return RECORDER_ERROR_NOT_SUPPORTED;
1971 if (orientation > RECORDER_ROTATION_270) {
1972 LOGE("invalid orientation %d", orientation);
1973 return RECORDER_ERROR_INVALID_PARAMETER;
1976 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1977 MMCAM_RECORDER_TAG_ENABLE, true,
1978 MMCAM_TAG_VIDEO_ORIENTATION, orientation,
1981 return __convert_recorder_error_code(__func__, ret);
1985 int legacy_recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
1987 int ret = MM_ERROR_NONE;
1988 recorder_s *handle = (recorder_s *)recorder;
1990 if (handle == NULL) {
1991 LOGE("handle is NULL");
1992 return RECORDER_ERROR_INVALID_PARAMETER;
1994 if (handle->camera_device_count == 0) {
1995 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1996 return RECORDER_ERROR_NOT_SUPPORTED;
1998 if (orientation == NULL) {
1999 LOGE("orientation is NULL");
2000 return RECORDER_ERROR_INVALID_PARAMETER;
2003 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
2004 MMCAM_TAG_VIDEO_ORIENTATION, orientation,
2007 return __convert_recorder_error_code(__func__, ret);