summaryrefslogtreecommitdiff
path: root/src/camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera.c')
-rw-r--r--src/camera.c72
1 files changed, 20 insertions, 52 deletions
diff --git a/src/camera.c b/src/camera.c
index b2b566a..e514488 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -41,6 +41,7 @@ static GList *g_cam_dev_state_changed_cb_list;
static int g_cam_dev_state_changed_cb_id;
static GDBusConnection *g_cam_dev_state_changed_cb_conn;
static guint g_cam_dev_state_changed_cb_subscribe_id;
+static GMutex g_cam_idle_event_lock;
static void _camera_msg_send(int api, camera_cb_info_s *cb_info,
int *ret, int timeout);
@@ -1467,49 +1468,41 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
return;
}
-static bool _camera_idle_event_callback(void *data)
+static gboolean _camera_idle_event_callback(gpointer data)
{
camera_cb_info_s *cb_info = NULL;
camera_idle_event_s *cam_idle_event = (camera_idle_event_s *)data;
if (cam_idle_event == NULL) {
LOGE("cam_idle_event is NULL");
- return false;
+ return FALSE;
}
/* lock event */
- g_mutex_lock(&cam_idle_event->event_mutex);
+ g_mutex_lock(&g_cam_idle_event_lock);
cb_info = cam_idle_event->cb_info;
if (cb_info == NULL) {
LOGW("camera cb_info is NULL. event %p %d", cam_idle_event, cam_idle_event->event);
+ g_mutex_unlock(&g_cam_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)cam_idle_event);
- /*LOGD("remove camera idle event %p, %p", cam_idle_event, cb_info->idle_event_list);*/
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_cam_idle_event_lock);
/* user callback */
_camera_client_user_callback(cb_info, cam_idle_event->recv_msg, cam_idle_event->event);
- /* send signal for waiting thread */
- g_cond_signal(&cb_info->idle_event_cond);
-
IDLE_EVENT_CALLBACK_DONE:
- /* unlock and release event */
- g_mutex_unlock(&cam_idle_event->event_mutex);
- g_mutex_clear(&cam_idle_event->event_mutex);
-
+ /* release event */
g_free(cam_idle_event);
cam_idle_event = NULL;
- return false;
+ return FALSE;
}
static void *_camera_msg_handler_func(gpointer data)
@@ -1592,14 +1585,14 @@ static void *_camera_msg_handler_func(gpointer data)
cam_idle_event->event = cam_msg->event;
cam_idle_event->cb_info = cb_info;
- g_mutex_init(&cam_idle_event->event_mutex);
+
strncpy(cam_idle_event->recv_msg, cam_msg->recv_msg, sizeof(cam_idle_event->recv_msg) - 1);
/*LOGD("t:%d add camera event[%d, %p] to IDLE", type, cam_msg->event, cam_idle_event);*/
- g_mutex_lock(&cb_info->idle_event_mutex);
+ g_mutex_lock(&g_cam_idle_event_lock);
cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)cam_idle_event);
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_cam_idle_event_lock);
g_idle_add_full(G_PRIORITY_DEFAULT,
(GSourceFunc)_camera_idle_event_callback,
@@ -1644,18 +1637,17 @@ static void _camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
{
camera_idle_event_s *cam_idle_event = NULL;
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_cam_idle_event_lock);
if (cb_info->idle_event_list == NULL) {
LOGD("No remained idle event");
- g_mutex_unlock(&cb_info->idle_event_mutex);
+ g_mutex_unlock(&g_cam_idle_event_lock);
return;
}
@@ -1675,42 +1667,24 @@ static void _camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
- g_mutex_clear(&cam_idle_event->event_mutex);
g_free(cam_idle_event);
cam_idle_event = NULL;
continue;
}
- LOGW("remove idle event %p failed", cam_idle_event);
-
- if (!g_mutex_trylock(&cam_idle_event->event_mutex)) {
- LOGW("lock failed, %p event is calling now", cam_idle_event);
-
- end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
-
- if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
- LOGW("signal received");
- else
- LOGW("timeout");
-
- continue;
- }
-
LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
cam_idle_event, cam_idle_event->event);
cam_idle_event->cb_info = NULL;
cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
-
- g_mutex_unlock(&cam_idle_event->event_mutex);
}
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_cam_idle_event_lock);
return;
}
@@ -2141,8 +2115,6 @@ static camera_cb_info_s *_camera_client_callback_new(gint sockfd)
}
g_mutex_init(&cb_info->fd_lock);
- g_mutex_init(&cb_info->idle_event_mutex);
- g_cond_init(&cb_info->idle_event_cond);
g_mutex_init(&cb_info->mp_data_mutex);
for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
@@ -2195,8 +2167,6 @@ ErrorExit:
g_mutex_clear(&cb_info->user_cb_mutex[i]);
g_mutex_clear(&cb_info->fd_lock);
- g_mutex_clear(&cb_info->idle_event_mutex);
- g_cond_clear(&cb_info->idle_event_cond);
g_mutex_clear(&cb_info->mp_data_mutex);
for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
@@ -2234,8 +2204,6 @@ static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
g_mutex_clear(&cb_info->user_cb_mutex[i]);
g_mutex_clear(&cb_info->fd_lock);
- g_mutex_clear(&cb_info->idle_event_mutex);
- g_cond_clear(&cb_info->idle_event_cond);
g_mutex_clear(&cb_info->mp_data_mutex);
for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
@@ -2493,7 +2461,7 @@ int camera_create(camera_device_e device, camera_h *camera)
goto ErrorExit;
}
- LOGD("camera create 0x%x", pc->remote_handle);
+ LOGD("camera create 0x%td", pc->remote_handle);
*camera = (camera_h)pc;
@@ -3013,7 +2981,7 @@ int camera_cancel_focusing(camera_h camera)
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, remote_handle : %x", pc->remote_handle);
+ LOGD("Enter, remote_handle : %td", pc->remote_handle);
_camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
@@ -4464,7 +4432,7 @@ int camera_attr_set_zoom(camera_h camera, int zoom)
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, remote_handle : %x", pc->remote_handle);
+ LOGD("Enter, remote_handle : %td", pc->remote_handle);
CAMERA_MSG_PARAM_SET(param, INT, zoom);
@@ -4489,7 +4457,7 @@ int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, remote_handle : %x", pc->remote_handle);
+ LOGD("Enter, remote_handle : %td", pc->remote_handle);
CAMERA_MSG_PARAM_SET(param, INT, set_mode);
@@ -4853,7 +4821,7 @@ int camera_attr_set_tag_software(camera_h camera, const char *software)
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("Enter, remote_handle : %x", pc->remote_handle);
+ LOGD("Enter, remote_handle : %td", pc->remote_handle);
CAMERA_MSG_PARAM_SET(param, STRING, software);
@@ -5717,7 +5685,7 @@ int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps
_camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
- LOGD("Enter, handle :%x", pc->remote_handle);
+ LOGD("Enter, handle :%td", pc->remote_handle);
return ret;
}