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)
794 char *recv_msg = NULL;
795 char *error_msg = NULL;
796 char **parse_str = NULL;
797 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
799 if (cb_info == NULL) {
800 LOGE("cb_info NULL");
806 parse_str = (char **)malloc(sizeof(char *) * RECORDER_PARSE_STRING_SIZE);
807 if (parse_str == NULL) {
808 LOGE("parse_str malloc failed");
812 for (i = 0 ; i < RECORDER_PARSE_STRING_SIZE ; i++) {
813 parse_str[i] = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
814 if (parse_str[i] == NULL) {
815 LOGE("parse_str[%d] malloc failed", i);
816 goto CB_HANDLER_EXIT;
820 recv_msg = cb_info->recv_msg;
822 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
823 ret = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
825 cb_info->is_server_connected = FALSE;
826 LOGE("receive msg failed - server disconnected");
830 recv_msg[ret] = '\0';
836 /*LOGD("recvMSg : %s, length : %d", recv_msg, ret);*/
838 /* Need to split the combined entering msgs.
839 This module supports up to 200 combined msgs. */
840 for (str_pos = 0; str_pos < ret; str_pos++) {
841 if (recv_msg[str_pos] == '}') {
842 strncpy(parse_str[num_token], recv_msg + prev_pos, str_pos - prev_pos + 1);
843 /*LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);*/
844 prev_pos = str_pos+1;
849 /*LOGD("num_token : %d", num_token);*/
851 /* Re-construct to the useful single msg. */
852 for (i = 0; i < num_token; i++) {
853 if (i >= RECORDER_PARSE_STRING_SIZE) {
854 LOGE("invalid token index %d", i);
861 if (!muse_recorder_msg_get(api, parse_str[i])) {
862 LOGE("failed to get recorder api");
866 if (api == MUSE_RECORDER_CB_EVENT) {
867 if (!muse_recorder_msg_get(event, parse_str[i]) ||
868 !muse_recorder_msg_get(event_class, parse_str[i])) {
869 LOGE("failed to get event or event_class [%s]", parse_str[i]);
873 if (!muse_recorder_msg_get(api_class, parse_str[i])) {
874 LOGE("failed to get api_class [%s]", parse_str[i]);
879 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
880 if (api >= MUSE_RECORDER_API_MAX) {
881 LOGE("invalid api %d", api);
885 g_mutex_lock(&cb_info->api_mutex[api]);
887 if (!muse_recorder_msg_get(ret, parse_str[i])) {
888 LOGE("failed to get recorder ret");
889 g_mutex_unlock(&cb_info->api_mutex[api]);
893 cb_info->api_ret[api] = ret;
894 cb_info->api_activating[api] = 1;
896 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
897 g_atomic_int_set(&cb_info->msg_recv_running, 0);
898 LOGD("get device state done. close client cb handler");
901 case MUSE_RECORDER_API_CREATE:
902 if (ret != RECORDER_ERROR_NONE) {
903 g_atomic_int_set(&cb_info->msg_recv_running, 0);
904 LOGE("create error 0x%x. closing..", ret);
907 case MUSE_RECORDER_API_DESTROY:
908 if (ret == RECORDER_ERROR_NONE) {
909 g_atomic_int_set(&cb_info->msg_recv_running, 0);
910 LOGD("destroy done. closing..");
914 _recorder_get_api_operation(api, cb_info, parse_str[i]);
919 g_cond_signal(&cb_info->api_cond[api]);
920 g_mutex_unlock(&cb_info->api_mutex[api]);
921 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
922 __recorder_add_msg_to_queue(cb_info, api, event, event_class, parse_str[i]);
924 LOGW("unknown recorder api %d and api_class %d", api, api_class);
929 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
931 if (!cb_info->is_server_connected) {
932 /* send error msg for server disconnection */
933 error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
934 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
935 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
938 LOGE("error_msg failed");
939 goto CB_HANDLER_EXIT;
942 LOGE("add error msg for service disconnection done");
944 __recorder_add_msg_to_queue(cb_info,
945 MUSE_RECORDER_CB_EVENT,
946 MUSE_RECORDER_EVENT_TYPE_ERROR,
947 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
950 muse_core_msg_json_factory_free(error_msg);
953 LOGE("add error msg for service disconnection done");
958 for (i = 0 ; i < RECORDER_PARSE_STRING_SIZE ; i++) {
973 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
974 int type, const char *thread_name, recorder_cb_info_s *cb_info)
976 if (!handler_info || !thread_name || !cb_info) {
977 LOGE("t:%d NULL %p %p %p",
978 type, handler_info, thread_name, cb_info);
984 handler_info->type = type;
985 handler_info->queue = g_queue_new();
986 if (handler_info->queue == NULL) {
987 LOGE("t:%d queue failed", type);
991 g_mutex_init(&handler_info->mutex);
992 g_cond_init(&handler_info->cond);
994 handler_info->cb_info = (void *)cb_info;
995 g_atomic_int_set(&handler_info->running, 1);
997 handler_info->thread = g_thread_try_new(thread_name,
998 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
999 if (handler_info->thread == NULL) {
1000 LOGE("t:%d thread failed", type);
1002 g_mutex_clear(&handler_info->mutex);
1003 g_cond_clear(&handler_info->cond);
1004 g_queue_free(handler_info->queue);
1005 handler_info->queue = NULL;
1010 LOGD("t:%d done", type);
1016 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1020 if (!handler_info) {
1021 LOGE("NULL handler");
1025 if (!handler_info->thread) {
1026 LOGW("thread is not created");
1030 type = handler_info->type;
1032 LOGD("t:%d thread %p", type, handler_info->thread);
1034 g_mutex_lock(&handler_info->mutex);
1035 g_atomic_int_set(&handler_info->running, 0);
1036 g_cond_signal(&handler_info->cond);
1037 g_mutex_unlock(&handler_info->mutex);
1039 g_thread_join(handler_info->thread);
1040 g_thread_unref(handler_info->thread);
1041 handler_info->thread = NULL;
1043 g_mutex_clear(&handler_info->mutex);
1044 g_cond_clear(&handler_info->cond);
1045 g_queue_free(handler_info->queue);
1046 handler_info->queue = NULL;
1048 LOGD("t:%d done", type);
1054 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd, bool need_msg_handler_thread)
1056 recorder_cb_info_s *cb_info = NULL;
1059 g_return_val_if_fail(sockfd > 0, NULL);
1061 cb_info = g_new0(recorder_cb_info_s, 1);
1062 if (cb_info == NULL) {
1063 LOGE("cb_info failed");
1067 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1068 g_mutex_init(&cb_info->api_mutex[i]);
1069 g_cond_init(&cb_info->api_cond[i]);
1072 g_mutex_init(&cb_info->idle_event_mutex);
1073 g_cond_init(&cb_info->idle_event_cond);
1075 if (need_msg_handler_thread) {
1076 /* message handler thread */
1077 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1078 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1079 LOGE("msg_handler_info failed");
1083 /* message handler thread for audio stream callback */
1084 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1085 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1086 LOGE("audio_stream_cb_info failed");
1091 cb_info->fd = sockfd;
1093 /* message receive thread */
1094 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1095 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1096 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1097 if (cb_info->msg_recv_thread == NULL) {
1098 LOGE("message receive thread creation failed");
1102 cb_info->is_server_connected = TRUE;
1108 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1109 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1111 g_mutex_clear(&cb_info->idle_event_mutex);
1112 g_cond_clear(&cb_info->idle_event_cond);
1114 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1115 g_mutex_clear(&cb_info->api_mutex[i]);
1116 g_cond_clear(&cb_info->api_cond[i]);
1126 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1128 int ret = RECORDER_ERROR_NONE;
1131 /*LOGD("Enter api : %d", api);*/
1133 if (!cb_info->is_server_connected) {
1134 LOGE("server is disconnected");
1135 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1138 g_mutex_lock(&(cb_info->api_mutex[api]));
1140 if (cb_info->api_activating[api] == 0) {
1141 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1142 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1143 ret = cb_info->api_ret[api];
1144 cb_info->api_activating[api] = 0;
1146 /*LOGD("return value : 0x%x", ret);*/
1148 ret = RECORDER_ERROR_INVALID_OPERATION;
1150 LOGE("api %d was TIMED OUT!", api);
1153 ret = cb_info->api_ret[api];
1154 cb_info->api_activating[api] = 0;
1156 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1159 if (ret != RECORDER_ERROR_NONE) {
1160 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1162 if (ret == RECORDER_ERROR_SOUND_POLICY)
1163 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1164 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1165 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1166 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1167 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1170 g_mutex_unlock(&(cb_info->api_mutex[api]));
1176 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
1181 if (!cb_info || !ret) {
1182 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1183 return RECORDER_ERROR_INVALID_PARAMETER;
1186 msg = muse_core_msg_json_factory_new(api, NULL);
1188 LOGE("msg creation failed: api %d", api);
1189 return RECORDER_ERROR_OUT_OF_MEMORY;
1192 /*LOGD("send msg %s", msg);*/
1194 if (cb_info->is_server_connected)
1195 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1198 LOGE("message send failed");
1199 *ret = RECORDER_ERROR_INVALID_OPERATION;
1201 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1204 muse_core_msg_json_factory_free(msg);
1206 return RECORDER_ERROR_NONE;
1210 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1215 if (!cb_info || !ret || !param) {
1216 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1217 return RECORDER_ERROR_INVALID_PARAMETER;
1220 /*LOGD("type %d, name %s", param->type, param->name);*/
1222 switch (param->type) {
1224 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1226 case MUSE_TYPE_DOUBLE:
1227 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1229 case MUSE_TYPE_STRING:
1230 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1233 LOGE("unknown type %d", param->type);
1238 LOGE("msg creation failed: api %d, type %d, param name %s",
1239 api, param->type, param->name);
1240 return RECORDER_ERROR_OUT_OF_MEMORY;
1243 /*LOGD("send msg %s", msg);*/
1245 if (cb_info->is_server_connected)
1246 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1249 LOGE("message send failed");
1250 *ret = RECORDER_ERROR_INVALID_OPERATION;
1252 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1255 muse_core_msg_json_factory_free(msg);
1257 return RECORDER_ERROR_NONE;
1261 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1265 g_return_if_fail(cb_info != NULL);
1267 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1269 g_thread_join(cb_info->msg_recv_thread);
1270 g_thread_unref(cb_info->msg_recv_thread);
1271 cb_info->msg_recv_thread = NULL;
1273 LOGD("msg_recv thread removed");
1275 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1276 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1278 g_mutex_clear(&cb_info->idle_event_mutex);
1279 g_cond_clear(&cb_info->idle_event_cond);
1281 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1282 g_mutex_clear(&cb_info->api_mutex[i]);
1283 g_cond_clear(&cb_info->api_cond[i]);
1286 if (cb_info->fd > -1) {
1287 muse_core_connection_close(cb_info->fd);
1291 if (cb_info->bufmgr) {
1292 tbm_bufmgr_deinit(cb_info->bufmgr);
1293 cb_info->bufmgr = NULL;
1295 if (cb_info->get_filename) {
1296 free(cb_info->get_filename);
1297 cb_info->get_filename = NULL;
1307 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1309 char **root_directory = (char **)user_data;
1311 if (root_directory == NULL) {
1312 LOGE("user data is NULL");
1316 LOGD("storage id %d, type %d, state %d, path %s",
1317 storage_id, type, state, path ? path : "NULL");
1319 if (type == STORAGE_TYPE_INTERNAL && path) {
1320 if (*root_directory) {
1321 free(*root_directory);
1322 *root_directory = NULL;
1325 *root_directory = strdup(path);
1326 if (*root_directory) {
1327 LOGD("get root directory %s", *root_directory);
1330 LOGE("strdup %s failed", path);
1337 static int _recorder_client_get_root_directory(char **root_directory)
1339 int ret = STORAGE_ERROR_NONE;
1341 if (root_directory == NULL) {
1342 LOGE("user data is NULL");
1346 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1347 if (ret != STORAGE_ERROR_NONE) {
1348 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1355 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1357 int ret = RECORDER_ERROR_NONE;
1358 int destroy_ret = RECORDER_ERROR_NONE;
1361 char *send_msg = NULL;
1362 char *root_directory = NULL;
1363 intptr_t camera_handle = 0;
1364 intptr_t handle = 0;
1365 tbm_bufmgr bufmgr = NULL;
1366 recorder_cli_s *pc = NULL;
1367 recorder_msg_param param;
1369 LOGD("Enter - type %d", type);
1371 if (recorder == NULL) {
1372 LOGE("NULL pointer for recorder handle");
1373 return RECORDER_ERROR_INVALID_PARAMETER;
1376 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1377 LOGE("NULL pointer for camera handle on video recorder mode");
1378 return RECORDER_ERROR_INVALID_PARAMETER;
1381 bufmgr = tbm_bufmgr_init(-1);
1382 if (bufmgr == NULL) {
1383 LOGE("get tbm bufmgr failed");
1384 return RECORDER_ERROR_INVALID_OPERATION;
1387 pc = g_new0(recorder_cli_s, 1);
1389 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1390 goto _ERR_RECORDER_EXIT;
1393 sock_fd = muse_core_client_new();
1395 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1396 ret = RECORDER_ERROR_INVALID_OPERATION;
1397 goto _ERR_RECORDER_EXIT;
1400 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1401 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1402 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1403 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1404 MUSE_TYPE_INT, "pid", getpid(),
1407 pc->camera = camera;
1408 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1409 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1410 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1411 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1412 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1418 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1419 goto _ERR_RECORDER_EXIT;
1422 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1424 send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1426 muse_core_msg_json_factory_free(send_msg);
1430 LOGE("send msg failed %d", errno);
1431 ret = RECORDER_ERROR_INVALID_OPERATION;
1432 goto _ERR_RECORDER_EXIT;
1435 pc->cb_info = _recorder_client_callback_new(sock_fd, true);
1436 if (pc->cb_info == NULL) {
1437 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1438 goto _ERR_RECORDER_EXIT;
1443 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1444 if (ret != RECORDER_ERROR_NONE) {
1445 LOGE("API_CREATE failed 0x%x", ret);
1446 goto _ERR_RECORDER_EXIT;
1449 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1451 LOGE("Receiving Handle Failed!!");
1452 ret = RECORDER_ERROR_INVALID_OPERATION;
1453 goto _ERR_RECORDER_AFTER_CREATE;
1456 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1457 LOGE("failed to get root directory of internal storage");
1458 ret = RECORDER_ERROR_INVALID_OPERATION;
1459 goto _ERR_RECORDER_AFTER_CREATE;
1462 LOGD("root directory [%s]", root_directory);
1464 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1466 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1468 if (ret != RECORDER_ERROR_NONE) {
1469 LOGE("failed to set root directory %s", root_directory);
1470 ret = RECORDER_ERROR_INVALID_OPERATION;
1471 goto _ERR_RECORDER_AFTER_CREATE;
1474 free(root_directory);
1475 root_directory = NULL;
1477 pc->remote_handle = handle;
1478 pc->cb_info->bufmgr = bufmgr;
1480 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1481 type, pc, pc->remote_handle);
1483 *recorder = (recorder_h)pc;
1487 return RECORDER_ERROR_NONE;
1489 _ERR_RECORDER_AFTER_CREATE:
1490 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
1491 LOGE("destroy return 0x%x", destroy_ret);
1494 tbm_bufmgr_deinit(bufmgr);
1497 if (root_directory) {
1498 free(root_directory);
1499 root_directory = NULL;
1503 muse_core_connection_close(sock_fd);
1509 _recorder_client_callback_destroy(pc->cb_info);
1520 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1522 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1526 int recorder_create_audiorecorder(recorder_h *recorder)
1528 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1532 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1534 int ret = RECORDER_ERROR_NONE;
1535 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1536 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1538 if (!pc || !pc->cb_info) {
1539 LOGE("NULL handle");
1540 return RECORDER_ERROR_INVALID_PARAMETER;
1543 if (state == NULL) {
1544 LOGE("NULL pointer state");
1545 return RECORDER_ERROR_INVALID_PARAMETER;
1548 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1550 _recorder_msg_send(api, pc->cb_info, &ret);
1552 if (ret == RECORDER_ERROR_NONE)
1553 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1555 LOGD("ret : 0x%x, state : %d", ret, *state);
1561 int recorder_destroy(recorder_h recorder)
1563 int ret = RECORDER_ERROR_NONE;
1564 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1565 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1567 if (!pc || !pc->cb_info) {
1568 LOGE("NULL handle");
1569 return RECORDER_ERROR_INVALID_PARAMETER;
1574 if (pc->cb_info->is_server_connected)
1575 _recorder_msg_send(api, pc->cb_info, &ret);
1577 LOGW("server disconnected. release resource without send message.");
1579 if (ret == RECORDER_ERROR_NONE) {
1580 _recorder_remove_idle_event_all(pc->cb_info);
1581 _recorder_client_callback_destroy(pc->cb_info);
1586 LOGD("ret : 0x%x", ret);
1592 int recorder_prepare(recorder_h recorder)
1594 int ret = RECORDER_ERROR_NONE;
1595 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1596 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1598 if (!pc || !pc->cb_info) {
1599 LOGE("NULL handle");
1600 return RECORDER_ERROR_INVALID_PARAMETER;
1605 _recorder_msg_send(api, pc->cb_info, &ret);
1607 LOGD("ret : 0x%x", ret);
1609 if (ret == RECORDER_ERROR_NONE && pc->camera)
1610 camera_start_evas_rendering(pc->camera);
1616 int recorder_unprepare(recorder_h recorder)
1618 int ret = RECORDER_ERROR_NONE;
1619 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1620 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1621 camera_state_e camera_state = CAMERA_STATE_NONE;
1623 if (!pc || !pc->cb_info) {
1624 LOGE("NULL handle");
1625 return RECORDER_ERROR_INVALID_PARAMETER;
1631 ret = camera_get_state(pc->camera, &camera_state);
1632 if (ret != CAMERA_ERROR_NONE) {
1633 LOGE("failed to get camera state 0x%x", ret);
1634 return RECORDER_ERROR_INVALID_OPERATION;
1637 if (camera_state == CAMERA_STATE_PREVIEW) {
1638 ret = camera_stop_evas_rendering(pc->camera, false);
1639 if (ret != CAMERA_ERROR_NONE) {
1640 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1641 return RECORDER_ERROR_INVALID_OPERATION;
1646 _recorder_msg_send(api, pc->cb_info, &ret);
1648 LOGD("ret : 0x%x", ret);
1654 int recorder_start(recorder_h recorder)
1656 int ret = RECORDER_ERROR_NONE;
1657 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1658 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1659 recorder_state_e current_state = RECORDER_STATE_NONE;
1661 if (!pc || !pc->cb_info) {
1662 LOGE("NULL handle");
1663 return RECORDER_ERROR_INVALID_PARAMETER;
1669 ret = recorder_get_state(recorder, ¤t_state);
1670 if (ret != RECORDER_ERROR_NONE) {
1671 LOGE("failed to get current state 0x%x", ret);
1672 return RECORDER_ERROR_INVALID_OPERATION;
1675 if (current_state == RECORDER_STATE_READY) {
1676 ret = camera_stop_evas_rendering(pc->camera, true);
1677 if (ret != CAMERA_ERROR_NONE) {
1678 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1679 return RECORDER_ERROR_INVALID_OPERATION;
1684 _recorder_msg_send(api, pc->cb_info, &ret);
1686 if (pc->camera && current_state == RECORDER_STATE_READY)
1687 camera_start_evas_rendering(pc->camera);
1689 LOGD("ret : 0x%x", ret);
1695 int recorder_pause(recorder_h recorder)
1697 int ret = RECORDER_ERROR_NONE;
1698 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1699 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1701 if (!pc || !pc->cb_info) {
1702 LOGE("NULL handle");
1703 return RECORDER_ERROR_INVALID_PARAMETER;
1708 _recorder_msg_send(api, pc->cb_info, &ret);
1710 LOGD("ret : 0x%x", ret);
1716 int recorder_commit(recorder_h recorder)
1718 int ret = RECORDER_ERROR_NONE;
1719 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1720 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1721 recorder_state_e current_state = RECORDER_STATE_NONE;
1723 if (!pc || !pc->cb_info) {
1724 LOGE("NULL handle");
1725 return RECORDER_ERROR_INVALID_PARAMETER;
1731 ret = recorder_get_state(recorder, ¤t_state);
1732 if (ret != RECORDER_ERROR_NONE) {
1733 LOGE("failed to get current state 0x%x", ret);
1734 return RECORDER_ERROR_INVALID_OPERATION;
1737 if (current_state >= RECORDER_STATE_RECORDING) {
1738 ret = camera_stop_evas_rendering(pc->camera, true);
1739 if (ret != CAMERA_ERROR_NONE) {
1740 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1741 return RECORDER_ERROR_INVALID_OPERATION;
1746 _recorder_msg_send(api, pc->cb_info, &ret);
1748 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1749 camera_start_evas_rendering(pc->camera);
1751 LOGD("ret : 0x%x", ret);
1757 int recorder_cancel(recorder_h recorder)
1759 int ret = RECORDER_ERROR_NONE;
1760 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1761 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1762 recorder_state_e current_state = RECORDER_STATE_NONE;
1764 if (!pc || !pc->cb_info) {
1765 LOGE("NULL handle");
1766 return RECORDER_ERROR_INVALID_PARAMETER;
1772 ret = recorder_get_state(recorder, ¤t_state);
1773 if (ret != RECORDER_ERROR_NONE) {
1774 LOGE("failed to get current state 0x%x", ret);
1775 return RECORDER_ERROR_INVALID_OPERATION;
1778 if (current_state >= RECORDER_STATE_RECORDING) {
1779 ret = camera_stop_evas_rendering(pc->camera, true);
1780 if (ret != CAMERA_ERROR_NONE) {
1781 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1782 return RECORDER_ERROR_INVALID_OPERATION;
1787 _recorder_msg_send(api, pc->cb_info, &ret);
1789 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1790 camera_start_evas_rendering(pc->camera);
1792 LOGD("ret : 0x%x", ret);
1798 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1800 int ret = RECORDER_ERROR_NONE;
1802 char *send_msg = NULL;
1803 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1804 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1806 if (!pc || !pc->cb_info) {
1807 LOGE("NULL handle");
1808 return RECORDER_ERROR_INVALID_PARAMETER;
1813 send_msg = muse_core_msg_json_factory_new(api,
1814 MUSE_TYPE_INT, "width", width,
1815 MUSE_TYPE_INT, "height", height,
1818 if (pc->cb_info->is_server_connected)
1819 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1822 LOGE("message send failed");
1823 ret = RECORDER_ERROR_INVALID_OPERATION;
1825 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1828 muse_core_msg_json_factory_free(send_msg);
1830 LOGE("failed to create msg");
1831 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1834 LOGD("ret : 0x%x", ret);
1840 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1842 int ret = RECORDER_ERROR_NONE;
1843 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1844 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1846 if (!pc || !pc->cb_info) {
1847 LOGE("NULL handle");
1848 return RECORDER_ERROR_INVALID_PARAMETER;
1851 if (!width || !height) {
1852 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1853 return RECORDER_ERROR_INVALID_PARAMETER;
1858 _recorder_msg_send(api, pc->cb_info, &ret);
1860 if (ret == RECORDER_ERROR_NONE) {
1861 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
1862 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
1865 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
1871 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1872 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1874 int ret = RECORDER_ERROR_NONE;
1875 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1876 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1878 if (!pc || !pc->cb_info || foreach_cb == NULL) {
1879 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1880 return RECORDER_ERROR_INVALID_PARAMETER;
1883 LOGD("Enter, handle :%x", pc->remote_handle);
1885 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1886 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
1888 _recorder_msg_send(api, pc->cb_info, &ret);
1890 LOGD("ret : 0x%x", ret);
1896 int recorder_get_audio_level(recorder_h recorder, double *level)
1898 int ret = RECORDER_ERROR_NONE;
1899 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
1900 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1902 if (!pc || !pc->cb_info || level == NULL) {
1903 LOGE("NULL pointer %p %p", pc, level);
1904 return RECORDER_ERROR_INVALID_PARAMETER;
1909 _recorder_msg_send(api, pc->cb_info, &ret);
1911 if (ret == RECORDER_ERROR_NONE)
1912 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
1914 LOGD("ret : 0x%x, level %lf", ret, *level);
1920 int recorder_set_filename(recorder_h recorder, const char *filename)
1922 int ret = RECORDER_ERROR_NONE;
1923 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
1924 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1925 recorder_msg_param param;
1926 char set_filename[RECORDER_FILENAME_MAX] = {0, };
1928 if (!pc || !pc->cb_info) {
1929 LOGE("NULL handle");
1930 return RECORDER_ERROR_INVALID_PARAMETER;
1933 if (filename == NULL) {
1934 LOGE("filename is NULL");
1935 return RECORDER_ERROR_INVALID_PARAMETER;
1940 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
1941 /* Cannot convert. Use original path. */
1942 strncpy(set_filename, filename, strlen(filename));
1944 /* Converted. Use converted path. */
1945 LOGD("Converted filename : %s -> %s", filename, set_filename);
1948 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
1950 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
1952 LOGD("ret : 0x%x", ret);
1958 int recorder_get_filename(recorder_h recorder, char **filename)
1960 int ret = RECORDER_ERROR_NONE;
1961 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
1962 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1963 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
1965 if (!pc || !pc->cb_info) {
1966 LOGE("NULL handle");
1967 return RECORDER_ERROR_INVALID_PARAMETER;
1970 if (filename == NULL) {
1971 LOGE("filename is NULL");
1972 return RECORDER_ERROR_INVALID_PARAMETER;
1977 _recorder_msg_send(api, pc->cb_info, &ret);
1979 if (ret == RECORDER_ERROR_NONE) {
1980 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
1981 /* Cannot convert. Use original path. */
1982 *filename = pc->cb_info->get_filename;
1984 /* Converted. Use converted path. */
1985 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
1986 *filename = strdup(compat_filename);
1987 free(pc->cb_info->get_filename);
1990 pc->cb_info->get_filename = NULL;
1993 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
1999 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2001 int ret = RECORDER_ERROR_NONE;
2002 int set_format = (int)format;
2003 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2004 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2005 recorder_msg_param param;
2007 if (!pc || !pc->cb_info) {
2008 LOGE("NULL handle");
2009 return RECORDER_ERROR_INVALID_PARAMETER;
2012 LOGD("ENTER, set_format : %d", set_format);
2014 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2016 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2018 LOGD("ret : 0x%x", ret);
2023 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2025 int ret = RECORDER_ERROR_NONE;
2026 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2027 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2029 if (!pc || !pc->cb_info) {
2030 LOGE("NULL handle");
2031 return RECORDER_ERROR_INVALID_PARAMETER;
2034 if (format == NULL) {
2035 LOGE("NULL pointer data");
2036 return RECORDER_ERROR_INVALID_PARAMETER;
2041 _recorder_msg_send(api, pc->cb_info, &ret);
2043 if (ret == RECORDER_ERROR_NONE)
2044 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2046 LOGD("ret : 0x%x, format %d", ret, *format);
2052 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2054 int ret = RECORDER_ERROR_NONE;
2055 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2056 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2057 bool is_available = false;
2058 int stream_index = 0;
2059 char *stream_type = NULL;
2060 char *send_msg = NULL;
2063 if (!pc || !pc->cb_info || stream_info == NULL) {
2064 LOGE("NULL handle");
2065 return RECORDER_ERROR_INVALID_PARAMETER;
2070 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2071 if (ret != SOUND_MANAGER_ERROR_NONE) {
2072 LOGE("stream info verification failed");
2073 return RECORDER_ERROR_INVALID_OPERATION;
2076 if (is_available == false) {
2077 LOGE("stream information is not available");
2078 return RECORDER_ERROR_INVALID_OPERATION;
2081 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2082 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2084 LOGD("sound manager return [0x%x]", ret);
2086 if (ret == SOUND_MANAGER_ERROR_NONE) {
2087 send_msg = muse_core_msg_json_factory_new(api,
2088 MUSE_TYPE_STRING, "stream_type", stream_type,
2089 MUSE_TYPE_INT, "stream_index", stream_index,
2092 if (pc->cb_info->is_server_connected)
2093 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2096 LOGE("message send failed");
2097 ret = RECORDER_ERROR_INVALID_OPERATION;
2099 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2102 muse_core_msg_json_factory_free(send_msg);
2104 LOGE("failed to create msg");
2105 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2108 ret = RECORDER_ERROR_INVALID_OPERATION;
2115 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
2117 int ret = RECORDER_ERROR_NONE;
2118 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2119 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2121 if (!pc || !pc->cb_info || callback == NULL) {
2122 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2123 return RECORDER_ERROR_INVALID_PARAMETER;
2126 LOGD("Enter, handle :%x", pc->remote_handle);
2128 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2129 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2131 _recorder_msg_send(api, pc->cb_info, &ret);
2133 LOGD("ret : 0x%x", ret);
2139 int recorder_unset_state_changed_cb(recorder_h recorder)
2141 int ret = RECORDER_ERROR_NONE;
2142 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2143 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2145 if (!pc || !pc->cb_info) {
2146 LOGE("NULL handle");
2147 return RECORDER_ERROR_INVALID_PARAMETER;
2152 _recorder_msg_send(api, pc->cb_info, &ret);
2154 LOGD("ret : 0x%x", ret);
2160 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2162 int ret = RECORDER_ERROR_NONE;
2163 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2164 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2166 if (!pc || !pc->cb_info || callback == NULL) {
2167 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2168 return RECORDER_ERROR_INVALID_PARAMETER;
2171 LOGD("Enter, handle :%x", pc->remote_handle);
2173 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2174 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2176 _recorder_msg_send(api, pc->cb_info, &ret);
2178 LOGD("ret : 0x%x", ret);
2184 int recorder_unset_interrupted_cb(recorder_h recorder)
2186 int ret = RECORDER_ERROR_NONE;
2187 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2188 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2190 if (!pc || !pc->cb_info) {
2191 LOGE("NULL handle");
2192 return RECORDER_ERROR_INVALID_PARAMETER;
2197 _recorder_msg_send(api, pc->cb_info, &ret);
2199 LOGD("ret : 0x%x", ret);
2205 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
2207 int ret = RECORDER_ERROR_NONE;
2208 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2209 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2211 if (!pc || !pc->cb_info || callback == NULL) {
2212 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2213 return RECORDER_ERROR_INVALID_PARAMETER;
2216 LOGD("Enter, handle :%x", pc->remote_handle);
2218 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2219 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2221 _recorder_msg_send(api, pc->cb_info, &ret);
2223 LOGD("ret : 0x%x", ret);
2229 int recorder_unset_audio_stream_cb(recorder_h recorder)
2231 int ret = RECORDER_ERROR_NONE;
2232 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2233 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2235 if (!pc || !pc->cb_info) {
2236 LOGE("NULL handle");
2237 return RECORDER_ERROR_INVALID_PARAMETER;
2242 _recorder_msg_send(api, pc->cb_info, &ret);
2244 LOGD("ret : 0x%x", ret);
2250 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2252 int ret = RECORDER_ERROR_NONE;
2253 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2254 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2256 if (!pc || !pc->cb_info || callback == NULL) {
2257 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2258 return RECORDER_ERROR_INVALID_PARAMETER;
2261 LOGD("Enter, handle :%x", pc->remote_handle);
2263 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2264 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2266 _recorder_msg_send(api, pc->cb_info, &ret);
2268 LOGD("ret : 0x%x", ret);
2274 int recorder_unset_error_cb(recorder_h recorder)
2276 int ret = RECORDER_ERROR_NONE;
2277 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2278 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2280 if (!pc || !pc->cb_info) {
2281 LOGE("NULL handle");
2282 return RECORDER_ERROR_INVALID_PARAMETER;
2287 _recorder_msg_send(api, pc->cb_info, &ret);
2289 LOGD("ret : 0x%x", ret);
2295 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
2297 int ret = RECORDER_ERROR_NONE;
2298 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2299 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2301 if (!pc || !pc->cb_info || callback == NULL) {
2302 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2303 return RECORDER_ERROR_INVALID_PARAMETER;
2306 LOGD("Enter, handle :%x", pc->remote_handle);
2308 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2309 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2311 _recorder_msg_send(api, pc->cb_info, &ret);
2313 LOGD("ret : 0x%x", ret);
2319 int recorder_unset_recording_status_cb(recorder_h recorder)
2321 int ret = RECORDER_ERROR_NONE;
2322 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2323 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2325 if (!pc || !pc->cb_info) {
2326 LOGE("NULL handle");
2327 return RECORDER_ERROR_INVALID_PARAMETER;
2332 _recorder_msg_send(api, pc->cb_info, &ret);
2334 LOGD("ret : 0x%x", ret);
2340 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
2342 int ret = RECORDER_ERROR_NONE;
2343 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2344 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2346 if (!pc || !pc->cb_info || callback == NULL) {
2347 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2348 return RECORDER_ERROR_INVALID_PARAMETER;
2351 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2352 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2354 _recorder_msg_send(api, pc->cb_info, &ret);
2356 LOGD("ret : 0x%x", ret);
2362 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2364 int ret = RECORDER_ERROR_NONE;
2365 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2366 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2368 if (!pc || !pc->cb_info) {
2369 LOGE("NULL handle");
2370 return RECORDER_ERROR_INVALID_PARAMETER;
2375 _recorder_msg_send(api, pc->cb_info, &ret);
2377 LOGD("ret : 0x%x", ret);
2383 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2385 int ret = RECORDER_ERROR_NONE;
2386 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2387 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2389 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2390 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2391 return RECORDER_ERROR_INVALID_PARAMETER;
2394 LOGD("Enter, handle :%x", pc->remote_handle);
2396 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2397 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2399 _recorder_msg_send(api, pc->cb_info, &ret);
2401 LOGD("ret : 0x%x", ret);
2407 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2409 int ret = RECORDER_ERROR_NONE;
2410 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2411 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2412 recorder_msg_param param;
2414 if (!pc || !pc->cb_info) {
2415 LOGE("NULL handle");
2416 return RECORDER_ERROR_INVALID_PARAMETER;
2421 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2423 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2425 LOGD("ret : 0x%x", ret);
2431 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2433 int ret = RECORDER_ERROR_NONE;
2434 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2435 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2436 recorder_msg_param param;
2438 if (!pc || !pc->cb_info) {
2439 LOGE("NULL handle");
2440 return RECORDER_ERROR_INVALID_PARAMETER;
2445 RECORDER_MSG_PARAM_SET(param, INT, second);
2447 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2449 LOGD("ret : 0x%x", ret);
2455 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2457 int ret = RECORDER_ERROR_NONE;
2458 int set_device = (int)device;
2459 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2460 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2461 recorder_msg_param param;
2463 if (!pc || !pc->cb_info) {
2464 LOGE("NULL handle");
2465 return RECORDER_ERROR_INVALID_PARAMETER;
2470 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2472 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2474 LOGD("ret : 0x%x", ret);
2480 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2482 int ret = RECORDER_ERROR_NONE;
2483 int set_codec = (int)codec;
2484 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2485 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2486 recorder_msg_param param;
2488 if (!pc || !pc->cb_info) {
2489 LOGE("NULL handle");
2490 return RECORDER_ERROR_INVALID_PARAMETER;
2495 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2497 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2499 LOGD("ret : 0x%x", ret);
2505 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2507 int ret = RECORDER_ERROR_NONE;
2508 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2509 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2511 if (!pc || !pc->cb_info) {
2512 LOGE("NULL handle");
2513 return RECORDER_ERROR_INVALID_PARAMETER;
2516 if (codec == NULL) {
2517 LOGE("codec is NULL");
2518 return RECORDER_ERROR_INVALID_PARAMETER;
2523 _recorder_msg_send(api, pc->cb_info, &ret);
2525 if (ret == RECORDER_ERROR_NONE)
2526 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2528 LOGD("ret : 0x%x, codec %d", ret, *codec);
2534 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2536 int ret = RECORDER_ERROR_NONE;
2537 int set_codec = (int)codec;
2538 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2539 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2540 recorder_msg_param param;
2542 if (!pc || !pc->cb_info) {
2543 LOGE("NULL handle");
2544 return RECORDER_ERROR_INVALID_PARAMETER;
2549 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2551 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2553 LOGD("ret : 0x%x", ret);
2559 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2561 int ret = RECORDER_ERROR_NONE;
2562 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2563 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2565 if (!pc || !pc->cb_info) {
2566 LOGE("NULL handle");
2567 return RECORDER_ERROR_INVALID_PARAMETER;
2570 if (codec == NULL) {
2571 LOGE("codec is NULL");
2572 return RECORDER_ERROR_INVALID_PARAMETER;
2577 _recorder_msg_send(api, pc->cb_info, &ret);
2579 if (ret == RECORDER_ERROR_NONE)
2580 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2582 LOGD("ret : 0x%x, codec %d", ret, *codec);
2588 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2590 int ret = RECORDER_ERROR_NONE;
2591 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2592 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2593 recorder_msg_param param;
2595 if (!pc || !pc->cb_info) {
2596 LOGE("NULL handle");
2597 return RECORDER_ERROR_INVALID_PARAMETER;
2600 LOGD("ENTER, samplerate : %d", samplerate);
2602 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2604 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2606 LOGD("ret : 0x%x", ret);
2612 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2614 int ret = RECORDER_ERROR_NONE;
2615 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2616 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2617 recorder_msg_param param;
2619 if (!pc || !pc->cb_info) {
2620 LOGE("NULL handle");
2621 return RECORDER_ERROR_INVALID_PARAMETER;
2626 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2628 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2630 LOGD("ret : 0x%x", ret);
2636 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2638 int ret = RECORDER_ERROR_NONE;
2639 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2640 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2641 recorder_msg_param param;
2643 if (!pc || !pc->cb_info) {
2644 LOGE("NULL handle");
2645 return RECORDER_ERROR_INVALID_PARAMETER;
2650 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2652 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2654 LOGD("ret : 0x%x", ret);
2660 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2662 int ret = RECORDER_ERROR_NONE;
2663 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2664 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2666 if (!pc || !pc->cb_info) {
2667 LOGE("NULL handle");
2668 return RECORDER_ERROR_INVALID_PARAMETER;
2671 if (kbyte == NULL) {
2672 LOGE("NULL pointer kbyte");
2673 return RECORDER_ERROR_INVALID_PARAMETER;
2678 _recorder_msg_send(api, pc->cb_info, &ret);
2680 if (ret == RECORDER_ERROR_NONE)
2681 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
2683 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
2689 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2691 int ret = RECORDER_ERROR_NONE;
2692 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2693 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2695 if (!pc || !pc->cb_info) {
2696 LOGE("NULL handle");
2697 return RECORDER_ERROR_INVALID_PARAMETER;
2700 if (second == NULL) {
2701 LOGE("NULL pointer second");
2702 return RECORDER_ERROR_INVALID_PARAMETER;
2707 _recorder_msg_send(api, pc->cb_info, &ret);
2709 if (ret == RECORDER_ERROR_NONE)
2710 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
2712 LOGD("ret : 0x%x, %d second", ret, *second);
2718 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2720 int ret = RECORDER_ERROR_NONE;
2721 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2722 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2724 if (!pc || !pc->cb_info) {
2725 LOGE("NULL handle");
2726 return RECORDER_ERROR_INVALID_PARAMETER;
2729 if (device == NULL) {
2730 LOGE("NULL pointer device");
2731 return RECORDER_ERROR_INVALID_PARAMETER;
2736 _recorder_msg_send(api, pc->cb_info, &ret);
2738 if (ret == RECORDER_ERROR_NONE)
2739 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
2741 LOGD("ret : 0x%x, device %d", ret, *device);
2747 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2749 int ret = RECORDER_ERROR_NONE;
2750 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2751 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2753 if (!pc || !pc->cb_info) {
2754 LOGE("NULL handle");
2755 return RECORDER_ERROR_INVALID_PARAMETER;
2758 if (samplerate == NULL) {
2759 LOGE("NULL pointer handle");
2760 return RECORDER_ERROR_INVALID_PARAMETER;
2765 _recorder_msg_send(api, pc->cb_info, &ret);
2767 if (ret == RECORDER_ERROR_NONE)
2768 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
2770 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
2776 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2778 int ret = RECORDER_ERROR_NONE;
2779 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2780 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2782 if (!pc || !pc->cb_info) {
2783 LOGE("NULL handle");
2784 return RECORDER_ERROR_INVALID_PARAMETER;
2787 if (bitrate == NULL) {
2788 LOGE("NULL pointer");
2789 return RECORDER_ERROR_INVALID_PARAMETER;
2794 _recorder_msg_send(api, pc->cb_info, &ret);
2796 if (ret == RECORDER_ERROR_NONE)
2797 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
2799 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
2805 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
2807 int ret = RECORDER_ERROR_NONE;
2808 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
2809 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2811 if (!pc || !pc->cb_info) {
2812 LOGE("NULL handle");
2813 return RECORDER_ERROR_INVALID_PARAMETER;
2816 if (bitrate == NULL) {
2817 LOGE("NULL pointer");
2818 return RECORDER_ERROR_INVALID_PARAMETER;
2823 _recorder_msg_send(api, pc->cb_info, &ret);
2825 if (ret == RECORDER_ERROR_NONE)
2826 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
2828 LOGD("ret : 0x%x", ret);
2834 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
2836 int ret = RECORDER_ERROR_NONE;
2837 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2838 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
2840 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2841 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2842 return RECORDER_ERROR_INVALID_PARAMETER;
2845 LOGD("Enter, handle :%x", pc->remote_handle);
2847 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
2848 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
2850 _recorder_msg_send(api, pc->cb_info, &ret);
2852 LOGD("ret : 0x%x", ret);
2858 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
2860 int ret = RECORDER_ERROR_NONE;
2861 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2862 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
2864 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2865 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2866 return RECORDER_ERROR_INVALID_PARAMETER;
2869 LOGD("Enter, handle :%x", pc->remote_handle);
2871 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
2872 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
2874 _recorder_msg_send(api, pc->cb_info, &ret);
2876 LOGD("ret : 0x%x", ret);
2882 int recorder_attr_set_mute(recorder_h recorder, bool enable)
2884 int ret = RECORDER_ERROR_NONE;
2885 int set_enable = (int)enable;
2886 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
2887 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2888 recorder_msg_param param;
2890 if (!pc || !pc->cb_info) {
2891 LOGE("NULL handle");
2892 return RECORDER_ERROR_INVALID_PARAMETER;
2897 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
2899 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2901 LOGD("ret : 0x%x", ret);
2907 bool recorder_attr_is_muted(recorder_h recorder)
2910 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
2911 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2913 if (!pc || !pc->cb_info) {
2914 LOGE("NULL handle");
2920 _recorder_msg_send(api, pc->cb_info, &ret);
2922 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
2925 LOGD("ret : %d", ret);
2931 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
2933 int ret = RECORDER_ERROR_NONE;
2934 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
2935 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2936 recorder_msg_param param;
2938 if (!pc || !pc->cb_info) {
2939 LOGE("NULL handle");
2940 return RECORDER_ERROR_INVALID_PARAMETER;
2943 LOGD("ENTER - %.20lf", rate);
2945 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
2947 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2949 LOGD("ret : 0x%x", ret);
2955 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
2957 int ret = RECORDER_ERROR_NONE;
2958 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
2959 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2961 if (!pc || !pc->cb_info) {
2962 LOGE("NULL handle");
2963 return RECORDER_ERROR_INVALID_PARAMETER;
2967 LOGE("rate is NULL");
2968 return RECORDER_ERROR_INVALID_PARAMETER;
2973 _recorder_msg_send(api, pc->cb_info, &ret);
2974 if (ret == RECORDER_ERROR_NONE)
2975 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
2977 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
2983 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
2985 int ret = RECORDER_ERROR_NONE;
2986 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
2987 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2988 recorder_msg_param param;
2990 if (!pc || !pc->cb_info) {
2991 LOGE("NULL handle");
2992 return RECORDER_ERROR_INVALID_PARAMETER;
2997 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
2999 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3001 LOGD("ret : 0x%x", ret);
3007 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3009 int ret = RECORDER_ERROR_NONE;
3010 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3011 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3013 if (!pc || !pc->cb_info) {
3014 LOGE("NULL handle");
3015 return RECORDER_ERROR_INVALID_PARAMETER;
3018 if (channel_count == NULL) {
3019 LOGE("channel_count is NULL");
3020 return RECORDER_ERROR_INVALID_PARAMETER;
3025 _recorder_msg_send(api, pc->cb_info, &ret);
3027 if (ret == RECORDER_ERROR_NONE)
3028 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3030 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3036 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3038 int ret = RECORDER_ERROR_NONE;
3039 int set_orientation = (int)orientation;
3040 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3041 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3042 recorder_msg_param param;
3044 if (!pc || !pc->cb_info) {
3045 LOGE("NULL handle");
3046 return RECORDER_ERROR_INVALID_PARAMETER;
3051 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3053 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3055 LOGD("ret : 0x%x", ret);
3061 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3063 int ret = RECORDER_ERROR_NONE;
3064 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3065 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3067 if (!pc || !pc->cb_info) {
3068 LOGE("NULL handle");
3069 return RECORDER_ERROR_INVALID_PARAMETER;
3072 if (orientation == NULL) {
3073 LOGE("orientation is NULL");
3074 return RECORDER_ERROR_INVALID_PARAMETER;
3079 _recorder_msg_send(api, pc->cb_info, &ret);
3081 if (ret == RECORDER_ERROR_NONE)
3082 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3084 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3090 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3092 int ret = RECORDER_ERROR_NONE;
3094 int get_device_state = 0;
3095 char *send_msg = NULL;
3096 muse_recorder_api_e api = MUSE_RECORDER_API_GET_DEVICE_STATE;
3097 recorder_cb_info_s *cb_info = NULL;
3100 LOGE("NULL pointer");
3101 return RECORDER_ERROR_INVALID_PARAMETER;
3104 LOGD("Enter - type %d", type);
3106 sock_fd = muse_core_client_new();
3108 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3109 ret = RECORDER_ERROR_INVALID_OPERATION;
3110 goto _GET_DEVICE_STATE_EXIT;
3113 send_msg = muse_core_msg_json_factory_new(api,
3114 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3115 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3119 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3120 goto _GET_DEVICE_STATE_EXIT;
3123 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3125 ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3127 muse_core_msg_json_factory_free(send_msg);
3131 LOGE("send msg failed %d", errno);
3132 ret = RECORDER_ERROR_INVALID_OPERATION;
3133 goto _GET_DEVICE_STATE_EXIT;
3136 cb_info = _recorder_client_callback_new(sock_fd, false);
3137 if (cb_info == NULL) {
3138 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3139 goto _GET_DEVICE_STATE_EXIT;
3144 ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
3145 if (ret != RECORDER_ERROR_NONE) {
3146 LOGE("API_CREATE failed 0x%x", ret);
3147 goto _GET_DEVICE_STATE_EXIT;
3150 if (ret == RECORDER_ERROR_NONE) {
3151 muse_recorder_msg_get(get_device_state, cb_info->recv_msg);
3152 *state = (recorder_device_state_e)get_device_state;
3153 LOGD("device state %d", *state);
3155 LOGE("failed 0x%x", ret);
3158 _GET_DEVICE_STATE_EXIT:
3160 _recorder_client_callback_destroy(cb_info);
3165 muse_core_connection_close(sock_fd);
3173 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3175 int ret = RECORDER_ERROR_NONE;
3176 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3177 recorder_cb_info *info = NULL;
3179 if (!callback || !cb_id) {
3180 LOGE("invalid pointer %p %p", callback, cb_id);
3181 return RECORDER_ERROR_INVALID_PARAMETER;
3184 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3186 /* check recorder support */
3187 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3188 if (ret != RECORDER_ERROR_NONE) {
3189 LOGE("get device state failed");
3190 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3194 g_rec_dev_last_state = state;
3196 info = g_new0(recorder_cb_info, 1);
3198 LOGE("info failed");
3199 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3203 info->id = ++g_rec_dev_state_changed_cb_id;
3204 info->callback = (void *)callback;
3208 /* subscribe dbus signal for camera state change */
3209 if (!g_rec_dev_state_changed_cb_conn) {
3210 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3211 if (!g_rec_dev_state_changed_cb_conn) {
3212 LOGE("failed to get gdbus connection");
3213 ret = RECORDER_ERROR_INVALID_OPERATION;
3217 LOGD("subscribe signal %s - %s - %s",
3218 MM_CAMCORDER_DBUS_OBJECT,
3219 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3220 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3222 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3223 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3224 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3225 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3226 LOGE("failed to get gdbus connection");
3227 ret = RECORDER_ERROR_INVALID_OPERATION;
3231 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3234 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3236 LOGD("callback id %d", info->id);
3239 if (ret != RECORDER_ERROR_NONE) {
3245 if (g_rec_dev_state_changed_cb_conn) {
3246 g_object_unref(g_rec_dev_state_changed_cb_conn);
3247 g_rec_dev_state_changed_cb_conn = NULL;
3251 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3257 int recorder_remove_device_state_changed_cb(int cb_id)
3259 int ret = RECORDER_ERROR_NONE;
3260 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3261 GList *tmp_list = NULL;
3262 recorder_cb_info *info = NULL;
3264 /* check recorder support */
3265 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3266 if (ret != RECORDER_ERROR_NONE) {
3267 LOGE("get device state failed");
3271 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3273 if (!g_rec_dev_state_changed_cb_list) {
3274 LOGE("there is no callback info");
3275 ret = RECORDER_ERROR_INVALID_OPERATION;
3279 tmp_list = g_rec_dev_state_changed_cb_list;
3282 info = tmp_list->data;
3283 tmp_list = tmp_list->next;
3290 if (info->id == cb_id) {
3291 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3296 if (!g_rec_dev_state_changed_cb_list) {
3297 /* no remained callback */
3298 if (g_rec_dev_state_changed_cb_conn) {
3299 /* unsubscribe signal */
3300 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3301 g_rec_dev_state_changed_cb_subscribe_id = 0;
3303 /* unref connection */
3304 g_object_unref(g_rec_dev_state_changed_cb_conn);
3305 g_rec_dev_state_changed_cb_conn = NULL;
3309 LOGD("id %d callback removed", cb_id);
3310 ret = RECORDER_ERROR_NONE;
3316 LOGE("id %d callback not found", cb_id);
3317 ret = RECORDER_ERROR_INVALID_PARAMETER;
3320 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);