static guint g_rec_dev_state_changed_cb_subscribe_id;
+
+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,
const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
const gchar *signal_name, GVariant *param, gpointer user_data)
g_mutex_lock(&cb_info->api_mutex[api]);
- cb_info->api_ret[api] = ret;
- cb_info->api_activating[api] = 1;
-
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");
}
}
- g_cond_signal(&cb_info->api_cond[api]);
+ if (cb_info->api_waiting[api] > 0) {
+ cb_info->api_ret[api] = ret;
+ cb_info->api_activating[api] = 1;
+
+ 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);
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;
+ if (cb_info->api_waiting[api] > 0) {
+ cb_info->api_ret[api] = ret;
+ cb_info->api_activating[api] = 1;
- /*LOGD("recorder api %d - return 0x%x", ret);*/
+ /*LOGD("recorder api %d - return 0x%x", ret);*/
- g_cond_signal(&cb_info->api_cond[api]);
+ 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);
}
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]);
/*LOGD("send msg %s", msg);*/
- if (cb_info->is_server_connected)
+ if (cb_info->is_server_connected) {
+ __recorder_update_api_waiting(cb_info, api, 1);
+
send_ret = muse_core_ipc_send_msg(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);
}
+ __recorder_update_api_waiting(cb_info, api, -1);
+
muse_core_msg_json_factory_free(msg);
return RECORDER_ERROR_NONE;
/*LOGD("send msg %s", msg);*/
- if (cb_info->is_server_connected)
+ if (cb_info->is_server_connected) {
+ __recorder_update_api_waiting(cb_info, api, 1);
+
send_ret = muse_core_ipc_send_msg(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);
}
+ __recorder_update_api_waiting(cb_info, api, -1);
+
muse_core_msg_json_factory_free(msg);
return RECORDER_ERROR_NONE;
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_TYPE_INT, "height", height,
NULL);
if (send_msg) {
- if (pc->cb_info->is_server_connected)
+ if (pc->cb_info->is_server_connected) {
+ __recorder_update_api_waiting(pc->cb_info, api, 1);
+
send_ret = muse_core_ipc_send_msg(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);
}
+ __recorder_update_api_waiting(pc->cb_info, api, -1);
+
muse_core_msg_json_factory_free(send_msg);
} else {
LOGE("failed to create msg");
MUSE_TYPE_INT, "stream_index", stream_index,
NULL);
if (send_msg) {
- if (pc->cb_info->is_server_connected)
+ if (pc->cb_info->is_server_connected) {
+ __recorder_update_api_waiting(pc->cb_info, api, 1);
+
send_ret = muse_core_ipc_send_msg(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);
}
+ __recorder_update_api_waiting(pc->cb_info, api, -1);
+
muse_core_msg_json_factory_free(send_msg);
} else {
LOGE("failed to create msg");