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.
20 #include <camera_internal.h>
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
25 #include <storage-internal.h>
26 #include <muse_recorder.h>
27 #include <muse_recorder_msg.h>
28 #include <muse_core_ipc.h>
29 #include <muse_core_module.h>
30 #include <recorder_private.h>
34 #include <tzplatform_config.h>
39 #define LOG_TAG "TIZEN_N_RECORDER"
41 /* for device changed callback */
42 static GMutex g_rec_dev_state_changed_cb_lock;
43 static GList *g_rec_dev_state_changed_cb_list;
44 static int g_rec_dev_state_changed_cb_id;
45 static GDBusConnection *g_rec_dev_state_changed_cb_conn;
46 static guint g_rec_dev_state_changed_cb_subscribe_id;
50 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
53 api < 0 || api >= MUSE_RECORDER_API_MAX) {
54 LOGE("invalid param %p %d", cb_info, api);
58 g_mutex_lock(&(cb_info->api_mutex[api]));
59 cb_info->api_waiting[api] += value;
60 g_mutex_unlock(&(cb_info->api_mutex[api]));
62 /*LOGD("api %d, value %d, waiting %d",
63 api, value, cb_info->api_waiting[api]);*/
69 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
70 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
71 const gchar *signal_name, GVariant *param, gpointer user_data)
74 recorder_type_e type = RECORDER_TYPE_AUDIO;
75 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
76 GList *tmp_list = NULL;
77 recorder_cb_info *info = NULL;
79 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
81 if (!g_rec_dev_state_changed_cb_list || !param) {
82 LOGW("no callback or NULL param %p", param);
86 /* get device type and state */
87 g_variant_get(param, "(i)", &value);
90 state = 0x0000ffff & value;
92 LOGD("type %d, state %d", type, state);
94 tmp_list = g_rec_dev_state_changed_cb_list;
97 info = (recorder_cb_info *)tmp_list->data;
100 if (info->callback) {
101 LOGD("start id[%d] callback", info->id);
102 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
103 LOGD("returned id[%d] callback", info->id);
105 LOGW("NULL callback for id %d", info->id);
109 tmp_list = tmp_list->next;
113 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
119 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
121 tbm_bo tmp_bo = NULL;
122 tbm_bo_handle tmp_bo_handle = {NULL, };
124 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
125 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
126 bufmgr, bo, bo_handle, tbm_key);
130 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
131 if (tmp_bo == NULL) {
132 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
136 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
137 if (tmp_bo_handle.ptr == NULL) {
138 LOGE("bo map failed %p", tmp_bo);
139 tbm_bo_unref(tmp_bo);
144 /* set bo and bo_handle */
146 *bo_handle = tmp_bo_handle;
151 static void _recorder_release_imported_bo(tbm_bo *bo)
153 if (bo == NULL || *bo == NULL) {
165 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
167 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
168 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
172 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
174 if (cb_info->user_cb[event] == NULL) {
175 LOGW("user callback for event %d is not set", event);
180 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
186 muse_recorder_msg_get(previous, recv_msg);
187 muse_recorder_msg_get(current, recv_msg);
188 muse_recorder_msg_get(by_policy, recv_msg);
190 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
191 (recorder_state_e)current,
193 cb_info->user_data[event]);
196 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
200 muse_recorder_msg_get(type, recv_msg);
202 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
203 cb_info->user_data[event]);
206 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
208 int64_t cb_elapsed_time = 0;
209 int64_t cb_file_size = 0;
211 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
212 muse_recorder_msg_get(cb_file_size, recv_msg);
214 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
215 (unsigned long long)cb_file_size,
216 cb_info->user_data[event]);
219 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
225 muse_recorder_msg_get(policy, recv_msg);
226 muse_recorder_msg_get(previous, recv_msg);
227 muse_recorder_msg_get(current, recv_msg);
229 if (policy == RECORDER_POLICY_SOUND)
230 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
231 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
232 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
233 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
234 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
236 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
237 (recorder_state_e)previous,
238 (recorder_state_e)current,
239 cb_info->user_data[event]);
242 case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
247 muse_recorder_msg_get(policy, recv_msg);
248 muse_recorder_msg_get(state, recv_msg);
250 LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
252 if (policy == RECORDER_POLICY_SOUND)
253 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
254 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
255 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
256 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
257 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
259 ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
260 (recorder_state_e)state, cb_info->user_data[event]);
263 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
271 tbm_bo_handle bo_handle = {.ptr = NULL};
272 char *send_msg = NULL;
274 muse_recorder_msg_get(tbm_key, recv_msg);
280 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
281 LOGE("tbm key %d import failed", tbm_key);
285 muse_recorder_msg_get(size, recv_msg);
286 muse_recorder_msg_get(format, recv_msg);
287 muse_recorder_msg_get(channel, recv_msg);
288 muse_recorder_msg_get(timestamp, recv_msg);
290 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
292 (audio_sample_type_e)format,
294 (unsigned int)timestamp,
295 cb_info->user_data[event]);
297 /* release imported bo */
298 _recorder_release_imported_bo(&bo);
301 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
302 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
304 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
305 LOGE("sending message failed");
307 muse_core_msg_json_factory_free(send_msg);
310 case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
317 tbm_bo_handle bo_handle = {.ptr = NULL};
318 char *send_msg = NULL;
320 muse_recorder_msg_get(tbm_key, recv_msg);
326 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
327 LOGE("tbm key %d import failed", tbm_key);
331 muse_recorder_msg_get(size, recv_msg);
332 muse_recorder_msg_get(offset, recv_msg);
334 ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
335 size, (unsigned long long)offset, cb_info->user_data[event]);
337 /* release imported bo */
338 _recorder_release_imported_bo(&bo);
341 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
342 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
344 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
345 LOGE("sending message failed");
347 muse_core_msg_json_factory_free(send_msg);
350 LOGE("failed to create send msg for key %d", tbm_key);
355 case MUSE_RECORDER_EVENT_TYPE_ERROR:
358 int current_state = 0;
360 muse_recorder_msg_get(error, recv_msg);
361 muse_recorder_msg_get(current_state, recv_msg);
363 if (error == RECORDER_ERROR_SOUND_POLICY)
364 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
365 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
366 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
367 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
368 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
370 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
371 (recorder_state_e)current_state,
372 cb_info->user_data[event]);
376 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
380 muse_recorder_msg_get(codec, recv_msg);
382 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
383 cb_info->user_cb[event] = NULL;
384 cb_info->user_data[event] = NULL;
385 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
389 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
393 muse_recorder_msg_get(format, recv_msg);
395 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
396 cb_info->user_cb[event] = NULL;
397 cb_info->user_data[event] = NULL;
398 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
402 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
406 muse_recorder_msg_get(codec, recv_msg);
408 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
409 cb_info->user_cb[event] = NULL;
410 cb_info->user_data[event] = NULL;
411 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
415 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
420 muse_recorder_msg_get(width, recv_msg);
421 muse_recorder_msg_get(height, recv_msg);
423 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
424 cb_info->user_cb[event] = NULL;
425 cb_info->user_data[event] = NULL;
426 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
436 static bool _recorder_idle_event_callback(void *data)
438 recorder_cb_info_s *cb_info = NULL;
439 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
441 if (rec_idle_event == NULL) {
442 LOGE("rec_idle_event is NULL");
447 g_mutex_lock(&rec_idle_event->event_mutex);
449 cb_info = rec_idle_event->cb_info;
450 if (cb_info == NULL) {
451 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
452 goto IDLE_EVENT_CALLBACK_DONE;
455 /* remove event from list */
456 g_mutex_lock(&cb_info->idle_event_mutex);
458 if (cb_info->idle_event_list)
459 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
461 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
462 g_mutex_unlock(&cb_info->idle_event_mutex);
465 _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
467 /* send signal for waiting thread */
468 g_cond_signal(&cb_info->idle_event_cond);
470 IDLE_EVENT_CALLBACK_DONE:
471 /* unlock and release event */
472 g_mutex_unlock(&rec_idle_event->event_mutex);
473 g_mutex_clear(&rec_idle_event->event_mutex);
475 g_free(rec_idle_event);
476 rec_idle_event = NULL;
482 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
484 recorder_idle_event_s *rec_idle_event = NULL;
488 if (cb_info == NULL) {
489 LOGE("cb_info is NULL");
493 g_mutex_lock(&cb_info->idle_event_mutex);
495 if (cb_info->idle_event_list == NULL) {
498 list = cb_info->idle_event_list;
501 rec_idle_event = list->data;
502 list = g_list_next(list);
504 if (!rec_idle_event) {
505 LOGW("The event is NULL");
509 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
510 LOGW("lock failed, %p event is calling now", rec_idle_event);
512 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
514 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
515 LOGW("signal received");
522 LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
523 rec_idle_event, rec_idle_event->event);
525 rec_idle_event->cb_info = NULL;
527 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
529 g_mutex_unlock(&rec_idle_event->event_mutex);
532 g_list_free(cb_info->idle_event_list);
533 cb_info->idle_event_list = NULL;
536 g_mutex_unlock(&cb_info->idle_event_mutex);
542 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
544 recorder_message_s *rec_msg = NULL;
545 recorder_msg_handler_info_s *msg_handler_info = NULL;
547 if (!cb_info || !msg) {
548 LOGE("NULL pointer %p %p", cb_info, msg);
552 rec_msg = g_new0(recorder_message_s, 1);
554 LOGE("failed to alloc rec_msg for [%s]", msg);
559 rec_msg->event = event;
560 rec_msg->event_class = event_class;
562 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
564 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
566 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
567 msg_handler_info = &cb_info->audio_stream_cb_info;
568 else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
569 msg_handler_info = &cb_info->muxed_stream_cb_info;
571 msg_handler_info = &cb_info->msg_handler_info;
573 g_mutex_lock(&msg_handler_info->mutex);
574 g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
575 g_cond_signal(&msg_handler_info->cond);
576 g_mutex_unlock(&msg_handler_info->mutex);
584 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
586 if (!cb_info || !msg) {
587 LOGE("NULL pointer %p %p", cb_info, msg);
592 case MUSE_RECORDER_API_GET_STATE:
595 muse_recorder_msg_get(get_state, msg);
596 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
599 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
603 muse_recorder_msg_get(get_width, msg);
604 muse_recorder_msg_get(get_height, msg);
605 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
606 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
609 case MUSE_RECORDER_API_GET_FILE_FORMAT:
612 muse_recorder_msg_get(get_format, msg);
613 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
616 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
619 muse_recorder_msg_get(get_codec, msg);
620 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
623 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
626 muse_recorder_msg_get(get_codec, msg);
627 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
630 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
633 muse_recorder_msg_get(get_kbyte, msg);
634 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
637 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
640 muse_recorder_msg_get(get_second, msg);
641 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
644 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
647 muse_recorder_msg_get(get_device, msg);
648 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
651 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
653 int get_samplerate = 0;
654 muse_recorder_msg_get(get_samplerate, msg);
655 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
658 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
661 muse_recorder_msg_get(get_bitrate, msg);
662 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
665 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
668 muse_recorder_msg_get(get_bitrate, msg);
669 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
672 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
675 muse_recorder_msg_get_double(get_rate, msg);
676 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
679 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
681 int get_channel_count = 0;
682 muse_recorder_msg_get(get_channel_count, msg);
683 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
686 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
688 int get_orientation = 0;
689 muse_recorder_msg_get(get_orientation, msg);
690 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
693 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
695 double get_level = 0.0;
696 muse_recorder_msg_get_double(get_level, msg);
697 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
700 case MUSE_RECORDER_API_GET_FILENAME:
702 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
703 muse_recorder_msg_get_string(get_filename, msg);
704 if (cb_info->get_filename) {
705 free(cb_info->get_filename);
706 cb_info->get_filename = NULL;
708 cb_info->get_filename = strdup(get_filename);
719 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
721 int ret = RECORDER_ERROR_NONE;
725 int event_class = -1;
727 if (!cb_info || !msg) {
728 LOGE("invalid ptr %p %p", cb_info, msg);
732 /*LOGD("msg [%s]", msg);*/
734 if (!muse_recorder_msg_get(api, msg)) {
735 LOGE("failed to get recorder api");
739 if (api == MUSE_RECORDER_CB_EVENT) {
740 if (!muse_recorder_msg_get(event, msg) ||
741 !muse_recorder_msg_get(event_class, msg)) {
742 LOGE("failed to get event or event_class [%s]", msg);
746 if (!muse_recorder_msg_get(api_class, msg)) {
747 LOGE("failed to get api_class [%s]", msg);
752 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
753 if (api >= MUSE_RECORDER_API_MAX) {
754 LOGE("invalid api %d", api);
758 if (!muse_recorder_msg_get(ret, msg)) {
759 LOGE("failed to get recorder ret");
763 g_mutex_lock(&cb_info->api_mutex[api]);
765 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
766 g_atomic_int_set(&cb_info->msg_recv_running, 0);
767 LOGD("get device state done. close client cb handler");
770 case MUSE_RECORDER_API_CREATE:
771 if (ret != RECORDER_ERROR_NONE) {
772 g_atomic_int_set(&cb_info->msg_recv_running, 0);
773 LOGE("create error 0x%x. closing..", ret);
776 case MUSE_RECORDER_API_DESTROY:
777 if (ret == RECORDER_ERROR_NONE) {
778 g_atomic_int_set(&cb_info->msg_recv_running, 0);
779 LOGD("destroy done. closing..");
783 __recorder_get_api_operation(api, cb_info, msg);
788 if (cb_info->api_waiting[api] > 0) {
789 cb_info->api_ret[api] = ret;
790 cb_info->api_activating[api] = 1;
792 g_cond_signal(&cb_info->api_cond[api]);
794 LOGE("no waiting for api [%d]", api);
797 g_mutex_unlock(&cb_info->api_mutex[api]);
798 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
799 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
801 LOGW("unknown recorder api %d and api_class %d", api, api_class);
808 static void *_recorder_msg_handler_func(gpointer data)
812 recorder_message_s *rec_msg = NULL;
813 recorder_idle_event_s *rec_idle_event = NULL;
814 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
815 recorder_cb_info_s *cb_info = NULL;
817 if (!handler_info || !handler_info->cb_info) {
818 LOGE("NULL handler %p", handler_info);
822 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
823 type = handler_info->type;
825 LOGD("t:%d start", type);
827 g_mutex_lock(&handler_info->mutex);
829 while (g_atomic_int_get(&handler_info->running)) {
830 if (g_queue_is_empty(handler_info->queue)) {
831 /*LOGD("signal wait...");*/
832 g_cond_wait(&handler_info->cond, &handler_info->mutex);
833 /*LOGD("signal received");*/
835 if (g_atomic_int_get(&handler_info->running) == 0) {
836 LOGD("stop event thread");
841 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
842 g_mutex_unlock(&handler_info->mutex);
843 if (rec_msg == NULL) {
844 LOGE("NULL message");
845 g_mutex_lock(&handler_info->mutex);
851 if (api < MUSE_RECORDER_API_MAX) {
854 g_mutex_lock(&cb_info->api_mutex[api]);
856 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
857 if (cb_info->api_waiting[api] > 0) {
858 cb_info->api_ret[api] = ret;
859 cb_info->api_activating[api] = 1;
861 /*LOGD("recorder api %d - return 0x%x", ret);*/
863 g_cond_signal(&cb_info->api_cond[api]);
865 LOGE("no waiting for api [%d]", api);
868 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
871 g_mutex_unlock(&cb_info->api_mutex[api]);
872 } else if (api == MUSE_RECORDER_CB_EVENT) {
873 switch (rec_msg->event_class) {
874 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
875 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
877 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
878 rec_idle_event = g_new0(recorder_idle_event_s, 1);
879 if (rec_idle_event == NULL) {
880 LOGE("event alloc failed");
884 rec_idle_event->event = rec_msg->event;
885 rec_idle_event->cb_info = cb_info;
886 g_mutex_init(&rec_idle_event->event_mutex);
887 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
889 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
891 g_mutex_lock(&cb_info->idle_event_mutex);
892 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
893 g_mutex_unlock(&cb_info->idle_event_mutex);
895 g_idle_add_full(G_PRIORITY_DEFAULT,
896 (GSourceFunc)_recorder_idle_event_callback,
897 (gpointer)rec_idle_event,
901 LOGE("unknown event class %d", rec_msg->event_class);
905 LOGE("unknown api[%d] message", api);
911 g_mutex_lock(&handler_info->mutex);
914 /* remove remained event */
915 while (!g_queue_is_empty(handler_info->queue)) {
916 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
918 LOGD("remove message %p", rec_msg);
922 LOGW("NULL message");
926 g_mutex_unlock(&handler_info->mutex);
934 static void *_recorder_msg_recv_func(gpointer data)
937 int single_length = 0;
938 int remained_length = 0;
939 char *recv_msg = NULL;
940 char *single_msg = NULL;
941 char *remained_msg = NULL;
945 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
947 if (cb_info == NULL) {
948 LOGE("cb_info NULL");
954 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
955 if (single_msg == NULL) {
956 LOGE("single_msg malloc failed");
957 goto CB_HANDLER_EXIT;
960 recv_msg = cb_info->recv_msg;
962 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
963 recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
964 if (recv_length <= 0) {
966 cb_info->is_server_connected = FALSE;
967 LOGE("receive msg failed - server disconnected");
972 recv_msg[recv_length] = '\0';
978 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
980 /* Need to split the combined entering msgs */
981 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
982 if (recv_msg[cur_pos] == '}') {
983 single_length = cur_pos - prev_pos + 1;
985 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
986 /* check remained msg */
987 if (remained_length > 0) {
990 strncpy(single_msg, remained_msg, remained_length);
991 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
992 single_msg[remained_length + single_length] = '\0';
997 strncpy(single_msg, recv_msg + prev_pos, single_length);
998 single_msg[single_length] = '\0';
999 LOGE("lost msg [%s], skip...", single_msg);
1002 remained_length = 0;
1005 strncpy(single_msg, recv_msg + prev_pos, single_length);
1006 single_msg[single_length] = '\0';
1009 if (single_msg[0] == '{') {
1011 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
1012 __recorder_process_msg(cb_info, single_msg);
1014 LOGE("invalid msg [%s]", single_msg);
1017 LOGE("too long message [len %d] skip...", single_length);
1020 prev_pos = cur_pos + 1;
1024 /* check incompleted message */
1025 if (recv_msg[recv_length - 1] != '}') {
1027 remained_length = recv_length - prev_pos;
1029 LOGW("incompleted message [len %d]", remained_length);
1031 remained_msg = (char *)malloc(remained_length + 1);
1033 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
1034 remained_msg[remained_length] = '\0';
1036 LOGE("failed to alloc for remained msg");
1040 remained_length = 0;
1044 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1046 if (!cb_info->is_server_connected) {
1048 /* send error msg for server disconnection */
1049 char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
1050 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1051 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1055 LOGE("error_msg failed");
1056 goto CB_HANDLER_EXIT;
1059 LOGE("add error msg for service disconnection done");
1061 __recorder_add_msg_to_queue(cb_info,
1062 MUSE_RECORDER_CB_EVENT,
1063 MUSE_RECORDER_EVENT_TYPE_ERROR,
1064 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1067 muse_core_msg_json_factory_free(error_msg);
1070 LOGE("add error msg for service disconnection done");
1082 remained_msg = NULL;
1089 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1090 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1092 if (!handler_info || !thread_name || !cb_info) {
1093 LOGE("t:%d NULL %p %p %p",
1094 type, handler_info, thread_name, cb_info);
1100 handler_info->type = type;
1101 handler_info->queue = g_queue_new();
1102 if (handler_info->queue == NULL) {
1103 LOGE("t:%d queue failed", type);
1107 g_mutex_init(&handler_info->mutex);
1108 g_cond_init(&handler_info->cond);
1110 handler_info->cb_info = (void *)cb_info;
1111 g_atomic_int_set(&handler_info->running, 1);
1113 handler_info->thread = g_thread_try_new(thread_name,
1114 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1115 if (handler_info->thread == NULL) {
1117 LOGE("t:%d thread failed", type);
1119 g_mutex_clear(&handler_info->mutex);
1120 g_cond_clear(&handler_info->cond);
1121 g_queue_free(handler_info->queue);
1122 handler_info->queue = NULL;
1128 LOGD("t:%d done", type);
1134 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1138 if (!handler_info) {
1139 LOGE("NULL handler");
1143 if (!handler_info->thread) {
1144 LOGW("thread is not created");
1148 type = handler_info->type;
1150 LOGD("t:%d thread %p", type, handler_info->thread);
1152 g_mutex_lock(&handler_info->mutex);
1153 g_atomic_int_set(&handler_info->running, 0);
1154 g_cond_signal(&handler_info->cond);
1155 g_mutex_unlock(&handler_info->mutex);
1157 g_thread_join(handler_info->thread);
1158 handler_info->thread = NULL;
1160 g_mutex_clear(&handler_info->mutex);
1161 g_cond_clear(&handler_info->cond);
1162 g_queue_free(handler_info->queue);
1163 handler_info->queue = NULL;
1165 LOGD("t:%d done", type);
1171 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1173 recorder_cb_info_s *cb_info = NULL;
1176 g_return_val_if_fail(sockfd > 0, NULL);
1178 cb_info = g_new0(recorder_cb_info_s, 1);
1179 if (cb_info == NULL) {
1180 LOGE("cb_info failed");
1184 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1186 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1187 g_mutex_init(&cb_info->api_mutex[i]);
1188 g_cond_init(&cb_info->api_cond[i]);
1191 g_mutex_init(&cb_info->idle_event_mutex);
1192 g_cond_init(&cb_info->idle_event_cond);
1194 /* message handler thread */
1195 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1196 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1197 LOGE("msg_handler_info failed");
1201 /* message handler thread for audio stream callback */
1202 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1203 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1204 LOGE("audio_stream_cb_info failed");
1208 /* message handler thread for muxed stream callback */
1209 if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
1210 _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
1211 LOGE("muxed_stream_cb_info failed");
1215 cb_info->fd = sockfd;
1217 /* message receive thread */
1218 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1219 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1220 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1221 if (cb_info->msg_recv_thread == NULL) {
1222 LOGE("message receive thread creation failed");
1226 cb_info->is_server_connected = TRUE;
1232 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1233 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1234 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1236 g_mutex_clear(&cb_info->idle_event_mutex);
1237 g_cond_clear(&cb_info->idle_event_cond);
1239 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1240 g_mutex_clear(&cb_info->api_mutex[i]);
1241 g_cond_clear(&cb_info->api_cond[i]);
1252 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1254 int ret = RECORDER_ERROR_NONE;
1257 /*LOGD("Enter api : %d", api);*/
1259 if (!cb_info->is_server_connected) {
1260 LOGE("server is disconnected");
1261 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1264 g_mutex_lock(&(cb_info->api_mutex[api]));
1266 if (cb_info->api_activating[api] == 0) {
1267 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1268 LOGW("wait for api %d", api);
1269 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1270 ret = cb_info->api_ret[api];
1271 cb_info->api_activating[api] = 0;
1272 LOGW("api %d returned 0x%x", api, ret);
1274 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1275 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1276 ret = cb_info->api_ret[api];
1277 cb_info->api_activating[api] = 0;
1278 /*LOGD("return value : 0x%x", ret);*/
1280 ret = RECORDER_ERROR_INVALID_OPERATION;
1281 LOGE("api %d was TIMED OUT!", api);
1285 ret = cb_info->api_ret[api];
1286 cb_info->api_activating[api] = 0;
1288 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1291 if (ret != RECORDER_ERROR_NONE) {
1292 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1294 if (ret == RECORDER_ERROR_SOUND_POLICY)
1295 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1296 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1297 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1298 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1299 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1302 g_mutex_unlock(&(cb_info->api_mutex[api]));
1308 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
1313 if (!cb_info || !ret) {
1314 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1315 return RECORDER_ERROR_INVALID_PARAMETER;
1318 msg = muse_core_msg_json_factory_new(api, NULL);
1320 LOGE("msg creation failed: api %d", api);
1321 return RECORDER_ERROR_OUT_OF_MEMORY;
1324 /*LOGD("send msg %s", msg);*/
1326 if (cb_info->is_server_connected) {
1327 __recorder_update_api_waiting(cb_info, api, 1);
1328 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1332 LOGE("message send failed");
1333 *ret = RECORDER_ERROR_INVALID_OPERATION;
1335 *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
1338 __recorder_update_api_waiting(cb_info, api, -1);
1340 muse_core_msg_json_factory_free(msg);
1342 return RECORDER_ERROR_NONE;
1346 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1351 if (!cb_info || !ret || !param) {
1352 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1353 return RECORDER_ERROR_INVALID_PARAMETER;
1356 /*LOGD("type %d, name %s", param->type, param->name);*/
1358 switch (param->type) {
1360 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1362 case MUSE_TYPE_DOUBLE:
1363 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1365 case MUSE_TYPE_STRING:
1366 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1369 LOGE("unknown type %d", param->type);
1374 LOGE("msg creation failed: api %d, type %d, param name %s",
1375 api, param->type, param->name);
1376 return RECORDER_ERROR_OUT_OF_MEMORY;
1379 /*LOGD("send msg %s", msg);*/
1381 if (cb_info->is_server_connected) {
1382 __recorder_update_api_waiting(cb_info, api, 1);
1384 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1388 LOGE("message send failed");
1389 *ret = RECORDER_ERROR_INVALID_OPERATION;
1391 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1394 __recorder_update_api_waiting(cb_info, api, -1);
1396 muse_core_msg_json_factory_free(msg);
1398 return RECORDER_ERROR_NONE;
1402 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1406 g_return_if_fail(cb_info != NULL);
1408 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1410 g_thread_join(cb_info->msg_recv_thread);
1411 cb_info->msg_recv_thread = NULL;
1413 LOGD("msg_recv thread removed");
1415 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1416 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1417 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1419 g_mutex_clear(&cb_info->idle_event_mutex);
1420 g_cond_clear(&cb_info->idle_event_cond);
1422 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1423 g_mutex_clear(&cb_info->api_mutex[i]);
1424 g_cond_clear(&cb_info->api_cond[i]);
1427 if (cb_info->fd > -1) {
1428 muse_core_connection_close(cb_info->fd);
1432 if (cb_info->bufmgr) {
1433 tbm_bufmgr_deinit(cb_info->bufmgr);
1434 cb_info->bufmgr = NULL;
1436 if (cb_info->get_filename) {
1437 free(cb_info->get_filename);
1438 cb_info->get_filename = NULL;
1448 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1450 char **root_directory = (char **)user_data;
1452 if (root_directory == NULL) {
1453 LOGE("user data is NULL");
1457 LOGD("storage id %d, type %d, state %d, path %s",
1458 storage_id, type, state, path ? path : "NULL");
1460 if (type == STORAGE_TYPE_INTERNAL && path) {
1461 if (*root_directory) {
1462 free(*root_directory);
1463 *root_directory = NULL;
1466 *root_directory = strdup(path);
1467 if (*root_directory) {
1468 LOGD("get root directory %s", *root_directory);
1471 LOGE("strdup %s failed", path);
1478 static int _recorder_client_get_root_directory(char **root_directory)
1480 int ret = STORAGE_ERROR_NONE;
1482 if (root_directory == NULL) {
1483 LOGE("user data is NULL");
1487 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1488 if (ret != STORAGE_ERROR_NONE) {
1489 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1496 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1498 int ret = RECORDER_ERROR_NONE;
1499 int destroy_ret = RECORDER_ERROR_NONE;
1502 char *send_msg = NULL;
1503 char *root_directory = NULL;
1504 intptr_t camera_handle = 0;
1505 intptr_t handle = 0;
1506 tbm_bufmgr bufmgr = NULL;
1507 recorder_cli_s *pc = NULL;
1508 recorder_msg_param param;
1510 LOGD("Enter - type %d", type);
1512 if (recorder == NULL) {
1513 LOGE("NULL pointer for recorder handle");
1514 return RECORDER_ERROR_INVALID_PARAMETER;
1517 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1518 LOGE("NULL pointer for camera handle on video recorder mode");
1519 return RECORDER_ERROR_INVALID_PARAMETER;
1522 bufmgr = tbm_bufmgr_init(-1);
1523 if (bufmgr == NULL) {
1524 LOGE("get tbm bufmgr failed");
1525 return RECORDER_ERROR_INVALID_OPERATION;
1528 pc = g_new0(recorder_cli_s, 1);
1530 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1531 goto _ERR_RECORDER_EXIT;
1534 sock_fd = muse_core_client_new();
1537 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1538 ret = RECORDER_ERROR_INVALID_OPERATION;
1539 goto _ERR_RECORDER_EXIT;
1543 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1544 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1545 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1546 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1547 MUSE_TYPE_INT, "pid", getpid(),
1550 pc->camera = camera;
1551 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1552 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1553 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1554 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1555 MUSE_TYPE_INT, "pid", getpid(),
1556 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1563 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1564 goto _ERR_RECORDER_EXIT;
1568 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1570 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1572 muse_core_msg_json_factory_free(send_msg);
1577 LOGE("send msg failed %d", errno);
1578 ret = RECORDER_ERROR_INVALID_OPERATION;
1579 goto _ERR_RECORDER_EXIT;
1583 pc->cb_info = _recorder_client_callback_new(sock_fd);
1584 if (pc->cb_info == NULL) {
1585 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1586 goto _ERR_RECORDER_EXIT;
1591 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1593 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1595 if (ret != RECORDER_ERROR_NONE) {
1596 LOGE("API_CREATE failed 0x%x", ret);
1597 goto _ERR_RECORDER_EXIT;
1600 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1603 LOGE("Receiving Handle Failed!!");
1604 ret = RECORDER_ERROR_INVALID_OPERATION;
1605 goto _ERR_RECORDER_AFTER_CREATE;
1609 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1611 LOGE("failed to get root directory of internal storage");
1612 ret = RECORDER_ERROR_INVALID_OPERATION;
1613 goto _ERR_RECORDER_AFTER_CREATE;
1617 LOGD("root directory [%s]", root_directory);
1619 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1621 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1623 if (ret != RECORDER_ERROR_NONE) {
1624 LOGE("failed to set root directory %s", root_directory);
1625 ret = RECORDER_ERROR_INVALID_OPERATION;
1626 goto _ERR_RECORDER_AFTER_CREATE;
1629 free(root_directory);
1630 root_directory = NULL;
1632 pc->remote_handle = handle;
1633 pc->cb_info->bufmgr = bufmgr;
1635 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1636 type, pc, pc->remote_handle);
1638 *recorder = (recorder_h)pc;
1642 return RECORDER_ERROR_NONE;
1644 _ERR_RECORDER_AFTER_CREATE:
1645 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
1646 LOGE("destroy return 0x%x", destroy_ret);
1649 tbm_bufmgr_deinit(bufmgr);
1652 if (root_directory) {
1653 free(root_directory);
1654 root_directory = NULL;
1658 muse_core_connection_close(sock_fd);
1664 _recorder_client_callback_destroy(pc->cb_info);
1676 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1678 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1682 int recorder_create_audiorecorder(recorder_h *recorder)
1684 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1688 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1690 int ret = RECORDER_ERROR_NONE;
1691 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1692 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1694 if (!pc || !pc->cb_info) {
1695 LOGE("NULL handle");
1696 return RECORDER_ERROR_INVALID_PARAMETER;
1699 if (state == NULL) {
1700 LOGE("NULL pointer state");
1701 return RECORDER_ERROR_INVALID_PARAMETER;
1704 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1706 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1708 if (ret == RECORDER_ERROR_NONE)
1709 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1711 LOGD("ret : 0x%x, state : %d", ret, *state);
1717 int recorder_destroy(recorder_h recorder)
1719 int ret = RECORDER_ERROR_NONE;
1720 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1721 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1723 if (!pc || !pc->cb_info) {
1724 LOGE("NULL handle");
1725 return RECORDER_ERROR_INVALID_PARAMETER;
1730 if (pc->cb_info->is_server_connected)
1731 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1733 LOGW("server disconnected. release resource without send message.");
1735 if (ret == RECORDER_ERROR_NONE) {
1736 _recorder_deactivate_idle_event_all(pc->cb_info);
1737 _recorder_client_callback_destroy(pc->cb_info);
1742 LOGD("ret : 0x%x", ret);
1748 int recorder_prepare(recorder_h recorder)
1750 int ret = RECORDER_ERROR_NONE;
1751 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1752 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1754 if (!pc || !pc->cb_info) {
1755 LOGE("NULL handle");
1756 return RECORDER_ERROR_INVALID_PARAMETER;
1761 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1763 LOGD("ret : 0x%x", ret);
1765 if (ret == RECORDER_ERROR_NONE && pc->camera)
1766 camera_start_evas_rendering(pc->camera);
1772 int recorder_unprepare(recorder_h recorder)
1774 int ret = RECORDER_ERROR_NONE;
1775 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1776 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1777 camera_state_e camera_state = CAMERA_STATE_NONE;
1779 if (!pc || !pc->cb_info) {
1780 LOGE("NULL handle");
1781 return RECORDER_ERROR_INVALID_PARAMETER;
1788 ret = camera_get_state(pc->camera, &camera_state);
1789 if (ret != CAMERA_ERROR_NONE) {
1790 LOGE("failed to get camera state 0x%x", ret);
1791 return RECORDER_ERROR_INVALID_OPERATION;
1794 if (camera_state == CAMERA_STATE_PREVIEW) {
1795 ret = camera_stop_evas_rendering(pc->camera, false);
1796 if (ret != CAMERA_ERROR_NONE) {
1797 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1798 return RECORDER_ERROR_INVALID_OPERATION;
1804 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1806 LOGD("ret : 0x%x", ret);
1812 int recorder_start(recorder_h recorder)
1814 int ret = RECORDER_ERROR_NONE;
1815 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1816 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1817 recorder_state_e current_state = RECORDER_STATE_NONE;
1819 if (!pc || !pc->cb_info) {
1820 LOGE("NULL handle");
1821 return RECORDER_ERROR_INVALID_PARAMETER;
1828 ret = recorder_get_state(recorder, ¤t_state);
1829 if (ret != RECORDER_ERROR_NONE) {
1830 LOGE("failed to get current state 0x%x", ret);
1831 return RECORDER_ERROR_INVALID_OPERATION;
1834 if (current_state == RECORDER_STATE_READY) {
1835 ret = camera_stop_evas_rendering(pc->camera, true);
1836 if (ret != CAMERA_ERROR_NONE) {
1837 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1838 return RECORDER_ERROR_INVALID_OPERATION;
1844 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
1846 if (pc->camera && current_state == RECORDER_STATE_READY)
1847 camera_start_evas_rendering(pc->camera);
1849 LOGD("ret : 0x%x", ret);
1855 int recorder_pause(recorder_h recorder)
1857 int ret = RECORDER_ERROR_NONE;
1858 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1859 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1861 if (!pc || !pc->cb_info) {
1862 LOGE("NULL handle");
1863 return RECORDER_ERROR_INVALID_PARAMETER;
1868 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1870 LOGD("ret : 0x%x", ret);
1876 int recorder_commit(recorder_h recorder)
1878 int ret = RECORDER_ERROR_NONE;
1879 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1880 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1881 recorder_state_e current_state = RECORDER_STATE_NONE;
1883 if (!pc || !pc->cb_info) {
1884 LOGE("NULL handle");
1885 return RECORDER_ERROR_INVALID_PARAMETER;
1892 ret = recorder_get_state(recorder, ¤t_state);
1893 if (ret != RECORDER_ERROR_NONE) {
1894 LOGE("failed to get current state 0x%x", ret);
1895 return RECORDER_ERROR_INVALID_OPERATION;
1898 if (current_state >= RECORDER_STATE_RECORDING) {
1899 ret = camera_stop_evas_rendering(pc->camera, true);
1900 if (ret != CAMERA_ERROR_NONE) {
1901 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1902 return RECORDER_ERROR_INVALID_OPERATION;
1908 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1910 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1911 camera_start_evas_rendering(pc->camera);
1913 LOGD("ret : 0x%x", ret);
1919 int recorder_cancel(recorder_h recorder)
1921 int ret = RECORDER_ERROR_NONE;
1922 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1923 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1924 recorder_state_e current_state = RECORDER_STATE_NONE;
1926 if (!pc || !pc->cb_info) {
1927 LOGE("NULL handle");
1928 return RECORDER_ERROR_INVALID_PARAMETER;
1934 ret = recorder_get_state(recorder, ¤t_state);
1935 if (ret != RECORDER_ERROR_NONE) {
1936 LOGE("failed to get current state 0x%x", ret);
1937 return RECORDER_ERROR_INVALID_OPERATION;
1940 if (current_state >= RECORDER_STATE_RECORDING) {
1941 ret = camera_stop_evas_rendering(pc->camera, true);
1942 if (ret != CAMERA_ERROR_NONE) {
1943 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1944 return RECORDER_ERROR_INVALID_OPERATION;
1949 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1951 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1952 camera_start_evas_rendering(pc->camera);
1954 LOGD("ret : 0x%x", ret);
1960 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1962 int ret = RECORDER_ERROR_NONE;
1964 char *send_msg = NULL;
1965 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1966 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1968 if (!pc || !pc->cb_info) {
1969 LOGE("NULL handle");
1970 return RECORDER_ERROR_INVALID_PARAMETER;
1975 send_msg = muse_core_msg_json_factory_new(api,
1976 MUSE_TYPE_INT, "width", width,
1977 MUSE_TYPE_INT, "height", height,
1980 if (pc->cb_info->is_server_connected) {
1981 __recorder_update_api_waiting(pc->cb_info, api, 1);
1983 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1987 LOGE("message send failed");
1988 ret = RECORDER_ERROR_INVALID_OPERATION;
1990 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1993 __recorder_update_api_waiting(pc->cb_info, api, -1);
1995 muse_core_msg_json_factory_free(send_msg);
1997 LOGE("failed to create msg");
1998 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2001 LOGD("ret : 0x%x", ret);
2007 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
2009 int ret = RECORDER_ERROR_NONE;
2010 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
2011 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2013 if (!pc || !pc->cb_info) {
2014 LOGE("NULL handle");
2015 return RECORDER_ERROR_INVALID_PARAMETER;
2018 if (!width || !height) {
2019 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
2020 return RECORDER_ERROR_INVALID_PARAMETER;
2025 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2027 if (ret == RECORDER_ERROR_NONE) {
2028 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
2029 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
2032 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
2038 int recorder_foreach_supported_video_resolution(recorder_h recorder,
2039 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
2041 int ret = RECORDER_ERROR_NONE;
2042 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2043 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
2045 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2046 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2047 return RECORDER_ERROR_INVALID_PARAMETER;
2050 LOGD("Enter, handle :%x", pc->remote_handle);
2052 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2053 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2055 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2057 LOGD("ret : 0x%x", ret);
2063 int recorder_get_audio_level(recorder_h recorder, double *level)
2065 int ret = RECORDER_ERROR_NONE;
2066 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2067 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2069 if (!pc || !pc->cb_info || level == NULL) {
2070 LOGE("NULL pointer %p %p", pc, level);
2071 return RECORDER_ERROR_INVALID_PARAMETER;
2076 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2078 if (ret == RECORDER_ERROR_NONE)
2079 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2081 LOGD("ret : 0x%x, level %lf", ret, *level);
2087 int recorder_set_filename(recorder_h recorder, const char *filename)
2089 int ret = RECORDER_ERROR_NONE;
2091 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2092 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2093 recorder_msg_param param;
2094 char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2096 if (!pc || !pc->cb_info) {
2097 LOGE("NULL handle");
2098 return RECORDER_ERROR_INVALID_PARAMETER;
2101 if (filename == NULL) {
2102 LOGE("filename is NULL");
2103 return RECORDER_ERROR_INVALID_PARAMETER;
2106 LOGD("ENTER [%s]", filename);
2108 length = strlen(filename);
2110 if (length >= RECORDER_FILENAME_MAX - 1) {
2111 LOGE("too long file name [%d]", length);
2112 return RECORDER_ERROR_INVALID_PARAMETER;
2115 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2116 /* Cannot convert. Use original path. */
2117 strncpy(set_filename, filename, length + 1);
2119 /* Converted. Use converted path. */
2120 LOGD("Converted filename : %s -> %s", filename, set_filename);
2123 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2125 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2127 LOGD("ret : 0x%x", ret);
2133 int recorder_get_filename(recorder_h recorder, char **filename)
2135 int ret = RECORDER_ERROR_NONE;
2136 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2137 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2138 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2140 if (!pc || !pc->cb_info) {
2141 LOGE("NULL handle");
2142 return RECORDER_ERROR_INVALID_PARAMETER;
2145 if (filename == NULL) {
2146 LOGE("filename is NULL");
2147 return RECORDER_ERROR_INVALID_PARAMETER;
2152 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2154 if (ret == RECORDER_ERROR_NONE) {
2155 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2156 /* Cannot convert. Use original path. */
2157 *filename = pc->cb_info->get_filename;
2159 /* Converted. Use converted path. */
2160 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2161 *filename = strdup(compat_filename);
2162 free(pc->cb_info->get_filename);
2165 pc->cb_info->get_filename = NULL;
2168 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2174 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2176 int ret = RECORDER_ERROR_NONE;
2177 int set_format = (int)format;
2178 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2179 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2180 recorder_msg_param param;
2182 if (!pc || !pc->cb_info) {
2183 LOGE("NULL handle");
2184 return RECORDER_ERROR_INVALID_PARAMETER;
2187 LOGD("ENTER, set_format : %d", set_format);
2189 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2191 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2193 LOGD("ret : 0x%x", ret);
2198 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2200 int ret = RECORDER_ERROR_NONE;
2201 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2202 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2204 if (!pc || !pc->cb_info) {
2205 LOGE("NULL handle");
2206 return RECORDER_ERROR_INVALID_PARAMETER;
2209 if (format == NULL) {
2210 LOGE("NULL pointer data");
2211 return RECORDER_ERROR_INVALID_PARAMETER;
2216 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2218 if (ret == RECORDER_ERROR_NONE)
2219 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2221 LOGD("ret : 0x%x, format %d", ret, *format);
2227 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2229 int ret = RECORDER_ERROR_NONE;
2230 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2231 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2232 bool is_available = false;
2233 int stream_index = 0;
2234 char *stream_type = NULL;
2235 char *send_msg = NULL;
2238 if (!pc || !pc->cb_info || stream_info == NULL) {
2239 LOGE("NULL handle");
2240 return RECORDER_ERROR_INVALID_PARAMETER;
2245 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2246 if (ret != SOUND_MANAGER_ERROR_NONE) {
2247 LOGE("stream info verification failed");
2248 return RECORDER_ERROR_INVALID_OPERATION;
2251 if (is_available == false) {
2252 LOGE("stream information is not available");
2253 return RECORDER_ERROR_INVALID_OPERATION;
2256 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2257 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2259 LOGD("sound manager return [0x%x]", ret);
2261 if (ret == SOUND_MANAGER_ERROR_NONE) {
2262 send_msg = muse_core_msg_json_factory_new(api,
2263 MUSE_TYPE_STRING, "stream_type", stream_type,
2264 MUSE_TYPE_INT, "stream_index", stream_index,
2267 if (pc->cb_info->is_server_connected) {
2268 __recorder_update_api_waiting(pc->cb_info, api, 1);
2270 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2274 LOGE("message send failed");
2275 ret = RECORDER_ERROR_INVALID_OPERATION;
2277 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2280 __recorder_update_api_waiting(pc->cb_info, api, -1);
2282 muse_core_msg_json_factory_free(send_msg);
2284 LOGE("failed to create msg");
2285 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2288 ret = RECORDER_ERROR_INVALID_OPERATION;
2295 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2297 int ret = RECORDER_ERROR_NONE;
2298 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2299 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2301 if (!pc || !pc->cb_info || callback == NULL) {
2302 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2303 return RECORDER_ERROR_INVALID_PARAMETER;
2306 LOGD("Enter, handle :%x", pc->remote_handle);
2308 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2310 if (ret == RECORDER_ERROR_NONE) {
2311 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2312 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2315 LOGD("ret : 0x%x", ret);
2321 int recorder_unset_state_changed_cb(recorder_h recorder)
2323 int ret = RECORDER_ERROR_NONE;
2324 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2325 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2327 if (!pc || !pc->cb_info) {
2328 LOGE("NULL handle");
2329 return RECORDER_ERROR_INVALID_PARAMETER;
2334 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2336 if (ret == RECORDER_ERROR_NONE) {
2337 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2338 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2341 LOGD("ret : 0x%x", ret);
2347 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2349 int ret = RECORDER_ERROR_NONE;
2350 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2351 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2353 if (!pc || !pc->cb_info || callback == NULL) {
2354 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2355 return RECORDER_ERROR_INVALID_PARAMETER;
2358 LOGD("Enter, handle :%x", pc->remote_handle);
2360 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2362 if (ret == RECORDER_ERROR_NONE) {
2363 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2364 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2367 LOGD("ret : 0x%x", ret);
2373 int recorder_unset_interrupted_cb(recorder_h recorder)
2375 int ret = RECORDER_ERROR_NONE;
2376 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2377 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2379 if (!pc || !pc->cb_info) {
2380 LOGE("NULL handle");
2381 return RECORDER_ERROR_INVALID_PARAMETER;
2386 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2388 if (ret == RECORDER_ERROR_NONE) {
2389 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2390 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2393 LOGD("ret : 0x%x", ret);
2399 int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
2401 int ret = RECORDER_ERROR_NONE;
2402 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2403 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
2405 if (!pc || !pc->cb_info || callback == NULL) {
2406 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2407 return RECORDER_ERROR_INVALID_PARAMETER;
2410 LOGD("Enter, handle :%x", pc->remote_handle);
2412 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2414 if (ret == RECORDER_ERROR_NONE) {
2415 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
2416 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
2419 LOGD("ret : 0x%x", ret);
2425 int recorder_unset_interrupt_started_cb(recorder_h recorder)
2427 int ret = RECORDER_ERROR_NONE;
2428 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
2429 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2431 if (!pc || !pc->cb_info) {
2432 LOGE("NULL handle");
2433 return RECORDER_ERROR_INVALID_PARAMETER;
2438 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2440 if (ret == RECORDER_ERROR_NONE) {
2441 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2442 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2445 LOGD("ret : 0x%x", ret);
2451 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2453 int ret = RECORDER_ERROR_NONE;
2454 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2455 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2457 if (!pc || !pc->cb_info || callback == NULL) {
2458 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2459 return RECORDER_ERROR_INVALID_PARAMETER;
2462 LOGD("Enter, handle :%x", pc->remote_handle);
2464 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2466 if (ret == RECORDER_ERROR_NONE) {
2467 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2468 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2471 LOGD("ret : 0x%x", ret);
2477 int recorder_unset_audio_stream_cb(recorder_h recorder)
2479 int ret = RECORDER_ERROR_NONE;
2480 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2481 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2483 if (!pc || !pc->cb_info) {
2484 LOGE("NULL handle");
2485 return RECORDER_ERROR_INVALID_PARAMETER;
2490 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2492 if (ret == RECORDER_ERROR_NONE) {
2493 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2494 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2497 LOGD("ret : 0x%x", ret);
2503 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2505 int ret = RECORDER_ERROR_NONE;
2506 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2507 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2509 if (!pc || !pc->cb_info || !callback) {
2510 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2511 return RECORDER_ERROR_INVALID_PARAMETER;
2514 LOGD("Enter, handle :%x", pc->remote_handle);
2516 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2518 if (ret == RECORDER_ERROR_NONE) {
2519 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2520 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2523 LOGD("ret : 0x%x", ret);
2529 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2531 int ret = RECORDER_ERROR_NONE;
2532 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2533 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2535 if (!pc || !pc->cb_info) {
2536 LOGE("NULL handle");
2537 return RECORDER_ERROR_INVALID_PARAMETER;
2542 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2544 if (ret == RECORDER_ERROR_NONE) {
2545 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2546 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2549 LOGD("ret : 0x%x", ret);
2555 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2557 int ret = RECORDER_ERROR_NONE;
2558 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2559 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2561 if (!pc || !pc->cb_info || callback == NULL) {
2562 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2563 return RECORDER_ERROR_INVALID_PARAMETER;
2566 LOGD("Enter, handle :%x", pc->remote_handle);
2568 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2570 if (ret == RECORDER_ERROR_NONE) {
2571 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2572 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2575 LOGD("ret : 0x%x", ret);
2581 int recorder_unset_error_cb(recorder_h recorder)
2583 int ret = RECORDER_ERROR_NONE;
2584 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2585 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2587 if (!pc || !pc->cb_info) {
2588 LOGE("NULL handle");
2589 return RECORDER_ERROR_INVALID_PARAMETER;
2594 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2596 if (ret == RECORDER_ERROR_NONE) {
2597 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2598 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2601 LOGD("ret : 0x%x", ret);
2607 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2609 int ret = RECORDER_ERROR_NONE;
2610 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2611 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2613 if (!pc || !pc->cb_info || callback == NULL) {
2614 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2615 return RECORDER_ERROR_INVALID_PARAMETER;
2618 LOGD("Enter, handle :%x", pc->remote_handle);
2620 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2622 if (ret == RECORDER_ERROR_NONE) {
2623 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2624 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2627 LOGD("ret : 0x%x", ret);
2633 int recorder_unset_recording_status_cb(recorder_h recorder)
2635 int ret = RECORDER_ERROR_NONE;
2636 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2637 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2639 if (!pc || !pc->cb_info) {
2640 LOGE("NULL handle");
2641 return RECORDER_ERROR_INVALID_PARAMETER;
2646 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2648 if (ret == RECORDER_ERROR_NONE) {
2649 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2650 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2653 LOGD("ret : 0x%x", ret);
2659 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2661 int ret = RECORDER_ERROR_NONE;
2662 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2663 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2665 if (!pc || !pc->cb_info || callback == NULL) {
2666 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2667 return RECORDER_ERROR_INVALID_PARAMETER;
2670 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2672 if (ret == RECORDER_ERROR_NONE) {
2673 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2674 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2677 LOGD("ret : 0x%x", ret);
2683 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2685 int ret = RECORDER_ERROR_NONE;
2686 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2687 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2689 if (!pc || !pc->cb_info) {
2690 LOGE("NULL handle");
2691 return RECORDER_ERROR_INVALID_PARAMETER;
2696 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2698 if (ret == RECORDER_ERROR_NONE) {
2699 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2700 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2703 LOGD("ret : 0x%x", ret);
2709 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2711 int ret = RECORDER_ERROR_NONE;
2712 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2713 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2715 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2716 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2717 return RECORDER_ERROR_INVALID_PARAMETER;
2720 LOGD("Enter, handle :%x", pc->remote_handle);
2722 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2723 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2725 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2727 LOGD("ret : 0x%x", ret);
2733 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2735 int ret = RECORDER_ERROR_NONE;
2736 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2737 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2738 recorder_msg_param param;
2740 if (!pc || !pc->cb_info) {
2741 LOGE("NULL handle");
2742 return RECORDER_ERROR_INVALID_PARAMETER;
2747 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2749 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2751 LOGD("ret : 0x%x", ret);
2757 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2759 int ret = RECORDER_ERROR_NONE;
2760 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2761 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2762 recorder_msg_param param;
2764 if (!pc || !pc->cb_info) {
2765 LOGE("NULL handle");
2766 return RECORDER_ERROR_INVALID_PARAMETER;
2771 RECORDER_MSG_PARAM_SET(param, INT, second);
2773 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2775 LOGD("ret : 0x%x", ret);
2781 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2783 int ret = RECORDER_ERROR_NONE;
2784 int set_device = (int)device;
2785 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2786 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2787 recorder_msg_param param;
2789 if (!pc || !pc->cb_info) {
2790 LOGE("NULL handle");
2791 return RECORDER_ERROR_INVALID_PARAMETER;
2796 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2798 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2800 LOGD("ret : 0x%x", ret);
2806 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2808 int ret = RECORDER_ERROR_NONE;
2809 int set_codec = (int)codec;
2810 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2811 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2812 recorder_msg_param param;
2814 if (!pc || !pc->cb_info) {
2815 LOGE("NULL handle");
2816 return RECORDER_ERROR_INVALID_PARAMETER;
2821 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2823 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2825 LOGD("ret : 0x%x", ret);
2831 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2833 int ret = RECORDER_ERROR_NONE;
2834 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2835 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2837 if (!pc || !pc->cb_info) {
2838 LOGE("NULL handle");
2839 return RECORDER_ERROR_INVALID_PARAMETER;
2842 if (codec == NULL) {
2843 LOGE("codec is NULL");
2844 return RECORDER_ERROR_INVALID_PARAMETER;
2849 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2851 if (ret == RECORDER_ERROR_NONE)
2852 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2854 LOGD("ret : 0x%x, codec %d", ret, *codec);
2860 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2862 int ret = RECORDER_ERROR_NONE;
2863 int set_codec = (int)codec;
2864 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2865 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2866 recorder_msg_param param;
2868 if (!pc || !pc->cb_info) {
2869 LOGE("NULL handle");
2870 return RECORDER_ERROR_INVALID_PARAMETER;
2875 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2877 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2879 LOGD("ret : 0x%x", ret);
2885 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2887 int ret = RECORDER_ERROR_NONE;
2888 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2889 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2891 if (!pc || !pc->cb_info) {
2892 LOGE("NULL handle");
2893 return RECORDER_ERROR_INVALID_PARAMETER;
2896 if (codec == NULL) {
2897 LOGE("codec is NULL");
2898 return RECORDER_ERROR_INVALID_PARAMETER;
2903 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2905 if (ret == RECORDER_ERROR_NONE)
2906 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2908 LOGD("ret : 0x%x, codec %d", ret, *codec);
2914 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2916 int ret = RECORDER_ERROR_NONE;
2917 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2918 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2919 recorder_msg_param param;
2921 if (!pc || !pc->cb_info) {
2922 LOGE("NULL handle");
2923 return RECORDER_ERROR_INVALID_PARAMETER;
2926 LOGD("ENTER, samplerate : %d", samplerate);
2928 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2930 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2932 LOGD("ret : 0x%x", ret);
2938 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2940 int ret = RECORDER_ERROR_NONE;
2941 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2942 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2943 recorder_msg_param param;
2945 if (!pc || !pc->cb_info) {
2946 LOGE("NULL handle");
2947 return RECORDER_ERROR_INVALID_PARAMETER;
2952 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2954 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2956 LOGD("ret : 0x%x", ret);
2962 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2964 int ret = RECORDER_ERROR_NONE;
2965 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2966 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2967 recorder_msg_param param;
2969 if (!pc || !pc->cb_info) {
2970 LOGE("NULL handle");
2971 return RECORDER_ERROR_INVALID_PARAMETER;
2976 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2978 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2980 LOGD("ret : 0x%x", ret);
2986 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2988 int ret = RECORDER_ERROR_NONE;
2989 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2990 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2992 if (!pc || !pc->cb_info) {
2993 LOGE("NULL handle");
2994 return RECORDER_ERROR_INVALID_PARAMETER;
2997 if (kbyte == NULL) {
2998 LOGE("NULL pointer kbyte");
2999 return RECORDER_ERROR_INVALID_PARAMETER;
3004 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3006 if (ret == RECORDER_ERROR_NONE)
3007 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
3009 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
3015 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
3017 int ret = RECORDER_ERROR_NONE;
3018 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
3019 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3021 if (!pc || !pc->cb_info) {
3022 LOGE("NULL handle");
3023 return RECORDER_ERROR_INVALID_PARAMETER;
3026 if (second == NULL) {
3027 LOGE("NULL pointer second");
3028 return RECORDER_ERROR_INVALID_PARAMETER;
3033 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3035 if (ret == RECORDER_ERROR_NONE)
3036 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
3038 LOGD("ret : 0x%x, %d second", ret, *second);
3044 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
3046 int ret = RECORDER_ERROR_NONE;
3047 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
3048 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3050 if (!pc || !pc->cb_info) {
3051 LOGE("NULL handle");
3052 return RECORDER_ERROR_INVALID_PARAMETER;
3055 if (device == NULL) {
3056 LOGE("NULL pointer device");
3057 return RECORDER_ERROR_INVALID_PARAMETER;
3062 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3064 if (ret == RECORDER_ERROR_NONE)
3065 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
3067 LOGD("ret : 0x%x, device %d", ret, *device);
3073 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
3075 int ret = RECORDER_ERROR_NONE;
3076 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
3077 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3079 if (!pc || !pc->cb_info) {
3080 LOGE("NULL handle");
3081 return RECORDER_ERROR_INVALID_PARAMETER;
3084 if (samplerate == NULL) {
3085 LOGE("NULL pointer handle");
3086 return RECORDER_ERROR_INVALID_PARAMETER;
3091 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3093 if (ret == RECORDER_ERROR_NONE)
3094 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3096 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3102 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3104 int ret = RECORDER_ERROR_NONE;
3105 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3106 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3108 if (!pc || !pc->cb_info) {
3109 LOGE("NULL handle");
3110 return RECORDER_ERROR_INVALID_PARAMETER;
3113 if (bitrate == NULL) {
3114 LOGE("NULL pointer");
3115 return RECORDER_ERROR_INVALID_PARAMETER;
3120 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3122 if (ret == RECORDER_ERROR_NONE)
3123 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3125 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3131 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3133 int ret = RECORDER_ERROR_NONE;
3134 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3135 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3137 if (!pc || !pc->cb_info) {
3138 LOGE("NULL handle");
3139 return RECORDER_ERROR_INVALID_PARAMETER;
3142 if (bitrate == NULL) {
3143 LOGE("NULL pointer");
3144 return RECORDER_ERROR_INVALID_PARAMETER;
3149 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3151 if (ret == RECORDER_ERROR_NONE)
3152 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3154 LOGD("ret : 0x%x", ret);
3160 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3162 int ret = RECORDER_ERROR_NONE;
3163 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3164 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3166 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3167 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3168 return RECORDER_ERROR_INVALID_PARAMETER;
3171 LOGD("Enter, handle :%x", pc->remote_handle);
3173 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3174 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3176 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3178 LOGD("ret : 0x%x", ret);
3184 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3186 int ret = RECORDER_ERROR_NONE;
3187 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3188 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3190 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3191 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3192 return RECORDER_ERROR_INVALID_PARAMETER;
3195 LOGD("Enter, handle :%x", pc->remote_handle);
3197 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3198 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3200 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3202 LOGD("ret : 0x%x", ret);
3208 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3210 int ret = RECORDER_ERROR_NONE;
3211 int set_enable = (int)enable;
3212 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3213 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3214 recorder_msg_param param;
3216 if (!pc || !pc->cb_info) {
3217 LOGE("NULL handle");
3218 return RECORDER_ERROR_INVALID_PARAMETER;
3223 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3225 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3227 LOGD("ret : 0x%x", ret);
3233 bool recorder_attr_is_muted(recorder_h recorder)
3236 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3237 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3239 if (!pc || !pc->cb_info) {
3240 LOGE("NULL handle");
3246 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3248 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3251 LOGD("ret : %d", ret);
3257 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3259 int ret = RECORDER_ERROR_NONE;
3260 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3261 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3262 recorder_msg_param param;
3264 if (!pc || !pc->cb_info) {
3265 LOGE("NULL handle");
3266 return RECORDER_ERROR_INVALID_PARAMETER;
3269 LOGD("ENTER - %.20lf", rate);
3271 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3273 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3275 LOGD("ret : 0x%x", ret);
3281 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3283 int ret = RECORDER_ERROR_NONE;
3284 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3285 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3287 if (!pc || !pc->cb_info) {
3288 LOGE("NULL handle");
3289 return RECORDER_ERROR_INVALID_PARAMETER;
3293 LOGE("rate is NULL");
3294 return RECORDER_ERROR_INVALID_PARAMETER;
3299 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3300 if (ret == RECORDER_ERROR_NONE)
3301 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3303 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3309 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3311 int ret = RECORDER_ERROR_NONE;
3312 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3313 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3314 recorder_msg_param param;
3316 if (!pc || !pc->cb_info) {
3317 LOGE("NULL handle");
3318 return RECORDER_ERROR_INVALID_PARAMETER;
3323 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3325 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3327 LOGD("ret : 0x%x", ret);
3333 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3335 int ret = RECORDER_ERROR_NONE;
3336 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3337 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3339 if (!pc || !pc->cb_info) {
3340 LOGE("NULL handle");
3341 return RECORDER_ERROR_INVALID_PARAMETER;
3344 if (channel_count == NULL) {
3345 LOGE("channel_count is NULL");
3346 return RECORDER_ERROR_INVALID_PARAMETER;
3351 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3353 if (ret == RECORDER_ERROR_NONE)
3354 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3356 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3362 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3364 int ret = RECORDER_ERROR_NONE;
3365 int set_orientation = (int)orientation;
3366 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3367 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3368 recorder_msg_param param;
3370 if (!pc || !pc->cb_info) {
3371 LOGE("NULL handle");
3372 return RECORDER_ERROR_INVALID_PARAMETER;
3377 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3379 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3381 LOGD("ret : 0x%x", ret);
3387 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3389 int ret = RECORDER_ERROR_NONE;
3390 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3391 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3393 if (!pc || !pc->cb_info) {
3394 LOGE("NULL handle");
3395 return RECORDER_ERROR_INVALID_PARAMETER;
3398 if (orientation == NULL) {
3399 LOGE("orientation is NULL");
3400 return RECORDER_ERROR_INVALID_PARAMETER;
3405 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3407 if (ret == RECORDER_ERROR_NONE)
3408 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3410 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3416 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3418 int ret = RECORDER_ERROR_NONE;
3420 int get_device_state = 0;
3421 char *send_msg = NULL;
3422 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3425 LOGE("NULL pointer");
3426 return RECORDER_ERROR_INVALID_PARAMETER;
3429 LOGD("Enter - type %d", type);
3431 sock_fd = muse_core_client_new();
3434 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3435 ret = RECORDER_ERROR_INVALID_OPERATION;
3436 goto _GET_DEVICE_STATE_EXIT;
3440 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3441 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3442 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3447 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3448 goto _GET_DEVICE_STATE_EXIT;
3452 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3454 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3456 muse_core_msg_json_factory_free(send_msg);
3461 LOGE("send msg failed %d", errno);
3462 ret = RECORDER_ERROR_INVALID_OPERATION;
3463 goto _GET_DEVICE_STATE_EXIT;
3467 ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3470 LOGE("recv msg failed %d", errno);
3471 ret = RECORDER_ERROR_INVALID_OPERATION;
3472 goto _GET_DEVICE_STATE_EXIT;
3476 if (!muse_recorder_msg_get(ret, recv_msg)) {
3478 LOGE("failed to get return value from msg [%s]", recv_msg);
3479 ret = RECORDER_ERROR_INVALID_OPERATION;
3480 goto _GET_DEVICE_STATE_EXIT;
3484 if (ret == RECORDER_ERROR_NONE) {
3485 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3486 *state = (recorder_device_state_e)get_device_state;
3487 LOGD("device type %d state %d", type, *state);
3489 LOGE("failed to get device state from msg [%s]", recv_msg);
3490 ret = RECORDER_ERROR_INVALID_OPERATION;
3493 LOGE("failed 0x%x", ret);
3496 _GET_DEVICE_STATE_EXIT:
3498 muse_core_connection_close(sock_fd);
3506 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3508 int ret = RECORDER_ERROR_NONE;
3509 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3510 recorder_cb_info *info = NULL;
3512 if (!callback || !cb_id) {
3513 LOGE("invalid pointer %p %p", callback, cb_id);
3514 return RECORDER_ERROR_INVALID_PARAMETER;
3517 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3519 /* check recorder support */
3520 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3521 if (ret != RECORDER_ERROR_NONE) {
3522 LOGE("get device state failed");
3523 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3527 info = g_new0(recorder_cb_info, 1);
3529 LOGE("info failed");
3530 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3534 info->id = ++g_rec_dev_state_changed_cb_id;
3535 info->callback = (void *)callback;
3536 info->user_data = user_data;
3540 /* subscribe dbus signal for camera state change */
3541 if (!g_rec_dev_state_changed_cb_conn) {
3542 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3543 if (!g_rec_dev_state_changed_cb_conn) {
3544 LOGE("failed to get gdbus connection");
3545 ret = RECORDER_ERROR_INVALID_OPERATION;
3549 LOGD("subscribe signal %s - %s - %s",
3550 MM_CAMCORDER_DBUS_OBJECT,
3551 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3552 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3554 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3555 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3556 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3557 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3558 LOGE("failed to get gdbus connection");
3559 ret = RECORDER_ERROR_INVALID_OPERATION;
3563 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3566 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3568 LOGD("callback id %d", info->id);
3571 if (ret != RECORDER_ERROR_NONE) {
3578 if (g_rec_dev_state_changed_cb_conn) {
3579 g_object_unref(g_rec_dev_state_changed_cb_conn);
3580 g_rec_dev_state_changed_cb_conn = NULL;
3585 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3591 int recorder_remove_device_state_changed_cb(int cb_id)
3593 int ret = RECORDER_ERROR_NONE;
3594 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3595 GList *tmp_list = NULL;
3596 recorder_cb_info *info = NULL;
3598 /* check recorder support */
3599 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3600 if (ret != RECORDER_ERROR_NONE) {
3601 LOGE("get device state failed");
3605 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3607 if (!g_rec_dev_state_changed_cb_list) {
3608 LOGE("there is no callback info");
3609 ret = RECORDER_ERROR_INVALID_OPERATION;
3613 tmp_list = g_rec_dev_state_changed_cb_list;
3616 info = tmp_list->data;
3617 tmp_list = tmp_list->next;
3624 if (info->id == cb_id) {
3625 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3630 if (!g_rec_dev_state_changed_cb_list) {
3631 /* no remained callback */
3632 if (g_rec_dev_state_changed_cb_conn) {
3633 /* unsubscribe signal */
3634 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3635 g_rec_dev_state_changed_cb_subscribe_id = 0;
3637 /* unref connection */
3638 g_object_unref(g_rec_dev_state_changed_cb_conn);
3639 g_rec_dev_state_changed_cb_conn = NULL;
3643 LOGD("id %d callback removed", cb_id);
3644 ret = RECORDER_ERROR_NONE;
3650 LOGE("id %d callback not found", cb_id);
3651 ret = RECORDER_ERROR_INVALID_PARAMETER;
3654 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);