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;
49 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
50 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
51 const gchar *signal_name, GVariant *param, gpointer user_data)
54 recorder_type_e type = RECORDER_TYPE_AUDIO;
55 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
56 GList *tmp_list = NULL;
57 recorder_cb_info *info = NULL;
59 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
61 if (!g_rec_dev_state_changed_cb_list || !param) {
62 LOGW("no callback or NULL param %p", param);
66 /* get device type and state */
67 g_variant_get(param, "(i)", &value);
70 state = 0x0000ffff & value;
72 LOGD("type %d, state %d", type, state);
74 tmp_list = g_rec_dev_state_changed_cb_list;
77 info = (recorder_cb_info *)tmp_list->data;
81 LOGD("start id[%d] callback", info->id);
82 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
83 LOGD("returned id[%d] callback", info->id);
85 LOGW("NULL callback for id %d", info->id);
89 tmp_list = tmp_list->next;
93 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
99 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
101 tbm_bo tmp_bo = NULL;
102 tbm_bo_handle tmp_bo_handle = {NULL, };
104 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
105 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
106 bufmgr, bo, bo_handle, tbm_key);
110 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
111 if (tmp_bo == NULL) {
112 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
116 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
117 if (tmp_bo_handle.ptr == NULL) {
118 LOGE("bo map failed %p", tmp_bo);
119 tbm_bo_unref(tmp_bo);
124 /* set bo and bo_handle */
126 *bo_handle = tmp_bo_handle;
131 static void _recorder_release_imported_bo(tbm_bo *bo)
133 if (bo == NULL || *bo == NULL) {
145 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
147 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
148 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
152 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
154 if (cb_info->user_cb[event] == NULL) {
155 LOGW("user callback for event %d is not set", event);
160 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
166 muse_recorder_msg_get(previous, recv_msg);
167 muse_recorder_msg_get(current, recv_msg);
168 muse_recorder_msg_get(by_policy, recv_msg);
170 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
171 (recorder_state_e)current,
173 cb_info->user_data[event]);
176 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
180 muse_recorder_msg_get(type, recv_msg);
182 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
183 cb_info->user_data[event]);
186 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
188 int64_t cb_elapsed_time = 0;
189 int64_t cb_file_size = 0;
191 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
192 muse_recorder_msg_get(cb_file_size, recv_msg);
194 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
195 (unsigned long long)cb_file_size,
196 cb_info->user_data[event]);
199 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
205 muse_recorder_msg_get(policy, recv_msg);
206 muse_recorder_msg_get(previous, recv_msg);
207 muse_recorder_msg_get(current, recv_msg);
209 if (policy == RECORDER_POLICY_SOUND)
210 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
211 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
212 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
213 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
214 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
216 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
217 (recorder_state_e)previous,
218 (recorder_state_e)current,
219 cb_info->user_data[event]);
222 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
230 tbm_bo_handle bo_handle = {.ptr = NULL};
231 char *send_msg = NULL;
233 muse_recorder_msg_get(tbm_key, recv_msg);
239 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
240 LOGE("tbm key %d import failed", tbm_key);
244 muse_recorder_msg_get(size, recv_msg);
245 muse_recorder_msg_get(format, recv_msg);
246 muse_recorder_msg_get(channel, recv_msg);
247 muse_recorder_msg_get(timestamp, recv_msg);
249 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
251 (audio_sample_type_e)format,
253 (unsigned int)timestamp,
254 cb_info->user_data[event]);
256 /* release imported bo */
257 _recorder_release_imported_bo(&bo);
260 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
261 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
263 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
264 LOGE("sending message failed");
266 muse_core_msg_json_factory_free(send_msg);
269 case MUSE_RECORDER_EVENT_TYPE_ERROR:
272 int current_state = 0;
274 muse_recorder_msg_get(error, recv_msg);
275 muse_recorder_msg_get(current_state, recv_msg);
277 if (error == RECORDER_ERROR_SOUND_POLICY)
278 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
279 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
280 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
281 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
282 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
284 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
285 (recorder_state_e)current_state,
286 cb_info->user_data[event]);
289 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
293 muse_recorder_msg_get(codec, recv_msg);
295 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
296 cb_info->user_cb[event] = NULL;
297 cb_info->user_data[event] = NULL;
298 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
302 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
306 muse_recorder_msg_get(format, recv_msg);
308 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
309 cb_info->user_cb[event] = NULL;
310 cb_info->user_data[event] = NULL;
311 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
315 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
319 muse_recorder_msg_get(codec, recv_msg);
321 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
322 cb_info->user_cb[event] = NULL;
323 cb_info->user_data[event] = NULL;
324 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
328 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
333 muse_recorder_msg_get(width, recv_msg);
334 muse_recorder_msg_get(height, recv_msg);
336 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
337 cb_info->user_cb[event] = NULL;
338 cb_info->user_data[event] = NULL;
339 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
349 static bool _recorder_idle_event_callback(void *data)
351 recorder_cb_info_s *cb_info = NULL;
352 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
354 if (rec_idle_event == NULL) {
355 LOGE("rec_idle_event is NULL");
360 g_mutex_lock(&rec_idle_event->event_mutex);
362 cb_info = rec_idle_event->cb_info;
363 if (cb_info == NULL) {
364 LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
365 goto IDLE_EVENT_CALLBACK_DONE;
368 /* remove event from list */
369 g_mutex_lock(&cb_info->idle_event_mutex);
370 if (cb_info->idle_event_list)
371 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
373 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
374 g_mutex_unlock(&cb_info->idle_event_mutex);
377 _recorder_client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
379 /* send signal for waiting thread */
380 g_cond_signal(&cb_info->idle_event_cond);
382 IDLE_EVENT_CALLBACK_DONE:
383 /* unlock and release event */
384 g_mutex_unlock(&rec_idle_event->event_mutex);
385 g_mutex_clear(&rec_idle_event->event_mutex);
387 g_free(rec_idle_event);
388 rec_idle_event = NULL;
394 static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
396 recorder_idle_event_s *rec_idle_event = NULL;
401 if (cb_info == NULL) {
402 LOGE("cb_info is NULL");
406 g_mutex_lock(&cb_info->idle_event_mutex);
408 if (cb_info->idle_event_list == NULL) {
411 list = cb_info->idle_event_list;
414 rec_idle_event = list->data;
415 list = g_list_next(list);
417 if (!rec_idle_event) {
418 LOGW("The event is NULL");
422 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
425 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
427 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
428 LOGW("signal received");
435 ret = g_idle_remove_by_data(rec_idle_event);
437 LOGD("remove event %p, ret %d", rec_idle_event, ret);
440 rec_idle_event->cb_info = NULL;
441 LOGW("idle cb for event %p will be called later", rec_idle_event);
444 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
446 g_mutex_unlock(&rec_idle_event->event_mutex);
449 g_mutex_clear(&rec_idle_event->event_mutex);
451 g_free(rec_idle_event);
452 rec_idle_event = NULL;
454 LOGD("remove event done");
458 g_list_free(cb_info->idle_event_list);
459 cb_info->idle_event_list = NULL;
462 g_mutex_unlock(&cb_info->idle_event_mutex);
468 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
470 recorder_message_s *rec_msg = NULL;
472 if (!cb_info || !msg) {
473 LOGE("NULL pointer %p %p", cb_info, msg);
477 rec_msg = g_new0(recorder_message_s, 1);
479 LOGE("failed to alloc rec_msg for [%s]", msg);
484 rec_msg->event = event;
485 rec_msg->event_class = event_class;
487 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
489 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
491 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
492 g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
493 g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
494 g_cond_signal(&cb_info->audio_stream_cb_info.cond);
495 g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
497 g_mutex_lock(&cb_info->msg_handler_info.mutex);
498 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
499 g_cond_signal(&cb_info->msg_handler_info.cond);
500 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
509 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
511 if (!cb_info || !msg) {
512 LOGE("NULL pointer %p %p", cb_info, msg);
517 case MUSE_RECORDER_API_GET_STATE:
520 muse_recorder_msg_get(get_state, msg);
521 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
524 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
528 muse_recorder_msg_get(get_width, msg);
529 muse_recorder_msg_get(get_height, msg);
530 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
531 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
534 case MUSE_RECORDER_API_GET_FILE_FORMAT:
537 muse_recorder_msg_get(get_format, msg);
538 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
541 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
544 muse_recorder_msg_get(get_codec, msg);
545 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
548 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
551 muse_recorder_msg_get(get_codec, msg);
552 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
555 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
558 muse_recorder_msg_get(get_kbyte, msg);
559 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
562 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
565 muse_recorder_msg_get(get_second, msg);
566 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
569 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
572 muse_recorder_msg_get(get_device, msg);
573 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
576 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
578 int get_samplerate = 0;
579 muse_recorder_msg_get(get_samplerate, msg);
580 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
583 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
586 muse_recorder_msg_get(get_bitrate, msg);
587 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
590 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
593 muse_recorder_msg_get(get_bitrate, msg);
594 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
597 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
600 muse_recorder_msg_get_double(get_rate, msg);
601 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
604 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
606 int get_channel_count = 0;
607 muse_recorder_msg_get(get_channel_count, msg);
608 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
611 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
613 int get_orientation = 0;
614 muse_recorder_msg_get(get_orientation, msg);
615 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
618 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
620 double get_level = 0.0;
621 muse_recorder_msg_get_double(get_level, msg);
622 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
625 case MUSE_RECORDER_API_GET_FILENAME:
627 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
628 muse_recorder_msg_get_string(get_filename, msg);
629 if (cb_info->get_filename) {
630 free(cb_info->get_filename);
631 cb_info->get_filename = NULL;
633 cb_info->get_filename = strdup(get_filename);
644 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
646 int ret = RECORDER_ERROR_NONE;
650 int event_class = -1;
652 if (!cb_info || !msg) {
653 LOGE("invalid ptr %p %p", cb_info, msg);
657 /*LOGD("msg [%s]", msg);*/
659 if (!muse_recorder_msg_get(api, msg)) {
660 LOGE("failed to get recorder api");
664 if (api == MUSE_RECORDER_CB_EVENT) {
665 if (!muse_recorder_msg_get(event, msg) ||
666 !muse_recorder_msg_get(event_class, msg)) {
667 LOGE("failed to get event or event_class [%s]", msg);
671 if (!muse_recorder_msg_get(api_class, msg)) {
672 LOGE("failed to get api_class [%s]", msg);
677 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
678 if (api >= MUSE_RECORDER_API_MAX) {
679 LOGE("invalid api %d", api);
683 if (!muse_recorder_msg_get(ret, msg)) {
684 LOGE("failed to get recorder ret");
688 g_mutex_lock(&cb_info->api_mutex[api]);
690 cb_info->api_ret[api] = ret;
691 cb_info->api_activating[api] = 1;
693 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
694 g_atomic_int_set(&cb_info->msg_recv_running, 0);
695 LOGD("get device state done. close client cb handler");
698 case MUSE_RECORDER_API_CREATE:
699 if (ret != RECORDER_ERROR_NONE) {
700 g_atomic_int_set(&cb_info->msg_recv_running, 0);
701 LOGE("create error 0x%x. closing..", ret);
704 case MUSE_RECORDER_API_DESTROY:
705 if (ret == RECORDER_ERROR_NONE) {
706 g_atomic_int_set(&cb_info->msg_recv_running, 0);
707 LOGD("destroy done. closing..");
711 __recorder_get_api_operation(api, cb_info, msg);
716 g_cond_signal(&cb_info->api_cond[api]);
717 g_mutex_unlock(&cb_info->api_mutex[api]);
718 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
719 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
721 LOGW("unknown recorder api %d and api_class %d", api, api_class);
728 static void *_recorder_msg_handler_func(gpointer data)
732 recorder_message_s *rec_msg = NULL;
733 recorder_idle_event_s *rec_idle_event = NULL;
734 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
735 recorder_cb_info_s *cb_info = NULL;
737 if (!handler_info || !handler_info->cb_info) {
738 LOGE("NULL handler %p", handler_info);
742 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
743 type = handler_info->type;
745 LOGD("t:%d start", type);
747 g_mutex_lock(&handler_info->mutex);
749 while (g_atomic_int_get(&handler_info->running)) {
750 if (g_queue_is_empty(handler_info->queue)) {
751 /*LOGD("signal wait...");*/
752 g_cond_wait(&handler_info->cond, &handler_info->mutex);
753 /*LOGD("signal received");*/
755 if (g_atomic_int_get(&handler_info->running) == 0) {
756 LOGD("stop event thread");
761 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
762 g_mutex_unlock(&handler_info->mutex);
763 if (rec_msg == NULL) {
764 LOGE("NULL message");
765 g_mutex_lock(&handler_info->mutex);
771 if (api < MUSE_RECORDER_API_MAX) {
774 g_mutex_lock(&cb_info->api_mutex[api]);
776 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
777 cb_info->api_ret[api] = ret;
778 cb_info->api_activating[api] = 1;
780 /*LOGD("recorder api %d - return 0x%x", ret);*/
782 g_cond_signal(&cb_info->api_cond[api]);
784 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
787 g_mutex_unlock(&cb_info->api_mutex[api]);
788 } else if (api == MUSE_RECORDER_CB_EVENT) {
789 switch (rec_msg->event_class) {
790 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
791 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
793 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
794 rec_idle_event = g_new0(recorder_idle_event_s, 1);
795 if (rec_idle_event == NULL) {
796 LOGE("event alloc failed");
800 rec_idle_event->event = rec_msg->event;
801 rec_idle_event->cb_info = cb_info;
802 g_mutex_init(&rec_idle_event->event_mutex);
803 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
805 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
807 g_mutex_lock(&cb_info->idle_event_mutex);
808 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
809 g_mutex_unlock(&cb_info->idle_event_mutex);
811 g_idle_add_full(G_PRIORITY_DEFAULT,
812 (GSourceFunc)_recorder_idle_event_callback,
813 (gpointer)rec_idle_event,
817 LOGE("unknown event class %d", rec_msg->event_class);
821 LOGE("unknown api[%d] message", api);
827 g_mutex_lock(&handler_info->mutex);
830 /* remove remained event */
831 while (!g_queue_is_empty(handler_info->queue)) {
832 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
834 LOGD("remove message %p", rec_msg);
838 LOGW("NULL message");
842 g_mutex_unlock(&handler_info->mutex);
850 static void *_recorder_msg_recv_func(gpointer data)
853 int single_length = 0;
854 int remained_length = 0;
855 char *recv_msg = NULL;
856 char *single_msg = NULL;
857 char *remained_msg = NULL;
861 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
863 if (cb_info == NULL) {
864 LOGE("cb_info NULL");
870 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
871 if (single_msg == NULL) {
872 LOGE("single_msg malloc failed");
873 goto CB_HANDLER_EXIT;
876 recv_msg = cb_info->recv_msg;
878 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
879 recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
880 if (recv_length <= 0) {
881 cb_info->is_server_connected = FALSE;
882 LOGE("receive msg failed - server disconnected");
886 recv_msg[recv_length] = '\0';
892 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
894 /* Need to split the combined entering msgs */
895 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
896 if (recv_msg[cur_pos] == '}') {
897 single_length = cur_pos - prev_pos + 1;
899 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
900 /* check remained msg */
901 if (remained_length > 0) {
903 strncpy(single_msg, remained_msg, remained_length);
904 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
905 single_msg[remained_length + single_length] = '\0';
910 strncpy(single_msg, recv_msg + prev_pos, single_length);
911 single_msg[single_length] = '\0';
912 LOGE("lost msg [%s], skip...", single_msg);
917 strncpy(single_msg, recv_msg + prev_pos, single_length);
918 single_msg[single_length] = '\0';
921 if (single_msg[0] == '{') {
923 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
924 __recorder_process_msg(cb_info, single_msg);
926 LOGE("invalid msg [%s]", single_msg);
929 LOGE("too long message [len %d] skip...", single_length);
932 prev_pos = cur_pos + 1;
936 /* check incompleted message */
937 if (recv_msg[recv_length - 1] != '}') {
938 remained_length = recv_length - prev_pos;
940 LOGW("incompleted message [len %d]", remained_length);
942 remained_msg = (char *)malloc(remained_length + 1);
944 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
945 remained_msg[remained_length] = '\0';
947 LOGE("failed to alloc for remained msg");
954 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
956 if (!cb_info->is_server_connected) {
957 /* send error msg for server disconnection */
958 char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
959 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
960 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
964 LOGE("error_msg failed");
965 goto CB_HANDLER_EXIT;
968 LOGE("add error msg for service disconnection done");
970 __recorder_add_msg_to_queue(cb_info,
971 MUSE_RECORDER_CB_EVENT,
972 MUSE_RECORDER_EVENT_TYPE_ERROR,
973 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
976 muse_core_msg_json_factory_free(error_msg);
979 LOGE("add error msg for service disconnection done");
997 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
998 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1000 if (!handler_info || !thread_name || !cb_info) {
1001 LOGE("t:%d NULL %p %p %p",
1002 type, handler_info, thread_name, cb_info);
1008 handler_info->type = type;
1009 handler_info->queue = g_queue_new();
1010 if (handler_info->queue == NULL) {
1011 LOGE("t:%d queue failed", type);
1015 g_mutex_init(&handler_info->mutex);
1016 g_cond_init(&handler_info->cond);
1018 handler_info->cb_info = (void *)cb_info;
1019 g_atomic_int_set(&handler_info->running, 1);
1021 handler_info->thread = g_thread_try_new(thread_name,
1022 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1023 if (handler_info->thread == NULL) {
1024 LOGE("t:%d thread failed", type);
1026 g_mutex_clear(&handler_info->mutex);
1027 g_cond_clear(&handler_info->cond);
1028 g_queue_free(handler_info->queue);
1029 handler_info->queue = NULL;
1034 LOGD("t:%d done", type);
1040 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1044 if (!handler_info) {
1045 LOGE("NULL handler");
1049 if (!handler_info->thread) {
1050 LOGW("thread is not created");
1054 type = handler_info->type;
1056 LOGD("t:%d thread %p", type, handler_info->thread);
1058 g_mutex_lock(&handler_info->mutex);
1059 g_atomic_int_set(&handler_info->running, 0);
1060 g_cond_signal(&handler_info->cond);
1061 g_mutex_unlock(&handler_info->mutex);
1063 g_thread_join(handler_info->thread);
1064 g_thread_unref(handler_info->thread);
1065 handler_info->thread = NULL;
1067 g_mutex_clear(&handler_info->mutex);
1068 g_cond_clear(&handler_info->cond);
1069 g_queue_free(handler_info->queue);
1070 handler_info->queue = NULL;
1072 LOGD("t:%d done", type);
1078 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1080 recorder_cb_info_s *cb_info = NULL;
1083 g_return_val_if_fail(sockfd > 0, NULL);
1085 cb_info = g_new0(recorder_cb_info_s, 1);
1086 if (cb_info == NULL) {
1087 LOGE("cb_info failed");
1091 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1092 g_mutex_init(&cb_info->api_mutex[i]);
1093 g_cond_init(&cb_info->api_cond[i]);
1096 g_mutex_init(&cb_info->idle_event_mutex);
1097 g_cond_init(&cb_info->idle_event_cond);
1099 /* message handler thread */
1100 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1101 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1102 LOGE("msg_handler_info failed");
1106 /* message handler thread for audio stream callback */
1107 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1108 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1109 LOGE("audio_stream_cb_info failed");
1113 cb_info->fd = sockfd;
1115 /* message receive thread */
1116 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1117 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1118 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1119 if (cb_info->msg_recv_thread == NULL) {
1120 LOGE("message receive thread creation failed");
1124 cb_info->is_server_connected = TRUE;
1130 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1131 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1133 g_mutex_clear(&cb_info->idle_event_mutex);
1134 g_cond_clear(&cb_info->idle_event_cond);
1136 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1137 g_mutex_clear(&cb_info->api_mutex[i]);
1138 g_cond_clear(&cb_info->api_cond[i]);
1148 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1150 int ret = RECORDER_ERROR_NONE;
1153 /*LOGD("Enter api : %d", api);*/
1155 if (!cb_info->is_server_connected) {
1156 LOGE("server is disconnected");
1157 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1160 g_mutex_lock(&(cb_info->api_mutex[api]));
1162 if (cb_info->api_activating[api] == 0) {
1163 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1164 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1165 ret = cb_info->api_ret[api];
1166 cb_info->api_activating[api] = 0;
1168 /*LOGD("return value : 0x%x", ret);*/
1170 ret = RECORDER_ERROR_INVALID_OPERATION;
1172 LOGE("api %d was TIMED OUT!", api);
1175 ret = cb_info->api_ret[api];
1176 cb_info->api_activating[api] = 0;
1178 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1181 if (ret != RECORDER_ERROR_NONE) {
1182 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1184 if (ret == RECORDER_ERROR_SOUND_POLICY)
1185 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1186 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1187 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1188 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1189 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1192 g_mutex_unlock(&(cb_info->api_mutex[api]));
1198 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1203 if (!cb_info || !ret) {
1204 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1205 return RECORDER_ERROR_INVALID_PARAMETER;
1208 msg = muse_core_msg_json_factory_new(api, NULL);
1210 LOGE("msg creation failed: api %d", api);
1211 return RECORDER_ERROR_OUT_OF_MEMORY;
1214 /*LOGD("send msg %s", msg);*/
1216 if (cb_info->is_server_connected)
1217 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1220 LOGE("message send failed");
1221 *ret = RECORDER_ERROR_INVALID_OPERATION;
1223 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1226 muse_core_msg_json_factory_free(msg);
1228 return RECORDER_ERROR_NONE;
1232 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1237 if (!cb_info || !ret || !param) {
1238 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1239 return RECORDER_ERROR_INVALID_PARAMETER;
1242 /*LOGD("type %d, name %s", param->type, param->name);*/
1244 switch (param->type) {
1246 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1248 case MUSE_TYPE_DOUBLE:
1249 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1251 case MUSE_TYPE_STRING:
1252 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1255 LOGE("unknown type %d", param->type);
1260 LOGE("msg creation failed: api %d, type %d, param name %s",
1261 api, param->type, param->name);
1262 return RECORDER_ERROR_OUT_OF_MEMORY;
1265 /*LOGD("send msg %s", msg);*/
1267 if (cb_info->is_server_connected)
1268 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1271 LOGE("message send failed");
1272 *ret = RECORDER_ERROR_INVALID_OPERATION;
1274 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1277 muse_core_msg_json_factory_free(msg);
1279 return RECORDER_ERROR_NONE;
1283 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1287 g_return_if_fail(cb_info != NULL);
1289 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1291 g_thread_join(cb_info->msg_recv_thread);
1292 g_thread_unref(cb_info->msg_recv_thread);
1293 cb_info->msg_recv_thread = NULL;
1295 LOGD("msg_recv thread removed");
1297 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1298 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1300 g_mutex_clear(&cb_info->idle_event_mutex);
1301 g_cond_clear(&cb_info->idle_event_cond);
1303 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1304 g_mutex_clear(&cb_info->api_mutex[i]);
1305 g_cond_clear(&cb_info->api_cond[i]);
1308 if (cb_info->fd > -1) {
1309 muse_core_connection_close(cb_info->fd);
1313 if (cb_info->bufmgr) {
1314 tbm_bufmgr_deinit(cb_info->bufmgr);
1315 cb_info->bufmgr = NULL;
1317 if (cb_info->get_filename) {
1318 free(cb_info->get_filename);
1319 cb_info->get_filename = NULL;
1329 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1331 char **root_directory = (char **)user_data;
1333 if (root_directory == NULL) {
1334 LOGE("user data is NULL");
1338 LOGD("storage id %d, type %d, state %d, path %s",
1339 storage_id, type, state, path ? path : "NULL");
1341 if (type == STORAGE_TYPE_INTERNAL && path) {
1342 if (*root_directory) {
1343 free(*root_directory);
1344 *root_directory = NULL;
1347 *root_directory = strdup(path);
1348 if (*root_directory) {
1349 LOGD("get root directory %s", *root_directory);
1352 LOGE("strdup %s failed", path);
1359 static int _recorder_client_get_root_directory(char **root_directory)
1361 int ret = STORAGE_ERROR_NONE;
1363 if (root_directory == NULL) {
1364 LOGE("user data is NULL");
1368 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1369 if (ret != STORAGE_ERROR_NONE) {
1370 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1377 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1379 int ret = RECORDER_ERROR_NONE;
1380 int destroy_ret = RECORDER_ERROR_NONE;
1383 char *send_msg = NULL;
1384 char *root_directory = NULL;
1385 intptr_t camera_handle = 0;
1386 intptr_t handle = 0;
1387 tbm_bufmgr bufmgr = NULL;
1388 recorder_cli_s *pc = NULL;
1389 recorder_msg_param param;
1391 LOGD("Enter - type %d", type);
1393 if (recorder == NULL) {
1394 LOGE("NULL pointer for recorder handle");
1395 return RECORDER_ERROR_INVALID_PARAMETER;
1398 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1399 LOGE("NULL pointer for camera handle on video recorder mode");
1400 return RECORDER_ERROR_INVALID_PARAMETER;
1403 bufmgr = tbm_bufmgr_init(-1);
1404 if (bufmgr == NULL) {
1405 LOGE("get tbm bufmgr failed");
1406 return RECORDER_ERROR_INVALID_OPERATION;
1409 pc = g_new0(recorder_cli_s, 1);
1411 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1412 goto _ERR_RECORDER_EXIT;
1415 sock_fd = muse_core_client_new();
1417 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1418 ret = RECORDER_ERROR_INVALID_OPERATION;
1419 goto _ERR_RECORDER_EXIT;
1422 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1423 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1424 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1425 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1426 MUSE_TYPE_INT, "pid", getpid(),
1429 pc->camera = camera;
1430 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1431 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1432 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1433 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1434 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1440 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1441 goto _ERR_RECORDER_EXIT;
1444 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1446 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1448 muse_core_msg_json_factory_free(send_msg);
1452 LOGE("send msg failed %d", errno);
1453 ret = RECORDER_ERROR_INVALID_OPERATION;
1454 goto _ERR_RECORDER_EXIT;
1457 pc->cb_info = _recorder_client_callback_new(sock_fd);
1458 if (pc->cb_info == NULL) {
1459 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1460 goto _ERR_RECORDER_EXIT;
1465 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1466 if (ret != RECORDER_ERROR_NONE) {
1467 LOGE("API_CREATE failed 0x%x", ret);
1468 goto _ERR_RECORDER_EXIT;
1471 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1473 LOGE("Receiving Handle Failed!!");
1474 ret = RECORDER_ERROR_INVALID_OPERATION;
1475 goto _ERR_RECORDER_AFTER_CREATE;
1478 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1479 LOGE("failed to get root directory of internal storage");
1480 ret = RECORDER_ERROR_INVALID_OPERATION;
1481 goto _ERR_RECORDER_AFTER_CREATE;
1484 LOGD("root directory [%s]", root_directory);
1486 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1488 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1490 if (ret != RECORDER_ERROR_NONE) {
1491 LOGE("failed to set root directory %s", root_directory);
1492 ret = RECORDER_ERROR_INVALID_OPERATION;
1493 goto _ERR_RECORDER_AFTER_CREATE;
1496 free(root_directory);
1497 root_directory = NULL;
1499 pc->remote_handle = handle;
1500 pc->cb_info->bufmgr = bufmgr;
1502 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1503 type, pc, pc->remote_handle);
1505 *recorder = (recorder_h)pc;
1509 return RECORDER_ERROR_NONE;
1511 _ERR_RECORDER_AFTER_CREATE:
1512 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1513 LOGE("destroy return 0x%x", destroy_ret);
1516 tbm_bufmgr_deinit(bufmgr);
1519 if (root_directory) {
1520 free(root_directory);
1521 root_directory = NULL;
1525 muse_core_connection_close(sock_fd);
1531 _recorder_client_callback_destroy(pc->cb_info);
1542 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1544 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1548 int recorder_create_audiorecorder(recorder_h *recorder)
1550 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1554 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1556 int ret = RECORDER_ERROR_NONE;
1557 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1558 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1560 if (!pc || !pc->cb_info) {
1561 LOGE("NULL handle");
1562 return RECORDER_ERROR_INVALID_PARAMETER;
1565 if (state == NULL) {
1566 LOGE("NULL pointer state");
1567 return RECORDER_ERROR_INVALID_PARAMETER;
1570 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1572 _recorder_msg_send(api, pc->cb_info, &ret);
1574 if (ret == RECORDER_ERROR_NONE)
1575 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1577 LOGD("ret : 0x%x, state : %d", ret, *state);
1583 int recorder_destroy(recorder_h recorder)
1585 int ret = RECORDER_ERROR_NONE;
1586 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1587 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1589 if (!pc || !pc->cb_info) {
1590 LOGE("NULL handle");
1591 return RECORDER_ERROR_INVALID_PARAMETER;
1596 if (pc->cb_info->is_server_connected)
1597 _recorder_msg_send(api, pc->cb_info, &ret);
1599 LOGW("server disconnected. release resource without send message.");
1601 if (ret == RECORDER_ERROR_NONE) {
1602 _recorder_remove_idle_event_all(pc->cb_info);
1603 _recorder_client_callback_destroy(pc->cb_info);
1608 LOGD("ret : 0x%x", ret);
1614 int recorder_prepare(recorder_h recorder)
1616 int ret = RECORDER_ERROR_NONE;
1617 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1618 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1620 if (!pc || !pc->cb_info) {
1621 LOGE("NULL handle");
1622 return RECORDER_ERROR_INVALID_PARAMETER;
1627 _recorder_msg_send(api, pc->cb_info, &ret);
1629 LOGD("ret : 0x%x", ret);
1631 if (ret == RECORDER_ERROR_NONE && pc->camera)
1632 camera_start_evas_rendering(pc->camera);
1638 int recorder_unprepare(recorder_h recorder)
1640 int ret = RECORDER_ERROR_NONE;
1641 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1642 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1643 camera_state_e camera_state = CAMERA_STATE_NONE;
1645 if (!pc || !pc->cb_info) {
1646 LOGE("NULL handle");
1647 return RECORDER_ERROR_INVALID_PARAMETER;
1653 ret = camera_get_state(pc->camera, &camera_state);
1654 if (ret != CAMERA_ERROR_NONE) {
1655 LOGE("failed to get camera state 0x%x", ret);
1656 return RECORDER_ERROR_INVALID_OPERATION;
1659 if (camera_state == CAMERA_STATE_PREVIEW) {
1660 ret = camera_stop_evas_rendering(pc->camera, false);
1661 if (ret != CAMERA_ERROR_NONE) {
1662 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1663 return RECORDER_ERROR_INVALID_OPERATION;
1668 _recorder_msg_send(api, pc->cb_info, &ret);
1670 LOGD("ret : 0x%x", ret);
1676 int recorder_start(recorder_h recorder)
1678 int ret = RECORDER_ERROR_NONE;
1679 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1680 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1681 recorder_state_e current_state = RECORDER_STATE_NONE;
1683 if (!pc || !pc->cb_info) {
1684 LOGE("NULL handle");
1685 return RECORDER_ERROR_INVALID_PARAMETER;
1691 ret = recorder_get_state(recorder, ¤t_state);
1692 if (ret != RECORDER_ERROR_NONE) {
1693 LOGE("failed to get current state 0x%x", ret);
1694 return RECORDER_ERROR_INVALID_OPERATION;
1697 if (current_state == RECORDER_STATE_READY) {
1698 ret = camera_stop_evas_rendering(pc->camera, true);
1699 if (ret != CAMERA_ERROR_NONE) {
1700 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1701 return RECORDER_ERROR_INVALID_OPERATION;
1706 _recorder_msg_send(api, pc->cb_info, &ret);
1708 if (pc->camera && current_state == RECORDER_STATE_READY)
1709 camera_start_evas_rendering(pc->camera);
1711 LOGD("ret : 0x%x", ret);
1717 int recorder_pause(recorder_h recorder)
1719 int ret = RECORDER_ERROR_NONE;
1720 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
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 _recorder_msg_send(api, pc->cb_info, &ret);
1732 LOGD("ret : 0x%x", ret);
1738 int recorder_commit(recorder_h recorder)
1740 int ret = RECORDER_ERROR_NONE;
1741 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1742 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1743 recorder_state_e current_state = RECORDER_STATE_NONE;
1745 if (!pc || !pc->cb_info) {
1746 LOGE("NULL handle");
1747 return RECORDER_ERROR_INVALID_PARAMETER;
1753 ret = recorder_get_state(recorder, ¤t_state);
1754 if (ret != RECORDER_ERROR_NONE) {
1755 LOGE("failed to get current state 0x%x", ret);
1756 return RECORDER_ERROR_INVALID_OPERATION;
1759 if (current_state >= RECORDER_STATE_RECORDING) {
1760 ret = camera_stop_evas_rendering(pc->camera, true);
1761 if (ret != CAMERA_ERROR_NONE) {
1762 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1763 return RECORDER_ERROR_INVALID_OPERATION;
1768 _recorder_msg_send(api, pc->cb_info, &ret);
1770 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1771 camera_start_evas_rendering(pc->camera);
1773 LOGD("ret : 0x%x", ret);
1779 int recorder_cancel(recorder_h recorder)
1781 int ret = RECORDER_ERROR_NONE;
1782 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1783 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1784 recorder_state_e current_state = RECORDER_STATE_NONE;
1786 if (!pc || !pc->cb_info) {
1787 LOGE("NULL handle");
1788 return RECORDER_ERROR_INVALID_PARAMETER;
1794 ret = recorder_get_state(recorder, ¤t_state);
1795 if (ret != RECORDER_ERROR_NONE) {
1796 LOGE("failed to get current state 0x%x", ret);
1797 return RECORDER_ERROR_INVALID_OPERATION;
1800 if (current_state >= RECORDER_STATE_RECORDING) {
1801 ret = camera_stop_evas_rendering(pc->camera, true);
1802 if (ret != CAMERA_ERROR_NONE) {
1803 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1804 return RECORDER_ERROR_INVALID_OPERATION;
1809 _recorder_msg_send(api, pc->cb_info, &ret);
1811 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1812 camera_start_evas_rendering(pc->camera);
1814 LOGD("ret : 0x%x", ret);
1820 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1822 int ret = RECORDER_ERROR_NONE;
1824 char *send_msg = NULL;
1825 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1826 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1828 if (!pc || !pc->cb_info) {
1829 LOGE("NULL handle");
1830 return RECORDER_ERROR_INVALID_PARAMETER;
1835 send_msg = muse_core_msg_json_factory_new(api,
1836 MUSE_TYPE_INT, "width", width,
1837 MUSE_TYPE_INT, "height", height,
1840 if (pc->cb_info->is_server_connected)
1841 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1844 LOGE("message send failed");
1845 ret = RECORDER_ERROR_INVALID_OPERATION;
1847 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1850 muse_core_msg_json_factory_free(send_msg);
1852 LOGE("failed to create msg");
1853 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1856 LOGD("ret : 0x%x", ret);
1862 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1864 int ret = RECORDER_ERROR_NONE;
1865 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1866 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1868 if (!pc || !pc->cb_info) {
1869 LOGE("NULL handle");
1870 return RECORDER_ERROR_INVALID_PARAMETER;
1873 if (!width || !height) {
1874 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1875 return RECORDER_ERROR_INVALID_PARAMETER;
1880 _recorder_msg_send(api, pc->cb_info, &ret);
1882 if (ret == RECORDER_ERROR_NONE) {
1883 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1884 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1887 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1893 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1894 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1896 int ret = RECORDER_ERROR_NONE;
1897 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1898 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1900 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1901 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1902 return RECORDER_ERROR_INVALID_PARAMETER;
1905 LOGD("Enter, handle :%x", pc->remote_handle);
1907 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1908 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
1910 _recorder_msg_send(api, pc->cb_info, &ret);
1912 LOGD("ret : 0x%x", ret);
1918 int recorder_get_audio_level(recorder_h recorder, double *level)
1920 int ret = RECORDER_ERROR_NONE;
1921 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
1922 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1924 if (!pc || !pc->cb_info || level == NULL) {
1925 LOGE("NULL pointer %p %p", pc, level);
1926 return RECORDER_ERROR_INVALID_PARAMETER;
1931 _recorder_msg_send(api, pc->cb_info, &ret);
1933 if (ret == RECORDER_ERROR_NONE)
1934 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
1936 LOGD("ret : 0x%x, level %lf", ret, *level);
1942 int recorder_set_filename(recorder_h recorder, const char *filename)
1944 int ret = RECORDER_ERROR_NONE;
1945 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
1946 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1947 recorder_msg_param param;
1948 char set_filename[RECORDER_FILENAME_MAX] = {0, };
1950 if (!pc || !pc->cb_info) {
1951 LOGE("NULL handle");
1952 return RECORDER_ERROR_INVALID_PARAMETER;
1955 if (filename == NULL) {
1956 LOGE("filename is NULL");
1957 return RECORDER_ERROR_INVALID_PARAMETER;
1962 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
1963 /* Cannot convert. Use original path. */
1964 strncpy(set_filename, filename, strlen(filename));
1966 /* Converted. Use converted path. */
1967 LOGD("Converted filename : %s -> %s", filename, set_filename);
1970 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
1972 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
1974 LOGD("ret : 0x%x", ret);
1980 int recorder_get_filename(recorder_h recorder, char **filename)
1982 int ret = RECORDER_ERROR_NONE;
1983 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
1984 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1985 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
1987 if (!pc || !pc->cb_info) {
1988 LOGE("NULL handle");
1989 return RECORDER_ERROR_INVALID_PARAMETER;
1992 if (filename == NULL) {
1993 LOGE("filename is NULL");
1994 return RECORDER_ERROR_INVALID_PARAMETER;
1999 _recorder_msg_send(api, pc->cb_info, &ret);
2001 if (ret == RECORDER_ERROR_NONE) {
2002 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2003 /* Cannot convert. Use original path. */
2004 *filename = pc->cb_info->get_filename;
2006 /* Converted. Use converted path. */
2007 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2008 *filename = strdup(compat_filename);
2009 free(pc->cb_info->get_filename);
2012 pc->cb_info->get_filename = NULL;
2015 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2021 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2023 int ret = RECORDER_ERROR_NONE;
2024 int set_format = (int)format;
2025 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2026 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2027 recorder_msg_param param;
2029 if (!pc || !pc->cb_info) {
2030 LOGE("NULL handle");
2031 return RECORDER_ERROR_INVALID_PARAMETER;
2034 LOGD("ENTER, set_format : %d", set_format);
2036 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2038 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2040 LOGD("ret : 0x%x", ret);
2045 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2047 int ret = RECORDER_ERROR_NONE;
2048 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2049 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2051 if (!pc || !pc->cb_info) {
2052 LOGE("NULL handle");
2053 return RECORDER_ERROR_INVALID_PARAMETER;
2056 if (format == NULL) {
2057 LOGE("NULL pointer data");
2058 return RECORDER_ERROR_INVALID_PARAMETER;
2063 _recorder_msg_send(api, pc->cb_info, &ret);
2065 if (ret == RECORDER_ERROR_NONE)
2066 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2068 LOGD("ret : 0x%x, format %d", ret, *format);
2074 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2076 int ret = RECORDER_ERROR_NONE;
2077 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2078 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2079 bool is_available = false;
2080 int stream_index = 0;
2081 char *stream_type = NULL;
2082 char *send_msg = NULL;
2085 if (!pc || !pc->cb_info || stream_info == NULL) {
2086 LOGE("NULL handle");
2087 return RECORDER_ERROR_INVALID_PARAMETER;
2092 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2093 if (ret != SOUND_MANAGER_ERROR_NONE) {
2094 LOGE("stream info verification failed");
2095 return RECORDER_ERROR_INVALID_OPERATION;
2098 if (is_available == false) {
2099 LOGE("stream information is not available");
2100 return RECORDER_ERROR_INVALID_OPERATION;
2103 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2104 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2106 LOGD("sound manager return [0x%x]", ret);
2108 if (ret == SOUND_MANAGER_ERROR_NONE) {
2109 send_msg = muse_core_msg_json_factory_new(api,
2110 MUSE_TYPE_STRING, "stream_type", stream_type,
2111 MUSE_TYPE_INT, "stream_index", stream_index,
2114 if (pc->cb_info->is_server_connected)
2115 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2118 LOGE("message send failed");
2119 ret = RECORDER_ERROR_INVALID_OPERATION;
2121 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2124 muse_core_msg_json_factory_free(send_msg);
2126 LOGE("failed to create msg");
2127 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2130 ret = RECORDER_ERROR_INVALID_OPERATION;
2137 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
2139 int ret = RECORDER_ERROR_NONE;
2140 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2141 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2143 if (!pc || !pc->cb_info || callback == NULL) {
2144 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2145 return RECORDER_ERROR_INVALID_PARAMETER;
2148 LOGD("Enter, handle :%x", pc->remote_handle);
2150 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2151 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2153 _recorder_msg_send(api, pc->cb_info, &ret);
2155 LOGD("ret : 0x%x", ret);
2161 int recorder_unset_state_changed_cb(recorder_h recorder)
2163 int ret = RECORDER_ERROR_NONE;
2164 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2165 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2167 if (!pc || !pc->cb_info) {
2168 LOGE("NULL handle");
2169 return RECORDER_ERROR_INVALID_PARAMETER;
2174 _recorder_msg_send(api, pc->cb_info, &ret);
2176 LOGD("ret : 0x%x", ret);
2182 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2184 int ret = RECORDER_ERROR_NONE;
2185 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2186 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2188 if (!pc || !pc->cb_info || callback == NULL) {
2189 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2190 return RECORDER_ERROR_INVALID_PARAMETER;
2193 LOGD("Enter, handle :%x", pc->remote_handle);
2195 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2196 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2198 _recorder_msg_send(api, pc->cb_info, &ret);
2200 LOGD("ret : 0x%x", ret);
2206 int recorder_unset_interrupted_cb(recorder_h recorder)
2208 int ret = RECORDER_ERROR_NONE;
2209 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2210 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2212 if (!pc || !pc->cb_info) {
2213 LOGE("NULL handle");
2214 return RECORDER_ERROR_INVALID_PARAMETER;
2219 _recorder_msg_send(api, pc->cb_info, &ret);
2221 LOGD("ret : 0x%x", ret);
2227 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
2229 int ret = RECORDER_ERROR_NONE;
2230 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2231 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2233 if (!pc || !pc->cb_info || callback == NULL) {
2234 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2235 return RECORDER_ERROR_INVALID_PARAMETER;
2238 LOGD("Enter, handle :%x", pc->remote_handle);
2240 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2241 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2243 _recorder_msg_send(api, pc->cb_info, &ret);
2245 LOGD("ret : 0x%x", ret);
2251 int recorder_unset_audio_stream_cb(recorder_h recorder)
2253 int ret = RECORDER_ERROR_NONE;
2254 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2255 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2257 if (!pc || !pc->cb_info) {
2258 LOGE("NULL handle");
2259 return RECORDER_ERROR_INVALID_PARAMETER;
2264 _recorder_msg_send(api, pc->cb_info, &ret);
2266 LOGD("ret : 0x%x", ret);
2272 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2274 int ret = RECORDER_ERROR_NONE;
2275 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2276 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2278 if (!pc || !pc->cb_info || callback == NULL) {
2279 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2280 return RECORDER_ERROR_INVALID_PARAMETER;
2283 LOGD("Enter, handle :%x", pc->remote_handle);
2285 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2286 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2288 _recorder_msg_send(api, pc->cb_info, &ret);
2290 LOGD("ret : 0x%x", ret);
2296 int recorder_unset_error_cb(recorder_h recorder)
2298 int ret = RECORDER_ERROR_NONE;
2299 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2300 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2302 if (!pc || !pc->cb_info) {
2303 LOGE("NULL handle");
2304 return RECORDER_ERROR_INVALID_PARAMETER;
2309 _recorder_msg_send(api, pc->cb_info, &ret);
2311 LOGD("ret : 0x%x", ret);
2317 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
2319 int ret = RECORDER_ERROR_NONE;
2320 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2321 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2323 if (!pc || !pc->cb_info || callback == NULL) {
2324 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2325 return RECORDER_ERROR_INVALID_PARAMETER;
2328 LOGD("Enter, handle :%x", pc->remote_handle);
2330 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2331 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2333 _recorder_msg_send(api, pc->cb_info, &ret);
2335 LOGD("ret : 0x%x", ret);
2341 int recorder_unset_recording_status_cb(recorder_h recorder)
2343 int ret = RECORDER_ERROR_NONE;
2344 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2345 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2347 if (!pc || !pc->cb_info) {
2348 LOGE("NULL handle");
2349 return RECORDER_ERROR_INVALID_PARAMETER;
2354 _recorder_msg_send(api, pc->cb_info, &ret);
2356 LOGD("ret : 0x%x", ret);
2362 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
2364 int ret = RECORDER_ERROR_NONE;
2365 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2366 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2368 if (!pc || !pc->cb_info || callback == NULL) {
2369 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2370 return RECORDER_ERROR_INVALID_PARAMETER;
2373 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2374 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2376 _recorder_msg_send(api, pc->cb_info, &ret);
2378 LOGD("ret : 0x%x", ret);
2384 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2386 int ret = RECORDER_ERROR_NONE;
2387 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2388 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2390 if (!pc || !pc->cb_info) {
2391 LOGE("NULL handle");
2392 return RECORDER_ERROR_INVALID_PARAMETER;
2397 _recorder_msg_send(api, pc->cb_info, &ret);
2399 LOGD("ret : 0x%x", ret);
2405 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2407 int ret = RECORDER_ERROR_NONE;
2408 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2409 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2411 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2412 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2413 return RECORDER_ERROR_INVALID_PARAMETER;
2416 LOGD("Enter, handle :%x", pc->remote_handle);
2418 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2419 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2421 _recorder_msg_send(api, pc->cb_info, &ret);
2423 LOGD("ret : 0x%x", ret);
2429 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2431 int ret = RECORDER_ERROR_NONE;
2432 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2433 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2434 recorder_msg_param param;
2436 if (!pc || !pc->cb_info) {
2437 LOGE("NULL handle");
2438 return RECORDER_ERROR_INVALID_PARAMETER;
2443 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2445 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2447 LOGD("ret : 0x%x", ret);
2453 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2455 int ret = RECORDER_ERROR_NONE;
2456 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2457 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2458 recorder_msg_param param;
2460 if (!pc || !pc->cb_info) {
2461 LOGE("NULL handle");
2462 return RECORDER_ERROR_INVALID_PARAMETER;
2467 RECORDER_MSG_PARAM_SET(param, INT, second);
2469 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2471 LOGD("ret : 0x%x", ret);
2477 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2479 int ret = RECORDER_ERROR_NONE;
2480 int set_device = (int)device;
2481 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2482 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2483 recorder_msg_param param;
2485 if (!pc || !pc->cb_info) {
2486 LOGE("NULL handle");
2487 return RECORDER_ERROR_INVALID_PARAMETER;
2492 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2494 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2496 LOGD("ret : 0x%x", ret);
2502 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2504 int ret = RECORDER_ERROR_NONE;
2505 int set_codec = (int)codec;
2506 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2507 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2508 recorder_msg_param param;
2510 if (!pc || !pc->cb_info) {
2511 LOGE("NULL handle");
2512 return RECORDER_ERROR_INVALID_PARAMETER;
2517 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2519 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2521 LOGD("ret : 0x%x", ret);
2527 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2529 int ret = RECORDER_ERROR_NONE;
2530 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2531 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2533 if (!pc || !pc->cb_info) {
2534 LOGE("NULL handle");
2535 return RECORDER_ERROR_INVALID_PARAMETER;
2538 if (codec == NULL) {
2539 LOGE("codec is NULL");
2540 return RECORDER_ERROR_INVALID_PARAMETER;
2545 _recorder_msg_send(api, pc->cb_info, &ret);
2547 if (ret == RECORDER_ERROR_NONE)
2548 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2550 LOGD("ret : 0x%x, codec %d", ret, *codec);
2556 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2558 int ret = RECORDER_ERROR_NONE;
2559 int set_codec = (int)codec;
2560 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2561 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2562 recorder_msg_param param;
2564 if (!pc || !pc->cb_info) {
2565 LOGE("NULL handle");
2566 return RECORDER_ERROR_INVALID_PARAMETER;
2571 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2573 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2575 LOGD("ret : 0x%x", ret);
2581 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2583 int ret = RECORDER_ERROR_NONE;
2584 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
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;
2592 if (codec == NULL) {
2593 LOGE("codec is NULL");
2594 return RECORDER_ERROR_INVALID_PARAMETER;
2599 _recorder_msg_send(api, pc->cb_info, &ret);
2601 if (ret == RECORDER_ERROR_NONE)
2602 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2604 LOGD("ret : 0x%x, codec %d", ret, *codec);
2610 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2612 int ret = RECORDER_ERROR_NONE;
2613 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2614 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2615 recorder_msg_param param;
2617 if (!pc || !pc->cb_info) {
2618 LOGE("NULL handle");
2619 return RECORDER_ERROR_INVALID_PARAMETER;
2622 LOGD("ENTER, samplerate : %d", samplerate);
2624 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2626 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2628 LOGD("ret : 0x%x", ret);
2634 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2636 int ret = RECORDER_ERROR_NONE;
2637 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2638 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2639 recorder_msg_param param;
2641 if (!pc || !pc->cb_info) {
2642 LOGE("NULL handle");
2643 return RECORDER_ERROR_INVALID_PARAMETER;
2648 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2650 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2652 LOGD("ret : 0x%x", ret);
2658 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2660 int ret = RECORDER_ERROR_NONE;
2661 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2662 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2663 recorder_msg_param param;
2665 if (!pc || !pc->cb_info) {
2666 LOGE("NULL handle");
2667 return RECORDER_ERROR_INVALID_PARAMETER;
2672 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2674 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2676 LOGD("ret : 0x%x", ret);
2682 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2684 int ret = RECORDER_ERROR_NONE;
2685 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2686 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2688 if (!pc || !pc->cb_info) {
2689 LOGE("NULL handle");
2690 return RECORDER_ERROR_INVALID_PARAMETER;
2693 if (kbyte == NULL) {
2694 LOGE("NULL pointer kbyte");
2695 return RECORDER_ERROR_INVALID_PARAMETER;
2700 _recorder_msg_send(api, pc->cb_info, &ret);
2702 if (ret == RECORDER_ERROR_NONE)
2703 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2705 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2711 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2713 int ret = RECORDER_ERROR_NONE;
2714 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2715 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2717 if (!pc || !pc->cb_info) {
2718 LOGE("NULL handle");
2719 return RECORDER_ERROR_INVALID_PARAMETER;
2722 if (second == NULL) {
2723 LOGE("NULL pointer second");
2724 return RECORDER_ERROR_INVALID_PARAMETER;
2729 _recorder_msg_send(api, pc->cb_info, &ret);
2731 if (ret == RECORDER_ERROR_NONE)
2732 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2734 LOGD("ret : 0x%x, %d second", ret, *second);
2740 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2742 int ret = RECORDER_ERROR_NONE;
2743 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2744 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2746 if (!pc || !pc->cb_info) {
2747 LOGE("NULL handle");
2748 return RECORDER_ERROR_INVALID_PARAMETER;
2751 if (device == NULL) {
2752 LOGE("NULL pointer device");
2753 return RECORDER_ERROR_INVALID_PARAMETER;
2758 _recorder_msg_send(api, pc->cb_info, &ret);
2760 if (ret == RECORDER_ERROR_NONE)
2761 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2763 LOGD("ret : 0x%x, device %d", ret, *device);
2769 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2771 int ret = RECORDER_ERROR_NONE;
2772 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2773 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2775 if (!pc || !pc->cb_info) {
2776 LOGE("NULL handle");
2777 return RECORDER_ERROR_INVALID_PARAMETER;
2780 if (samplerate == NULL) {
2781 LOGE("NULL pointer handle");
2782 return RECORDER_ERROR_INVALID_PARAMETER;
2787 _recorder_msg_send(api, pc->cb_info, &ret);
2789 if (ret == RECORDER_ERROR_NONE)
2790 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
2792 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
2798 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2800 int ret = RECORDER_ERROR_NONE;
2801 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2802 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2804 if (!pc || !pc->cb_info) {
2805 LOGE("NULL handle");
2806 return RECORDER_ERROR_INVALID_PARAMETER;
2809 if (bitrate == NULL) {
2810 LOGE("NULL pointer");
2811 return RECORDER_ERROR_INVALID_PARAMETER;
2816 _recorder_msg_send(api, pc->cb_info, &ret);
2818 if (ret == RECORDER_ERROR_NONE)
2819 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
2821 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
2827 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
2829 int ret = RECORDER_ERROR_NONE;
2830 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
2831 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2833 if (!pc || !pc->cb_info) {
2834 LOGE("NULL handle");
2835 return RECORDER_ERROR_INVALID_PARAMETER;
2838 if (bitrate == NULL) {
2839 LOGE("NULL pointer");
2840 return RECORDER_ERROR_INVALID_PARAMETER;
2845 _recorder_msg_send(api, pc->cb_info, &ret);
2847 if (ret == RECORDER_ERROR_NONE)
2848 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
2850 LOGD("ret : 0x%x", ret);
2856 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
2858 int ret = RECORDER_ERROR_NONE;
2859 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2860 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
2862 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2863 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2864 return RECORDER_ERROR_INVALID_PARAMETER;
2867 LOGD("Enter, handle :%x", pc->remote_handle);
2869 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
2870 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
2872 _recorder_msg_send(api, pc->cb_info, &ret);
2874 LOGD("ret : 0x%x", ret);
2880 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
2882 int ret = RECORDER_ERROR_NONE;
2883 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2884 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
2886 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2887 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2888 return RECORDER_ERROR_INVALID_PARAMETER;
2891 LOGD("Enter, handle :%x", pc->remote_handle);
2893 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
2894 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
2896 _recorder_msg_send(api, pc->cb_info, &ret);
2898 LOGD("ret : 0x%x", ret);
2904 int recorder_attr_set_mute(recorder_h recorder, bool enable)
2906 int ret = RECORDER_ERROR_NONE;
2907 int set_enable = (int)enable;
2908 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
2909 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2910 recorder_msg_param param;
2912 if (!pc || !pc->cb_info) {
2913 LOGE("NULL handle");
2914 return RECORDER_ERROR_INVALID_PARAMETER;
2919 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
2921 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2923 LOGD("ret : 0x%x", ret);
2929 bool recorder_attr_is_muted(recorder_h recorder)
2932 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
2933 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2935 if (!pc || !pc->cb_info) {
2936 LOGE("NULL handle");
2942 _recorder_msg_send(api, pc->cb_info, &ret);
2944 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
2947 LOGD("ret : %d", ret);
2953 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
2955 int ret = RECORDER_ERROR_NONE;
2956 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
2957 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2958 recorder_msg_param param;
2960 if (!pc || !pc->cb_info) {
2961 LOGE("NULL handle");
2962 return RECORDER_ERROR_INVALID_PARAMETER;
2965 LOGD("ENTER - %.20lf", rate);
2967 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
2969 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2971 LOGD("ret : 0x%x", ret);
2977 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
2979 int ret = RECORDER_ERROR_NONE;
2980 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
2981 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2983 if (!pc || !pc->cb_info) {
2984 LOGE("NULL handle");
2985 return RECORDER_ERROR_INVALID_PARAMETER;
2989 LOGE("rate is NULL");
2990 return RECORDER_ERROR_INVALID_PARAMETER;
2995 _recorder_msg_send(api, pc->cb_info, &ret);
2996 if (ret == RECORDER_ERROR_NONE)
2997 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
2999 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3005 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3007 int ret = RECORDER_ERROR_NONE;
3008 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3009 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3010 recorder_msg_param param;
3012 if (!pc || !pc->cb_info) {
3013 LOGE("NULL handle");
3014 return RECORDER_ERROR_INVALID_PARAMETER;
3019 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3021 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3023 LOGD("ret : 0x%x", ret);
3029 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3031 int ret = RECORDER_ERROR_NONE;
3032 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3033 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3035 if (!pc || !pc->cb_info) {
3036 LOGE("NULL handle");
3037 return RECORDER_ERROR_INVALID_PARAMETER;
3040 if (channel_count == NULL) {
3041 LOGE("channel_count is NULL");
3042 return RECORDER_ERROR_INVALID_PARAMETER;
3047 _recorder_msg_send(api, pc->cb_info, &ret);
3049 if (ret == RECORDER_ERROR_NONE)
3050 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3052 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3058 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3060 int ret = RECORDER_ERROR_NONE;
3061 int set_orientation = (int)orientation;
3062 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3063 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3064 recorder_msg_param param;
3066 if (!pc || !pc->cb_info) {
3067 LOGE("NULL handle");
3068 return RECORDER_ERROR_INVALID_PARAMETER;
3073 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3075 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3077 LOGD("ret : 0x%x", ret);
3083 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3085 int ret = RECORDER_ERROR_NONE;
3086 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3087 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3089 if (!pc || !pc->cb_info) {
3090 LOGE("NULL handle");
3091 return RECORDER_ERROR_INVALID_PARAMETER;
3094 if (orientation == NULL) {
3095 LOGE("orientation is NULL");
3096 return RECORDER_ERROR_INVALID_PARAMETER;
3101 _recorder_msg_send(api, pc->cb_info, &ret);
3103 if (ret == RECORDER_ERROR_NONE)
3104 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3106 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3112 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3114 int ret = RECORDER_ERROR_NONE;
3116 int get_device_state = 0;
3117 char *send_msg = NULL;
3118 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3121 LOGE("NULL pointer");
3122 return RECORDER_ERROR_INVALID_PARAMETER;
3125 LOGD("Enter - type %d", type);
3127 sock_fd = muse_core_client_new();
3129 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3130 ret = RECORDER_ERROR_INVALID_OPERATION;
3131 goto _GET_DEVICE_STATE_EXIT;
3134 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3135 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3136 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3140 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3141 goto _GET_DEVICE_STATE_EXIT;
3144 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3146 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3148 muse_core_msg_json_factory_free(send_msg);
3152 LOGE("send msg failed %d", errno);
3153 ret = RECORDER_ERROR_INVALID_OPERATION;
3154 goto _GET_DEVICE_STATE_EXIT;
3157 ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3159 LOGE("recv msg failed %d", errno);
3160 ret = RECORDER_ERROR_INVALID_OPERATION;
3161 goto _GET_DEVICE_STATE_EXIT;
3164 if (!muse_recorder_msg_get(ret, recv_msg)) {
3165 LOGE("failed to get return value from msg [%s]", recv_msg);
3166 ret = RECORDER_ERROR_INVALID_OPERATION;
3167 goto _GET_DEVICE_STATE_EXIT;
3170 if (ret == RECORDER_ERROR_NONE) {
3171 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3172 *state = (recorder_device_state_e)get_device_state;
3173 LOGD("device type %d state %d", type, *state);
3175 LOGE("failed to get device state from msg [%s]", recv_msg);
3176 ret = RECORDER_ERROR_INVALID_OPERATION;
3179 LOGE("failed 0x%x", ret);
3182 _GET_DEVICE_STATE_EXIT:
3184 muse_core_connection_close(sock_fd);
3192 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3194 int ret = RECORDER_ERROR_NONE;
3195 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3196 recorder_cb_info *info = NULL;
3198 if (!callback || !cb_id) {
3199 LOGE("invalid pointer %p %p", callback, cb_id);
3200 return RECORDER_ERROR_INVALID_PARAMETER;
3203 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3205 /* check recorder support */
3206 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3207 if (ret != RECORDER_ERROR_NONE) {
3208 LOGE("get device state failed");
3209 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3213 info = g_new0(recorder_cb_info, 1);
3215 LOGE("info failed");
3216 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3220 info->id = ++g_rec_dev_state_changed_cb_id;
3221 info->callback = (void *)callback;
3222 info->user_data = user_data;
3226 /* subscribe dbus signal for camera state change */
3227 if (!g_rec_dev_state_changed_cb_conn) {
3228 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3229 if (!g_rec_dev_state_changed_cb_conn) {
3230 LOGE("failed to get gdbus connection");
3231 ret = RECORDER_ERROR_INVALID_OPERATION;
3235 LOGD("subscribe signal %s - %s - %s",
3236 MM_CAMCORDER_DBUS_OBJECT,
3237 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3238 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3240 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3241 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3242 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3243 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3244 LOGE("failed to get gdbus connection");
3245 ret = RECORDER_ERROR_INVALID_OPERATION;
3249 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3252 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3254 LOGD("callback id %d", info->id);
3257 if (ret != RECORDER_ERROR_NONE) {
3263 if (g_rec_dev_state_changed_cb_conn) {
3264 g_object_unref(g_rec_dev_state_changed_cb_conn);
3265 g_rec_dev_state_changed_cb_conn = NULL;
3269 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3275 int recorder_remove_device_state_changed_cb(int cb_id)
3277 int ret = RECORDER_ERROR_NONE;
3278 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3279 GList *tmp_list = NULL;
3280 recorder_cb_info *info = NULL;
3282 /* check recorder support */
3283 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3284 if (ret != RECORDER_ERROR_NONE) {
3285 LOGE("get device state failed");
3289 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3291 if (!g_rec_dev_state_changed_cb_list) {
3292 LOGE("there is no callback info");
3293 ret = RECORDER_ERROR_INVALID_OPERATION;
3297 tmp_list = g_rec_dev_state_changed_cb_list;
3300 info = tmp_list->data;
3301 tmp_list = tmp_list->next;
3308 if (info->id == cb_id) {
3309 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3314 if (!g_rec_dev_state_changed_cb_list) {
3315 /* no remained callback */
3316 if (g_rec_dev_state_changed_cb_conn) {
3317 /* unsubscribe signal */
3318 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3319 g_rec_dev_state_changed_cb_subscribe_id = 0;
3321 /* unref connection */
3322 g_object_unref(g_rec_dev_state_changed_cb_conn);
3323 g_rec_dev_state_changed_cb_conn = NULL;
3327 LOGD("id %d callback removed", cb_id);
3328 ret = RECORDER_ERROR_NONE;
3334 LOGE("id %d callback not found", cb_id);
3335 ret = RECORDER_ERROR_INVALID_PARAMETER;
3338 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);