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;
47 static recorder_device_state_e g_rec_dev_last_state;
50 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
51 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
52 const gchar *signal_name, GVariant *param, gpointer user_data)
55 recorder_type_e type = RECORDER_TYPE_AUDIO;
56 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
57 GList *tmp_list = NULL;
58 recorder_cb_info *info = NULL;
60 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
62 if (!g_rec_dev_state_changed_cb_list || !param) {
63 LOGW("no callback or NULL param %p", param);
67 /* get device and state */
68 g_variant_get(param, "(i)", &value);
70 /* get type only from message */
73 if (recorder_get_device_state(type, &state) != RECORDER_ERROR_NONE) {
74 LOGE("failed to get recorder device state");
78 LOGD("type %d, state %d", type, state);
80 if (state == g_rec_dev_last_state) {
81 LOGW("no need to call recorder device state changed cb [state %d]", state);
85 g_rec_dev_last_state = state;
87 tmp_list = g_rec_dev_state_changed_cb_list;
90 info = (recorder_cb_info *)tmp_list->data;
94 LOGD("start id[%d] callback", info->id);
95 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
96 LOGD("returned id[%d] callback", info->id);
98 LOGW("NULL callback for id %d", info->id);
102 tmp_list = tmp_list->next;
106 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
112 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
114 tbm_bo tmp_bo = NULL;
115 tbm_bo_handle tmp_bo_handle = {NULL, };
117 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
118 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
119 bufmgr, bo, bo_handle, tbm_key);
123 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
124 if (tmp_bo == NULL) {
125 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
129 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
130 if (tmp_bo_handle.ptr == NULL) {
131 LOGE("bo map failed %p", tmp_bo);
132 tbm_bo_unref(tmp_bo);
137 /* set bo and bo_handle */
139 *bo_handle = tmp_bo_handle;
144 static void _recorder_release_imported_bo(tbm_bo *bo)
146 if (bo == NULL || *bo == NULL) {
158 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
160 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
161 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
165 LOGD("get recorder msg %s, event %d", recv_msg, event);
167 if (cb_info->user_cb[event] == NULL) {
168 LOGW("user callback for event %d is not set", event);
173 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
179 muse_recorder_msg_get(previous, recv_msg);
180 muse_recorder_msg_get(current, recv_msg);
181 muse_recorder_msg_get(by_policy, recv_msg);
183 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
184 (recorder_state_e)current,
186 cb_info->user_data[event]);
189 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
193 muse_recorder_msg_get(type, recv_msg);
195 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
196 cb_info->user_data[event]);
199 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
201 int64_t cb_elapsed_time = 0;
202 int64_t cb_file_size = 0;
204 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
205 muse_recorder_msg_get(cb_file_size, recv_msg);
207 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
208 (unsigned long long)cb_file_size,
209 cb_info->user_data[event]);
212 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
218 muse_recorder_msg_get(policy, recv_msg);
219 muse_recorder_msg_get(previous, recv_msg);
220 muse_recorder_msg_get(current, recv_msg);
222 if (policy == RECORDER_POLICY_SOUND)
223 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
224 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
225 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
226 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
227 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
229 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
230 (recorder_state_e)previous,
231 (recorder_state_e)current,
232 cb_info->user_data[event]);
235 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
243 tbm_bo_handle bo_handle = {.ptr = NULL};
244 char *send_msg = NULL;
246 muse_recorder_msg_get(tbm_key, recv_msg);
252 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
253 LOGE("tbm key %d import failed", tbm_key);
257 muse_recorder_msg_get(size, recv_msg);
258 muse_recorder_msg_get(format, recv_msg);
259 muse_recorder_msg_get(channel, recv_msg);
260 muse_recorder_msg_get(timestamp, recv_msg);
262 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
264 (audio_sample_type_e)format,
266 (unsigned int)timestamp,
267 cb_info->user_data[event]);
269 /* release imported bo */
270 _recorder_release_imported_bo(&bo);
273 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
274 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
276 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
277 LOGE("sending message failed");
279 muse_core_msg_json_factory_free(send_msg);
282 case MUSE_RECORDER_EVENT_TYPE_ERROR:
285 int current_state = 0;
287 muse_recorder_msg_get(error, recv_msg);
288 muse_recorder_msg_get(current_state, recv_msg);
290 if (error == RECORDER_ERROR_SOUND_POLICY)
291 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
292 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
293 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
294 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
295 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
297 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
298 (recorder_state_e)current_state,
299 cb_info->user_data[event]);
302 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
306 muse_recorder_msg_get(codec, recv_msg);
308 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
309 cb_info->user_cb[event] = NULL;
310 cb_info->user_data[event] = NULL;
311 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
315 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
319 muse_recorder_msg_get(format, recv_msg);
321 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
322 cb_info->user_cb[event] = NULL;
323 cb_info->user_data[event] = NULL;
324 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
328 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
332 muse_recorder_msg_get(codec, recv_msg);
334 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
335 cb_info->user_cb[event] = NULL;
336 cb_info->user_data[event] = NULL;
337 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
341 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION:
346 muse_recorder_msg_get(width, recv_msg);
347 muse_recorder_msg_get(height, recv_msg);
349 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
350 cb_info->user_cb[event] = NULL;
351 cb_info->user_data[event] = NULL;
352 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
358 LOGE("Unknonw recorder event %d", event);
366 static bool _recorder_idle_event_callback(void *data)
368 recorder_cb_info_s *cb_info = NULL;
369 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
371 if (rec_idle_event == NULL) {
372 LOGE("rec_idle_event is NULL");
377 g_mutex_lock(&rec_idle_event->event_mutex);
379 cb_info = rec_idle_event->cb_info;
380 if (cb_info == NULL) {
381 LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
382 goto IDLE_EVENT_CALLBACK_DONE;
385 /* remove event from list */
386 g_mutex_lock(&cb_info->idle_event_mutex);
387 if (cb_info->idle_event_list)
388 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
390 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
391 g_mutex_unlock(&cb_info->idle_event_mutex);
394 _recorder_client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
396 /* send signal for waiting thread */
397 g_cond_signal(&cb_info->idle_event_cond);
399 IDLE_EVENT_CALLBACK_DONE:
400 /* unlock and release event */
401 g_mutex_unlock(&rec_idle_event->event_mutex);
402 g_mutex_clear(&rec_idle_event->event_mutex);
404 g_free(rec_idle_event);
405 rec_idle_event = NULL;
411 static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
413 recorder_idle_event_s *rec_idle_event = NULL;
418 if (cb_info == NULL) {
419 LOGE("cb_info is NULL");
423 g_mutex_lock(&cb_info->idle_event_mutex);
425 if (cb_info->idle_event_list == NULL) {
428 list = cb_info->idle_event_list;
431 rec_idle_event = list->data;
432 list = g_list_next(list);
434 if (!rec_idle_event) {
435 LOGW("The event is NULL");
439 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
442 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
444 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
445 LOGW("signal received");
452 ret = g_idle_remove_by_data(rec_idle_event);
454 LOGD("remove event %p, ret %d", rec_idle_event, ret);
457 rec_idle_event->cb_info = NULL;
458 LOGW("idle cb for event %p will be called later", rec_idle_event);
461 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
463 g_mutex_unlock(&rec_idle_event->event_mutex);
466 g_mutex_clear(&rec_idle_event->event_mutex);
468 g_free(rec_idle_event);
469 rec_idle_event = NULL;
471 LOGD("remove event done");
475 g_list_free(cb_info->idle_event_list);
476 cb_info->idle_event_list = NULL;
479 g_mutex_unlock(&cb_info->idle_event_mutex);
485 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
487 recorder_message_s *rec_msg = NULL;
489 if (!cb_info || !msg) {
490 LOGE("NULL pointer %p %p", cb_info, msg);
494 rec_msg = g_new0(recorder_message_s, 1);
496 LOGE("failed to alloc rec_msg for [%s]", msg);
501 rec_msg->event = event;
502 rec_msg->event_class = event_class;
504 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
506 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
508 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
509 g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
510 g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
511 g_cond_signal(&cb_info->audio_stream_cb_info.cond);
512 g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
514 g_mutex_lock(&cb_info->msg_handler_info.mutex);
515 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
516 g_cond_signal(&cb_info->msg_handler_info.cond);
517 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
526 static void *_recorder_msg_handler_func(gpointer data)
530 recorder_message_s *rec_msg = NULL;
531 recorder_idle_event_s *rec_idle_event = NULL;
532 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
533 recorder_cb_info_s *cb_info = NULL;
535 if (!handler_info || !handler_info->cb_info) {
536 LOGE("NULL handler %p", handler_info);
540 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
541 type = handler_info->type;
543 LOGD("t:%d start", type);
545 g_mutex_lock(&handler_info->mutex);
547 while (g_atomic_int_get(&handler_info->running)) {
548 if (g_queue_is_empty(handler_info->queue)) {
549 /*LOGD("signal wait...");*/
550 g_cond_wait(&handler_info->cond, &handler_info->mutex);
551 /*LOGD("signal received");*/
553 if (g_atomic_int_get(&handler_info->running) == 0) {
554 LOGD("stop event thread");
559 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
560 g_mutex_unlock(&handler_info->mutex);
561 if (rec_msg == NULL) {
562 LOGE("NULL message");
563 g_mutex_lock(&handler_info->mutex);
569 if (api < MUSE_RECORDER_API_MAX) {
572 g_mutex_lock(&cb_info->api_mutex[api]);
574 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
575 cb_info->api_ret[api] = ret;
576 cb_info->api_activating[api] = 1;
578 /*LOGD("recorder api %d - return 0x%x", ret);*/
580 g_cond_signal(&cb_info->api_cond[api]);
582 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
585 g_mutex_unlock(&cb_info->api_mutex[api]);
586 } else if (api == MUSE_RECORDER_CB_EVENT) {
587 switch (rec_msg->event_class) {
588 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
589 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
591 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
592 rec_idle_event = g_new0(recorder_idle_event_s, 1);
593 if (rec_idle_event == NULL) {
594 LOGE("event alloc failed");
598 rec_idle_event->event = rec_msg->event;
599 rec_idle_event->cb_info = cb_info;
600 g_mutex_init(&rec_idle_event->event_mutex);
601 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
603 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
605 g_mutex_lock(&cb_info->idle_event_mutex);
606 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
607 g_mutex_unlock(&cb_info->idle_event_mutex);
609 g_idle_add_full(G_PRIORITY_DEFAULT,
610 (GSourceFunc)_recorder_idle_event_callback,
611 (gpointer)rec_idle_event,
615 LOGE("unknown event class %d", rec_msg->event_class);
619 LOGE("unknown api[%d] message", api);
625 g_mutex_lock(&handler_info->mutex);
628 /* remove remained event */
629 while (!g_queue_is_empty(handler_info->queue)) {
630 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
632 LOGD("remove message %p", rec_msg);
636 LOGW("NULL message");
640 g_mutex_unlock(&handler_info->mutex);
648 static void _recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
650 if (!cb_info || !msg) {
651 LOGE("NULL pointer %p %p", cb_info, msg);
656 case MUSE_RECORDER_API_GET_STATE:
659 muse_recorder_msg_get(get_state, msg);
660 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
663 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
667 muse_recorder_msg_get(get_width, msg);
668 muse_recorder_msg_get(get_height, msg);
669 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
670 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
673 case MUSE_RECORDER_API_GET_FILE_FORMAT:
676 muse_recorder_msg_get(get_format, msg);
677 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
680 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
683 muse_recorder_msg_get(get_codec, msg);
684 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
687 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
690 muse_recorder_msg_get(get_codec, msg);
691 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
694 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
697 muse_recorder_msg_get(get_kbyte, msg);
698 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
701 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
704 muse_recorder_msg_get(get_second, msg);
705 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
708 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
711 muse_recorder_msg_get(get_device, msg);
712 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
715 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
717 int get_samplerate = 0;
718 muse_recorder_msg_get(get_samplerate, msg);
719 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
722 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
725 muse_recorder_msg_get(get_bitrate, msg);
726 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
729 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
732 muse_recorder_msg_get(get_bitrate, msg);
733 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
736 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
739 muse_recorder_msg_get_double(get_rate, msg);
740 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
743 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
745 int get_channel_count = 0;
746 muse_recorder_msg_get(get_channel_count, msg);
747 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
750 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
752 int get_orientation = 0;
753 muse_recorder_msg_get(get_orientation, msg);
754 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
757 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
759 double get_level = 0.0;
760 muse_recorder_msg_get_double(get_level, msg);
761 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
764 case MUSE_RECORDER_API_GET_FILENAME:
766 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
767 muse_recorder_msg_get_string(get_filename, msg);
768 if (cb_info->get_filename) {
769 free(cb_info->get_filename);
770 cb_info->get_filename = NULL;
772 cb_info->get_filename = strdup(get_filename);
783 static void *_recorder_msg_recv_func(gpointer data)
795 char *recv_msg = NULL;
796 char *error_msg = NULL;
797 char **parse_str = NULL;
798 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
800 if (cb_info == NULL) {
801 LOGE("cb_info NULL");
807 parse_str = (char **)malloc(sizeof(char *) * RECORDER_PARSED_STRING_NUM_MAX);
808 if (parse_str == NULL) {
809 LOGE("parse_str malloc failed");
813 for (i = 0 ; i < RECORDER_PARSED_STRING_NUM_MAX ; i++) {
814 parse_str[i] = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
815 if (parse_str[i] == NULL) {
816 LOGE("parse_str[%d] malloc failed", i);
817 goto CB_HANDLER_EXIT;
821 recv_msg = cb_info->recv_msg;
823 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
824 ret = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
826 cb_info->is_server_connected = FALSE;
827 LOGE("receive msg failed - server disconnected");
831 recv_msg[ret] = '\0';
837 /*LOGD("recvMSg : %s, length : %d", recv_msg, ret);*/
839 /* Need to split the combined entering msgs.
840 This module supports up to 20 combined msgs. */
841 for (str_pos = 0; str_pos < ret; str_pos++) {
842 if (recv_msg[str_pos] == '}') {
843 msg_length = str_pos - prev_pos + 1;
845 if (msg_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
846 strncpy(parse_str[num_token], recv_msg + prev_pos, msg_length);
847 parse_str[num_token][msg_length] = '\0';
849 /*LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);*/
851 LOGW("too long message : length %d [%s]", msg_length, recv_msg + prev_pos);
854 prev_pos = str_pos + 1;
856 if (num_token >= RECORDER_PARSED_STRING_NUM_MAX) {
857 LOGE("There's too many tokens. Remained msg : %s", recv_msg[++str_pos]);
863 /*LOGD("num_token : %d", num_token);*/
865 /* Re-construct to the useful single msg. */
866 for (i = 0; i < num_token; i++) {
867 if (i >= RECORDER_PARSED_STRING_NUM_MAX) {
868 LOGE("invalid token index %d", i);
875 if (!muse_recorder_msg_get(api, parse_str[i])) {
876 LOGE("failed to get recorder api");
880 if (api == MUSE_RECORDER_CB_EVENT) {
881 if (!muse_recorder_msg_get(event, parse_str[i]) ||
882 !muse_recorder_msg_get(event_class, parse_str[i])) {
883 LOGE("failed to get event or event_class [%s]", parse_str[i]);
887 if (!muse_recorder_msg_get(api_class, parse_str[i])) {
888 LOGE("failed to get api_class [%s]", parse_str[i]);
893 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
894 if (api >= MUSE_RECORDER_API_MAX) {
895 LOGE("invalid api %d", api);
899 g_mutex_lock(&cb_info->api_mutex[api]);
901 if (!muse_recorder_msg_get(ret, parse_str[i])) {
902 LOGE("failed to get recorder ret");
903 g_mutex_unlock(&cb_info->api_mutex[api]);
907 cb_info->api_ret[api] = ret;
908 cb_info->api_activating[api] = 1;
910 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
911 g_atomic_int_set(&cb_info->msg_recv_running, 0);
912 LOGD("get device state done. close client cb handler");
915 case MUSE_RECORDER_API_CREATE:
916 if (ret != RECORDER_ERROR_NONE) {
917 g_atomic_int_set(&cb_info->msg_recv_running, 0);
918 LOGE("create error 0x%x. closing..", ret);
921 case MUSE_RECORDER_API_DESTROY:
922 if (ret == RECORDER_ERROR_NONE) {
923 g_atomic_int_set(&cb_info->msg_recv_running, 0);
924 LOGD("destroy done. closing..");
928 _recorder_get_api_operation(api, cb_info, parse_str[i]);
933 g_cond_signal(&cb_info->api_cond[api]);
934 g_mutex_unlock(&cb_info->api_mutex[api]);
935 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
936 __recorder_add_msg_to_queue(cb_info, api, event, event_class, parse_str[i]);
938 LOGW("unknown recorder api %d and api_class %d", api, api_class);
943 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
945 if (!cb_info->is_server_connected) {
946 /* send error msg for server disconnection */
947 error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
948 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
949 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
952 LOGE("error_msg failed");
953 goto CB_HANDLER_EXIT;
956 LOGE("add error msg for service disconnection done");
958 __recorder_add_msg_to_queue(cb_info,
959 MUSE_RECORDER_CB_EVENT,
960 MUSE_RECORDER_EVENT_TYPE_ERROR,
961 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
964 muse_core_msg_json_factory_free(error_msg);
967 LOGE("add error msg for service disconnection done");
972 for (i = 0 ; i < RECORDER_PARSED_STRING_NUM_MAX ; i++) {
987 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
988 int type, const char *thread_name, recorder_cb_info_s *cb_info)
990 if (!handler_info || !thread_name || !cb_info) {
991 LOGE("t:%d NULL %p %p %p",
992 type, handler_info, thread_name, cb_info);
998 handler_info->type = type;
999 handler_info->queue = g_queue_new();
1000 if (handler_info->queue == NULL) {
1001 LOGE("t:%d queue failed", type);
1005 g_mutex_init(&handler_info->mutex);
1006 g_cond_init(&handler_info->cond);
1008 handler_info->cb_info = (void *)cb_info;
1009 g_atomic_int_set(&handler_info->running, 1);
1011 handler_info->thread = g_thread_try_new(thread_name,
1012 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1013 if (handler_info->thread == NULL) {
1014 LOGE("t:%d thread failed", type);
1016 g_mutex_clear(&handler_info->mutex);
1017 g_cond_clear(&handler_info->cond);
1018 g_queue_free(handler_info->queue);
1019 handler_info->queue = NULL;
1024 LOGD("t:%d done", type);
1030 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1034 if (!handler_info) {
1035 LOGE("NULL handler");
1039 if (!handler_info->thread) {
1040 LOGW("thread is not created");
1044 type = handler_info->type;
1046 LOGD("t:%d thread %p", type, handler_info->thread);
1048 g_mutex_lock(&handler_info->mutex);
1049 g_atomic_int_set(&handler_info->running, 0);
1050 g_cond_signal(&handler_info->cond);
1051 g_mutex_unlock(&handler_info->mutex);
1053 g_thread_join(handler_info->thread);
1054 g_thread_unref(handler_info->thread);
1055 handler_info->thread = NULL;
1057 g_mutex_clear(&handler_info->mutex);
1058 g_cond_clear(&handler_info->cond);
1059 g_queue_free(handler_info->queue);
1060 handler_info->queue = NULL;
1062 LOGD("t:%d done", type);
1068 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd, bool need_msg_handler_thread)
1070 recorder_cb_info_s *cb_info = NULL;
1073 g_return_val_if_fail(sockfd > 0, NULL);
1075 cb_info = g_new0(recorder_cb_info_s, 1);
1076 if (cb_info == NULL) {
1077 LOGE("cb_info failed");
1081 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1082 g_mutex_init(&cb_info->api_mutex[i]);
1083 g_cond_init(&cb_info->api_cond[i]);
1086 g_mutex_init(&cb_info->idle_event_mutex);
1087 g_cond_init(&cb_info->idle_event_cond);
1089 if (need_msg_handler_thread) {
1090 /* message handler thread */
1091 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1092 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1093 LOGE("msg_handler_info failed");
1097 /* message handler thread for audio stream callback */
1098 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1099 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1100 LOGE("audio_stream_cb_info failed");
1105 cb_info->fd = sockfd;
1107 /* message receive thread */
1108 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1109 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1110 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1111 if (cb_info->msg_recv_thread == NULL) {
1112 LOGE("message receive thread creation failed");
1116 cb_info->is_server_connected = TRUE;
1122 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1123 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1125 g_mutex_clear(&cb_info->idle_event_mutex);
1126 g_cond_clear(&cb_info->idle_event_cond);
1128 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1129 g_mutex_clear(&cb_info->api_mutex[i]);
1130 g_cond_clear(&cb_info->api_cond[i]);
1140 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1142 int ret = RECORDER_ERROR_NONE;
1145 /*LOGD("Enter api : %d", api);*/
1147 if (!cb_info->is_server_connected) {
1148 LOGE("server is disconnected");
1149 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1152 g_mutex_lock(&(cb_info->api_mutex[api]));
1154 if (cb_info->api_activating[api] == 0) {
1155 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1156 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1157 ret = cb_info->api_ret[api];
1158 cb_info->api_activating[api] = 0;
1160 /*LOGD("return value : 0x%x", ret);*/
1162 ret = RECORDER_ERROR_INVALID_OPERATION;
1164 LOGE("api %d was TIMED OUT!", api);
1167 ret = cb_info->api_ret[api];
1168 cb_info->api_activating[api] = 0;
1170 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1173 if (ret != RECORDER_ERROR_NONE) {
1174 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1176 if (ret == RECORDER_ERROR_SOUND_POLICY)
1177 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1178 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1179 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1180 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1181 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1184 g_mutex_unlock(&(cb_info->api_mutex[api]));
1190 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1195 if (!cb_info || !ret) {
1196 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1197 return RECORDER_ERROR_INVALID_PARAMETER;
1200 msg = muse_core_msg_json_factory_new(api, NULL);
1202 LOGE("msg creation failed: api %d", api);
1203 return RECORDER_ERROR_OUT_OF_MEMORY;
1206 /*LOGD("send msg %s", msg);*/
1208 if (cb_info->is_server_connected)
1209 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1212 LOGE("message send failed");
1213 *ret = RECORDER_ERROR_INVALID_OPERATION;
1215 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1218 muse_core_msg_json_factory_free(msg);
1220 return RECORDER_ERROR_NONE;
1224 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1229 if (!cb_info || !ret || !param) {
1230 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1231 return RECORDER_ERROR_INVALID_PARAMETER;
1234 /*LOGD("type %d, name %s", param->type, param->name);*/
1236 switch (param->type) {
1238 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1240 case MUSE_TYPE_DOUBLE:
1241 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1243 case MUSE_TYPE_STRING:
1244 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1247 LOGE("unknown type %d", param->type);
1252 LOGE("msg creation failed: api %d, type %d, param name %s",
1253 api, param->type, param->name);
1254 return RECORDER_ERROR_OUT_OF_MEMORY;
1257 /*LOGD("send msg %s", msg);*/
1259 if (cb_info->is_server_connected)
1260 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1263 LOGE("message send failed");
1264 *ret = RECORDER_ERROR_INVALID_OPERATION;
1266 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1269 muse_core_msg_json_factory_free(msg);
1271 return RECORDER_ERROR_NONE;
1275 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1279 g_return_if_fail(cb_info != NULL);
1281 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1283 g_thread_join(cb_info->msg_recv_thread);
1284 g_thread_unref(cb_info->msg_recv_thread);
1285 cb_info->msg_recv_thread = NULL;
1287 LOGD("msg_recv thread removed");
1289 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1290 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1292 g_mutex_clear(&cb_info->idle_event_mutex);
1293 g_cond_clear(&cb_info->idle_event_cond);
1295 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1296 g_mutex_clear(&cb_info->api_mutex[i]);
1297 g_cond_clear(&cb_info->api_cond[i]);
1300 if (cb_info->fd > -1) {
1301 muse_core_connection_close(cb_info->fd);
1305 if (cb_info->bufmgr) {
1306 tbm_bufmgr_deinit(cb_info->bufmgr);
1307 cb_info->bufmgr = NULL;
1309 if (cb_info->get_filename) {
1310 free(cb_info->get_filename);
1311 cb_info->get_filename = NULL;
1321 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1323 char **root_directory = (char **)user_data;
1325 if (root_directory == NULL) {
1326 LOGE("user data is NULL");
1330 LOGD("storage id %d, type %d, state %d, path %s",
1331 storage_id, type, state, path ? path : "NULL");
1333 if (type == STORAGE_TYPE_INTERNAL && path) {
1334 if (*root_directory) {
1335 free(*root_directory);
1336 *root_directory = NULL;
1339 *root_directory = strdup(path);
1340 if (*root_directory) {
1341 LOGD("get root directory %s", *root_directory);
1344 LOGE("strdup %s failed", path);
1351 static int _recorder_client_get_root_directory(char **root_directory)
1353 int ret = STORAGE_ERROR_NONE;
1355 if (root_directory == NULL) {
1356 LOGE("user data is NULL");
1360 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1361 if (ret != STORAGE_ERROR_NONE) {
1362 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1369 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1371 int ret = RECORDER_ERROR_NONE;
1372 int destroy_ret = RECORDER_ERROR_NONE;
1375 char *send_msg = NULL;
1376 char *root_directory = NULL;
1377 intptr_t camera_handle = 0;
1378 intptr_t handle = 0;
1379 tbm_bufmgr bufmgr = NULL;
1380 recorder_cli_s *pc = NULL;
1381 recorder_msg_param param;
1383 LOGD("Enter - type %d", type);
1385 if (recorder == NULL) {
1386 LOGE("NULL pointer for recorder handle");
1387 return RECORDER_ERROR_INVALID_PARAMETER;
1390 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1391 LOGE("NULL pointer for camera handle on video recorder mode");
1392 return RECORDER_ERROR_INVALID_PARAMETER;
1395 bufmgr = tbm_bufmgr_init(-1);
1396 if (bufmgr == NULL) {
1397 LOGE("get tbm bufmgr failed");
1398 return RECORDER_ERROR_INVALID_OPERATION;
1401 pc = g_new0(recorder_cli_s, 1);
1403 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1404 goto _ERR_RECORDER_EXIT;
1407 sock_fd = muse_core_client_new();
1409 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1410 ret = RECORDER_ERROR_INVALID_OPERATION;
1411 goto _ERR_RECORDER_EXIT;
1414 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1415 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1416 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1417 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1418 MUSE_TYPE_INT, "pid", getpid(),
1421 pc->camera = camera;
1422 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1423 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1424 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1425 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1426 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1432 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1433 goto _ERR_RECORDER_EXIT;
1436 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1438 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1440 muse_core_msg_json_factory_free(send_msg);
1444 LOGE("send msg failed %d", errno);
1445 ret = RECORDER_ERROR_INVALID_OPERATION;
1446 goto _ERR_RECORDER_EXIT;
1449 pc->cb_info = _recorder_client_callback_new(sock_fd, true);
1450 if (pc->cb_info == NULL) {
1451 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1452 goto _ERR_RECORDER_EXIT;
1457 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1458 if (ret != RECORDER_ERROR_NONE) {
1459 LOGE("API_CREATE failed 0x%x", ret);
1460 goto _ERR_RECORDER_EXIT;
1463 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1465 LOGE("Receiving Handle Failed!!");
1466 ret = RECORDER_ERROR_INVALID_OPERATION;
1467 goto _ERR_RECORDER_AFTER_CREATE;
1470 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1471 LOGE("failed to get root directory of internal storage");
1472 ret = RECORDER_ERROR_INVALID_OPERATION;
1473 goto _ERR_RECORDER_AFTER_CREATE;
1476 LOGD("root directory [%s]", root_directory);
1478 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1480 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1482 if (ret != RECORDER_ERROR_NONE) {
1483 LOGE("failed to set root directory %s", root_directory);
1484 ret = RECORDER_ERROR_INVALID_OPERATION;
1485 goto _ERR_RECORDER_AFTER_CREATE;
1488 free(root_directory);
1489 root_directory = NULL;
1491 pc->remote_handle = handle;
1492 pc->cb_info->bufmgr = bufmgr;
1494 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1495 type, pc, pc->remote_handle);
1497 *recorder = (recorder_h)pc;
1501 return RECORDER_ERROR_NONE;
1503 _ERR_RECORDER_AFTER_CREATE:
1504 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1505 LOGE("destroy return 0x%x", destroy_ret);
1508 tbm_bufmgr_deinit(bufmgr);
1511 if (root_directory) {
1512 free(root_directory);
1513 root_directory = NULL;
1517 muse_core_connection_close(sock_fd);
1523 _recorder_client_callback_destroy(pc->cb_info);
1534 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1536 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1540 int recorder_create_audiorecorder(recorder_h *recorder)
1542 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1546 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1548 int ret = RECORDER_ERROR_NONE;
1549 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1550 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1552 if (!pc || !pc->cb_info) {
1553 LOGE("NULL handle");
1554 return RECORDER_ERROR_INVALID_PARAMETER;
1557 if (state == NULL) {
1558 LOGE("NULL pointer state");
1559 return RECORDER_ERROR_INVALID_PARAMETER;
1562 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1564 _recorder_msg_send(api, pc->cb_info, &ret);
1566 if (ret == RECORDER_ERROR_NONE)
1567 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1569 LOGD("ret : 0x%x, state : %d", ret, *state);
1575 int recorder_destroy(recorder_h recorder)
1577 int ret = RECORDER_ERROR_NONE;
1578 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1579 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1581 if (!pc || !pc->cb_info) {
1582 LOGE("NULL handle");
1583 return RECORDER_ERROR_INVALID_PARAMETER;
1588 if (pc->cb_info->is_server_connected)
1589 _recorder_msg_send(api, pc->cb_info, &ret);
1591 LOGW("server disconnected. release resource without send message.");
1593 if (ret == RECORDER_ERROR_NONE) {
1594 _recorder_remove_idle_event_all(pc->cb_info);
1595 _recorder_client_callback_destroy(pc->cb_info);
1600 LOGD("ret : 0x%x", ret);
1606 int recorder_prepare(recorder_h recorder)
1608 int ret = RECORDER_ERROR_NONE;
1609 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1610 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1612 if (!pc || !pc->cb_info) {
1613 LOGE("NULL handle");
1614 return RECORDER_ERROR_INVALID_PARAMETER;
1619 _recorder_msg_send(api, pc->cb_info, &ret);
1621 LOGD("ret : 0x%x", ret);
1623 if (ret == RECORDER_ERROR_NONE && pc->camera)
1624 camera_start_evas_rendering(pc->camera);
1630 int recorder_unprepare(recorder_h recorder)
1632 int ret = RECORDER_ERROR_NONE;
1633 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1634 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1635 camera_state_e camera_state = CAMERA_STATE_NONE;
1637 if (!pc || !pc->cb_info) {
1638 LOGE("NULL handle");
1639 return RECORDER_ERROR_INVALID_PARAMETER;
1645 ret = camera_get_state(pc->camera, &camera_state);
1646 if (ret != CAMERA_ERROR_NONE) {
1647 LOGE("failed to get camera state 0x%x", ret);
1648 return RECORDER_ERROR_INVALID_OPERATION;
1651 if (camera_state == CAMERA_STATE_PREVIEW) {
1652 ret = camera_stop_evas_rendering(pc->camera, false);
1653 if (ret != CAMERA_ERROR_NONE) {
1654 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1655 return RECORDER_ERROR_INVALID_OPERATION;
1660 _recorder_msg_send(api, pc->cb_info, &ret);
1662 LOGD("ret : 0x%x", ret);
1668 int recorder_start(recorder_h recorder)
1670 int ret = RECORDER_ERROR_NONE;
1671 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1672 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1673 recorder_state_e current_state = RECORDER_STATE_NONE;
1675 if (!pc || !pc->cb_info) {
1676 LOGE("NULL handle");
1677 return RECORDER_ERROR_INVALID_PARAMETER;
1683 ret = recorder_get_state(recorder, ¤t_state);
1684 if (ret != RECORDER_ERROR_NONE) {
1685 LOGE("failed to get current state 0x%x", ret);
1686 return RECORDER_ERROR_INVALID_OPERATION;
1689 if (current_state == RECORDER_STATE_READY) {
1690 ret = camera_stop_evas_rendering(pc->camera, true);
1691 if (ret != CAMERA_ERROR_NONE) {
1692 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1693 return RECORDER_ERROR_INVALID_OPERATION;
1698 _recorder_msg_send(api, pc->cb_info, &ret);
1700 if (pc->camera && current_state == RECORDER_STATE_READY)
1701 camera_start_evas_rendering(pc->camera);
1703 LOGD("ret : 0x%x", ret);
1709 int recorder_pause(recorder_h recorder)
1711 int ret = RECORDER_ERROR_NONE;
1712 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1713 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1715 if (!pc || !pc->cb_info) {
1716 LOGE("NULL handle");
1717 return RECORDER_ERROR_INVALID_PARAMETER;
1722 _recorder_msg_send(api, pc->cb_info, &ret);
1724 LOGD("ret : 0x%x", ret);
1730 int recorder_commit(recorder_h recorder)
1732 int ret = RECORDER_ERROR_NONE;
1733 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1734 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1735 recorder_state_e current_state = RECORDER_STATE_NONE;
1737 if (!pc || !pc->cb_info) {
1738 LOGE("NULL handle");
1739 return RECORDER_ERROR_INVALID_PARAMETER;
1745 ret = recorder_get_state(recorder, ¤t_state);
1746 if (ret != RECORDER_ERROR_NONE) {
1747 LOGE("failed to get current state 0x%x", ret);
1748 return RECORDER_ERROR_INVALID_OPERATION;
1751 if (current_state >= RECORDER_STATE_RECORDING) {
1752 ret = camera_stop_evas_rendering(pc->camera, true);
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 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1763 camera_start_evas_rendering(pc->camera);
1765 LOGD("ret : 0x%x", ret);
1771 int recorder_cancel(recorder_h recorder)
1773 int ret = RECORDER_ERROR_NONE;
1774 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1775 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1776 recorder_state_e current_state = RECORDER_STATE_NONE;
1778 if (!pc || !pc->cb_info) {
1779 LOGE("NULL handle");
1780 return RECORDER_ERROR_INVALID_PARAMETER;
1786 ret = recorder_get_state(recorder, ¤t_state);
1787 if (ret != RECORDER_ERROR_NONE) {
1788 LOGE("failed to get current state 0x%x", ret);
1789 return RECORDER_ERROR_INVALID_OPERATION;
1792 if (current_state >= RECORDER_STATE_RECORDING) {
1793 ret = camera_stop_evas_rendering(pc->camera, true);
1794 if (ret != CAMERA_ERROR_NONE) {
1795 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1796 return RECORDER_ERROR_INVALID_OPERATION;
1801 _recorder_msg_send(api, pc->cb_info, &ret);
1803 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1804 camera_start_evas_rendering(pc->camera);
1806 LOGD("ret : 0x%x", ret);
1812 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1814 int ret = RECORDER_ERROR_NONE;
1816 char *send_msg = NULL;
1817 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1818 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1820 if (!pc || !pc->cb_info) {
1821 LOGE("NULL handle");
1822 return RECORDER_ERROR_INVALID_PARAMETER;
1827 send_msg = muse_core_msg_json_factory_new(api,
1828 MUSE_TYPE_INT, "width", width,
1829 MUSE_TYPE_INT, "height", height,
1832 if (pc->cb_info->is_server_connected)
1833 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1836 LOGE("message send failed");
1837 ret = RECORDER_ERROR_INVALID_OPERATION;
1839 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1842 muse_core_msg_json_factory_free(send_msg);
1844 LOGE("failed to create msg");
1845 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1848 LOGD("ret : 0x%x", ret);
1854 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1856 int ret = RECORDER_ERROR_NONE;
1857 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1858 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1860 if (!pc || !pc->cb_info) {
1861 LOGE("NULL handle");
1862 return RECORDER_ERROR_INVALID_PARAMETER;
1865 if (!width || !height) {
1866 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1867 return RECORDER_ERROR_INVALID_PARAMETER;
1872 _recorder_msg_send(api, pc->cb_info, &ret);
1874 if (ret == RECORDER_ERROR_NONE) {
1875 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1876 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1879 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1885 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1886 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1888 int ret = RECORDER_ERROR_NONE;
1889 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1890 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1892 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1893 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1894 return RECORDER_ERROR_INVALID_PARAMETER;
1897 LOGD("Enter, handle :%x", pc->remote_handle);
1899 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1900 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
1902 _recorder_msg_send(api, pc->cb_info, &ret);
1904 LOGD("ret : 0x%x", ret);
1910 int recorder_get_audio_level(recorder_h recorder, double *level)
1912 int ret = RECORDER_ERROR_NONE;
1913 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
1914 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1916 if (!pc || !pc->cb_info || level == NULL) {
1917 LOGE("NULL pointer %p %p", pc, level);
1918 return RECORDER_ERROR_INVALID_PARAMETER;
1923 _recorder_msg_send(api, pc->cb_info, &ret);
1925 if (ret == RECORDER_ERROR_NONE)
1926 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
1928 LOGD("ret : 0x%x, level %lf", ret, *level);
1934 int recorder_set_filename(recorder_h recorder, const char *filename)
1936 int ret = RECORDER_ERROR_NONE;
1937 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
1938 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1939 recorder_msg_param param;
1940 char set_filename[RECORDER_FILENAME_MAX] = {0, };
1942 if (!pc || !pc->cb_info) {
1943 LOGE("NULL handle");
1944 return RECORDER_ERROR_INVALID_PARAMETER;
1947 if (filename == NULL) {
1948 LOGE("filename is NULL");
1949 return RECORDER_ERROR_INVALID_PARAMETER;
1954 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
1955 /* Cannot convert. Use original path. */
1956 strncpy(set_filename, filename, strlen(filename));
1958 /* Converted. Use converted path. */
1959 LOGD("Converted filename : %s -> %s", filename, set_filename);
1962 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
1964 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
1966 LOGD("ret : 0x%x", ret);
1972 int recorder_get_filename(recorder_h recorder, char **filename)
1974 int ret = RECORDER_ERROR_NONE;
1975 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
1976 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1977 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
1979 if (!pc || !pc->cb_info) {
1980 LOGE("NULL handle");
1981 return RECORDER_ERROR_INVALID_PARAMETER;
1984 if (filename == NULL) {
1985 LOGE("filename is NULL");
1986 return RECORDER_ERROR_INVALID_PARAMETER;
1991 _recorder_msg_send(api, pc->cb_info, &ret);
1993 if (ret == RECORDER_ERROR_NONE) {
1994 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
1995 /* Cannot convert. Use original path. */
1996 *filename = pc->cb_info->get_filename;
1998 /* Converted. Use converted path. */
1999 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2000 *filename = strdup(compat_filename);
2001 free(pc->cb_info->get_filename);
2004 pc->cb_info->get_filename = NULL;
2007 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2013 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2015 int ret = RECORDER_ERROR_NONE;
2016 int set_format = (int)format;
2017 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2018 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2019 recorder_msg_param param;
2021 if (!pc || !pc->cb_info) {
2022 LOGE("NULL handle");
2023 return RECORDER_ERROR_INVALID_PARAMETER;
2026 LOGD("ENTER, set_format : %d", set_format);
2028 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2030 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2032 LOGD("ret : 0x%x", ret);
2037 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2039 int ret = RECORDER_ERROR_NONE;
2040 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2041 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2043 if (!pc || !pc->cb_info) {
2044 LOGE("NULL handle");
2045 return RECORDER_ERROR_INVALID_PARAMETER;
2048 if (format == NULL) {
2049 LOGE("NULL pointer data");
2050 return RECORDER_ERROR_INVALID_PARAMETER;
2055 _recorder_msg_send(api, pc->cb_info, &ret);
2057 if (ret == RECORDER_ERROR_NONE)
2058 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2060 LOGD("ret : 0x%x, format %d", ret, *format);
2066 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2068 int ret = RECORDER_ERROR_NONE;
2069 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2070 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2071 bool is_available = false;
2072 int stream_index = 0;
2073 char *stream_type = NULL;
2074 char *send_msg = NULL;
2077 if (!pc || !pc->cb_info || stream_info == NULL) {
2078 LOGE("NULL handle");
2079 return RECORDER_ERROR_INVALID_PARAMETER;
2084 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2085 if (ret != SOUND_MANAGER_ERROR_NONE) {
2086 LOGE("stream info verification failed");
2087 return RECORDER_ERROR_INVALID_OPERATION;
2090 if (is_available == false) {
2091 LOGE("stream information is not available");
2092 return RECORDER_ERROR_INVALID_OPERATION;
2095 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2096 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2098 LOGD("sound manager return [0x%x]", ret);
2100 if (ret == SOUND_MANAGER_ERROR_NONE) {
2101 send_msg = muse_core_msg_json_factory_new(api,
2102 MUSE_TYPE_STRING, "stream_type", stream_type,
2103 MUSE_TYPE_INT, "stream_index", stream_index,
2106 if (pc->cb_info->is_server_connected)
2107 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2110 LOGE("message send failed");
2111 ret = RECORDER_ERROR_INVALID_OPERATION;
2113 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2116 muse_core_msg_json_factory_free(send_msg);
2118 LOGE("failed to create msg");
2119 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2122 ret = RECORDER_ERROR_INVALID_OPERATION;
2129 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
2131 int ret = RECORDER_ERROR_NONE;
2132 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2133 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2135 if (!pc || !pc->cb_info || callback == NULL) {
2136 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2137 return RECORDER_ERROR_INVALID_PARAMETER;
2140 LOGD("Enter, handle :%x", pc->remote_handle);
2142 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2143 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2145 _recorder_msg_send(api, pc->cb_info, &ret);
2147 LOGD("ret : 0x%x", ret);
2153 int recorder_unset_state_changed_cb(recorder_h recorder)
2155 int ret = RECORDER_ERROR_NONE;
2156 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2157 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2159 if (!pc || !pc->cb_info) {
2160 LOGE("NULL handle");
2161 return RECORDER_ERROR_INVALID_PARAMETER;
2166 _recorder_msg_send(api, pc->cb_info, &ret);
2168 LOGD("ret : 0x%x", ret);
2174 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2176 int ret = RECORDER_ERROR_NONE;
2177 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2178 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2180 if (!pc || !pc->cb_info || callback == NULL) {
2181 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2182 return RECORDER_ERROR_INVALID_PARAMETER;
2185 LOGD("Enter, handle :%x", pc->remote_handle);
2187 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2188 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2190 _recorder_msg_send(api, pc->cb_info, &ret);
2192 LOGD("ret : 0x%x", ret);
2198 int recorder_unset_interrupted_cb(recorder_h recorder)
2200 int ret = RECORDER_ERROR_NONE;
2201 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2202 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2204 if (!pc || !pc->cb_info) {
2205 LOGE("NULL handle");
2206 return RECORDER_ERROR_INVALID_PARAMETER;
2211 _recorder_msg_send(api, pc->cb_info, &ret);
2213 LOGD("ret : 0x%x", ret);
2219 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
2221 int ret = RECORDER_ERROR_NONE;
2222 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2223 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2225 if (!pc || !pc->cb_info || callback == NULL) {
2226 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2227 return RECORDER_ERROR_INVALID_PARAMETER;
2230 LOGD("Enter, handle :%x", pc->remote_handle);
2232 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2233 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2235 _recorder_msg_send(api, pc->cb_info, &ret);
2237 LOGD("ret : 0x%x", ret);
2243 int recorder_unset_audio_stream_cb(recorder_h recorder)
2245 int ret = RECORDER_ERROR_NONE;
2246 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2247 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2249 if (!pc || !pc->cb_info) {
2250 LOGE("NULL handle");
2251 return RECORDER_ERROR_INVALID_PARAMETER;
2256 _recorder_msg_send(api, pc->cb_info, &ret);
2258 LOGD("ret : 0x%x", ret);
2264 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2266 int ret = RECORDER_ERROR_NONE;
2267 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2268 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2270 if (!pc || !pc->cb_info || callback == NULL) {
2271 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2272 return RECORDER_ERROR_INVALID_PARAMETER;
2275 LOGD("Enter, handle :%x", pc->remote_handle);
2277 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2278 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2280 _recorder_msg_send(api, pc->cb_info, &ret);
2282 LOGD("ret : 0x%x", ret);
2288 int recorder_unset_error_cb(recorder_h recorder)
2290 int ret = RECORDER_ERROR_NONE;
2291 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2292 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2294 if (!pc || !pc->cb_info) {
2295 LOGE("NULL handle");
2296 return RECORDER_ERROR_INVALID_PARAMETER;
2301 _recorder_msg_send(api, pc->cb_info, &ret);
2303 LOGD("ret : 0x%x", ret);
2309 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
2311 int ret = RECORDER_ERROR_NONE;
2312 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2313 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2315 if (!pc || !pc->cb_info || callback == NULL) {
2316 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2317 return RECORDER_ERROR_INVALID_PARAMETER;
2320 LOGD("Enter, handle :%x", pc->remote_handle);
2322 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2323 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2325 _recorder_msg_send(api, pc->cb_info, &ret);
2327 LOGD("ret : 0x%x", ret);
2333 int recorder_unset_recording_status_cb(recorder_h recorder)
2335 int ret = RECORDER_ERROR_NONE;
2336 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2337 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2339 if (!pc || !pc->cb_info) {
2340 LOGE("NULL handle");
2341 return RECORDER_ERROR_INVALID_PARAMETER;
2346 _recorder_msg_send(api, pc->cb_info, &ret);
2348 LOGD("ret : 0x%x", ret);
2354 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
2356 int ret = RECORDER_ERROR_NONE;
2357 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2358 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2360 if (!pc || !pc->cb_info || callback == NULL) {
2361 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2362 return RECORDER_ERROR_INVALID_PARAMETER;
2365 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2366 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2368 _recorder_msg_send(api, pc->cb_info, &ret);
2370 LOGD("ret : 0x%x", ret);
2376 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2378 int ret = RECORDER_ERROR_NONE;
2379 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2380 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2382 if (!pc || !pc->cb_info) {
2383 LOGE("NULL handle");
2384 return RECORDER_ERROR_INVALID_PARAMETER;
2389 _recorder_msg_send(api, pc->cb_info, &ret);
2391 LOGD("ret : 0x%x", ret);
2397 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2399 int ret = RECORDER_ERROR_NONE;
2400 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2401 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2403 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2404 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2405 return RECORDER_ERROR_INVALID_PARAMETER;
2408 LOGD("Enter, handle :%x", pc->remote_handle);
2410 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2411 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2413 _recorder_msg_send(api, pc->cb_info, &ret);
2415 LOGD("ret : 0x%x", ret);
2421 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2423 int ret = RECORDER_ERROR_NONE;
2424 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2425 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2426 recorder_msg_param param;
2428 if (!pc || !pc->cb_info) {
2429 LOGE("NULL handle");
2430 return RECORDER_ERROR_INVALID_PARAMETER;
2435 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2437 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2439 LOGD("ret : 0x%x", ret);
2445 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2447 int ret = RECORDER_ERROR_NONE;
2448 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2449 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2450 recorder_msg_param param;
2452 if (!pc || !pc->cb_info) {
2453 LOGE("NULL handle");
2454 return RECORDER_ERROR_INVALID_PARAMETER;
2459 RECORDER_MSG_PARAM_SET(param, INT, second);
2461 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2463 LOGD("ret : 0x%x", ret);
2469 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2471 int ret = RECORDER_ERROR_NONE;
2472 int set_device = (int)device;
2473 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2474 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2475 recorder_msg_param param;
2477 if (!pc || !pc->cb_info) {
2478 LOGE("NULL handle");
2479 return RECORDER_ERROR_INVALID_PARAMETER;
2484 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2486 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2488 LOGD("ret : 0x%x", ret);
2494 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2496 int ret = RECORDER_ERROR_NONE;
2497 int set_codec = (int)codec;
2498 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2499 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2500 recorder_msg_param param;
2502 if (!pc || !pc->cb_info) {
2503 LOGE("NULL handle");
2504 return RECORDER_ERROR_INVALID_PARAMETER;
2509 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2511 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2513 LOGD("ret : 0x%x", ret);
2519 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2521 int ret = RECORDER_ERROR_NONE;
2522 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
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;
2530 if (codec == NULL) {
2531 LOGE("codec is NULL");
2532 return RECORDER_ERROR_INVALID_PARAMETER;
2537 _recorder_msg_send(api, pc->cb_info, &ret);
2539 if (ret == RECORDER_ERROR_NONE)
2540 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2542 LOGD("ret : 0x%x, codec %d", ret, *codec);
2548 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2550 int ret = RECORDER_ERROR_NONE;
2551 int set_codec = (int)codec;
2552 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2553 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2554 recorder_msg_param param;
2556 if (!pc || !pc->cb_info) {
2557 LOGE("NULL handle");
2558 return RECORDER_ERROR_INVALID_PARAMETER;
2563 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2565 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2567 LOGD("ret : 0x%x", ret);
2573 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2575 int ret = RECORDER_ERROR_NONE;
2576 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2577 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2579 if (!pc || !pc->cb_info) {
2580 LOGE("NULL handle");
2581 return RECORDER_ERROR_INVALID_PARAMETER;
2584 if (codec == NULL) {
2585 LOGE("codec is NULL");
2586 return RECORDER_ERROR_INVALID_PARAMETER;
2591 _recorder_msg_send(api, pc->cb_info, &ret);
2593 if (ret == RECORDER_ERROR_NONE)
2594 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2596 LOGD("ret : 0x%x, codec %d", ret, *codec);
2602 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2604 int ret = RECORDER_ERROR_NONE;
2605 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2606 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2607 recorder_msg_param param;
2609 if (!pc || !pc->cb_info) {
2610 LOGE("NULL handle");
2611 return RECORDER_ERROR_INVALID_PARAMETER;
2614 LOGD("ENTER, samplerate : %d", samplerate);
2616 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2618 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2620 LOGD("ret : 0x%x", ret);
2626 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2628 int ret = RECORDER_ERROR_NONE;
2629 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2630 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2631 recorder_msg_param param;
2633 if (!pc || !pc->cb_info) {
2634 LOGE("NULL handle");
2635 return RECORDER_ERROR_INVALID_PARAMETER;
2640 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2642 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2644 LOGD("ret : 0x%x", ret);
2650 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2652 int ret = RECORDER_ERROR_NONE;
2653 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2654 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2655 recorder_msg_param param;
2657 if (!pc || !pc->cb_info) {
2658 LOGE("NULL handle");
2659 return RECORDER_ERROR_INVALID_PARAMETER;
2664 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2666 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2668 LOGD("ret : 0x%x", ret);
2674 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2676 int ret = RECORDER_ERROR_NONE;
2677 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2678 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2680 if (!pc || !pc->cb_info) {
2681 LOGE("NULL handle");
2682 return RECORDER_ERROR_INVALID_PARAMETER;
2685 if (kbyte == NULL) {
2686 LOGE("NULL pointer kbyte");
2687 return RECORDER_ERROR_INVALID_PARAMETER;
2692 _recorder_msg_send(api, pc->cb_info, &ret);
2694 if (ret == RECORDER_ERROR_NONE)
2695 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2697 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2703 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2705 int ret = RECORDER_ERROR_NONE;
2706 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2707 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2709 if (!pc || !pc->cb_info) {
2710 LOGE("NULL handle");
2711 return RECORDER_ERROR_INVALID_PARAMETER;
2714 if (second == NULL) {
2715 LOGE("NULL pointer second");
2716 return RECORDER_ERROR_INVALID_PARAMETER;
2721 _recorder_msg_send(api, pc->cb_info, &ret);
2723 if (ret == RECORDER_ERROR_NONE)
2724 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2726 LOGD("ret : 0x%x, %d second", ret, *second);
2732 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2734 int ret = RECORDER_ERROR_NONE;
2735 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2736 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2738 if (!pc || !pc->cb_info) {
2739 LOGE("NULL handle");
2740 return RECORDER_ERROR_INVALID_PARAMETER;
2743 if (device == NULL) {
2744 LOGE("NULL pointer device");
2745 return RECORDER_ERROR_INVALID_PARAMETER;
2750 _recorder_msg_send(api, pc->cb_info, &ret);
2752 if (ret == RECORDER_ERROR_NONE)
2753 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2755 LOGD("ret : 0x%x, device %d", ret, *device);
2761 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2763 int ret = RECORDER_ERROR_NONE;
2764 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2765 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2767 if (!pc || !pc->cb_info) {
2768 LOGE("NULL handle");
2769 return RECORDER_ERROR_INVALID_PARAMETER;
2772 if (samplerate == NULL) {
2773 LOGE("NULL pointer handle");
2774 return RECORDER_ERROR_INVALID_PARAMETER;
2779 _recorder_msg_send(api, pc->cb_info, &ret);
2781 if (ret == RECORDER_ERROR_NONE)
2782 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
2784 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
2790 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2792 int ret = RECORDER_ERROR_NONE;
2793 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2794 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2796 if (!pc || !pc->cb_info) {
2797 LOGE("NULL handle");
2798 return RECORDER_ERROR_INVALID_PARAMETER;
2801 if (bitrate == NULL) {
2802 LOGE("NULL pointer");
2803 return RECORDER_ERROR_INVALID_PARAMETER;
2808 _recorder_msg_send(api, pc->cb_info, &ret);
2810 if (ret == RECORDER_ERROR_NONE)
2811 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
2813 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
2819 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
2821 int ret = RECORDER_ERROR_NONE;
2822 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
2823 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2825 if (!pc || !pc->cb_info) {
2826 LOGE("NULL handle");
2827 return RECORDER_ERROR_INVALID_PARAMETER;
2830 if (bitrate == NULL) {
2831 LOGE("NULL pointer");
2832 return RECORDER_ERROR_INVALID_PARAMETER;
2837 _recorder_msg_send(api, pc->cb_info, &ret);
2839 if (ret == RECORDER_ERROR_NONE)
2840 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
2842 LOGD("ret : 0x%x", ret);
2848 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
2850 int ret = RECORDER_ERROR_NONE;
2851 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2852 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
2854 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2855 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2856 return RECORDER_ERROR_INVALID_PARAMETER;
2859 LOGD("Enter, handle :%x", pc->remote_handle);
2861 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
2862 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
2864 _recorder_msg_send(api, pc->cb_info, &ret);
2866 LOGD("ret : 0x%x", ret);
2872 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
2874 int ret = RECORDER_ERROR_NONE;
2875 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2876 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
2878 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2879 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2880 return RECORDER_ERROR_INVALID_PARAMETER;
2883 LOGD("Enter, handle :%x", pc->remote_handle);
2885 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
2886 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
2888 _recorder_msg_send(api, pc->cb_info, &ret);
2890 LOGD("ret : 0x%x", ret);
2896 int recorder_attr_set_mute(recorder_h recorder, bool enable)
2898 int ret = RECORDER_ERROR_NONE;
2899 int set_enable = (int)enable;
2900 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
2901 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2902 recorder_msg_param param;
2904 if (!pc || !pc->cb_info) {
2905 LOGE("NULL handle");
2906 return RECORDER_ERROR_INVALID_PARAMETER;
2911 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
2913 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2915 LOGD("ret : 0x%x", ret);
2921 bool recorder_attr_is_muted(recorder_h recorder)
2924 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
2925 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2927 if (!pc || !pc->cb_info) {
2928 LOGE("NULL handle");
2934 _recorder_msg_send(api, pc->cb_info, &ret);
2936 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
2939 LOGD("ret : %d", ret);
2945 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
2947 int ret = RECORDER_ERROR_NONE;
2948 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
2949 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2950 recorder_msg_param param;
2952 if (!pc || !pc->cb_info) {
2953 LOGE("NULL handle");
2954 return RECORDER_ERROR_INVALID_PARAMETER;
2957 LOGD("ENTER - %.20lf", rate);
2959 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
2961 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2963 LOGD("ret : 0x%x", ret);
2969 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
2971 int ret = RECORDER_ERROR_NONE;
2972 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
2973 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2975 if (!pc || !pc->cb_info) {
2976 LOGE("NULL handle");
2977 return RECORDER_ERROR_INVALID_PARAMETER;
2981 LOGE("rate is NULL");
2982 return RECORDER_ERROR_INVALID_PARAMETER;
2987 _recorder_msg_send(api, pc->cb_info, &ret);
2988 if (ret == RECORDER_ERROR_NONE)
2989 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
2991 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
2997 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
2999 int ret = RECORDER_ERROR_NONE;
3000 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3001 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3002 recorder_msg_param param;
3004 if (!pc || !pc->cb_info) {
3005 LOGE("NULL handle");
3006 return RECORDER_ERROR_INVALID_PARAMETER;
3011 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3013 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3015 LOGD("ret : 0x%x", ret);
3021 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3023 int ret = RECORDER_ERROR_NONE;
3024 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3025 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3027 if (!pc || !pc->cb_info) {
3028 LOGE("NULL handle");
3029 return RECORDER_ERROR_INVALID_PARAMETER;
3032 if (channel_count == NULL) {
3033 LOGE("channel_count is NULL");
3034 return RECORDER_ERROR_INVALID_PARAMETER;
3039 _recorder_msg_send(api, pc->cb_info, &ret);
3041 if (ret == RECORDER_ERROR_NONE)
3042 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3044 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3050 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3052 int ret = RECORDER_ERROR_NONE;
3053 int set_orientation = (int)orientation;
3054 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3055 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3056 recorder_msg_param param;
3058 if (!pc || !pc->cb_info) {
3059 LOGE("NULL handle");
3060 return RECORDER_ERROR_INVALID_PARAMETER;
3065 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3067 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3069 LOGD("ret : 0x%x", ret);
3075 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3077 int ret = RECORDER_ERROR_NONE;
3078 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3079 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3081 if (!pc || !pc->cb_info) {
3082 LOGE("NULL handle");
3083 return RECORDER_ERROR_INVALID_PARAMETER;
3086 if (orientation == NULL) {
3087 LOGE("orientation is NULL");
3088 return RECORDER_ERROR_INVALID_PARAMETER;
3093 _recorder_msg_send(api, pc->cb_info, &ret);
3095 if (ret == RECORDER_ERROR_NONE)
3096 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3098 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3104 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3106 int ret = RECORDER_ERROR_NONE;
3108 int get_device_state = 0;
3109 char *send_msg = NULL;
3110 muse_recorder_api_e api = MUSE_RECORDER_API_GET_DEVICE_STATE;
3111 recorder_cb_info_s *cb_info = NULL;
3114 LOGE("NULL pointer");
3115 return RECORDER_ERROR_INVALID_PARAMETER;
3118 LOGD("Enter - type %d", type);
3120 sock_fd = muse_core_client_new();
3122 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3123 ret = RECORDER_ERROR_INVALID_OPERATION;
3124 goto _GET_DEVICE_STATE_EXIT;
3127 send_msg = muse_core_msg_json_factory_new(api,
3128 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3129 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3133 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3134 goto _GET_DEVICE_STATE_EXIT;
3137 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3139 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3141 muse_core_msg_json_factory_free(send_msg);
3145 LOGE("send msg failed %d", errno);
3146 ret = RECORDER_ERROR_INVALID_OPERATION;
3147 goto _GET_DEVICE_STATE_EXIT;
3150 cb_info = _recorder_client_callback_new(sock_fd, false);
3151 if (cb_info == NULL) {
3152 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3153 goto _GET_DEVICE_STATE_EXIT;
3158 ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
3159 if (ret != RECORDER_ERROR_NONE) {
3160 LOGE("API_CREATE failed 0x%x", ret);
3161 goto _GET_DEVICE_STATE_EXIT;
3164 if (ret == RECORDER_ERROR_NONE) {
3165 muse_recorder_msg_get(get_device_state, cb_info->recv_msg);
3166 *state = (recorder_device_state_e)get_device_state;
3167 LOGD("device state %d", *state);
3169 LOGE("failed 0x%x", ret);
3172 _GET_DEVICE_STATE_EXIT:
3174 _recorder_client_callback_destroy(cb_info);
3179 muse_core_connection_close(sock_fd);
3187 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3189 int ret = RECORDER_ERROR_NONE;
3190 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3191 recorder_cb_info *info = NULL;
3193 if (!callback || !cb_id) {
3194 LOGE("invalid pointer %p %p", callback, cb_id);
3195 return RECORDER_ERROR_INVALID_PARAMETER;
3198 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3200 /* check recorder support */
3201 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3202 if (ret != RECORDER_ERROR_NONE) {
3203 LOGE("get device state failed");
3204 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3208 g_rec_dev_last_state = state;
3210 info = g_new0(recorder_cb_info, 1);
3212 LOGE("info failed");
3213 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3217 info->id = ++g_rec_dev_state_changed_cb_id;
3218 info->callback = (void *)callback;
3219 info->user_data = user_data;
3223 /* subscribe dbus signal for camera state change */
3224 if (!g_rec_dev_state_changed_cb_conn) {
3225 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3226 if (!g_rec_dev_state_changed_cb_conn) {
3227 LOGE("failed to get gdbus connection");
3228 ret = RECORDER_ERROR_INVALID_OPERATION;
3232 LOGD("subscribe signal %s - %s - %s",
3233 MM_CAMCORDER_DBUS_OBJECT,
3234 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3235 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3237 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3238 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3239 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3240 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3241 LOGE("failed to get gdbus connection");
3242 ret = RECORDER_ERROR_INVALID_OPERATION;
3246 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3249 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3251 LOGD("callback id %d", info->id);
3254 if (ret != RECORDER_ERROR_NONE) {
3260 if (g_rec_dev_state_changed_cb_conn) {
3261 g_object_unref(g_rec_dev_state_changed_cb_conn);
3262 g_rec_dev_state_changed_cb_conn = NULL;
3266 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3272 int recorder_remove_device_state_changed_cb(int cb_id)
3274 int ret = RECORDER_ERROR_NONE;
3275 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3276 GList *tmp_list = NULL;
3277 recorder_cb_info *info = NULL;
3279 /* check recorder support */
3280 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3281 if (ret != RECORDER_ERROR_NONE) {
3282 LOGE("get device state failed");
3286 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3288 if (!g_rec_dev_state_changed_cb_list) {
3289 LOGE("there is no callback info");
3290 ret = RECORDER_ERROR_INVALID_OPERATION;
3294 tmp_list = g_rec_dev_state_changed_cb_list;
3297 info = tmp_list->data;
3298 tmp_list = tmp_list->next;
3305 if (info->id == cb_id) {
3306 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3311 if (!g_rec_dev_state_changed_cb_list) {
3312 /* no remained callback */
3313 if (g_rec_dev_state_changed_cb_conn) {
3314 /* unsubscribe signal */
3315 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3316 g_rec_dev_state_changed_cb_subscribe_id = 0;
3318 /* unref connection */
3319 g_object_unref(g_rec_dev_state_changed_cb_conn);
3320 g_rec_dev_state_changed_cb_conn = NULL;
3324 LOGD("id %d callback removed", cb_id);
3325 ret = RECORDER_ERROR_NONE;
3331 LOGE("id %d callback not found", cb_id);
3332 ret = RECORDER_ERROR_INVALID_PARAMETER;
3335 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);