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_MUXED_STREAM:
296 tbm_bo_handle bo_handle = {.ptr = NULL};
297 char *send_msg = NULL;
299 muse_recorder_msg_get(tbm_key, recv_msg);
305 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
306 LOGE("tbm key %d import failed", tbm_key);
310 muse_recorder_msg_get(size, recv_msg);
311 muse_recorder_msg_get(offset, recv_msg);
313 ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
314 size, (unsigned long long)offset, cb_info->user_data[event]);
316 /* release imported bo */
317 _recorder_release_imported_bo(&bo);
320 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
321 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
323 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
324 LOGE("sending message failed");
326 muse_core_msg_json_factory_free(send_msg);
329 LOGE("failed to create send msg for key %d", tbm_key);
334 case MUSE_RECORDER_EVENT_TYPE_ERROR:
337 int current_state = 0;
339 muse_recorder_msg_get(error, recv_msg);
340 muse_recorder_msg_get(current_state, recv_msg);
342 if (error == RECORDER_ERROR_SOUND_POLICY)
343 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
344 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
345 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
346 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
347 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
349 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
350 (recorder_state_e)current_state,
351 cb_info->user_data[event]);
355 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
359 muse_recorder_msg_get(codec, recv_msg);
361 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
362 cb_info->user_cb[event] = NULL;
363 cb_info->user_data[event] = NULL;
364 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
368 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
372 muse_recorder_msg_get(format, recv_msg);
374 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
375 cb_info->user_cb[event] = NULL;
376 cb_info->user_data[event] = NULL;
377 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
381 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
385 muse_recorder_msg_get(codec, recv_msg);
387 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
388 cb_info->user_cb[event] = NULL;
389 cb_info->user_data[event] = NULL;
390 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
394 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
399 muse_recorder_msg_get(width, recv_msg);
400 muse_recorder_msg_get(height, recv_msg);
402 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
403 cb_info->user_cb[event] = NULL;
404 cb_info->user_data[event] = NULL;
405 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
415 static bool _recorder_idle_event_callback(void *data)
417 recorder_cb_info_s *cb_info = NULL;
418 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
420 if (rec_idle_event == NULL) {
421 LOGE("rec_idle_event is NULL");
426 g_mutex_lock(&rec_idle_event->event_mutex);
428 cb_info = rec_idle_event->cb_info;
429 if (cb_info == NULL) {
430 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
431 goto IDLE_EVENT_CALLBACK_DONE;
434 /* remove event from list */
435 g_mutex_lock(&cb_info->idle_event_mutex);
437 if (cb_info->idle_event_list)
438 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
440 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
441 g_mutex_unlock(&cb_info->idle_event_mutex);
444 _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
446 /* send signal for waiting thread */
447 g_cond_signal(&cb_info->idle_event_cond);
449 IDLE_EVENT_CALLBACK_DONE:
450 /* unlock and release event */
451 g_mutex_unlock(&rec_idle_event->event_mutex);
452 g_mutex_clear(&rec_idle_event->event_mutex);
454 g_free(rec_idle_event);
455 rec_idle_event = NULL;
461 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
463 recorder_idle_event_s *rec_idle_event = NULL;
467 if (cb_info == NULL) {
468 LOGE("cb_info is NULL");
472 g_mutex_lock(&cb_info->idle_event_mutex);
474 if (cb_info->idle_event_list == NULL) {
477 list = cb_info->idle_event_list;
480 rec_idle_event = list->data;
481 list = g_list_next(list);
483 if (!rec_idle_event) {
484 LOGW("The event is NULL");
488 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
489 LOGW("lock failed, %p event is calling now", rec_idle_event);
491 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
493 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
494 LOGW("signal received");
501 LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
502 rec_idle_event, rec_idle_event->event);
504 rec_idle_event->cb_info = NULL;
506 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
508 g_mutex_unlock(&rec_idle_event->event_mutex);
511 g_list_free(cb_info->idle_event_list);
512 cb_info->idle_event_list = NULL;
515 g_mutex_unlock(&cb_info->idle_event_mutex);
521 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
523 recorder_message_s *rec_msg = NULL;
525 if (!cb_info || !msg) {
526 LOGE("NULL pointer %p %p", cb_info, msg);
530 rec_msg = g_new0(recorder_message_s, 1);
532 LOGE("failed to alloc rec_msg for [%s]", msg);
537 rec_msg->event = event;
538 rec_msg->event_class = event_class;
540 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
542 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
544 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
545 g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
546 g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
547 g_cond_signal(&cb_info->audio_stream_cb_info.cond);
548 g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
550 g_mutex_lock(&cb_info->msg_handler_info.mutex);
551 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
552 g_cond_signal(&cb_info->msg_handler_info.cond);
553 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
562 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
564 if (!cb_info || !msg) {
565 LOGE("NULL pointer %p %p", cb_info, msg);
570 case MUSE_RECORDER_API_GET_STATE:
573 muse_recorder_msg_get(get_state, msg);
574 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
577 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
581 muse_recorder_msg_get(get_width, msg);
582 muse_recorder_msg_get(get_height, msg);
583 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
584 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
587 case MUSE_RECORDER_API_GET_FILE_FORMAT:
590 muse_recorder_msg_get(get_format, msg);
591 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
594 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
597 muse_recorder_msg_get(get_codec, msg);
598 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
601 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
604 muse_recorder_msg_get(get_codec, msg);
605 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
608 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
611 muse_recorder_msg_get(get_kbyte, msg);
612 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
615 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
618 muse_recorder_msg_get(get_second, msg);
619 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
622 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
625 muse_recorder_msg_get(get_device, msg);
626 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
629 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
631 int get_samplerate = 0;
632 muse_recorder_msg_get(get_samplerate, msg);
633 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
636 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
639 muse_recorder_msg_get(get_bitrate, msg);
640 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
643 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
646 muse_recorder_msg_get(get_bitrate, msg);
647 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
650 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
653 muse_recorder_msg_get_double(get_rate, msg);
654 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
657 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
659 int get_channel_count = 0;
660 muse_recorder_msg_get(get_channel_count, msg);
661 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
664 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
666 int get_orientation = 0;
667 muse_recorder_msg_get(get_orientation, msg);
668 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
671 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
673 double get_level = 0.0;
674 muse_recorder_msg_get_double(get_level, msg);
675 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
678 case MUSE_RECORDER_API_GET_FILENAME:
680 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
681 muse_recorder_msg_get_string(get_filename, msg);
682 if (cb_info->get_filename) {
683 free(cb_info->get_filename);
684 cb_info->get_filename = NULL;
686 cb_info->get_filename = strdup(get_filename);
697 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
699 int ret = RECORDER_ERROR_NONE;
703 int event_class = -1;
705 if (!cb_info || !msg) {
706 LOGE("invalid ptr %p %p", cb_info, msg);
710 /*LOGD("msg [%s]", msg);*/
712 if (!muse_recorder_msg_get(api, msg)) {
713 LOGE("failed to get recorder api");
717 if (api == MUSE_RECORDER_CB_EVENT) {
718 if (!muse_recorder_msg_get(event, msg) ||
719 !muse_recorder_msg_get(event_class, msg)) {
720 LOGE("failed to get event or event_class [%s]", msg);
724 if (!muse_recorder_msg_get(api_class, msg)) {
725 LOGE("failed to get api_class [%s]", msg);
730 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
731 if (api >= MUSE_RECORDER_API_MAX) {
732 LOGE("invalid api %d", api);
736 if (!muse_recorder_msg_get(ret, msg)) {
737 LOGE("failed to get recorder ret");
741 g_mutex_lock(&cb_info->api_mutex[api]);
743 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
744 g_atomic_int_set(&cb_info->msg_recv_running, 0);
745 LOGD("get device state done. close client cb handler");
748 case MUSE_RECORDER_API_CREATE:
749 if (ret != RECORDER_ERROR_NONE) {
750 g_atomic_int_set(&cb_info->msg_recv_running, 0);
751 LOGE("create error 0x%x. closing..", ret);
754 case MUSE_RECORDER_API_DESTROY:
755 if (ret == RECORDER_ERROR_NONE) {
756 g_atomic_int_set(&cb_info->msg_recv_running, 0);
757 LOGD("destroy done. closing..");
761 __recorder_get_api_operation(api, cb_info, msg);
766 if (cb_info->api_waiting[api] > 0) {
767 cb_info->api_ret[api] = ret;
768 cb_info->api_activating[api] = 1;
770 g_cond_signal(&cb_info->api_cond[api]);
772 LOGE("no waiting for api [%d]", api);
775 g_mutex_unlock(&cb_info->api_mutex[api]);
776 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
777 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
779 LOGW("unknown recorder api %d and api_class %d", api, api_class);
786 static void *_recorder_msg_handler_func(gpointer data)
790 recorder_message_s *rec_msg = NULL;
791 recorder_idle_event_s *rec_idle_event = NULL;
792 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
793 recorder_cb_info_s *cb_info = NULL;
795 if (!handler_info || !handler_info->cb_info) {
796 LOGE("NULL handler %p", handler_info);
800 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
801 type = handler_info->type;
803 LOGD("t:%d start", type);
805 g_mutex_lock(&handler_info->mutex);
807 while (g_atomic_int_get(&handler_info->running)) {
808 if (g_queue_is_empty(handler_info->queue)) {
809 /*LOGD("signal wait...");*/
810 g_cond_wait(&handler_info->cond, &handler_info->mutex);
811 /*LOGD("signal received");*/
813 if (g_atomic_int_get(&handler_info->running) == 0) {
814 LOGD("stop event thread");
819 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
820 g_mutex_unlock(&handler_info->mutex);
821 if (rec_msg == NULL) {
822 LOGE("NULL message");
823 g_mutex_lock(&handler_info->mutex);
829 if (api < MUSE_RECORDER_API_MAX) {
832 g_mutex_lock(&cb_info->api_mutex[api]);
834 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
835 if (cb_info->api_waiting[api] > 0) {
836 cb_info->api_ret[api] = ret;
837 cb_info->api_activating[api] = 1;
839 /*LOGD("recorder api %d - return 0x%x", ret);*/
841 g_cond_signal(&cb_info->api_cond[api]);
843 LOGE("no waiting for api [%d]", api);
846 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
849 g_mutex_unlock(&cb_info->api_mutex[api]);
850 } else if (api == MUSE_RECORDER_CB_EVENT) {
851 switch (rec_msg->event_class) {
852 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
853 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
855 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
856 rec_idle_event = g_new0(recorder_idle_event_s, 1);
857 if (rec_idle_event == NULL) {
858 LOGE("event alloc failed");
862 rec_idle_event->event = rec_msg->event;
863 rec_idle_event->cb_info = cb_info;
864 g_mutex_init(&rec_idle_event->event_mutex);
865 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
867 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
869 g_mutex_lock(&cb_info->idle_event_mutex);
870 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
871 g_mutex_unlock(&cb_info->idle_event_mutex);
873 g_idle_add_full(G_PRIORITY_DEFAULT,
874 (GSourceFunc)_recorder_idle_event_callback,
875 (gpointer)rec_idle_event,
879 LOGE("unknown event class %d", rec_msg->event_class);
883 LOGE("unknown api[%d] message", api);
889 g_mutex_lock(&handler_info->mutex);
892 /* remove remained event */
893 while (!g_queue_is_empty(handler_info->queue)) {
894 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
896 LOGD("remove message %p", rec_msg);
900 LOGW("NULL message");
904 g_mutex_unlock(&handler_info->mutex);
912 static void *_recorder_msg_recv_func(gpointer data)
915 int single_length = 0;
916 int remained_length = 0;
917 char *recv_msg = NULL;
918 char *single_msg = NULL;
919 char *remained_msg = NULL;
923 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
925 if (cb_info == NULL) {
926 LOGE("cb_info NULL");
932 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
933 if (single_msg == NULL) {
934 LOGE("single_msg malloc failed");
935 goto CB_HANDLER_EXIT;
938 recv_msg = cb_info->recv_msg;
940 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
941 recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
942 if (recv_length <= 0) {
944 cb_info->is_server_connected = FALSE;
945 LOGE("receive msg failed - server disconnected");
950 recv_msg[recv_length] = '\0';
956 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
958 /* Need to split the combined entering msgs */
959 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
960 if (recv_msg[cur_pos] == '}') {
961 single_length = cur_pos - prev_pos + 1;
963 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
964 /* check remained msg */
965 if (remained_length > 0) {
968 strncpy(single_msg, remained_msg, remained_length);
969 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
970 single_msg[remained_length + single_length] = '\0';
975 strncpy(single_msg, recv_msg + prev_pos, single_length);
976 single_msg[single_length] = '\0';
977 LOGE("lost msg [%s], skip...", single_msg);
983 strncpy(single_msg, recv_msg + prev_pos, single_length);
984 single_msg[single_length] = '\0';
987 if (single_msg[0] == '{') {
989 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
990 __recorder_process_msg(cb_info, single_msg);
992 LOGE("invalid msg [%s]", single_msg);
995 LOGE("too long message [len %d] skip...", single_length);
998 prev_pos = cur_pos + 1;
1002 /* check incompleted message */
1003 if (recv_msg[recv_length - 1] != '}') {
1005 remained_length = recv_length - prev_pos;
1007 LOGW("incompleted message [len %d]", remained_length);
1009 remained_msg = (char *)malloc(remained_length + 1);
1011 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
1012 remained_msg[remained_length] = '\0';
1014 LOGE("failed to alloc for remained msg");
1018 remained_length = 0;
1022 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1024 if (!cb_info->is_server_connected) {
1026 /* send error msg for server disconnection */
1027 char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
1028 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1029 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1033 LOGE("error_msg failed");
1034 goto CB_HANDLER_EXIT;
1037 LOGE("add error msg for service disconnection done");
1039 __recorder_add_msg_to_queue(cb_info,
1040 MUSE_RECORDER_CB_EVENT,
1041 MUSE_RECORDER_EVENT_TYPE_ERROR,
1042 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1045 muse_core_msg_json_factory_free(error_msg);
1048 LOGE("add error msg for service disconnection done");
1060 remained_msg = NULL;
1067 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1068 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1070 if (!handler_info || !thread_name || !cb_info) {
1071 LOGE("t:%d NULL %p %p %p",
1072 type, handler_info, thread_name, cb_info);
1078 handler_info->type = type;
1079 handler_info->queue = g_queue_new();
1080 if (handler_info->queue == NULL) {
1081 LOGE("t:%d queue failed", type);
1085 g_mutex_init(&handler_info->mutex);
1086 g_cond_init(&handler_info->cond);
1088 handler_info->cb_info = (void *)cb_info;
1089 g_atomic_int_set(&handler_info->running, 1);
1091 handler_info->thread = g_thread_try_new(thread_name,
1092 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1093 if (handler_info->thread == NULL) {
1095 LOGE("t:%d thread failed", type);
1097 g_mutex_clear(&handler_info->mutex);
1098 g_cond_clear(&handler_info->cond);
1099 g_queue_free(handler_info->queue);
1100 handler_info->queue = NULL;
1106 LOGD("t:%d done", type);
1112 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1116 if (!handler_info) {
1117 LOGE("NULL handler");
1121 if (!handler_info->thread) {
1122 LOGW("thread is not created");
1126 type = handler_info->type;
1128 LOGD("t:%d thread %p", type, handler_info->thread);
1130 g_mutex_lock(&handler_info->mutex);
1131 g_atomic_int_set(&handler_info->running, 0);
1132 g_cond_signal(&handler_info->cond);
1133 g_mutex_unlock(&handler_info->mutex);
1135 g_thread_join(handler_info->thread);
1136 handler_info->thread = NULL;
1138 g_mutex_clear(&handler_info->mutex);
1139 g_cond_clear(&handler_info->cond);
1140 g_queue_free(handler_info->queue);
1141 handler_info->queue = NULL;
1143 LOGD("t:%d done", type);
1149 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1151 recorder_cb_info_s *cb_info = NULL;
1154 g_return_val_if_fail(sockfd > 0, NULL);
1156 cb_info = g_new0(recorder_cb_info_s, 1);
1157 if (cb_info == NULL) {
1158 LOGE("cb_info failed");
1162 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1164 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1165 g_mutex_init(&cb_info->api_mutex[i]);
1166 g_cond_init(&cb_info->api_cond[i]);
1169 g_mutex_init(&cb_info->idle_event_mutex);
1170 g_cond_init(&cb_info->idle_event_cond);
1172 /* message handler thread */
1173 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1174 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1175 LOGE("msg_handler_info failed");
1179 /* message handler thread for audio stream callback */
1180 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1181 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1182 LOGE("audio_stream_cb_info failed");
1186 cb_info->fd = sockfd;
1188 /* message receive thread */
1189 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1190 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1191 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1192 if (cb_info->msg_recv_thread == NULL) {
1193 LOGE("message receive thread creation failed");
1197 cb_info->is_server_connected = TRUE;
1203 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1204 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1206 g_mutex_clear(&cb_info->idle_event_mutex);
1207 g_cond_clear(&cb_info->idle_event_cond);
1209 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1210 g_mutex_clear(&cb_info->api_mutex[i]);
1211 g_cond_clear(&cb_info->api_cond[i]);
1222 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1224 int ret = RECORDER_ERROR_NONE;
1227 /*LOGD("Enter api : %d", api);*/
1229 if (!cb_info->is_server_connected) {
1230 LOGE("server is disconnected");
1231 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1234 g_mutex_lock(&(cb_info->api_mutex[api]));
1236 if (cb_info->api_activating[api] == 0) {
1237 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1238 LOGW("wait for api %d", api);
1239 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1240 ret = cb_info->api_ret[api];
1241 cb_info->api_activating[api] = 0;
1242 LOGW("api %d returned 0x%x", api, ret);
1244 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1245 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1246 ret = cb_info->api_ret[api];
1247 cb_info->api_activating[api] = 0;
1248 /*LOGD("return value : 0x%x", ret);*/
1250 ret = RECORDER_ERROR_INVALID_OPERATION;
1251 LOGE("api %d was TIMED OUT!", api);
1255 ret = cb_info->api_ret[api];
1256 cb_info->api_activating[api] = 0;
1258 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1261 if (ret != RECORDER_ERROR_NONE) {
1262 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1264 if (ret == RECORDER_ERROR_SOUND_POLICY)
1265 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1266 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1267 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1268 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1269 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1272 g_mutex_unlock(&(cb_info->api_mutex[api]));
1278 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1283 if (!cb_info || !ret) {
1284 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1285 return RECORDER_ERROR_INVALID_PARAMETER;
1288 msg = muse_core_msg_json_factory_new(api, NULL);
1290 LOGE("msg creation failed: api %d", api);
1291 return RECORDER_ERROR_OUT_OF_MEMORY;
1294 /*LOGD("send msg %s", msg);*/
1296 if (cb_info->is_server_connected) {
1297 __recorder_update_api_waiting(cb_info, api, 1);
1299 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1303 LOGE("message send failed");
1304 *ret = RECORDER_ERROR_INVALID_OPERATION;
1306 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1309 __recorder_update_api_waiting(cb_info, api, -1);
1311 muse_core_msg_json_factory_free(msg);
1313 return RECORDER_ERROR_NONE;
1317 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1322 if (!cb_info || !ret || !param) {
1323 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1324 return RECORDER_ERROR_INVALID_PARAMETER;
1327 /*LOGD("type %d, name %s", param->type, param->name);*/
1329 switch (param->type) {
1331 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1333 case MUSE_TYPE_DOUBLE:
1334 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1336 case MUSE_TYPE_STRING:
1337 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1340 LOGE("unknown type %d", param->type);
1345 LOGE("msg creation failed: api %d, type %d, param name %s",
1346 api, param->type, param->name);
1347 return RECORDER_ERROR_OUT_OF_MEMORY;
1350 /*LOGD("send msg %s", msg);*/
1352 if (cb_info->is_server_connected) {
1353 __recorder_update_api_waiting(cb_info, api, 1);
1355 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1359 LOGE("message send failed");
1360 *ret = RECORDER_ERROR_INVALID_OPERATION;
1362 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1365 __recorder_update_api_waiting(cb_info, api, -1);
1367 muse_core_msg_json_factory_free(msg);
1369 return RECORDER_ERROR_NONE;
1373 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1377 g_return_if_fail(cb_info != NULL);
1379 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1381 g_thread_join(cb_info->msg_recv_thread);
1382 cb_info->msg_recv_thread = NULL;
1384 LOGD("msg_recv thread removed");
1386 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1387 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1389 g_mutex_clear(&cb_info->idle_event_mutex);
1390 g_cond_clear(&cb_info->idle_event_cond);
1392 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1393 g_mutex_clear(&cb_info->api_mutex[i]);
1394 g_cond_clear(&cb_info->api_cond[i]);
1397 if (cb_info->fd > -1) {
1398 muse_core_connection_close(cb_info->fd);
1402 if (cb_info->bufmgr) {
1403 tbm_bufmgr_deinit(cb_info->bufmgr);
1404 cb_info->bufmgr = NULL;
1406 if (cb_info->get_filename) {
1407 free(cb_info->get_filename);
1408 cb_info->get_filename = NULL;
1418 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1420 char **root_directory = (char **)user_data;
1422 if (root_directory == NULL) {
1423 LOGE("user data is NULL");
1427 LOGD("storage id %d, type %d, state %d, path %s",
1428 storage_id, type, state, path ? path : "NULL");
1430 if (type == STORAGE_TYPE_INTERNAL && path) {
1431 if (*root_directory) {
1432 free(*root_directory);
1433 *root_directory = NULL;
1436 *root_directory = strdup(path);
1437 if (*root_directory) {
1438 LOGD("get root directory %s", *root_directory);
1441 LOGE("strdup %s failed", path);
1448 static int _recorder_client_get_root_directory(char **root_directory)
1450 int ret = STORAGE_ERROR_NONE;
1452 if (root_directory == NULL) {
1453 LOGE("user data is NULL");
1457 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1458 if (ret != STORAGE_ERROR_NONE) {
1459 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1466 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1468 int ret = RECORDER_ERROR_NONE;
1469 int destroy_ret = RECORDER_ERROR_NONE;
1472 char *send_msg = NULL;
1473 char *root_directory = NULL;
1474 intptr_t camera_handle = 0;
1475 intptr_t handle = 0;
1476 tbm_bufmgr bufmgr = NULL;
1477 recorder_cli_s *pc = NULL;
1478 recorder_msg_param param;
1480 LOGD("Enter - type %d", type);
1482 if (recorder == NULL) {
1483 LOGE("NULL pointer for recorder handle");
1484 return RECORDER_ERROR_INVALID_PARAMETER;
1487 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1488 LOGE("NULL pointer for camera handle on video recorder mode");
1489 return RECORDER_ERROR_INVALID_PARAMETER;
1492 bufmgr = tbm_bufmgr_init(-1);
1493 if (bufmgr == NULL) {
1494 LOGE("get tbm bufmgr failed");
1495 return RECORDER_ERROR_INVALID_OPERATION;
1498 pc = g_new0(recorder_cli_s, 1);
1500 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1501 goto _ERR_RECORDER_EXIT;
1504 sock_fd = muse_core_client_new();
1507 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1508 ret = RECORDER_ERROR_INVALID_OPERATION;
1509 goto _ERR_RECORDER_EXIT;
1513 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1514 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1515 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1516 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1517 MUSE_TYPE_INT, "pid", getpid(),
1520 pc->camera = camera;
1521 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1522 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1523 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1524 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1525 MUSE_TYPE_INT, "pid", getpid(),
1526 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1533 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1534 goto _ERR_RECORDER_EXIT;
1538 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1540 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1542 muse_core_msg_json_factory_free(send_msg);
1547 LOGE("send msg failed %d", errno);
1548 ret = RECORDER_ERROR_INVALID_OPERATION;
1549 goto _ERR_RECORDER_EXIT;
1553 pc->cb_info = _recorder_client_callback_new(sock_fd);
1554 if (pc->cb_info == NULL) {
1555 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1556 goto _ERR_RECORDER_EXIT;
1561 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_NO_TIMEOUT);
1563 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1565 if (ret != RECORDER_ERROR_NONE) {
1566 LOGE("API_CREATE failed 0x%x", ret);
1567 goto _ERR_RECORDER_EXIT;
1570 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1573 LOGE("Receiving Handle Failed!!");
1574 ret = RECORDER_ERROR_INVALID_OPERATION;
1575 goto _ERR_RECORDER_AFTER_CREATE;
1579 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1581 LOGE("failed to get root directory of internal storage");
1582 ret = RECORDER_ERROR_INVALID_OPERATION;
1583 goto _ERR_RECORDER_AFTER_CREATE;
1587 LOGD("root directory [%s]", root_directory);
1589 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1591 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1593 if (ret != RECORDER_ERROR_NONE) {
1594 LOGE("failed to set root directory %s", root_directory);
1595 ret = RECORDER_ERROR_INVALID_OPERATION;
1596 goto _ERR_RECORDER_AFTER_CREATE;
1599 free(root_directory);
1600 root_directory = NULL;
1602 pc->remote_handle = handle;
1603 pc->cb_info->bufmgr = bufmgr;
1605 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1606 type, pc, pc->remote_handle);
1608 *recorder = (recorder_h)pc;
1612 return RECORDER_ERROR_NONE;
1614 _ERR_RECORDER_AFTER_CREATE:
1615 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1616 LOGE("destroy return 0x%x", destroy_ret);
1619 tbm_bufmgr_deinit(bufmgr);
1622 if (root_directory) {
1623 free(root_directory);
1624 root_directory = NULL;
1628 muse_core_connection_close(sock_fd);
1634 _recorder_client_callback_destroy(pc->cb_info);
1646 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1648 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1652 int recorder_create_audiorecorder(recorder_h *recorder)
1654 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1658 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1660 int ret = RECORDER_ERROR_NONE;
1661 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1662 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1664 if (!pc || !pc->cb_info) {
1665 LOGE("NULL handle");
1666 return RECORDER_ERROR_INVALID_PARAMETER;
1669 if (state == NULL) {
1670 LOGE("NULL pointer state");
1671 return RECORDER_ERROR_INVALID_PARAMETER;
1674 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1676 _recorder_msg_send(api, pc->cb_info, &ret);
1678 if (ret == RECORDER_ERROR_NONE)
1679 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1681 LOGD("ret : 0x%x, state : %d", ret, *state);
1687 int recorder_destroy(recorder_h recorder)
1689 int ret = RECORDER_ERROR_NONE;
1690 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1691 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1693 if (!pc || !pc->cb_info) {
1694 LOGE("NULL handle");
1695 return RECORDER_ERROR_INVALID_PARAMETER;
1700 if (pc->cb_info->is_server_connected)
1701 _recorder_msg_send(api, pc->cb_info, &ret);
1703 LOGW("server disconnected. release resource without send message.");
1705 if (ret == RECORDER_ERROR_NONE) {
1706 _recorder_deactivate_idle_event_all(pc->cb_info);
1707 _recorder_client_callback_destroy(pc->cb_info);
1712 LOGD("ret : 0x%x", ret);
1718 int recorder_prepare(recorder_h recorder)
1720 int ret = RECORDER_ERROR_NONE;
1721 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1722 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1724 if (!pc || !pc->cb_info) {
1725 LOGE("NULL handle");
1726 return RECORDER_ERROR_INVALID_PARAMETER;
1731 _recorder_msg_send(api, pc->cb_info, &ret);
1733 LOGD("ret : 0x%x", ret);
1735 if (ret == RECORDER_ERROR_NONE && pc->camera)
1736 camera_start_evas_rendering(pc->camera);
1742 int recorder_unprepare(recorder_h recorder)
1744 int ret = RECORDER_ERROR_NONE;
1745 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1746 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1747 camera_state_e camera_state = CAMERA_STATE_NONE;
1749 if (!pc || !pc->cb_info) {
1750 LOGE("NULL handle");
1751 return RECORDER_ERROR_INVALID_PARAMETER;
1758 ret = camera_get_state(pc->camera, &camera_state);
1759 if (ret != CAMERA_ERROR_NONE) {
1760 LOGE("failed to get camera state 0x%x", ret);
1761 return RECORDER_ERROR_INVALID_OPERATION;
1764 if (camera_state == CAMERA_STATE_PREVIEW) {
1765 ret = camera_stop_evas_rendering(pc->camera, false);
1766 if (ret != CAMERA_ERROR_NONE) {
1767 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1768 return RECORDER_ERROR_INVALID_OPERATION;
1774 _recorder_msg_send(api, pc->cb_info, &ret);
1776 LOGD("ret : 0x%x", ret);
1782 int recorder_start(recorder_h recorder)
1784 int ret = RECORDER_ERROR_NONE;
1785 muse_recorder_api_e api = MUSE_RECORDER_API_START;
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;
1798 ret = recorder_get_state(recorder, ¤t_state);
1799 if (ret != RECORDER_ERROR_NONE) {
1800 LOGE("failed to get current state 0x%x", ret);
1801 return RECORDER_ERROR_INVALID_OPERATION;
1804 if (current_state == RECORDER_STATE_READY) {
1805 ret = camera_stop_evas_rendering(pc->camera, true);
1806 if (ret != CAMERA_ERROR_NONE) {
1807 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1808 return RECORDER_ERROR_INVALID_OPERATION;
1814 _recorder_msg_send(api, pc->cb_info, &ret);
1816 if (pc->camera && current_state == RECORDER_STATE_READY)
1817 camera_start_evas_rendering(pc->camera);
1819 LOGD("ret : 0x%x", ret);
1825 int recorder_pause(recorder_h recorder)
1827 int ret = RECORDER_ERROR_NONE;
1828 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1829 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1831 if (!pc || !pc->cb_info) {
1832 LOGE("NULL handle");
1833 return RECORDER_ERROR_INVALID_PARAMETER;
1838 _recorder_msg_send(api, pc->cb_info, &ret);
1840 LOGD("ret : 0x%x", ret);
1846 int recorder_commit(recorder_h recorder)
1848 int ret = RECORDER_ERROR_NONE;
1849 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1850 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1851 recorder_state_e current_state = RECORDER_STATE_NONE;
1853 if (!pc || !pc->cb_info) {
1854 LOGE("NULL handle");
1855 return RECORDER_ERROR_INVALID_PARAMETER;
1862 ret = recorder_get_state(recorder, ¤t_state);
1863 if (ret != RECORDER_ERROR_NONE) {
1864 LOGE("failed to get current state 0x%x", ret);
1865 return RECORDER_ERROR_INVALID_OPERATION;
1868 if (current_state >= RECORDER_STATE_RECORDING) {
1869 ret = camera_stop_evas_rendering(pc->camera, true);
1870 if (ret != CAMERA_ERROR_NONE) {
1871 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1872 return RECORDER_ERROR_INVALID_OPERATION;
1878 _recorder_msg_send(api, pc->cb_info, &ret);
1880 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1881 camera_start_evas_rendering(pc->camera);
1883 LOGD("ret : 0x%x", ret);
1889 int recorder_cancel(recorder_h recorder)
1891 int ret = RECORDER_ERROR_NONE;
1892 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1893 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1894 recorder_state_e current_state = RECORDER_STATE_NONE;
1896 if (!pc || !pc->cb_info) {
1897 LOGE("NULL handle");
1898 return RECORDER_ERROR_INVALID_PARAMETER;
1904 ret = recorder_get_state(recorder, ¤t_state);
1905 if (ret != RECORDER_ERROR_NONE) {
1906 LOGE("failed to get current state 0x%x", ret);
1907 return RECORDER_ERROR_INVALID_OPERATION;
1910 if (current_state >= RECORDER_STATE_RECORDING) {
1911 ret = camera_stop_evas_rendering(pc->camera, true);
1912 if (ret != CAMERA_ERROR_NONE) {
1913 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1914 return RECORDER_ERROR_INVALID_OPERATION;
1919 _recorder_msg_send(api, pc->cb_info, &ret);
1921 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1922 camera_start_evas_rendering(pc->camera);
1924 LOGD("ret : 0x%x", ret);
1930 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1932 int ret = RECORDER_ERROR_NONE;
1934 char *send_msg = NULL;
1935 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1936 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1938 if (!pc || !pc->cb_info) {
1939 LOGE("NULL handle");
1940 return RECORDER_ERROR_INVALID_PARAMETER;
1945 send_msg = muse_core_msg_json_factory_new(api,
1946 MUSE_TYPE_INT, "width", width,
1947 MUSE_TYPE_INT, "height", height,
1950 if (pc->cb_info->is_server_connected) {
1951 __recorder_update_api_waiting(pc->cb_info, api, 1);
1953 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1957 LOGE("message send failed");
1958 ret = RECORDER_ERROR_INVALID_OPERATION;
1960 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1963 __recorder_update_api_waiting(pc->cb_info, api, -1);
1965 muse_core_msg_json_factory_free(send_msg);
1967 LOGE("failed to create msg");
1968 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1971 LOGD("ret : 0x%x", ret);
1977 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1979 int ret = RECORDER_ERROR_NONE;
1980 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1981 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1983 if (!pc || !pc->cb_info) {
1984 LOGE("NULL handle");
1985 return RECORDER_ERROR_INVALID_PARAMETER;
1988 if (!width || !height) {
1989 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1990 return RECORDER_ERROR_INVALID_PARAMETER;
1995 _recorder_msg_send(api, pc->cb_info, &ret);
1997 if (ret == RECORDER_ERROR_NONE) {
1998 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1999 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
2002 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
2008 int recorder_foreach_supported_video_resolution(recorder_h recorder,
2009 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
2011 int ret = RECORDER_ERROR_NONE;
2012 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2013 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
2015 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2016 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2017 return RECORDER_ERROR_INVALID_PARAMETER;
2020 LOGD("Enter, handle :%x", pc->remote_handle);
2022 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2023 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2025 _recorder_msg_send(api, pc->cb_info, &ret);
2027 LOGD("ret : 0x%x", ret);
2033 int recorder_get_audio_level(recorder_h recorder, double *level)
2035 int ret = RECORDER_ERROR_NONE;
2036 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2037 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2039 if (!pc || !pc->cb_info || level == NULL) {
2040 LOGE("NULL pointer %p %p", pc, level);
2041 return RECORDER_ERROR_INVALID_PARAMETER;
2046 _recorder_msg_send(api, pc->cb_info, &ret);
2048 if (ret == RECORDER_ERROR_NONE)
2049 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2051 LOGD("ret : 0x%x, level %lf", ret, *level);
2057 int recorder_set_filename(recorder_h recorder, const char *filename)
2059 int ret = RECORDER_ERROR_NONE;
2061 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2062 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2063 recorder_msg_param param;
2064 char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2066 if (!pc || !pc->cb_info) {
2067 LOGE("NULL handle");
2068 return RECORDER_ERROR_INVALID_PARAMETER;
2071 if (filename == NULL) {
2072 LOGE("filename is NULL");
2073 return RECORDER_ERROR_INVALID_PARAMETER;
2076 LOGD("ENTER [%s]", filename);
2078 length = strlen(filename);
2080 if (length >= RECORDER_FILENAME_MAX - 1) {
2081 LOGE("too long file name [%d]", length);
2082 return RECORDER_ERROR_INVALID_PARAMETER;
2085 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2086 /* Cannot convert. Use original path. */
2087 strncpy(set_filename, filename, length + 1);
2089 /* Converted. Use converted path. */
2090 LOGD("Converted filename : %s -> %s", filename, set_filename);
2093 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2095 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2097 LOGD("ret : 0x%x", ret);
2103 int recorder_get_filename(recorder_h recorder, char **filename)
2105 int ret = RECORDER_ERROR_NONE;
2106 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2107 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2108 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2110 if (!pc || !pc->cb_info) {
2111 LOGE("NULL handle");
2112 return RECORDER_ERROR_INVALID_PARAMETER;
2115 if (filename == NULL) {
2116 LOGE("filename is NULL");
2117 return RECORDER_ERROR_INVALID_PARAMETER;
2122 _recorder_msg_send(api, pc->cb_info, &ret);
2124 if (ret == RECORDER_ERROR_NONE) {
2125 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2126 /* Cannot convert. Use original path. */
2127 *filename = pc->cb_info->get_filename;
2129 /* Converted. Use converted path. */
2130 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2131 *filename = strdup(compat_filename);
2132 free(pc->cb_info->get_filename);
2135 pc->cb_info->get_filename = NULL;
2138 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2144 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2146 int ret = RECORDER_ERROR_NONE;
2147 int set_format = (int)format;
2148 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2149 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2150 recorder_msg_param param;
2152 if (!pc || !pc->cb_info) {
2153 LOGE("NULL handle");
2154 return RECORDER_ERROR_INVALID_PARAMETER;
2157 LOGD("ENTER, set_format : %d", set_format);
2159 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2161 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2163 LOGD("ret : 0x%x", ret);
2168 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2170 int ret = RECORDER_ERROR_NONE;
2171 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2172 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2174 if (!pc || !pc->cb_info) {
2175 LOGE("NULL handle");
2176 return RECORDER_ERROR_INVALID_PARAMETER;
2179 if (format == NULL) {
2180 LOGE("NULL pointer data");
2181 return RECORDER_ERROR_INVALID_PARAMETER;
2186 _recorder_msg_send(api, pc->cb_info, &ret);
2188 if (ret == RECORDER_ERROR_NONE)
2189 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2191 LOGD("ret : 0x%x, format %d", ret, *format);
2197 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2199 int ret = RECORDER_ERROR_NONE;
2200 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2201 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2202 bool is_available = false;
2203 int stream_index = 0;
2204 char *stream_type = NULL;
2205 char *send_msg = NULL;
2208 if (!pc || !pc->cb_info || stream_info == NULL) {
2209 LOGE("NULL handle");
2210 return RECORDER_ERROR_INVALID_PARAMETER;
2215 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2216 if (ret != SOUND_MANAGER_ERROR_NONE) {
2217 LOGE("stream info verification failed");
2218 return RECORDER_ERROR_INVALID_OPERATION;
2221 if (is_available == false) {
2222 LOGE("stream information is not available");
2223 return RECORDER_ERROR_INVALID_OPERATION;
2226 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2227 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2229 LOGD("sound manager return [0x%x]", ret);
2231 if (ret == SOUND_MANAGER_ERROR_NONE) {
2232 send_msg = muse_core_msg_json_factory_new(api,
2233 MUSE_TYPE_STRING, "stream_type", stream_type,
2234 MUSE_TYPE_INT, "stream_index", stream_index,
2237 if (pc->cb_info->is_server_connected) {
2238 __recorder_update_api_waiting(pc->cb_info, api, 1);
2240 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2244 LOGE("message send failed");
2245 ret = RECORDER_ERROR_INVALID_OPERATION;
2247 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2250 __recorder_update_api_waiting(pc->cb_info, api, -1);
2252 muse_core_msg_json_factory_free(send_msg);
2254 LOGE("failed to create msg");
2255 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2258 ret = RECORDER_ERROR_INVALID_OPERATION;
2265 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2267 int ret = RECORDER_ERROR_NONE;
2268 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2269 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2271 if (!pc || !pc->cb_info || callback == NULL) {
2272 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2273 return RECORDER_ERROR_INVALID_PARAMETER;
2276 LOGD("Enter, handle :%x", pc->remote_handle);
2278 _recorder_msg_send(api, pc->cb_info, &ret);
2280 if (ret == RECORDER_ERROR_NONE) {
2281 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2282 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2285 LOGD("ret : 0x%x", ret);
2291 int recorder_unset_state_changed_cb(recorder_h recorder)
2293 int ret = RECORDER_ERROR_NONE;
2294 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2295 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2297 if (!pc || !pc->cb_info) {
2298 LOGE("NULL handle");
2299 return RECORDER_ERROR_INVALID_PARAMETER;
2304 _recorder_msg_send(api, pc->cb_info, &ret);
2306 if (ret == RECORDER_ERROR_NONE) {
2307 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2308 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2311 LOGD("ret : 0x%x", ret);
2317 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_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_INTERRUPTED_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 _recorder_msg_send(api, pc->cb_info, &ret);
2332 if (ret == RECORDER_ERROR_NONE) {
2333 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2334 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2337 LOGD("ret : 0x%x", ret);
2343 int recorder_unset_interrupted_cb(recorder_h recorder)
2345 int ret = RECORDER_ERROR_NONE;
2346 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2347 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2349 if (!pc || !pc->cb_info) {
2350 LOGE("NULL handle");
2351 return RECORDER_ERROR_INVALID_PARAMETER;
2356 _recorder_msg_send(api, pc->cb_info, &ret);
2358 if (ret == RECORDER_ERROR_NONE) {
2359 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2360 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2363 LOGD("ret : 0x%x", ret);
2369 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2371 int ret = RECORDER_ERROR_NONE;
2372 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2373 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2375 if (!pc || !pc->cb_info || callback == NULL) {
2376 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2377 return RECORDER_ERROR_INVALID_PARAMETER;
2380 LOGD("Enter, handle :%x", pc->remote_handle);
2382 _recorder_msg_send(api, pc->cb_info, &ret);
2384 if (ret == RECORDER_ERROR_NONE) {
2385 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2386 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2389 LOGD("ret : 0x%x", ret);
2395 int recorder_unset_audio_stream_cb(recorder_h recorder)
2397 int ret = RECORDER_ERROR_NONE;
2398 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_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 if (ret == RECORDER_ERROR_NONE) {
2411 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2412 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2415 LOGD("ret : 0x%x", ret);
2421 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2423 int ret = RECORDER_ERROR_NONE;
2424 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2425 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2427 if (!pc || !pc->cb_info || !callback) {
2428 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2429 return RECORDER_ERROR_INVALID_PARAMETER;
2432 LOGD("Enter, handle :%x", pc->remote_handle);
2434 _recorder_msg_send(api, pc->cb_info, &ret);
2436 if (ret == RECORDER_ERROR_NONE) {
2437 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2438 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2441 LOGD("ret : 0x%x", ret);
2447 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2449 int ret = RECORDER_ERROR_NONE;
2450 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2451 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2453 if (!pc || !pc->cb_info) {
2454 LOGE("NULL handle");
2455 return RECORDER_ERROR_INVALID_PARAMETER;
2460 _recorder_msg_send(api, pc->cb_info, &ret);
2462 if (ret == RECORDER_ERROR_NONE) {
2463 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2464 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2467 LOGD("ret : 0x%x", ret);
2473 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2475 int ret = RECORDER_ERROR_NONE;
2476 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2477 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2479 if (!pc || !pc->cb_info || callback == NULL) {
2480 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2481 return RECORDER_ERROR_INVALID_PARAMETER;
2484 LOGD("Enter, handle :%x", pc->remote_handle);
2486 _recorder_msg_send(api, pc->cb_info, &ret);
2488 if (ret == RECORDER_ERROR_NONE) {
2489 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2490 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2493 LOGD("ret : 0x%x", ret);
2499 int recorder_unset_error_cb(recorder_h recorder)
2501 int ret = RECORDER_ERROR_NONE;
2502 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2503 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2505 if (!pc || !pc->cb_info) {
2506 LOGE("NULL handle");
2507 return RECORDER_ERROR_INVALID_PARAMETER;
2512 _recorder_msg_send(api, pc->cb_info, &ret);
2514 if (ret == RECORDER_ERROR_NONE) {
2515 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2516 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2519 LOGD("ret : 0x%x", ret);
2525 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2527 int ret = RECORDER_ERROR_NONE;
2528 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2529 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2531 if (!pc || !pc->cb_info || callback == NULL) {
2532 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2533 return RECORDER_ERROR_INVALID_PARAMETER;
2536 LOGD("Enter, handle :%x", pc->remote_handle);
2538 _recorder_msg_send(api, pc->cb_info, &ret);
2540 if (ret == RECORDER_ERROR_NONE) {
2541 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2542 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2545 LOGD("ret : 0x%x", ret);
2551 int recorder_unset_recording_status_cb(recorder_h recorder)
2553 int ret = RECORDER_ERROR_NONE;
2554 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2555 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2557 if (!pc || !pc->cb_info) {
2558 LOGE("NULL handle");
2559 return RECORDER_ERROR_INVALID_PARAMETER;
2564 _recorder_msg_send(api, pc->cb_info, &ret);
2566 if (ret == RECORDER_ERROR_NONE) {
2567 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2568 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2571 LOGD("ret : 0x%x", ret);
2577 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2579 int ret = RECORDER_ERROR_NONE;
2580 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2581 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2583 if (!pc || !pc->cb_info || callback == NULL) {
2584 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2585 return RECORDER_ERROR_INVALID_PARAMETER;
2588 _recorder_msg_send(api, pc->cb_info, &ret);
2590 if (ret == RECORDER_ERROR_NONE) {
2591 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2592 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2595 LOGD("ret : 0x%x", ret);
2601 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2603 int ret = RECORDER_ERROR_NONE;
2604 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2605 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2607 if (!pc || !pc->cb_info) {
2608 LOGE("NULL handle");
2609 return RECORDER_ERROR_INVALID_PARAMETER;
2614 _recorder_msg_send(api, pc->cb_info, &ret);
2616 if (ret == RECORDER_ERROR_NONE) {
2617 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2618 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2621 LOGD("ret : 0x%x", ret);
2627 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2629 int ret = RECORDER_ERROR_NONE;
2630 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2631 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2633 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2634 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2635 return RECORDER_ERROR_INVALID_PARAMETER;
2638 LOGD("Enter, handle :%x", pc->remote_handle);
2640 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2641 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2643 _recorder_msg_send(api, pc->cb_info, &ret);
2645 LOGD("ret : 0x%x", ret);
2651 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2653 int ret = RECORDER_ERROR_NONE;
2654 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2655 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2656 recorder_msg_param param;
2658 if (!pc || !pc->cb_info) {
2659 LOGE("NULL handle");
2660 return RECORDER_ERROR_INVALID_PARAMETER;
2665 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2667 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2669 LOGD("ret : 0x%x", ret);
2675 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2677 int ret = RECORDER_ERROR_NONE;
2678 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2679 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2680 recorder_msg_param param;
2682 if (!pc || !pc->cb_info) {
2683 LOGE("NULL handle");
2684 return RECORDER_ERROR_INVALID_PARAMETER;
2689 RECORDER_MSG_PARAM_SET(param, INT, second);
2691 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2693 LOGD("ret : 0x%x", ret);
2699 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2701 int ret = RECORDER_ERROR_NONE;
2702 int set_device = (int)device;
2703 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2704 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2705 recorder_msg_param param;
2707 if (!pc || !pc->cb_info) {
2708 LOGE("NULL handle");
2709 return RECORDER_ERROR_INVALID_PARAMETER;
2714 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2716 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2718 LOGD("ret : 0x%x", ret);
2724 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2726 int ret = RECORDER_ERROR_NONE;
2727 int set_codec = (int)codec;
2728 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2729 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2730 recorder_msg_param param;
2732 if (!pc || !pc->cb_info) {
2733 LOGE("NULL handle");
2734 return RECORDER_ERROR_INVALID_PARAMETER;
2739 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2741 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2743 LOGD("ret : 0x%x", ret);
2749 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2751 int ret = RECORDER_ERROR_NONE;
2752 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2753 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2755 if (!pc || !pc->cb_info) {
2756 LOGE("NULL handle");
2757 return RECORDER_ERROR_INVALID_PARAMETER;
2760 if (codec == NULL) {
2761 LOGE("codec is NULL");
2762 return RECORDER_ERROR_INVALID_PARAMETER;
2767 _recorder_msg_send(api, pc->cb_info, &ret);
2769 if (ret == RECORDER_ERROR_NONE)
2770 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2772 LOGD("ret : 0x%x, codec %d", ret, *codec);
2778 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2780 int ret = RECORDER_ERROR_NONE;
2781 int set_codec = (int)codec;
2782 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2783 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2784 recorder_msg_param param;
2786 if (!pc || !pc->cb_info) {
2787 LOGE("NULL handle");
2788 return RECORDER_ERROR_INVALID_PARAMETER;
2793 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2795 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2797 LOGD("ret : 0x%x", ret);
2803 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2805 int ret = RECORDER_ERROR_NONE;
2806 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2807 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2809 if (!pc || !pc->cb_info) {
2810 LOGE("NULL handle");
2811 return RECORDER_ERROR_INVALID_PARAMETER;
2814 if (codec == NULL) {
2815 LOGE("codec is NULL");
2816 return RECORDER_ERROR_INVALID_PARAMETER;
2821 _recorder_msg_send(api, pc->cb_info, &ret);
2823 if (ret == RECORDER_ERROR_NONE)
2824 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2826 LOGD("ret : 0x%x, codec %d", ret, *codec);
2832 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2834 int ret = RECORDER_ERROR_NONE;
2835 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2836 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2837 recorder_msg_param param;
2839 if (!pc || !pc->cb_info) {
2840 LOGE("NULL handle");
2841 return RECORDER_ERROR_INVALID_PARAMETER;
2844 LOGD("ENTER, samplerate : %d", samplerate);
2846 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2848 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2850 LOGD("ret : 0x%x", ret);
2856 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2858 int ret = RECORDER_ERROR_NONE;
2859 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2860 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2861 recorder_msg_param param;
2863 if (!pc || !pc->cb_info) {
2864 LOGE("NULL handle");
2865 return RECORDER_ERROR_INVALID_PARAMETER;
2870 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2872 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2874 LOGD("ret : 0x%x", ret);
2880 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2882 int ret = RECORDER_ERROR_NONE;
2883 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2884 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2885 recorder_msg_param param;
2887 if (!pc || !pc->cb_info) {
2888 LOGE("NULL handle");
2889 return RECORDER_ERROR_INVALID_PARAMETER;
2894 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2896 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2898 LOGD("ret : 0x%x", ret);
2904 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2906 int ret = RECORDER_ERROR_NONE;
2907 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2908 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2910 if (!pc || !pc->cb_info) {
2911 LOGE("NULL handle");
2912 return RECORDER_ERROR_INVALID_PARAMETER;
2915 if (kbyte == NULL) {
2916 LOGE("NULL pointer kbyte");
2917 return RECORDER_ERROR_INVALID_PARAMETER;
2922 _recorder_msg_send(api, pc->cb_info, &ret);
2924 if (ret == RECORDER_ERROR_NONE)
2925 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2927 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2933 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2935 int ret = RECORDER_ERROR_NONE;
2936 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2937 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2939 if (!pc || !pc->cb_info) {
2940 LOGE("NULL handle");
2941 return RECORDER_ERROR_INVALID_PARAMETER;
2944 if (second == NULL) {
2945 LOGE("NULL pointer second");
2946 return RECORDER_ERROR_INVALID_PARAMETER;
2951 _recorder_msg_send(api, pc->cb_info, &ret);
2953 if (ret == RECORDER_ERROR_NONE)
2954 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2956 LOGD("ret : 0x%x, %d second", ret, *second);
2962 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2964 int ret = RECORDER_ERROR_NONE;
2965 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2966 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2968 if (!pc || !pc->cb_info) {
2969 LOGE("NULL handle");
2970 return RECORDER_ERROR_INVALID_PARAMETER;
2973 if (device == NULL) {
2974 LOGE("NULL pointer device");
2975 return RECORDER_ERROR_INVALID_PARAMETER;
2980 _recorder_msg_send(api, pc->cb_info, &ret);
2982 if (ret == RECORDER_ERROR_NONE)
2983 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2985 LOGD("ret : 0x%x, device %d", ret, *device);
2991 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2993 int ret = RECORDER_ERROR_NONE;
2994 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2995 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2997 if (!pc || !pc->cb_info) {
2998 LOGE("NULL handle");
2999 return RECORDER_ERROR_INVALID_PARAMETER;
3002 if (samplerate == NULL) {
3003 LOGE("NULL pointer handle");
3004 return RECORDER_ERROR_INVALID_PARAMETER;
3009 _recorder_msg_send(api, pc->cb_info, &ret);
3011 if (ret == RECORDER_ERROR_NONE)
3012 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3014 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3020 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3022 int ret = RECORDER_ERROR_NONE;
3023 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3024 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3026 if (!pc || !pc->cb_info) {
3027 LOGE("NULL handle");
3028 return RECORDER_ERROR_INVALID_PARAMETER;
3031 if (bitrate == NULL) {
3032 LOGE("NULL pointer");
3033 return RECORDER_ERROR_INVALID_PARAMETER;
3038 _recorder_msg_send(api, pc->cb_info, &ret);
3040 if (ret == RECORDER_ERROR_NONE)
3041 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3043 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3049 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3051 int ret = RECORDER_ERROR_NONE;
3052 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3053 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3055 if (!pc || !pc->cb_info) {
3056 LOGE("NULL handle");
3057 return RECORDER_ERROR_INVALID_PARAMETER;
3060 if (bitrate == NULL) {
3061 LOGE("NULL pointer");
3062 return RECORDER_ERROR_INVALID_PARAMETER;
3067 _recorder_msg_send(api, pc->cb_info, &ret);
3069 if (ret == RECORDER_ERROR_NONE)
3070 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3072 LOGD("ret : 0x%x", ret);
3078 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3080 int ret = RECORDER_ERROR_NONE;
3081 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3082 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3084 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3085 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3086 return RECORDER_ERROR_INVALID_PARAMETER;
3089 LOGD("Enter, handle :%x", pc->remote_handle);
3091 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3092 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3094 _recorder_msg_send(api, pc->cb_info, &ret);
3096 LOGD("ret : 0x%x", ret);
3102 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3104 int ret = RECORDER_ERROR_NONE;
3105 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3106 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3108 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3109 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3110 return RECORDER_ERROR_INVALID_PARAMETER;
3113 LOGD("Enter, handle :%x", pc->remote_handle);
3115 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3116 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3118 _recorder_msg_send(api, pc->cb_info, &ret);
3120 LOGD("ret : 0x%x", ret);
3126 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3128 int ret = RECORDER_ERROR_NONE;
3129 int set_enable = (int)enable;
3130 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3131 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3132 recorder_msg_param param;
3134 if (!pc || !pc->cb_info) {
3135 LOGE("NULL handle");
3136 return RECORDER_ERROR_INVALID_PARAMETER;
3141 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3143 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3145 LOGD("ret : 0x%x", ret);
3151 bool recorder_attr_is_muted(recorder_h recorder)
3154 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3155 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3157 if (!pc || !pc->cb_info) {
3158 LOGE("NULL handle");
3164 _recorder_msg_send(api, pc->cb_info, &ret);
3166 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3169 LOGD("ret : %d", ret);
3175 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3177 int ret = RECORDER_ERROR_NONE;
3178 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3179 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3180 recorder_msg_param param;
3182 if (!pc || !pc->cb_info) {
3183 LOGE("NULL handle");
3184 return RECORDER_ERROR_INVALID_PARAMETER;
3187 LOGD("ENTER - %.20lf", rate);
3189 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3191 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3193 LOGD("ret : 0x%x", ret);
3199 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3201 int ret = RECORDER_ERROR_NONE;
3202 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3203 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3205 if (!pc || !pc->cb_info) {
3206 LOGE("NULL handle");
3207 return RECORDER_ERROR_INVALID_PARAMETER;
3211 LOGE("rate is NULL");
3212 return RECORDER_ERROR_INVALID_PARAMETER;
3217 _recorder_msg_send(api, pc->cb_info, &ret);
3218 if (ret == RECORDER_ERROR_NONE)
3219 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3221 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3227 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3229 int ret = RECORDER_ERROR_NONE;
3230 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3231 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3232 recorder_msg_param param;
3234 if (!pc || !pc->cb_info) {
3235 LOGE("NULL handle");
3236 return RECORDER_ERROR_INVALID_PARAMETER;
3241 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3243 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3245 LOGD("ret : 0x%x", ret);
3251 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3253 int ret = RECORDER_ERROR_NONE;
3254 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3255 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3257 if (!pc || !pc->cb_info) {
3258 LOGE("NULL handle");
3259 return RECORDER_ERROR_INVALID_PARAMETER;
3262 if (channel_count == NULL) {
3263 LOGE("channel_count is NULL");
3264 return RECORDER_ERROR_INVALID_PARAMETER;
3269 _recorder_msg_send(api, pc->cb_info, &ret);
3271 if (ret == RECORDER_ERROR_NONE)
3272 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3274 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3280 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3282 int ret = RECORDER_ERROR_NONE;
3283 int set_orientation = (int)orientation;
3284 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3285 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3286 recorder_msg_param param;
3288 if (!pc || !pc->cb_info) {
3289 LOGE("NULL handle");
3290 return RECORDER_ERROR_INVALID_PARAMETER;
3295 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3297 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3299 LOGD("ret : 0x%x", ret);
3305 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3307 int ret = RECORDER_ERROR_NONE;
3308 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3309 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3311 if (!pc || !pc->cb_info) {
3312 LOGE("NULL handle");
3313 return RECORDER_ERROR_INVALID_PARAMETER;
3316 if (orientation == NULL) {
3317 LOGE("orientation is NULL");
3318 return RECORDER_ERROR_INVALID_PARAMETER;
3323 _recorder_msg_send(api, pc->cb_info, &ret);
3325 if (ret == RECORDER_ERROR_NONE)
3326 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3328 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3334 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3336 int ret = RECORDER_ERROR_NONE;
3338 int get_device_state = 0;
3339 char *send_msg = NULL;
3340 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3343 LOGE("NULL pointer");
3344 return RECORDER_ERROR_INVALID_PARAMETER;
3347 LOGD("Enter - type %d", type);
3349 sock_fd = muse_core_client_new();
3352 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3353 ret = RECORDER_ERROR_INVALID_OPERATION;
3354 goto _GET_DEVICE_STATE_EXIT;
3358 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3359 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3360 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3365 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3366 goto _GET_DEVICE_STATE_EXIT;
3370 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3372 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3374 muse_core_msg_json_factory_free(send_msg);
3379 LOGE("send msg failed %d", errno);
3380 ret = RECORDER_ERROR_INVALID_OPERATION;
3381 goto _GET_DEVICE_STATE_EXIT;
3385 ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3388 LOGE("recv msg failed %d", errno);
3389 ret = RECORDER_ERROR_INVALID_OPERATION;
3390 goto _GET_DEVICE_STATE_EXIT;
3394 if (!muse_recorder_msg_get(ret, recv_msg)) {
3396 LOGE("failed to get return value from msg [%s]", recv_msg);
3397 ret = RECORDER_ERROR_INVALID_OPERATION;
3398 goto _GET_DEVICE_STATE_EXIT;
3402 if (ret == RECORDER_ERROR_NONE) {
3403 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3404 *state = (recorder_device_state_e)get_device_state;
3405 LOGD("device type %d state %d", type, *state);
3407 LOGE("failed to get device state from msg [%s]", recv_msg);
3408 ret = RECORDER_ERROR_INVALID_OPERATION;
3411 LOGE("failed 0x%x", ret);
3414 _GET_DEVICE_STATE_EXIT:
3416 muse_core_connection_close(sock_fd);
3424 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3426 int ret = RECORDER_ERROR_NONE;
3427 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3428 recorder_cb_info *info = NULL;
3430 if (!callback || !cb_id) {
3431 LOGE("invalid pointer %p %p", callback, cb_id);
3432 return RECORDER_ERROR_INVALID_PARAMETER;
3435 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3437 /* check recorder support */
3438 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3439 if (ret != RECORDER_ERROR_NONE) {
3440 LOGE("get device state failed");
3441 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3445 info = g_new0(recorder_cb_info, 1);
3447 LOGE("info failed");
3448 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3452 info->id = ++g_rec_dev_state_changed_cb_id;
3453 info->callback = (void *)callback;
3454 info->user_data = user_data;
3458 /* subscribe dbus signal for camera state change */
3459 if (!g_rec_dev_state_changed_cb_conn) {
3460 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3461 if (!g_rec_dev_state_changed_cb_conn) {
3462 LOGE("failed to get gdbus connection");
3463 ret = RECORDER_ERROR_INVALID_OPERATION;
3467 LOGD("subscribe signal %s - %s - %s",
3468 MM_CAMCORDER_DBUS_OBJECT,
3469 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3470 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3472 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3473 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3474 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3475 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3476 LOGE("failed to get gdbus connection");
3477 ret = RECORDER_ERROR_INVALID_OPERATION;
3481 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3484 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3486 LOGD("callback id %d", info->id);
3489 if (ret != RECORDER_ERROR_NONE) {
3496 if (g_rec_dev_state_changed_cb_conn) {
3497 g_object_unref(g_rec_dev_state_changed_cb_conn);
3498 g_rec_dev_state_changed_cb_conn = NULL;
3503 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3509 int recorder_remove_device_state_changed_cb(int cb_id)
3511 int ret = RECORDER_ERROR_NONE;
3512 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3513 GList *tmp_list = NULL;
3514 recorder_cb_info *info = NULL;
3516 /* check recorder support */
3517 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3518 if (ret != RECORDER_ERROR_NONE) {
3519 LOGE("get device state failed");
3523 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3525 if (!g_rec_dev_state_changed_cb_list) {
3526 LOGE("there is no callback info");
3527 ret = RECORDER_ERROR_INVALID_OPERATION;
3531 tmp_list = g_rec_dev_state_changed_cb_list;
3534 info = tmp_list->data;
3535 tmp_list = tmp_list->next;
3542 if (info->id == cb_id) {
3543 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3548 if (!g_rec_dev_state_changed_cb_list) {
3549 /* no remained callback */
3550 if (g_rec_dev_state_changed_cb_conn) {
3551 /* unsubscribe signal */
3552 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3553 g_rec_dev_state_changed_cb_subscribe_id = 0;
3555 /* unref connection */
3556 g_object_unref(g_rec_dev_state_changed_cb_conn);
3557 g_rec_dev_state_changed_cb_conn = NULL;
3561 LOGD("id %d callback removed", cb_id);
3562 ret = RECORDER_ERROR_NONE;
3568 LOGE("id %d callback not found", cb_id);
3569 ret = RECORDER_ERROR_INVALID_PARAMETER;
3572 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);