2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <camera_internal.h>
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
25 #include <storage-internal.h>
26 #include <muse_recorder.h>
27 #include <muse_recorder_msg.h>
28 #include <muse_core_ipc.h>
29 #include <muse_core_module.h>
30 #include <recorder_private.h>
34 #include <tzplatform_config.h>
39 #define LOG_TAG "TIZEN_N_RECORDER"
41 /* for device changed callback */
42 static GMutex g_rec_dev_state_changed_cb_lock;
43 static GList *g_rec_dev_state_changed_cb_list;
44 static int g_rec_dev_state_changed_cb_id;
45 static GDBusConnection *g_rec_dev_state_changed_cb_conn;
46 static guint g_rec_dev_state_changed_cb_subscribe_id;
50 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
53 api < 0 || api >= MUSE_RECORDER_API_MAX) {
54 LOGE("invalid param %p %d", cb_info, api);
58 g_mutex_lock(&(cb_info->api_mutex[api]));
59 cb_info->api_waiting[api] += value;
60 g_mutex_unlock(&(cb_info->api_mutex[api]));
62 /*LOGD("api %d, value %d, waiting %d",
63 api, value, cb_info->api_waiting[api]);*/
69 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
70 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
71 const gchar *signal_name, GVariant *param, gpointer user_data)
74 recorder_type_e type = RECORDER_TYPE_AUDIO;
75 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
76 GList *tmp_list = NULL;
77 recorder_cb_info *info = NULL;
79 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
81 if (!g_rec_dev_state_changed_cb_list || !param) {
82 LOGW("no callback or NULL param %p", param);
86 /* get device type and state */
87 g_variant_get(param, "(i)", &value);
90 state = 0x0000ffff & value;
92 LOGD("type %d, state %d", type, state);
94 tmp_list = g_rec_dev_state_changed_cb_list;
97 info = (recorder_cb_info *)tmp_list->data;
100 if (info->callback) {
101 LOGD("start id[%d] callback", info->id);
102 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
103 LOGD("returned id[%d] callback", info->id);
105 LOGW("NULL callback for id %d", info->id);
109 tmp_list = tmp_list->next;
113 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
119 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
121 tbm_bo tmp_bo = NULL;
122 tbm_bo_handle tmp_bo_handle = {NULL, };
124 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
125 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
126 bufmgr, bo, bo_handle, tbm_key);
130 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
131 if (tmp_bo == NULL) {
132 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
136 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
137 if (tmp_bo_handle.ptr == NULL) {
138 LOGE("bo map failed %p", tmp_bo);
139 tbm_bo_unref(tmp_bo);
144 /* set bo and bo_handle */
146 *bo_handle = tmp_bo_handle;
151 static void _recorder_release_imported_bo(tbm_bo *bo)
153 if (bo == NULL || *bo == NULL) {
165 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
167 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
168 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
172 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
174 if (cb_info->user_cb[event] == NULL) {
175 LOGW("user callback for event %d is not set", event);
180 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
186 muse_recorder_msg_get(previous, recv_msg);
187 muse_recorder_msg_get(current, recv_msg);
188 muse_recorder_msg_get(by_policy, recv_msg);
190 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
191 (recorder_state_e)current,
193 cb_info->user_data[event]);
196 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
200 muse_recorder_msg_get(type, recv_msg);
202 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
203 cb_info->user_data[event]);
206 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
208 int64_t cb_elapsed_time = 0;
209 int64_t cb_file_size = 0;
211 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
212 muse_recorder_msg_get(cb_file_size, recv_msg);
214 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
215 (unsigned long long)cb_file_size,
216 cb_info->user_data[event]);
219 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
225 muse_recorder_msg_get(policy, recv_msg);
226 muse_recorder_msg_get(previous, recv_msg);
227 muse_recorder_msg_get(current, recv_msg);
229 if (policy == RECORDER_POLICY_SOUND)
230 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
231 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
232 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
233 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
234 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
236 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
237 (recorder_state_e)previous,
238 (recorder_state_e)current,
239 cb_info->user_data[event]);
242 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
250 tbm_bo_handle bo_handle = {.ptr = NULL};
251 char *send_msg = NULL;
253 muse_recorder_msg_get(tbm_key, recv_msg);
259 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
260 LOGE("tbm key %d import failed", tbm_key);
264 muse_recorder_msg_get(size, recv_msg);
265 muse_recorder_msg_get(format, recv_msg);
266 muse_recorder_msg_get(channel, recv_msg);
267 muse_recorder_msg_get(timestamp, recv_msg);
269 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
271 (audio_sample_type_e)format,
273 (unsigned int)timestamp,
274 cb_info->user_data[event]);
276 /* release imported bo */
277 _recorder_release_imported_bo(&bo);
280 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
281 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
283 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
284 LOGE("sending message failed");
286 muse_core_msg_json_factory_free(send_msg);
289 case MUSE_RECORDER_EVENT_TYPE_ERROR:
292 int current_state = 0;
294 muse_recorder_msg_get(error, recv_msg);
295 muse_recorder_msg_get(current_state, recv_msg);
297 if (error == RECORDER_ERROR_SOUND_POLICY)
298 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
299 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
300 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
301 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
302 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
304 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
305 (recorder_state_e)current_state,
306 cb_info->user_data[event]);
309 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
313 muse_recorder_msg_get(codec, recv_msg);
315 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
316 cb_info->user_cb[event] = NULL;
317 cb_info->user_data[event] = NULL;
318 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
322 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
326 muse_recorder_msg_get(format, recv_msg);
328 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
329 cb_info->user_cb[event] = NULL;
330 cb_info->user_data[event] = NULL;
331 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
335 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
339 muse_recorder_msg_get(codec, recv_msg);
341 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
342 cb_info->user_cb[event] = NULL;
343 cb_info->user_data[event] = NULL;
344 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
348 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
353 muse_recorder_msg_get(width, recv_msg);
354 muse_recorder_msg_get(height, recv_msg);
356 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
357 cb_info->user_cb[event] = NULL;
358 cb_info->user_data[event] = NULL;
359 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
369 static bool _recorder_idle_event_callback(void *data)
371 recorder_cb_info_s *cb_info = NULL;
372 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
374 if (rec_idle_event == NULL) {
375 LOGE("rec_idle_event is NULL");
380 g_mutex_lock(&rec_idle_event->event_mutex);
382 cb_info = rec_idle_event->cb_info;
383 if (cb_info == NULL) {
384 LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
385 goto IDLE_EVENT_CALLBACK_DONE;
388 /* remove event from list */
389 g_mutex_lock(&cb_info->idle_event_mutex);
390 if (cb_info->idle_event_list)
391 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
393 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
394 g_mutex_unlock(&cb_info->idle_event_mutex);
397 _recorder_client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
399 /* send signal for waiting thread */
400 g_cond_signal(&cb_info->idle_event_cond);
402 IDLE_EVENT_CALLBACK_DONE:
403 /* unlock and release event */
404 g_mutex_unlock(&rec_idle_event->event_mutex);
405 g_mutex_clear(&rec_idle_event->event_mutex);
407 g_free(rec_idle_event);
408 rec_idle_event = NULL;
414 static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
416 recorder_idle_event_s *rec_idle_event = NULL;
421 if (cb_info == NULL) {
422 LOGE("cb_info is NULL");
426 g_mutex_lock(&cb_info->idle_event_mutex);
428 if (cb_info->idle_event_list == NULL) {
431 list = cb_info->idle_event_list;
434 rec_idle_event = list->data;
435 list = g_list_next(list);
437 if (!rec_idle_event) {
438 LOGW("The event is NULL");
442 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
445 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
447 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
448 LOGW("signal received");
455 ret = g_idle_remove_by_data(rec_idle_event);
457 LOGD("remove event %p, ret %d", rec_idle_event, ret);
460 rec_idle_event->cb_info = NULL;
461 LOGW("idle cb for event %p will be called later", rec_idle_event);
464 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
466 g_mutex_unlock(&rec_idle_event->event_mutex);
469 g_mutex_clear(&rec_idle_event->event_mutex);
471 g_free(rec_idle_event);
472 rec_idle_event = NULL;
474 LOGD("remove event done");
478 g_list_free(cb_info->idle_event_list);
479 cb_info->idle_event_list = NULL;
482 g_mutex_unlock(&cb_info->idle_event_mutex);
488 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
490 recorder_message_s *rec_msg = NULL;
492 if (!cb_info || !msg) {
493 LOGE("NULL pointer %p %p", cb_info, msg);
497 rec_msg = g_new0(recorder_message_s, 1);
499 LOGE("failed to alloc rec_msg for [%s]", msg);
504 rec_msg->event = event;
505 rec_msg->event_class = event_class;
507 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
509 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
511 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
512 g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
513 g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
514 g_cond_signal(&cb_info->audio_stream_cb_info.cond);
515 g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
517 g_mutex_lock(&cb_info->msg_handler_info.mutex);
518 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
519 g_cond_signal(&cb_info->msg_handler_info.cond);
520 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
529 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
531 if (!cb_info || !msg) {
532 LOGE("NULL pointer %p %p", cb_info, msg);
537 case MUSE_RECORDER_API_GET_STATE:
540 muse_recorder_msg_get(get_state, msg);
541 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
544 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
548 muse_recorder_msg_get(get_width, msg);
549 muse_recorder_msg_get(get_height, msg);
550 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
551 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
554 case MUSE_RECORDER_API_GET_FILE_FORMAT:
557 muse_recorder_msg_get(get_format, msg);
558 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
561 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
564 muse_recorder_msg_get(get_codec, msg);
565 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
568 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
571 muse_recorder_msg_get(get_codec, msg);
572 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
575 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
578 muse_recorder_msg_get(get_kbyte, msg);
579 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
582 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
585 muse_recorder_msg_get(get_second, msg);
586 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
589 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
592 muse_recorder_msg_get(get_device, msg);
593 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
596 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
598 int get_samplerate = 0;
599 muse_recorder_msg_get(get_samplerate, msg);
600 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
603 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
606 muse_recorder_msg_get(get_bitrate, msg);
607 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
610 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
613 muse_recorder_msg_get(get_bitrate, msg);
614 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
617 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
620 muse_recorder_msg_get_double(get_rate, msg);
621 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
624 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
626 int get_channel_count = 0;
627 muse_recorder_msg_get(get_channel_count, msg);
628 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
631 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
633 int get_orientation = 0;
634 muse_recorder_msg_get(get_orientation, msg);
635 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
638 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
640 double get_level = 0.0;
641 muse_recorder_msg_get_double(get_level, msg);
642 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
645 case MUSE_RECORDER_API_GET_FILENAME:
647 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
648 muse_recorder_msg_get_string(get_filename, msg);
649 if (cb_info->get_filename) {
650 free(cb_info->get_filename);
651 cb_info->get_filename = NULL;
653 cb_info->get_filename = strdup(get_filename);
664 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
666 int ret = RECORDER_ERROR_NONE;
670 int event_class = -1;
672 if (!cb_info || !msg) {
673 LOGE("invalid ptr %p %p", cb_info, msg);
677 /*LOGD("msg [%s]", msg);*/
679 if (!muse_recorder_msg_get(api, msg)) {
680 LOGE("failed to get recorder api");
684 if (api == MUSE_RECORDER_CB_EVENT) {
685 if (!muse_recorder_msg_get(event, msg) ||
686 !muse_recorder_msg_get(event_class, msg)) {
687 LOGE("failed to get event or event_class [%s]", msg);
691 if (!muse_recorder_msg_get(api_class, msg)) {
692 LOGE("failed to get api_class [%s]", msg);
697 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
698 if (api >= MUSE_RECORDER_API_MAX) {
699 LOGE("invalid api %d", api);
703 if (!muse_recorder_msg_get(ret, msg)) {
704 LOGE("failed to get recorder ret");
708 g_mutex_lock(&cb_info->api_mutex[api]);
710 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
711 g_atomic_int_set(&cb_info->msg_recv_running, 0);
712 LOGD("get device state done. close client cb handler");
715 case MUSE_RECORDER_API_CREATE:
716 if (ret != RECORDER_ERROR_NONE) {
717 g_atomic_int_set(&cb_info->msg_recv_running, 0);
718 LOGE("create error 0x%x. closing..", ret);
721 case MUSE_RECORDER_API_DESTROY:
722 if (ret == RECORDER_ERROR_NONE) {
723 g_atomic_int_set(&cb_info->msg_recv_running, 0);
724 LOGD("destroy done. closing..");
728 __recorder_get_api_operation(api, cb_info, msg);
733 if (cb_info->api_waiting[api] > 0) {
734 cb_info->api_ret[api] = ret;
735 cb_info->api_activating[api] = 1;
737 g_cond_signal(&cb_info->api_cond[api]);
739 LOGE("no waiting for api [%d]", api);
742 g_mutex_unlock(&cb_info->api_mutex[api]);
743 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
744 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
746 LOGW("unknown recorder api %d and api_class %d", api, api_class);
753 static void *_recorder_msg_handler_func(gpointer data)
757 recorder_message_s *rec_msg = NULL;
758 recorder_idle_event_s *rec_idle_event = NULL;
759 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
760 recorder_cb_info_s *cb_info = NULL;
762 if (!handler_info || !handler_info->cb_info) {
763 LOGE("NULL handler %p", handler_info);
767 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
768 type = handler_info->type;
770 LOGD("t:%d start", type);
772 g_mutex_lock(&handler_info->mutex);
774 while (g_atomic_int_get(&handler_info->running)) {
775 if (g_queue_is_empty(handler_info->queue)) {
776 /*LOGD("signal wait...");*/
777 g_cond_wait(&handler_info->cond, &handler_info->mutex);
778 /*LOGD("signal received");*/
780 if (g_atomic_int_get(&handler_info->running) == 0) {
781 LOGD("stop event thread");
786 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
787 g_mutex_unlock(&handler_info->mutex);
788 if (rec_msg == NULL) {
789 LOGE("NULL message");
790 g_mutex_lock(&handler_info->mutex);
796 if (api < MUSE_RECORDER_API_MAX) {
799 g_mutex_lock(&cb_info->api_mutex[api]);
801 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
802 if (cb_info->api_waiting[api] > 0) {
803 cb_info->api_ret[api] = ret;
804 cb_info->api_activating[api] = 1;
806 /*LOGD("recorder api %d - return 0x%x", ret);*/
808 g_cond_signal(&cb_info->api_cond[api]);
810 LOGE("no waiting for api [%d]", api);
813 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
816 g_mutex_unlock(&cb_info->api_mutex[api]);
817 } else if (api == MUSE_RECORDER_CB_EVENT) {
818 switch (rec_msg->event_class) {
819 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
820 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
822 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
823 rec_idle_event = g_new0(recorder_idle_event_s, 1);
824 if (rec_idle_event == NULL) {
825 LOGE("event alloc failed");
829 rec_idle_event->event = rec_msg->event;
830 rec_idle_event->cb_info = cb_info;
831 g_mutex_init(&rec_idle_event->event_mutex);
832 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
834 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
836 g_mutex_lock(&cb_info->idle_event_mutex);
837 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
838 g_mutex_unlock(&cb_info->idle_event_mutex);
840 g_idle_add_full(G_PRIORITY_DEFAULT,
841 (GSourceFunc)_recorder_idle_event_callback,
842 (gpointer)rec_idle_event,
846 LOGE("unknown event class %d", rec_msg->event_class);
850 LOGE("unknown api[%d] message", api);
856 g_mutex_lock(&handler_info->mutex);
859 /* remove remained event */
860 while (!g_queue_is_empty(handler_info->queue)) {
861 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
863 LOGD("remove message %p", rec_msg);
867 LOGW("NULL message");
871 g_mutex_unlock(&handler_info->mutex);
879 static void *_recorder_msg_recv_func(gpointer data)
882 int single_length = 0;
883 int remained_length = 0;
884 char *recv_msg = NULL;
885 char *single_msg = NULL;
886 char *remained_msg = NULL;
890 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
892 if (cb_info == NULL) {
893 LOGE("cb_info NULL");
899 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
900 if (single_msg == NULL) {
901 LOGE("single_msg malloc failed");
902 goto CB_HANDLER_EXIT;
905 recv_msg = cb_info->recv_msg;
907 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
908 recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
909 if (recv_length <= 0) {
910 cb_info->is_server_connected = FALSE;
911 LOGE("receive msg failed - server disconnected");
915 recv_msg[recv_length] = '\0';
921 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
923 /* Need to split the combined entering msgs */
924 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
925 if (recv_msg[cur_pos] == '}') {
926 single_length = cur_pos - prev_pos + 1;
928 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
929 /* check remained msg */
930 if (remained_length > 0) {
932 strncpy(single_msg, remained_msg, remained_length);
933 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
934 single_msg[remained_length + single_length] = '\0';
939 strncpy(single_msg, recv_msg + prev_pos, single_length);
940 single_msg[single_length] = '\0';
941 LOGE("lost msg [%s], skip...", single_msg);
946 strncpy(single_msg, recv_msg + prev_pos, single_length);
947 single_msg[single_length] = '\0';
950 if (single_msg[0] == '{') {
952 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
953 __recorder_process_msg(cb_info, single_msg);
955 LOGE("invalid msg [%s]", single_msg);
958 LOGE("too long message [len %d] skip...", single_length);
961 prev_pos = cur_pos + 1;
965 /* check incompleted message */
966 if (recv_msg[recv_length - 1] != '}') {
967 remained_length = recv_length - prev_pos;
969 LOGW("incompleted message [len %d]", remained_length);
971 remained_msg = (char *)malloc(remained_length + 1);
973 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
974 remained_msg[remained_length] = '\0';
976 LOGE("failed to alloc for remained msg");
983 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
985 if (!cb_info->is_server_connected) {
986 /* send error msg for server disconnection */
987 char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
988 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
989 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
993 LOGE("error_msg failed");
994 goto CB_HANDLER_EXIT;
997 LOGE("add error msg for service disconnection done");
999 __recorder_add_msg_to_queue(cb_info,
1000 MUSE_RECORDER_CB_EVENT,
1001 MUSE_RECORDER_EVENT_TYPE_ERROR,
1002 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1005 muse_core_msg_json_factory_free(error_msg);
1008 LOGE("add error msg for service disconnection done");
1019 remained_msg = NULL;
1026 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1027 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1029 if (!handler_info || !thread_name || !cb_info) {
1030 LOGE("t:%d NULL %p %p %p",
1031 type, handler_info, thread_name, cb_info);
1037 handler_info->type = type;
1038 handler_info->queue = g_queue_new();
1039 if (handler_info->queue == NULL) {
1040 LOGE("t:%d queue failed", type);
1044 g_mutex_init(&handler_info->mutex);
1045 g_cond_init(&handler_info->cond);
1047 handler_info->cb_info = (void *)cb_info;
1048 g_atomic_int_set(&handler_info->running, 1);
1050 handler_info->thread = g_thread_try_new(thread_name,
1051 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1052 if (handler_info->thread == NULL) {
1053 LOGE("t:%d thread failed", type);
1055 g_mutex_clear(&handler_info->mutex);
1056 g_cond_clear(&handler_info->cond);
1057 g_queue_free(handler_info->queue);
1058 handler_info->queue = NULL;
1063 LOGD("t:%d done", type);
1069 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1073 if (!handler_info) {
1074 LOGE("NULL handler");
1078 if (!handler_info->thread) {
1079 LOGW("thread is not created");
1083 type = handler_info->type;
1085 LOGD("t:%d thread %p", type, handler_info->thread);
1087 g_mutex_lock(&handler_info->mutex);
1088 g_atomic_int_set(&handler_info->running, 0);
1089 g_cond_signal(&handler_info->cond);
1090 g_mutex_unlock(&handler_info->mutex);
1092 g_thread_join(handler_info->thread);
1093 g_thread_unref(handler_info->thread);
1094 handler_info->thread = NULL;
1096 g_mutex_clear(&handler_info->mutex);
1097 g_cond_clear(&handler_info->cond);
1098 g_queue_free(handler_info->queue);
1099 handler_info->queue = NULL;
1101 LOGD("t:%d done", type);
1107 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1109 recorder_cb_info_s *cb_info = NULL;
1112 g_return_val_if_fail(sockfd > 0, NULL);
1114 cb_info = g_new0(recorder_cb_info_s, 1);
1115 if (cb_info == NULL) {
1116 LOGE("cb_info failed");
1120 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1122 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1123 g_mutex_init(&cb_info->api_mutex[i]);
1124 g_cond_init(&cb_info->api_cond[i]);
1127 g_mutex_init(&cb_info->idle_event_mutex);
1128 g_cond_init(&cb_info->idle_event_cond);
1130 /* message handler thread */
1131 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1132 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1133 LOGE("msg_handler_info failed");
1137 /* message handler thread for audio stream callback */
1138 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1139 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1140 LOGE("audio_stream_cb_info failed");
1144 cb_info->fd = sockfd;
1146 /* message receive thread */
1147 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1148 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1149 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1150 if (cb_info->msg_recv_thread == NULL) {
1151 LOGE("message receive thread creation failed");
1155 cb_info->is_server_connected = TRUE;
1161 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1162 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1164 g_mutex_clear(&cb_info->idle_event_mutex);
1165 g_cond_clear(&cb_info->idle_event_cond);
1167 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1168 g_mutex_clear(&cb_info->api_mutex[i]);
1169 g_cond_clear(&cb_info->api_cond[i]);
1179 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1181 int ret = RECORDER_ERROR_NONE;
1184 /*LOGD("Enter api : %d", api);*/
1186 if (!cb_info->is_server_connected) {
1187 LOGE("server is disconnected");
1188 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1191 g_mutex_lock(&(cb_info->api_mutex[api]));
1193 if (cb_info->api_activating[api] == 0) {
1194 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1195 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1196 ret = cb_info->api_ret[api];
1197 cb_info->api_activating[api] = 0;
1199 /*LOGD("return value : 0x%x", ret);*/
1201 ret = RECORDER_ERROR_INVALID_OPERATION;
1203 LOGE("api %d was TIMED OUT!", api);
1206 ret = cb_info->api_ret[api];
1207 cb_info->api_activating[api] = 0;
1209 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1212 if (ret != RECORDER_ERROR_NONE) {
1213 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1215 if (ret == RECORDER_ERROR_SOUND_POLICY)
1216 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1217 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1218 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1219 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1220 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1223 g_mutex_unlock(&(cb_info->api_mutex[api]));
1229 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1234 if (!cb_info || !ret) {
1235 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1236 return RECORDER_ERROR_INVALID_PARAMETER;
1239 msg = muse_core_msg_json_factory_new(api, NULL);
1241 LOGE("msg creation failed: api %d", api);
1242 return RECORDER_ERROR_OUT_OF_MEMORY;
1245 /*LOGD("send msg %s", msg);*/
1247 if (cb_info->is_server_connected) {
1248 __recorder_update_api_waiting(cb_info, api, 1);
1250 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1254 LOGE("message send failed");
1255 *ret = RECORDER_ERROR_INVALID_OPERATION;
1257 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1260 __recorder_update_api_waiting(cb_info, api, -1);
1262 muse_core_msg_json_factory_free(msg);
1264 return RECORDER_ERROR_NONE;
1268 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1273 if (!cb_info || !ret || !param) {
1274 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1275 return RECORDER_ERROR_INVALID_PARAMETER;
1278 /*LOGD("type %d, name %s", param->type, param->name);*/
1280 switch (param->type) {
1282 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1284 case MUSE_TYPE_DOUBLE:
1285 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1287 case MUSE_TYPE_STRING:
1288 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1291 LOGE("unknown type %d", param->type);
1296 LOGE("msg creation failed: api %d, type %d, param name %s",
1297 api, param->type, param->name);
1298 return RECORDER_ERROR_OUT_OF_MEMORY;
1301 /*LOGD("send msg %s", msg);*/
1303 if (cb_info->is_server_connected) {
1304 __recorder_update_api_waiting(cb_info, api, 1);
1306 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1310 LOGE("message send failed");
1311 *ret = RECORDER_ERROR_INVALID_OPERATION;
1313 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1316 __recorder_update_api_waiting(cb_info, api, -1);
1318 muse_core_msg_json_factory_free(msg);
1320 return RECORDER_ERROR_NONE;
1324 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1328 g_return_if_fail(cb_info != NULL);
1330 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1332 g_thread_join(cb_info->msg_recv_thread);
1333 g_thread_unref(cb_info->msg_recv_thread);
1334 cb_info->msg_recv_thread = NULL;
1336 LOGD("msg_recv thread removed");
1338 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1339 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1341 g_mutex_clear(&cb_info->idle_event_mutex);
1342 g_cond_clear(&cb_info->idle_event_cond);
1344 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1345 g_mutex_clear(&cb_info->api_mutex[i]);
1346 g_cond_clear(&cb_info->api_cond[i]);
1349 if (cb_info->fd > -1) {
1350 muse_core_connection_close(cb_info->fd);
1354 if (cb_info->bufmgr) {
1355 tbm_bufmgr_deinit(cb_info->bufmgr);
1356 cb_info->bufmgr = NULL;
1358 if (cb_info->get_filename) {
1359 free(cb_info->get_filename);
1360 cb_info->get_filename = NULL;
1370 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1372 char **root_directory = (char **)user_data;
1374 if (root_directory == NULL) {
1375 LOGE("user data is NULL");
1379 LOGD("storage id %d, type %d, state %d, path %s",
1380 storage_id, type, state, path ? path : "NULL");
1382 if (type == STORAGE_TYPE_INTERNAL && path) {
1383 if (*root_directory) {
1384 free(*root_directory);
1385 *root_directory = NULL;
1388 *root_directory = strdup(path);
1389 if (*root_directory) {
1390 LOGD("get root directory %s", *root_directory);
1393 LOGE("strdup %s failed", path);
1400 static int _recorder_client_get_root_directory(char **root_directory)
1402 int ret = STORAGE_ERROR_NONE;
1404 if (root_directory == NULL) {
1405 LOGE("user data is NULL");
1409 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1410 if (ret != STORAGE_ERROR_NONE) {
1411 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1418 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1420 int ret = RECORDER_ERROR_NONE;
1421 int destroy_ret = RECORDER_ERROR_NONE;
1424 char *send_msg = NULL;
1425 char *root_directory = NULL;
1426 intptr_t camera_handle = 0;
1427 intptr_t handle = 0;
1428 tbm_bufmgr bufmgr = NULL;
1429 recorder_cli_s *pc = NULL;
1430 recorder_msg_param param;
1432 LOGD("Enter - type %d", type);
1434 if (recorder == NULL) {
1435 LOGE("NULL pointer for recorder handle");
1436 return RECORDER_ERROR_INVALID_PARAMETER;
1439 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1440 LOGE("NULL pointer for camera handle on video recorder mode");
1441 return RECORDER_ERROR_INVALID_PARAMETER;
1444 bufmgr = tbm_bufmgr_init(-1);
1445 if (bufmgr == NULL) {
1446 LOGE("get tbm bufmgr failed");
1447 return RECORDER_ERROR_INVALID_OPERATION;
1450 pc = g_new0(recorder_cli_s, 1);
1452 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1453 goto _ERR_RECORDER_EXIT;
1456 sock_fd = muse_core_client_new();
1458 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1459 ret = RECORDER_ERROR_INVALID_OPERATION;
1460 goto _ERR_RECORDER_EXIT;
1463 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1464 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1465 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1466 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1467 MUSE_TYPE_INT, "pid", getpid(),
1470 pc->camera = camera;
1471 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1472 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1473 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1474 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1475 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1481 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1482 goto _ERR_RECORDER_EXIT;
1485 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1487 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1489 muse_core_msg_json_factory_free(send_msg);
1493 LOGE("send msg failed %d", errno);
1494 ret = RECORDER_ERROR_INVALID_OPERATION;
1495 goto _ERR_RECORDER_EXIT;
1498 pc->cb_info = _recorder_client_callback_new(sock_fd);
1499 if (pc->cb_info == NULL) {
1500 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1501 goto _ERR_RECORDER_EXIT;
1506 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1508 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1510 if (ret != RECORDER_ERROR_NONE) {
1511 LOGE("API_CREATE failed 0x%x", ret);
1512 goto _ERR_RECORDER_EXIT;
1515 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1517 LOGE("Receiving Handle Failed!!");
1518 ret = RECORDER_ERROR_INVALID_OPERATION;
1519 goto _ERR_RECORDER_AFTER_CREATE;
1522 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1523 LOGE("failed to get root directory of internal storage");
1524 ret = RECORDER_ERROR_INVALID_OPERATION;
1525 goto _ERR_RECORDER_AFTER_CREATE;
1528 LOGD("root directory [%s]", root_directory);
1530 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1532 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1534 if (ret != RECORDER_ERROR_NONE) {
1535 LOGE("failed to set root directory %s", root_directory);
1536 ret = RECORDER_ERROR_INVALID_OPERATION;
1537 goto _ERR_RECORDER_AFTER_CREATE;
1540 free(root_directory);
1541 root_directory = NULL;
1543 pc->remote_handle = handle;
1544 pc->cb_info->bufmgr = bufmgr;
1546 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1547 type, pc, pc->remote_handle);
1549 *recorder = (recorder_h)pc;
1553 return RECORDER_ERROR_NONE;
1555 _ERR_RECORDER_AFTER_CREATE:
1556 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1557 LOGE("destroy return 0x%x", destroy_ret);
1560 tbm_bufmgr_deinit(bufmgr);
1563 if (root_directory) {
1564 free(root_directory);
1565 root_directory = NULL;
1569 muse_core_connection_close(sock_fd);
1575 _recorder_client_callback_destroy(pc->cb_info);
1586 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1588 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1592 int recorder_create_audiorecorder(recorder_h *recorder)
1594 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1598 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1600 int ret = RECORDER_ERROR_NONE;
1601 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1602 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1604 if (!pc || !pc->cb_info) {
1605 LOGE("NULL handle");
1606 return RECORDER_ERROR_INVALID_PARAMETER;
1609 if (state == NULL) {
1610 LOGE("NULL pointer state");
1611 return RECORDER_ERROR_INVALID_PARAMETER;
1614 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1616 _recorder_msg_send(api, pc->cb_info, &ret);
1618 if (ret == RECORDER_ERROR_NONE)
1619 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1621 LOGD("ret : 0x%x, state : %d", ret, *state);
1627 int recorder_destroy(recorder_h recorder)
1629 int ret = RECORDER_ERROR_NONE;
1630 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1631 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1633 if (!pc || !pc->cb_info) {
1634 LOGE("NULL handle");
1635 return RECORDER_ERROR_INVALID_PARAMETER;
1640 if (pc->cb_info->is_server_connected)
1641 _recorder_msg_send(api, pc->cb_info, &ret);
1643 LOGW("server disconnected. release resource without send message.");
1645 if (ret == RECORDER_ERROR_NONE) {
1646 _recorder_remove_idle_event_all(pc->cb_info);
1647 _recorder_client_callback_destroy(pc->cb_info);
1652 LOGD("ret : 0x%x", ret);
1658 int recorder_prepare(recorder_h recorder)
1660 int ret = RECORDER_ERROR_NONE;
1661 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1662 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1664 if (!pc || !pc->cb_info) {
1665 LOGE("NULL handle");
1666 return RECORDER_ERROR_INVALID_PARAMETER;
1671 _recorder_msg_send(api, pc->cb_info, &ret);
1673 LOGD("ret : 0x%x", ret);
1675 if (ret == RECORDER_ERROR_NONE && pc->camera)
1676 camera_start_evas_rendering(pc->camera);
1682 int recorder_unprepare(recorder_h recorder)
1684 int ret = RECORDER_ERROR_NONE;
1685 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1686 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1687 camera_state_e camera_state = CAMERA_STATE_NONE;
1689 if (!pc || !pc->cb_info) {
1690 LOGE("NULL handle");
1691 return RECORDER_ERROR_INVALID_PARAMETER;
1697 ret = camera_get_state(pc->camera, &camera_state);
1698 if (ret != CAMERA_ERROR_NONE) {
1699 LOGE("failed to get camera state 0x%x", ret);
1700 return RECORDER_ERROR_INVALID_OPERATION;
1703 if (camera_state == CAMERA_STATE_PREVIEW) {
1704 ret = camera_stop_evas_rendering(pc->camera, false);
1705 if (ret != CAMERA_ERROR_NONE) {
1706 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1707 return RECORDER_ERROR_INVALID_OPERATION;
1712 _recorder_msg_send(api, pc->cb_info, &ret);
1714 LOGD("ret : 0x%x", ret);
1720 int recorder_start(recorder_h recorder)
1722 int ret = RECORDER_ERROR_NONE;
1723 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1724 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1725 recorder_state_e current_state = RECORDER_STATE_NONE;
1727 if (!pc || !pc->cb_info) {
1728 LOGE("NULL handle");
1729 return RECORDER_ERROR_INVALID_PARAMETER;
1735 ret = recorder_get_state(recorder, ¤t_state);
1736 if (ret != RECORDER_ERROR_NONE) {
1737 LOGE("failed to get current state 0x%x", ret);
1738 return RECORDER_ERROR_INVALID_OPERATION;
1741 if (current_state == RECORDER_STATE_READY) {
1742 ret = camera_stop_evas_rendering(pc->camera, true);
1743 if (ret != CAMERA_ERROR_NONE) {
1744 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1745 return RECORDER_ERROR_INVALID_OPERATION;
1750 _recorder_msg_send(api, pc->cb_info, &ret);
1752 if (pc->camera && current_state == RECORDER_STATE_READY)
1753 camera_start_evas_rendering(pc->camera);
1755 LOGD("ret : 0x%x", ret);
1761 int recorder_pause(recorder_h recorder)
1763 int ret = RECORDER_ERROR_NONE;
1764 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1765 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1767 if (!pc || !pc->cb_info) {
1768 LOGE("NULL handle");
1769 return RECORDER_ERROR_INVALID_PARAMETER;
1774 _recorder_msg_send(api, pc->cb_info, &ret);
1776 LOGD("ret : 0x%x", ret);
1782 int recorder_commit(recorder_h recorder)
1784 int ret = RECORDER_ERROR_NONE;
1785 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1786 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1787 recorder_state_e current_state = RECORDER_STATE_NONE;
1789 if (!pc || !pc->cb_info) {
1790 LOGE("NULL handle");
1791 return RECORDER_ERROR_INVALID_PARAMETER;
1797 ret = recorder_get_state(recorder, ¤t_state);
1798 if (ret != RECORDER_ERROR_NONE) {
1799 LOGE("failed to get current state 0x%x", ret);
1800 return RECORDER_ERROR_INVALID_OPERATION;
1803 if (current_state >= RECORDER_STATE_RECORDING) {
1804 ret = camera_stop_evas_rendering(pc->camera, true);
1805 if (ret != CAMERA_ERROR_NONE) {
1806 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1807 return RECORDER_ERROR_INVALID_OPERATION;
1812 _recorder_msg_send(api, pc->cb_info, &ret);
1814 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1815 camera_start_evas_rendering(pc->camera);
1817 LOGD("ret : 0x%x", ret);
1823 int recorder_cancel(recorder_h recorder)
1825 int ret = RECORDER_ERROR_NONE;
1826 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1827 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1828 recorder_state_e current_state = RECORDER_STATE_NONE;
1830 if (!pc || !pc->cb_info) {
1831 LOGE("NULL handle");
1832 return RECORDER_ERROR_INVALID_PARAMETER;
1838 ret = recorder_get_state(recorder, ¤t_state);
1839 if (ret != RECORDER_ERROR_NONE) {
1840 LOGE("failed to get current state 0x%x", ret);
1841 return RECORDER_ERROR_INVALID_OPERATION;
1844 if (current_state >= RECORDER_STATE_RECORDING) {
1845 ret = camera_stop_evas_rendering(pc->camera, true);
1846 if (ret != CAMERA_ERROR_NONE) {
1847 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1848 return RECORDER_ERROR_INVALID_OPERATION;
1853 _recorder_msg_send(api, pc->cb_info, &ret);
1855 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1856 camera_start_evas_rendering(pc->camera);
1858 LOGD("ret : 0x%x", ret);
1864 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1866 int ret = RECORDER_ERROR_NONE;
1868 char *send_msg = NULL;
1869 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1870 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1872 if (!pc || !pc->cb_info) {
1873 LOGE("NULL handle");
1874 return RECORDER_ERROR_INVALID_PARAMETER;
1879 send_msg = muse_core_msg_json_factory_new(api,
1880 MUSE_TYPE_INT, "width", width,
1881 MUSE_TYPE_INT, "height", height,
1884 if (pc->cb_info->is_server_connected) {
1885 __recorder_update_api_waiting(pc->cb_info, api, 1);
1887 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1891 LOGE("message send failed");
1892 ret = RECORDER_ERROR_INVALID_OPERATION;
1894 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1897 __recorder_update_api_waiting(pc->cb_info, api, -1);
1899 muse_core_msg_json_factory_free(send_msg);
1901 LOGE("failed to create msg");
1902 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1905 LOGD("ret : 0x%x", ret);
1911 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1913 int ret = RECORDER_ERROR_NONE;
1914 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1915 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1917 if (!pc || !pc->cb_info) {
1918 LOGE("NULL handle");
1919 return RECORDER_ERROR_INVALID_PARAMETER;
1922 if (!width || !height) {
1923 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1924 return RECORDER_ERROR_INVALID_PARAMETER;
1929 _recorder_msg_send(api, pc->cb_info, &ret);
1931 if (ret == RECORDER_ERROR_NONE) {
1932 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1933 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1936 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1942 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1943 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1945 int ret = RECORDER_ERROR_NONE;
1946 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1947 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1949 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1950 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1951 return RECORDER_ERROR_INVALID_PARAMETER;
1954 LOGD("Enter, handle :%x", pc->remote_handle);
1956 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1957 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
1959 _recorder_msg_send(api, pc->cb_info, &ret);
1961 LOGD("ret : 0x%x", ret);
1967 int recorder_get_audio_level(recorder_h recorder, double *level)
1969 int ret = RECORDER_ERROR_NONE;
1970 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
1971 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1973 if (!pc || !pc->cb_info || level == NULL) {
1974 LOGE("NULL pointer %p %p", pc, level);
1975 return RECORDER_ERROR_INVALID_PARAMETER;
1980 _recorder_msg_send(api, pc->cb_info, &ret);
1982 if (ret == RECORDER_ERROR_NONE)
1983 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
1985 LOGD("ret : 0x%x, level %lf", ret, *level);
1991 int recorder_set_filename(recorder_h recorder, const char *filename)
1993 int ret = RECORDER_ERROR_NONE;
1994 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
1995 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1996 recorder_msg_param param;
1997 char set_filename[RECORDER_FILENAME_MAX] = {0, };
1999 if (!pc || !pc->cb_info) {
2000 LOGE("NULL handle");
2001 return RECORDER_ERROR_INVALID_PARAMETER;
2004 if (filename == NULL) {
2005 LOGE("filename is NULL");
2006 return RECORDER_ERROR_INVALID_PARAMETER;
2011 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2012 /* Cannot convert. Use original path. */
2013 strncpy(set_filename, filename, strlen(filename));
2015 /* Converted. Use converted path. */
2016 LOGD("Converted filename : %s -> %s", filename, set_filename);
2019 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2021 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2023 LOGD("ret : 0x%x", ret);
2029 int recorder_get_filename(recorder_h recorder, char **filename)
2031 int ret = RECORDER_ERROR_NONE;
2032 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2033 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2034 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2036 if (!pc || !pc->cb_info) {
2037 LOGE("NULL handle");
2038 return RECORDER_ERROR_INVALID_PARAMETER;
2041 if (filename == NULL) {
2042 LOGE("filename is NULL");
2043 return RECORDER_ERROR_INVALID_PARAMETER;
2048 _recorder_msg_send(api, pc->cb_info, &ret);
2050 if (ret == RECORDER_ERROR_NONE) {
2051 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2052 /* Cannot convert. Use original path. */
2053 *filename = pc->cb_info->get_filename;
2055 /* Converted. Use converted path. */
2056 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2057 *filename = strdup(compat_filename);
2058 free(pc->cb_info->get_filename);
2061 pc->cb_info->get_filename = NULL;
2064 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2070 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2072 int ret = RECORDER_ERROR_NONE;
2073 int set_format = (int)format;
2074 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2075 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2076 recorder_msg_param param;
2078 if (!pc || !pc->cb_info) {
2079 LOGE("NULL handle");
2080 return RECORDER_ERROR_INVALID_PARAMETER;
2083 LOGD("ENTER, set_format : %d", set_format);
2085 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2087 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2089 LOGD("ret : 0x%x", ret);
2094 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2096 int ret = RECORDER_ERROR_NONE;
2097 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2098 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2100 if (!pc || !pc->cb_info) {
2101 LOGE("NULL handle");
2102 return RECORDER_ERROR_INVALID_PARAMETER;
2105 if (format == NULL) {
2106 LOGE("NULL pointer data");
2107 return RECORDER_ERROR_INVALID_PARAMETER;
2112 _recorder_msg_send(api, pc->cb_info, &ret);
2114 if (ret == RECORDER_ERROR_NONE)
2115 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2117 LOGD("ret : 0x%x, format %d", ret, *format);
2123 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2125 int ret = RECORDER_ERROR_NONE;
2126 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2127 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2128 bool is_available = false;
2129 int stream_index = 0;
2130 char *stream_type = NULL;
2131 char *send_msg = NULL;
2134 if (!pc || !pc->cb_info || stream_info == NULL) {
2135 LOGE("NULL handle");
2136 return RECORDER_ERROR_INVALID_PARAMETER;
2141 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2142 if (ret != SOUND_MANAGER_ERROR_NONE) {
2143 LOGE("stream info verification failed");
2144 return RECORDER_ERROR_INVALID_OPERATION;
2147 if (is_available == false) {
2148 LOGE("stream information is not available");
2149 return RECORDER_ERROR_INVALID_OPERATION;
2152 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2153 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2155 LOGD("sound manager return [0x%x]", ret);
2157 if (ret == SOUND_MANAGER_ERROR_NONE) {
2158 send_msg = muse_core_msg_json_factory_new(api,
2159 MUSE_TYPE_STRING, "stream_type", stream_type,
2160 MUSE_TYPE_INT, "stream_index", stream_index,
2163 if (pc->cb_info->is_server_connected) {
2164 __recorder_update_api_waiting(pc->cb_info, api, 1);
2166 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2170 LOGE("message send failed");
2171 ret = RECORDER_ERROR_INVALID_OPERATION;
2173 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2176 __recorder_update_api_waiting(pc->cb_info, api, -1);
2178 muse_core_msg_json_factory_free(send_msg);
2180 LOGE("failed to create msg");
2181 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2184 ret = RECORDER_ERROR_INVALID_OPERATION;
2191 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
2193 int ret = RECORDER_ERROR_NONE;
2194 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2195 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2197 if (!pc || !pc->cb_info || callback == NULL) {
2198 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2199 return RECORDER_ERROR_INVALID_PARAMETER;
2202 LOGD("Enter, handle :%x", pc->remote_handle);
2204 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2205 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2207 _recorder_msg_send(api, pc->cb_info, &ret);
2209 LOGD("ret : 0x%x", ret);
2215 int recorder_unset_state_changed_cb(recorder_h recorder)
2217 int ret = RECORDER_ERROR_NONE;
2218 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2219 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2221 if (!pc || !pc->cb_info) {
2222 LOGE("NULL handle");
2223 return RECORDER_ERROR_INVALID_PARAMETER;
2228 _recorder_msg_send(api, pc->cb_info, &ret);
2230 LOGD("ret : 0x%x", ret);
2236 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2238 int ret = RECORDER_ERROR_NONE;
2239 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2240 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2242 if (!pc || !pc->cb_info || callback == NULL) {
2243 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2244 return RECORDER_ERROR_INVALID_PARAMETER;
2247 LOGD("Enter, handle :%x", pc->remote_handle);
2249 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2250 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2252 _recorder_msg_send(api, pc->cb_info, &ret);
2254 LOGD("ret : 0x%x", ret);
2260 int recorder_unset_interrupted_cb(recorder_h recorder)
2262 int ret = RECORDER_ERROR_NONE;
2263 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2264 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2266 if (!pc || !pc->cb_info) {
2267 LOGE("NULL handle");
2268 return RECORDER_ERROR_INVALID_PARAMETER;
2273 _recorder_msg_send(api, pc->cb_info, &ret);
2275 LOGD("ret : 0x%x", ret);
2281 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
2283 int ret = RECORDER_ERROR_NONE;
2284 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2285 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2287 if (!pc || !pc->cb_info || callback == NULL) {
2288 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2289 return RECORDER_ERROR_INVALID_PARAMETER;
2292 LOGD("Enter, handle :%x", pc->remote_handle);
2294 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2295 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2297 _recorder_msg_send(api, pc->cb_info, &ret);
2299 LOGD("ret : 0x%x", ret);
2305 int recorder_unset_audio_stream_cb(recorder_h recorder)
2307 int ret = RECORDER_ERROR_NONE;
2308 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2309 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2311 if (!pc || !pc->cb_info) {
2312 LOGE("NULL handle");
2313 return RECORDER_ERROR_INVALID_PARAMETER;
2318 _recorder_msg_send(api, pc->cb_info, &ret);
2320 LOGD("ret : 0x%x", ret);
2326 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2328 int ret = RECORDER_ERROR_NONE;
2329 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2330 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2332 if (!pc || !pc->cb_info || callback == NULL) {
2333 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2334 return RECORDER_ERROR_INVALID_PARAMETER;
2337 LOGD("Enter, handle :%x", pc->remote_handle);
2339 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2340 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2342 _recorder_msg_send(api, pc->cb_info, &ret);
2344 LOGD("ret : 0x%x", ret);
2350 int recorder_unset_error_cb(recorder_h recorder)
2352 int ret = RECORDER_ERROR_NONE;
2353 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2354 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2356 if (!pc || !pc->cb_info) {
2357 LOGE("NULL handle");
2358 return RECORDER_ERROR_INVALID_PARAMETER;
2363 _recorder_msg_send(api, pc->cb_info, &ret);
2365 LOGD("ret : 0x%x", ret);
2371 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
2373 int ret = RECORDER_ERROR_NONE;
2374 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2375 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2377 if (!pc || !pc->cb_info || callback == NULL) {
2378 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2379 return RECORDER_ERROR_INVALID_PARAMETER;
2382 LOGD("Enter, handle :%x", pc->remote_handle);
2384 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2385 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2387 _recorder_msg_send(api, pc->cb_info, &ret);
2389 LOGD("ret : 0x%x", ret);
2395 int recorder_unset_recording_status_cb(recorder_h recorder)
2397 int ret = RECORDER_ERROR_NONE;
2398 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2399 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2401 if (!pc || !pc->cb_info) {
2402 LOGE("NULL handle");
2403 return RECORDER_ERROR_INVALID_PARAMETER;
2408 _recorder_msg_send(api, pc->cb_info, &ret);
2410 LOGD("ret : 0x%x", ret);
2416 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
2418 int ret = RECORDER_ERROR_NONE;
2419 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2420 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2422 if (!pc || !pc->cb_info || callback == NULL) {
2423 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2424 return RECORDER_ERROR_INVALID_PARAMETER;
2427 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2428 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2430 _recorder_msg_send(api, pc->cb_info, &ret);
2432 LOGD("ret : 0x%x", ret);
2438 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2440 int ret = RECORDER_ERROR_NONE;
2441 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2442 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2444 if (!pc || !pc->cb_info) {
2445 LOGE("NULL handle");
2446 return RECORDER_ERROR_INVALID_PARAMETER;
2451 _recorder_msg_send(api, pc->cb_info, &ret);
2453 LOGD("ret : 0x%x", ret);
2459 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2461 int ret = RECORDER_ERROR_NONE;
2462 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2463 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2465 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2466 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2467 return RECORDER_ERROR_INVALID_PARAMETER;
2470 LOGD("Enter, handle :%x", pc->remote_handle);
2472 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2473 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2475 _recorder_msg_send(api, pc->cb_info, &ret);
2477 LOGD("ret : 0x%x", ret);
2483 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2485 int ret = RECORDER_ERROR_NONE;
2486 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2487 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2488 recorder_msg_param param;
2490 if (!pc || !pc->cb_info) {
2491 LOGE("NULL handle");
2492 return RECORDER_ERROR_INVALID_PARAMETER;
2497 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2499 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2501 LOGD("ret : 0x%x", ret);
2507 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2509 int ret = RECORDER_ERROR_NONE;
2510 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2511 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2512 recorder_msg_param param;
2514 if (!pc || !pc->cb_info) {
2515 LOGE("NULL handle");
2516 return RECORDER_ERROR_INVALID_PARAMETER;
2521 RECORDER_MSG_PARAM_SET(param, INT, second);
2523 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2525 LOGD("ret : 0x%x", ret);
2531 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2533 int ret = RECORDER_ERROR_NONE;
2534 int set_device = (int)device;
2535 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2536 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2537 recorder_msg_param param;
2539 if (!pc || !pc->cb_info) {
2540 LOGE("NULL handle");
2541 return RECORDER_ERROR_INVALID_PARAMETER;
2546 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2548 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2550 LOGD("ret : 0x%x", ret);
2556 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_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_AUDIO_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_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2583 int ret = RECORDER_ERROR_NONE;
2584 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_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_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2604 LOGD("ret : 0x%x, codec %d", ret, *codec);
2610 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2612 int ret = RECORDER_ERROR_NONE;
2613 int set_codec = (int)codec;
2614 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2615 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2616 recorder_msg_param param;
2618 if (!pc || !pc->cb_info) {
2619 LOGE("NULL handle");
2620 return RECORDER_ERROR_INVALID_PARAMETER;
2625 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2627 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2629 LOGD("ret : 0x%x", ret);
2635 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2637 int ret = RECORDER_ERROR_NONE;
2638 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2639 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2641 if (!pc || !pc->cb_info) {
2642 LOGE("NULL handle");
2643 return RECORDER_ERROR_INVALID_PARAMETER;
2646 if (codec == NULL) {
2647 LOGE("codec is NULL");
2648 return RECORDER_ERROR_INVALID_PARAMETER;
2653 _recorder_msg_send(api, pc->cb_info, &ret);
2655 if (ret == RECORDER_ERROR_NONE)
2656 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2658 LOGD("ret : 0x%x, codec %d", ret, *codec);
2664 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2666 int ret = RECORDER_ERROR_NONE;
2667 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2668 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2669 recorder_msg_param param;
2671 if (!pc || !pc->cb_info) {
2672 LOGE("NULL handle");
2673 return RECORDER_ERROR_INVALID_PARAMETER;
2676 LOGD("ENTER, samplerate : %d", samplerate);
2678 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2680 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2682 LOGD("ret : 0x%x", ret);
2688 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2690 int ret = RECORDER_ERROR_NONE;
2691 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2692 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2693 recorder_msg_param param;
2695 if (!pc || !pc->cb_info) {
2696 LOGE("NULL handle");
2697 return RECORDER_ERROR_INVALID_PARAMETER;
2702 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2704 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2706 LOGD("ret : 0x%x", ret);
2712 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2714 int ret = RECORDER_ERROR_NONE;
2715 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2716 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2717 recorder_msg_param param;
2719 if (!pc || !pc->cb_info) {
2720 LOGE("NULL handle");
2721 return RECORDER_ERROR_INVALID_PARAMETER;
2726 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2728 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2730 LOGD("ret : 0x%x", ret);
2736 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2738 int ret = RECORDER_ERROR_NONE;
2739 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2740 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2742 if (!pc || !pc->cb_info) {
2743 LOGE("NULL handle");
2744 return RECORDER_ERROR_INVALID_PARAMETER;
2747 if (kbyte == NULL) {
2748 LOGE("NULL pointer kbyte");
2749 return RECORDER_ERROR_INVALID_PARAMETER;
2754 _recorder_msg_send(api, pc->cb_info, &ret);
2756 if (ret == RECORDER_ERROR_NONE)
2757 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2759 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2765 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2767 int ret = RECORDER_ERROR_NONE;
2768 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2769 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2771 if (!pc || !pc->cb_info) {
2772 LOGE("NULL handle");
2773 return RECORDER_ERROR_INVALID_PARAMETER;
2776 if (second == NULL) {
2777 LOGE("NULL pointer second");
2778 return RECORDER_ERROR_INVALID_PARAMETER;
2783 _recorder_msg_send(api, pc->cb_info, &ret);
2785 if (ret == RECORDER_ERROR_NONE)
2786 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2788 LOGD("ret : 0x%x, %d second", ret, *second);
2794 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2796 int ret = RECORDER_ERROR_NONE;
2797 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2798 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2800 if (!pc || !pc->cb_info) {
2801 LOGE("NULL handle");
2802 return RECORDER_ERROR_INVALID_PARAMETER;
2805 if (device == NULL) {
2806 LOGE("NULL pointer device");
2807 return RECORDER_ERROR_INVALID_PARAMETER;
2812 _recorder_msg_send(api, pc->cb_info, &ret);
2814 if (ret == RECORDER_ERROR_NONE)
2815 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2817 LOGD("ret : 0x%x, device %d", ret, *device);
2823 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2825 int ret = RECORDER_ERROR_NONE;
2826 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2827 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2829 if (!pc || !pc->cb_info) {
2830 LOGE("NULL handle");
2831 return RECORDER_ERROR_INVALID_PARAMETER;
2834 if (samplerate == NULL) {
2835 LOGE("NULL pointer handle");
2836 return RECORDER_ERROR_INVALID_PARAMETER;
2841 _recorder_msg_send(api, pc->cb_info, &ret);
2843 if (ret == RECORDER_ERROR_NONE)
2844 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
2846 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
2852 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2854 int ret = RECORDER_ERROR_NONE;
2855 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2856 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2858 if (!pc || !pc->cb_info) {
2859 LOGE("NULL handle");
2860 return RECORDER_ERROR_INVALID_PARAMETER;
2863 if (bitrate == NULL) {
2864 LOGE("NULL pointer");
2865 return RECORDER_ERROR_INVALID_PARAMETER;
2870 _recorder_msg_send(api, pc->cb_info, &ret);
2872 if (ret == RECORDER_ERROR_NONE)
2873 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
2875 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
2881 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
2883 int ret = RECORDER_ERROR_NONE;
2884 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
2885 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2887 if (!pc || !pc->cb_info) {
2888 LOGE("NULL handle");
2889 return RECORDER_ERROR_INVALID_PARAMETER;
2892 if (bitrate == NULL) {
2893 LOGE("NULL pointer");
2894 return RECORDER_ERROR_INVALID_PARAMETER;
2899 _recorder_msg_send(api, pc->cb_info, &ret);
2901 if (ret == RECORDER_ERROR_NONE)
2902 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
2904 LOGD("ret : 0x%x", ret);
2910 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
2912 int ret = RECORDER_ERROR_NONE;
2913 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2914 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
2916 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2917 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2918 return RECORDER_ERROR_INVALID_PARAMETER;
2921 LOGD("Enter, handle :%x", pc->remote_handle);
2923 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
2924 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
2926 _recorder_msg_send(api, pc->cb_info, &ret);
2928 LOGD("ret : 0x%x", ret);
2934 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
2936 int ret = RECORDER_ERROR_NONE;
2937 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2938 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
2940 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2941 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2942 return RECORDER_ERROR_INVALID_PARAMETER;
2945 LOGD("Enter, handle :%x", pc->remote_handle);
2947 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
2948 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
2950 _recorder_msg_send(api, pc->cb_info, &ret);
2952 LOGD("ret : 0x%x", ret);
2958 int recorder_attr_set_mute(recorder_h recorder, bool enable)
2960 int ret = RECORDER_ERROR_NONE;
2961 int set_enable = (int)enable;
2962 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
2963 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2964 recorder_msg_param param;
2966 if (!pc || !pc->cb_info) {
2967 LOGE("NULL handle");
2968 return RECORDER_ERROR_INVALID_PARAMETER;
2973 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
2975 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2977 LOGD("ret : 0x%x", ret);
2983 bool recorder_attr_is_muted(recorder_h recorder)
2986 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
2987 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2989 if (!pc || !pc->cb_info) {
2990 LOGE("NULL handle");
2996 _recorder_msg_send(api, pc->cb_info, &ret);
2998 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3001 LOGD("ret : %d", ret);
3007 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3009 int ret = RECORDER_ERROR_NONE;
3010 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3011 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3012 recorder_msg_param param;
3014 if (!pc || !pc->cb_info) {
3015 LOGE("NULL handle");
3016 return RECORDER_ERROR_INVALID_PARAMETER;
3019 LOGD("ENTER - %.20lf", rate);
3021 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3023 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3025 LOGD("ret : 0x%x", ret);
3031 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3033 int ret = RECORDER_ERROR_NONE;
3034 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3035 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3037 if (!pc || !pc->cb_info) {
3038 LOGE("NULL handle");
3039 return RECORDER_ERROR_INVALID_PARAMETER;
3043 LOGE("rate is NULL");
3044 return RECORDER_ERROR_INVALID_PARAMETER;
3049 _recorder_msg_send(api, pc->cb_info, &ret);
3050 if (ret == RECORDER_ERROR_NONE)
3051 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3053 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3059 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3061 int ret = RECORDER_ERROR_NONE;
3062 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
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, channel_count);
3075 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3077 LOGD("ret : 0x%x", ret);
3083 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3085 int ret = RECORDER_ERROR_NONE;
3086 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
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 (channel_count == NULL) {
3095 LOGE("channel_count is NULL");
3096 return RECORDER_ERROR_INVALID_PARAMETER;
3101 _recorder_msg_send(api, pc->cb_info, &ret);
3103 if (ret == RECORDER_ERROR_NONE)
3104 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3106 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3112 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3114 int ret = RECORDER_ERROR_NONE;
3115 int set_orientation = (int)orientation;
3116 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3117 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3118 recorder_msg_param param;
3120 if (!pc || !pc->cb_info) {
3121 LOGE("NULL handle");
3122 return RECORDER_ERROR_INVALID_PARAMETER;
3127 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3129 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3131 LOGD("ret : 0x%x", ret);
3137 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3139 int ret = RECORDER_ERROR_NONE;
3140 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3141 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3143 if (!pc || !pc->cb_info) {
3144 LOGE("NULL handle");
3145 return RECORDER_ERROR_INVALID_PARAMETER;
3148 if (orientation == NULL) {
3149 LOGE("orientation is NULL");
3150 return RECORDER_ERROR_INVALID_PARAMETER;
3155 _recorder_msg_send(api, pc->cb_info, &ret);
3157 if (ret == RECORDER_ERROR_NONE)
3158 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3160 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3166 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3168 int ret = RECORDER_ERROR_NONE;
3170 int get_device_state = 0;
3171 char *send_msg = NULL;
3172 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3175 LOGE("NULL pointer");
3176 return RECORDER_ERROR_INVALID_PARAMETER;
3179 LOGD("Enter - type %d", type);
3181 sock_fd = muse_core_client_new();
3183 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3184 ret = RECORDER_ERROR_INVALID_OPERATION;
3185 goto _GET_DEVICE_STATE_EXIT;
3188 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3189 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3190 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3194 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3195 goto _GET_DEVICE_STATE_EXIT;
3198 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3200 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3202 muse_core_msg_json_factory_free(send_msg);
3206 LOGE("send msg failed %d", errno);
3207 ret = RECORDER_ERROR_INVALID_OPERATION;
3208 goto _GET_DEVICE_STATE_EXIT;
3211 ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3213 LOGE("recv msg failed %d", errno);
3214 ret = RECORDER_ERROR_INVALID_OPERATION;
3215 goto _GET_DEVICE_STATE_EXIT;
3218 if (!muse_recorder_msg_get(ret, recv_msg)) {
3219 LOGE("failed to get return value from msg [%s]", recv_msg);
3220 ret = RECORDER_ERROR_INVALID_OPERATION;
3221 goto _GET_DEVICE_STATE_EXIT;
3224 if (ret == RECORDER_ERROR_NONE) {
3225 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3226 *state = (recorder_device_state_e)get_device_state;
3227 LOGD("device type %d state %d", type, *state);
3229 LOGE("failed to get device state from msg [%s]", recv_msg);
3230 ret = RECORDER_ERROR_INVALID_OPERATION;
3233 LOGE("failed 0x%x", ret);
3236 _GET_DEVICE_STATE_EXIT:
3238 muse_core_connection_close(sock_fd);
3246 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3248 int ret = RECORDER_ERROR_NONE;
3249 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3250 recorder_cb_info *info = NULL;
3252 if (!callback || !cb_id) {
3253 LOGE("invalid pointer %p %p", callback, cb_id);
3254 return RECORDER_ERROR_INVALID_PARAMETER;
3257 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3259 /* check recorder support */
3260 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3261 if (ret != RECORDER_ERROR_NONE) {
3262 LOGE("get device state failed");
3263 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3267 info = g_new0(recorder_cb_info, 1);
3269 LOGE("info failed");
3270 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3274 info->id = ++g_rec_dev_state_changed_cb_id;
3275 info->callback = (void *)callback;
3276 info->user_data = user_data;
3280 /* subscribe dbus signal for camera state change */
3281 if (!g_rec_dev_state_changed_cb_conn) {
3282 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3283 if (!g_rec_dev_state_changed_cb_conn) {
3284 LOGE("failed to get gdbus connection");
3285 ret = RECORDER_ERROR_INVALID_OPERATION;
3289 LOGD("subscribe signal %s - %s - %s",
3290 MM_CAMCORDER_DBUS_OBJECT,
3291 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3292 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3294 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3295 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3296 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3297 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3298 LOGE("failed to get gdbus connection");
3299 ret = RECORDER_ERROR_INVALID_OPERATION;
3303 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3306 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3308 LOGD("callback id %d", info->id);
3311 if (ret != RECORDER_ERROR_NONE) {
3317 if (g_rec_dev_state_changed_cb_conn) {
3318 g_object_unref(g_rec_dev_state_changed_cb_conn);
3319 g_rec_dev_state_changed_cb_conn = NULL;
3323 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3329 int recorder_remove_device_state_changed_cb(int cb_id)
3331 int ret = RECORDER_ERROR_NONE;
3332 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3333 GList *tmp_list = NULL;
3334 recorder_cb_info *info = NULL;
3336 /* check recorder support */
3337 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3338 if (ret != RECORDER_ERROR_NONE) {
3339 LOGE("get device state failed");
3343 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3345 if (!g_rec_dev_state_changed_cb_list) {
3346 LOGE("there is no callback info");
3347 ret = RECORDER_ERROR_INVALID_OPERATION;
3351 tmp_list = g_rec_dev_state_changed_cb_list;
3354 info = tmp_list->data;
3355 tmp_list = tmp_list->next;
3362 if (info->id == cb_id) {
3363 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3368 if (!g_rec_dev_state_changed_cb_list) {
3369 /* no remained callback */
3370 if (g_rec_dev_state_changed_cb_conn) {
3371 /* unsubscribe signal */
3372 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3373 g_rec_dev_state_changed_cb_subscribe_id = 0;
3375 /* unref connection */
3376 g_object_unref(g_rec_dev_state_changed_cb_conn);
3377 g_rec_dev_state_changed_cb_conn = NULL;
3381 LOGD("id %d callback removed", cb_id);
3382 ret = RECORDER_ERROR_NONE;
3388 LOGE("id %d callback not found", cb_id);
3389 ret = RECORDER_ERROR_INVALID_PARAMETER;
3392 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);