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
43 * camera_private function
45 int _camera_get_mm_handle(camera_h camera , MMHandleType *handle);
46 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data);
47 int _camera_set_use(camera_h camera, bool used);
48 bool _camera_is_used(camera_h camera);
50 * end of camera_private function
53 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param);
54 static int __mm_recorder_msg_cb(int message, void *param, void *user_data);
57 static int __convert_error_code_camera_to_recorder(int code)
62 case CAMERA_ERROR_INVALID_STATE :
63 new_code = RECORDER_ERROR_INVALID_STATE;
65 case CAMERA_ERROR_DEVICE:
66 new_code = RECORDER_ERROR_DEVICE;
68 case CAMERA_ERROR_SOUND_POLICY:
69 new_code = RECORDER_ERROR_SOUND_POLICY;
71 case CAMERA_ERROR_SECURITY_RESTRICTED:
72 new_code = RECORDER_ERROR_SECURITY_RESTRICTED;
82 int __convert_recorder_error_code(const char *func, int code)
84 int ret = RECORDER_ERROR_INVALID_OPERATION;
85 const char *errorstr = NULL;
88 case RECORDER_ERROR_INVALID_PARAMETER:
89 ret = RECORDER_ERROR_INVALID_PARAMETER;
90 errorstr = "INVALID_PARAMETER";
93 ret = RECORDER_ERROR_NONE;
94 errorstr = "ERROR_NONE";
96 case MM_ERROR_CAMCORDER_INVALID_ARGUMENT :
97 case MM_ERROR_COMMON_INVALID_ATTRTYPE :
98 ret = RECORDER_ERROR_INVALID_PARAMETER;
99 errorstr = "INVALID_PARAMETER";
101 case MM_ERROR_COMMON_INVALID_PERMISSION :
102 ret = RECORDER_ERROR_PERMISSION_DENIED;
103 errorstr = "ERROR_PERMISSION_DENIED";
105 case MM_ERROR_CAMCORDER_NOT_INITIALIZED :
106 case MM_ERROR_CAMCORDER_INVALID_STATE :
107 ret = RECORDER_ERROR_INVALID_STATE;
108 errorstr = "INVALID_STATE";
110 case MM_ERROR_CAMCORDER_DEVICE :
111 case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND :
112 case MM_ERROR_CAMCORDER_DEVICE_BUSY :
113 case MM_ERROR_CAMCORDER_DEVICE_OPEN :
114 case MM_ERROR_CAMCORDER_DEVICE_IO :
115 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT :
116 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG :
117 case MM_ERROR_CAMCORDER_DEVICE_LACK_BUFFER :
118 ret = RECORDER_ERROR_DEVICE;
119 errorstr = "ERROR_DEVICE";
121 case MM_ERROR_CAMCORDER_GST_CORE :
122 case MM_ERROR_CAMCORDER_GST_LIBRARY :
123 case MM_ERROR_CAMCORDER_GST_RESOURCE :
124 case MM_ERROR_CAMCORDER_GST_STREAM :
125 case MM_ERROR_CAMCORDER_GST_STATECHANGE :
126 case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
127 case MM_ERROR_CAMCORDER_GST_LINK :
128 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
129 case MM_ERROR_CAMCORDER_ENCODER :
130 case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
131 case MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE :
132 case MM_ERROR_CAMCORDER_ENCODER_WORKING :
133 case MM_ERROR_CAMCORDER_INTERNAL :
134 case MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT :
135 case MM_ERROR_CAMCORDER_CMD_IS_RUNNING :
136 case MM_ERROR_CAMCORDER_DSP_FAIL :
137 case MM_ERROR_CAMCORDER_AUDIO_EMPTY :
138 case MM_ERROR_CAMCORDER_CREATE_CONFIGURE :
139 case MM_ERROR_CAMCORDER_FILE_SIZE_OVER :
140 case MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF :
141 case MM_ERROR_CAMCORDER_INVALID_CONDITION :
142 ret = RECORDER_ERROR_INVALID_OPERATION;
143 errorstr = "INVALID_OPERATION";
145 case MM_ERROR_CAMCORDER_RESOURCE_CREATION :
146 case MM_ERROR_COMMON_OUT_OF_MEMORY:
147 ret = RECORDER_ERROR_OUT_OF_MEMORY;
148 errorstr = "OUT_OF_MEMORY";
150 case MM_ERROR_POLICY_BLOCKED:
151 ret = RECORDER_ERROR_SOUND_POLICY;
152 errorstr = "ERROR_SOUND_POLICY";
154 case MM_ERROR_POLICY_BLOCKED_BY_CALL:
155 ret = RECORDER_ERROR_SOUND_POLICY_BY_CALL;
156 errorstr = "ERROR_SOUND_POLICY_BY_CALL";
158 case MM_ERROR_POLICY_BLOCKED_BY_ALARM:
159 ret = RECORDER_ERROR_SOUND_POLICY_BY_ALARM;
160 errorstr = "ERROR_SOUND_POLICY_BY_ALARM";
162 case MM_ERROR_POLICY_RESTRICTED:
163 ret = RECORDER_ERROR_SECURITY_RESTRICTED;
164 errorstr = "ERROR_RESTRICTED";
166 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
167 ret = RECORDER_ERROR_ESD;
168 errorstr = "ERROR_ESD";
170 case MM_ERROR_OUT_OF_STORAGE:
171 ret = RECORDER_ERROR_OUT_OF_STORAGE;
172 errorstr = "OUT_OF_STORAGE";
174 case MM_ERROR_COMMON_OUT_OF_ARRAY:
175 case MM_ERROR_COMMON_OUT_OF_RANGE:
176 case MM_ERROR_COMMON_ATTR_NOT_EXIST:
177 case MM_ERROR_CAMCORDER_NOT_SUPPORTED:
178 ret = RECORDER_ERROR_NOT_SUPPORTED;
179 errorstr = "NOT_SUPPORTED";
182 ret = RECORDER_ERROR_INVALID_OPERATION;
183 errorstr = "INVALID_OPERATION";
187 LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code);
193 static recorder_state_e __recorder_state_convert(MMCamcorderStateType mm_state)
195 recorder_state_e state = RECORDER_STATE_NONE;
197 case MM_CAMCORDER_STATE_NONE:
198 state = RECORDER_STATE_NONE;
200 case MM_CAMCORDER_STATE_NULL:
201 state = RECORDER_STATE_CREATED;
203 case MM_CAMCORDER_STATE_READY:
204 state = RECORDER_STATE_CREATED;
206 case MM_CAMCORDER_STATE_PREPARE:
207 state = RECORDER_STATE_READY;
209 case MM_CAMCORDER_STATE_CAPTURING:
210 state = RECORDER_STATE_READY;
212 case MM_CAMCORDER_STATE_RECORDING:
213 state = RECORDER_STATE_RECORDING;
215 case MM_CAMCORDER_STATE_PAUSED:
216 state = RECORDER_STATE_PAUSED;
219 state = RECORDER_STATE_NONE;
227 static int __mm_recorder_msg_cb(int message, void *param, void *user_data)
229 recorder_s * handle = (recorder_s *)user_data;
230 MMMessageParamType *m = (MMMessageParamType *)param;
231 recorder_state_e previous_state;
232 recorder_recording_limit_type_e type;
233 int recorder_error = 0;
236 case MM_MESSAGE_READY_TO_RESUME:
237 LOGW("not supported message");
239 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
240 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
241 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY:
242 previous_state = handle->state;
243 handle->state = __recorder_state_convert(m->state.current);
244 recorder_policy_e policy = RECORDER_POLICY_NONE;
245 if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM) {
246 switch (m->state.code) {
247 case ASM_EVENT_SOURCE_CALL_START:
248 case ASM_EVENT_SOURCE_CALL_END:
249 policy = RECORDER_POLICY_SOUND_BY_CALL;
250 LOGE("RECORDER_POLICY_SOUND_BY_CALL");
252 case ASM_EVENT_SOURCE_ALARM_START:
253 case ASM_EVENT_SOURCE_ALARM_END:
254 policy = RECORDER_POLICY_SOUND_BY_ALARM;
255 LOGE("RECORDER_POLICY_SOUND_BY_ALARM");
258 policy = RECORDER_POLICY_SOUND;
259 LOGE("RECORDER_POLICY_SOUND");
262 } else if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY) {
263 policy = RECORDER_POLICY_SECURITY;
264 LOGE("RECORDER_POLICY_SECURITY");
267 if (previous_state != handle->state && handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE]) {
268 ((recorder_state_changed_cb)handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state, policy, handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE]);
271 /* should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state */
272 if (policy != RECORDER_POLICY_NONE &&
273 (m->state.current == MM_CAMCORDER_STATE_PAUSED || m->state.current == MM_CAMCORDER_STATE_NULL)) {
274 if (handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED]) {
275 ((recorder_interrupted_cb)handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED]);
277 LOGW("_RECORDER_EVENT_TYPE_INTERRUPTED cb is NULL");
281 case MM_MESSAGE_CAMCORDER_MAX_SIZE:
282 case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
283 case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
284 if (MM_MESSAGE_CAMCORDER_MAX_SIZE == message) {
285 type = RECORDER_RECORDING_LIMIT_SIZE;
286 } else if (MM_MESSAGE_CAMCORDER_NO_FREE_SPACE == message) {
287 type = RECORDER_RECORDING_LIMIT_FREE_SPACE;
289 type = RECORDER_RECORDING_LIMIT_TIME;
291 if (handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]) {
292 ((recorder_recording_limit_reached_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED])(type, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
295 case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
296 if (handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS]) {
297 ((recorder_recording_status_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS])(m->recording_status.elapsed, m->recording_status.filesize, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
300 case MM_MESSAGE_CAMCORDER_ERROR:
302 case MM_ERROR_CAMCORDER_DEVICE:
303 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT:
304 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG:
305 recorder_error = RECORDER_ERROR_DEVICE;
307 case MM_ERROR_CAMCORDER_GST_CORE:
308 case MM_ERROR_CAMCORDER_GST_LIBRARY:
309 case MM_ERROR_CAMCORDER_GST_RESOURCE:
310 case MM_ERROR_CAMCORDER_GST_STREAM:
311 case MM_ERROR_CAMCORDER_GST_NEGOTIATION:
312 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR:
313 case MM_ERROR_CAMCORDER_ENCODER:
314 case MM_ERROR_CAMCORDER_ENCODER_BUFFER:
315 case MM_ERROR_CAMCORDER_ENCODER_WORKING:
316 case MM_ERROR_CAMCORDER_MNOTE_CREATION:
317 case MM_ERROR_CAMCORDER_MNOTE_ADD_ENTRY:
318 case MM_ERROR_CAMCORDER_INTERNAL:
319 case MM_ERROR_FILE_NOT_FOUND:
320 case MM_ERROR_FILE_READ:
321 recorder_error = RECORDER_ERROR_INVALID_OPERATION;
323 case MM_ERROR_CAMCORDER_LOW_MEMORY:
324 case MM_ERROR_CAMCORDER_MNOTE_MALLOC:
325 recorder_error = RECORDER_ERROR_OUT_OF_MEMORY;
327 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE:
328 recorder_error = RECORDER_ERROR_ESD;
330 case MM_ERROR_OUT_OF_STORAGE:
331 recorder_error = RECORDER_ERROR_OUT_OF_STORAGE;
334 recorder_error = RECORDER_ERROR_INVALID_OPERATION;
338 if (recorder_error != 0 && handle->user_cb[_RECORDER_EVENT_TYPE_ERROR]) {
339 ((recorder_error_cb)handle->user_cb[_RECORDER_EVENT_TYPE_ERROR])(recorder_error, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_ERROR]);
342 case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
343 if (handle->last_max_input_level < m->rec_volume_dB) {
344 handle->last_max_input_level = m->rec_volume_dB;
355 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param)
357 if (user_param == NULL || stream == NULL) {
361 recorder_s *handle = (recorder_s *)user_param;
362 audio_sample_type_e format = AUDIO_SAMPLE_TYPE_U8;
364 if (stream->format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
365 format = AUDIO_SAMPLE_TYPE_S16_LE;
368 if( handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] ){
369 ((recorder_audio_stream_cb)(handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM]))(stream->data, stream->length, format,
370 stream->channel, stream->timestamp,
371 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
378 static int _recorder_check_and_set_attribute(recorder_h recorder, const char *attribute_name, int set_value)
380 bool reset_pipeline = false;
381 bool restore_set = false;
382 int ret = MM_ERROR_NONE;
383 int ret2 = MM_ERROR_NONE;
384 int current_value = -1;
385 int current_audio_disable = 0;
387 recorder_s *handle = (recorder_s *)recorder;
388 MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
390 if (recorder == NULL) {
391 LOGE("handle is NULL");
392 return RECORDER_ERROR_INVALID_PARAMETER;
395 mm_camcorder_get_state(handle->mm_handle, &mmstate);
396 if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
397 LOGE("invalid state %d", mmstate);
398 return RECORDER_ERROR_INVALID_STATE;
401 if (handle->type == _RECORDER_TYPE_AUDIO && mmstate == MM_CAMCORDER_STATE_PREPARE) {
402 mm_camcorder_get_attributes(handle->mm_handle, NULL,
403 MMCAM_AUDIO_DISABLE, ¤t_audio_disable,
404 attribute_name, ¤t_value,
407 if (current_value != set_value) {
408 LOGD("try to reset pipeline");
410 ret = mm_camcorder_stop(handle->mm_handle);
411 if (ret != MM_ERROR_NONE) {
412 LOGE("mm_camcorder_stop failed 0x%x", ret);
413 return __convert_recorder_error_code(attribute_name, ret);
416 ret = mm_camcorder_unrealize(handle->mm_handle);
417 if (ret != MM_ERROR_NONE) {
418 LOGE("mm_camcorder_unrealize failed 0x%x", ret);
419 mm_camcorder_start(handle->mm_handle);
420 return __convert_recorder_error_code(attribute_name, ret);
423 reset_pipeline = true;
427 if (!strcmp(attribute_name, MMCAM_AUDIO_ENCODER)) {
428 if (set_value == RECORDER_AUDIO_CODEC_DISABLE) {
429 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
430 MMCAM_AUDIO_DISABLE, true,
433 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
434 MMCAM_AUDIO_DISABLE, false,
435 MMCAM_AUDIO_ENCODER, set_value,
439 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
440 attribute_name, set_value,
444 if (ret != MM_ERROR_NONE) {
445 LOGE("set [%s] failed 0x%x", attribute_name, ret);
448 if (reset_pipeline) {
449 ret2 = mm_camcorder_realize(handle->mm_handle);
450 if (ret2 == MM_ERROR_NONE) {
451 ret2 = mm_camcorder_start(handle->mm_handle);
452 if (ret2 == MM_ERROR_NONE) {
453 LOGW("restart pipeline done.");
455 LOGE("mm_camcorder_start failed 0x%x", ret2);
456 mm_camcorder_unrealize(handle->mm_handle);
459 LOGE("mm_camcorder_realize failed 0x%x", ret2);
462 if (ret2 != MM_ERROR_NONE) {
464 /* determine return value */
465 if (ret == MM_ERROR_NONE) {
472 ret2 = mm_camcorder_set_attributes(handle->mm_handle, NULL,
473 MMCAM_AUDIO_DISABLE, current_audio_disable,
474 attribute_name, current_value,
476 LOGW("restore attribute set : 0x%x", ret2);
478 ret2 = mm_camcorder_realize(handle->mm_handle);
479 LOGW("restore mm_camcorder_realize : 0x%x", ret2);
481 ret2 = mm_camcorder_start(handle->mm_handle);
482 LOGW("restore mm_camcorder_realize : 0x%x", ret2);
483 if (ret2 != MM_ERROR_NONE) {
484 ret2 = mm_camcorder_unrealize(handle->mm_handle);
485 LOGW("restore mm_camcorder_unrealize : 0x%x", ret2);
489 return __convert_recorder_error_code(attribute_name, ret);
493 int legacy_recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
495 int ret = MM_ERROR_NONE;
496 recorder_s *handle = NULL;
497 int preview_format = MM_PIXEL_FORMAT_NV12;
498 int camera_device_count = 0;
500 if (camera == NULL) {
501 LOGE("NULL pointer camera handle");
502 return RECORDER_ERROR_INVALID_PARAMETER;
504 if (recorder == NULL) {
505 LOGE("NULL pointer recorder handle");
506 return RECORDER_ERROR_INVALID_PARAMETER;
509 /* Check already used in another recorder */
510 if (_camera_is_used(camera)) {
511 LOGE("[%s] camera is using in another recorder.", __func__);
512 return RECORDER_ERROR_INVALID_PARAMETER;
515 handle = (recorder_s*)malloc( sizeof(recorder_s) );
517 LOGE("[%s] malloc error", __func__);
518 return RECORDER_ERROR_OUT_OF_MEMORY;
521 memset(handle, 0 , sizeof(recorder_s));
522 handle->src_type = _RECORDER_SOURCE_TYPE_CAMERA;
523 handle->last_max_input_level = LOWSET_DECIBEL;
524 handle->changed_preview_format = -1;
525 handle->mm_source.camera = camera;
527 _camera_get_mm_handle(camera, &handle->mm_handle);
528 _camera_set_relay_mm_message_callback(camera, __mm_recorder_msg_cb , (void*)handle);
529 handle->type = _RECORDER_TYPE_VIDEO;
530 legacy_recorder_get_state((recorder_h)handle, (recorder_state_e*)&handle->state);
532 mm_camcorder_get_attributes(handle->mm_handle, NULL,
533 MMCAM_CAMERA_FORMAT, &preview_format,
535 handle->origin_preview_format = preview_format;
536 mm_camcorder_get_attributes(handle->mm_handle, NULL,
537 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, &preview_format,
539 ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL,
540 MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count,
542 if (ret != MM_ERROR_NONE) {
545 LOGE("get device count error");
546 return __convert_recorder_error_code(__func__, ret);
548 if (camera_device_count == 0) {
551 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
552 return RECORDER_ERROR_NOT_SUPPORTED;
554 handle->camera_device_count = camera_device_count;
557 _camera_set_use(camera, true);
558 if (handle->state == RECORDER_STATE_CREATED) {
559 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
560 MMCAM_CAMERA_FORMAT, preview_format,
562 if (ret == MM_ERROR_NONE) {
563 handle->changed_preview_format = preview_format;
566 *recorder = (recorder_h)handle;
568 return RECORDER_ERROR_NONE;
572 int legacy_recorder_create_audiorecorder(recorder_h *recorder)
574 int ret = MM_ERROR_NONE;
575 recorder_s *handle = NULL;
577 int camera_device_count = 0;
579 if (recorder == NULL) {
580 LOGE("NULL pointer handle");
581 return RECORDER_ERROR_INVALID_PARAMETER;
584 info.videodev_type = MM_VIDEO_DEVICE_NONE;
586 handle = (recorder_s *)malloc(sizeof(recorder_s));
587 if (handle == NULL) {
588 LOGE("OUT_OF_MEMORY(0x%08x)", RECORDER_ERROR_OUT_OF_MEMORY);
589 return RECORDER_ERROR_OUT_OF_MEMORY;
592 memset(handle, 0, sizeof(recorder_s));
594 handle->last_max_input_level = LOWSET_DECIBEL;
596 ret = mm_camcorder_create(&handle->mm_handle, &info);
597 if (ret != MM_ERROR_NONE) {
600 LOGE("mm_camcorder_create fail");
601 return __convert_recorder_error_code(__func__, ret);
604 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
605 MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
608 if (ret != MM_ERROR_NONE) {
609 mm_camcorder_destroy(handle->mm_handle);
612 LOGE("AUDIO mode setting fail");
613 return __convert_recorder_error_code(__func__, ret);
615 ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL,
616 MMCAM_CAMERA_DEVICE_COUNT, &camera_device_count, NULL);
617 if (ret != MM_ERROR_NONE) {
618 mm_camcorder_destroy(handle->mm_handle);
621 LOGE("get device count error");
622 return __convert_recorder_error_code(__func__, ret);
624 handle->camera_device_count = camera_device_count;
626 handle->state = RECORDER_STATE_CREATED;
627 handle->mm_source.camera = NULL;
628 handle->type = _RECORDER_TYPE_AUDIO;
630 mm_camcorder_set_message_callback(handle->mm_handle, __mm_recorder_msg_cb, (void*)handle);
632 *recorder = (recorder_h)handle;
634 return RECORDER_ERROR_NONE;
638 int legacy_recorder_get_state(recorder_h recorder, recorder_state_e *state)
640 int ret = MM_ERROR_NONE;
641 MMCamcorderStateType mmstate;
643 if (recorder == NULL) {
644 LOGE("NULL pointer handle");
645 return RECORDER_ERROR_INVALID_PARAMETER;
648 LOGE("NULL pointer state");
649 return RECORDER_ERROR_INVALID_PARAMETER;
652 recorder_s *handle = (recorder_s*)recorder;
654 ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
655 if (ret != MM_ERROR_NONE) {
656 return __convert_recorder_error_code(__func__, ret);
659 *state = __recorder_state_convert(mmstate);
661 return RECORDER_ERROR_NONE;
665 int legacy_recorder_destroy(recorder_h recorder)
667 recorder_s *handle = NULL;
668 int ret = MM_ERROR_NONE;
671 if (recorder == NULL) {
672 LOGE("NULL pointer handle");
673 return RECORDER_ERROR_INVALID_PARAMETER;
676 handle = (recorder_s *)recorder;
678 if (handle->type == _RECORDER_TYPE_VIDEO) {
680 _camera_set_use(handle->mm_source.camera, false);
681 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
682 MMCAM_CAMERA_FORMAT, &preview_format,
685 /* preview format was changed? */
686 if (ret == MM_ERROR_NONE && preview_format == handle->changed_preview_format) {
687 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
688 MMCAM_CAMERA_FORMAT, handle->origin_preview_format,
692 if (ret == MM_ERROR_NONE) {
693 _camera_set_relay_mm_message_callback(handle->mm_source.camera, NULL, NULL);
696 ret = mm_camcorder_destroy(handle->mm_handle);
699 if (ret == MM_ERROR_NONE) {
703 return __convert_recorder_error_code(__func__, ret);
707 int legacy_recorder_prepare(recorder_h recorder)
709 int ret = MM_ERROR_NONE;
710 recorder_s *handle = (recorder_s *)recorder;
711 MMCamcorderStateType mmstate;
713 if (recorder == NULL) {
714 LOGE("NULL pointer handle");
715 return RECORDER_ERROR_INVALID_PARAMETER;
718 if (handle->type == _RECORDER_TYPE_VIDEO) {
719 return __convert_error_code_camera_to_recorder(legacy_camera_start_preview(handle->mm_source.camera));
722 ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
724 if (ret == MM_ERROR_NONE && mmstate < MM_CAMCORDER_STATE_READY) {
725 ret = mm_camcorder_realize(handle->mm_handle);
726 if (ret != MM_ERROR_NONE) {
727 LOGE("mm_camcorder_realize fail");
728 return __convert_recorder_error_code(__func__, ret);
732 ret = mm_camcorder_start(handle->mm_handle);
733 if (ret != MM_ERROR_NONE) {
734 LOGE("mm_camcorder_start fail");
735 mm_camcorder_unrealize(handle->mm_handle);
736 return __convert_recorder_error_code(__func__, ret);
739 return RECORDER_ERROR_NONE;
743 int legacy_recorder_unprepare(recorder_h recorder)
745 int ret = MM_ERROR_NONE;
746 recorder_s *handle = (recorder_s *)recorder;
747 MMCamcorderStateType mmstate;
749 if (recorder == NULL) {
750 LOGE("NULL pointer handle");
751 return RECORDER_ERROR_INVALID_PARAMETER;
754 ret = mm_camcorder_get_state(handle->mm_handle, &mmstate);
755 if (ret == MM_ERROR_NONE && mmstate == MM_CAMCORDER_STATE_PREPARE) {
756 ret = mm_camcorder_stop(handle->mm_handle);
757 if( ret != MM_ERROR_NONE){
758 LOGE("mm_camcorder_stop fail");
762 if (ret == MM_ERROR_NONE) {
763 ret = mm_camcorder_unrealize(handle->mm_handle);
764 if (ret != MM_ERROR_NONE) {
765 LOGE("mm_camcorder_unrealize fail");
766 mm_camcorder_start(handle->mm_handle);
770 return __convert_recorder_error_code(__func__, ret);
774 int legacy_recorder_start(recorder_h recorder)
776 recorder_s *handle = (recorder_s *)recorder;
778 if (recorder == NULL) {
779 LOGE("NULL pointer handle");
780 return RECORDER_ERROR_INVALID_PARAMETER;
783 return __convert_recorder_error_code(__func__, mm_camcorder_record(handle->mm_handle));
787 int legacy_recorder_pause(recorder_h recorder)
789 recorder_s *handle = (recorder_s *)recorder;
791 if (recorder == NULL) {
792 LOGE("NULL pointer handle");
793 return RECORDER_ERROR_INVALID_PARAMETER;
796 return __convert_recorder_error_code(__func__, mm_camcorder_pause(handle->mm_handle));
800 int legacy_recorder_commit(recorder_h recorder)
802 recorder_s *handle = (recorder_s *)recorder;
804 if (recorder == NULL) {
805 LOGE("NULL pointer handle");
806 return RECORDER_ERROR_INVALID_PARAMETER;
809 return __convert_recorder_error_code(__func__, mm_camcorder_commit(handle->mm_handle));
813 int legacy_recorder_cancel(recorder_h recorder)
815 recorder_s *handle = (recorder_s *)recorder;
817 if (recorder == NULL) {
818 LOGE("NULL pointer handle");
819 return RECORDER_ERROR_INVALID_PARAMETER;
822 return __convert_recorder_error_code(__func__, mm_camcorder_cancel(handle->mm_handle));
826 int legacy_recorder_set_video_resolution(recorder_h recorder, int width, int height)
828 int ret = MM_ERROR_NONE;
829 recorder_s *handle = (recorder_s*)recorder;
830 recorder_state_e state;
832 if (handle == NULL) {
833 LOGE("NULL pointer handle");
834 return RECORDER_ERROR_INVALID_PARAMETER;
836 if (handle->camera_device_count == 0) {
837 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
838 return RECORDER_ERROR_NOT_SUPPORTED;
840 legacy_recorder_get_state(recorder, &state);
841 if (state > RECORDER_STATE_READY) {
842 LOGE("RECORDER_ERROR_INVALID_STATE (state:%d)", state);
843 return RECORDER_ERROR_INVALID_STATE;
846 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
847 MMCAM_VIDEO_WIDTH, width,
848 MMCAM_VIDEO_HEIGHT, height,
851 return __convert_recorder_error_code(__func__, ret);
855 int legacy_recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
857 int ret = MM_ERROR_NONE;
858 recorder_s *handle = (recorder_s*)recorder;
861 LOGE("NULL pointer handle");
862 return RECORDER_ERROR_INVALID_PARAMETER;
865 if (handle->camera_device_count == 0) {
866 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
867 return RECORDER_ERROR_NOT_SUPPORTED;
870 if (!width || !height) {
871 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
872 return RECORDER_ERROR_INVALID_PARAMETER;
875 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
876 MMCAM_VIDEO_WIDTH, width,
877 MMCAM_VIDEO_HEIGHT, height,
880 return __convert_recorder_error_code(__func__, ret);
884 int legacy_recorder_foreach_supported_video_resolution(recorder_h recorder,
885 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
888 int ret = MM_ERROR_NONE;
889 recorder_s * handle = (recorder_s*)recorder;
890 MMCamAttrsInfo video_width;
891 MMCamAttrsInfo video_height;
894 LOGE("NULL pointer handle");
895 return RECORDER_ERROR_INVALID_PARAMETER;
898 if (handle->camera_device_count == 0) {
899 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
900 return RECORDER_ERROR_NOT_SUPPORTED;
904 LOGE("NULL pointer callback");
905 return RECORDER_ERROR_INVALID_PARAMETER;
908 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_WIDTH, &video_width);
909 ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_HEIGHT, &video_height);
911 if (ret != MM_ERROR_NONE ) {
912 return __convert_recorder_error_code(__func__, ret);
915 for (i = 0 ; i < video_width.int_array.count ; i++) {
916 if (!foreach_cb(video_width.int_array.array[i], video_height.int_array.array[i], user_data)) {
921 return RECORDER_ERROR_NONE;
925 int legacy_recorder_get_audio_level(recorder_h recorder, double *level)
927 recorder_s *handle = (recorder_s *)recorder;
928 recorder_state_e state;
930 if (recorder == NULL || level == NULL) {
931 LOGE("NULL pointer %p %p", recorder, level);
932 return RECORDER_ERROR_INVALID_PARAMETER;
935 legacy_recorder_get_state(recorder, &state);
936 if (state < RECORDER_STATE_RECORDING) {
937 LOGE("RECORDER_ERROR_INVALID_STATE(0x%08x)", RECORDER_ERROR_INVALID_STATE);
938 return RECORDER_ERROR_INVALID_STATE;
941 *level = handle->last_max_input_level;
942 handle->last_max_input_level = LOWSET_DECIBEL;
944 return RECORDER_ERROR_NONE;
948 int legacy_recorder_set_filename(recorder_h recorder, const char *filename)
950 int ret = MM_ERROR_NONE;
951 recorder_s *handle = (recorder_s *)recorder;
952 MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
954 if (recorder == NULL) {
955 LOGE("handle is NULL");
956 return RECORDER_ERROR_INVALID_PARAMETER;
959 if (filename == NULL) {
960 LOGE("filename is NULL");
961 return RECORDER_ERROR_INVALID_PARAMETER;
964 mm_camcorder_get_state(handle->mm_handle, &mmstate);
965 if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
966 LOGE("invalid state %d", mmstate);
967 return RECORDER_ERROR_INVALID_STATE;
970 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
971 MMCAM_TARGET_FILENAME, filename, strlen(filename),
974 return __convert_recorder_error_code(__func__, ret);
978 int legacy_recorder_get_filename(recorder_h recorder, char **filename)
980 int ret = MM_ERROR_NONE;
981 char *record_filename = NULL;
982 int record_filename_size;
983 recorder_s *handle = (recorder_s *)recorder;
985 if (recorder == NULL) {
986 LOGE("handle is NULL");
987 return RECORDER_ERROR_INVALID_PARAMETER;
990 if (filename == NULL) {
991 LOGE("filename is NULL");
992 return RECORDER_ERROR_INVALID_PARAMETER;
995 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
996 MMCAM_TARGET_FILENAME, &record_filename, &record_filename_size,
998 if (ret == MM_ERROR_NONE && record_filename) {
999 *filename = strdup(record_filename);
1001 LOGE("internal return (0x%08x), get filename p:%p", ret, record_filename);
1005 return __convert_recorder_error_code(__func__, ret);
1009 int legacy_recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
1011 int format_table[6] = { MM_FILE_FORMAT_3GP, /* RECORDER_FILE_FORMAT_3GP */
1012 MM_FILE_FORMAT_MP4, /* RECORDER_FILE_FORMAT_MP4 */
1013 MM_FILE_FORMAT_AMR, /* RECORDER_FILE_FORMAT_AMR */
1014 MM_FILE_FORMAT_AAC, /* RECORDER_FILE_FORMAT_ADTS */
1015 MM_FILE_FORMAT_WAV, /* RECORDER_FILE_FORMAT_WAV */
1016 MM_FILE_FORMAT_OGG /* RECORDER_FILE_FORMAT_OGG */
1019 if (format < RECORDER_FILE_FORMAT_3GP || format > RECORDER_FILE_FORMAT_OGG) {
1020 LOGE("invalid format %d", format);
1021 return RECORDER_ERROR_INVALID_PARAMETER;
1024 return _recorder_check_and_set_attribute(recorder, MMCAM_FILE_FORMAT, format_table[format]);
1028 int legacy_recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
1030 int ret = MM_ERROR_NONE;
1031 recorder_s *handle = (recorder_s *)recorder;
1034 if (recorder == NULL) {
1035 LOGE("handle is NULL");
1036 return RECORDER_ERROR_INVALID_PARAMETER;
1039 if (format == NULL) {
1040 LOGE("format is NULL");
1041 return RECORDER_ERROR_INVALID_PARAMETER;
1044 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1045 MMCAM_FILE_FORMAT, &mm_format,
1047 if (ret == MM_ERROR_NONE) {
1048 switch (mm_format) {
1049 case MM_FILE_FORMAT_3GP:
1050 *format = RECORDER_FILE_FORMAT_3GP;
1052 case MM_FILE_FORMAT_MP4 :
1053 *format = RECORDER_FILE_FORMAT_MP4;
1055 case MM_FILE_FORMAT_AMR :
1056 *format = RECORDER_FILE_FORMAT_AMR;
1058 case MM_FILE_FORMAT_AAC :
1059 *format = RECORDER_FILE_FORMAT_ADTS;
1061 case MM_FILE_FORMAT_WAV:
1062 *format = RECORDER_FILE_FORMAT_WAV;
1064 case MM_FILE_FORMAT_OGG:
1065 *format = RECORDER_FILE_FORMAT_OGG;
1068 ret = MM_ERROR_CAMCORDER_INTERNAL;
1073 return __convert_recorder_error_code(__func__, ret);
1077 int legacy_recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
1079 recorder_s *handle = (recorder_s *)recorder;
1081 if (recorder == NULL) {
1082 LOGE("NULL pointer handle");
1083 return RECORDER_ERROR_INVALID_PARAMETER;
1086 if (callback == NULL) {
1087 LOGE("NULL pointer callback");
1088 return RECORDER_ERROR_INVALID_PARAMETER;
1091 handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
1092 handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
1094 return RECORDER_ERROR_NONE;
1098 int legacy_recorder_unset_state_changed_cb(recorder_h recorder)
1100 recorder_s *handle = (recorder_s *)recorder;
1102 if (recorder == NULL) {
1103 LOGE("NULL pointer handle");
1104 return RECORDER_ERROR_INVALID_PARAMETER;
1107 handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1108 handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
1110 return RECORDER_ERROR_NONE;
1114 int legacy_recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
1116 recorder_s *handle = (recorder_s *)recorder;
1118 if (recorder == NULL) {
1119 LOGE("NULL pointer handle");
1120 return RECORDER_ERROR_INVALID_PARAMETER;
1122 if (callback == NULL) {
1123 LOGE("NULL pointer callback");
1124 return RECORDER_ERROR_INVALID_PARAMETER;
1127 handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
1128 handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
1130 return RECORDER_ERROR_NONE;
1134 int legacy_recorder_unset_interrupted_cb(recorder_h recorder)
1136 recorder_s *handle = (recorder_s *)recorder;
1138 if (recorder == NULL) {
1139 LOGE("NULL pointer handle");
1140 return RECORDER_ERROR_INVALID_PARAMETER;
1143 handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1144 handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
1146 return RECORDER_ERROR_NONE;
1150 int legacy_recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
1152 int ret = MM_ERROR_NONE;
1153 recorder_s *handle = (recorder_s *)recorder;
1155 if (recorder == NULL) {
1156 LOGE("NULL pointer handle");
1157 return RECORDER_ERROR_INVALID_PARAMETER;
1159 if (callback == NULL) {
1160 LOGE("NULL pointer callback");
1161 return RECORDER_ERROR_INVALID_PARAMETER;
1164 ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, __mm_audio_stream_cb, handle);
1165 if (ret == MM_ERROR_NONE){
1166 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
1167 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
1170 return __convert_recorder_error_code(__func__, ret);
1174 int legacy_recorder_unset_audio_stream_cb(recorder_h recorder)
1176 int ret = MM_ERROR_NONE;
1177 recorder_s *handle = (recorder_s *)recorder;
1179 if (recorder == NULL) {
1180 LOGE("NULL pointer handle");
1181 return RECORDER_ERROR_INVALID_PARAMETER;
1184 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1185 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
1187 ret = mm_camcorder_set_audio_stream_callback(handle->mm_handle, NULL, NULL);
1189 return __convert_recorder_error_code(__func__, ret);
1193 int legacy_recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
1195 recorder_s *handle = (recorder_s *)recorder;
1197 if (recorder == NULL) {
1198 LOGE("NULL pointer handle");
1199 return RECORDER_ERROR_INVALID_PARAMETER;
1201 if (callback == NULL) {
1202 LOGE("NULL pointer callback");
1203 return RECORDER_ERROR_INVALID_PARAMETER;
1206 handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = callback;
1207 handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = user_data;
1209 return RECORDER_ERROR_NONE;
1213 int legacy_recorder_unset_error_cb(recorder_h recorder)
1215 recorder_s *handle = (recorder_s *)recorder;
1217 if (recorder == NULL) {
1218 LOGE("NULL pointer handle");
1219 return RECORDER_ERROR_INVALID_PARAMETER;
1222 handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1223 handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = NULL;
1225 return RECORDER_ERROR_NONE;
1229 int legacy_recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
1231 recorder_s *handle = (recorder_s *)recorder;
1233 if (recorder == NULL) {
1234 LOGE("NULL pointer handle");
1235 return RECORDER_ERROR_INVALID_PARAMETER;
1237 if (callback == NULL) {
1238 LOGE("NULL pointer callback");
1239 return RECORDER_ERROR_INVALID_PARAMETER;
1242 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
1243 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
1245 return RECORDER_ERROR_NONE;
1249 int legacy_recorder_unset_recording_status_cb(recorder_h recorder)
1251 recorder_s *handle = (recorder_s *)recorder;
1253 if (recorder == NULL) {
1254 LOGE("NULL pointer handle");
1255 return RECORDER_ERROR_INVALID_PARAMETER;
1258 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1259 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
1261 return RECORDER_ERROR_NONE;
1265 int legacy_recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
1267 recorder_s *handle = (recorder_s *)recorder;
1269 if (recorder == NULL) {
1270 LOGE("NULL pointer handle");
1271 return RECORDER_ERROR_INVALID_PARAMETER;
1273 if (callback == NULL) {
1274 LOGE("NULL pointer callback");
1275 return RECORDER_ERROR_INVALID_PARAMETER;
1278 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
1279 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
1281 return RECORDER_ERROR_NONE;
1285 int legacy_recorder_unset_recording_limit_reached_cb(recorder_h recorder)
1287 recorder_s *handle = (recorder_s *)recorder;
1289 if (recorder == NULL) {
1290 LOGE("NULL pointer handle");
1291 return RECORDER_ERROR_INVALID_PARAMETER;
1294 handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1295 handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
1297 return RECORDER_ERROR_NONE;
1301 int legacy_recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
1304 int ret = MM_ERROR_NONE;
1305 recorder_s *handle = (recorder_s *)recorder;
1306 MMCamAttrsInfo info;
1309 if (recorder == NULL) {
1310 LOGE("NULL pointer handle");
1311 return RECORDER_ERROR_INVALID_PARAMETER;
1313 if (foreach_cb == NULL) {
1314 LOGE("NULL pointer foreach_cb");
1315 return RECORDER_ERROR_INVALID_PARAMETER;
1318 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILE_FORMAT, &info);
1319 if (ret != MM_ERROR_NONE) {
1320 LOGE("mm_camcorder_get_attribute_info failed 0x%x", ret);
1321 return __convert_recorder_error_code(__func__, ret);;
1324 for (i = 0 ; i < info.int_array.count ; i++) {
1325 switch (info.int_array.array[i]) {
1326 case MM_FILE_FORMAT_3GP:
1327 format = RECORDER_FILE_FORMAT_3GP;
1329 case MM_FILE_FORMAT_MP4 :
1330 format = RECORDER_FILE_FORMAT_MP4;
1332 case MM_FILE_FORMAT_AMR :
1333 format = RECORDER_FILE_FORMAT_AMR;
1335 case MM_FILE_FORMAT_AAC:
1336 format = RECORDER_FILE_FORMAT_ADTS;
1338 case MM_FILE_FORMAT_WAV:
1339 format = RECORDER_FILE_FORMAT_WAV;
1346 if (format != -1 && !foreach_cb(format,user_data)) {
1351 return RECORDER_ERROR_NONE;
1355 int legacy_recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
1357 int ret = MM_ERROR_NONE;
1358 recorder_s *handle = (recorder_s *)recorder;
1360 if (recorder == NULL) {
1361 LOGE("NULL pointer handle");
1362 return RECORDER_ERROR_INVALID_PARAMETER;
1365 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1366 MMCAM_TARGET_MAX_SIZE, kbyte,
1369 return __convert_recorder_error_code(__func__, ret);
1373 int legacy_recorder_attr_set_time_limit(recorder_h recorder, int second)
1375 int ret = MM_ERROR_NONE;
1376 recorder_s *handle = (recorder_s *)recorder;
1378 if (recorder == NULL) {
1379 LOGE("NULL pointer handle");
1380 return RECORDER_ERROR_INVALID_PARAMETER;
1383 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1384 MMCAM_TARGET_TIME_LIMIT, second,
1387 return __convert_recorder_error_code(__func__, ret);
1391 int legacy_recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
1393 if (device < RECORDER_AUDIO_DEVICE_MIC || device > RECORDER_AUDIO_DEVICE_MODEM) {
1394 LOGE("invalid device %d", device);
1395 return RECORDER_ERROR_INVALID_PARAMETER;
1398 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_DEVICE, device);
1402 int legacy_recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
1404 recorder_s *handle = (recorder_s *)recorder;
1405 int audio_table[4] = { MM_AUDIO_CODEC_AMR, /* RECORDER_AUDIO_CODEC_AMR */
1406 MM_AUDIO_CODEC_AAC, /* RECORDER_AUDIO_CODEC_AAC */
1407 MM_AUDIO_CODEC_VORBIS, /* RECORDER_AUDIO_CODEC_VORBIS */
1408 MM_AUDIO_CODEC_WAVE /* RECORDER_AUDIO_CODEC_PCM */
1411 if (recorder == NULL) {
1412 LOGE("handle is NULL");
1413 return RECORDER_ERROR_INVALID_PARAMETER;
1416 if (codec != RECORDER_AUDIO_CODEC_DISABLE &&
1417 (codec < RECORDER_AUDIO_CODEC_AMR || codec > RECORDER_AUDIO_CODEC_PCM)) {
1418 LOGE("invalid parameter : codec %d", codec);
1419 return RECORDER_ERROR_INVALID_PARAMETER;
1422 if (handle->type == _RECORDER_TYPE_AUDIO && codec == RECORDER_AUDIO_CODEC_DISABLE) {
1423 LOGE("AUDIO_CODEC_DISABLE is not supported in audio mode");
1424 return RECORDER_ERROR_NOT_SUPPORTED;
1427 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER, codec == RECORDER_AUDIO_CODEC_DISABLE ? RECORDER_AUDIO_CODEC_DISABLE : audio_table[codec]);
1431 int legacy_recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
1433 int ret = MM_ERROR_NONE;
1435 int audio_disable = 0;
1436 recorder_s *handle = (recorder_s *)recorder;
1438 if (recorder == NULL) {
1439 LOGE("handle is NULL");
1440 return RECORDER_ERROR_INVALID_PARAMETER;
1443 if (codec == NULL) {
1444 LOGE("codec is NULL");
1445 return RECORDER_ERROR_INVALID_PARAMETER;
1448 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1449 MMCAM_AUDIO_ENCODER, &mm_codec,
1450 MMCAM_AUDIO_DISABLE, &audio_disable,
1453 if (ret == MM_ERROR_NONE && audio_disable == 0) {
1455 case MM_AUDIO_CODEC_AMR :
1456 *codec = RECORDER_AUDIO_CODEC_AMR;
1458 case MM_AUDIO_CODEC_AAC :
1459 *codec = RECORDER_AUDIO_CODEC_AAC;
1461 case MM_AUDIO_CODEC_VORBIS:
1462 *codec = RECORDER_AUDIO_CODEC_VORBIS;
1464 case MM_AUDIO_CODEC_WAVE:
1465 *codec = RECORDER_AUDIO_CODEC_PCM;
1468 ret = MM_ERROR_CAMCORDER_INTERNAL;
1471 } else if (ret == MM_ERROR_NONE && audio_disable) {
1472 *codec = RECORDER_AUDIO_CODEC_DISABLE;
1475 return __convert_recorder_error_code(__func__, ret);
1479 int legacy_recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
1481 int ret = MM_ERROR_NONE;
1482 int video_table[4] = { MM_VIDEO_CODEC_H263, /* RECORDER_VIDEO_CODEC_H263 */
1483 MM_VIDEO_CODEC_H264, /* RECORDER_VIDEO_CODEC_H264 */
1484 MM_VIDEO_CODEC_MPEG4, /* RECORDER_VIDEO_CODEC_MPEG4 */
1485 MM_VIDEO_CODEC_THEORA /* RECORDER_VIDEO_CODEC_THEORA */
1487 recorder_s *handle = (recorder_s *)recorder;
1489 if (handle == NULL) {
1490 LOGE("handle is NULL");
1491 return RECORDER_ERROR_INVALID_PARAMETER;
1494 if (handle->camera_device_count == 0) {
1495 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1496 return RECORDER_ERROR_NOT_SUPPORTED;
1499 if (codec < RECORDER_VIDEO_CODEC_H263 || codec > RECORDER_VIDEO_CODEC_THEORA) {
1500 LOGE("invalid codec %d", codec);
1501 return RECORDER_ERROR_INVALID_PARAMETER;
1504 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1505 MMCAM_VIDEO_ENCODER, video_table[codec],
1508 return __convert_recorder_error_code(__func__, ret);
1512 int legacy_recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
1514 int ret = MM_ERROR_NONE;
1516 recorder_s *handle = (recorder_s *)recorder;
1518 if (handle == NULL) {
1519 LOGE("handle is NULL");
1520 return RECORDER_ERROR_INVALID_PARAMETER;
1522 if (handle->camera_device_count == 0) {
1523 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1524 return RECORDER_ERROR_NOT_SUPPORTED;
1526 if (codec == NULL) {
1527 LOGE("codec is NULL");
1528 return RECORDER_ERROR_INVALID_PARAMETER;
1531 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1532 MMCAM_VIDEO_ENCODER, &mm_codec,
1534 if (ret == MM_ERROR_NONE) {
1536 case MM_VIDEO_CODEC_H263 :
1537 *codec = RECORDER_VIDEO_CODEC_H263;
1539 case MM_VIDEO_CODEC_H264 :
1540 *codec = RECORDER_VIDEO_CODEC_H264;
1542 case MM_VIDEO_CODEC_MPEG4 :
1543 *codec = RECORDER_VIDEO_CODEC_MPEG4;
1545 case MM_VIDEO_CODEC_THEORA:
1546 *codec = RECORDER_VIDEO_CODEC_THEORA;
1549 ret = MM_ERROR_CAMCORDER_INTERNAL;
1554 return __convert_recorder_error_code(__func__, ret);
1558 int legacy_recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
1560 if (samplerate < 1) {
1561 LOGE("invalid samplerate %d", samplerate);
1562 return RECORDER_ERROR_INVALID_PARAMETER;
1565 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_SAMPLERATE, samplerate);
1569 int legacy_recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
1572 LOGE("invalid bitrate %d", bitrate);
1573 return RECORDER_ERROR_INVALID_PARAMETER;
1576 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_ENCODER_BITRATE, bitrate);
1580 int legacy_recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
1582 int ret = MM_ERROR_NONE;
1583 recorder_s *handle = (recorder_s *)recorder;
1585 if (handle == NULL) {
1586 LOGE("handle is NULL");
1587 return RECORDER_ERROR_INVALID_PARAMETER;
1589 if (handle->camera_device_count == 0) {
1590 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1591 return RECORDER_ERROR_NOT_SUPPORTED;
1594 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1595 MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1598 return __convert_recorder_error_code(__func__, ret);
1602 int legacy_recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
1604 int ret = MM_ERROR_NONE;
1605 recorder_s *handle = (recorder_s *)recorder;
1607 if (recorder == NULL) {
1608 LOGE("handle is NULL");
1609 return RECORDER_ERROR_INVALID_PARAMETER;
1612 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1613 MMCAM_TARGET_MAX_SIZE, kbyte,
1616 return __convert_recorder_error_code(__func__, ret);
1620 int legacy_recorder_attr_get_time_limit(recorder_h recorder, int *second)
1622 int ret = MM_ERROR_NONE;
1623 recorder_s *handle = (recorder_s *)recorder;
1625 if (recorder == NULL) {
1626 LOGE("handle is NULL");
1627 return RECORDER_ERROR_INVALID_PARAMETER;
1630 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1631 MMCAM_TARGET_TIME_LIMIT, second,
1634 return __convert_recorder_error_code(__func__, ret);
1638 int legacy_recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
1640 int ret = MM_ERROR_NONE;
1641 recorder_s *handle = (recorder_s *)recorder;
1643 if (recorder == NULL) {
1644 LOGE("handle is NULL");
1645 return RECORDER_ERROR_INVALID_PARAMETER;
1648 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1649 MMCAM_AUDIO_DEVICE, device,
1652 return __convert_recorder_error_code(__func__, ret);
1656 int legacy_recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
1658 int ret = MM_ERROR_NONE;
1659 recorder_s *handle = (recorder_s *)recorder;
1661 if (recorder == NULL) {
1662 LOGE("handle is NULL");
1663 return RECORDER_ERROR_INVALID_PARAMETER;
1666 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1667 MMCAM_AUDIO_SAMPLERATE, samplerate,
1670 return __convert_recorder_error_code(__func__, ret);
1674 int legacy_recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
1676 int ret = MM_ERROR_NONE;
1677 recorder_s *handle = (recorder_s *)recorder;
1679 if (recorder == NULL) {
1680 LOGE("handle is NULL");
1681 return RECORDER_ERROR_INVALID_PARAMETER;
1684 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1685 MMCAM_AUDIO_ENCODER_BITRATE, bitrate,
1688 return __convert_recorder_error_code(__func__, ret);
1692 int legacy_recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
1694 int ret = MM_ERROR_NONE;
1695 recorder_s *handle = (recorder_s *)recorder;
1697 if (handle == NULL) {
1698 LOGE("handle is NULL");
1699 return RECORDER_ERROR_INVALID_PARAMETER;
1701 if (handle->camera_device_count == 0) {
1702 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1703 return RECORDER_ERROR_NOT_SUPPORTED;
1705 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1706 MMCAM_VIDEO_ENCODER_BITRATE, bitrate,
1709 return __convert_recorder_error_code(__func__, ret);
1713 int legacy_recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
1716 int ret = MM_ERROR_NONE;
1718 recorder_s *handle = (recorder_s *)recorder;
1719 MMCamAttrsInfo info;
1721 if (recorder == NULL) {
1722 LOGE("handle is NULL");
1723 return RECORDER_ERROR_INVALID_PARAMETER;
1725 if (foreach_cb == NULL) {
1726 LOGE("foreach_cb is NULL");
1727 return RECORDER_ERROR_INVALID_PARAMETER;
1730 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_AUDIO_ENCODER, &info);
1731 if (ret != MM_ERROR_NONE) {
1732 return __convert_recorder_error_code(__func__, ret);
1735 for (i = 0 ; i < info.int_array.count ; i++) {
1736 switch (info.int_array.array[i]) {
1737 case MM_AUDIO_CODEC_AMR:
1738 codec = RECORDER_AUDIO_CODEC_AMR;
1740 case MM_AUDIO_CODEC_AAC :
1741 codec = RECORDER_AUDIO_CODEC_AAC;
1743 case MM_AUDIO_CODEC_VORBIS:
1744 codec = RECORDER_AUDIO_CODEC_VORBIS;
1746 case MM_AUDIO_CODEC_WAVE:
1747 codec = RECORDER_AUDIO_CODEC_PCM;
1753 if (codec != -1 && !foreach_cb(codec,user_data)) {
1758 return RECORDER_ERROR_NONE;
1762 int legacy_recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
1765 int ret = MM_ERROR_NONE;
1767 recorder_s *handle = (recorder_s *)recorder;
1768 MMCamAttrsInfo info;
1770 if (handle == NULL) {
1771 LOGE("handle is NULL");
1772 return RECORDER_ERROR_INVALID_PARAMETER;
1774 if (handle->camera_device_count == 0) {
1775 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1776 return RECORDER_ERROR_NOT_SUPPORTED;
1778 if (foreach_cb == NULL) {
1779 LOGE("foreach_cb is NULL");
1780 return RECORDER_ERROR_INVALID_PARAMETER;
1783 ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_ENCODER, &info);
1784 if (ret != MM_ERROR_NONE) {
1785 return __convert_recorder_error_code(__func__, ret);
1788 for (i = 0 ; i < info.int_array.count ; i++) {
1789 switch (info.int_array.array[i]){
1790 case MM_VIDEO_CODEC_H263 :
1791 codec = RECORDER_VIDEO_CODEC_H263;
1793 case MM_VIDEO_CODEC_H264 :
1794 codec = RECORDER_VIDEO_CODEC_H264;
1796 case MM_VIDEO_CODEC_MPEG4 :
1797 codec = RECORDER_VIDEO_CODEC_MPEG4;
1799 case MM_VIDEO_CODEC_THEORA :
1800 codec = RECORDER_VIDEO_CODEC_THEORA;
1807 if (codec != -1 && !foreach_cb(codec,user_data)) {
1812 return RECORDER_ERROR_NONE;
1816 int legacy_recorder_attr_set_mute(recorder_h recorder, bool enable)
1818 int ret = MM_ERROR_NONE;
1819 recorder_s *handle = (recorder_s *)recorder;
1821 if (recorder == NULL) {
1822 LOGE("handle is NULL");
1823 return RECORDER_ERROR_INVALID_PARAMETER;
1826 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1827 MMCAM_AUDIO_VOLUME, enable ? 0.0 : 1.0,
1830 return __convert_recorder_error_code(__func__, ret);
1834 bool legacy_recorder_attr_is_muted(recorder_h recorder)
1836 int ret = MM_ERROR_NONE;
1837 double volume = 1.0;
1838 recorder_s *handle = (recorder_s *)recorder;
1840 if (recorder == NULL) {
1841 LOGE("handle is NULL");
1845 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1846 MMCAM_AUDIO_VOLUME, &volume,
1849 set_last_result(__convert_recorder_error_code(__func__, ret));
1851 if (volume == 0.0) {
1859 int legacy_recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
1861 int ret = MM_ERROR_NONE;
1862 recorder_s *handle = (recorder_s *)recorder;
1864 if (handle == NULL) {
1865 LOGE("handle is NULL");
1866 return RECORDER_ERROR_INVALID_PARAMETER;
1868 if (handle->camera_device_count == 0) {
1869 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1870 return RECORDER_ERROR_NOT_SUPPORTED;
1872 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1873 MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1876 return __convert_recorder_error_code(__func__, ret);
1880 int legacy_recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
1882 int ret = MM_ERROR_NONE;
1883 recorder_s *handle = (recorder_s *)recorder;
1885 if (handle == NULL) {
1886 LOGE("handle is NULL");
1887 return RECORDER_ERROR_INVALID_PARAMETER;
1889 if (handle->camera_device_count == 0) {
1890 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1891 return RECORDER_ERROR_NOT_SUPPORTED;
1894 LOGE("rate is NULL");
1895 return RECORDER_ERROR_INVALID_PARAMETER;
1898 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1899 MMCAM_CAMERA_RECORDING_MOTION_RATE, rate,
1902 return __convert_recorder_error_code(__func__, ret);
1906 int legacy_recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
1908 if (channel_count < 1) {
1909 LOGE("invalid channel %d", channel_count);
1910 return RECORDER_ERROR_INVALID_PARAMETER;
1913 return _recorder_check_and_set_attribute(recorder, MMCAM_AUDIO_CHANNEL, channel_count);
1917 int legacy_recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
1919 int ret = MM_ERROR_NONE;
1920 recorder_s *handle = (recorder_s *)recorder;
1922 if (recorder == NULL) {
1923 LOGE("handle is NULL");
1924 return RECORDER_ERROR_INVALID_PARAMETER;
1926 if (channel_count == NULL) {
1927 LOGE("channel_count is NULL");
1928 return RECORDER_ERROR_INVALID_PARAMETER;
1931 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1932 MMCAM_AUDIO_CHANNEL, channel_count,
1935 return __convert_recorder_error_code(__func__, ret);
1939 int legacy_recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
1941 int ret = MM_ERROR_NONE;
1942 recorder_s *handle = (recorder_s *)recorder;
1944 if (handle == NULL) {
1945 LOGE("handle is NULL");
1946 return RECORDER_ERROR_INVALID_PARAMETER;
1948 if (handle->camera_device_count == 0) {
1949 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1950 return RECORDER_ERROR_NOT_SUPPORTED;
1952 if (orientation > RECORDER_ROTATION_270) {
1953 LOGE("invalid orientation %d", orientation);
1954 return RECORDER_ERROR_INVALID_PARAMETER;
1957 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
1958 MMCAM_RECORDER_TAG_ENABLE, true,
1959 MMCAM_TAG_VIDEO_ORIENTATION, orientation,
1962 return __convert_recorder_error_code(__func__, ret);
1966 int legacy_recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
1968 int ret = MM_ERROR_NONE;
1969 recorder_s *handle = (recorder_s *)recorder;
1971 if (handle == NULL) {
1972 LOGE("handle is NULL");
1973 return RECORDER_ERROR_INVALID_PARAMETER;
1975 if (handle->camera_device_count == 0) {
1976 LOGE("RECORDER_ERROR_NOT_SUPPORTED");
1977 return RECORDER_ERROR_NOT_SUPPORTED;
1979 if (orientation == NULL) {
1980 LOGE("orientation is NULL");
1981 return RECORDER_ERROR_INVALID_PARAMETER;
1984 ret = mm_camcorder_get_attributes(handle->mm_handle, NULL,
1985 MMCAM_TAG_VIDEO_ORIENTATION, orientation,
1988 return __convert_recorder_error_code(__func__, ret);
1992 int legacy_recorder_attr_set_root_directory(recorder_h recorder, const char *root_directory)
1994 int ret = MM_ERROR_NONE;
1995 recorder_s *handle = (recorder_s *)recorder;
1996 MMCamcorderStateType mmstate = MM_CAMCORDER_STATE_NONE;
1998 if (recorder == NULL) {
1999 LOGE("handle is NULL");
2000 return RECORDER_ERROR_INVALID_PARAMETER;
2003 if (root_directory == NULL) {
2004 LOGE("filename is NULL");
2005 return RECORDER_ERROR_INVALID_PARAMETER;
2008 mm_camcorder_get_state(handle->mm_handle, &mmstate);
2009 if (mmstate >= MM_CAMCORDER_STATE_RECORDING) {
2010 LOGE("invalid state %d", mmstate);
2011 return RECORDER_ERROR_INVALID_STATE;
2014 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
2015 MMCAM_ROOT_DIRECTORY, root_directory, strlen(root_directory),
2018 return __convert_recorder_error_code(__func__, ret);