2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <camera_internal.h>
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
25 #include <storage-internal.h>
26 #include <muse_recorder.h>
27 #include <muse_recorder_msg.h>
28 #include <muse_core.h>
29 #include <muse_client.h>
30 #include <recorder_private.h>
33 #include <tzplatform_config.h>
38 #define LOG_TAG "TIZEN_N_RECORDER"
39 #define MODULE_NAME "recorder"
41 /* for device changed callback */
42 static GMutex g_rec_dev_state_changed_cb_lock;
43 static GList *g_rec_dev_state_changed_cb_list;
44 static int g_rec_dev_state_changed_cb_id;
45 static GDBusConnection *g_rec_dev_state_changed_cb_conn;
46 static guint g_rec_dev_state_changed_cb_subscribe_id;
47 static GMutex g_rec_idle_event_lock;
51 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
54 api < 0 || api >= MUSE_RECORDER_API_MAX) {
55 LOGE("invalid param %p %d", cb_info, api);
59 g_mutex_lock(&(cb_info->api_mutex[api]));
60 cb_info->api_waiting[api] += value;
61 g_mutex_unlock(&(cb_info->api_mutex[api]));
63 /*LOGD("api %d, value %d, waiting %d",
64 api, value, cb_info->api_waiting[api]);*/
70 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
71 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
72 const gchar *signal_name, GVariant *param, gpointer user_data)
75 recorder_type_e type = RECORDER_TYPE_AUDIO;
76 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
77 GList *tmp_list = NULL;
78 recorder_cb_info *info = NULL;
80 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
82 if (!g_rec_dev_state_changed_cb_list || !param) {
83 LOGW("no callback or NULL param %p", param);
87 /* get device type and state */
88 g_variant_get(param, "(i)", &value);
91 state = 0x0000ffff & value;
93 LOGD("type %d, state %d", type, state);
95 tmp_list = g_rec_dev_state_changed_cb_list;
98 info = (recorder_cb_info *)tmp_list->data;
101 if (info->callback) {
102 LOGD("start id[%d] callback", info->id);
103 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
104 LOGD("returned id[%d] callback", info->id);
106 LOGW("NULL callback for id %d", info->id);
110 tmp_list = tmp_list->next;
114 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
120 static int _recorder_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
122 tbm_bo tmp_bo = NULL;
123 tbm_bo_handle tmp_bo_handle = {NULL, };
125 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || fd < 0) {
126 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, fd %d",
127 bufmgr, bo, bo_handle, fd);
131 tmp_bo = tbm_bo_import_fd(bufmgr, (tbm_fd)fd);
132 if (tmp_bo == NULL) {
133 LOGE("bo import failed - bufmgr %p, fd %d", bufmgr, fd);
137 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
138 if (tmp_bo_handle.ptr == NULL) {
139 LOGE("bo map failed %p", tmp_bo);
140 tbm_bo_unref(tmp_bo);
145 /* set bo and bo_handle */
147 *bo_handle = tmp_bo_handle;
152 static void _recorder_release_imported_bo(tbm_bo *bo)
154 if (bo == NULL || *bo == NULL) {
166 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event, int tfd)
168 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
169 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
173 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
175 g_mutex_lock(&cb_info->user_cb_mutex[event]);
177 if (cb_info->user_cb[event] == NULL) {
178 if (event != MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM &&
179 event != MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM) {
180 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
181 LOGW("NULL callback for event %d, return here", event);
184 LOGW("NULL callback for event %d, NOT return here", event);
189 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
195 muse_recorder_msg_get(previous, recv_msg);
196 muse_recorder_msg_get(current, recv_msg);
197 muse_recorder_msg_get(by_policy, recv_msg);
199 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
200 (recorder_state_e)current,
202 cb_info->user_data[event]);
205 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
209 muse_recorder_msg_get(type, recv_msg);
211 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
212 cb_info->user_data[event]);
215 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
217 int64_t cb_elapsed_time = 0;
218 int64_t cb_file_size = 0;
220 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
221 muse_recorder_msg_get(cb_file_size, recv_msg);
223 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
224 (unsigned long long)cb_file_size,
225 cb_info->user_data[event]);
228 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
234 muse_recorder_msg_get(policy, recv_msg);
235 muse_recorder_msg_get(previous, recv_msg);
236 muse_recorder_msg_get(current, recv_msg);
238 LOGW("INTERRUPTED - policy %d, state %d -> %d", policy, previous, current);
240 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
241 (recorder_state_e)previous,
242 (recorder_state_e)current,
243 cb_info->user_data[event]);
246 case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
251 muse_recorder_msg_get(policy, recv_msg);
252 muse_recorder_msg_get(state, recv_msg);
254 LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
256 ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
257 (recorder_state_e)state, cb_info->user_data[event]);
260 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
268 tbm_bo_handle bo_handle = {.ptr = NULL};
269 char *send_msg = NULL;
272 LOGE("invalid fd %d", tfd);
276 muse_recorder_msg_get(audio_fd, recv_msg);
278 if (cb_info->user_cb[event]) {
279 if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd, &bo, &bo_handle)) {
280 muse_recorder_msg_get(size, recv_msg);
281 muse_recorder_msg_get(format, recv_msg);
282 muse_recorder_msg_get(channel, recv_msg);
283 muse_recorder_msg_get(timestamp, recv_msg);
285 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
286 size, (audio_sample_type_e)format, channel,
287 (unsigned int)timestamp, cb_info->user_data[event]);
289 /* release imported bo */
290 _recorder_release_imported_bo(&bo);
292 LOGE("tbm fd %d import failed", tfd);
297 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
298 MUSE_TYPE_INT, "ret_fd", audio_fd, NULL);
301 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
302 LOGE("sending message failed");
304 muse_core_msg_free(send_msg);
307 LOGE("failed to create send msg for fd %d", audio_fd);
310 /* close imported fd */
315 case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
322 tbm_bo_handle bo_handle = {.ptr = NULL};
323 char *send_msg = NULL;
326 LOGE("invalid fd %d", tfd);
330 muse_recorder_msg_get(muxed_fd, recv_msg);
332 if (cb_info->user_cb[event]) {
333 if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd, &bo, &bo_handle)) {
334 muse_recorder_msg_get(size, recv_msg);
335 muse_recorder_msg_get(offset, recv_msg);
337 ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
338 size, (unsigned long long)offset, cb_info->user_data[event]);
340 /* release imported bo */
341 _recorder_release_imported_bo(&bo);
343 LOGE("tbm fd %d import failed", tfd);
348 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
349 MUSE_TYPE_INT, "ret_fd", muxed_fd, NULL);
351 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
352 LOGE("sending message failed");
354 muse_core_msg_free(send_msg);
357 LOGE("failed to create send msg for fd %d", tfd);
360 /* close imported fd */
366 case MUSE_RECORDER_EVENT_TYPE_ERROR:
369 int current_state = 0;
371 muse_recorder_msg_get(error, recv_msg);
372 muse_recorder_msg_get(current_state, recv_msg);
374 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
375 (recorder_state_e)current_state,
376 cb_info->user_data[event]);
380 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
384 muse_recorder_msg_get(codec, recv_msg);
386 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
387 cb_info->user_cb[event] = NULL;
388 cb_info->user_data[event] = NULL;
389 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
393 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
397 muse_recorder_msg_get(format, recv_msg);
399 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
400 cb_info->user_cb[event] = NULL;
401 cb_info->user_data[event] = NULL;
402 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
406 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
410 muse_recorder_msg_get(codec, recv_msg);
412 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
413 cb_info->user_cb[event] = NULL;
414 cb_info->user_data[event] = NULL;
415 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
419 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
424 muse_recorder_msg_get(width, recv_msg);
425 muse_recorder_msg_get(height, recv_msg);
427 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
428 cb_info->user_cb[event] = NULL;
429 cb_info->user_data[event] = NULL;
430 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
436 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
442 static gboolean _recorder_idle_event_callback(gpointer data)
444 recorder_cb_info_s *cb_info = NULL;
445 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
447 if (rec_idle_event == NULL) {
448 LOGE("rec_idle_event is NULL");
453 g_mutex_lock(&g_rec_idle_event_lock);
455 cb_info = rec_idle_event->cb_info;
456 if (cb_info == NULL) {
457 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
458 g_mutex_unlock(&g_rec_idle_event_lock);
459 goto IDLE_EVENT_CALLBACK_DONE;
462 /* remove event from list */
463 if (cb_info->idle_event_list)
464 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
466 g_mutex_unlock(&g_rec_idle_event_lock);
469 _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event, -1);
471 IDLE_EVENT_CALLBACK_DONE:
473 g_free(rec_idle_event);
474 rec_idle_event = NULL;
480 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
482 recorder_idle_event_s *rec_idle_event = NULL;
485 if (cb_info == NULL) {
486 LOGE("cb_info is NULL");
490 g_mutex_lock(&g_rec_idle_event_lock);
492 if (cb_info->idle_event_list == NULL) {
495 list = cb_info->idle_event_list;
498 rec_idle_event = list->data;
499 list = g_list_next(list);
501 if (!rec_idle_event) {
502 LOGW("The event is NULL");
506 if (g_idle_remove_by_data(rec_idle_event)) {
507 LOGW("remove idle event %p done", rec_idle_event);
509 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
511 g_free(rec_idle_event);
512 rec_idle_event = NULL;
517 LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
518 rec_idle_event, rec_idle_event->event);
520 rec_idle_event->cb_info = NULL;
522 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
525 g_list_free(cb_info->idle_event_list);
526 cb_info->idle_event_list = NULL;
529 g_mutex_unlock(&g_rec_idle_event_lock);
535 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg, int tfd)
537 recorder_message_s *rec_msg = NULL;
538 recorder_msg_handler_info_s *msg_handler_info = NULL;
540 if (!cb_info || !msg) {
541 LOGE("NULL pointer %p %p", cb_info, msg);
545 rec_msg = g_new0(recorder_message_s, 1);
547 LOGE("failed to alloc rec_msg for [%s]", msg);
552 rec_msg->event = event;
553 rec_msg->event_class = event_class;
556 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
558 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
560 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
561 msg_handler_info = &cb_info->audio_stream_cb_info;
562 else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
563 msg_handler_info = &cb_info->muxed_stream_cb_info;
565 msg_handler_info = &cb_info->msg_handler_info;
567 g_mutex_lock(&msg_handler_info->mutex);
568 g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
569 g_cond_signal(&msg_handler_info->cond);
570 g_mutex_unlock(&msg_handler_info->mutex);
578 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
580 if (!cb_info || !msg) {
581 LOGE("NULL pointer %p %p", cb_info, msg);
586 case MUSE_RECORDER_API_GET_STATE:
589 muse_recorder_msg_get(get_state, msg);
590 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
593 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
597 muse_recorder_msg_get(get_width, msg);
598 muse_recorder_msg_get(get_height, msg);
599 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
600 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
603 case MUSE_RECORDER_API_GET_FILE_FORMAT:
606 muse_recorder_msg_get(get_format, msg);
607 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
610 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
613 muse_recorder_msg_get(get_codec, msg);
614 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
617 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
620 muse_recorder_msg_get(get_codec, msg);
621 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
624 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
627 muse_recorder_msg_get(get_kbyte, msg);
628 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
631 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
634 muse_recorder_msg_get(get_second, msg);
635 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
638 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
641 muse_recorder_msg_get(get_device, msg);
642 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
645 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
647 int get_samplerate = 0;
648 muse_recorder_msg_get(get_samplerate, msg);
649 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
652 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
655 muse_recorder_msg_get(get_bitrate, msg);
656 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
659 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
662 muse_recorder_msg_get(get_bitrate, msg);
663 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
666 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
669 muse_recorder_msg_get_double(get_rate, msg);
670 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
673 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
675 int get_channel_count = 0;
676 muse_recorder_msg_get(get_channel_count, msg);
677 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
680 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
682 int get_orientation = 0;
683 muse_recorder_msg_get(get_orientation, msg);
684 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
687 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
689 double get_level = 0.0;
690 muse_recorder_msg_get_double(get_level, msg);
691 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
694 case MUSE_RECORDER_API_GET_FILENAME:
696 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
697 muse_recorder_msg_get_string(get_filename, msg);
698 if (cb_info->get_filename) {
699 free(cb_info->get_filename);
700 cb_info->get_filename = NULL;
702 cb_info->get_filename = strdup(get_filename);
713 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg, int tfd)
715 int ret = RECORDER_ERROR_NONE;
719 int event_class = -1;
721 if (!cb_info || !msg) {
722 LOGE("invalid ptr %p %p", cb_info, msg);
726 /*LOGD("msg [%s]", msg);*/
728 if (!muse_recorder_msg_get(api, msg)) {
729 LOGE("failed to get recorder api");
733 if (api == MUSE_RECORDER_CB_EVENT) {
734 if (!muse_recorder_msg_get(event, msg) ||
735 !muse_recorder_msg_get(event_class, msg)) {
736 LOGE("failed to get event or event_class [%s]", msg);
740 if (!muse_recorder_msg_get(api_class, msg)) {
741 LOGE("failed to get api_class [%s]", msg);
746 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
747 if (api >= MUSE_RECORDER_API_MAX) {
748 LOGE("invalid api %d", api);
752 if (!muse_recorder_msg_get(ret, msg)) {
753 LOGE("failed to get recorder ret");
757 g_mutex_lock(&cb_info->api_mutex[api]);
759 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
760 g_atomic_int_set(&cb_info->msg_recv_running, 0);
761 LOGD("get device state done. close client cb handler");
764 case MUSE_RECORDER_API_CREATE:
765 if (ret != RECORDER_ERROR_NONE) {
766 g_atomic_int_set(&cb_info->msg_recv_running, 0);
767 LOGE("create error 0x%x. closing..", ret);
770 case MUSE_RECORDER_API_DESTROY:
771 if (ret == RECORDER_ERROR_NONE) {
772 g_atomic_int_set(&cb_info->msg_recv_running, 0);
773 LOGD("destroy done. closing..");
777 __recorder_get_api_operation(api, cb_info, msg);
782 if (cb_info->api_waiting[api] > 0) {
783 cb_info->api_ret[api] = ret;
784 cb_info->api_activating[api] = 1;
786 g_cond_signal(&cb_info->api_cond[api]);
788 LOGE("no waiting for api [%d]", api);
791 g_mutex_unlock(&cb_info->api_mutex[api]);
792 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
793 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg, tfd);
795 LOGW("unknown recorder api %d and api_class %d", api, api_class);
802 static void *_recorder_msg_handler_func(gpointer data)
806 recorder_message_s *rec_msg = NULL;
807 recorder_idle_event_s *rec_idle_event = NULL;
808 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
809 recorder_cb_info_s *cb_info = NULL;
811 if (!handler_info || !handler_info->cb_info) {
812 LOGE("NULL handler %p", handler_info);
816 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
817 type = handler_info->type;
819 LOGD("t:%d start", type);
821 g_mutex_lock(&handler_info->mutex);
823 while (g_atomic_int_get(&handler_info->running)) {
824 if (g_queue_is_empty(handler_info->queue)) {
825 /*LOGD("signal wait...");*/
826 g_cond_wait(&handler_info->cond, &handler_info->mutex);
827 /*LOGD("signal received");*/
829 if (g_atomic_int_get(&handler_info->running) == 0) {
830 LOGD("stop event thread");
835 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
836 g_mutex_unlock(&handler_info->mutex);
837 if (rec_msg == NULL) {
838 LOGE("NULL message");
839 g_mutex_lock(&handler_info->mutex);
845 if (api < MUSE_RECORDER_API_MAX) {
848 g_mutex_lock(&cb_info->api_mutex[api]);
850 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
851 if (cb_info->api_waiting[api] > 0) {
852 cb_info->api_ret[api] = ret;
853 cb_info->api_activating[api] = 1;
855 /*LOGD("recorder api %d - return 0x%x", ret);*/
857 g_cond_signal(&cb_info->api_cond[api]);
859 LOGE("no waiting for api [%d]", api);
862 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
865 g_mutex_unlock(&cb_info->api_mutex[api]);
866 } else if (api == MUSE_RECORDER_CB_EVENT) {
867 switch (rec_msg->event_class) {
868 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
869 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event, rec_msg->tfd);
871 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
872 rec_idle_event = g_new0(recorder_idle_event_s, 1);
873 if (rec_idle_event == NULL) {
874 LOGE("event alloc failed");
878 rec_idle_event->event = rec_msg->event;
879 rec_idle_event->cb_info = cb_info;
881 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
883 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
885 g_mutex_lock(&g_rec_idle_event_lock);
886 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
887 g_mutex_unlock(&g_rec_idle_event_lock);
889 g_idle_add_full(G_PRIORITY_DEFAULT,
890 (GSourceFunc)_recorder_idle_event_callback,
891 (gpointer)rec_idle_event,
895 LOGE("unknown event class %d", rec_msg->event_class);
899 LOGE("unknown api[%d] message", api);
905 g_mutex_lock(&handler_info->mutex);
908 /* remove remained event */
909 while (!g_queue_is_empty(handler_info->queue)) {
910 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
912 LOGD("remove message %p", rec_msg);
916 LOGW("NULL message");
920 g_mutex_unlock(&handler_info->mutex);
928 static void *_recorder_msg_recv_func(gpointer data)
931 int tfd[MUSE_NUM_FD] = {-1, -1, -1, -1};
932 char *recv_msg = NULL;
933 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
935 if (cb_info == NULL) {
936 LOGE("cb_info NULL");
942 recv_msg = cb_info->recv_msg;
944 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
945 /* tfd[0] is only used. */
948 recv_length = muse_core_msg_recv_fd(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH, tfd);
949 if (recv_length <= 0) {
951 cb_info->is_server_connected = FALSE;
952 LOGE("receive msg failed - server disconnected");
957 recv_msg[recv_length] = '\0';
959 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
961 __recorder_process_msg(cb_info, recv_msg, tfd[0]);
964 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
966 if (!cb_info->is_server_connected) {
968 /* send error msg for server disconnection */
969 char *error_msg = muse_core_msg_new(MUSE_RECORDER_CB_EVENT,
970 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
971 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
975 LOGE("error_msg failed");
976 goto CB_HANDLER_EXIT;
979 LOGE("add error msg for service disconnection done");
981 __recorder_add_msg_to_queue(cb_info,
982 MUSE_RECORDER_CB_EVENT,
983 MUSE_RECORDER_EVENT_TYPE_ERROR,
984 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
988 muse_core_msg_free(error_msg);
991 LOGE("add error msg for service disconnection done");
1000 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1001 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1003 if (!handler_info || !thread_name || !cb_info) {
1004 LOGE("t:%d NULL %p %p %p",
1005 type, handler_info, thread_name, cb_info);
1011 handler_info->type = type;
1012 handler_info->queue = g_queue_new();
1013 if (handler_info->queue == NULL) {
1014 LOGE("t:%d queue failed", type);
1018 g_mutex_init(&handler_info->mutex);
1019 g_cond_init(&handler_info->cond);
1021 handler_info->cb_info = (void *)cb_info;
1022 g_atomic_int_set(&handler_info->running, 1);
1024 handler_info->thread = g_thread_try_new(thread_name,
1025 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1026 if (handler_info->thread == NULL) {
1028 LOGE("t:%d thread failed", type);
1030 g_mutex_clear(&handler_info->mutex);
1031 g_cond_clear(&handler_info->cond);
1032 g_queue_free(handler_info->queue);
1033 handler_info->queue = NULL;
1039 LOGD("t:%d done", type);
1045 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1049 if (!handler_info) {
1050 LOGE("NULL handler");
1054 if (!handler_info->thread) {
1055 LOGW("thread is not created");
1059 type = handler_info->type;
1061 LOGD("t:%d thread %p", type, handler_info->thread);
1063 g_mutex_lock(&handler_info->mutex);
1064 g_atomic_int_set(&handler_info->running, 0);
1065 g_cond_signal(&handler_info->cond);
1066 g_mutex_unlock(&handler_info->mutex);
1068 g_thread_join(handler_info->thread);
1069 handler_info->thread = NULL;
1071 g_mutex_clear(&handler_info->mutex);
1072 g_cond_clear(&handler_info->cond);
1073 g_queue_free(handler_info->queue);
1074 handler_info->queue = NULL;
1076 LOGD("t:%d done", type);
1082 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1084 recorder_cb_info_s *cb_info = NULL;
1087 g_return_val_if_fail(sockfd > 0, NULL);
1089 cb_info = g_new0(recorder_cb_info_s, 1);
1090 if (cb_info == NULL) {
1091 LOGE("cb_info failed");
1095 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1097 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1098 g_mutex_init(&cb_info->api_mutex[i]);
1099 g_cond_init(&cb_info->api_cond[i]);
1102 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1103 g_mutex_init(&cb_info->user_cb_mutex[i]);
1105 /* message handler thread */
1106 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1107 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1108 LOGE("msg_handler_info failed");
1112 /* message handler thread for audio stream callback */
1113 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1114 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1115 LOGE("audio_stream_cb_info failed");
1119 /* message handler thread for muxed stream callback */
1120 if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
1121 _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
1122 LOGE("muxed_stream_cb_info failed");
1126 cb_info->fd = sockfd;
1128 /* message receive thread */
1129 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1130 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1131 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1132 if (cb_info->msg_recv_thread == NULL) {
1133 LOGE("message receive thread creation failed");
1137 cb_info->is_server_connected = TRUE;
1143 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1144 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1145 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1147 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1148 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1150 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1151 g_mutex_clear(&cb_info->api_mutex[i]);
1152 g_cond_clear(&cb_info->api_cond[i]);
1163 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1165 int ret = RECORDER_ERROR_NONE;
1168 /*LOGD("Enter api : %d", api);*/
1170 if (!cb_info->is_server_connected) {
1171 LOGE("server is disconnected");
1172 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1175 g_mutex_lock(&(cb_info->api_mutex[api]));
1177 if (cb_info->api_activating[api] == 0) {
1178 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1179 LOGW("wait for api %d", api);
1180 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1181 ret = cb_info->api_ret[api];
1182 cb_info->api_activating[api] = 0;
1183 LOGW("api %d returned 0x%x", api, ret);
1185 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1186 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1187 ret = cb_info->api_ret[api];
1188 cb_info->api_activating[api] = 0;
1189 /*LOGD("return value : 0x%x", ret);*/
1191 ret = RECORDER_ERROR_INVALID_OPERATION;
1192 LOGE("api %d was TIMED OUT!", api);
1196 ret = cb_info->api_ret[api];
1197 cb_info->api_activating[api] = 0;
1199 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1202 if (ret != RECORDER_ERROR_NONE)
1203 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1205 g_mutex_unlock(&(cb_info->api_mutex[api]));
1211 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
1216 if (!cb_info || !ret) {
1217 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1218 return RECORDER_ERROR_INVALID_PARAMETER;
1221 msg = muse_core_msg_new(api, NULL);
1223 LOGE("msg creation failed: api %d", api);
1224 return RECORDER_ERROR_OUT_OF_MEMORY;
1227 /*LOGD("send msg %s", msg);*/
1229 if (cb_info->is_server_connected) {
1230 __recorder_update_api_waiting(cb_info, api, 1);
1231 send_ret = muse_core_msg_send(cb_info->fd, msg);
1235 LOGE("message send failed");
1236 *ret = RECORDER_ERROR_INVALID_OPERATION;
1238 *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
1241 __recorder_update_api_waiting(cb_info, api, -1);
1243 muse_core_msg_free(msg);
1245 return RECORDER_ERROR_NONE;
1249 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1254 if (!cb_info || !ret || !param) {
1255 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1256 return RECORDER_ERROR_INVALID_PARAMETER;
1259 /*LOGD("type %d, name %s", param->type, param->name);*/
1261 switch (param->type) {
1263 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_INT, NULL);
1265 case MUSE_TYPE_DOUBLE:
1266 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1268 case MUSE_TYPE_STRING:
1269 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_STRING, NULL);
1272 LOGE("unknown type %d", param->type);
1277 LOGE("msg creation failed: api %d, type %d, param name %s",
1278 api, param->type, param->name);
1279 return RECORDER_ERROR_OUT_OF_MEMORY;
1282 /*LOGD("send msg %s", msg);*/
1284 if (cb_info->is_server_connected) {
1285 __recorder_update_api_waiting(cb_info, api, 1);
1287 send_ret = muse_core_msg_send(cb_info->fd, msg);
1291 LOGE("message send failed");
1292 *ret = RECORDER_ERROR_INVALID_OPERATION;
1294 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1297 __recorder_update_api_waiting(cb_info, api, -1);
1299 muse_core_msg_free(msg);
1301 return RECORDER_ERROR_NONE;
1305 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1309 g_return_if_fail(cb_info != NULL);
1311 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1313 g_thread_join(cb_info->msg_recv_thread);
1314 cb_info->msg_recv_thread = NULL;
1316 LOGD("msg_recv thread removed");
1318 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1319 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1320 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1322 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1323 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1325 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1326 g_mutex_clear(&cb_info->api_mutex[i]);
1327 g_cond_clear(&cb_info->api_cond[i]);
1330 if (cb_info->fd > -1) {
1331 muse_client_close(cb_info->fd);
1335 if (cb_info->bufmgr) {
1336 tbm_bufmgr_deinit(cb_info->bufmgr);
1337 cb_info->bufmgr = NULL;
1339 if (cb_info->get_filename) {
1340 free(cb_info->get_filename);
1341 cb_info->get_filename = NULL;
1351 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1353 char **root_directory = (char **)user_data;
1355 if (root_directory == NULL) {
1356 LOGE("user data is NULL");
1360 LOGD("storage id %d, type %d, state %d, path %s",
1361 storage_id, type, state, path ? path : "NULL");
1363 if (type == STORAGE_TYPE_INTERNAL && path) {
1364 if (*root_directory) {
1365 free(*root_directory);
1366 *root_directory = NULL;
1369 *root_directory = strdup(path);
1370 if (*root_directory) {
1371 LOGD("get root directory %s", *root_directory);
1374 LOGE("strdup %s failed", path);
1381 static int _recorder_client_get_root_directory(char **root_directory)
1383 int ret = STORAGE_ERROR_NONE;
1385 if (root_directory == NULL) {
1386 LOGE("user data is NULL");
1390 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1391 if (ret != STORAGE_ERROR_NONE) {
1392 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1399 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1401 int ret = RECORDER_ERROR_NONE;
1402 int destroy_ret = RECORDER_ERROR_NONE;
1404 int module_index = -1;
1406 char *send_msg = NULL;
1407 char *root_directory = NULL;
1408 intptr_t camera_handle = 0;
1409 intptr_t handle = 0;
1410 tbm_bufmgr bufmgr = NULL;
1411 recorder_cli_s *pc = NULL;
1412 recorder_msg_param param;
1414 LOGD("Enter - type %d", type);
1416 if (recorder == NULL) {
1417 LOGE("NULL pointer for recorder handle");
1418 return RECORDER_ERROR_INVALID_PARAMETER;
1421 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1422 LOGE("NULL pointer for camera handle on video recorder mode");
1423 return RECORDER_ERROR_INVALID_PARAMETER;
1426 bufmgr = tbm_bufmgr_init(-1);
1427 if (bufmgr == NULL) {
1428 LOGE("get tbm bufmgr failed");
1429 return RECORDER_ERROR_INVALID_OPERATION;
1432 pc = g_new0(recorder_cli_s, 1);
1434 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1435 goto _ERR_RECORDER_EXIT;
1438 sock_fd = muse_client_new();
1441 LOGE("muse_client_new failed - returned fd %d", sock_fd);
1442 ret = RECORDER_ERROR_INVALID_OPERATION;
1443 goto _ERR_RECORDER_EXIT;
1447 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
1448 LOGE("muse client get module index failed");
1449 ret = RECORDER_ERROR_INVALID_OPERATION;
1450 goto _ERR_RECORDER_EXIT;
1453 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1454 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1455 MUSE_TYPE_INT, "module", module_index,
1456 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1457 MUSE_TYPE_INT, "pid", getpid(),
1460 pc->camera = camera;
1461 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1462 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1463 MUSE_TYPE_INT, "module", module_index,
1464 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1465 MUSE_TYPE_INT, "pid", getpid(),
1466 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1473 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1474 goto _ERR_RECORDER_EXIT;
1478 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1480 send_ret = muse_core_msg_send(sock_fd, send_msg);
1482 muse_core_msg_free(send_msg);
1487 LOGE("send msg failed %d", errno);
1488 ret = RECORDER_ERROR_INVALID_OPERATION;
1489 goto _ERR_RECORDER_EXIT;
1493 pc->cb_info = _recorder_client_callback_new(sock_fd);
1494 if (pc->cb_info == NULL) {
1495 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1496 goto _ERR_RECORDER_EXIT;
1501 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1503 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1505 if (ret != RECORDER_ERROR_NONE) {
1506 LOGE("API_CREATE failed 0x%x", ret);
1507 goto _ERR_RECORDER_EXIT;
1510 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1513 LOGE("Receiving Handle Failed!!");
1514 ret = RECORDER_ERROR_INVALID_OPERATION;
1515 goto _ERR_RECORDER_AFTER_CREATE;
1519 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1521 LOGE("failed to get root directory of internal storage");
1522 ret = RECORDER_ERROR_INVALID_OPERATION;
1523 goto _ERR_RECORDER_AFTER_CREATE;
1527 LOGD("root directory [%s]", root_directory);
1529 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1531 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1533 if (ret != RECORDER_ERROR_NONE) {
1534 LOGE("failed to set root directory %s", root_directory);
1535 ret = RECORDER_ERROR_INVALID_OPERATION;
1536 goto _ERR_RECORDER_AFTER_CREATE;
1539 free(root_directory);
1540 root_directory = NULL;
1542 pc->remote_handle = handle;
1543 pc->cb_info->bufmgr = bufmgr;
1545 LOGD("recorder[type %d] %p create success : remote handle 0x%td",
1546 type, pc, pc->remote_handle);
1548 *recorder = (recorder_h)pc;
1552 return RECORDER_ERROR_NONE;
1554 _ERR_RECORDER_AFTER_CREATE:
1555 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
1556 LOGE("destroy return 0x%x", destroy_ret);
1559 tbm_bufmgr_deinit(bufmgr);
1562 if (root_directory) {
1563 free(root_directory);
1564 root_directory = NULL;
1568 muse_client_close(sock_fd);
1574 _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 : %td", pc->remote_handle);
1616 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
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, RECORDER_CB_TIMEOUT);
1643 LOGW("server disconnected. release resource without send message.");
1645 if (ret == RECORDER_ERROR_NONE) {
1646 _recorder_deactivate_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, RECORDER_CB_TIMEOUT);
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;
1698 ret = camera_get_state(pc->camera, &camera_state);
1699 if (ret != CAMERA_ERROR_NONE) {
1700 LOGE("failed to get camera state 0x%x", ret);
1701 return RECORDER_ERROR_INVALID_OPERATION;
1704 if (camera_state == CAMERA_STATE_PREVIEW) {
1705 ret = camera_stop_evas_rendering(pc->camera, false);
1706 if (ret != CAMERA_ERROR_NONE) {
1707 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1708 return RECORDER_ERROR_INVALID_OPERATION;
1714 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1716 LOGD("ret : 0x%x", ret);
1722 int recorder_start(recorder_h recorder)
1724 int ret = RECORDER_ERROR_NONE;
1725 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1726 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1727 recorder_state_e current_state = RECORDER_STATE_NONE;
1729 if (!pc || !pc->cb_info) {
1730 LOGE("NULL handle");
1731 return RECORDER_ERROR_INVALID_PARAMETER;
1738 ret = recorder_get_state(recorder, ¤t_state);
1739 if (ret != RECORDER_ERROR_NONE) {
1740 LOGE("failed to get current state 0x%x", ret);
1741 return RECORDER_ERROR_INVALID_OPERATION;
1744 if (current_state == RECORDER_STATE_READY) {
1745 ret = camera_stop_evas_rendering(pc->camera, true);
1746 if (ret != CAMERA_ERROR_NONE) {
1747 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1748 return RECORDER_ERROR_INVALID_OPERATION;
1754 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
1756 if (pc->camera && current_state == RECORDER_STATE_READY)
1757 camera_start_evas_rendering(pc->camera);
1759 LOGD("ret : 0x%x", ret);
1765 int recorder_pause(recorder_h recorder)
1767 int ret = RECORDER_ERROR_NONE;
1768 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1769 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1771 if (!pc || !pc->cb_info) {
1772 LOGE("NULL handle");
1773 return RECORDER_ERROR_INVALID_PARAMETER;
1778 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1780 LOGD("ret : 0x%x", ret);
1786 int recorder_commit(recorder_h recorder)
1788 int ret = RECORDER_ERROR_NONE;
1789 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1790 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1791 recorder_state_e current_state = RECORDER_STATE_NONE;
1793 if (!pc || !pc->cb_info) {
1794 LOGE("NULL handle");
1795 return RECORDER_ERROR_INVALID_PARAMETER;
1802 ret = recorder_get_state(recorder, ¤t_state);
1803 if (ret != RECORDER_ERROR_NONE) {
1804 LOGE("failed to get current state 0x%x", ret);
1805 return RECORDER_ERROR_INVALID_OPERATION;
1808 if (current_state >= RECORDER_STATE_RECORDING) {
1809 ret = camera_stop_evas_rendering(pc->camera, true);
1810 if (ret != CAMERA_ERROR_NONE) {
1811 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1812 return RECORDER_ERROR_INVALID_OPERATION;
1818 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1820 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1821 camera_start_evas_rendering(pc->camera);
1823 LOGD("ret : 0x%x", ret);
1829 int recorder_cancel(recorder_h recorder)
1831 int ret = RECORDER_ERROR_NONE;
1832 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1833 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1834 recorder_state_e current_state = RECORDER_STATE_NONE;
1836 if (!pc || !pc->cb_info) {
1837 LOGE("NULL handle");
1838 return RECORDER_ERROR_INVALID_PARAMETER;
1844 ret = recorder_get_state(recorder, ¤t_state);
1845 if (ret != RECORDER_ERROR_NONE) {
1846 LOGE("failed to get current state 0x%x", ret);
1847 return RECORDER_ERROR_INVALID_OPERATION;
1850 if (current_state >= RECORDER_STATE_RECORDING) {
1851 ret = camera_stop_evas_rendering(pc->camera, true);
1852 if (ret != CAMERA_ERROR_NONE) {
1853 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1854 return RECORDER_ERROR_INVALID_OPERATION;
1859 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1861 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1862 camera_start_evas_rendering(pc->camera);
1864 LOGD("ret : 0x%x", ret);
1870 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1872 int ret = RECORDER_ERROR_NONE;
1874 char *send_msg = NULL;
1875 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1876 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1878 if (!pc || !pc->cb_info) {
1879 LOGE("NULL handle");
1880 return RECORDER_ERROR_INVALID_PARAMETER;
1885 send_msg = muse_core_msg_new(api,
1886 MUSE_TYPE_INT, "width", width,
1887 MUSE_TYPE_INT, "height", height,
1890 if (pc->cb_info->is_server_connected) {
1891 __recorder_update_api_waiting(pc->cb_info, api, 1);
1893 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
1897 LOGE("message send failed");
1898 ret = RECORDER_ERROR_INVALID_OPERATION;
1900 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1903 __recorder_update_api_waiting(pc->cb_info, api, -1);
1905 muse_core_msg_free(send_msg);
1907 LOGE("failed to create msg");
1908 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1911 LOGD("ret : 0x%x", ret);
1917 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1919 int ret = RECORDER_ERROR_NONE;
1920 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1921 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1923 if (!pc || !pc->cb_info) {
1924 LOGE("NULL handle");
1925 return RECORDER_ERROR_INVALID_PARAMETER;
1928 if (!width || !height) {
1929 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1930 return RECORDER_ERROR_INVALID_PARAMETER;
1935 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1937 if (ret == RECORDER_ERROR_NONE) {
1938 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1939 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1942 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1948 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1949 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1951 int ret = RECORDER_ERROR_NONE;
1952 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1953 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1955 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1956 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1957 return RECORDER_ERROR_INVALID_PARAMETER;
1960 LOGD("Enter, handle :%td", pc->remote_handle);
1962 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1963 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
1965 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1967 LOGD("ret : 0x%x", ret);
1973 int recorder_get_audio_level(recorder_h recorder, double *level)
1975 int ret = RECORDER_ERROR_NONE;
1976 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
1977 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1979 if (!pc || !pc->cb_info || level == NULL) {
1980 LOGE("NULL pointer %p %p", pc, level);
1981 return RECORDER_ERROR_INVALID_PARAMETER;
1986 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1988 if (ret == RECORDER_ERROR_NONE)
1989 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
1991 LOGD("ret : 0x%x, level %lf", ret, *level);
1997 int recorder_set_filename(recorder_h recorder, const char *filename)
1999 int ret = RECORDER_ERROR_NONE;
2001 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2002 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2003 recorder_msg_param param;
2004 char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2006 if (!pc || !pc->cb_info) {
2007 LOGE("NULL handle");
2008 return RECORDER_ERROR_INVALID_PARAMETER;
2011 if (filename == NULL) {
2012 LOGE("filename is NULL");
2013 return RECORDER_ERROR_INVALID_PARAMETER;
2016 LOGD("ENTER [%s]", filename);
2018 length = strlen(filename);
2020 if (length >= RECORDER_FILENAME_MAX - 1) {
2021 LOGE("too long file name [%zu]", length);
2022 return RECORDER_ERROR_INVALID_PARAMETER;
2025 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2026 /* Cannot convert. Use original path. */
2027 strncpy(set_filename, filename, length + 1);
2028 pc->cb_info->is_filename_converted = FALSE;
2030 /* Converted. Use converted path. */
2031 LOGD("Converted filename : %s -> %s", filename, set_filename);
2032 pc->cb_info->is_filename_converted = TRUE;
2035 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2037 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2039 LOGD("ret : 0x%x", ret);
2045 int recorder_get_filename(recorder_h recorder, char **filename)
2047 int ret = RECORDER_ERROR_NONE;
2048 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2049 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2050 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2052 if (!pc || !pc->cb_info) {
2053 LOGE("NULL handle");
2054 return RECORDER_ERROR_INVALID_PARAMETER;
2057 if (filename == NULL) {
2058 LOGE("filename is NULL");
2059 return RECORDER_ERROR_INVALID_PARAMETER;
2064 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2066 if (ret == RECORDER_ERROR_NONE) {
2067 if (pc->cb_info->is_filename_converted == FALSE ||
2068 storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2069 /* Use original path. */
2070 *filename = pc->cb_info->get_filename;
2072 /* Converted. Use converted path. */
2073 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2074 *filename = strdup(compat_filename);
2075 free(pc->cb_info->get_filename);
2078 pc->cb_info->get_filename = NULL;
2081 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2087 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2089 int ret = RECORDER_ERROR_NONE;
2090 int set_format = (int)format;
2091 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2092 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2093 recorder_msg_param param;
2095 if (!pc || !pc->cb_info) {
2096 LOGE("NULL handle");
2097 return RECORDER_ERROR_INVALID_PARAMETER;
2100 LOGD("ENTER, set_format : %d", set_format);
2102 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2104 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2106 LOGD("ret : 0x%x", ret);
2111 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2113 int ret = RECORDER_ERROR_NONE;
2114 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2115 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2117 if (!pc || !pc->cb_info) {
2118 LOGE("NULL handle");
2119 return RECORDER_ERROR_INVALID_PARAMETER;
2122 if (format == NULL) {
2123 LOGE("NULL pointer data");
2124 return RECORDER_ERROR_INVALID_PARAMETER;
2129 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2131 if (ret == RECORDER_ERROR_NONE)
2132 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2134 LOGD("ret : 0x%x, format %d", ret, *format);
2140 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2142 int ret = RECORDER_ERROR_NONE;
2143 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2144 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2145 bool is_available = false;
2146 int stream_index = 0;
2147 char *stream_type = NULL;
2148 char *send_msg = NULL;
2151 if (!pc || !pc->cb_info || stream_info == NULL) {
2152 LOGE("NULL handle");
2153 return RECORDER_ERROR_INVALID_PARAMETER;
2158 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2159 if (ret != SOUND_MANAGER_ERROR_NONE) {
2160 LOGE("stream info verification failed");
2161 return RECORDER_ERROR_INVALID_OPERATION;
2164 if (is_available == false) {
2165 LOGE("stream information is not available");
2166 return RECORDER_ERROR_INVALID_OPERATION;
2169 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2170 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2172 LOGD("sound manager return [0x%x]", ret);
2174 if (ret == SOUND_MANAGER_ERROR_NONE) {
2175 send_msg = muse_core_msg_new(api,
2176 MUSE_TYPE_STRING, "stream_type", stream_type,
2177 MUSE_TYPE_INT, "stream_index", stream_index,
2180 if (pc->cb_info->is_server_connected) {
2181 __recorder_update_api_waiting(pc->cb_info, api, 1);
2183 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
2187 LOGE("message send failed");
2188 ret = RECORDER_ERROR_INVALID_OPERATION;
2190 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2193 __recorder_update_api_waiting(pc->cb_info, api, -1);
2195 muse_core_msg_free(send_msg);
2197 LOGE("failed to create msg");
2198 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2201 ret = RECORDER_ERROR_INVALID_OPERATION;
2208 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2210 int ret = RECORDER_ERROR_NONE;
2211 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2212 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2214 if (!pc || !pc->cb_info || callback == NULL) {
2215 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2216 return RECORDER_ERROR_INVALID_PARAMETER;
2219 LOGD("Enter, handle :%td", pc->remote_handle);
2221 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2223 if (ret == RECORDER_ERROR_NONE) {
2224 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2226 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2227 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2229 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2232 LOGD("ret : 0x%x", ret);
2238 int recorder_unset_state_changed_cb(recorder_h recorder)
2240 int ret = RECORDER_ERROR_NONE;
2241 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2242 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2244 if (!pc || !pc->cb_info) {
2245 LOGE("NULL handle");
2246 return RECORDER_ERROR_INVALID_PARAMETER;
2251 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2253 if (ret == RECORDER_ERROR_NONE) {
2254 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2256 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2257 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2259 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2262 LOGD("ret : 0x%x", ret);
2268 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2270 int ret = RECORDER_ERROR_NONE;
2271 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2272 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2274 if (!pc || !pc->cb_info || callback == NULL) {
2275 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2276 return RECORDER_ERROR_INVALID_PARAMETER;
2279 LOGD("Enter, handle :%td", pc->remote_handle);
2281 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2283 if (ret == RECORDER_ERROR_NONE) {
2284 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2286 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2287 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2289 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2292 LOGD("ret : 0x%x", ret);
2298 int recorder_unset_interrupted_cb(recorder_h recorder)
2300 int ret = RECORDER_ERROR_NONE;
2301 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2302 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2304 if (!pc || !pc->cb_info) {
2305 LOGE("NULL handle");
2306 return RECORDER_ERROR_INVALID_PARAMETER;
2311 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2313 if (ret == RECORDER_ERROR_NONE) {
2314 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2316 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2317 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2319 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2322 LOGD("ret : 0x%x", ret);
2328 int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
2330 int ret = RECORDER_ERROR_NONE;
2331 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2332 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
2334 if (!pc || !pc->cb_info || callback == NULL) {
2335 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2336 return RECORDER_ERROR_INVALID_PARAMETER;
2339 LOGD("Enter, handle :%td", pc->remote_handle);
2341 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2343 if (ret == RECORDER_ERROR_NONE) {
2344 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2346 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
2347 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
2349 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2352 LOGD("ret : 0x%x", ret);
2358 int recorder_unset_interrupt_started_cb(recorder_h recorder)
2360 int ret = RECORDER_ERROR_NONE;
2361 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
2362 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2364 if (!pc || !pc->cb_info) {
2365 LOGE("NULL handle");
2366 return RECORDER_ERROR_INVALID_PARAMETER;
2371 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2373 if (ret == RECORDER_ERROR_NONE) {
2374 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2376 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2377 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2379 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2382 LOGD("ret : 0x%x", ret);
2388 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2390 int ret = RECORDER_ERROR_NONE;
2391 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2392 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2394 if (!pc || !pc->cb_info || callback == NULL) {
2395 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2396 return RECORDER_ERROR_INVALID_PARAMETER;
2399 LOGD("Enter, handle :%td", pc->remote_handle);
2401 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2403 if (ret == RECORDER_ERROR_NONE) {
2404 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2406 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2407 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2409 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2412 LOGD("ret : 0x%x", ret);
2418 int recorder_unset_audio_stream_cb(recorder_h recorder)
2420 int ret = RECORDER_ERROR_NONE;
2421 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2422 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2424 if (!pc || !pc->cb_info) {
2425 LOGE("NULL handle");
2426 return RECORDER_ERROR_INVALID_PARAMETER;
2431 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2433 if (ret == RECORDER_ERROR_NONE) {
2434 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2436 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2437 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2439 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2442 LOGD("ret : 0x%x", ret);
2448 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2450 int ret = RECORDER_ERROR_NONE;
2451 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2452 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2454 if (!pc || !pc->cb_info || !callback) {
2455 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2456 return RECORDER_ERROR_INVALID_PARAMETER;
2459 LOGD("Enter, handle :%td", pc->remote_handle);
2461 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2463 if (ret == RECORDER_ERROR_NONE) {
2464 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2466 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2467 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2469 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2472 LOGD("ret : 0x%x", ret);
2478 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2480 int ret = RECORDER_ERROR_NONE;
2481 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2482 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2484 if (!pc || !pc->cb_info) {
2485 LOGE("NULL handle");
2486 return RECORDER_ERROR_INVALID_PARAMETER;
2491 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2493 if (ret == RECORDER_ERROR_NONE) {
2494 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2496 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2497 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2499 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2502 LOGD("ret : 0x%x", ret);
2508 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2510 int ret = RECORDER_ERROR_NONE;
2511 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2512 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2514 if (!pc || !pc->cb_info || callback == NULL) {
2515 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2516 return RECORDER_ERROR_INVALID_PARAMETER;
2519 LOGD("Enter, handle :%td", pc->remote_handle);
2521 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2523 if (ret == RECORDER_ERROR_NONE) {
2524 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2526 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2527 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2529 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2532 LOGD("ret : 0x%x", ret);
2538 int recorder_unset_error_cb(recorder_h recorder)
2540 int ret = RECORDER_ERROR_NONE;
2541 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2542 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2544 if (!pc || !pc->cb_info) {
2545 LOGE("NULL handle");
2546 return RECORDER_ERROR_INVALID_PARAMETER;
2551 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2553 if (ret == RECORDER_ERROR_NONE) {
2554 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2556 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2557 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2559 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2562 LOGD("ret : 0x%x", ret);
2568 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2570 int ret = RECORDER_ERROR_NONE;
2571 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2572 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2574 if (!pc || !pc->cb_info || callback == NULL) {
2575 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2576 return RECORDER_ERROR_INVALID_PARAMETER;
2579 LOGD("Enter, handle :%td", pc->remote_handle);
2581 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2583 if (ret == RECORDER_ERROR_NONE) {
2584 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2586 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2587 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2589 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2592 LOGD("ret : 0x%x", ret);
2598 int recorder_unset_recording_status_cb(recorder_h recorder)
2600 int ret = RECORDER_ERROR_NONE;
2601 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2602 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2604 if (!pc || !pc->cb_info) {
2605 LOGE("NULL handle");
2606 return RECORDER_ERROR_INVALID_PARAMETER;
2611 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2613 if (ret == RECORDER_ERROR_NONE) {
2614 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2616 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2617 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2619 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2622 LOGD("ret : 0x%x", ret);
2628 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2630 int ret = RECORDER_ERROR_NONE;
2631 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2632 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2634 if (!pc || !pc->cb_info || callback == NULL) {
2635 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2636 return RECORDER_ERROR_INVALID_PARAMETER;
2639 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2641 if (ret == RECORDER_ERROR_NONE) {
2642 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2644 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2645 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2647 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2650 LOGD("ret : 0x%x", ret);
2656 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2658 int ret = RECORDER_ERROR_NONE;
2659 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2660 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2662 if (!pc || !pc->cb_info) {
2663 LOGE("NULL handle");
2664 return RECORDER_ERROR_INVALID_PARAMETER;
2669 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2671 if (ret == RECORDER_ERROR_NONE) {
2672 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2674 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2675 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2677 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2680 LOGD("ret : 0x%x", ret);
2686 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2688 int ret = RECORDER_ERROR_NONE;
2689 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2690 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2692 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2693 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2694 return RECORDER_ERROR_INVALID_PARAMETER;
2697 LOGD("Enter, handle :%td", pc->remote_handle);
2699 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2700 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2702 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2704 LOGD("ret : 0x%x", ret);
2710 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2712 int ret = RECORDER_ERROR_NONE;
2713 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2714 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2715 recorder_msg_param param;
2717 if (!pc || !pc->cb_info) {
2718 LOGE("NULL handle");
2719 return RECORDER_ERROR_INVALID_PARAMETER;
2724 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2726 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2728 LOGD("ret : 0x%x", ret);
2734 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2736 int ret = RECORDER_ERROR_NONE;
2737 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2738 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2739 recorder_msg_param param;
2741 if (!pc || !pc->cb_info) {
2742 LOGE("NULL handle");
2743 return RECORDER_ERROR_INVALID_PARAMETER;
2748 RECORDER_MSG_PARAM_SET(param, INT, second);
2750 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2752 LOGD("ret : 0x%x", ret);
2758 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2760 int ret = RECORDER_ERROR_NONE;
2761 int set_device = (int)device;
2762 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2763 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2764 recorder_msg_param param;
2766 if (!pc || !pc->cb_info) {
2767 LOGE("NULL handle");
2768 return RECORDER_ERROR_INVALID_PARAMETER;
2773 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2775 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2777 LOGD("ret : 0x%x", ret);
2783 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2785 int ret = RECORDER_ERROR_NONE;
2786 int set_codec = (int)codec;
2787 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2788 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2789 recorder_msg_param param;
2791 if (!pc || !pc->cb_info) {
2792 LOGE("NULL handle");
2793 return RECORDER_ERROR_INVALID_PARAMETER;
2798 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2800 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2802 LOGD("ret : 0x%x", ret);
2808 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2810 int ret = RECORDER_ERROR_NONE;
2811 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2812 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2814 if (!pc || !pc->cb_info) {
2815 LOGE("NULL handle");
2816 return RECORDER_ERROR_INVALID_PARAMETER;
2819 if (codec == NULL) {
2820 LOGE("codec is NULL");
2821 return RECORDER_ERROR_INVALID_PARAMETER;
2826 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2828 if (ret == RECORDER_ERROR_NONE)
2829 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2831 LOGD("ret : 0x%x, codec %d", ret, *codec);
2837 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2839 int ret = RECORDER_ERROR_NONE;
2840 int set_codec = (int)codec;
2841 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2842 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2843 recorder_msg_param param;
2845 if (!pc || !pc->cb_info) {
2846 LOGE("NULL handle");
2847 return RECORDER_ERROR_INVALID_PARAMETER;
2852 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2854 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2856 LOGD("ret : 0x%x", ret);
2862 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2864 int ret = RECORDER_ERROR_NONE;
2865 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2866 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2868 if (!pc || !pc->cb_info) {
2869 LOGE("NULL handle");
2870 return RECORDER_ERROR_INVALID_PARAMETER;
2873 if (codec == NULL) {
2874 LOGE("codec is NULL");
2875 return RECORDER_ERROR_INVALID_PARAMETER;
2880 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2882 if (ret == RECORDER_ERROR_NONE)
2883 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2885 LOGD("ret : 0x%x, codec %d", ret, *codec);
2891 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2893 int ret = RECORDER_ERROR_NONE;
2894 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2895 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2896 recorder_msg_param param;
2898 if (!pc || !pc->cb_info) {
2899 LOGE("NULL handle");
2900 return RECORDER_ERROR_INVALID_PARAMETER;
2903 LOGD("ENTER, samplerate : %d", samplerate);
2905 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2907 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2909 LOGD("ret : 0x%x", ret);
2915 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2917 int ret = RECORDER_ERROR_NONE;
2918 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2919 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2920 recorder_msg_param param;
2922 if (!pc || !pc->cb_info) {
2923 LOGE("NULL handle");
2924 return RECORDER_ERROR_INVALID_PARAMETER;
2929 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2931 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2933 LOGD("ret : 0x%x", ret);
2939 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2941 int ret = RECORDER_ERROR_NONE;
2942 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2943 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2944 recorder_msg_param param;
2946 if (!pc || !pc->cb_info) {
2947 LOGE("NULL handle");
2948 return RECORDER_ERROR_INVALID_PARAMETER;
2953 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2955 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2957 LOGD("ret : 0x%x", ret);
2963 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2965 int ret = RECORDER_ERROR_NONE;
2966 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2967 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2969 if (!pc || !pc->cb_info) {
2970 LOGE("NULL handle");
2971 return RECORDER_ERROR_INVALID_PARAMETER;
2974 if (kbyte == NULL) {
2975 LOGE("NULL pointer kbyte");
2976 return RECORDER_ERROR_INVALID_PARAMETER;
2981 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2983 if (ret == RECORDER_ERROR_NONE)
2984 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2986 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2992 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2994 int ret = RECORDER_ERROR_NONE;
2995 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2996 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2998 if (!pc || !pc->cb_info) {
2999 LOGE("NULL handle");
3000 return RECORDER_ERROR_INVALID_PARAMETER;
3003 if (second == NULL) {
3004 LOGE("NULL pointer second");
3005 return RECORDER_ERROR_INVALID_PARAMETER;
3010 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3012 if (ret == RECORDER_ERROR_NONE)
3013 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
3015 LOGD("ret : 0x%x, %d second", ret, *second);
3021 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
3023 int ret = RECORDER_ERROR_NONE;
3024 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
3025 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3027 if (!pc || !pc->cb_info) {
3028 LOGE("NULL handle");
3029 return RECORDER_ERROR_INVALID_PARAMETER;
3032 if (device == NULL) {
3033 LOGE("NULL pointer device");
3034 return RECORDER_ERROR_INVALID_PARAMETER;
3039 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3041 if (ret == RECORDER_ERROR_NONE)
3042 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
3044 LOGD("ret : 0x%x, device %d", ret, *device);
3050 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
3052 int ret = RECORDER_ERROR_NONE;
3053 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
3054 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3056 if (!pc || !pc->cb_info) {
3057 LOGE("NULL handle");
3058 return RECORDER_ERROR_INVALID_PARAMETER;
3061 if (samplerate == NULL) {
3062 LOGE("NULL pointer handle");
3063 return RECORDER_ERROR_INVALID_PARAMETER;
3068 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3070 if (ret == RECORDER_ERROR_NONE)
3071 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3073 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3079 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3081 int ret = RECORDER_ERROR_NONE;
3082 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3083 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3085 if (!pc || !pc->cb_info) {
3086 LOGE("NULL handle");
3087 return RECORDER_ERROR_INVALID_PARAMETER;
3090 if (bitrate == NULL) {
3091 LOGE("NULL pointer");
3092 return RECORDER_ERROR_INVALID_PARAMETER;
3097 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3099 if (ret == RECORDER_ERROR_NONE)
3100 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3102 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3108 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3110 int ret = RECORDER_ERROR_NONE;
3111 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3112 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3114 if (!pc || !pc->cb_info) {
3115 LOGE("NULL handle");
3116 return RECORDER_ERROR_INVALID_PARAMETER;
3119 if (bitrate == NULL) {
3120 LOGE("NULL pointer");
3121 return RECORDER_ERROR_INVALID_PARAMETER;
3126 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3128 if (ret == RECORDER_ERROR_NONE)
3129 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3131 LOGD("ret : 0x%x", ret);
3137 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3139 int ret = RECORDER_ERROR_NONE;
3140 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3141 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3143 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3144 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3145 return RECORDER_ERROR_INVALID_PARAMETER;
3148 LOGD("Enter, handle :%td", pc->remote_handle);
3150 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3151 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3153 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3155 LOGD("ret : 0x%x", ret);
3161 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3163 int ret = RECORDER_ERROR_NONE;
3164 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3165 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3167 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3168 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3169 return RECORDER_ERROR_INVALID_PARAMETER;
3172 LOGD("Enter, handle :%td", pc->remote_handle);
3174 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3175 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3177 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3179 LOGD("ret : 0x%x", ret);
3185 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3187 int ret = RECORDER_ERROR_NONE;
3188 int set_enable = (int)enable;
3189 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3190 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3191 recorder_msg_param param;
3193 if (!pc || !pc->cb_info) {
3194 LOGE("NULL handle");
3195 return RECORDER_ERROR_INVALID_PARAMETER;
3200 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3202 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3204 LOGD("ret : 0x%x", ret);
3210 bool recorder_attr_is_muted(recorder_h recorder)
3213 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3214 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3216 if (!pc || !pc->cb_info) {
3217 LOGE("NULL handle");
3223 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3225 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3228 LOGD("ret : %d", ret);
3234 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3236 int ret = RECORDER_ERROR_NONE;
3237 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3238 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3239 recorder_msg_param param;
3241 if (!pc || !pc->cb_info) {
3242 LOGE("NULL handle");
3243 return RECORDER_ERROR_INVALID_PARAMETER;
3246 LOGD("ENTER - %.20lf", rate);
3248 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3250 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3252 LOGD("ret : 0x%x", ret);
3258 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3260 int ret = RECORDER_ERROR_NONE;
3261 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3262 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3264 if (!pc || !pc->cb_info) {
3265 LOGE("NULL handle");
3266 return RECORDER_ERROR_INVALID_PARAMETER;
3270 LOGE("rate is NULL");
3271 return RECORDER_ERROR_INVALID_PARAMETER;
3276 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3277 if (ret == RECORDER_ERROR_NONE)
3278 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3280 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3286 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3288 int ret = RECORDER_ERROR_NONE;
3289 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3290 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3291 recorder_msg_param param;
3293 if (!pc || !pc->cb_info) {
3294 LOGE("NULL handle");
3295 return RECORDER_ERROR_INVALID_PARAMETER;
3300 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3302 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3304 LOGD("ret : 0x%x", ret);
3310 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3312 int ret = RECORDER_ERROR_NONE;
3313 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3314 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3316 if (!pc || !pc->cb_info) {
3317 LOGE("NULL handle");
3318 return RECORDER_ERROR_INVALID_PARAMETER;
3321 if (channel_count == NULL) {
3322 LOGE("channel_count is NULL");
3323 return RECORDER_ERROR_INVALID_PARAMETER;
3328 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3330 if (ret == RECORDER_ERROR_NONE)
3331 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3333 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3339 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3341 int ret = RECORDER_ERROR_NONE;
3342 int set_orientation = (int)orientation;
3343 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3344 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3345 recorder_msg_param param;
3347 if (!pc || !pc->cb_info) {
3348 LOGE("NULL handle");
3349 return RECORDER_ERROR_INVALID_PARAMETER;
3354 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3356 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3358 LOGD("ret : 0x%x", ret);
3364 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3366 int ret = RECORDER_ERROR_NONE;
3367 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3368 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3370 if (!pc || !pc->cb_info) {
3371 LOGE("NULL handle");
3372 return RECORDER_ERROR_INVALID_PARAMETER;
3375 if (orientation == NULL) {
3376 LOGE("orientation is NULL");
3377 return RECORDER_ERROR_INVALID_PARAMETER;
3382 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3384 if (ret == RECORDER_ERROR_NONE)
3385 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3387 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3393 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3395 int ret = RECORDER_ERROR_NONE;
3397 int module_index = -1;
3398 int get_device_state = 0;
3399 char *send_msg = NULL;
3400 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3403 LOGE("NULL pointer");
3404 return RECORDER_ERROR_INVALID_PARAMETER;
3407 LOGD("Enter - type %d", type);
3409 sock_fd = muse_client_new();
3412 LOGE("muse_client_new failed - returned fd %d", sock_fd);
3413 ret = RECORDER_ERROR_INVALID_OPERATION;
3414 goto _GET_DEVICE_STATE_EXIT;
3418 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
3419 LOGE("muse client get module index failed");
3420 ret = RECORDER_ERROR_INVALID_OPERATION;
3421 goto _GET_DEVICE_STATE_EXIT;
3424 send_msg = muse_core_msg_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3425 MUSE_TYPE_INT, "module", module_index,
3426 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3431 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3432 goto _GET_DEVICE_STATE_EXIT;
3436 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3438 ret = muse_core_msg_send(sock_fd, send_msg);
3440 muse_core_msg_free(send_msg);
3445 LOGE("send msg failed %d", errno);
3446 ret = RECORDER_ERROR_INVALID_OPERATION;
3447 goto _GET_DEVICE_STATE_EXIT;
3451 ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_RECORDER_MSG_MAX_LENGTH);
3454 LOGE("recv msg failed %d", errno);
3455 ret = RECORDER_ERROR_INVALID_OPERATION;
3456 goto _GET_DEVICE_STATE_EXIT;
3460 if (!muse_recorder_msg_get(ret, recv_msg)) {
3462 LOGE("failed to get return value from msg [%s]", recv_msg);
3463 ret = RECORDER_ERROR_INVALID_OPERATION;
3464 goto _GET_DEVICE_STATE_EXIT;
3468 if (ret == RECORDER_ERROR_NONE) {
3469 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3470 *state = (recorder_device_state_e)get_device_state;
3471 LOGD("device type %d state %d", type, *state);
3473 LOGE("failed to get device state from msg [%s]", recv_msg);
3474 ret = RECORDER_ERROR_INVALID_OPERATION;
3477 LOGE("failed 0x%x", ret);
3480 _GET_DEVICE_STATE_EXIT:
3482 muse_client_close(sock_fd);
3490 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3492 int ret = RECORDER_ERROR_NONE;
3493 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3494 recorder_cb_info *info = NULL;
3496 if (!callback || !cb_id) {
3497 LOGE("invalid pointer %p %p", callback, cb_id);
3498 return RECORDER_ERROR_INVALID_PARAMETER;
3501 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3503 /* check recorder support */
3504 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3505 if (ret != RECORDER_ERROR_NONE) {
3506 LOGE("get device state failed");
3507 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3511 info = g_new0(recorder_cb_info, 1);
3513 LOGE("info failed");
3514 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3518 info->id = ++g_rec_dev_state_changed_cb_id;
3519 info->callback = (void *)callback;
3520 info->user_data = user_data;
3524 /* subscribe dbus signal for camera state change */
3525 if (!g_rec_dev_state_changed_cb_conn) {
3526 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3527 if (!g_rec_dev_state_changed_cb_conn) {
3528 LOGE("failed to get gdbus connection");
3529 ret = RECORDER_ERROR_INVALID_OPERATION;
3533 LOGD("subscribe signal %s - %s - %s",
3534 MM_CAMCORDER_DBUS_OBJECT,
3535 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3536 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3538 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3539 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3540 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3541 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3542 LOGE("failed to get gdbus connection");
3543 ret = RECORDER_ERROR_INVALID_OPERATION;
3547 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3550 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3552 LOGD("callback id %d", info->id);
3555 if (ret != RECORDER_ERROR_NONE) {
3562 if (g_rec_dev_state_changed_cb_conn) {
3563 g_object_unref(g_rec_dev_state_changed_cb_conn);
3564 g_rec_dev_state_changed_cb_conn = NULL;
3569 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3575 int recorder_remove_device_state_changed_cb(int cb_id)
3577 int ret = RECORDER_ERROR_NONE;
3578 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3579 GList *tmp_list = NULL;
3580 recorder_cb_info *info = NULL;
3582 /* check recorder support */
3583 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3584 if (ret != RECORDER_ERROR_NONE) {
3585 LOGE("get device state failed");
3589 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3591 if (!g_rec_dev_state_changed_cb_list) {
3592 LOGE("there is no callback info");
3593 ret = RECORDER_ERROR_INVALID_OPERATION;
3597 tmp_list = g_rec_dev_state_changed_cb_list;
3600 info = tmp_list->data;
3601 tmp_list = tmp_list->next;
3608 if (info->id == cb_id) {
3609 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3614 if (!g_rec_dev_state_changed_cb_list) {
3615 /* no remained callback */
3616 if (g_rec_dev_state_changed_cb_conn) {
3617 /* unsubscribe signal */
3618 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3619 g_rec_dev_state_changed_cb_subscribe_id = 0;
3621 /* unref connection */
3622 g_object_unref(g_rec_dev_state_changed_cb_conn);
3623 g_rec_dev_state_changed_cb_conn = NULL;
3627 LOGD("id %d callback removed", cb_id);
3628 ret = RECORDER_ERROR_NONE;
3634 LOGE("id %d callback not found", cb_id);
3635 ret = RECORDER_ERROR_INVALID_PARAMETER;
3638 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);