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 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1238 LOGW("wait for api %d", api);
1239 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1240 ret = cb_info->api_ret[api];
1241 cb_info->api_activating[api] = 0;
1242 LOGW("api %d returned 0x%x", api, ret);
1244 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1245 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1246 ret = cb_info->api_ret[api];
1247 cb_info->api_activating[api] = 0;
1248 /*LOGD("return value : 0x%x", ret);*/
1250 ret = RECORDER_ERROR_INVALID_OPERATION;
1251 LOGE("api %d was TIMED OUT!", api);
1255 ret = cb_info->api_ret[api];
1256 cb_info->api_activating[api] = 0;
1258 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1261 if (ret != RECORDER_ERROR_NONE) {
1262 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1264 if (ret == RECORDER_ERROR_SOUND_POLICY)
1265 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1266 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1267 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1268 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1269 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1272 g_mutex_unlock(&(cb_info->api_mutex[api]));
1278 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1283 if (!cb_info || !ret) {
1284 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1285 return RECORDER_ERROR_INVALID_PARAMETER;
1288 msg = muse_core_msg_json_factory_new(api, NULL);
1290 LOGE("msg creation failed: api %d", api);
1291 return RECORDER_ERROR_OUT_OF_MEMORY;
1294 /*LOGD("send msg %s", msg);*/
1296 if (cb_info->is_server_connected) {
1297 __recorder_update_api_waiting(cb_info, api, 1);
1299 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1303 LOGE("message send failed");
1304 *ret = RECORDER_ERROR_INVALID_OPERATION;
1306 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1309 __recorder_update_api_waiting(cb_info, api, -1);
1311 muse_core_msg_json_factory_free(msg);
1313 return RECORDER_ERROR_NONE;
1317 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1322 if (!cb_info || !ret || !param) {
1323 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1324 return RECORDER_ERROR_INVALID_PARAMETER;
1327 /*LOGD("type %d, name %s", param->type, param->name);*/
1329 switch (param->type) {
1331 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1333 case MUSE_TYPE_DOUBLE:
1334 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1336 case MUSE_TYPE_STRING:
1337 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1340 LOGE("unknown type %d", param->type);
1345 LOGE("msg creation failed: api %d, type %d, param name %s",
1346 api, param->type, param->name);
1347 return RECORDER_ERROR_OUT_OF_MEMORY;
1350 /*LOGD("send msg %s", msg);*/
1352 if (cb_info->is_server_connected) {
1353 __recorder_update_api_waiting(cb_info, api, 1);
1355 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1359 LOGE("message send failed");
1360 *ret = RECORDER_ERROR_INVALID_OPERATION;
1362 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1365 __recorder_update_api_waiting(cb_info, api, -1);
1367 muse_core_msg_json_factory_free(msg);
1369 return RECORDER_ERROR_NONE;
1373 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1377 g_return_if_fail(cb_info != NULL);
1379 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1381 g_thread_join(cb_info->msg_recv_thread);
1382 cb_info->msg_recv_thread = NULL;
1384 LOGD("msg_recv thread removed");
1386 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1387 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1389 g_mutex_clear(&cb_info->idle_event_mutex);
1390 g_cond_clear(&cb_info->idle_event_cond);
1392 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1393 g_mutex_clear(&cb_info->api_mutex[i]);
1394 g_cond_clear(&cb_info->api_cond[i]);
1397 if (cb_info->fd > -1) {
1398 muse_core_connection_close(cb_info->fd);
1402 if (cb_info->bufmgr) {
1403 tbm_bufmgr_deinit(cb_info->bufmgr);
1404 cb_info->bufmgr = NULL;
1406 if (cb_info->get_filename) {
1407 free(cb_info->get_filename);
1408 cb_info->get_filename = NULL;
1418 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1420 char **root_directory = (char **)user_data;
1422 if (root_directory == NULL) {
1423 LOGE("user data is NULL");
1427 LOGD("storage id %d, type %d, state %d, path %s",
1428 storage_id, type, state, path ? path : "NULL");
1430 if (type == STORAGE_TYPE_INTERNAL && path) {
1431 if (*root_directory) {
1432 free(*root_directory);
1433 *root_directory = NULL;
1436 *root_directory = strdup(path);
1437 if (*root_directory) {
1438 LOGD("get root directory %s", *root_directory);
1441 LOGE("strdup %s failed", path);
1448 static int _recorder_client_get_root_directory(char **root_directory)
1450 int ret = STORAGE_ERROR_NONE;
1452 if (root_directory == NULL) {
1453 LOGE("user data is NULL");
1457 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1458 if (ret != STORAGE_ERROR_NONE) {
1459 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1466 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1468 int ret = RECORDER_ERROR_NONE;
1469 int destroy_ret = RECORDER_ERROR_NONE;
1472 char *send_msg = NULL;
1473 char *root_directory = NULL;
1474 intptr_t camera_handle = 0;
1475 intptr_t handle = 0;
1476 tbm_bufmgr bufmgr = NULL;
1477 recorder_cli_s *pc = NULL;
1478 recorder_msg_param param;
1480 LOGD("Enter - type %d", type);
1482 if (recorder == NULL) {
1483 LOGE("NULL pointer for recorder handle");
1484 return RECORDER_ERROR_INVALID_PARAMETER;
1487 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1488 LOGE("NULL pointer for camera handle on video recorder mode");
1489 return RECORDER_ERROR_INVALID_PARAMETER;
1492 bufmgr = tbm_bufmgr_init(-1);
1493 if (bufmgr == NULL) {
1494 LOGE("get tbm bufmgr failed");
1495 return RECORDER_ERROR_INVALID_OPERATION;
1498 pc = g_new0(recorder_cli_s, 1);
1500 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1501 goto _ERR_RECORDER_EXIT;
1504 sock_fd = muse_core_client_new();
1506 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1507 ret = RECORDER_ERROR_INVALID_OPERATION;
1508 goto _ERR_RECORDER_EXIT;
1511 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1512 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1513 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1514 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1515 MUSE_TYPE_INT, "pid", getpid(),
1518 pc->camera = camera;
1519 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1520 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1521 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1522 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1523 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1529 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1530 goto _ERR_RECORDER_EXIT;
1533 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1535 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1537 muse_core_msg_json_factory_free(send_msg);
1541 LOGE("send msg failed %d", errno);
1542 ret = RECORDER_ERROR_INVALID_OPERATION;
1543 goto _ERR_RECORDER_EXIT;
1546 pc->cb_info = _recorder_client_callback_new(sock_fd);
1547 if (pc->cb_info == NULL) {
1548 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1549 goto _ERR_RECORDER_EXIT;
1554 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_NO_TIMEOUT);
1556 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1558 if (ret != RECORDER_ERROR_NONE) {
1559 LOGE("API_CREATE failed 0x%x", ret);
1560 goto _ERR_RECORDER_EXIT;
1563 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1565 LOGE("Receiving Handle Failed!!");
1566 ret = RECORDER_ERROR_INVALID_OPERATION;
1567 goto _ERR_RECORDER_AFTER_CREATE;
1570 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1571 LOGE("failed to get root directory of internal storage");
1572 ret = RECORDER_ERROR_INVALID_OPERATION;
1573 goto _ERR_RECORDER_AFTER_CREATE;
1576 LOGD("root directory [%s]", root_directory);
1578 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1580 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1582 if (ret != RECORDER_ERROR_NONE) {
1583 LOGE("failed to set root directory %s", root_directory);
1584 ret = RECORDER_ERROR_INVALID_OPERATION;
1585 goto _ERR_RECORDER_AFTER_CREATE;
1588 free(root_directory);
1589 root_directory = NULL;
1591 pc->remote_handle = handle;
1592 pc->cb_info->bufmgr = bufmgr;
1594 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1595 type, pc, pc->remote_handle);
1597 *recorder = (recorder_h)pc;
1601 return RECORDER_ERROR_NONE;
1603 _ERR_RECORDER_AFTER_CREATE:
1604 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1605 LOGE("destroy return 0x%x", destroy_ret);
1608 tbm_bufmgr_deinit(bufmgr);
1611 if (root_directory) {
1612 free(root_directory);
1613 root_directory = NULL;
1617 muse_core_connection_close(sock_fd);
1623 _recorder_client_callback_destroy(pc->cb_info);
1634 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1636 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1640 int recorder_create_audiorecorder(recorder_h *recorder)
1642 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1646 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1648 int ret = RECORDER_ERROR_NONE;
1649 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1650 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1652 if (!pc || !pc->cb_info) {
1653 LOGE("NULL handle");
1654 return RECORDER_ERROR_INVALID_PARAMETER;
1657 if (state == NULL) {
1658 LOGE("NULL pointer state");
1659 return RECORDER_ERROR_INVALID_PARAMETER;
1662 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1664 _recorder_msg_send(api, pc->cb_info, &ret);
1666 if (ret == RECORDER_ERROR_NONE)
1667 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1669 LOGD("ret : 0x%x, state : %d", ret, *state);
1675 int recorder_destroy(recorder_h recorder)
1677 int ret = RECORDER_ERROR_NONE;
1678 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1679 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1681 if (!pc || !pc->cb_info) {
1682 LOGE("NULL handle");
1683 return RECORDER_ERROR_INVALID_PARAMETER;
1688 if (pc->cb_info->is_server_connected)
1689 _recorder_msg_send(api, pc->cb_info, &ret);
1691 LOGW("server disconnected. release resource without send message.");
1693 if (ret == RECORDER_ERROR_NONE) {
1694 _recorder_remove_idle_event_all(pc->cb_info);
1695 _recorder_client_callback_destroy(pc->cb_info);
1700 LOGD("ret : 0x%x", ret);
1706 int recorder_prepare(recorder_h recorder)
1708 int ret = RECORDER_ERROR_NONE;
1709 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1710 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1712 if (!pc || !pc->cb_info) {
1713 LOGE("NULL handle");
1714 return RECORDER_ERROR_INVALID_PARAMETER;
1719 _recorder_msg_send(api, pc->cb_info, &ret);
1721 LOGD("ret : 0x%x", ret);
1723 if (ret == RECORDER_ERROR_NONE && pc->camera)
1724 camera_start_evas_rendering(pc->camera);
1730 int recorder_unprepare(recorder_h recorder)
1732 int ret = RECORDER_ERROR_NONE;
1733 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1734 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1735 camera_state_e camera_state = CAMERA_STATE_NONE;
1737 if (!pc || !pc->cb_info) {
1738 LOGE("NULL handle");
1739 return RECORDER_ERROR_INVALID_PARAMETER;
1745 ret = camera_get_state(pc->camera, &camera_state);
1746 if (ret != CAMERA_ERROR_NONE) {
1747 LOGE("failed to get camera state 0x%x", ret);
1748 return RECORDER_ERROR_INVALID_OPERATION;
1751 if (camera_state == CAMERA_STATE_PREVIEW) {
1752 ret = camera_stop_evas_rendering(pc->camera, false);
1753 if (ret != CAMERA_ERROR_NONE) {
1754 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1755 return RECORDER_ERROR_INVALID_OPERATION;
1760 _recorder_msg_send(api, pc->cb_info, &ret);
1762 LOGD("ret : 0x%x", ret);
1768 int recorder_start(recorder_h recorder)
1770 int ret = RECORDER_ERROR_NONE;
1771 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1772 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1773 recorder_state_e current_state = RECORDER_STATE_NONE;
1775 if (!pc || !pc->cb_info) {
1776 LOGE("NULL handle");
1777 return RECORDER_ERROR_INVALID_PARAMETER;
1783 ret = recorder_get_state(recorder, ¤t_state);
1784 if (ret != RECORDER_ERROR_NONE) {
1785 LOGE("failed to get current state 0x%x", ret);
1786 return RECORDER_ERROR_INVALID_OPERATION;
1789 if (current_state == RECORDER_STATE_READY) {
1790 ret = camera_stop_evas_rendering(pc->camera, true);
1791 if (ret != CAMERA_ERROR_NONE) {
1792 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1793 return RECORDER_ERROR_INVALID_OPERATION;
1798 _recorder_msg_send(api, pc->cb_info, &ret);
1800 if (pc->camera && current_state == RECORDER_STATE_READY)
1801 camera_start_evas_rendering(pc->camera);
1803 LOGD("ret : 0x%x", ret);
1809 int recorder_pause(recorder_h recorder)
1811 int ret = RECORDER_ERROR_NONE;
1812 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1813 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1815 if (!pc || !pc->cb_info) {
1816 LOGE("NULL handle");
1817 return RECORDER_ERROR_INVALID_PARAMETER;
1822 _recorder_msg_send(api, pc->cb_info, &ret);
1824 LOGD("ret : 0x%x", ret);
1830 int recorder_commit(recorder_h recorder)
1832 int ret = RECORDER_ERROR_NONE;
1833 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1834 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1835 recorder_state_e current_state = RECORDER_STATE_NONE;
1837 if (!pc || !pc->cb_info) {
1838 LOGE("NULL handle");
1839 return RECORDER_ERROR_INVALID_PARAMETER;
1845 ret = recorder_get_state(recorder, ¤t_state);
1846 if (ret != RECORDER_ERROR_NONE) {
1847 LOGE("failed to get current state 0x%x", ret);
1848 return RECORDER_ERROR_INVALID_OPERATION;
1851 if (current_state >= RECORDER_STATE_RECORDING) {
1852 ret = camera_stop_evas_rendering(pc->camera, true);
1853 if (ret != CAMERA_ERROR_NONE) {
1854 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1855 return RECORDER_ERROR_INVALID_OPERATION;
1860 _recorder_msg_send(api, pc->cb_info, &ret);
1862 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1863 camera_start_evas_rendering(pc->camera);
1865 LOGD("ret : 0x%x", ret);
1871 int recorder_cancel(recorder_h recorder)
1873 int ret = RECORDER_ERROR_NONE;
1874 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1875 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1876 recorder_state_e current_state = RECORDER_STATE_NONE;
1878 if (!pc || !pc->cb_info) {
1879 LOGE("NULL handle");
1880 return RECORDER_ERROR_INVALID_PARAMETER;
1886 ret = recorder_get_state(recorder, ¤t_state);
1887 if (ret != RECORDER_ERROR_NONE) {
1888 LOGE("failed to get current state 0x%x", ret);
1889 return RECORDER_ERROR_INVALID_OPERATION;
1892 if (current_state >= RECORDER_STATE_RECORDING) {
1893 ret = camera_stop_evas_rendering(pc->camera, true);
1894 if (ret != CAMERA_ERROR_NONE) {
1895 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1896 return RECORDER_ERROR_INVALID_OPERATION;
1901 _recorder_msg_send(api, pc->cb_info, &ret);
1903 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1904 camera_start_evas_rendering(pc->camera);
1906 LOGD("ret : 0x%x", ret);
1912 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1914 int ret = RECORDER_ERROR_NONE;
1916 char *send_msg = NULL;
1917 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1918 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1920 if (!pc || !pc->cb_info) {
1921 LOGE("NULL handle");
1922 return RECORDER_ERROR_INVALID_PARAMETER;
1927 send_msg = muse_core_msg_json_factory_new(api,
1928 MUSE_TYPE_INT, "width", width,
1929 MUSE_TYPE_INT, "height", height,
1932 if (pc->cb_info->is_server_connected) {
1933 __recorder_update_api_waiting(pc->cb_info, api, 1);
1935 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1939 LOGE("message send failed");
1940 ret = RECORDER_ERROR_INVALID_OPERATION;
1942 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1945 __recorder_update_api_waiting(pc->cb_info, api, -1);
1947 muse_core_msg_json_factory_free(send_msg);
1949 LOGE("failed to create msg");
1950 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1953 LOGD("ret : 0x%x", ret);
1959 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1961 int ret = RECORDER_ERROR_NONE;
1962 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1963 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1965 if (!pc || !pc->cb_info) {
1966 LOGE("NULL handle");
1967 return RECORDER_ERROR_INVALID_PARAMETER;
1970 if (!width || !height) {
1971 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1972 return RECORDER_ERROR_INVALID_PARAMETER;
1977 _recorder_msg_send(api, pc->cb_info, &ret);
1979 if (ret == RECORDER_ERROR_NONE) {
1980 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1981 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1984 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1990 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1991 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1993 int ret = RECORDER_ERROR_NONE;
1994 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1995 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1997 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1998 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1999 return RECORDER_ERROR_INVALID_PARAMETER;
2002 LOGD("Enter, handle :%x", pc->remote_handle);
2004 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2005 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2007 _recorder_msg_send(api, pc->cb_info, &ret);
2009 LOGD("ret : 0x%x", ret);
2015 int recorder_get_audio_level(recorder_h recorder, double *level)
2017 int ret = RECORDER_ERROR_NONE;
2018 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2019 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2021 if (!pc || !pc->cb_info || level == NULL) {
2022 LOGE("NULL pointer %p %p", pc, level);
2023 return RECORDER_ERROR_INVALID_PARAMETER;
2028 _recorder_msg_send(api, pc->cb_info, &ret);
2030 if (ret == RECORDER_ERROR_NONE)
2031 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2033 LOGD("ret : 0x%x, level %lf", ret, *level);
2039 int recorder_set_filename(recorder_h recorder, const char *filename)
2041 int ret = RECORDER_ERROR_NONE;
2042 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2043 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2044 recorder_msg_param param;
2045 char set_filename[RECORDER_FILENAME_MAX] = {0, };
2047 if (!pc || !pc->cb_info) {
2048 LOGE("NULL handle");
2049 return RECORDER_ERROR_INVALID_PARAMETER;
2052 if (filename == NULL) {
2053 LOGE("filename is NULL");
2054 return RECORDER_ERROR_INVALID_PARAMETER;
2059 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2060 /* Cannot convert. Use original path. */
2061 strncpy(set_filename, filename, strlen(filename));
2063 /* Converted. Use converted path. */
2064 LOGD("Converted filename : %s -> %s", filename, set_filename);
2067 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2069 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2071 LOGD("ret : 0x%x", ret);
2077 int recorder_get_filename(recorder_h recorder, char **filename)
2079 int ret = RECORDER_ERROR_NONE;
2080 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2081 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2082 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2084 if (!pc || !pc->cb_info) {
2085 LOGE("NULL handle");
2086 return RECORDER_ERROR_INVALID_PARAMETER;
2089 if (filename == NULL) {
2090 LOGE("filename is NULL");
2091 return RECORDER_ERROR_INVALID_PARAMETER;
2096 _recorder_msg_send(api, pc->cb_info, &ret);
2098 if (ret == RECORDER_ERROR_NONE) {
2099 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2100 /* Cannot convert. Use original path. */
2101 *filename = pc->cb_info->get_filename;
2103 /* Converted. Use converted path. */
2104 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2105 *filename = strdup(compat_filename);
2106 free(pc->cb_info->get_filename);
2109 pc->cb_info->get_filename = NULL;
2112 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2118 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2120 int ret = RECORDER_ERROR_NONE;
2121 int set_format = (int)format;
2122 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2123 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2124 recorder_msg_param param;
2126 if (!pc || !pc->cb_info) {
2127 LOGE("NULL handle");
2128 return RECORDER_ERROR_INVALID_PARAMETER;
2131 LOGD("ENTER, set_format : %d", set_format);
2133 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2135 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2137 LOGD("ret : 0x%x", ret);
2142 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2144 int ret = RECORDER_ERROR_NONE;
2145 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2146 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2148 if (!pc || !pc->cb_info) {
2149 LOGE("NULL handle");
2150 return RECORDER_ERROR_INVALID_PARAMETER;
2153 if (format == NULL) {
2154 LOGE("NULL pointer data");
2155 return RECORDER_ERROR_INVALID_PARAMETER;
2160 _recorder_msg_send(api, pc->cb_info, &ret);
2162 if (ret == RECORDER_ERROR_NONE)
2163 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2165 LOGD("ret : 0x%x, format %d", ret, *format);
2171 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2173 int ret = RECORDER_ERROR_NONE;
2174 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2175 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2176 bool is_available = false;
2177 int stream_index = 0;
2178 char *stream_type = NULL;
2179 char *send_msg = NULL;
2182 if (!pc || !pc->cb_info || stream_info == NULL) {
2183 LOGE("NULL handle");
2184 return RECORDER_ERROR_INVALID_PARAMETER;
2189 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2190 if (ret != SOUND_MANAGER_ERROR_NONE) {
2191 LOGE("stream info verification failed");
2192 return RECORDER_ERROR_INVALID_OPERATION;
2195 if (is_available == false) {
2196 LOGE("stream information is not available");
2197 return RECORDER_ERROR_INVALID_OPERATION;
2200 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2201 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2203 LOGD("sound manager return [0x%x]", ret);
2205 if (ret == SOUND_MANAGER_ERROR_NONE) {
2206 send_msg = muse_core_msg_json_factory_new(api,
2207 MUSE_TYPE_STRING, "stream_type", stream_type,
2208 MUSE_TYPE_INT, "stream_index", stream_index,
2211 if (pc->cb_info->is_server_connected) {
2212 __recorder_update_api_waiting(pc->cb_info, api, 1);
2214 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2218 LOGE("message send failed");
2219 ret = RECORDER_ERROR_INVALID_OPERATION;
2221 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2224 __recorder_update_api_waiting(pc->cb_info, api, -1);
2226 muse_core_msg_json_factory_free(send_msg);
2228 LOGE("failed to create msg");
2229 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2232 ret = RECORDER_ERROR_INVALID_OPERATION;
2239 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2241 int ret = RECORDER_ERROR_NONE;
2242 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2243 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2245 if (!pc || !pc->cb_info || callback == NULL) {
2246 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2247 return RECORDER_ERROR_INVALID_PARAMETER;
2250 LOGD("Enter, handle :%x", pc->remote_handle);
2252 _recorder_msg_send(api, pc->cb_info, &ret);
2254 if (ret == RECORDER_ERROR_NONE) {
2255 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2256 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2259 LOGD("ret : 0x%x", ret);
2265 int recorder_unset_state_changed_cb(recorder_h recorder)
2267 int ret = RECORDER_ERROR_NONE;
2268 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2269 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2271 if (!pc || !pc->cb_info) {
2272 LOGE("NULL handle");
2273 return RECORDER_ERROR_INVALID_PARAMETER;
2278 _recorder_msg_send(api, pc->cb_info, &ret);
2280 if (ret == RECORDER_ERROR_NONE) {
2281 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2282 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2285 LOGD("ret : 0x%x", ret);
2291 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2293 int ret = RECORDER_ERROR_NONE;
2294 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2295 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2297 if (!pc || !pc->cb_info || callback == NULL) {
2298 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2299 return RECORDER_ERROR_INVALID_PARAMETER;
2302 LOGD("Enter, handle :%x", pc->remote_handle);
2304 _recorder_msg_send(api, pc->cb_info, &ret);
2306 if (ret == RECORDER_ERROR_NONE) {
2307 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2308 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2311 LOGD("ret : 0x%x", ret);
2317 int recorder_unset_interrupted_cb(recorder_h recorder)
2319 int ret = RECORDER_ERROR_NONE;
2320 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2321 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2323 if (!pc || !pc->cb_info) {
2324 LOGE("NULL handle");
2325 return RECORDER_ERROR_INVALID_PARAMETER;
2330 _recorder_msg_send(api, pc->cb_info, &ret);
2332 if (ret == RECORDER_ERROR_NONE) {
2333 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2334 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2337 LOGD("ret : 0x%x", ret);
2343 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2345 int ret = RECORDER_ERROR_NONE;
2346 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2347 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2349 if (!pc || !pc->cb_info || callback == NULL) {
2350 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2351 return RECORDER_ERROR_INVALID_PARAMETER;
2354 LOGD("Enter, handle :%x", pc->remote_handle);
2356 _recorder_msg_send(api, pc->cb_info, &ret);
2358 if (ret == RECORDER_ERROR_NONE) {
2359 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2360 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2363 LOGD("ret : 0x%x", ret);
2369 int recorder_unset_audio_stream_cb(recorder_h recorder)
2371 int ret = RECORDER_ERROR_NONE;
2372 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2373 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2375 if (!pc || !pc->cb_info) {
2376 LOGE("NULL handle");
2377 return RECORDER_ERROR_INVALID_PARAMETER;
2382 _recorder_msg_send(api, pc->cb_info, &ret);
2384 if (ret == RECORDER_ERROR_NONE) {
2385 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2386 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2389 LOGD("ret : 0x%x", ret);
2395 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2397 int ret = RECORDER_ERROR_NONE;
2398 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2399 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2401 if (!pc || !pc->cb_info || !callback) {
2402 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2403 return RECORDER_ERROR_INVALID_PARAMETER;
2406 LOGD("Enter, handle :%x", pc->remote_handle);
2408 _recorder_msg_send(api, pc->cb_info, &ret);
2410 if (ret == RECORDER_ERROR_NONE) {
2411 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2412 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2415 LOGD("ret : 0x%x", ret);
2421 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2423 int ret = RECORDER_ERROR_NONE;
2424 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2425 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2427 if (!pc || !pc->cb_info) {
2428 LOGE("NULL handle");
2429 return RECORDER_ERROR_INVALID_PARAMETER;
2434 _recorder_msg_send(api, pc->cb_info, &ret);
2436 if (ret == RECORDER_ERROR_NONE) {
2437 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2438 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2441 LOGD("ret : 0x%x", ret);
2447 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2449 int ret = RECORDER_ERROR_NONE;
2450 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2451 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2453 if (!pc || !pc->cb_info || callback == NULL) {
2454 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2455 return RECORDER_ERROR_INVALID_PARAMETER;
2458 LOGD("Enter, handle :%x", pc->remote_handle);
2460 _recorder_msg_send(api, pc->cb_info, &ret);
2462 if (ret == RECORDER_ERROR_NONE) {
2463 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2464 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2467 LOGD("ret : 0x%x", ret);
2473 int recorder_unset_error_cb(recorder_h recorder)
2475 int ret = RECORDER_ERROR_NONE;
2476 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2477 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2479 if (!pc || !pc->cb_info) {
2480 LOGE("NULL handle");
2481 return RECORDER_ERROR_INVALID_PARAMETER;
2486 _recorder_msg_send(api, pc->cb_info, &ret);
2488 if (ret == RECORDER_ERROR_NONE) {
2489 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2490 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2493 LOGD("ret : 0x%x", ret);
2499 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2501 int ret = RECORDER_ERROR_NONE;
2502 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2503 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2505 if (!pc || !pc->cb_info || callback == NULL) {
2506 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2507 return RECORDER_ERROR_INVALID_PARAMETER;
2510 LOGD("Enter, handle :%x", pc->remote_handle);
2512 _recorder_msg_send(api, pc->cb_info, &ret);
2514 if (ret == RECORDER_ERROR_NONE) {
2515 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2516 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2519 LOGD("ret : 0x%x", ret);
2525 int recorder_unset_recording_status_cb(recorder_h recorder)
2527 int ret = RECORDER_ERROR_NONE;
2528 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2529 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2531 if (!pc || !pc->cb_info) {
2532 LOGE("NULL handle");
2533 return RECORDER_ERROR_INVALID_PARAMETER;
2538 _recorder_msg_send(api, pc->cb_info, &ret);
2540 if (ret == RECORDER_ERROR_NONE) {
2541 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2542 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2545 LOGD("ret : 0x%x", ret);
2551 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2553 int ret = RECORDER_ERROR_NONE;
2554 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2555 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2557 if (!pc || !pc->cb_info || callback == NULL) {
2558 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2559 return RECORDER_ERROR_INVALID_PARAMETER;
2562 _recorder_msg_send(api, pc->cb_info, &ret);
2564 if (ret == RECORDER_ERROR_NONE) {
2565 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2566 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2569 LOGD("ret : 0x%x", ret);
2575 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2577 int ret = RECORDER_ERROR_NONE;
2578 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2579 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2581 if (!pc || !pc->cb_info) {
2582 LOGE("NULL handle");
2583 return RECORDER_ERROR_INVALID_PARAMETER;
2588 _recorder_msg_send(api, pc->cb_info, &ret);
2590 if (ret == RECORDER_ERROR_NONE) {
2591 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2592 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2595 LOGD("ret : 0x%x", ret);
2601 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2603 int ret = RECORDER_ERROR_NONE;
2604 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2605 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2607 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2608 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2609 return RECORDER_ERROR_INVALID_PARAMETER;
2612 LOGD("Enter, handle :%x", pc->remote_handle);
2614 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2615 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2617 _recorder_msg_send(api, pc->cb_info, &ret);
2619 LOGD("ret : 0x%x", ret);
2625 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2627 int ret = RECORDER_ERROR_NONE;
2628 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2629 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2630 recorder_msg_param param;
2632 if (!pc || !pc->cb_info) {
2633 LOGE("NULL handle");
2634 return RECORDER_ERROR_INVALID_PARAMETER;
2639 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2641 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2643 LOGD("ret : 0x%x", ret);
2649 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2651 int ret = RECORDER_ERROR_NONE;
2652 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2653 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2654 recorder_msg_param param;
2656 if (!pc || !pc->cb_info) {
2657 LOGE("NULL handle");
2658 return RECORDER_ERROR_INVALID_PARAMETER;
2663 RECORDER_MSG_PARAM_SET(param, INT, second);
2665 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2667 LOGD("ret : 0x%x", ret);
2673 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2675 int ret = RECORDER_ERROR_NONE;
2676 int set_device = (int)device;
2677 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2678 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2679 recorder_msg_param param;
2681 if (!pc || !pc->cb_info) {
2682 LOGE("NULL handle");
2683 return RECORDER_ERROR_INVALID_PARAMETER;
2688 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2690 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2692 LOGD("ret : 0x%x", ret);
2698 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2700 int ret = RECORDER_ERROR_NONE;
2701 int set_codec = (int)codec;
2702 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2703 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2704 recorder_msg_param param;
2706 if (!pc || !pc->cb_info) {
2707 LOGE("NULL handle");
2708 return RECORDER_ERROR_INVALID_PARAMETER;
2713 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2715 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2717 LOGD("ret : 0x%x", ret);
2723 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2725 int ret = RECORDER_ERROR_NONE;
2726 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2727 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2729 if (!pc || !pc->cb_info) {
2730 LOGE("NULL handle");
2731 return RECORDER_ERROR_INVALID_PARAMETER;
2734 if (codec == NULL) {
2735 LOGE("codec is NULL");
2736 return RECORDER_ERROR_INVALID_PARAMETER;
2741 _recorder_msg_send(api, pc->cb_info, &ret);
2743 if (ret == RECORDER_ERROR_NONE)
2744 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2746 LOGD("ret : 0x%x, codec %d", ret, *codec);
2752 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2754 int ret = RECORDER_ERROR_NONE;
2755 int set_codec = (int)codec;
2756 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2757 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2758 recorder_msg_param param;
2760 if (!pc || !pc->cb_info) {
2761 LOGE("NULL handle");
2762 return RECORDER_ERROR_INVALID_PARAMETER;
2767 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2769 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2771 LOGD("ret : 0x%x", ret);
2777 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2779 int ret = RECORDER_ERROR_NONE;
2780 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2781 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2783 if (!pc || !pc->cb_info) {
2784 LOGE("NULL handle");
2785 return RECORDER_ERROR_INVALID_PARAMETER;
2788 if (codec == NULL) {
2789 LOGE("codec is NULL");
2790 return RECORDER_ERROR_INVALID_PARAMETER;
2795 _recorder_msg_send(api, pc->cb_info, &ret);
2797 if (ret == RECORDER_ERROR_NONE)
2798 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2800 LOGD("ret : 0x%x, codec %d", ret, *codec);
2806 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2808 int ret = RECORDER_ERROR_NONE;
2809 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2810 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2811 recorder_msg_param param;
2813 if (!pc || !pc->cb_info) {
2814 LOGE("NULL handle");
2815 return RECORDER_ERROR_INVALID_PARAMETER;
2818 LOGD("ENTER, samplerate : %d", samplerate);
2820 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2822 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2824 LOGD("ret : 0x%x", ret);
2830 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2832 int ret = RECORDER_ERROR_NONE;
2833 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2834 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2835 recorder_msg_param param;
2837 if (!pc || !pc->cb_info) {
2838 LOGE("NULL handle");
2839 return RECORDER_ERROR_INVALID_PARAMETER;
2844 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2846 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2848 LOGD("ret : 0x%x", ret);
2854 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2856 int ret = RECORDER_ERROR_NONE;
2857 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2858 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2859 recorder_msg_param param;
2861 if (!pc || !pc->cb_info) {
2862 LOGE("NULL handle");
2863 return RECORDER_ERROR_INVALID_PARAMETER;
2868 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2870 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2872 LOGD("ret : 0x%x", ret);
2878 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2880 int ret = RECORDER_ERROR_NONE;
2881 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2882 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2884 if (!pc || !pc->cb_info) {
2885 LOGE("NULL handle");
2886 return RECORDER_ERROR_INVALID_PARAMETER;
2889 if (kbyte == NULL) {
2890 LOGE("NULL pointer kbyte");
2891 return RECORDER_ERROR_INVALID_PARAMETER;
2896 _recorder_msg_send(api, pc->cb_info, &ret);
2898 if (ret == RECORDER_ERROR_NONE)
2899 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2901 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2907 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2909 int ret = RECORDER_ERROR_NONE;
2910 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2911 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2913 if (!pc || !pc->cb_info) {
2914 LOGE("NULL handle");
2915 return RECORDER_ERROR_INVALID_PARAMETER;
2918 if (second == NULL) {
2919 LOGE("NULL pointer second");
2920 return RECORDER_ERROR_INVALID_PARAMETER;
2925 _recorder_msg_send(api, pc->cb_info, &ret);
2927 if (ret == RECORDER_ERROR_NONE)
2928 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2930 LOGD("ret : 0x%x, %d second", ret, *second);
2936 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2938 int ret = RECORDER_ERROR_NONE;
2939 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2940 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2942 if (!pc || !pc->cb_info) {
2943 LOGE("NULL handle");
2944 return RECORDER_ERROR_INVALID_PARAMETER;
2947 if (device == NULL) {
2948 LOGE("NULL pointer device");
2949 return RECORDER_ERROR_INVALID_PARAMETER;
2954 _recorder_msg_send(api, pc->cb_info, &ret);
2956 if (ret == RECORDER_ERROR_NONE)
2957 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2959 LOGD("ret : 0x%x, device %d", ret, *device);
2965 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2967 int ret = RECORDER_ERROR_NONE;
2968 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2969 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2971 if (!pc || !pc->cb_info) {
2972 LOGE("NULL handle");
2973 return RECORDER_ERROR_INVALID_PARAMETER;
2976 if (samplerate == NULL) {
2977 LOGE("NULL pointer handle");
2978 return RECORDER_ERROR_INVALID_PARAMETER;
2983 _recorder_msg_send(api, pc->cb_info, &ret);
2985 if (ret == RECORDER_ERROR_NONE)
2986 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
2988 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
2994 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2996 int ret = RECORDER_ERROR_NONE;
2997 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2998 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3000 if (!pc || !pc->cb_info) {
3001 LOGE("NULL handle");
3002 return RECORDER_ERROR_INVALID_PARAMETER;
3005 if (bitrate == NULL) {
3006 LOGE("NULL pointer");
3007 return RECORDER_ERROR_INVALID_PARAMETER;
3012 _recorder_msg_send(api, pc->cb_info, &ret);
3014 if (ret == RECORDER_ERROR_NONE)
3015 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3017 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3023 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3025 int ret = RECORDER_ERROR_NONE;
3026 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3027 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3029 if (!pc || !pc->cb_info) {
3030 LOGE("NULL handle");
3031 return RECORDER_ERROR_INVALID_PARAMETER;
3034 if (bitrate == NULL) {
3035 LOGE("NULL pointer");
3036 return RECORDER_ERROR_INVALID_PARAMETER;
3041 _recorder_msg_send(api, pc->cb_info, &ret);
3043 if (ret == RECORDER_ERROR_NONE)
3044 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3046 LOGD("ret : 0x%x", ret);
3052 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3054 int ret = RECORDER_ERROR_NONE;
3055 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3056 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3058 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3059 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3060 return RECORDER_ERROR_INVALID_PARAMETER;
3063 LOGD("Enter, handle :%x", pc->remote_handle);
3065 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3066 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3068 _recorder_msg_send(api, pc->cb_info, &ret);
3070 LOGD("ret : 0x%x", ret);
3076 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3078 int ret = RECORDER_ERROR_NONE;
3079 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3080 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3082 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3083 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3084 return RECORDER_ERROR_INVALID_PARAMETER;
3087 LOGD("Enter, handle :%x", pc->remote_handle);
3089 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3090 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3092 _recorder_msg_send(api, pc->cb_info, &ret);
3094 LOGD("ret : 0x%x", ret);
3100 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3102 int ret = RECORDER_ERROR_NONE;
3103 int set_enable = (int)enable;
3104 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3105 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3106 recorder_msg_param param;
3108 if (!pc || !pc->cb_info) {
3109 LOGE("NULL handle");
3110 return RECORDER_ERROR_INVALID_PARAMETER;
3115 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3117 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3119 LOGD("ret : 0x%x", ret);
3125 bool recorder_attr_is_muted(recorder_h recorder)
3128 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3129 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3131 if (!pc || !pc->cb_info) {
3132 LOGE("NULL handle");
3138 _recorder_msg_send(api, pc->cb_info, &ret);
3140 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3143 LOGD("ret : %d", ret);
3149 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3151 int ret = RECORDER_ERROR_NONE;
3152 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3153 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3154 recorder_msg_param param;
3156 if (!pc || !pc->cb_info) {
3157 LOGE("NULL handle");
3158 return RECORDER_ERROR_INVALID_PARAMETER;
3161 LOGD("ENTER - %.20lf", rate);
3163 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3165 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3167 LOGD("ret : 0x%x", ret);
3173 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3175 int ret = RECORDER_ERROR_NONE;
3176 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3177 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3179 if (!pc || !pc->cb_info) {
3180 LOGE("NULL handle");
3181 return RECORDER_ERROR_INVALID_PARAMETER;
3185 LOGE("rate is NULL");
3186 return RECORDER_ERROR_INVALID_PARAMETER;
3191 _recorder_msg_send(api, pc->cb_info, &ret);
3192 if (ret == RECORDER_ERROR_NONE)
3193 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3195 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3201 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3203 int ret = RECORDER_ERROR_NONE;
3204 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3205 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3206 recorder_msg_param param;
3208 if (!pc || !pc->cb_info) {
3209 LOGE("NULL handle");
3210 return RECORDER_ERROR_INVALID_PARAMETER;
3215 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3217 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3219 LOGD("ret : 0x%x", ret);
3225 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3227 int ret = RECORDER_ERROR_NONE;
3228 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3229 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3231 if (!pc || !pc->cb_info) {
3232 LOGE("NULL handle");
3233 return RECORDER_ERROR_INVALID_PARAMETER;
3236 if (channel_count == NULL) {
3237 LOGE("channel_count is NULL");
3238 return RECORDER_ERROR_INVALID_PARAMETER;
3243 _recorder_msg_send(api, pc->cb_info, &ret);
3245 if (ret == RECORDER_ERROR_NONE)
3246 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3248 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3254 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3256 int ret = RECORDER_ERROR_NONE;
3257 int set_orientation = (int)orientation;
3258 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3259 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3260 recorder_msg_param param;
3262 if (!pc || !pc->cb_info) {
3263 LOGE("NULL handle");
3264 return RECORDER_ERROR_INVALID_PARAMETER;
3269 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3271 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3273 LOGD("ret : 0x%x", ret);
3279 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3281 int ret = RECORDER_ERROR_NONE;
3282 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3283 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3285 if (!pc || !pc->cb_info) {
3286 LOGE("NULL handle");
3287 return RECORDER_ERROR_INVALID_PARAMETER;
3290 if (orientation == NULL) {
3291 LOGE("orientation is NULL");
3292 return RECORDER_ERROR_INVALID_PARAMETER;
3297 _recorder_msg_send(api, pc->cb_info, &ret);
3299 if (ret == RECORDER_ERROR_NONE)
3300 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3302 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3308 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3310 int ret = RECORDER_ERROR_NONE;
3312 int get_device_state = 0;
3313 char *send_msg = NULL;
3314 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3317 LOGE("NULL pointer");
3318 return RECORDER_ERROR_INVALID_PARAMETER;
3321 LOGD("Enter - type %d", type);
3323 sock_fd = muse_core_client_new();
3325 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3326 ret = RECORDER_ERROR_INVALID_OPERATION;
3327 goto _GET_DEVICE_STATE_EXIT;
3330 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3331 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3332 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3336 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3337 goto _GET_DEVICE_STATE_EXIT;
3340 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3342 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3344 muse_core_msg_json_factory_free(send_msg);
3348 LOGE("send msg failed %d", errno);
3349 ret = RECORDER_ERROR_INVALID_OPERATION;
3350 goto _GET_DEVICE_STATE_EXIT;
3353 ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3355 LOGE("recv msg failed %d", errno);
3356 ret = RECORDER_ERROR_INVALID_OPERATION;
3357 goto _GET_DEVICE_STATE_EXIT;
3360 if (!muse_recorder_msg_get(ret, recv_msg)) {
3361 LOGE("failed to get return value from msg [%s]", recv_msg);
3362 ret = RECORDER_ERROR_INVALID_OPERATION;
3363 goto _GET_DEVICE_STATE_EXIT;
3366 if (ret == RECORDER_ERROR_NONE) {
3367 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3368 *state = (recorder_device_state_e)get_device_state;
3369 LOGD("device type %d state %d", type, *state);
3371 LOGE("failed to get device state from msg [%s]", recv_msg);
3372 ret = RECORDER_ERROR_INVALID_OPERATION;
3375 LOGE("failed 0x%x", ret);
3378 _GET_DEVICE_STATE_EXIT:
3380 muse_core_connection_close(sock_fd);
3388 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3390 int ret = RECORDER_ERROR_NONE;
3391 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3392 recorder_cb_info *info = NULL;
3394 if (!callback || !cb_id) {
3395 LOGE("invalid pointer %p %p", callback, cb_id);
3396 return RECORDER_ERROR_INVALID_PARAMETER;
3399 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3401 /* check recorder support */
3402 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3403 if (ret != RECORDER_ERROR_NONE) {
3404 LOGE("get device state failed");
3405 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3409 info = g_new0(recorder_cb_info, 1);
3411 LOGE("info failed");
3412 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3416 info->id = ++g_rec_dev_state_changed_cb_id;
3417 info->callback = (void *)callback;
3418 info->user_data = user_data;
3422 /* subscribe dbus signal for camera state change */
3423 if (!g_rec_dev_state_changed_cb_conn) {
3424 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3425 if (!g_rec_dev_state_changed_cb_conn) {
3426 LOGE("failed to get gdbus connection");
3427 ret = RECORDER_ERROR_INVALID_OPERATION;
3431 LOGD("subscribe signal %s - %s - %s",
3432 MM_CAMCORDER_DBUS_OBJECT,
3433 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3434 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3436 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3437 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3438 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3439 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3440 LOGE("failed to get gdbus connection");
3441 ret = RECORDER_ERROR_INVALID_OPERATION;
3445 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3448 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3450 LOGD("callback id %d", info->id);
3453 if (ret != RECORDER_ERROR_NONE) {
3459 if (g_rec_dev_state_changed_cb_conn) {
3460 g_object_unref(g_rec_dev_state_changed_cb_conn);
3461 g_rec_dev_state_changed_cb_conn = NULL;
3465 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3471 int recorder_remove_device_state_changed_cb(int cb_id)
3473 int ret = RECORDER_ERROR_NONE;
3474 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3475 GList *tmp_list = NULL;
3476 recorder_cb_info *info = NULL;
3478 /* check recorder support */
3479 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3480 if (ret != RECORDER_ERROR_NONE) {
3481 LOGE("get device state failed");
3485 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3487 if (!g_rec_dev_state_changed_cb_list) {
3488 LOGE("there is no callback info");
3489 ret = RECORDER_ERROR_INVALID_OPERATION;
3493 tmp_list = g_rec_dev_state_changed_cb_list;
3496 info = tmp_list->data;
3497 tmp_list = tmp_list->next;
3504 if (info->id == cb_id) {
3505 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3510 if (!g_rec_dev_state_changed_cb_list) {
3511 /* no remained callback */
3512 if (g_rec_dev_state_changed_cb_conn) {
3513 /* unsubscribe signal */
3514 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3515 g_rec_dev_state_changed_cb_subscribe_id = 0;
3517 /* unref connection */
3518 g_object_unref(g_rec_dev_state_changed_cb_conn);
3519 g_rec_dev_state_changed_cb_conn = NULL;
3523 LOGD("id %d callback removed", cb_id);
3524 ret = RECORDER_ERROR_NONE;
3530 LOGE("id %d callback not found", cb_id);
3531 ret = RECORDER_ERROR_INVALID_PARAMETER;
3534 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);