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.h>
29 #include <muse_client.h>
30 #include <recorder_private.h>
33 #include <tzplatform_config.h>
38 #define LOG_TAG "TIZEN_N_RECORDER"
39 #define MODULE_NAME "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;
47 static GMutex g_rec_idle_event_lock;
51 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
54 api < 0 || api >= MUSE_RECORDER_API_MAX) {
55 LOGE("invalid param %p %d", cb_info, api);
59 g_mutex_lock(&(cb_info->api_mutex[api]));
60 cb_info->api_waiting[api] += value;
61 g_mutex_unlock(&(cb_info->api_mutex[api]));
63 /*LOGD("api %d, value %d, waiting %d",
64 api, value, cb_info->api_waiting[api]);*/
70 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
71 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
72 const gchar *signal_name, GVariant *param, gpointer user_data)
75 recorder_type_e type = RECORDER_TYPE_AUDIO;
76 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
77 GList *tmp_list = NULL;
78 recorder_cb_info *info = NULL;
80 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
82 if (!g_rec_dev_state_changed_cb_list || !param) {
83 LOGW("no callback or NULL param %p", param);
87 /* get device type and state */
88 g_variant_get(param, "(i)", &value);
91 state = 0x0000ffff & value;
93 LOGD("type %d, state %d", type, state);
95 tmp_list = g_rec_dev_state_changed_cb_list;
98 info = (recorder_cb_info *)tmp_list->data;
101 if (info->callback) {
102 LOGD("start id[%d] callback", info->id);
103 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
104 LOGD("returned id[%d] callback", info->id);
106 LOGW("NULL callback for id %d", info->id);
110 tmp_list = tmp_list->next;
114 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
120 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
122 tbm_bo tmp_bo = NULL;
123 tbm_bo_handle tmp_bo_handle = {NULL, };
125 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
126 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
127 bufmgr, bo, bo_handle, tbm_key);
131 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
132 if (tmp_bo == NULL) {
133 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
137 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
138 if (tmp_bo_handle.ptr == NULL) {
139 LOGE("bo map failed %p", tmp_bo);
140 tbm_bo_unref(tmp_bo);
145 /* set bo and bo_handle */
147 *bo_handle = tmp_bo_handle;
152 static void _recorder_release_imported_bo(tbm_bo *bo)
154 if (bo == NULL || *bo == NULL) {
166 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
168 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
169 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
173 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
175 g_mutex_lock(&cb_info->user_cb_mutex[event]);
177 if (cb_info->user_cb[event] == NULL) {
178 if (event != MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM &&
179 event != MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM) {
180 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
181 LOGW("NULL callback for event %d, return here", event);
184 LOGW("NULL callback for event %d, NOT return here", event);
189 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
195 muse_recorder_msg_get(previous, recv_msg);
196 muse_recorder_msg_get(current, recv_msg);
197 muse_recorder_msg_get(by_policy, recv_msg);
199 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
200 (recorder_state_e)current,
202 cb_info->user_data[event]);
205 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
209 muse_recorder_msg_get(type, recv_msg);
211 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
212 cb_info->user_data[event]);
215 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
217 int64_t cb_elapsed_time = 0;
218 int64_t cb_file_size = 0;
220 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
221 muse_recorder_msg_get(cb_file_size, recv_msg);
223 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
224 (unsigned long long)cb_file_size,
225 cb_info->user_data[event]);
228 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
234 muse_recorder_msg_get(policy, recv_msg);
235 muse_recorder_msg_get(previous, recv_msg);
236 muse_recorder_msg_get(current, recv_msg);
238 LOGW("INTERRUPTED - policy %d, state %d -> %d", policy, previous, current);
240 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
241 (recorder_state_e)previous,
242 (recorder_state_e)current,
243 cb_info->user_data[event]);
246 case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
251 muse_recorder_msg_get(policy, recv_msg);
252 muse_recorder_msg_get(state, recv_msg);
254 LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
256 ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
257 (recorder_state_e)state, cb_info->user_data[event]);
260 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
268 tbm_bo_handle bo_handle = {.ptr = NULL};
269 char *send_msg = NULL;
271 muse_recorder_msg_get(tbm_key, recv_msg);
277 if (cb_info->user_cb[event]) {
278 if (_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
279 muse_recorder_msg_get(size, recv_msg);
280 muse_recorder_msg_get(format, recv_msg);
281 muse_recorder_msg_get(channel, recv_msg);
282 muse_recorder_msg_get(timestamp, recv_msg);
284 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
285 size, (audio_sample_type_e)format, channel,
286 (unsigned int)timestamp, cb_info->user_data[event]);
288 /* release imported bo */
289 _recorder_release_imported_bo(&bo);
291 LOGE("tbm key %d import failed", tbm_key);
296 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
297 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
299 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
300 LOGE("sending message failed");
302 muse_core_msg_free(send_msg);
305 case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
312 tbm_bo_handle bo_handle = {.ptr = NULL};
313 char *send_msg = NULL;
315 muse_recorder_msg_get(tbm_key, recv_msg);
321 if (cb_info->user_cb[event]) {
322 if (_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
323 muse_recorder_msg_get(size, recv_msg);
324 muse_recorder_msg_get(offset, recv_msg);
326 ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
327 size, (unsigned long long)offset, cb_info->user_data[event]);
329 /* release imported bo */
330 _recorder_release_imported_bo(&bo);
332 LOGE("tbm key %d import failed", tbm_key);
337 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
338 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
340 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
341 LOGE("sending message failed");
343 muse_core_msg_free(send_msg);
346 LOGE("failed to create send msg for key %d", tbm_key);
350 case MUSE_RECORDER_EVENT_TYPE_ERROR:
353 int current_state = 0;
355 muse_recorder_msg_get(error, recv_msg);
356 muse_recorder_msg_get(current_state, recv_msg);
358 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
359 (recorder_state_e)current_state,
360 cb_info->user_data[event]);
363 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
367 muse_recorder_msg_get(codec, recv_msg);
369 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
370 cb_info->user_cb[event] = NULL;
371 cb_info->user_data[event] = NULL;
372 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
376 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
380 muse_recorder_msg_get(format, recv_msg);
382 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, 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_FILE_FORMAT");*/
389 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
393 muse_recorder_msg_get(codec, recv_msg);
395 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, 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_VIDEO_ENCODER");*/
402 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
407 muse_recorder_msg_get(width, recv_msg);
408 muse_recorder_msg_get(height, recv_msg);
410 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
411 cb_info->user_cb[event] = NULL;
412 cb_info->user_data[event] = NULL;
413 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
419 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
425 static gboolean _recorder_idle_event_callback(gpointer data)
427 recorder_cb_info_s *cb_info = NULL;
428 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
430 if (rec_idle_event == NULL) {
431 LOGE("rec_idle_event is NULL");
436 g_mutex_lock(&g_rec_idle_event_lock);
438 cb_info = rec_idle_event->cb_info;
439 if (cb_info == NULL) {
440 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
441 g_mutex_unlock(&g_rec_idle_event_lock);
442 goto IDLE_EVENT_CALLBACK_DONE;
445 /* remove event from list */
446 if (cb_info->idle_event_list)
447 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
449 g_mutex_unlock(&g_rec_idle_event_lock);
452 _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
454 IDLE_EVENT_CALLBACK_DONE:
456 g_free(rec_idle_event);
457 rec_idle_event = NULL;
463 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
465 recorder_idle_event_s *rec_idle_event = NULL;
468 if (cb_info == NULL) {
469 LOGE("cb_info is NULL");
473 g_mutex_lock(&g_rec_idle_event_lock);
475 if (cb_info->idle_event_list == NULL) {
478 list = cb_info->idle_event_list;
481 rec_idle_event = list->data;
482 list = g_list_next(list);
484 if (!rec_idle_event) {
485 LOGW("The event is NULL");
489 if (g_idle_remove_by_data(rec_idle_event)) {
490 LOGW("remove idle event %p done", rec_idle_event);
492 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
494 g_free(rec_idle_event);
495 rec_idle_event = NULL;
500 LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
501 rec_idle_event, rec_idle_event->event);
503 rec_idle_event->cb_info = NULL;
505 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
508 g_list_free(cb_info->idle_event_list);
509 cb_info->idle_event_list = NULL;
512 g_mutex_unlock(&g_rec_idle_event_lock);
518 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
520 recorder_message_s *rec_msg = NULL;
521 recorder_msg_handler_info_s *msg_handler_info = NULL;
523 if (!cb_info || !msg) {
524 LOGE("NULL pointer %p %p", cb_info, msg);
528 rec_msg = g_new0(recorder_message_s, 1);
530 LOGE("failed to alloc rec_msg for [%s]", msg);
535 rec_msg->event = event;
536 rec_msg->event_class = event_class;
538 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
540 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
542 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
543 msg_handler_info = &cb_info->audio_stream_cb_info;
544 else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
545 msg_handler_info = &cb_info->muxed_stream_cb_info;
547 msg_handler_info = &cb_info->msg_handler_info;
549 g_mutex_lock(&msg_handler_info->mutex);
550 g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
551 g_cond_signal(&msg_handler_info->cond);
552 g_mutex_unlock(&msg_handler_info->mutex);
560 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
562 if (!cb_info || !msg) {
563 LOGE("NULL pointer %p %p", cb_info, msg);
568 case MUSE_RECORDER_API_GET_STATE:
571 muse_recorder_msg_get(get_state, msg);
572 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
575 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
579 muse_recorder_msg_get(get_width, msg);
580 muse_recorder_msg_get(get_height, msg);
581 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
582 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
585 case MUSE_RECORDER_API_GET_FILE_FORMAT:
588 muse_recorder_msg_get(get_format, msg);
589 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
592 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
595 muse_recorder_msg_get(get_codec, msg);
596 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
599 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
602 muse_recorder_msg_get(get_codec, msg);
603 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
606 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
609 muse_recorder_msg_get(get_kbyte, msg);
610 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
613 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
616 muse_recorder_msg_get(get_second, msg);
617 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
620 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
623 muse_recorder_msg_get(get_device, msg);
624 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
627 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
629 int get_samplerate = 0;
630 muse_recorder_msg_get(get_samplerate, msg);
631 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
634 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
637 muse_recorder_msg_get(get_bitrate, msg);
638 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
641 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
644 muse_recorder_msg_get(get_bitrate, msg);
645 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
648 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
651 muse_recorder_msg_get_double(get_rate, msg);
652 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
655 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
657 int get_channel_count = 0;
658 muse_recorder_msg_get(get_channel_count, msg);
659 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
662 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
664 int get_orientation = 0;
665 muse_recorder_msg_get(get_orientation, msg);
666 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
669 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
671 double get_level = 0.0;
672 muse_recorder_msg_get_double(get_level, msg);
673 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
676 case MUSE_RECORDER_API_GET_FILENAME:
678 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
679 muse_recorder_msg_get_string(get_filename, msg);
680 if (cb_info->get_filename) {
681 free(cb_info->get_filename);
682 cb_info->get_filename = NULL;
684 cb_info->get_filename = strdup(get_filename);
695 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
697 int ret = RECORDER_ERROR_NONE;
701 int event_class = -1;
703 if (!cb_info || !msg) {
704 LOGE("invalid ptr %p %p", cb_info, msg);
708 /*LOGD("msg [%s]", msg);*/
710 if (!muse_recorder_msg_get(api, msg)) {
711 LOGE("failed to get recorder api");
715 if (api == MUSE_RECORDER_CB_EVENT) {
716 if (!muse_recorder_msg_get(event, msg) ||
717 !muse_recorder_msg_get(event_class, msg)) {
718 LOGE("failed to get event or event_class [%s]", msg);
722 if (!muse_recorder_msg_get(api_class, msg)) {
723 LOGE("failed to get api_class [%s]", msg);
728 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
729 if (api >= MUSE_RECORDER_API_MAX) {
730 LOGE("invalid api %d", api);
734 if (!muse_recorder_msg_get(ret, msg)) {
735 LOGE("failed to get recorder ret");
739 g_mutex_lock(&cb_info->api_mutex[api]);
741 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
742 g_atomic_int_set(&cb_info->msg_recv_running, 0);
743 LOGD("get device state done. close client cb handler");
746 case MUSE_RECORDER_API_CREATE:
747 if (ret != RECORDER_ERROR_NONE) {
748 g_atomic_int_set(&cb_info->msg_recv_running, 0);
749 LOGE("create error 0x%x. closing..", ret);
752 case MUSE_RECORDER_API_DESTROY:
753 if (ret == RECORDER_ERROR_NONE) {
754 g_atomic_int_set(&cb_info->msg_recv_running, 0);
755 LOGD("destroy done. closing..");
759 __recorder_get_api_operation(api, cb_info, msg);
764 if (cb_info->api_waiting[api] > 0) {
765 cb_info->api_ret[api] = ret;
766 cb_info->api_activating[api] = 1;
768 g_cond_signal(&cb_info->api_cond[api]);
770 LOGE("no waiting for api [%d]", api);
773 g_mutex_unlock(&cb_info->api_mutex[api]);
774 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
775 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
777 LOGW("unknown recorder api %d and api_class %d", api, api_class);
784 static void *_recorder_msg_handler_func(gpointer data)
788 recorder_message_s *rec_msg = NULL;
789 recorder_idle_event_s *rec_idle_event = NULL;
790 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
791 recorder_cb_info_s *cb_info = NULL;
793 if (!handler_info || !handler_info->cb_info) {
794 LOGE("NULL handler %p", handler_info);
798 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
799 type = handler_info->type;
801 LOGD("t:%d start", type);
803 g_mutex_lock(&handler_info->mutex);
805 while (g_atomic_int_get(&handler_info->running)) {
806 if (g_queue_is_empty(handler_info->queue)) {
807 /*LOGD("signal wait...");*/
808 g_cond_wait(&handler_info->cond, &handler_info->mutex);
809 /*LOGD("signal received");*/
811 if (g_atomic_int_get(&handler_info->running) == 0) {
812 LOGD("stop event thread");
817 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
818 g_mutex_unlock(&handler_info->mutex);
819 if (rec_msg == NULL) {
820 LOGE("NULL message");
821 g_mutex_lock(&handler_info->mutex);
827 if (api < MUSE_RECORDER_API_MAX) {
830 g_mutex_lock(&cb_info->api_mutex[api]);
832 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
833 if (cb_info->api_waiting[api] > 0) {
834 cb_info->api_ret[api] = ret;
835 cb_info->api_activating[api] = 1;
837 /*LOGD("recorder api %d - return 0x%x", ret);*/
839 g_cond_signal(&cb_info->api_cond[api]);
841 LOGE("no waiting for api [%d]", api);
844 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
847 g_mutex_unlock(&cb_info->api_mutex[api]);
848 } else if (api == MUSE_RECORDER_CB_EVENT) {
849 switch (rec_msg->event_class) {
850 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
851 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
853 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
854 rec_idle_event = g_new0(recorder_idle_event_s, 1);
855 if (rec_idle_event == NULL) {
856 LOGE("event alloc failed");
860 rec_idle_event->event = rec_msg->event;
861 rec_idle_event->cb_info = cb_info;
863 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
865 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
867 g_mutex_lock(&g_rec_idle_event_lock);
868 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
869 g_mutex_unlock(&g_rec_idle_event_lock);
871 g_idle_add_full(G_PRIORITY_DEFAULT,
872 (GSourceFunc)_recorder_idle_event_callback,
873 (gpointer)rec_idle_event,
877 LOGE("unknown event class %d", rec_msg->event_class);
881 LOGE("unknown api[%d] message", api);
887 g_mutex_lock(&handler_info->mutex);
890 /* remove remained event */
891 while (!g_queue_is_empty(handler_info->queue)) {
892 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
894 LOGD("remove message %p", rec_msg);
898 LOGW("NULL message");
902 g_mutex_unlock(&handler_info->mutex);
910 static void *_recorder_msg_recv_func(gpointer data)
913 int single_length = 0;
914 int remained_length = 0;
915 char *recv_msg = NULL;
916 char *single_msg = NULL;
917 char *remained_msg = NULL;
921 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
923 if (cb_info == NULL) {
924 LOGE("cb_info NULL");
930 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
931 if (single_msg == NULL) {
932 LOGE("single_msg malloc failed");
933 goto CB_HANDLER_EXIT;
936 recv_msg = cb_info->recv_msg;
938 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
939 recv_length = muse_core_msg_recv(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH);
940 if (recv_length <= 0) {
941 cb_info->is_server_connected = FALSE;
942 LOGE("receive msg failed - server disconnected");
946 recv_msg[recv_length] = '\0';
952 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
954 /* Need to split the combined entering msgs */
955 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
956 if (recv_msg[cur_pos] == '}') {
957 single_length = cur_pos - prev_pos + 1;
959 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
960 /* check remained msg */
961 if (remained_length > 0) {
963 strncpy(single_msg, remained_msg, remained_length);
964 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
965 single_msg[remained_length + single_length] = '\0';
970 strncpy(single_msg, recv_msg + prev_pos, single_length);
971 single_msg[single_length] = '\0';
972 LOGE("lost msg [%s], skip...", single_msg);
977 strncpy(single_msg, recv_msg + prev_pos, single_length);
978 single_msg[single_length] = '\0';
981 if (single_msg[0] == '{') {
983 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
984 __recorder_process_msg(cb_info, single_msg);
986 LOGE("invalid msg [%s]", single_msg);
989 LOGE("too long message [len %d] skip...", single_length);
992 prev_pos = cur_pos + 1;
996 /* check incompleted message */
997 if (recv_msg[recv_length - 1] != '}') {
998 remained_length = recv_length - prev_pos;
1000 LOGW("incompleted message [len %d]", remained_length);
1004 remained_msg = NULL;
1007 remained_msg = (char *)malloc(remained_length + 1);
1009 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
1010 remained_msg[remained_length] = '\0';
1012 LOGE("failed to alloc for remained msg");
1015 remained_length = 0;
1019 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1021 if (!cb_info->is_server_connected) {
1022 /* send error msg for server disconnection */
1023 char *error_msg = muse_core_msg_new(MUSE_RECORDER_CB_EVENT,
1024 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1025 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1029 LOGE("error_msg failed");
1030 goto CB_HANDLER_EXIT;
1033 LOGE("add error msg for service disconnection done");
1035 __recorder_add_msg_to_queue(cb_info,
1036 MUSE_RECORDER_CB_EVENT,
1037 MUSE_RECORDER_EVENT_TYPE_ERROR,
1038 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1041 muse_core_msg_free(error_msg);
1044 LOGE("add error msg for service disconnection done");
1055 remained_msg = NULL;
1062 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1063 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1065 if (!handler_info || !thread_name || !cb_info) {
1066 LOGE("t:%d NULL %p %p %p",
1067 type, handler_info, thread_name, cb_info);
1073 handler_info->type = type;
1074 handler_info->queue = g_queue_new();
1075 if (handler_info->queue == NULL) {
1076 LOGE("t:%d queue failed", type);
1080 g_mutex_init(&handler_info->mutex);
1081 g_cond_init(&handler_info->cond);
1083 handler_info->cb_info = (void *)cb_info;
1084 g_atomic_int_set(&handler_info->running, 1);
1086 handler_info->thread = g_thread_try_new(thread_name,
1087 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1088 if (handler_info->thread == NULL) {
1089 LOGE("t:%d thread failed", type);
1091 g_mutex_clear(&handler_info->mutex);
1092 g_cond_clear(&handler_info->cond);
1093 g_queue_free(handler_info->queue);
1094 handler_info->queue = NULL;
1099 LOGD("t:%d done", type);
1105 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1109 if (!handler_info) {
1110 LOGE("NULL handler");
1114 if (!handler_info->thread) {
1115 LOGW("thread is not created");
1119 type = handler_info->type;
1121 LOGD("t:%d thread %p", type, handler_info->thread);
1123 g_mutex_lock(&handler_info->mutex);
1124 g_atomic_int_set(&handler_info->running, 0);
1125 g_cond_signal(&handler_info->cond);
1126 g_mutex_unlock(&handler_info->mutex);
1128 g_thread_join(handler_info->thread);
1129 handler_info->thread = NULL;
1131 g_mutex_clear(&handler_info->mutex);
1132 g_cond_clear(&handler_info->cond);
1133 g_queue_free(handler_info->queue);
1134 handler_info->queue = NULL;
1136 LOGD("t:%d done", type);
1142 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1144 recorder_cb_info_s *cb_info = NULL;
1147 g_return_val_if_fail(sockfd > 0, NULL);
1149 cb_info = g_new0(recorder_cb_info_s, 1);
1150 if (cb_info == NULL) {
1151 LOGE("cb_info failed");
1155 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1157 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1158 g_mutex_init(&cb_info->api_mutex[i]);
1159 g_cond_init(&cb_info->api_cond[i]);
1162 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1163 g_mutex_init(&cb_info->user_cb_mutex[i]);
1165 /* message handler thread */
1166 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1167 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1168 LOGE("msg_handler_info failed");
1172 /* message handler thread for audio stream callback */
1173 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1174 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1175 LOGE("audio_stream_cb_info failed");
1179 /* message handler thread for muxed stream callback */
1180 if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
1181 _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
1182 LOGE("muxed_stream_cb_info failed");
1186 cb_info->fd = sockfd;
1188 /* message receive thread */
1189 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1190 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1191 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1192 if (cb_info->msg_recv_thread == NULL) {
1193 LOGE("message receive thread creation failed");
1197 cb_info->is_server_connected = TRUE;
1203 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1204 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1205 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1207 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1208 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1210 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1211 g_mutex_clear(&cb_info->api_mutex[i]);
1212 g_cond_clear(&cb_info->api_cond[i]);
1222 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1224 int ret = RECORDER_ERROR_NONE;
1227 /*LOGD("Enter api : %d", api);*/
1229 if (!cb_info->is_server_connected) {
1230 LOGE("server is disconnected");
1231 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1234 g_mutex_lock(&(cb_info->api_mutex[api]));
1236 if (cb_info->api_activating[api] == 0) {
1237 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1238 LOGW("wait for api %d", api);
1239 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1240 ret = cb_info->api_ret[api];
1241 cb_info->api_activating[api] = 0;
1242 LOGW("api %d returned 0x%x", api, ret);
1244 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1245 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1246 ret = cb_info->api_ret[api];
1247 cb_info->api_activating[api] = 0;
1248 /*LOGD("return value : 0x%x", ret);*/
1250 ret = RECORDER_ERROR_INVALID_OPERATION;
1251 LOGE("api %d was TIMED OUT!", api);
1255 ret = cb_info->api_ret[api];
1256 cb_info->api_activating[api] = 0;
1258 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1261 if (ret != RECORDER_ERROR_NONE)
1262 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1264 g_mutex_unlock(&(cb_info->api_mutex[api]));
1270 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
1275 if (!cb_info || !ret) {
1276 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1277 return RECORDER_ERROR_INVALID_PARAMETER;
1280 msg = muse_core_msg_new(api, NULL);
1282 LOGE("msg creation failed: api %d", api);
1283 return RECORDER_ERROR_OUT_OF_MEMORY;
1286 /*LOGD("send msg %s", msg);*/
1288 if (cb_info->is_server_connected) {
1289 __recorder_update_api_waiting(cb_info, api, 1);
1290 send_ret = muse_core_msg_send(cb_info->fd, msg);
1294 LOGE("message send failed");
1295 *ret = RECORDER_ERROR_INVALID_OPERATION;
1297 *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
1300 __recorder_update_api_waiting(cb_info, api, -1);
1302 muse_core_msg_free(msg);
1304 return RECORDER_ERROR_NONE;
1308 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1313 if (!cb_info || !ret || !param) {
1314 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1315 return RECORDER_ERROR_INVALID_PARAMETER;
1318 /*LOGD("type %d, name %s", param->type, param->name);*/
1320 switch (param->type) {
1322 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_INT, NULL);
1324 case MUSE_TYPE_DOUBLE:
1325 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1327 case MUSE_TYPE_STRING:
1328 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_STRING, NULL);
1331 LOGE("unknown type %d", param->type);
1336 LOGE("msg creation failed: api %d, type %d, param name %s",
1337 api, param->type, param->name);
1338 return RECORDER_ERROR_OUT_OF_MEMORY;
1341 /*LOGD("send msg %s", msg);*/
1343 if (cb_info->is_server_connected) {
1344 __recorder_update_api_waiting(cb_info, api, 1);
1346 send_ret = muse_core_msg_send(cb_info->fd, msg);
1350 LOGE("message send failed");
1351 *ret = RECORDER_ERROR_INVALID_OPERATION;
1353 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1356 __recorder_update_api_waiting(cb_info, api, -1);
1358 muse_core_msg_free(msg);
1360 return RECORDER_ERROR_NONE;
1364 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1368 g_return_if_fail(cb_info != NULL);
1370 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1372 g_thread_join(cb_info->msg_recv_thread);
1373 cb_info->msg_recv_thread = NULL;
1375 LOGD("msg_recv thread removed");
1377 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1378 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1379 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1381 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1382 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1384 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1385 g_mutex_clear(&cb_info->api_mutex[i]);
1386 g_cond_clear(&cb_info->api_cond[i]);
1389 if (cb_info->fd > -1) {
1390 muse_client_close(cb_info->fd);
1394 if (cb_info->bufmgr) {
1395 tbm_bufmgr_deinit(cb_info->bufmgr);
1396 cb_info->bufmgr = NULL;
1398 if (cb_info->get_filename) {
1399 free(cb_info->get_filename);
1400 cb_info->get_filename = NULL;
1410 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1412 char **root_directory = (char **)user_data;
1414 if (root_directory == NULL) {
1415 LOGE("user data is NULL");
1419 LOGD("storage id %d, type %d, state %d, path %s",
1420 storage_id, type, state, path ? path : "NULL");
1422 if (type == STORAGE_TYPE_INTERNAL && path) {
1423 if (*root_directory) {
1424 free(*root_directory);
1425 *root_directory = NULL;
1428 *root_directory = strdup(path);
1429 if (*root_directory) {
1430 LOGD("get root directory %s", *root_directory);
1433 LOGE("strdup %s failed", path);
1440 static int _recorder_client_get_root_directory(char **root_directory)
1442 int ret = STORAGE_ERROR_NONE;
1444 if (root_directory == NULL) {
1445 LOGE("user data is NULL");
1449 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1450 if (ret != STORAGE_ERROR_NONE) {
1451 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1458 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1460 int ret = RECORDER_ERROR_NONE;
1461 int destroy_ret = RECORDER_ERROR_NONE;
1463 int module_index = -1;
1465 char *send_msg = NULL;
1466 char *root_directory = NULL;
1467 intptr_t camera_handle = 0;
1468 intptr_t handle = 0;
1469 tbm_bufmgr bufmgr = NULL;
1470 recorder_cli_s *pc = NULL;
1471 recorder_msg_param param;
1473 LOGD("Enter - type %d", type);
1475 if (recorder == NULL) {
1476 LOGE("NULL pointer for recorder handle");
1477 return RECORDER_ERROR_INVALID_PARAMETER;
1480 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1481 LOGE("NULL pointer for camera handle on video recorder mode");
1482 return RECORDER_ERROR_INVALID_PARAMETER;
1485 bufmgr = tbm_bufmgr_init(-1);
1486 if (bufmgr == NULL) {
1487 LOGE("get tbm bufmgr failed");
1488 return RECORDER_ERROR_INVALID_OPERATION;
1491 pc = g_new0(recorder_cli_s, 1);
1493 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1494 goto _ERR_RECORDER_EXIT;
1497 sock_fd = muse_client_new();
1499 LOGE("muse_client_new failed - returned fd %d", sock_fd);
1500 ret = RECORDER_ERROR_INVALID_OPERATION;
1501 goto _ERR_RECORDER_EXIT;
1504 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
1505 LOGE("muse client get module index failed");
1506 ret = RECORDER_ERROR_INVALID_OPERATION;
1507 goto _ERR_RECORDER_EXIT;
1510 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1511 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1512 MUSE_TYPE_INT, "module", module_index,
1513 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1514 MUSE_TYPE_INT, "pid", getpid(),
1517 pc->camera = camera;
1518 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1519 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1520 MUSE_TYPE_INT, "module", module_index,
1521 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1522 MUSE_TYPE_INT, "pid", getpid(),
1523 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1529 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1530 goto _ERR_RECORDER_EXIT;
1533 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1535 send_ret = muse_core_msg_send(sock_fd, send_msg);
1537 muse_core_msg_free(send_msg);
1541 LOGE("send msg failed %d", errno);
1542 ret = RECORDER_ERROR_INVALID_OPERATION;
1543 goto _ERR_RECORDER_EXIT;
1546 pc->cb_info = _recorder_client_callback_new(sock_fd);
1547 if (pc->cb_info == NULL) {
1548 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1549 goto _ERR_RECORDER_EXIT;
1554 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1556 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1558 if (ret != RECORDER_ERROR_NONE) {
1559 LOGE("API_CREATE failed 0x%x", ret);
1560 goto _ERR_RECORDER_EXIT;
1563 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1565 LOGE("Receiving Handle Failed!!");
1566 ret = RECORDER_ERROR_INVALID_OPERATION;
1567 goto _ERR_RECORDER_AFTER_CREATE;
1570 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1571 LOGE("failed to get root directory of internal storage");
1572 ret = RECORDER_ERROR_INVALID_OPERATION;
1573 goto _ERR_RECORDER_AFTER_CREATE;
1576 LOGD("root directory [%s]", root_directory);
1578 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1580 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1582 if (ret != RECORDER_ERROR_NONE) {
1583 LOGE("failed to set root directory %s", root_directory);
1584 ret = RECORDER_ERROR_INVALID_OPERATION;
1585 goto _ERR_RECORDER_AFTER_CREATE;
1588 free(root_directory);
1589 root_directory = NULL;
1591 pc->remote_handle = handle;
1592 pc->cb_info->bufmgr = bufmgr;
1594 LOGD("recorder[type %d] %p create success : remote handle 0x%td",
1595 type, pc, pc->remote_handle);
1597 *recorder = (recorder_h)pc;
1601 return RECORDER_ERROR_NONE;
1603 _ERR_RECORDER_AFTER_CREATE:
1604 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
1605 LOGE("destroy return 0x%x", destroy_ret);
1608 tbm_bufmgr_deinit(bufmgr);
1611 if (root_directory) {
1612 free(root_directory);
1613 root_directory = NULL;
1617 muse_client_close(sock_fd);
1623 _recorder_client_callback_destroy(pc->cb_info);
1634 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1636 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1640 int recorder_create_audiorecorder(recorder_h *recorder)
1642 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1646 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1648 int ret = RECORDER_ERROR_NONE;
1649 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1650 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1652 if (!pc || !pc->cb_info) {
1653 LOGE("NULL handle");
1654 return RECORDER_ERROR_INVALID_PARAMETER;
1657 if (state == NULL) {
1658 LOGE("NULL pointer state");
1659 return RECORDER_ERROR_INVALID_PARAMETER;
1662 LOGD("Enter, remote_handle : %td", pc->remote_handle);
1664 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1666 if (ret == RECORDER_ERROR_NONE)
1667 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1669 LOGD("ret : 0x%x, state : %d", ret, *state);
1675 int recorder_destroy(recorder_h recorder)
1677 int ret = RECORDER_ERROR_NONE;
1678 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1679 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1681 if (!pc || !pc->cb_info) {
1682 LOGE("NULL handle");
1683 return RECORDER_ERROR_INVALID_PARAMETER;
1688 if (pc->cb_info->is_server_connected)
1689 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1691 LOGW("server disconnected. release resource without send message.");
1693 if (ret == RECORDER_ERROR_NONE) {
1694 _recorder_deactivate_idle_event_all(pc->cb_info);
1695 _recorder_client_callback_destroy(pc->cb_info);
1700 LOGD("ret : 0x%x", ret);
1706 int recorder_prepare(recorder_h recorder)
1708 int ret = RECORDER_ERROR_NONE;
1709 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1710 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1712 if (!pc || !pc->cb_info) {
1713 LOGE("NULL handle");
1714 return RECORDER_ERROR_INVALID_PARAMETER;
1719 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1721 LOGD("ret : 0x%x", ret);
1723 if (ret == RECORDER_ERROR_NONE && pc->camera)
1724 camera_start_evas_rendering(pc->camera);
1730 int recorder_unprepare(recorder_h recorder)
1732 int ret = RECORDER_ERROR_NONE;
1733 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1734 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1735 camera_state_e camera_state = CAMERA_STATE_NONE;
1737 if (!pc || !pc->cb_info) {
1738 LOGE("NULL handle");
1739 return RECORDER_ERROR_INVALID_PARAMETER;
1745 ret = camera_get_state(pc->camera, &camera_state);
1746 if (ret != CAMERA_ERROR_NONE) {
1747 LOGE("failed to get camera state 0x%x", ret);
1748 return RECORDER_ERROR_INVALID_OPERATION;
1751 if (camera_state == CAMERA_STATE_PREVIEW) {
1752 ret = camera_stop_evas_rendering(pc->camera, false);
1753 if (ret != CAMERA_ERROR_NONE) {
1754 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1755 return RECORDER_ERROR_INVALID_OPERATION;
1760 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1762 LOGD("ret : 0x%x", ret);
1768 int recorder_start(recorder_h recorder)
1770 int ret = RECORDER_ERROR_NONE;
1771 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1772 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1773 recorder_state_e current_state = RECORDER_STATE_NONE;
1775 if (!pc || !pc->cb_info) {
1776 LOGE("NULL handle");
1777 return RECORDER_ERROR_INVALID_PARAMETER;
1783 ret = recorder_get_state(recorder, ¤t_state);
1784 if (ret != RECORDER_ERROR_NONE) {
1785 LOGE("failed to get current state 0x%x", ret);
1786 return RECORDER_ERROR_INVALID_OPERATION;
1789 if (current_state == RECORDER_STATE_READY) {
1790 ret = camera_stop_evas_rendering(pc->camera, true);
1791 if (ret != CAMERA_ERROR_NONE) {
1792 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1793 return RECORDER_ERROR_INVALID_OPERATION;
1798 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
1800 if (pc->camera && current_state == RECORDER_STATE_READY)
1801 camera_start_evas_rendering(pc->camera);
1803 LOGD("ret : 0x%x", ret);
1809 int recorder_pause(recorder_h recorder)
1811 int ret = RECORDER_ERROR_NONE;
1812 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1813 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1815 if (!pc || !pc->cb_info) {
1816 LOGE("NULL handle");
1817 return RECORDER_ERROR_INVALID_PARAMETER;
1822 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1824 LOGD("ret : 0x%x", ret);
1830 int recorder_commit(recorder_h recorder)
1832 int ret = RECORDER_ERROR_NONE;
1833 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1834 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1835 recorder_state_e current_state = RECORDER_STATE_NONE;
1837 if (!pc || !pc->cb_info) {
1838 LOGE("NULL handle");
1839 return RECORDER_ERROR_INVALID_PARAMETER;
1845 ret = recorder_get_state(recorder, ¤t_state);
1846 if (ret != RECORDER_ERROR_NONE) {
1847 LOGE("failed to get current state 0x%x", ret);
1848 return RECORDER_ERROR_INVALID_OPERATION;
1851 if (current_state >= RECORDER_STATE_RECORDING) {
1852 ret = camera_stop_evas_rendering(pc->camera, true);
1853 if (ret != CAMERA_ERROR_NONE) {
1854 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1855 return RECORDER_ERROR_INVALID_OPERATION;
1860 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1862 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1863 camera_start_evas_rendering(pc->camera);
1865 LOGD("ret : 0x%x", ret);
1871 int recorder_cancel(recorder_h recorder)
1873 int ret = RECORDER_ERROR_NONE;
1874 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1875 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1876 recorder_state_e current_state = RECORDER_STATE_NONE;
1878 if (!pc || !pc->cb_info) {
1879 LOGE("NULL handle");
1880 return RECORDER_ERROR_INVALID_PARAMETER;
1886 ret = recorder_get_state(recorder, ¤t_state);
1887 if (ret != RECORDER_ERROR_NONE) {
1888 LOGE("failed to get current state 0x%x", ret);
1889 return RECORDER_ERROR_INVALID_OPERATION;
1892 if (current_state >= RECORDER_STATE_RECORDING) {
1893 ret = camera_stop_evas_rendering(pc->camera, true);
1894 if (ret != CAMERA_ERROR_NONE) {
1895 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1896 return RECORDER_ERROR_INVALID_OPERATION;
1901 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1903 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1904 camera_start_evas_rendering(pc->camera);
1906 LOGD("ret : 0x%x", ret);
1912 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1914 int ret = RECORDER_ERROR_NONE;
1916 char *send_msg = NULL;
1917 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1918 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1920 if (!pc || !pc->cb_info) {
1921 LOGE("NULL handle");
1922 return RECORDER_ERROR_INVALID_PARAMETER;
1927 send_msg = muse_core_msg_new(api,
1928 MUSE_TYPE_INT, "width", width,
1929 MUSE_TYPE_INT, "height", height,
1932 if (pc->cb_info->is_server_connected) {
1933 __recorder_update_api_waiting(pc->cb_info, api, 1);
1935 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
1939 LOGE("message send failed");
1940 ret = RECORDER_ERROR_INVALID_OPERATION;
1942 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1945 __recorder_update_api_waiting(pc->cb_info, api, -1);
1947 muse_core_msg_free(send_msg);
1949 LOGE("failed to create msg");
1950 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1953 LOGD("ret : 0x%x", ret);
1959 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1961 int ret = RECORDER_ERROR_NONE;
1962 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1963 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1965 if (!pc || !pc->cb_info) {
1966 LOGE("NULL handle");
1967 return RECORDER_ERROR_INVALID_PARAMETER;
1970 if (!width || !height) {
1971 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1972 return RECORDER_ERROR_INVALID_PARAMETER;
1977 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1979 if (ret == RECORDER_ERROR_NONE) {
1980 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1981 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1984 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1990 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1991 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1993 int ret = RECORDER_ERROR_NONE;
1994 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1995 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1997 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1998 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1999 return RECORDER_ERROR_INVALID_PARAMETER;
2002 LOGD("Enter, handle :%td", pc->remote_handle);
2004 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2005 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2007 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2009 LOGD("ret : 0x%x", ret);
2015 int recorder_get_audio_level(recorder_h recorder, double *level)
2017 int ret = RECORDER_ERROR_NONE;
2018 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2019 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2021 if (!pc || !pc->cb_info || level == NULL) {
2022 LOGE("NULL pointer %p %p", pc, level);
2023 return RECORDER_ERROR_INVALID_PARAMETER;
2028 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2030 if (ret == RECORDER_ERROR_NONE)
2031 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2033 LOGD("ret : 0x%x, level %lf", ret, *level);
2039 int recorder_set_filename(recorder_h recorder, const char *filename)
2041 int ret = RECORDER_ERROR_NONE;
2043 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2044 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2045 recorder_msg_param param;
2046 char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2048 if (!pc || !pc->cb_info) {
2049 LOGE("NULL handle");
2050 return RECORDER_ERROR_INVALID_PARAMETER;
2053 if (filename == NULL) {
2054 LOGE("filename is NULL");
2055 return RECORDER_ERROR_INVALID_PARAMETER;
2058 LOGD("ENTER [%s]", filename);
2060 length = strlen(filename);
2062 if (length >= RECORDER_FILENAME_MAX - 1) {
2063 LOGE("too long file name [%zu]", length);
2064 return RECORDER_ERROR_INVALID_PARAMETER;
2067 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2068 /* Cannot convert. Use original path. */
2069 strncpy(set_filename, filename, length + 1);
2070 pc->cb_info->is_filename_converted = FALSE;
2072 /* Converted. Use converted path. */
2073 LOGD("Converted filename : %s -> %s", filename, set_filename);
2074 pc->cb_info->is_filename_converted = TRUE;
2077 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2079 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2081 LOGD("ret : 0x%x", ret);
2087 int recorder_get_filename(recorder_h recorder, char **filename)
2089 int ret = RECORDER_ERROR_NONE;
2090 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2091 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2092 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2094 if (!pc || !pc->cb_info) {
2095 LOGE("NULL handle");
2096 return RECORDER_ERROR_INVALID_PARAMETER;
2099 if (filename == NULL) {
2100 LOGE("filename is NULL");
2101 return RECORDER_ERROR_INVALID_PARAMETER;
2106 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2108 if (ret == RECORDER_ERROR_NONE) {
2109 if (pc->cb_info->is_filename_converted == FALSE ||
2110 storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2111 /* Use original path. */
2112 *filename = pc->cb_info->get_filename;
2114 /* Converted. Use converted path. */
2115 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2116 *filename = strdup(compat_filename);
2117 free(pc->cb_info->get_filename);
2120 pc->cb_info->get_filename = NULL;
2123 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2129 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2131 int ret = RECORDER_ERROR_NONE;
2132 int set_format = (int)format;
2133 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2134 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2135 recorder_msg_param param;
2137 if (!pc || !pc->cb_info) {
2138 LOGE("NULL handle");
2139 return RECORDER_ERROR_INVALID_PARAMETER;
2142 LOGD("ENTER, set_format : %d", set_format);
2144 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2146 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2148 LOGD("ret : 0x%x", ret);
2153 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2155 int ret = RECORDER_ERROR_NONE;
2156 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2157 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2159 if (!pc || !pc->cb_info) {
2160 LOGE("NULL handle");
2161 return RECORDER_ERROR_INVALID_PARAMETER;
2164 if (format == NULL) {
2165 LOGE("NULL pointer data");
2166 return RECORDER_ERROR_INVALID_PARAMETER;
2171 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2173 if (ret == RECORDER_ERROR_NONE)
2174 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2176 LOGD("ret : 0x%x, format %d", ret, *format);
2182 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2184 int ret = RECORDER_ERROR_NONE;
2185 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2186 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2187 bool is_available = false;
2188 int stream_index = 0;
2189 char *stream_type = NULL;
2190 char *send_msg = NULL;
2193 if (!pc || !pc->cb_info || stream_info == NULL) {
2194 LOGE("NULL handle");
2195 return RECORDER_ERROR_INVALID_PARAMETER;
2200 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2201 if (ret != SOUND_MANAGER_ERROR_NONE) {
2202 LOGE("stream info verification failed");
2203 return RECORDER_ERROR_INVALID_OPERATION;
2206 if (is_available == false) {
2207 LOGE("stream information is not available");
2208 return RECORDER_ERROR_INVALID_OPERATION;
2211 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2212 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2214 LOGD("sound manager return [0x%x]", ret);
2216 if (ret == SOUND_MANAGER_ERROR_NONE) {
2217 send_msg = muse_core_msg_new(api,
2218 MUSE_TYPE_STRING, "stream_type", stream_type,
2219 MUSE_TYPE_INT, "stream_index", stream_index,
2222 if (pc->cb_info->is_server_connected) {
2223 __recorder_update_api_waiting(pc->cb_info, api, 1);
2225 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
2229 LOGE("message send failed");
2230 ret = RECORDER_ERROR_INVALID_OPERATION;
2232 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2235 __recorder_update_api_waiting(pc->cb_info, api, -1);
2237 muse_core_msg_free(send_msg);
2239 LOGE("failed to create msg");
2240 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2243 ret = RECORDER_ERROR_INVALID_OPERATION;
2250 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2252 int ret = RECORDER_ERROR_NONE;
2253 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2254 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2256 if (!pc || !pc->cb_info || callback == NULL) {
2257 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2258 return RECORDER_ERROR_INVALID_PARAMETER;
2261 LOGD("Enter, handle :%td", pc->remote_handle);
2263 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2265 if (ret == RECORDER_ERROR_NONE) {
2266 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2268 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2269 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2271 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2274 LOGD("ret : 0x%x", ret);
2280 int recorder_unset_state_changed_cb(recorder_h recorder)
2282 int ret = RECORDER_ERROR_NONE;
2283 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2284 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2286 if (!pc || !pc->cb_info) {
2287 LOGE("NULL handle");
2288 return RECORDER_ERROR_INVALID_PARAMETER;
2293 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2295 if (ret == RECORDER_ERROR_NONE) {
2296 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2298 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2299 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2301 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2304 LOGD("ret : 0x%x", ret);
2310 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2312 int ret = RECORDER_ERROR_NONE;
2313 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2314 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2316 if (!pc || !pc->cb_info || callback == NULL) {
2317 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2318 return RECORDER_ERROR_INVALID_PARAMETER;
2321 LOGD("Enter, handle :%td", pc->remote_handle);
2323 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2325 if (ret == RECORDER_ERROR_NONE) {
2326 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2328 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2329 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2331 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2334 LOGD("ret : 0x%x", ret);
2340 int recorder_unset_interrupted_cb(recorder_h recorder)
2342 int ret = RECORDER_ERROR_NONE;
2343 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2344 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2346 if (!pc || !pc->cb_info) {
2347 LOGE("NULL handle");
2348 return RECORDER_ERROR_INVALID_PARAMETER;
2353 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2355 if (ret == RECORDER_ERROR_NONE) {
2356 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2358 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2359 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2361 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2364 LOGD("ret : 0x%x", ret);
2370 int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
2372 int ret = RECORDER_ERROR_NONE;
2373 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2374 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
2376 if (!pc || !pc->cb_info || callback == NULL) {
2377 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2378 return RECORDER_ERROR_INVALID_PARAMETER;
2381 LOGD("Enter, handle :%td", pc->remote_handle);
2383 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2385 if (ret == RECORDER_ERROR_NONE) {
2386 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2388 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
2389 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
2391 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2394 LOGD("ret : 0x%x", ret);
2400 int recorder_unset_interrupt_started_cb(recorder_h recorder)
2402 int ret = RECORDER_ERROR_NONE;
2403 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
2404 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2406 if (!pc || !pc->cb_info) {
2407 LOGE("NULL handle");
2408 return RECORDER_ERROR_INVALID_PARAMETER;
2413 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2415 if (ret == RECORDER_ERROR_NONE) {
2416 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2418 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2419 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2421 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2424 LOGD("ret : 0x%x", ret);
2430 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2432 int ret = RECORDER_ERROR_NONE;
2433 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2434 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2436 if (!pc || !pc->cb_info || callback == NULL) {
2437 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2438 return RECORDER_ERROR_INVALID_PARAMETER;
2441 LOGD("Enter, handle :%td", pc->remote_handle);
2443 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2445 if (ret == RECORDER_ERROR_NONE) {
2446 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2448 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2449 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2451 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2454 LOGD("ret : 0x%x", ret);
2460 int recorder_unset_audio_stream_cb(recorder_h recorder)
2462 int ret = RECORDER_ERROR_NONE;
2463 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2464 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2466 if (!pc || !pc->cb_info) {
2467 LOGE("NULL handle");
2468 return RECORDER_ERROR_INVALID_PARAMETER;
2473 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2475 if (ret == RECORDER_ERROR_NONE) {
2476 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2478 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2479 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2481 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2484 LOGD("ret : 0x%x", ret);
2490 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2492 int ret = RECORDER_ERROR_NONE;
2493 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2494 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2496 if (!pc || !pc->cb_info || !callback) {
2497 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2498 return RECORDER_ERROR_INVALID_PARAMETER;
2501 LOGD("Enter, handle :%td", pc->remote_handle);
2503 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2505 if (ret == RECORDER_ERROR_NONE) {
2506 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2508 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2509 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2511 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2514 LOGD("ret : 0x%x", ret);
2520 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2522 int ret = RECORDER_ERROR_NONE;
2523 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2524 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2526 if (!pc || !pc->cb_info) {
2527 LOGE("NULL handle");
2528 return RECORDER_ERROR_INVALID_PARAMETER;
2533 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2535 if (ret == RECORDER_ERROR_NONE) {
2536 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2538 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2539 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2541 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2544 LOGD("ret : 0x%x", ret);
2550 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2552 int ret = RECORDER_ERROR_NONE;
2553 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2554 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2556 if (!pc || !pc->cb_info || callback == NULL) {
2557 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2558 return RECORDER_ERROR_INVALID_PARAMETER;
2561 LOGD("Enter, handle :%td", pc->remote_handle);
2563 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2565 if (ret == RECORDER_ERROR_NONE) {
2566 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2568 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2569 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2571 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2574 LOGD("ret : 0x%x", ret);
2580 int recorder_unset_error_cb(recorder_h recorder)
2582 int ret = RECORDER_ERROR_NONE;
2583 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2584 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2586 if (!pc || !pc->cb_info) {
2587 LOGE("NULL handle");
2588 return RECORDER_ERROR_INVALID_PARAMETER;
2593 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2595 if (ret == RECORDER_ERROR_NONE) {
2596 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2598 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2599 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2601 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2604 LOGD("ret : 0x%x", ret);
2610 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2612 int ret = RECORDER_ERROR_NONE;
2613 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2614 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2616 if (!pc || !pc->cb_info || callback == NULL) {
2617 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2618 return RECORDER_ERROR_INVALID_PARAMETER;
2621 LOGD("Enter, handle :%td", pc->remote_handle);
2623 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2625 if (ret == RECORDER_ERROR_NONE) {
2626 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2628 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2629 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2631 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2634 LOGD("ret : 0x%x", ret);
2640 int recorder_unset_recording_status_cb(recorder_h recorder)
2642 int ret = RECORDER_ERROR_NONE;
2643 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2644 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2646 if (!pc || !pc->cb_info) {
2647 LOGE("NULL handle");
2648 return RECORDER_ERROR_INVALID_PARAMETER;
2653 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2655 if (ret == RECORDER_ERROR_NONE) {
2656 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2658 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2659 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2661 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2664 LOGD("ret : 0x%x", ret);
2670 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2672 int ret = RECORDER_ERROR_NONE;
2673 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2674 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2676 if (!pc || !pc->cb_info || callback == NULL) {
2677 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2678 return RECORDER_ERROR_INVALID_PARAMETER;
2681 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2683 if (ret == RECORDER_ERROR_NONE) {
2684 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2686 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2687 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2689 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2692 LOGD("ret : 0x%x", ret);
2698 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2700 int ret = RECORDER_ERROR_NONE;
2701 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2702 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2704 if (!pc || !pc->cb_info) {
2705 LOGE("NULL handle");
2706 return RECORDER_ERROR_INVALID_PARAMETER;
2711 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2713 if (ret == RECORDER_ERROR_NONE) {
2714 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2716 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2717 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2719 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2722 LOGD("ret : 0x%x", ret);
2728 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2730 int ret = RECORDER_ERROR_NONE;
2731 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2732 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2734 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2735 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2736 return RECORDER_ERROR_INVALID_PARAMETER;
2739 LOGD("Enter, handle :%td", pc->remote_handle);
2741 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2742 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2744 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2746 LOGD("ret : 0x%x", ret);
2752 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2754 int ret = RECORDER_ERROR_NONE;
2755 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2756 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2757 recorder_msg_param param;
2759 if (!pc || !pc->cb_info) {
2760 LOGE("NULL handle");
2761 return RECORDER_ERROR_INVALID_PARAMETER;
2766 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2768 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2770 LOGD("ret : 0x%x", ret);
2776 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2778 int ret = RECORDER_ERROR_NONE;
2779 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2780 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2781 recorder_msg_param param;
2783 if (!pc || !pc->cb_info) {
2784 LOGE("NULL handle");
2785 return RECORDER_ERROR_INVALID_PARAMETER;
2790 RECORDER_MSG_PARAM_SET(param, INT, second);
2792 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2794 LOGD("ret : 0x%x", ret);
2800 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2802 int ret = RECORDER_ERROR_NONE;
2803 int set_device = (int)device;
2804 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2805 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2806 recorder_msg_param param;
2808 if (!pc || !pc->cb_info) {
2809 LOGE("NULL handle");
2810 return RECORDER_ERROR_INVALID_PARAMETER;
2815 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2817 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2819 LOGD("ret : 0x%x", ret);
2825 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2827 int ret = RECORDER_ERROR_NONE;
2828 int set_codec = (int)codec;
2829 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2830 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2831 recorder_msg_param param;
2833 if (!pc || !pc->cb_info) {
2834 LOGE("NULL handle");
2835 return RECORDER_ERROR_INVALID_PARAMETER;
2840 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2842 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2844 LOGD("ret : 0x%x", ret);
2850 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2852 int ret = RECORDER_ERROR_NONE;
2853 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2854 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2856 if (!pc || !pc->cb_info) {
2857 LOGE("NULL handle");
2858 return RECORDER_ERROR_INVALID_PARAMETER;
2861 if (codec == NULL) {
2862 LOGE("codec is NULL");
2863 return RECORDER_ERROR_INVALID_PARAMETER;
2868 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2870 if (ret == RECORDER_ERROR_NONE)
2871 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2873 LOGD("ret : 0x%x, codec %d", ret, *codec);
2879 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2881 int ret = RECORDER_ERROR_NONE;
2882 int set_codec = (int)codec;
2883 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2884 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2885 recorder_msg_param param;
2887 if (!pc || !pc->cb_info) {
2888 LOGE("NULL handle");
2889 return RECORDER_ERROR_INVALID_PARAMETER;
2894 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2896 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2898 LOGD("ret : 0x%x", ret);
2904 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2906 int ret = RECORDER_ERROR_NONE;
2907 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2908 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2910 if (!pc || !pc->cb_info) {
2911 LOGE("NULL handle");
2912 return RECORDER_ERROR_INVALID_PARAMETER;
2915 if (codec == NULL) {
2916 LOGE("codec is NULL");
2917 return RECORDER_ERROR_INVALID_PARAMETER;
2922 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2924 if (ret == RECORDER_ERROR_NONE)
2925 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2927 LOGD("ret : 0x%x, codec %d", ret, *codec);
2933 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2935 int ret = RECORDER_ERROR_NONE;
2936 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2937 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2938 recorder_msg_param param;
2940 if (!pc || !pc->cb_info) {
2941 LOGE("NULL handle");
2942 return RECORDER_ERROR_INVALID_PARAMETER;
2945 LOGD("ENTER, samplerate : %d", samplerate);
2947 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2949 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2951 LOGD("ret : 0x%x", ret);
2957 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2959 int ret = RECORDER_ERROR_NONE;
2960 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2961 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2962 recorder_msg_param param;
2964 if (!pc || !pc->cb_info) {
2965 LOGE("NULL handle");
2966 return RECORDER_ERROR_INVALID_PARAMETER;
2971 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2973 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2975 LOGD("ret : 0x%x", ret);
2981 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2983 int ret = RECORDER_ERROR_NONE;
2984 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2985 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2986 recorder_msg_param param;
2988 if (!pc || !pc->cb_info) {
2989 LOGE("NULL handle");
2990 return RECORDER_ERROR_INVALID_PARAMETER;
2995 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2997 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2999 LOGD("ret : 0x%x", ret);
3005 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
3007 int ret = RECORDER_ERROR_NONE;
3008 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
3009 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3011 if (!pc || !pc->cb_info) {
3012 LOGE("NULL handle");
3013 return RECORDER_ERROR_INVALID_PARAMETER;
3016 if (kbyte == NULL) {
3017 LOGE("NULL pointer kbyte");
3018 return RECORDER_ERROR_INVALID_PARAMETER;
3023 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3025 if (ret == RECORDER_ERROR_NONE)
3026 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
3028 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
3034 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
3036 int ret = RECORDER_ERROR_NONE;
3037 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
3038 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3040 if (!pc || !pc->cb_info) {
3041 LOGE("NULL handle");
3042 return RECORDER_ERROR_INVALID_PARAMETER;
3045 if (second == NULL) {
3046 LOGE("NULL pointer second");
3047 return RECORDER_ERROR_INVALID_PARAMETER;
3052 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3054 if (ret == RECORDER_ERROR_NONE)
3055 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
3057 LOGD("ret : 0x%x, %d second", ret, *second);
3063 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
3065 int ret = RECORDER_ERROR_NONE;
3066 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
3067 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3069 if (!pc || !pc->cb_info) {
3070 LOGE("NULL handle");
3071 return RECORDER_ERROR_INVALID_PARAMETER;
3074 if (device == NULL) {
3075 LOGE("NULL pointer device");
3076 return RECORDER_ERROR_INVALID_PARAMETER;
3081 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3083 if (ret == RECORDER_ERROR_NONE)
3084 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
3086 LOGD("ret : 0x%x, device %d", ret, *device);
3092 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
3094 int ret = RECORDER_ERROR_NONE;
3095 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
3096 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3098 if (!pc || !pc->cb_info) {
3099 LOGE("NULL handle");
3100 return RECORDER_ERROR_INVALID_PARAMETER;
3103 if (samplerate == NULL) {
3104 LOGE("NULL pointer handle");
3105 return RECORDER_ERROR_INVALID_PARAMETER;
3110 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3112 if (ret == RECORDER_ERROR_NONE)
3113 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3115 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3121 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3123 int ret = RECORDER_ERROR_NONE;
3124 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3125 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3127 if (!pc || !pc->cb_info) {
3128 LOGE("NULL handle");
3129 return RECORDER_ERROR_INVALID_PARAMETER;
3132 if (bitrate == NULL) {
3133 LOGE("NULL pointer");
3134 return RECORDER_ERROR_INVALID_PARAMETER;
3139 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3141 if (ret == RECORDER_ERROR_NONE)
3142 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3144 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3150 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3152 int ret = RECORDER_ERROR_NONE;
3153 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3154 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3156 if (!pc || !pc->cb_info) {
3157 LOGE("NULL handle");
3158 return RECORDER_ERROR_INVALID_PARAMETER;
3161 if (bitrate == NULL) {
3162 LOGE("NULL pointer");
3163 return RECORDER_ERROR_INVALID_PARAMETER;
3168 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3170 if (ret == RECORDER_ERROR_NONE)
3171 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3173 LOGD("ret : 0x%x", ret);
3179 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3181 int ret = RECORDER_ERROR_NONE;
3182 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3183 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3185 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3186 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3187 return RECORDER_ERROR_INVALID_PARAMETER;
3190 LOGD("Enter, handle :%td", pc->remote_handle);
3192 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3193 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3195 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3197 LOGD("ret : 0x%x", ret);
3203 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3205 int ret = RECORDER_ERROR_NONE;
3206 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3207 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3209 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3210 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3211 return RECORDER_ERROR_INVALID_PARAMETER;
3214 LOGD("Enter, handle :%td", pc->remote_handle);
3216 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3217 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3219 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3221 LOGD("ret : 0x%x", ret);
3227 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3229 int ret = RECORDER_ERROR_NONE;
3230 int set_enable = (int)enable;
3231 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3232 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3233 recorder_msg_param param;
3235 if (!pc || !pc->cb_info) {
3236 LOGE("NULL handle");
3237 return RECORDER_ERROR_INVALID_PARAMETER;
3242 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3244 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3246 LOGD("ret : 0x%x", ret);
3252 bool recorder_attr_is_muted(recorder_h recorder)
3255 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3256 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3258 if (!pc || !pc->cb_info) {
3259 LOGE("NULL handle");
3265 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3267 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3270 LOGD("ret : %d", ret);
3276 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3278 int ret = RECORDER_ERROR_NONE;
3279 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3280 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3281 recorder_msg_param param;
3283 if (!pc || !pc->cb_info) {
3284 LOGE("NULL handle");
3285 return RECORDER_ERROR_INVALID_PARAMETER;
3288 LOGD("ENTER - %.20lf", rate);
3290 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3292 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3294 LOGD("ret : 0x%x", ret);
3300 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3302 int ret = RECORDER_ERROR_NONE;
3303 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3304 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3306 if (!pc || !pc->cb_info) {
3307 LOGE("NULL handle");
3308 return RECORDER_ERROR_INVALID_PARAMETER;
3312 LOGE("rate is NULL");
3313 return RECORDER_ERROR_INVALID_PARAMETER;
3318 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3319 if (ret == RECORDER_ERROR_NONE)
3320 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3322 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3328 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3330 int ret = RECORDER_ERROR_NONE;
3331 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3332 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3333 recorder_msg_param param;
3335 if (!pc || !pc->cb_info) {
3336 LOGE("NULL handle");
3337 return RECORDER_ERROR_INVALID_PARAMETER;
3342 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3344 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3346 LOGD("ret : 0x%x", ret);
3352 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3354 int ret = RECORDER_ERROR_NONE;
3355 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3356 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3358 if (!pc || !pc->cb_info) {
3359 LOGE("NULL handle");
3360 return RECORDER_ERROR_INVALID_PARAMETER;
3363 if (channel_count == NULL) {
3364 LOGE("channel_count is NULL");
3365 return RECORDER_ERROR_INVALID_PARAMETER;
3370 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3372 if (ret == RECORDER_ERROR_NONE)
3373 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3375 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3381 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3383 int ret = RECORDER_ERROR_NONE;
3384 int set_orientation = (int)orientation;
3385 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3386 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3387 recorder_msg_param param;
3389 if (!pc || !pc->cb_info) {
3390 LOGE("NULL handle");
3391 return RECORDER_ERROR_INVALID_PARAMETER;
3396 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3398 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3400 LOGD("ret : 0x%x", ret);
3406 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3408 int ret = RECORDER_ERROR_NONE;
3409 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3410 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3412 if (!pc || !pc->cb_info) {
3413 LOGE("NULL handle");
3414 return RECORDER_ERROR_INVALID_PARAMETER;
3417 if (orientation == NULL) {
3418 LOGE("orientation is NULL");
3419 return RECORDER_ERROR_INVALID_PARAMETER;
3424 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3426 if (ret == RECORDER_ERROR_NONE)
3427 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3429 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3435 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3437 int ret = RECORDER_ERROR_NONE;
3439 int module_index = -1;
3440 int get_device_state = 0;
3441 char *send_msg = NULL;
3442 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3445 LOGE("NULL pointer");
3446 return RECORDER_ERROR_INVALID_PARAMETER;
3449 LOGD("Enter - type %d", type);
3451 sock_fd = muse_client_new();
3453 LOGE("muse_client_new failed - returned fd %d", sock_fd);
3454 ret = RECORDER_ERROR_INVALID_OPERATION;
3455 goto _GET_DEVICE_STATE_EXIT;
3458 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
3459 LOGE("muse client get module index failed");
3460 ret = RECORDER_ERROR_INVALID_OPERATION;
3461 goto _GET_DEVICE_STATE_EXIT;
3464 send_msg = muse_core_msg_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3465 MUSE_TYPE_INT, "module", module_index,
3466 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3470 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3471 goto _GET_DEVICE_STATE_EXIT;
3474 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3476 ret = muse_core_msg_send(sock_fd, send_msg);
3478 muse_core_msg_free(send_msg);
3482 LOGE("send msg failed %d", errno);
3483 ret = RECORDER_ERROR_INVALID_OPERATION;
3484 goto _GET_DEVICE_STATE_EXIT;
3487 ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_RECORDER_MSG_MAX_LENGTH);
3489 LOGE("recv msg failed %d", errno);
3490 ret = RECORDER_ERROR_INVALID_OPERATION;
3491 goto _GET_DEVICE_STATE_EXIT;
3494 if (!muse_recorder_msg_get(ret, recv_msg)) {
3495 LOGE("failed to get return value from msg [%s]", recv_msg);
3496 ret = RECORDER_ERROR_INVALID_OPERATION;
3497 goto _GET_DEVICE_STATE_EXIT;
3500 if (ret == RECORDER_ERROR_NONE) {
3501 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3502 *state = (recorder_device_state_e)get_device_state;
3503 LOGD("device type %d state %d", type, *state);
3505 LOGE("failed to get device state from msg [%s]", recv_msg);
3506 ret = RECORDER_ERROR_INVALID_OPERATION;
3509 LOGE("failed 0x%x", ret);
3512 _GET_DEVICE_STATE_EXIT:
3514 muse_client_close(sock_fd);
3522 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3524 int ret = RECORDER_ERROR_NONE;
3525 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3526 recorder_cb_info *info = NULL;
3528 if (!callback || !cb_id) {
3529 LOGE("invalid pointer %p %p", callback, cb_id);
3530 return RECORDER_ERROR_INVALID_PARAMETER;
3533 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3535 /* check recorder support */
3536 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3537 if (ret != RECORDER_ERROR_NONE) {
3538 LOGE("get device state failed");
3539 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3543 info = g_new0(recorder_cb_info, 1);
3545 LOGE("info failed");
3546 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3550 info->id = ++g_rec_dev_state_changed_cb_id;
3551 info->callback = (void *)callback;
3552 info->user_data = user_data;
3556 /* subscribe dbus signal for camera state change */
3557 if (!g_rec_dev_state_changed_cb_conn) {
3558 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3559 if (!g_rec_dev_state_changed_cb_conn) {
3560 LOGE("failed to get gdbus connection");
3561 ret = RECORDER_ERROR_INVALID_OPERATION;
3565 LOGD("subscribe signal %s - %s - %s",
3566 MM_CAMCORDER_DBUS_OBJECT,
3567 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3568 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3570 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3571 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3572 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3573 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3574 LOGE("failed to get gdbus connection");
3575 ret = RECORDER_ERROR_INVALID_OPERATION;
3579 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3582 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3584 LOGD("callback id %d", info->id);
3587 if (ret != RECORDER_ERROR_NONE) {
3593 if (g_rec_dev_state_changed_cb_conn) {
3594 g_object_unref(g_rec_dev_state_changed_cb_conn);
3595 g_rec_dev_state_changed_cb_conn = NULL;
3599 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3605 int recorder_remove_device_state_changed_cb(int cb_id)
3607 int ret = RECORDER_ERROR_NONE;
3608 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3609 GList *tmp_list = NULL;
3610 recorder_cb_info *info = NULL;
3612 /* check recorder support */
3613 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3614 if (ret != RECORDER_ERROR_NONE) {
3615 LOGE("get device state failed");
3619 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3621 if (!g_rec_dev_state_changed_cb_list) {
3622 LOGE("there is no callback info");
3623 ret = RECORDER_ERROR_INVALID_OPERATION;
3627 tmp_list = g_rec_dev_state_changed_cb_list;
3630 info = tmp_list->data;
3631 tmp_list = tmp_list->next;
3638 if (info->id == cb_id) {
3639 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3644 if (!g_rec_dev_state_changed_cb_list) {
3645 /* no remained callback */
3646 if (g_rec_dev_state_changed_cb_conn) {
3647 /* unsubscribe signal */
3648 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3649 g_rec_dev_state_changed_cb_subscribe_id = 0;
3651 /* unref connection */
3652 g_object_unref(g_rec_dev_state_changed_cb_conn);
3653 g_rec_dev_state_changed_cb_conn = NULL;
3657 LOGD("id %d callback removed", cb_id);
3658 ret = RECORDER_ERROR_NONE;
3664 LOGE("id %d callback not found", cb_id);
3665 ret = RECORDER_ERROR_INVALID_PARAMETER;
3668 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);