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);
333 case MUSE_RECORDER_EVENT_TYPE_ERROR:
336 int current_state = 0;
338 muse_recorder_msg_get(error, recv_msg);
339 muse_recorder_msg_get(current_state, recv_msg);
341 if (error == RECORDER_ERROR_SOUND_POLICY)
342 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
343 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
344 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
345 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
346 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
348 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
349 (recorder_state_e)current_state,
350 cb_info->user_data[event]);
353 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
357 muse_recorder_msg_get(codec, recv_msg);
359 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
360 cb_info->user_cb[event] = NULL;
361 cb_info->user_data[event] = NULL;
362 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
366 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
370 muse_recorder_msg_get(format, recv_msg);
372 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
373 cb_info->user_cb[event] = NULL;
374 cb_info->user_data[event] = NULL;
375 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
379 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
383 muse_recorder_msg_get(codec, recv_msg);
385 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
386 cb_info->user_cb[event] = NULL;
387 cb_info->user_data[event] = NULL;
388 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
392 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
397 muse_recorder_msg_get(width, recv_msg);
398 muse_recorder_msg_get(height, recv_msg);
400 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
401 cb_info->user_cb[event] = NULL;
402 cb_info->user_data[event] = NULL;
403 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
413 static bool _recorder_idle_event_callback(void *data)
415 recorder_cb_info_s *cb_info = NULL;
416 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
418 if (rec_idle_event == NULL) {
419 LOGE("rec_idle_event is NULL");
424 g_mutex_lock(&rec_idle_event->event_mutex);
426 cb_info = rec_idle_event->cb_info;
427 if (cb_info == NULL) {
428 LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
429 goto IDLE_EVENT_CALLBACK_DONE;
432 /* remove event from list */
433 g_mutex_lock(&cb_info->idle_event_mutex);
434 if (cb_info->idle_event_list)
435 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
437 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
438 g_mutex_unlock(&cb_info->idle_event_mutex);
441 _recorder_client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
443 /* send signal for waiting thread */
444 g_cond_signal(&cb_info->idle_event_cond);
446 IDLE_EVENT_CALLBACK_DONE:
447 /* unlock and release event */
448 g_mutex_unlock(&rec_idle_event->event_mutex);
449 g_mutex_clear(&rec_idle_event->event_mutex);
451 g_free(rec_idle_event);
452 rec_idle_event = NULL;
458 static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
460 recorder_idle_event_s *rec_idle_event = NULL;
465 if (cb_info == NULL) {
466 LOGE("cb_info is NULL");
470 g_mutex_lock(&cb_info->idle_event_mutex);
472 if (cb_info->idle_event_list == NULL) {
475 list = cb_info->idle_event_list;
478 rec_idle_event = list->data;
479 list = g_list_next(list);
481 if (!rec_idle_event) {
482 LOGW("The event is NULL");
486 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
489 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
491 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
492 LOGW("signal received");
499 ret = g_idle_remove_by_data(rec_idle_event);
501 LOGD("remove event %p, ret %d", rec_idle_event, ret);
504 rec_idle_event->cb_info = NULL;
505 LOGW("idle cb for event %p will be called later", rec_idle_event);
508 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
510 g_mutex_unlock(&rec_idle_event->event_mutex);
513 g_mutex_clear(&rec_idle_event->event_mutex);
515 g_free(rec_idle_event);
516 rec_idle_event = NULL;
518 LOGD("remove event done");
522 g_list_free(cb_info->idle_event_list);
523 cb_info->idle_event_list = NULL;
526 g_mutex_unlock(&cb_info->idle_event_mutex);
532 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
534 recorder_message_s *rec_msg = NULL;
536 if (!cb_info || !msg) {
537 LOGE("NULL pointer %p %p", cb_info, msg);
541 rec_msg = g_new0(recorder_message_s, 1);
543 LOGE("failed to alloc rec_msg for [%s]", msg);
548 rec_msg->event = event;
549 rec_msg->event_class = event_class;
551 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
553 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
555 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
556 g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
557 g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
558 g_cond_signal(&cb_info->audio_stream_cb_info.cond);
559 g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
561 g_mutex_lock(&cb_info->msg_handler_info.mutex);
562 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
563 g_cond_signal(&cb_info->msg_handler_info.cond);
564 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
573 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
575 if (!cb_info || !msg) {
576 LOGE("NULL pointer %p %p", cb_info, msg);
581 case MUSE_RECORDER_API_GET_STATE:
584 muse_recorder_msg_get(get_state, msg);
585 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
588 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
592 muse_recorder_msg_get(get_width, msg);
593 muse_recorder_msg_get(get_height, msg);
594 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
595 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
598 case MUSE_RECORDER_API_GET_FILE_FORMAT:
601 muse_recorder_msg_get(get_format, msg);
602 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
605 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
608 muse_recorder_msg_get(get_codec, msg);
609 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
612 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
615 muse_recorder_msg_get(get_codec, msg);
616 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
619 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
622 muse_recorder_msg_get(get_kbyte, msg);
623 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
626 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
629 muse_recorder_msg_get(get_second, msg);
630 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
633 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
636 muse_recorder_msg_get(get_device, msg);
637 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
640 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
642 int get_samplerate = 0;
643 muse_recorder_msg_get(get_samplerate, msg);
644 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
647 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
650 muse_recorder_msg_get(get_bitrate, msg);
651 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
654 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
657 muse_recorder_msg_get(get_bitrate, msg);
658 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
661 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
664 muse_recorder_msg_get_double(get_rate, msg);
665 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
668 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
670 int get_channel_count = 0;
671 muse_recorder_msg_get(get_channel_count, msg);
672 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
675 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
677 int get_orientation = 0;
678 muse_recorder_msg_get(get_orientation, msg);
679 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
682 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
684 double get_level = 0.0;
685 muse_recorder_msg_get_double(get_level, msg);
686 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
689 case MUSE_RECORDER_API_GET_FILENAME:
691 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
692 muse_recorder_msg_get_string(get_filename, msg);
693 if (cb_info->get_filename) {
694 free(cb_info->get_filename);
695 cb_info->get_filename = NULL;
697 cb_info->get_filename = strdup(get_filename);
708 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
710 int ret = RECORDER_ERROR_NONE;
714 int event_class = -1;
716 if (!cb_info || !msg) {
717 LOGE("invalid ptr %p %p", cb_info, msg);
721 /*LOGD("msg [%s]", msg);*/
723 if (!muse_recorder_msg_get(api, msg)) {
724 LOGE("failed to get recorder api");
728 if (api == MUSE_RECORDER_CB_EVENT) {
729 if (!muse_recorder_msg_get(event, msg) ||
730 !muse_recorder_msg_get(event_class, msg)) {
731 LOGE("failed to get event or event_class [%s]", msg);
735 if (!muse_recorder_msg_get(api_class, msg)) {
736 LOGE("failed to get api_class [%s]", msg);
741 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
742 if (api >= MUSE_RECORDER_API_MAX) {
743 LOGE("invalid api %d", api);
747 if (!muse_recorder_msg_get(ret, msg)) {
748 LOGE("failed to get recorder ret");
752 g_mutex_lock(&cb_info->api_mutex[api]);
754 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
755 g_atomic_int_set(&cb_info->msg_recv_running, 0);
756 LOGD("get device state done. close client cb handler");
759 case MUSE_RECORDER_API_CREATE:
760 if (ret != RECORDER_ERROR_NONE) {
761 g_atomic_int_set(&cb_info->msg_recv_running, 0);
762 LOGE("create error 0x%x. closing..", ret);
765 case MUSE_RECORDER_API_DESTROY:
766 if (ret == RECORDER_ERROR_NONE) {
767 g_atomic_int_set(&cb_info->msg_recv_running, 0);
768 LOGD("destroy done. closing..");
772 __recorder_get_api_operation(api, cb_info, msg);
777 if (cb_info->api_waiting[api] > 0) {
778 cb_info->api_ret[api] = ret;
779 cb_info->api_activating[api] = 1;
781 g_cond_signal(&cb_info->api_cond[api]);
783 LOGE("no waiting for api [%d]", api);
786 g_mutex_unlock(&cb_info->api_mutex[api]);
787 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
788 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
790 LOGW("unknown recorder api %d and api_class %d", api, api_class);
797 static void *_recorder_msg_handler_func(gpointer data)
801 recorder_message_s *rec_msg = NULL;
802 recorder_idle_event_s *rec_idle_event = NULL;
803 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
804 recorder_cb_info_s *cb_info = NULL;
806 if (!handler_info || !handler_info->cb_info) {
807 LOGE("NULL handler %p", handler_info);
811 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
812 type = handler_info->type;
814 LOGD("t:%d start", type);
816 g_mutex_lock(&handler_info->mutex);
818 while (g_atomic_int_get(&handler_info->running)) {
819 if (g_queue_is_empty(handler_info->queue)) {
820 /*LOGD("signal wait...");*/
821 g_cond_wait(&handler_info->cond, &handler_info->mutex);
822 /*LOGD("signal received");*/
824 if (g_atomic_int_get(&handler_info->running) == 0) {
825 LOGD("stop event thread");
830 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
831 g_mutex_unlock(&handler_info->mutex);
832 if (rec_msg == NULL) {
833 LOGE("NULL message");
834 g_mutex_lock(&handler_info->mutex);
840 if (api < MUSE_RECORDER_API_MAX) {
843 g_mutex_lock(&cb_info->api_mutex[api]);
845 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
846 if (cb_info->api_waiting[api] > 0) {
847 cb_info->api_ret[api] = ret;
848 cb_info->api_activating[api] = 1;
850 /*LOGD("recorder api %d - return 0x%x", ret);*/
852 g_cond_signal(&cb_info->api_cond[api]);
854 LOGE("no waiting for api [%d]", api);
857 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
860 g_mutex_unlock(&cb_info->api_mutex[api]);
861 } else if (api == MUSE_RECORDER_CB_EVENT) {
862 switch (rec_msg->event_class) {
863 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
864 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
866 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
867 rec_idle_event = g_new0(recorder_idle_event_s, 1);
868 if (rec_idle_event == NULL) {
869 LOGE("event alloc failed");
873 rec_idle_event->event = rec_msg->event;
874 rec_idle_event->cb_info = cb_info;
875 g_mutex_init(&rec_idle_event->event_mutex);
876 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
878 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
880 g_mutex_lock(&cb_info->idle_event_mutex);
881 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
882 g_mutex_unlock(&cb_info->idle_event_mutex);
884 g_idle_add_full(G_PRIORITY_DEFAULT,
885 (GSourceFunc)_recorder_idle_event_callback,
886 (gpointer)rec_idle_event,
890 LOGE("unknown event class %d", rec_msg->event_class);
894 LOGE("unknown api[%d] message", api);
900 g_mutex_lock(&handler_info->mutex);
903 /* remove remained event */
904 while (!g_queue_is_empty(handler_info->queue)) {
905 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
907 LOGD("remove message %p", rec_msg);
911 LOGW("NULL message");
915 g_mutex_unlock(&handler_info->mutex);
923 static void *_recorder_msg_recv_func(gpointer data)
926 int single_length = 0;
927 int remained_length = 0;
928 char *recv_msg = NULL;
929 char *single_msg = NULL;
930 char *remained_msg = NULL;
934 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
936 if (cb_info == NULL) {
937 LOGE("cb_info NULL");
943 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
944 if (single_msg == NULL) {
945 LOGE("single_msg malloc failed");
946 goto CB_HANDLER_EXIT;
949 recv_msg = cb_info->recv_msg;
951 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
952 recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
953 if (recv_length <= 0) {
954 cb_info->is_server_connected = FALSE;
955 LOGE("receive msg failed - server disconnected");
959 recv_msg[recv_length] = '\0';
965 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
967 /* Need to split the combined entering msgs */
968 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
969 if (recv_msg[cur_pos] == '}') {
970 single_length = cur_pos - prev_pos + 1;
972 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
973 /* check remained msg */
974 if (remained_length > 0) {
976 strncpy(single_msg, remained_msg, remained_length);
977 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
978 single_msg[remained_length + single_length] = '\0';
983 strncpy(single_msg, recv_msg + prev_pos, single_length);
984 single_msg[single_length] = '\0';
985 LOGE("lost msg [%s], skip...", single_msg);
990 strncpy(single_msg, recv_msg + prev_pos, single_length);
991 single_msg[single_length] = '\0';
994 if (single_msg[0] == '{') {
996 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
997 __recorder_process_msg(cb_info, single_msg);
999 LOGE("invalid msg [%s]", single_msg);
1002 LOGE("too long message [len %d] skip...", single_length);
1005 prev_pos = cur_pos + 1;
1009 /* check incompleted message */
1010 if (recv_msg[recv_length - 1] != '}') {
1011 remained_length = recv_length - prev_pos;
1013 LOGW("incompleted message [len %d]", remained_length);
1015 remained_msg = (char *)malloc(remained_length + 1);
1017 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
1018 remained_msg[remained_length] = '\0';
1020 LOGE("failed to alloc for remained msg");
1023 remained_length = 0;
1027 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1029 if (!cb_info->is_server_connected) {
1030 /* send error msg for server disconnection */
1031 char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
1032 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1033 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1037 LOGE("error_msg failed");
1038 goto CB_HANDLER_EXIT;
1041 LOGE("add error msg for service disconnection done");
1043 __recorder_add_msg_to_queue(cb_info,
1044 MUSE_RECORDER_CB_EVENT,
1045 MUSE_RECORDER_EVENT_TYPE_ERROR,
1046 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1049 muse_core_msg_json_factory_free(error_msg);
1052 LOGE("add error msg for service disconnection done");
1063 remained_msg = NULL;
1070 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1071 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1073 if (!handler_info || !thread_name || !cb_info) {
1074 LOGE("t:%d NULL %p %p %p",
1075 type, handler_info, thread_name, cb_info);
1081 handler_info->type = type;
1082 handler_info->queue = g_queue_new();
1083 if (handler_info->queue == NULL) {
1084 LOGE("t:%d queue failed", type);
1088 g_mutex_init(&handler_info->mutex);
1089 g_cond_init(&handler_info->cond);
1091 handler_info->cb_info = (void *)cb_info;
1092 g_atomic_int_set(&handler_info->running, 1);
1094 handler_info->thread = g_thread_try_new(thread_name,
1095 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1096 if (handler_info->thread == NULL) {
1097 LOGE("t:%d thread failed", type);
1099 g_mutex_clear(&handler_info->mutex);
1100 g_cond_clear(&handler_info->cond);
1101 g_queue_free(handler_info->queue);
1102 handler_info->queue = NULL;
1107 LOGD("t:%d done", type);
1113 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1117 if (!handler_info) {
1118 LOGE("NULL handler");
1122 if (!handler_info->thread) {
1123 LOGW("thread is not created");
1127 type = handler_info->type;
1129 LOGD("t:%d thread %p", type, handler_info->thread);
1131 g_mutex_lock(&handler_info->mutex);
1132 g_atomic_int_set(&handler_info->running, 0);
1133 g_cond_signal(&handler_info->cond);
1134 g_mutex_unlock(&handler_info->mutex);
1136 g_thread_join(handler_info->thread);
1137 handler_info->thread = NULL;
1139 g_mutex_clear(&handler_info->mutex);
1140 g_cond_clear(&handler_info->cond);
1141 g_queue_free(handler_info->queue);
1142 handler_info->queue = NULL;
1144 LOGD("t:%d done", type);
1150 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1152 recorder_cb_info_s *cb_info = NULL;
1155 g_return_val_if_fail(sockfd > 0, NULL);
1157 cb_info = g_new0(recorder_cb_info_s, 1);
1158 if (cb_info == NULL) {
1159 LOGE("cb_info failed");
1163 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1165 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1166 g_mutex_init(&cb_info->api_mutex[i]);
1167 g_cond_init(&cb_info->api_cond[i]);
1170 g_mutex_init(&cb_info->idle_event_mutex);
1171 g_cond_init(&cb_info->idle_event_cond);
1173 /* message handler thread */
1174 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1175 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1176 LOGE("msg_handler_info failed");
1180 /* message handler thread for audio stream callback */
1181 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1182 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1183 LOGE("audio_stream_cb_info failed");
1187 cb_info->fd = sockfd;
1189 /* message receive thread */
1190 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1191 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1192 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1193 if (cb_info->msg_recv_thread == NULL) {
1194 LOGE("message receive thread creation failed");
1198 cb_info->is_server_connected = TRUE;
1204 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1205 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1207 g_mutex_clear(&cb_info->idle_event_mutex);
1208 g_cond_clear(&cb_info->idle_event_cond);
1210 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1211 g_mutex_clear(&cb_info->api_mutex[i]);
1212 g_cond_clear(&cb_info->api_cond[i]);
1222 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1224 int ret = RECORDER_ERROR_NONE;
1227 /*LOGD("Enter api : %d", api);*/
1229 if (!cb_info->is_server_connected) {
1230 LOGE("server is disconnected");
1231 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1234 g_mutex_lock(&(cb_info->api_mutex[api]));
1236 if (cb_info->api_activating[api] == 0) {
1237 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1238 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1239 ret = cb_info->api_ret[api];
1240 cb_info->api_activating[api] = 0;
1242 /*LOGD("return value : 0x%x", ret);*/
1244 ret = RECORDER_ERROR_INVALID_OPERATION;
1246 LOGE("api %d was TIMED OUT!", api);
1249 ret = cb_info->api_ret[api];
1250 cb_info->api_activating[api] = 0;
1252 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1255 if (ret != RECORDER_ERROR_NONE) {
1256 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1258 if (ret == RECORDER_ERROR_SOUND_POLICY)
1259 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1260 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1261 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1262 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1263 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1266 g_mutex_unlock(&(cb_info->api_mutex[api]));
1272 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1277 if (!cb_info || !ret) {
1278 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1279 return RECORDER_ERROR_INVALID_PARAMETER;
1282 msg = muse_core_msg_json_factory_new(api, NULL);
1284 LOGE("msg creation failed: api %d", api);
1285 return RECORDER_ERROR_OUT_OF_MEMORY;
1288 /*LOGD("send msg %s", msg);*/
1290 if (cb_info->is_server_connected) {
1291 __recorder_update_api_waiting(cb_info, api, 1);
1293 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1297 LOGE("message send failed");
1298 *ret = RECORDER_ERROR_INVALID_OPERATION;
1300 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1303 __recorder_update_api_waiting(cb_info, api, -1);
1305 muse_core_msg_json_factory_free(msg);
1307 return RECORDER_ERROR_NONE;
1311 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1316 if (!cb_info || !ret || !param) {
1317 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1318 return RECORDER_ERROR_INVALID_PARAMETER;
1321 /*LOGD("type %d, name %s", param->type, param->name);*/
1323 switch (param->type) {
1325 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1327 case MUSE_TYPE_DOUBLE:
1328 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1330 case MUSE_TYPE_STRING:
1331 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1334 LOGE("unknown type %d", param->type);
1339 LOGE("msg creation failed: api %d, type %d, param name %s",
1340 api, param->type, param->name);
1341 return RECORDER_ERROR_OUT_OF_MEMORY;
1344 /*LOGD("send msg %s", msg);*/
1346 if (cb_info->is_server_connected) {
1347 __recorder_update_api_waiting(cb_info, api, 1);
1349 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1353 LOGE("message send failed");
1354 *ret = RECORDER_ERROR_INVALID_OPERATION;
1356 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1359 __recorder_update_api_waiting(cb_info, api, -1);
1361 muse_core_msg_json_factory_free(msg);
1363 return RECORDER_ERROR_NONE;
1367 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1371 g_return_if_fail(cb_info != NULL);
1373 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1375 g_thread_join(cb_info->msg_recv_thread);
1376 cb_info->msg_recv_thread = NULL;
1378 LOGD("msg_recv thread removed");
1380 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1381 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1383 g_mutex_clear(&cb_info->idle_event_mutex);
1384 g_cond_clear(&cb_info->idle_event_cond);
1386 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1387 g_mutex_clear(&cb_info->api_mutex[i]);
1388 g_cond_clear(&cb_info->api_cond[i]);
1391 if (cb_info->fd > -1) {
1392 muse_core_connection_close(cb_info->fd);
1396 if (cb_info->bufmgr) {
1397 tbm_bufmgr_deinit(cb_info->bufmgr);
1398 cb_info->bufmgr = NULL;
1400 if (cb_info->get_filename) {
1401 free(cb_info->get_filename);
1402 cb_info->get_filename = NULL;
1412 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1414 char **root_directory = (char **)user_data;
1416 if (root_directory == NULL) {
1417 LOGE("user data is NULL");
1421 LOGD("storage id %d, type %d, state %d, path %s",
1422 storage_id, type, state, path ? path : "NULL");
1424 if (type == STORAGE_TYPE_INTERNAL && path) {
1425 if (*root_directory) {
1426 free(*root_directory);
1427 *root_directory = NULL;
1430 *root_directory = strdup(path);
1431 if (*root_directory) {
1432 LOGD("get root directory %s", *root_directory);
1435 LOGE("strdup %s failed", path);
1442 static int _recorder_client_get_root_directory(char **root_directory)
1444 int ret = STORAGE_ERROR_NONE;
1446 if (root_directory == NULL) {
1447 LOGE("user data is NULL");
1451 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1452 if (ret != STORAGE_ERROR_NONE) {
1453 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1460 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1462 int ret = RECORDER_ERROR_NONE;
1463 int destroy_ret = RECORDER_ERROR_NONE;
1466 char *send_msg = NULL;
1467 char *root_directory = NULL;
1468 intptr_t camera_handle = 0;
1469 intptr_t handle = 0;
1470 tbm_bufmgr bufmgr = NULL;
1471 recorder_cli_s *pc = NULL;
1472 recorder_msg_param param;
1474 LOGD("Enter - type %d", type);
1476 if (recorder == NULL) {
1477 LOGE("NULL pointer for recorder handle");
1478 return RECORDER_ERROR_INVALID_PARAMETER;
1481 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1482 LOGE("NULL pointer for camera handle on video recorder mode");
1483 return RECORDER_ERROR_INVALID_PARAMETER;
1486 bufmgr = tbm_bufmgr_init(-1);
1487 if (bufmgr == NULL) {
1488 LOGE("get tbm bufmgr failed");
1489 return RECORDER_ERROR_INVALID_OPERATION;
1492 pc = g_new0(recorder_cli_s, 1);
1494 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1495 goto _ERR_RECORDER_EXIT;
1498 sock_fd = muse_core_client_new();
1500 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1501 ret = RECORDER_ERROR_INVALID_OPERATION;
1502 goto _ERR_RECORDER_EXIT;
1505 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1506 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1507 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1508 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1509 MUSE_TYPE_INT, "pid", getpid(),
1512 pc->camera = camera;
1513 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
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_VIDEO,
1517 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1523 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1524 goto _ERR_RECORDER_EXIT;
1527 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1529 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1531 muse_core_msg_json_factory_free(send_msg);
1535 LOGE("send msg failed %d", errno);
1536 ret = RECORDER_ERROR_INVALID_OPERATION;
1537 goto _ERR_RECORDER_EXIT;
1540 pc->cb_info = _recorder_client_callback_new(sock_fd);
1541 if (pc->cb_info == NULL) {
1542 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1543 goto _ERR_RECORDER_EXIT;
1548 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1550 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1552 if (ret != RECORDER_ERROR_NONE) {
1553 LOGE("API_CREATE failed 0x%x", ret);
1554 goto _ERR_RECORDER_EXIT;
1557 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1559 LOGE("Receiving Handle Failed!!");
1560 ret = RECORDER_ERROR_INVALID_OPERATION;
1561 goto _ERR_RECORDER_AFTER_CREATE;
1564 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1565 LOGE("failed to get root directory of internal storage");
1566 ret = RECORDER_ERROR_INVALID_OPERATION;
1567 goto _ERR_RECORDER_AFTER_CREATE;
1570 LOGD("root directory [%s]", root_directory);
1572 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1574 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1576 if (ret != RECORDER_ERROR_NONE) {
1577 LOGE("failed to set root directory %s", root_directory);
1578 ret = RECORDER_ERROR_INVALID_OPERATION;
1579 goto _ERR_RECORDER_AFTER_CREATE;
1582 free(root_directory);
1583 root_directory = NULL;
1585 pc->remote_handle = handle;
1586 pc->cb_info->bufmgr = bufmgr;
1588 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1589 type, pc, pc->remote_handle);
1591 *recorder = (recorder_h)pc;
1595 return RECORDER_ERROR_NONE;
1597 _ERR_RECORDER_AFTER_CREATE:
1598 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1599 LOGE("destroy return 0x%x", destroy_ret);
1602 tbm_bufmgr_deinit(bufmgr);
1605 if (root_directory) {
1606 free(root_directory);
1607 root_directory = NULL;
1611 muse_core_connection_close(sock_fd);
1617 _recorder_client_callback_destroy(pc->cb_info);
1628 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1630 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1634 int recorder_create_audiorecorder(recorder_h *recorder)
1636 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1640 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1642 int ret = RECORDER_ERROR_NONE;
1643 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1644 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1646 if (!pc || !pc->cb_info) {
1647 LOGE("NULL handle");
1648 return RECORDER_ERROR_INVALID_PARAMETER;
1651 if (state == NULL) {
1652 LOGE("NULL pointer state");
1653 return RECORDER_ERROR_INVALID_PARAMETER;
1656 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1658 _recorder_msg_send(api, pc->cb_info, &ret);
1660 if (ret == RECORDER_ERROR_NONE)
1661 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1663 LOGD("ret : 0x%x, state : %d", ret, *state);
1669 int recorder_destroy(recorder_h recorder)
1671 int ret = RECORDER_ERROR_NONE;
1672 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1673 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1675 if (!pc || !pc->cb_info) {
1676 LOGE("NULL handle");
1677 return RECORDER_ERROR_INVALID_PARAMETER;
1682 if (pc->cb_info->is_server_connected)
1683 _recorder_msg_send(api, pc->cb_info, &ret);
1685 LOGW("server disconnected. release resource without send message.");
1687 if (ret == RECORDER_ERROR_NONE) {
1688 _recorder_remove_idle_event_all(pc->cb_info);
1689 _recorder_client_callback_destroy(pc->cb_info);
1694 LOGD("ret : 0x%x", ret);
1700 int recorder_prepare(recorder_h recorder)
1702 int ret = RECORDER_ERROR_NONE;
1703 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1704 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1706 if (!pc || !pc->cb_info) {
1707 LOGE("NULL handle");
1708 return RECORDER_ERROR_INVALID_PARAMETER;
1713 _recorder_msg_send(api, pc->cb_info, &ret);
1715 LOGD("ret : 0x%x", ret);
1717 if (ret == RECORDER_ERROR_NONE && pc->camera)
1718 camera_start_evas_rendering(pc->camera);
1724 int recorder_unprepare(recorder_h recorder)
1726 int ret = RECORDER_ERROR_NONE;
1727 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1728 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1729 camera_state_e camera_state = CAMERA_STATE_NONE;
1731 if (!pc || !pc->cb_info) {
1732 LOGE("NULL handle");
1733 return RECORDER_ERROR_INVALID_PARAMETER;
1739 ret = camera_get_state(pc->camera, &camera_state);
1740 if (ret != CAMERA_ERROR_NONE) {
1741 LOGE("failed to get camera state 0x%x", ret);
1742 return RECORDER_ERROR_INVALID_OPERATION;
1745 if (camera_state == CAMERA_STATE_PREVIEW) {
1746 ret = camera_stop_evas_rendering(pc->camera, false);
1747 if (ret != CAMERA_ERROR_NONE) {
1748 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1749 return RECORDER_ERROR_INVALID_OPERATION;
1754 _recorder_msg_send(api, pc->cb_info, &ret);
1756 LOGD("ret : 0x%x", ret);
1762 int recorder_start(recorder_h recorder)
1764 int ret = RECORDER_ERROR_NONE;
1765 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1766 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1767 recorder_state_e current_state = RECORDER_STATE_NONE;
1769 if (!pc || !pc->cb_info) {
1770 LOGE("NULL handle");
1771 return RECORDER_ERROR_INVALID_PARAMETER;
1777 ret = recorder_get_state(recorder, ¤t_state);
1778 if (ret != RECORDER_ERROR_NONE) {
1779 LOGE("failed to get current state 0x%x", ret);
1780 return RECORDER_ERROR_INVALID_OPERATION;
1783 if (current_state == RECORDER_STATE_READY) {
1784 ret = camera_stop_evas_rendering(pc->camera, true);
1785 if (ret != CAMERA_ERROR_NONE) {
1786 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1787 return RECORDER_ERROR_INVALID_OPERATION;
1792 _recorder_msg_send(api, pc->cb_info, &ret);
1794 if (pc->camera && current_state == RECORDER_STATE_READY)
1795 camera_start_evas_rendering(pc->camera);
1797 LOGD("ret : 0x%x", ret);
1803 int recorder_pause(recorder_h recorder)
1805 int ret = RECORDER_ERROR_NONE;
1806 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1807 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1809 if (!pc || !pc->cb_info) {
1810 LOGE("NULL handle");
1811 return RECORDER_ERROR_INVALID_PARAMETER;
1816 _recorder_msg_send(api, pc->cb_info, &ret);
1818 LOGD("ret : 0x%x", ret);
1824 int recorder_commit(recorder_h recorder)
1826 int ret = RECORDER_ERROR_NONE;
1827 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1828 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1829 recorder_state_e current_state = RECORDER_STATE_NONE;
1831 if (!pc || !pc->cb_info) {
1832 LOGE("NULL handle");
1833 return RECORDER_ERROR_INVALID_PARAMETER;
1839 ret = recorder_get_state(recorder, ¤t_state);
1840 if (ret != RECORDER_ERROR_NONE) {
1841 LOGE("failed to get current state 0x%x", ret);
1842 return RECORDER_ERROR_INVALID_OPERATION;
1845 if (current_state >= RECORDER_STATE_RECORDING) {
1846 ret = camera_stop_evas_rendering(pc->camera, true);
1847 if (ret != CAMERA_ERROR_NONE) {
1848 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1849 return RECORDER_ERROR_INVALID_OPERATION;
1854 _recorder_msg_send(api, pc->cb_info, &ret);
1856 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1857 camera_start_evas_rendering(pc->camera);
1859 LOGD("ret : 0x%x", ret);
1865 int recorder_cancel(recorder_h recorder)
1867 int ret = RECORDER_ERROR_NONE;
1868 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1869 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1870 recorder_state_e current_state = RECORDER_STATE_NONE;
1872 if (!pc || !pc->cb_info) {
1873 LOGE("NULL handle");
1874 return RECORDER_ERROR_INVALID_PARAMETER;
1880 ret = recorder_get_state(recorder, ¤t_state);
1881 if (ret != RECORDER_ERROR_NONE) {
1882 LOGE("failed to get current state 0x%x", ret);
1883 return RECORDER_ERROR_INVALID_OPERATION;
1886 if (current_state >= RECORDER_STATE_RECORDING) {
1887 ret = camera_stop_evas_rendering(pc->camera, true);
1888 if (ret != CAMERA_ERROR_NONE) {
1889 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1890 return RECORDER_ERROR_INVALID_OPERATION;
1895 _recorder_msg_send(api, pc->cb_info, &ret);
1897 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1898 camera_start_evas_rendering(pc->camera);
1900 LOGD("ret : 0x%x", ret);
1906 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1908 int ret = RECORDER_ERROR_NONE;
1910 char *send_msg = NULL;
1911 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1912 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1914 if (!pc || !pc->cb_info) {
1915 LOGE("NULL handle");
1916 return RECORDER_ERROR_INVALID_PARAMETER;
1921 send_msg = muse_core_msg_json_factory_new(api,
1922 MUSE_TYPE_INT, "width", width,
1923 MUSE_TYPE_INT, "height", height,
1926 if (pc->cb_info->is_server_connected) {
1927 __recorder_update_api_waiting(pc->cb_info, api, 1);
1929 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1933 LOGE("message send failed");
1934 ret = RECORDER_ERROR_INVALID_OPERATION;
1936 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1939 __recorder_update_api_waiting(pc->cb_info, api, -1);
1941 muse_core_msg_json_factory_free(send_msg);
1943 LOGE("failed to create msg");
1944 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1947 LOGD("ret : 0x%x", ret);
1953 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1955 int ret = RECORDER_ERROR_NONE;
1956 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1957 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1959 if (!pc || !pc->cb_info) {
1960 LOGE("NULL handle");
1961 return RECORDER_ERROR_INVALID_PARAMETER;
1964 if (!width || !height) {
1965 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1966 return RECORDER_ERROR_INVALID_PARAMETER;
1971 _recorder_msg_send(api, pc->cb_info, &ret);
1973 if (ret == RECORDER_ERROR_NONE) {
1974 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1975 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1978 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1984 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1985 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1987 int ret = RECORDER_ERROR_NONE;
1988 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1989 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1991 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1992 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1993 return RECORDER_ERROR_INVALID_PARAMETER;
1996 LOGD("Enter, handle :%x", pc->remote_handle);
1998 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1999 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2001 _recorder_msg_send(api, pc->cb_info, &ret);
2003 LOGD("ret : 0x%x", ret);
2009 int recorder_get_audio_level(recorder_h recorder, double *level)
2011 int ret = RECORDER_ERROR_NONE;
2012 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2013 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2015 if (!pc || !pc->cb_info || level == NULL) {
2016 LOGE("NULL pointer %p %p", pc, level);
2017 return RECORDER_ERROR_INVALID_PARAMETER;
2022 _recorder_msg_send(api, pc->cb_info, &ret);
2024 if (ret == RECORDER_ERROR_NONE)
2025 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2027 LOGD("ret : 0x%x, level %lf", ret, *level);
2033 int recorder_set_filename(recorder_h recorder, const char *filename)
2035 int ret = RECORDER_ERROR_NONE;
2036 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2037 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2038 recorder_msg_param param;
2039 char set_filename[RECORDER_FILENAME_MAX] = {0, };
2041 if (!pc || !pc->cb_info) {
2042 LOGE("NULL handle");
2043 return RECORDER_ERROR_INVALID_PARAMETER;
2046 if (filename == NULL) {
2047 LOGE("filename is NULL");
2048 return RECORDER_ERROR_INVALID_PARAMETER;
2053 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2054 /* Cannot convert. Use original path. */
2055 strncpy(set_filename, filename, strlen(filename));
2057 /* Converted. Use converted path. */
2058 LOGD("Converted filename : %s -> %s", filename, set_filename);
2061 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2063 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2065 LOGD("ret : 0x%x", ret);
2071 int recorder_get_filename(recorder_h recorder, char **filename)
2073 int ret = RECORDER_ERROR_NONE;
2074 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2075 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2076 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2078 if (!pc || !pc->cb_info) {
2079 LOGE("NULL handle");
2080 return RECORDER_ERROR_INVALID_PARAMETER;
2083 if (filename == NULL) {
2084 LOGE("filename is NULL");
2085 return RECORDER_ERROR_INVALID_PARAMETER;
2090 _recorder_msg_send(api, pc->cb_info, &ret);
2092 if (ret == RECORDER_ERROR_NONE) {
2093 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2094 /* Cannot convert. Use original path. */
2095 *filename = pc->cb_info->get_filename;
2097 /* Converted. Use converted path. */
2098 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2099 *filename = strdup(compat_filename);
2100 free(pc->cb_info->get_filename);
2103 pc->cb_info->get_filename = NULL;
2106 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2112 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2114 int ret = RECORDER_ERROR_NONE;
2115 int set_format = (int)format;
2116 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2117 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2118 recorder_msg_param param;
2120 if (!pc || !pc->cb_info) {
2121 LOGE("NULL handle");
2122 return RECORDER_ERROR_INVALID_PARAMETER;
2125 LOGD("ENTER, set_format : %d", set_format);
2127 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2129 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2131 LOGD("ret : 0x%x", ret);
2136 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2138 int ret = RECORDER_ERROR_NONE;
2139 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2140 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2142 if (!pc || !pc->cb_info) {
2143 LOGE("NULL handle");
2144 return RECORDER_ERROR_INVALID_PARAMETER;
2147 if (format == NULL) {
2148 LOGE("NULL pointer data");
2149 return RECORDER_ERROR_INVALID_PARAMETER;
2154 _recorder_msg_send(api, pc->cb_info, &ret);
2156 if (ret == RECORDER_ERROR_NONE)
2157 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2159 LOGD("ret : 0x%x, format %d", ret, *format);
2165 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2167 int ret = RECORDER_ERROR_NONE;
2168 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2169 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2170 bool is_available = false;
2171 int stream_index = 0;
2172 char *stream_type = NULL;
2173 char *send_msg = NULL;
2176 if (!pc || !pc->cb_info || stream_info == NULL) {
2177 LOGE("NULL handle");
2178 return RECORDER_ERROR_INVALID_PARAMETER;
2183 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2184 if (ret != SOUND_MANAGER_ERROR_NONE) {
2185 LOGE("stream info verification failed");
2186 return RECORDER_ERROR_INVALID_OPERATION;
2189 if (is_available == false) {
2190 LOGE("stream information is not available");
2191 return RECORDER_ERROR_INVALID_OPERATION;
2194 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2195 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2197 LOGD("sound manager return [0x%x]", ret);
2199 if (ret == SOUND_MANAGER_ERROR_NONE) {
2200 send_msg = muse_core_msg_json_factory_new(api,
2201 MUSE_TYPE_STRING, "stream_type", stream_type,
2202 MUSE_TYPE_INT, "stream_index", stream_index,
2205 if (pc->cb_info->is_server_connected) {
2206 __recorder_update_api_waiting(pc->cb_info, api, 1);
2208 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2212 LOGE("message send failed");
2213 ret = RECORDER_ERROR_INVALID_OPERATION;
2215 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2218 __recorder_update_api_waiting(pc->cb_info, api, -1);
2220 muse_core_msg_json_factory_free(send_msg);
2222 LOGE("failed to create msg");
2223 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2226 ret = RECORDER_ERROR_INVALID_OPERATION;
2233 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2235 int ret = RECORDER_ERROR_NONE;
2236 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2237 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2239 if (!pc || !pc->cb_info || callback == NULL) {
2240 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2241 return RECORDER_ERROR_INVALID_PARAMETER;
2244 LOGD("Enter, handle :%x", pc->remote_handle);
2246 _recorder_msg_send(api, pc->cb_info, &ret);
2248 if (ret == RECORDER_ERROR_NONE) {
2249 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2250 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2253 LOGD("ret : 0x%x", ret);
2259 int recorder_unset_state_changed_cb(recorder_h recorder)
2261 int ret = RECORDER_ERROR_NONE;
2262 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2263 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2265 if (!pc || !pc->cb_info) {
2266 LOGE("NULL handle");
2267 return RECORDER_ERROR_INVALID_PARAMETER;
2272 _recorder_msg_send(api, pc->cb_info, &ret);
2274 if (ret == RECORDER_ERROR_NONE) {
2275 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2276 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2279 LOGD("ret : 0x%x", ret);
2285 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2287 int ret = RECORDER_ERROR_NONE;
2288 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2289 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2291 if (!pc || !pc->cb_info || callback == NULL) {
2292 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2293 return RECORDER_ERROR_INVALID_PARAMETER;
2296 LOGD("Enter, handle :%x", pc->remote_handle);
2298 _recorder_msg_send(api, pc->cb_info, &ret);
2300 if (ret == RECORDER_ERROR_NONE) {
2301 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2302 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2305 LOGD("ret : 0x%x", ret);
2311 int recorder_unset_interrupted_cb(recorder_h recorder)
2313 int ret = RECORDER_ERROR_NONE;
2314 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2315 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2317 if (!pc || !pc->cb_info) {
2318 LOGE("NULL handle");
2319 return RECORDER_ERROR_INVALID_PARAMETER;
2324 _recorder_msg_send(api, pc->cb_info, &ret);
2326 if (ret == RECORDER_ERROR_NONE) {
2327 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2328 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2331 LOGD("ret : 0x%x", ret);
2337 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2339 int ret = RECORDER_ERROR_NONE;
2340 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2341 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2343 if (!pc || !pc->cb_info || callback == NULL) {
2344 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2345 return RECORDER_ERROR_INVALID_PARAMETER;
2348 LOGD("Enter, handle :%x", pc->remote_handle);
2350 _recorder_msg_send(api, pc->cb_info, &ret);
2352 if (ret == RECORDER_ERROR_NONE) {
2353 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2354 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2357 LOGD("ret : 0x%x", ret);
2363 int recorder_unset_audio_stream_cb(recorder_h recorder)
2365 int ret = RECORDER_ERROR_NONE;
2366 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2367 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2369 if (!pc || !pc->cb_info) {
2370 LOGE("NULL handle");
2371 return RECORDER_ERROR_INVALID_PARAMETER;
2376 _recorder_msg_send(api, pc->cb_info, &ret);
2378 if (ret == RECORDER_ERROR_NONE) {
2379 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2380 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2383 LOGD("ret : 0x%x", ret);
2389 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2391 int ret = RECORDER_ERROR_NONE;
2392 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2393 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2395 if (!pc || !pc->cb_info || !callback) {
2396 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2397 return RECORDER_ERROR_INVALID_PARAMETER;
2400 LOGD("Enter, handle :%x", pc->remote_handle);
2402 _recorder_msg_send(api, pc->cb_info, &ret);
2404 if (ret == RECORDER_ERROR_NONE) {
2405 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2406 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2409 LOGD("ret : 0x%x", ret);
2415 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2417 int ret = RECORDER_ERROR_NONE;
2418 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2419 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2421 if (!pc || !pc->cb_info) {
2422 LOGE("NULL handle");
2423 return RECORDER_ERROR_INVALID_PARAMETER;
2428 _recorder_msg_send(api, pc->cb_info, &ret);
2430 if (ret == RECORDER_ERROR_NONE) {
2431 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2432 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2435 LOGD("ret : 0x%x", ret);
2441 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2443 int ret = RECORDER_ERROR_NONE;
2444 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2445 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2447 if (!pc || !pc->cb_info || callback == NULL) {
2448 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2449 return RECORDER_ERROR_INVALID_PARAMETER;
2452 LOGD("Enter, handle :%x", pc->remote_handle);
2454 _recorder_msg_send(api, pc->cb_info, &ret);
2456 if (ret == RECORDER_ERROR_NONE) {
2457 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2458 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2461 LOGD("ret : 0x%x", ret);
2467 int recorder_unset_error_cb(recorder_h recorder)
2469 int ret = RECORDER_ERROR_NONE;
2470 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2471 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2473 if (!pc || !pc->cb_info) {
2474 LOGE("NULL handle");
2475 return RECORDER_ERROR_INVALID_PARAMETER;
2480 _recorder_msg_send(api, pc->cb_info, &ret);
2482 if (ret == RECORDER_ERROR_NONE) {
2483 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2484 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2487 LOGD("ret : 0x%x", ret);
2493 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2495 int ret = RECORDER_ERROR_NONE;
2496 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2497 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2499 if (!pc || !pc->cb_info || callback == NULL) {
2500 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2501 return RECORDER_ERROR_INVALID_PARAMETER;
2504 LOGD("Enter, handle :%x", pc->remote_handle);
2506 _recorder_msg_send(api, pc->cb_info, &ret);
2508 if (ret == RECORDER_ERROR_NONE) {
2509 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2510 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2513 LOGD("ret : 0x%x", ret);
2519 int recorder_unset_recording_status_cb(recorder_h recorder)
2521 int ret = RECORDER_ERROR_NONE;
2522 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2523 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2525 if (!pc || !pc->cb_info) {
2526 LOGE("NULL handle");
2527 return RECORDER_ERROR_INVALID_PARAMETER;
2532 _recorder_msg_send(api, pc->cb_info, &ret);
2534 if (ret == RECORDER_ERROR_NONE) {
2535 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2536 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2539 LOGD("ret : 0x%x", ret);
2545 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2547 int ret = RECORDER_ERROR_NONE;
2548 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2549 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2551 if (!pc || !pc->cb_info || callback == NULL) {
2552 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2553 return RECORDER_ERROR_INVALID_PARAMETER;
2556 _recorder_msg_send(api, pc->cb_info, &ret);
2558 if (ret == RECORDER_ERROR_NONE) {
2559 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2560 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2563 LOGD("ret : 0x%x", ret);
2569 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2571 int ret = RECORDER_ERROR_NONE;
2572 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2573 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2575 if (!pc || !pc->cb_info) {
2576 LOGE("NULL handle");
2577 return RECORDER_ERROR_INVALID_PARAMETER;
2582 _recorder_msg_send(api, pc->cb_info, &ret);
2584 if (ret == RECORDER_ERROR_NONE) {
2585 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2586 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2589 LOGD("ret : 0x%x", ret);
2595 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2597 int ret = RECORDER_ERROR_NONE;
2598 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2599 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2601 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2602 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2603 return RECORDER_ERROR_INVALID_PARAMETER;
2606 LOGD("Enter, handle :%x", pc->remote_handle);
2608 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2609 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2611 _recorder_msg_send(api, pc->cb_info, &ret);
2613 LOGD("ret : 0x%x", ret);
2619 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2621 int ret = RECORDER_ERROR_NONE;
2622 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2623 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2624 recorder_msg_param param;
2626 if (!pc || !pc->cb_info) {
2627 LOGE("NULL handle");
2628 return RECORDER_ERROR_INVALID_PARAMETER;
2633 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2635 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2637 LOGD("ret : 0x%x", ret);
2643 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2645 int ret = RECORDER_ERROR_NONE;
2646 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2647 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2648 recorder_msg_param param;
2650 if (!pc || !pc->cb_info) {
2651 LOGE("NULL handle");
2652 return RECORDER_ERROR_INVALID_PARAMETER;
2657 RECORDER_MSG_PARAM_SET(param, INT, second);
2659 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2661 LOGD("ret : 0x%x", ret);
2667 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2669 int ret = RECORDER_ERROR_NONE;
2670 int set_device = (int)device;
2671 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2672 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2673 recorder_msg_param param;
2675 if (!pc || !pc->cb_info) {
2676 LOGE("NULL handle");
2677 return RECORDER_ERROR_INVALID_PARAMETER;
2682 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2684 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2686 LOGD("ret : 0x%x", ret);
2692 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2694 int ret = RECORDER_ERROR_NONE;
2695 int set_codec = (int)codec;
2696 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2697 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2698 recorder_msg_param param;
2700 if (!pc || !pc->cb_info) {
2701 LOGE("NULL handle");
2702 return RECORDER_ERROR_INVALID_PARAMETER;
2707 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2709 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2711 LOGD("ret : 0x%x", ret);
2717 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2719 int ret = RECORDER_ERROR_NONE;
2720 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2721 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2723 if (!pc || !pc->cb_info) {
2724 LOGE("NULL handle");
2725 return RECORDER_ERROR_INVALID_PARAMETER;
2728 if (codec == NULL) {
2729 LOGE("codec is NULL");
2730 return RECORDER_ERROR_INVALID_PARAMETER;
2735 _recorder_msg_send(api, pc->cb_info, &ret);
2737 if (ret == RECORDER_ERROR_NONE)
2738 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2740 LOGD("ret : 0x%x, codec %d", ret, *codec);
2746 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2748 int ret = RECORDER_ERROR_NONE;
2749 int set_codec = (int)codec;
2750 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2751 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2752 recorder_msg_param param;
2754 if (!pc || !pc->cb_info) {
2755 LOGE("NULL handle");
2756 return RECORDER_ERROR_INVALID_PARAMETER;
2761 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2763 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2765 LOGD("ret : 0x%x", ret);
2771 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2773 int ret = RECORDER_ERROR_NONE;
2774 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2775 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2777 if (!pc || !pc->cb_info) {
2778 LOGE("NULL handle");
2779 return RECORDER_ERROR_INVALID_PARAMETER;
2782 if (codec == NULL) {
2783 LOGE("codec is NULL");
2784 return RECORDER_ERROR_INVALID_PARAMETER;
2789 _recorder_msg_send(api, pc->cb_info, &ret);
2791 if (ret == RECORDER_ERROR_NONE)
2792 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2794 LOGD("ret : 0x%x, codec %d", ret, *codec);
2800 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2802 int ret = RECORDER_ERROR_NONE;
2803 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2804 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2805 recorder_msg_param param;
2807 if (!pc || !pc->cb_info) {
2808 LOGE("NULL handle");
2809 return RECORDER_ERROR_INVALID_PARAMETER;
2812 LOGD("ENTER, samplerate : %d", samplerate);
2814 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2816 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2818 LOGD("ret : 0x%x", ret);
2824 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2826 int ret = RECORDER_ERROR_NONE;
2827 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2828 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2829 recorder_msg_param param;
2831 if (!pc || !pc->cb_info) {
2832 LOGE("NULL handle");
2833 return RECORDER_ERROR_INVALID_PARAMETER;
2838 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2840 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2842 LOGD("ret : 0x%x", ret);
2848 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2850 int ret = RECORDER_ERROR_NONE;
2851 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2852 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2853 recorder_msg_param param;
2855 if (!pc || !pc->cb_info) {
2856 LOGE("NULL handle");
2857 return RECORDER_ERROR_INVALID_PARAMETER;
2862 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2864 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2866 LOGD("ret : 0x%x", ret);
2872 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2874 int ret = RECORDER_ERROR_NONE;
2875 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2876 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2878 if (!pc || !pc->cb_info) {
2879 LOGE("NULL handle");
2880 return RECORDER_ERROR_INVALID_PARAMETER;
2883 if (kbyte == NULL) {
2884 LOGE("NULL pointer kbyte");
2885 return RECORDER_ERROR_INVALID_PARAMETER;
2890 _recorder_msg_send(api, pc->cb_info, &ret);
2892 if (ret == RECORDER_ERROR_NONE)
2893 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2895 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2901 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2903 int ret = RECORDER_ERROR_NONE;
2904 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2905 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2907 if (!pc || !pc->cb_info) {
2908 LOGE("NULL handle");
2909 return RECORDER_ERROR_INVALID_PARAMETER;
2912 if (second == NULL) {
2913 LOGE("NULL pointer second");
2914 return RECORDER_ERROR_INVALID_PARAMETER;
2919 _recorder_msg_send(api, pc->cb_info, &ret);
2921 if (ret == RECORDER_ERROR_NONE)
2922 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2924 LOGD("ret : 0x%x, %d second", ret, *second);
2930 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2932 int ret = RECORDER_ERROR_NONE;
2933 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2934 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2936 if (!pc || !pc->cb_info) {
2937 LOGE("NULL handle");
2938 return RECORDER_ERROR_INVALID_PARAMETER;
2941 if (device == NULL) {
2942 LOGE("NULL pointer device");
2943 return RECORDER_ERROR_INVALID_PARAMETER;
2948 _recorder_msg_send(api, pc->cb_info, &ret);
2950 if (ret == RECORDER_ERROR_NONE)
2951 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2953 LOGD("ret : 0x%x, device %d", ret, *device);
2959 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2961 int ret = RECORDER_ERROR_NONE;
2962 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2963 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2965 if (!pc || !pc->cb_info) {
2966 LOGE("NULL handle");
2967 return RECORDER_ERROR_INVALID_PARAMETER;
2970 if (samplerate == NULL) {
2971 LOGE("NULL pointer handle");
2972 return RECORDER_ERROR_INVALID_PARAMETER;
2977 _recorder_msg_send(api, pc->cb_info, &ret);
2979 if (ret == RECORDER_ERROR_NONE)
2980 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
2982 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
2988 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2990 int ret = RECORDER_ERROR_NONE;
2991 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2992 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2994 if (!pc || !pc->cb_info) {
2995 LOGE("NULL handle");
2996 return RECORDER_ERROR_INVALID_PARAMETER;
2999 if (bitrate == NULL) {
3000 LOGE("NULL pointer");
3001 return RECORDER_ERROR_INVALID_PARAMETER;
3006 _recorder_msg_send(api, pc->cb_info, &ret);
3008 if (ret == RECORDER_ERROR_NONE)
3009 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3011 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3017 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3019 int ret = RECORDER_ERROR_NONE;
3020 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3021 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3023 if (!pc || !pc->cb_info) {
3024 LOGE("NULL handle");
3025 return RECORDER_ERROR_INVALID_PARAMETER;
3028 if (bitrate == NULL) {
3029 LOGE("NULL pointer");
3030 return RECORDER_ERROR_INVALID_PARAMETER;
3035 _recorder_msg_send(api, pc->cb_info, &ret);
3037 if (ret == RECORDER_ERROR_NONE)
3038 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3040 LOGD("ret : 0x%x", ret);
3046 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3048 int ret = RECORDER_ERROR_NONE;
3049 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3050 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3052 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3053 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3054 return RECORDER_ERROR_INVALID_PARAMETER;
3057 LOGD("Enter, handle :%x", pc->remote_handle);
3059 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3060 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3062 _recorder_msg_send(api, pc->cb_info, &ret);
3064 LOGD("ret : 0x%x", ret);
3070 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3072 int ret = RECORDER_ERROR_NONE;
3073 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3074 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3076 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3077 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3078 return RECORDER_ERROR_INVALID_PARAMETER;
3081 LOGD("Enter, handle :%x", pc->remote_handle);
3083 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3084 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3086 _recorder_msg_send(api, pc->cb_info, &ret);
3088 LOGD("ret : 0x%x", ret);
3094 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3096 int ret = RECORDER_ERROR_NONE;
3097 int set_enable = (int)enable;
3098 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3099 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3100 recorder_msg_param param;
3102 if (!pc || !pc->cb_info) {
3103 LOGE("NULL handle");
3104 return RECORDER_ERROR_INVALID_PARAMETER;
3109 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3111 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3113 LOGD("ret : 0x%x", ret);
3119 bool recorder_attr_is_muted(recorder_h recorder)
3122 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3123 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3125 if (!pc || !pc->cb_info) {
3126 LOGE("NULL handle");
3132 _recorder_msg_send(api, pc->cb_info, &ret);
3134 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3137 LOGD("ret : %d", ret);
3143 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3145 int ret = RECORDER_ERROR_NONE;
3146 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3147 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3148 recorder_msg_param param;
3150 if (!pc || !pc->cb_info) {
3151 LOGE("NULL handle");
3152 return RECORDER_ERROR_INVALID_PARAMETER;
3155 LOGD("ENTER - %.20lf", rate);
3157 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3159 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3161 LOGD("ret : 0x%x", ret);
3167 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3169 int ret = RECORDER_ERROR_NONE;
3170 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3171 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3173 if (!pc || !pc->cb_info) {
3174 LOGE("NULL handle");
3175 return RECORDER_ERROR_INVALID_PARAMETER;
3179 LOGE("rate is NULL");
3180 return RECORDER_ERROR_INVALID_PARAMETER;
3185 _recorder_msg_send(api, pc->cb_info, &ret);
3186 if (ret == RECORDER_ERROR_NONE)
3187 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3189 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3195 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3197 int ret = RECORDER_ERROR_NONE;
3198 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3199 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3200 recorder_msg_param param;
3202 if (!pc || !pc->cb_info) {
3203 LOGE("NULL handle");
3204 return RECORDER_ERROR_INVALID_PARAMETER;
3209 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3211 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3213 LOGD("ret : 0x%x", ret);
3219 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3221 int ret = RECORDER_ERROR_NONE;
3222 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3223 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3225 if (!pc || !pc->cb_info) {
3226 LOGE("NULL handle");
3227 return RECORDER_ERROR_INVALID_PARAMETER;
3230 if (channel_count == NULL) {
3231 LOGE("channel_count is NULL");
3232 return RECORDER_ERROR_INVALID_PARAMETER;
3237 _recorder_msg_send(api, pc->cb_info, &ret);
3239 if (ret == RECORDER_ERROR_NONE)
3240 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3242 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3248 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3250 int ret = RECORDER_ERROR_NONE;
3251 int set_orientation = (int)orientation;
3252 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3253 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3254 recorder_msg_param param;
3256 if (!pc || !pc->cb_info) {
3257 LOGE("NULL handle");
3258 return RECORDER_ERROR_INVALID_PARAMETER;
3263 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3265 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3267 LOGD("ret : 0x%x", ret);
3273 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3275 int ret = RECORDER_ERROR_NONE;
3276 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3277 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3279 if (!pc || !pc->cb_info) {
3280 LOGE("NULL handle");
3281 return RECORDER_ERROR_INVALID_PARAMETER;
3284 if (orientation == NULL) {
3285 LOGE("orientation is NULL");
3286 return RECORDER_ERROR_INVALID_PARAMETER;
3291 _recorder_msg_send(api, pc->cb_info, &ret);
3293 if (ret == RECORDER_ERROR_NONE)
3294 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3296 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3302 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3304 int ret = RECORDER_ERROR_NONE;
3306 int get_device_state = 0;
3307 char *send_msg = NULL;
3308 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3311 LOGE("NULL pointer");
3312 return RECORDER_ERROR_INVALID_PARAMETER;
3315 LOGD("Enter - type %d", type);
3317 sock_fd = muse_core_client_new();
3319 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3320 ret = RECORDER_ERROR_INVALID_OPERATION;
3321 goto _GET_DEVICE_STATE_EXIT;
3324 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3325 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3326 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3330 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3331 goto _GET_DEVICE_STATE_EXIT;
3334 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3336 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3338 muse_core_msg_json_factory_free(send_msg);
3342 LOGE("send msg failed %d", errno);
3343 ret = RECORDER_ERROR_INVALID_OPERATION;
3344 goto _GET_DEVICE_STATE_EXIT;
3347 ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3349 LOGE("recv msg failed %d", errno);
3350 ret = RECORDER_ERROR_INVALID_OPERATION;
3351 goto _GET_DEVICE_STATE_EXIT;
3354 if (!muse_recorder_msg_get(ret, recv_msg)) {
3355 LOGE("failed to get return value from msg [%s]", recv_msg);
3356 ret = RECORDER_ERROR_INVALID_OPERATION;
3357 goto _GET_DEVICE_STATE_EXIT;
3360 if (ret == RECORDER_ERROR_NONE) {
3361 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3362 *state = (recorder_device_state_e)get_device_state;
3363 LOGD("device type %d state %d", type, *state);
3365 LOGE("failed to get device state from msg [%s]", recv_msg);
3366 ret = RECORDER_ERROR_INVALID_OPERATION;
3369 LOGE("failed 0x%x", ret);
3372 _GET_DEVICE_STATE_EXIT:
3374 muse_core_connection_close(sock_fd);
3382 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3384 int ret = RECORDER_ERROR_NONE;
3385 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3386 recorder_cb_info *info = NULL;
3388 if (!callback || !cb_id) {
3389 LOGE("invalid pointer %p %p", callback, cb_id);
3390 return RECORDER_ERROR_INVALID_PARAMETER;
3393 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3395 /* check recorder support */
3396 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3397 if (ret != RECORDER_ERROR_NONE) {
3398 LOGE("get device state failed");
3399 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3403 info = g_new0(recorder_cb_info, 1);
3405 LOGE("info failed");
3406 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3410 info->id = ++g_rec_dev_state_changed_cb_id;
3411 info->callback = (void *)callback;
3412 info->user_data = user_data;
3416 /* subscribe dbus signal for camera state change */
3417 if (!g_rec_dev_state_changed_cb_conn) {
3418 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3419 if (!g_rec_dev_state_changed_cb_conn) {
3420 LOGE("failed to get gdbus connection");
3421 ret = RECORDER_ERROR_INVALID_OPERATION;
3425 LOGD("subscribe signal %s - %s - %s",
3426 MM_CAMCORDER_DBUS_OBJECT,
3427 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3428 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3430 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3431 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3432 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3433 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3434 LOGE("failed to get gdbus connection");
3435 ret = RECORDER_ERROR_INVALID_OPERATION;
3439 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3442 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3444 LOGD("callback id %d", info->id);
3447 if (ret != RECORDER_ERROR_NONE) {
3453 if (g_rec_dev_state_changed_cb_conn) {
3454 g_object_unref(g_rec_dev_state_changed_cb_conn);
3455 g_rec_dev_state_changed_cb_conn = NULL;
3459 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3465 int recorder_remove_device_state_changed_cb(int cb_id)
3467 int ret = RECORDER_ERROR_NONE;
3468 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3469 GList *tmp_list = NULL;
3470 recorder_cb_info *info = NULL;
3472 /* check recorder support */
3473 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3474 if (ret != RECORDER_ERROR_NONE) {
3475 LOGE("get device state failed");
3479 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3481 if (!g_rec_dev_state_changed_cb_list) {
3482 LOGE("there is no callback info");
3483 ret = RECORDER_ERROR_INVALID_OPERATION;
3487 tmp_list = g_rec_dev_state_changed_cb_list;
3490 info = tmp_list->data;
3491 tmp_list = tmp_list->next;
3498 if (info->id == cb_id) {
3499 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3504 if (!g_rec_dev_state_changed_cb_list) {
3505 /* no remained callback */
3506 if (g_rec_dev_state_changed_cb_conn) {
3507 /* unsubscribe signal */
3508 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3509 g_rec_dev_state_changed_cb_subscribe_id = 0;
3511 /* unref connection */
3512 g_object_unref(g_rec_dev_state_changed_cb_conn);
3513 g_rec_dev_state_changed_cb_conn = NULL;
3517 LOGD("id %d callback removed", cb_id);
3518 ret = RECORDER_ERROR_NONE;
3524 LOGE("id %d callback not found", cb_id);
3525 ret = RECORDER_ERROR_INVALID_PARAMETER;
3528 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);