#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <inttypes.h>
#include <camera_internal.h>
#include <recorder.h>
#include <sound_manager.h>
#include <storage-internal.h>
#include <muse_recorder.h>
#include <muse_recorder_msg.h>
-#include <muse_core_ipc.h>
-#include <muse_core_module.h>
+#include <muse_core.h>
+#include <muse_client.h>
#include <recorder_private.h>
-#include <glib.h>
#include <gio/gio.h>
#include <dlog.h>
#include <tzplatform_config.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
-#define LOG_TAG "TIZEN_N_RECORDER"
+#define LOG_TAG "TIZEN_N_RECORDER"
+#define MODULE_NAME "recorder"
/* for device changed callback */
static GMutex g_rec_dev_state_changed_cb_lock;
static int g_rec_dev_state_changed_cb_id;
static GDBusConnection *g_rec_dev_state_changed_cb_conn;
static guint g_rec_dev_state_changed_cb_subscribe_id;
+static GMutex g_rec_idle_event_lock;
+
+
+
+static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
+{
+ if (!cb_info ||
+ api < 0 || api >= MUSE_RECORDER_API_MAX) {
+ LOGE("invalid param %p %d", cb_info, api);
+ return;
+ }
+
+ g_mutex_lock(&(cb_info->api_mutex[api]));
+ cb_info->api_waiting[api] += value;
+ g_mutex_unlock(&(cb_info->api_mutex[api]));
+
+ /*LOGD("api %d, value %d, waiting %d",
+ api, value, cb_info->api_waiting[api]);*/
+
+ return;
+}
static void __recorder_device_state_changed_cb(GDBusConnection *connection,
}
-static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
+static int _recorder_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
{
tbm_bo tmp_bo = NULL;
tbm_bo_handle tmp_bo_handle = {NULL, };
- if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
- LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
- bufmgr, bo, bo_handle, tbm_key);
+ if (bufmgr == NULL || bo == NULL || bo_handle == NULL || fd < 0) {
+ LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, fd %d",
+ bufmgr, bo, bo_handle, fd);
return false;
}
- tmp_bo = tbm_bo_import(bufmgr, tbm_key);
+ tmp_bo = tbm_bo_import_fd(bufmgr, (tbm_fd)fd);
if (tmp_bo == NULL) {
- LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
+ LOGE("bo import failed - bufmgr %p, fd %d", bufmgr, fd);
return false;
}
return;
}
-static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
+static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event, int tfd)
{
if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
/*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
+ g_mutex_lock(&cb_info->user_cb_mutex[event]);
+
if (cb_info->user_cb[event] == NULL) {
- LOGW("user callback for event %d is not set", event);
- return;
+ if (event != MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM &&
+ event != MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM) {
+ g_mutex_unlock(&cb_info->user_cb_mutex[event]);
+ LOGW("NULL callback for event %d, return here", event);
+ return;
+ } else {
+ LOGW("NULL callback for event %d, NOT return here", event);
+ }
}
switch (event) {
int64_t cb_elapsed_time = 0;
int64_t cb_file_size = 0;
- muse_recorder_msg_get(cb_elapsed_time, recv_msg);
- muse_recorder_msg_get(cb_file_size, recv_msg);
+ muse_recorder_msg_get_int64(cb_elapsed_time, recv_msg);
+ muse_recorder_msg_get_int64(cb_file_size, recv_msg);
((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
(unsigned long long)cb_file_size,
muse_recorder_msg_get(previous, recv_msg);
muse_recorder_msg_get(current, recv_msg);
- if (policy == RECORDER_POLICY_SOUND)
- LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
- else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
- LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
- else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
- LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
+ LOGW("INTERRUPTED - policy %d, state %d -> %d", policy, previous, current);
((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
(recorder_state_e)previous,
cb_info->user_data[event]);
break;
}
+ case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
+ {
+ int policy = 0;
+ int state = 0;
+
+ muse_recorder_msg_get(policy, recv_msg);
+ muse_recorder_msg_get(state, recv_msg);
+
+ LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
+
+ ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
+ (recorder_state_e)state, cb_info->user_data[event]);
+ }
+ break;
case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
{
- int tbm_key = 0;
+ int audio_fd = -1;
int size = 0;
int format = 0;
int channel = 0;
tbm_bo_handle bo_handle = {.ptr = NULL};
char *send_msg = NULL;
- muse_recorder_msg_get(tbm_key, recv_msg);
- if (tbm_key == 0) {
- LOGE("invalid key");
+ if (tfd < 0) {
+ LOGE("invalid fd %d", tfd);
break;
}
- if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
- LOGE("tbm key %d import failed", tbm_key);
+ muse_recorder_msg_get(audio_fd, recv_msg);
+
+ if (cb_info->user_cb[event]) {
+ if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd, &bo, &bo_handle)) {
+ muse_recorder_msg_get(size, recv_msg);
+ muse_recorder_msg_get(format, recv_msg);
+ muse_recorder_msg_get(channel, recv_msg);
+ muse_recorder_msg_get(timestamp, recv_msg);
+
+ LOGD("%p, size %d, format %d, channel %d, timestamp %d",
+ bo_handle.ptr, size, format, channel, timestamp);
+
+ ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
+ size, (audio_sample_type_e)format, channel,
+ (unsigned int)timestamp, cb_info->user_data[event]);
+
+ LOGD("returned");
+
+ /* release imported bo */
+ _recorder_release_imported_bo(&bo);
+ } else {
+ LOGE("tbm fd %d import failed", tfd);
+ }
+ }
+
+ /* return buffer */
+ send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
+ MUSE_TYPE_INT, "ret_fd", audio_fd, NULL);
+
+ if (send_msg) {
+ if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
+ LOGE("sending message failed");
+
+ muse_core_msg_free(send_msg);
+ send_msg = NULL;
+ } else {
+ LOGE("failed to create send msg for fd %d", audio_fd);
+ }
+
+ /* close imported fd */
+ close(tfd);
+ tfd = -1;
+ break;
+ }
+ case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
+ {
+ int muxed_fd = -1;
+ int size = 0;
+ int64_t offset = 0;
+
+ tbm_bo bo = NULL;
+ tbm_bo_handle bo_handle = {.ptr = NULL};
+ char *send_msg = NULL;
+
+ if (tfd < 0) {
+ LOGE("invalid fd %d", tfd);
break;
}
- muse_recorder_msg_get(size, recv_msg);
- muse_recorder_msg_get(format, recv_msg);
- muse_recorder_msg_get(channel, recv_msg);
- muse_recorder_msg_get(timestamp, recv_msg);
-
- ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
- size,
- (audio_sample_type_e)format,
- channel,
- (unsigned int)timestamp,
- cb_info->user_data[event]);
+ muse_recorder_msg_get(muxed_fd, recv_msg);
- /* release imported bo */
- _recorder_release_imported_bo(&bo);
+ if (cb_info->user_cb[event]) {
+ if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd, &bo, &bo_handle)) {
+ muse_recorder_msg_get(size, recv_msg);
+ muse_recorder_msg_get_int64(offset, recv_msg);
- /* return buffer */
- send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
- MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
+ LOGD("%p, size %d, offset %"PRId64, bo_handle.ptr, size, offset);
+
+ ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
+ size, (unsigned long long)offset, cb_info->user_data[event]);
+
+ LOGD("returned");
+
+ /* release imported bo */
+ _recorder_release_imported_bo(&bo);
+ } else {
+ LOGE("tbm fd %d import failed", tfd);
+ }
+ }
- if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
- LOGE("sending message failed");
+ /* return buffer */
+ send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
+ MUSE_TYPE_INT, "ret_fd", muxed_fd, NULL);
+ if (send_msg) {
+ if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
+ LOGE("sending message failed");
+
+ muse_core_msg_free(send_msg);
+ send_msg = NULL;
+ } else {
+ LOGE("failed to create send msg for fd %d", tfd);
+ }
- muse_core_msg_json_factory_free(send_msg);
+ /* close imported fd */
+ close(tfd);
+ tfd = -1;
break;
}
+//LCOV_EXCL_START
case MUSE_RECORDER_EVENT_TYPE_ERROR:
{
int error = 0;
muse_recorder_msg_get(error, recv_msg);
muse_recorder_msg_get(current_state, recv_msg);
- if (error == RECORDER_ERROR_SOUND_POLICY)
- LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
- else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
- LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
- else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
- LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
-
((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
(recorder_state_e)current_state,
cb_info->user_data[event]);
break;
}
+//LCOV_EXCL_STOP
case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
{
int codec = 0;
}
break;
}
- case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION:
+ default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
{
int width = 0;
int height = 0;
}
break;
}
-
- default:
- LOGE("Unknonw recorder event %d", event);
- break;
}
+ g_mutex_unlock(&cb_info->user_cb_mutex[event]);
+
return;
}
-static bool _recorder_idle_event_callback(void *data)
+static gboolean _recorder_idle_event_callback(gpointer data)
{
recorder_cb_info_s *cb_info = NULL;
recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
if (rec_idle_event == NULL) {
LOGE("rec_idle_event is NULL");
- return false;
+ return FALSE;
}
/* lock event */
- g_mutex_lock(&rec_idle_event->event_mutex);
+ g_mutex_lock(&g_rec_idle_event_lock);
cb_info = rec_idle_event->cb_info;
if (cb_info == NULL) {
- LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
+ LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
+ g_mutex_unlock(&g_rec_idle_event_lock);
goto IDLE_EVENT_CALLBACK_DONE;
}
/* remove event from list */
- g_mutex_lock(&cb_info->idle_event_mutex);
if (cb_info->idle_event_list)
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
- /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_rec_idle_event_lock);
/* user callback */
- _recorder_client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
-
- /* send signal for waiting thread */
- g_cond_signal(&cb_info->idle_event_cond);
+ _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event, -1);
IDLE_EVENT_CALLBACK_DONE:
- /* unlock and release event */
- g_mutex_unlock(&rec_idle_event->event_mutex);
- g_mutex_clear(&rec_idle_event->event_mutex);
-
+ /* release event */
g_free(rec_idle_event);
rec_idle_event = NULL;
- return false;
+ return FALSE;
}
-static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
+static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
{
recorder_idle_event_s *rec_idle_event = NULL;
- gboolean ret = true;
GList *list = NULL;
- gint64 end_time = 0;
if (cb_info == NULL) {
LOGE("cb_info is NULL");
return;
}
- g_mutex_lock(&cb_info->idle_event_mutex);
+ g_mutex_lock(&g_rec_idle_event_lock);
if (cb_info->idle_event_list == NULL) {
LOGD("No event");
continue;
}
- if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
- LOGW("lock failed");
+ if (g_idle_remove_by_data(rec_idle_event)) {
+ LOGW("remove idle event %p done", rec_idle_event);
- end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
+ cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
- if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
- LOGW("signal received");
- else
- LOGW("timeout");
+ g_free(rec_idle_event);
+ rec_idle_event = NULL;
continue;
}
- ret = g_idle_remove_by_data(rec_idle_event);
+ LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
+ rec_idle_event, rec_idle_event->event);
- LOGD("remove event %p, ret %d", rec_idle_event, ret);
-
- if (!ret) {
- rec_idle_event->cb_info = NULL;
- LOGW("idle cb for event %p will be called later", rec_idle_event);
- }
+ rec_idle_event->cb_info = NULL;
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
-
- g_mutex_unlock(&rec_idle_event->event_mutex);
-
- if (ret) {
- g_mutex_clear(&rec_idle_event->event_mutex);
-
- g_free(rec_idle_event);
- rec_idle_event = NULL;
-
- LOGD("remove event done");
- }
}
g_list_free(cb_info->idle_event_list);
cb_info->idle_event_list = NULL;
}
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_rec_idle_event_lock);
return;
}
-static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
+static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg, int tfd)
{
recorder_message_s *rec_msg = NULL;
+ recorder_msg_handler_info_s *msg_handler_info = NULL;
if (!cb_info || !msg) {
LOGE("NULL pointer %p %p", cb_info, msg);
rec_msg->api = api;
rec_msg->event = event;
rec_msg->event_class = event_class;
+ rec_msg->tfd = tfd;
strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
/*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
- if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
- g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
- g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
- g_cond_signal(&cb_info->audio_stream_cb_info.cond);
- g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
- } else {
- g_mutex_lock(&cb_info->msg_handler_info.mutex);
- g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
- g_cond_signal(&cb_info->msg_handler_info.cond);
- g_mutex_unlock(&cb_info->msg_handler_info.mutex);
- }
+ if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
+ msg_handler_info = &cb_info->audio_stream_cb_info;
+ else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
+ msg_handler_info = &cb_info->muxed_stream_cb_info;
+ else
+ msg_handler_info = &cb_info->msg_handler_info;
+
+ g_mutex_lock(&msg_handler_info->mutex);
+ g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
+ g_cond_signal(&msg_handler_info->cond);
+ g_mutex_unlock(&msg_handler_info->mutex);
rec_msg = NULL;
}
-static void *_recorder_msg_handler_func(gpointer data)
-{
- int api = 0;
- int type = 0;
- recorder_message_s *rec_msg = NULL;
- recorder_idle_event_s *rec_idle_event = NULL;
- recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
- recorder_cb_info_s *cb_info = NULL;
-
- if (!handler_info || !handler_info->cb_info) {
- LOGE("NULL handler %p", handler_info);
- return NULL;
- }
-
- cb_info = (recorder_cb_info_s *)handler_info->cb_info;
- type = handler_info->type;
-
- LOGD("t:%d start", type);
-
- g_mutex_lock(&handler_info->mutex);
-
- while (g_atomic_int_get(&handler_info->running)) {
- if (g_queue_is_empty(handler_info->queue)) {
- /*LOGD("signal wait...");*/
- g_cond_wait(&handler_info->cond, &handler_info->mutex);
- /*LOGD("signal received");*/
-
- if (g_atomic_int_get(&handler_info->running) == 0) {
- LOGD("stop event thread");
- break;
- }
- }
-
- rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
- g_mutex_unlock(&handler_info->mutex);
- if (rec_msg == NULL) {
- LOGE("NULL message");
- g_mutex_lock(&handler_info->mutex);
- continue;
- }
-
- api = rec_msg->api;
-
- if (api < MUSE_RECORDER_API_MAX) {
- int ret = 0;
-
- g_mutex_lock(&cb_info->api_mutex[api]);
-
- if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
- cb_info->api_ret[api] = ret;
- cb_info->api_activating[api] = 1;
-
- /*LOGD("recorder api %d - return 0x%x", ret);*/
-
- g_cond_signal(&cb_info->api_cond[api]);
- } else {
- LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
- }
-
- g_mutex_unlock(&cb_info->api_mutex[api]);
- } else if (api == MUSE_RECORDER_CB_EVENT) {
- switch (rec_msg->event_class) {
- case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
- _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
- break;
- case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
- rec_idle_event = g_new0(recorder_idle_event_s, 1);
- if (rec_idle_event == NULL) {
- LOGE("event alloc failed");
- break;
- }
-
- rec_idle_event->event = rec_msg->event;
- rec_idle_event->cb_info = cb_info;
- g_mutex_init(&rec_idle_event->event_mutex);
- strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
-
- /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
-
- g_mutex_lock(&cb_info->idle_event_mutex);
- cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
- g_mutex_unlock(&cb_info->idle_event_mutex);
-
- g_idle_add_full(G_PRIORITY_DEFAULT,
- (GSourceFunc)_recorder_idle_event_callback,
- (gpointer)rec_idle_event,
- NULL);
- break;
- default:
- LOGE("unknown event class %d", rec_msg->event_class);
- break;
- }
- } else {
- LOGE("unknown api[%d] message", api);
- }
-
- g_free(rec_msg);
- rec_msg = NULL;
-
- g_mutex_lock(&handler_info->mutex);
- }
-
- /* remove remained event */
- while (!g_queue_is_empty(handler_info->queue)) {
- rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
- if (rec_msg) {
- LOGD("remove message %p", rec_msg);
- free(rec_msg);
- rec_msg = NULL;
- } else {
- LOGW("NULL message");
- }
- }
-
- g_mutex_unlock(&handler_info->mutex);
-
- LOGD("return");
-
- return NULL;
-}
-
-
-static void _recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
+static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
{
if (!cb_info || !msg) {
LOGE("NULL pointer %p %p", cb_info, msg);
}
cb_info->get_filename = strdup(get_filename);
}
- break;
- default:
- break;
+ break;
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg, int tfd)
+{
+ int ret = RECORDER_ERROR_NONE;
+ int api = -1;
+ int api_class = -1;
+ int event = -1;
+ int event_class = -1;
+
+ if (!cb_info || !msg) {
+ LOGE("invalid ptr %p %p", cb_info, msg);
+ return;
+ }
+
+ /*LOGD("msg [%s]", msg);*/
+
+ if (!muse_recorder_msg_get(api, msg)) {
+ LOGE("failed to get recorder api");
+ return;
+ }
+
+ if (api == MUSE_RECORDER_CB_EVENT) {
+ if (!muse_recorder_msg_get(event, msg) ||
+ !muse_recorder_msg_get(event_class, msg)) {
+ LOGE("failed to get event or event_class [%s]", msg);
+ return;
+ }
+ } else {
+ if (!muse_recorder_msg_get(api_class, msg)) {
+ LOGE("failed to get api_class [%s]", msg);
+ return;
+ }
+ }
+
+ if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
+ if (api >= MUSE_RECORDER_API_MAX) {
+ LOGE("invalid api %d", api);
+ return;
+ }
+
+ if (!muse_recorder_msg_get(ret, msg)) {
+ LOGE("failed to get recorder ret");
+ return;
+ }
+
+ g_mutex_lock(&cb_info->api_mutex[api]);
+
+ if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
+ g_atomic_int_set(&cb_info->msg_recv_running, 0);
+ LOGD("get device state done. close client cb handler");
+ } else {
+ switch (api) {
+ case MUSE_RECORDER_API_CREATE:
+ if (ret != RECORDER_ERROR_NONE) {
+ g_atomic_int_set(&cb_info->msg_recv_running, 0);
+ LOGE("create error 0x%x. closing..", ret);
+ }
+ break;
+ case MUSE_RECORDER_API_DESTROY:
+ if (ret == RECORDER_ERROR_NONE) {
+ g_atomic_int_set(&cb_info->msg_recv_running, 0);
+ LOGD("destroy done. closing..");
+ }
+ break;
+ default:
+ __recorder_get_api_operation(api, cb_info, msg);
+ break;
+ }
+ }
+
+ if (cb_info->api_waiting[api] > 0) {
+ cb_info->api_ret[api] = ret;
+ cb_info->api_activating[api] = TRUE;
+
+ g_cond_signal(&cb_info->api_cond[api]);
+ } else {
+ LOGE("no waiting for api [%d]", api);
+ }
+
+ g_mutex_unlock(&cb_info->api_mutex[api]);
+ } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
+ __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg, tfd);
+ } else {
+ LOGW("unknown recorder api %d and api_class %d", api, api_class);
+ }
+
+ return;
+}
+
+
+static void *_recorder_msg_handler_func(gpointer data)
+{
+ int api = 0;
+ int type = 0;
+ recorder_message_s *rec_msg = NULL;
+ recorder_idle_event_s *rec_idle_event = NULL;
+ recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
+ recorder_cb_info_s *cb_info = NULL;
+
+ if (!handler_info || !handler_info->cb_info) {
+ LOGE("NULL handler %p", handler_info);
+ return NULL;
+ }
+
+ cb_info = (recorder_cb_info_s *)handler_info->cb_info;
+ type = handler_info->type;
+
+ LOGD("t:%d start", type);
+
+ g_mutex_lock(&handler_info->mutex);
+
+ while (g_atomic_int_get(&handler_info->running)) {
+ if (g_queue_is_empty(handler_info->queue)) {
+ /*LOGD("signal wait...");*/
+ g_cond_wait(&handler_info->cond, &handler_info->mutex);
+ /*LOGD("signal received");*/
+
+ if (g_atomic_int_get(&handler_info->running) == 0) {
+ LOGD("stop event thread");
+ break;
+ }
+ }
+
+ rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
+ g_mutex_unlock(&handler_info->mutex);
+ if (rec_msg == NULL) {
+ LOGE("NULL message");
+ g_mutex_lock(&handler_info->mutex);
+ continue;
+ }
+
+ api = rec_msg->api;
+
+ if (api < MUSE_RECORDER_API_MAX) {
+ int ret = 0;
+
+ g_mutex_lock(&cb_info->api_mutex[api]);
+
+ if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
+ if (cb_info->api_waiting[api] > 0) {
+ cb_info->api_ret[api] = ret;
+ cb_info->api_activating[api] = TRUE;
+
+ /*LOGD("recorder api %d - return 0x%x", api, ret);*/
+
+ g_cond_signal(&cb_info->api_cond[api]);
+ } else {
+ LOGE("no waiting for api [%d]", api);
+ }
+ } else {
+ LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
+ }
+
+ g_mutex_unlock(&cb_info->api_mutex[api]);
+ } else if (api == MUSE_RECORDER_CB_EVENT) {
+ switch (rec_msg->event_class) {
+ case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
+ _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event, rec_msg->tfd);
+ break;
+ case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
+ rec_idle_event = g_new0(recorder_idle_event_s, 1);
+ if (rec_idle_event == NULL) {
+ LOGE("event alloc failed");
+ break;
+ }
+
+ rec_idle_event->event = rec_msg->event;
+ rec_idle_event->cb_info = cb_info;
+
+ strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg));
+
+ /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
+
+ g_mutex_lock(&g_rec_idle_event_lock);
+ cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
+ g_mutex_unlock(&g_rec_idle_event_lock);
+
+ g_idle_add_full(G_PRIORITY_DEFAULT,
+ (GSourceFunc)_recorder_idle_event_callback,
+ (gpointer)rec_idle_event,
+ NULL);
+ break;
+ default:
+ LOGE("unknown event class %d", rec_msg->event_class);
+ break;
+ }
+ } else {
+ LOGE("unknown api[%d] message", api);
+ }
+
+ g_free(rec_msg);
+ rec_msg = NULL;
+
+ g_mutex_lock(&handler_info->mutex);
+ }
+
+ /* remove remained event */
+ while (!g_queue_is_empty(handler_info->queue)) {
+ rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
+ if (rec_msg) {
+ LOGD("remove message %p", rec_msg);
+ free(rec_msg);
+ rec_msg = NULL;
+ } else {
+ LOGW("NULL message");
+ }
}
- return;
+ g_mutex_unlock(&handler_info->mutex);
+
+ LOGD("return");
+
+ return NULL;
}
static void *_recorder_msg_recv_func(gpointer data)
{
- int i = 0;
- int ret = 0;
- int api = 0;
- int api_class = 0;
- int event = 0;
- int event_class = 0;
- int num_token = 0;
- int str_pos = 0;
- int prev_pos = 0;
- int msg_length = 0;
+ int recv_length = 0;
+ int tfd[MUSE_NUM_FD] = {-1, -1, -1, -1};
char *recv_msg = NULL;
- char *error_msg = NULL;
- char **parse_str = NULL;
recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
if (cb_info == NULL) {
LOGD("start");
- parse_str = (char **)malloc(sizeof(char *) * RECORDER_PARSED_STRING_NUM_MAX);
- if (parse_str == NULL) {
- LOGE("parse_str malloc failed");
- return NULL;
- }
-
- for (i = 0 ; i < RECORDER_PARSED_STRING_NUM_MAX ; i++) {
- parse_str[i] = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
- if (parse_str[i] == NULL) {
- LOGE("parse_str[%d] malloc failed", i);
- goto CB_HANDLER_EXIT;
- }
- }
-
recv_msg = cb_info->recv_msg;
while (g_atomic_int_get(&cb_info->msg_recv_running)) {
- ret = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
- if (ret <= 0) {
+ /* tfd[0] is only used. */
+ tfd[0] = -1;
+
+ recv_length = muse_core_msg_recv_fd(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH, tfd);
+ if (recv_length <= 0) {
+//LCOV_EXCL_START
cb_info->is_server_connected = FALSE;
LOGE("receive msg failed - server disconnected");
break;
+//LCOV_EXCL_STOP
}
- recv_msg[ret] = '\0';
-
- str_pos = 0;
- prev_pos = 0;
- num_token = 0;
-
- /*LOGD("recvMSg : %s, length : %d", recv_msg, ret);*/
-
- /* Need to split the combined entering msgs.
- This module supports up to 20 combined msgs. */
- for (str_pos = 0; str_pos < ret; str_pos++) {
- if (recv_msg[str_pos] == '}') {
- msg_length = str_pos - prev_pos + 1;
-
- if (msg_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
- strncpy(parse_str[num_token], recv_msg + prev_pos, msg_length);
- parse_str[num_token][msg_length] = '\0';
- num_token++;
- /*LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);*/
- } else {
- LOGW("too long message : length %d [%s]", msg_length, recv_msg + prev_pos);
- }
-
- prev_pos = str_pos + 1;
-
- if (num_token >= RECORDER_PARSED_STRING_NUM_MAX) {
- LOGE("There's too many tokens. Remained msg length %d", ret - str_pos);
- break;
- }
- }
- }
-
- /*LOGD("num_token : %d", num_token);*/
-
- /* Re-construct to the useful single msg. */
- for (i = 0; i < num_token; i++) {
- if (i >= RECORDER_PARSED_STRING_NUM_MAX) {
- LOGE("invalid token index %d", i);
- break;
- }
-
- api = -1;
- api_class = -1;
-
- if (!muse_recorder_msg_get(api, parse_str[i])) {
- LOGE("failed to get recorder api");
- continue;
- }
-
- if (api == MUSE_RECORDER_CB_EVENT) {
- if (!muse_recorder_msg_get(event, parse_str[i]) ||
- !muse_recorder_msg_get(event_class, parse_str[i])) {
- LOGE("failed to get event or event_class [%s]", parse_str[i]);
- continue;
- }
- } else {
- if (!muse_recorder_msg_get(api_class, parse_str[i])) {
- LOGE("failed to get api_class [%s]", parse_str[i]);
- continue;
- }
- }
-
- if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
- if (api >= MUSE_RECORDER_API_MAX) {
- LOGE("invalid api %d", api);
- continue;
- }
-
- g_mutex_lock(&cb_info->api_mutex[api]);
-
- if (!muse_recorder_msg_get(ret, parse_str[i])) {
- LOGE("failed to get recorder ret");
- g_mutex_unlock(&cb_info->api_mutex[api]);
- continue;
- }
-
- cb_info->api_ret[api] = ret;
- cb_info->api_activating[api] = 1;
+ recv_msg[recv_length] = '\0';
- if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
- g_atomic_int_set(&cb_info->msg_recv_running, 0);
- LOGD("get device state done. close client cb handler");
- } else {
- switch (api) {
- case MUSE_RECORDER_API_CREATE:
- if (ret != RECORDER_ERROR_NONE) {
- g_atomic_int_set(&cb_info->msg_recv_running, 0);
- LOGE("create error 0x%x. closing..", ret);
- }
- break;
- case MUSE_RECORDER_API_DESTROY:
- if (ret == RECORDER_ERROR_NONE) {
- g_atomic_int_set(&cb_info->msg_recv_running, 0);
- LOGD("destroy done. closing..");
- }
- break;
- default:
- _recorder_get_api_operation(api, cb_info, parse_str[i]);
- break;
- }
- }
+ /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
- g_cond_signal(&cb_info->api_cond[api]);
- g_mutex_unlock(&cb_info->api_mutex[api]);
- } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
- __recorder_add_msg_to_queue(cb_info, api, event, event_class, parse_str[i]);
- } else {
- LOGW("unknown recorder api %d and api_class %d", api, api_class);
- }
- }
+ __recorder_process_msg(cb_info, recv_msg, tfd[0]);
}
LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
if (!cb_info->is_server_connected) {
+//LCOV_EXCL_START
/* send error msg for server disconnection */
- error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
+ char *error_msg = muse_core_msg_new(MUSE_RECORDER_CB_EVENT,
MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
NULL);
+
if (!error_msg) {
LOGE("error_msg failed");
goto CB_HANDLER_EXIT;
MUSE_RECORDER_CB_EVENT,
MUSE_RECORDER_EVENT_TYPE_ERROR,
MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
- error_msg);
+ error_msg,
+ -1);
- muse_core_msg_json_factory_free(error_msg);
+ muse_core_msg_free(error_msg);
error_msg = NULL;
LOGE("add error msg for service disconnection done");
+//LCOV_EXCL_STOP
}
CB_HANDLER_EXIT:
- if (parse_str) {
- for (i = 0 ; i < RECORDER_PARSED_STRING_NUM_MAX ; i++) {
- if (parse_str[i]) {
- free(parse_str[i]);
- parse_str[i] = NULL;
- }
- }
-
- free(parse_str);
- parse_str = NULL;
- }
-
return NULL;
}
handler_info->thread = g_thread_try_new(thread_name,
_recorder_msg_handler_func, (gpointer)handler_info, NULL);
if (handler_info->thread == NULL) {
+//LCOV_EXCL_START
LOGE("t:%d thread failed", type);
g_mutex_clear(&handler_info->mutex);
handler_info->queue = NULL;
return false;
+//LCOV_EXCL_STOP
}
LOGD("t:%d done", type);
g_mutex_unlock(&handler_info->mutex);
g_thread_join(handler_info->thread);
- g_thread_unref(handler_info->thread);
handler_info->thread = NULL;
g_mutex_clear(&handler_info->mutex);
goto ErrorExit;
}
+ cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
+
for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
g_mutex_init(&cb_info->api_mutex[i]);
g_cond_init(&cb_info->api_cond[i]);
}
- g_mutex_init(&cb_info->idle_event_mutex);
- g_cond_init(&cb_info->idle_event_cond);
+ for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
+ g_mutex_init(&cb_info->user_cb_mutex[i]);
/* message handler thread */
if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
goto ErrorExit;
}
+ /* message handler thread for muxed stream callback */
+ if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
+ _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
+ LOGE("muxed_stream_cb_info failed");
+ goto ErrorExit;
+ }
+
cb_info->fd = sockfd;
/* message receive thread */
cb_info->is_server_connected = TRUE;
return cb_info;
-
+//LCOV_EXCL_START
ErrorExit:
if (cb_info) {
__destroy_msg_handler_thread(&cb_info->msg_handler_info);
__destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
+ __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
- g_mutex_clear(&cb_info->idle_event_mutex);
- g_cond_clear(&cb_info->idle_event_cond);
+ for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
+ g_mutex_clear(&cb_info->user_cb_mutex[i]);
for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
g_mutex_clear(&cb_info->api_mutex[i]);
}
return NULL;
+//LCOV_EXCL_STOP
}
static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
g_mutex_lock(&(cb_info->api_mutex[api]));
- if (cb_info->api_activating[api] == 0) {
- end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
- if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
- ret = cb_info->api_ret[api];
- cb_info->api_activating[api] = 0;
+ LOGD("api [%d], timeout [%d sec]", api, time_out);
- /*LOGD("return value : 0x%x", ret);*/
- } else {
- ret = RECORDER_ERROR_INVALID_OPERATION;
+ end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
+ while (!cb_info->api_activating[api]) {
+ if (time_out == RECORDER_CB_NO_TIMEOUT) {
+ g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
+ LOGW("api %d returned 0x%x", api, cb_info->api_ret[api]);
+ } else if (!g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
LOGE("api %d was TIMED OUT!", api);
+ ret = RECORDER_ERROR_INVALID_OPERATION;
+ goto _CB_RETURN_END;
}
- } else {
- ret = cb_info->api_ret[api];
- cb_info->api_activating[api] = 0;
- /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
+ if (!cb_info->api_activating[api])
+ LOGW("invalid signal received, wait again...");
}
- if (ret != RECORDER_ERROR_NONE) {
- LOGE("ERROR : api %d - ret 0x%x", api, ret);
-
- if (ret == RECORDER_ERROR_SOUND_POLICY)
- LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
- else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
- LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
- else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
- LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
- }
+ ret = cb_info->api_ret[api];
+ cb_info->api_activating[api] = FALSE;
+_CB_RETURN_END:
g_mutex_unlock(&(cb_info->api_mutex[api]));
+ if (ret != RECORDER_ERROR_NONE)
+ LOGE("ERROR : api %d - ret 0x%x", api, ret);
+
return ret;
}
-static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret)
+static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
{
int send_ret = 0;
char *msg = NULL;
return RECORDER_ERROR_INVALID_PARAMETER;
}
- msg = muse_core_msg_json_factory_new(api, NULL);
+ msg = muse_core_msg_new(api, NULL);
if (!msg) {
LOGE("msg creation failed: api %d", api);
return RECORDER_ERROR_OUT_OF_MEMORY;
/*LOGD("send msg %s", msg);*/
- if (cb_info->is_server_connected)
- send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
+ if (cb_info->is_server_connected) {
+ __recorder_update_api_waiting(cb_info, api, 1);
+ send_ret = muse_core_msg_send(cb_info->fd, msg);
+ }
if (send_ret < 0) {
LOGE("message send failed");
*ret = RECORDER_ERROR_INVALID_OPERATION;
} else {
- *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
+ *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
}
- muse_core_msg_json_factory_free(msg);
+ __recorder_update_api_waiting(cb_info, api, -1);
+
+ muse_core_msg_free(msg);
return RECORDER_ERROR_NONE;
}
switch (param->type) {
case MUSE_TYPE_INT:
- msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
+ msg = muse_core_msg_new(api, param->type, param->name, param->value.value_INT, NULL);
break;
case MUSE_TYPE_DOUBLE:
- msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
+ msg = muse_core_msg_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
break;
case MUSE_TYPE_STRING:
- msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
+ msg = muse_core_msg_new(api, param->type, param->name, param->value.value_STRING, NULL);
break;
default:
LOGE("unknown type %d", param->type);
/*LOGD("send msg %s", msg);*/
- if (cb_info->is_server_connected)
- send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
+ if (cb_info->is_server_connected) {
+ __recorder_update_api_waiting(cb_info, api, 1);
+
+ send_ret = muse_core_msg_send(cb_info->fd, msg);
+ }
if (send_ret < 0) {
LOGE("message send failed");
*ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
}
- muse_core_msg_json_factory_free(msg);
+ __recorder_update_api_waiting(cb_info, api, -1);
+
+ muse_core_msg_free(msg);
return RECORDER_ERROR_NONE;
}
LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
g_thread_join(cb_info->msg_recv_thread);
- g_thread_unref(cb_info->msg_recv_thread);
cb_info->msg_recv_thread = NULL;
LOGD("msg_recv thread removed");
__destroy_msg_handler_thread(&cb_info->msg_handler_info);
__destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
+ __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
- g_mutex_clear(&cb_info->idle_event_mutex);
- g_cond_clear(&cb_info->idle_event_cond);
+ for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
+ g_mutex_clear(&cb_info->user_cb_mutex[i]);
for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
g_mutex_clear(&cb_info->api_mutex[i]);
}
if (cb_info->fd > -1) {
- muse_core_connection_close(cb_info->fd);
+ muse_client_close(cb_info->fd);
cb_info->fd = -1;
}
}
-static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+static bool _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
{
char **root_directory = (char **)user_data;
int ret = RECORDER_ERROR_NONE;
int destroy_ret = RECORDER_ERROR_NONE;
int sock_fd = -1;
+ int module_index = -1;
int send_ret = 0;
char *send_msg = NULL;
char *root_directory = NULL;
goto _ERR_RECORDER_EXIT;
}
- sock_fd = muse_core_client_new();
+ sock_fd = muse_client_new();
if (sock_fd < 0) {
- LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
+//LCOV_EXCL_START
+ LOGE("muse_client_new failed - returned fd %d", sock_fd);
+ ret = RECORDER_ERROR_INVALID_OPERATION;
+ goto _ERR_RECORDER_EXIT;
+//LCOV_EXCL_STOP
+ }
+
+ if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
+ LOGE("muse client get module index failed");
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _ERR_RECORDER_EXIT;
}
if (type == MUSE_RECORDER_TYPE_AUDIO) {
- send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
- MUSE_TYPE_INT, "module", MUSE_RECORDER,
+ send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
+ MUSE_TYPE_INT, "module", module_index,
MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
MUSE_TYPE_INT, "pid", getpid(),
NULL);
} else {
pc->camera = camera;
camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
- send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
- MUSE_TYPE_INT, "module", MUSE_RECORDER,
+ send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
+ MUSE_TYPE_INT, "module", module_index,
MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
+ MUSE_TYPE_INT, "pid", getpid(),
MUSE_TYPE_POINTER, "camera_handle", camera_handle,
NULL);
}
if (!send_msg) {
+//LCOV_EXCL_START
LOGE("NULL msg");
ret = RECORDER_ERROR_OUT_OF_MEMORY;
goto _ERR_RECORDER_EXIT;
+//LCOV_EXCL_STOP
}
LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
- send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
+ send_ret = muse_core_msg_send(sock_fd, send_msg);
- muse_core_msg_json_factory_free(send_msg);
+ muse_core_msg_free(send_msg);
send_msg = NULL;
if (send_ret < 0) {
+//LCOV_EXCL_START
LOGE("send msg failed %d", errno);
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _ERR_RECORDER_EXIT;
+//LCOV_EXCL_STOP
}
pc->cb_info = _recorder_client_callback_new(sock_fd);
sock_fd = -1;
ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
+
+ pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
+
if (ret != RECORDER_ERROR_NONE) {
LOGE("API_CREATE failed 0x%x", ret);
goto _ERR_RECORDER_EXIT;
muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
if (handle == 0) {
+//LCOV_EXCL_START
LOGE("Receiving Handle Failed!!");
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _ERR_RECORDER_AFTER_CREATE;
+//LCOV_EXCL_STOP
}
if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
+//LCOV_EXCL_START
LOGE("failed to get root directory of internal storage");
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _ERR_RECORDER_AFTER_CREATE;
+//LCOV_EXCL_STOP
}
LOGD("root directory [%s]", root_directory);
pc->remote_handle = handle;
pc->cb_info->bufmgr = bufmgr;
- LOGD("recorder[type %d] %p create success : remote handle 0x%x",
+ LOGD("recorder[type %d] %p create success : remote handle 0x%td",
type, pc, pc->remote_handle);
*recorder = (recorder_h)pc;
LOGD("done");
return RECORDER_ERROR_NONE;
-
+//LCOV_EXCL_START
_ERR_RECORDER_AFTER_CREATE:
- _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret);
+ _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
LOGE("destroy return 0x%x", destroy_ret);
_ERR_RECORDER_EXIT:
}
if (sock_fd > -1) {
- muse_core_connection_close(sock_fd);
+ muse_client_close(sock_fd);
sock_fd = -1;
}
}
return ret;
+//LCOV_EXCL_STOP
}
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, remote_handle : %x", pc->remote_handle);
+ LOGD("Enter, remote_handle : %td", pc->remote_handle);
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
LOGD("ENTER");
if (pc->cb_info->is_server_connected)
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
else
LOGW("server disconnected. release resource without send message.");
if (ret == RECORDER_ERROR_NONE) {
- _recorder_remove_idle_event_all(pc->cb_info);
+ _recorder_deactivate_idle_event_all(pc->cb_info);
_recorder_client_callback_destroy(pc->cb_info);
g_free(pc);
pc = NULL;
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
if (pc->camera) {
+//LCOV_EXCL_START
ret = camera_get_state(pc->camera, &camera_state);
if (ret != CAMERA_ERROR_NONE) {
LOGE("failed to get camera state 0x%x", ret);
return RECORDER_ERROR_INVALID_OPERATION;
}
}
+//LCOV_EXCL_STOP
}
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
if (pc->camera) {
+//LCOV_EXCL_START
ret = recorder_get_state(recorder, ¤t_state);
if (ret != RECORDER_ERROR_NONE) {
LOGE("failed to get current state 0x%x", ret);
return RECORDER_ERROR_INVALID_OPERATION;
}
}
+//LCOV_EXCL_STOP
}
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
if (pc->camera && current_state == RECORDER_STATE_READY)
camera_start_evas_rendering(pc->camera);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
if (pc->camera) {
+//LCOV_EXCL_START
ret = recorder_get_state(recorder, ¤t_state);
if (ret != RECORDER_ERROR_NONE) {
LOGE("failed to get current state 0x%x", ret);
return RECORDER_ERROR_INVALID_OPERATION;
}
}
+//LCOV_EXCL_STOP
}
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
camera_start_evas_rendering(pc->camera);
}
}
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
camera_start_evas_rendering(pc->camera);
LOGD("ENTER");
- send_msg = muse_core_msg_json_factory_new(api,
+ send_msg = muse_core_msg_new(api,
MUSE_TYPE_INT, "width", width,
MUSE_TYPE_INT, "height", height,
NULL);
if (send_msg) {
- if (pc->cb_info->is_server_connected)
- send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
+ if (pc->cb_info->is_server_connected) {
+ __recorder_update_api_waiting(pc->cb_info, api, 1);
+
+ send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
+ }
if (send_ret < 0) {
LOGE("message send failed");
ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
}
- muse_core_msg_json_factory_free(send_msg);
+ __recorder_update_api_waiting(pc->cb_info, api, -1);
+
+ muse_core_msg_free(send_msg);
} else {
LOGE("failed to create msg");
ret = RECORDER_ERROR_OUT_OF_MEMORY;
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE) {
*width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
}
-int recorder_set_filename(recorder_h recorder, const char *filename)
+int recorder_set_filename(recorder_h recorder, const char *filename)
{
int ret = RECORDER_ERROR_NONE;
+ size_t length = 0;
muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
recorder_cli_s *pc = (recorder_cli_s *)recorder;
recorder_msg_param param;
- char set_filename[RECORDER_FILENAME_MAX] = {0, };
+ char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
if (!pc || !pc->cb_info) {
LOGE("NULL handle");
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("ENTER");
+ LOGD("ENTER [%s]", filename);
+
+ length = strlen(filename);
+
+ if (length >= RECORDER_FILENAME_MAX - 1) {
+ LOGE("too long file name [%zu]", length);
+ return RECORDER_ERROR_INVALID_PARAMETER;
+ }
if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
/* Cannot convert. Use original path. */
- strncpy(set_filename, filename, strlen(filename));
+ strncpy(set_filename, filename, length + 1);
+ pc->cb_info->is_filename_converted = FALSE;
} else {
/* Converted. Use converted path. */
LOGD("Converted filename : %s -> %s", filename, set_filename);
+ pc->cb_info->is_filename_converted = TRUE;
}
RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE) {
- if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
- /* Cannot convert. Use original path. */
+ if (pc->cb_info->is_filename_converted == FALSE ||
+ storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
+ /* Use original path. */
*filename = pc->cb_info->get_filename;
} else {
/* Converted. Use converted path. */
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
LOGD("sound manager return [0x%x]", ret);
if (ret == SOUND_MANAGER_ERROR_NONE) {
- send_msg = muse_core_msg_json_factory_new(api,
+ send_msg = muse_core_msg_new(api,
MUSE_TYPE_STRING, "stream_type", stream_type,
MUSE_TYPE_INT, "stream_index", stream_index,
NULL);
if (send_msg) {
- if (pc->cb_info->is_server_connected)
- send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
+ if (pc->cb_info->is_server_connected) {
+ __recorder_update_api_waiting(pc->cb_info, api, 1);
+
+ send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
+ }
if (send_ret < 0) {
LOGE("message send failed");
ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
}
- muse_core_msg_json_factory_free(send_msg);
+ __recorder_update_api_waiting(pc->cb_info, api, -1);
+
+ muse_core_msg_free(send_msg);
} else {
LOGE("failed to create msg");
ret = RECORDER_ERROR_OUT_OF_MEMORY;
}
-int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
+int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
{
int ret = RECORDER_ERROR_NONE;
recorder_cli_s *pc = (recorder_cli_s *)recorder;
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
- pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
- pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
+ }
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
+ }
LOGD("ret : 0x%x", ret);
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
- pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
- pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
+ }
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
+ }
+
+ LOGD("ret : 0x%x", ret);
+
+ return ret;
+}
+
+
+int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
+{
+ int ret = RECORDER_ERROR_NONE;
+ recorder_cli_s *pc = (recorder_cli_s *)recorder;
+ muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
+
+ if (!pc || !pc->cb_info || callback == NULL) {
+ LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
+ return RECORDER_ERROR_INVALID_PARAMETER;
+ }
+
+ LOGD("Enter, handle :%td", pc->remote_handle);
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
+ }
+
+ LOGD("ret : 0x%x", ret);
+
+ return ret;
+}
+
+
+int recorder_unset_interrupt_started_cb(recorder_h recorder)
+{
+ int ret = RECORDER_ERROR_NONE;
+ muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
+ recorder_cli_s *pc = (recorder_cli_s *)recorder;
+
+ if (!pc || !pc->cb_info) {
+ LOGE("NULL handle");
+ return RECORDER_ERROR_INVALID_PARAMETER;
+ }
+
+ LOGD("ENTER");
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
+ }
LOGD("ret : 0x%x", ret);
}
-int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
+int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
{
int ret = RECORDER_ERROR_NONE;
recorder_cli_s *pc = (recorder_cli_s *)recorder;
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
- pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
- pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
- _recorder_msg_send(api, pc->cb_info, &ret);
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
+ }
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
+ }
+
+ LOGD("ret : 0x%x", ret);
+
+ return ret;
+}
+
+
+int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
+{
+ int ret = RECORDER_ERROR_NONE;
+ recorder_cli_s *pc = (recorder_cli_s *)recorder;
+ muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
+
+ if (!pc || !pc->cb_info || !callback) {
+ LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
+ return RECORDER_ERROR_INVALID_PARAMETER;
+ }
+
+ LOGD("Enter, handle :%td", pc->remote_handle);
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
+ }
+
+ LOGD("ret : 0x%x", ret);
+
+ return ret;
+}
+
+
+int recorder_unset_muxed_stream_cb(recorder_h recorder)
+{
+ int ret = RECORDER_ERROR_NONE;
+ muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
+ recorder_cli_s *pc = (recorder_cli_s *)recorder;
+
+ if (!pc || !pc->cb_info) {
+ LOGE("NULL handle");
+ return RECORDER_ERROR_INVALID_PARAMETER;
+ }
+
+ LOGD("ENTER");
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
+ }
LOGD("ret : 0x%x", ret);
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
- pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
- pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
+ }
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
+ }
LOGD("ret : 0x%x", ret);
}
-int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
+int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
{
int ret = RECORDER_ERROR_NONE;
recorder_cli_s *pc = (recorder_cli_s *)recorder;
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
+
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
- pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
- pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
+ }
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
+ }
LOGD("ret : 0x%x", ret);
}
-int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
+int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
{
int ret = RECORDER_ERROR_NONE;
recorder_cli_s *pc = (recorder_cli_s *)recorder;
return RECORDER_ERROR_INVALID_PARAMETER;
}
- pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
- pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
+ }
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
+
+ if (ret == RECORDER_ERROR_NONE) {
+ g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
+
+ pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
+ pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
+
+ g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
+ }
LOGD("ret : 0x%x", ret);
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
return RECORDER_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
LOGD("ret : 0x%x", ret);
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
ret = false;
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
LOGD("ENTER");
- _recorder_msg_send(api, pc->cb_info, &ret);
+ _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
if (ret == RECORDER_ERROR_NONE)
*orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
{
int ret = RECORDER_ERROR_NONE;
int sock_fd = -1;
+ int module_index = -1;
int get_device_state = 0;
char *send_msg = NULL;
char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
LOGD("Enter - type %d", type);
- sock_fd = muse_core_client_new();
+ sock_fd = muse_client_new();
if (sock_fd < 0) {
- LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
+//LCOV_EXCL_START
+ LOGE("muse_client_new failed - returned fd %d", sock_fd);
+ ret = RECORDER_ERROR_INVALID_OPERATION;
+ goto _GET_DEVICE_STATE_EXIT;
+//LCOV_EXCL_STOP
+ }
+
+ if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
+ LOGE("muse client get module index failed");
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _GET_DEVICE_STATE_EXIT;
}
- send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
- MUSE_TYPE_INT, "module", MUSE_RECORDER,
+ send_msg = muse_core_msg_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
+ MUSE_TYPE_INT, "module", module_index,
MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
NULL);
if (!send_msg) {
+//LCOV_EXCL_START
LOGE("NULL msg");
ret = RECORDER_ERROR_OUT_OF_MEMORY;
goto _GET_DEVICE_STATE_EXIT;
+//LCOV_EXCL_STOP
}
LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
- ret = muse_core_ipc_send_msg(sock_fd, send_msg);
+ ret = muse_core_msg_send(sock_fd, send_msg);
- muse_core_msg_json_factory_free(send_msg);
+ muse_core_msg_free(send_msg);
send_msg = NULL;
if (ret < 0) {
+//LCOV_EXCL_START
LOGE("send msg failed %d", errno);
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _GET_DEVICE_STATE_EXIT;
+//LCOV_EXCL_STOP
}
- ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
+ ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_RECORDER_MSG_MAX_LENGTH);
if (ret <= 0) {
+//LCOV_EXCL_START
LOGE("recv msg failed %d", errno);
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _GET_DEVICE_STATE_EXIT;
+//LCOV_EXCL_STOP
}
if (!muse_recorder_msg_get(ret, recv_msg)) {
+//LCOV_EXCL_START
LOGE("failed to get return value from msg [%s]", recv_msg);
ret = RECORDER_ERROR_INVALID_OPERATION;
goto _GET_DEVICE_STATE_EXIT;
+//LCOV_EXCL_STOP
}
if (ret == RECORDER_ERROR_NONE) {
_GET_DEVICE_STATE_EXIT:
if (sock_fd > -1) {
- muse_core_connection_close(sock_fd);
+ muse_client_close(sock_fd);
sock_fd = -1;
}
_DONE:
if (ret != RECORDER_ERROR_NONE) {
+//LCOV_EXCL_START
if (info) {
g_free(info);
info = NULL;
g_object_unref(g_rec_dev_state_changed_cb_conn);
g_rec_dev_state_changed_cb_conn = NULL;
}
+//LCOV_EXCL_STOP
}
g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);