static void __camera_hal_v4l2_destructor(void) __attribute__((destructor));
+static void __camera_send_message(hal_camera_handle *handle, camera_message_type_e type, int value);
static void __camera_hal_v4l2_destructor(void)
}
+static void __camera_send_message(hal_camera_handle *handle, camera_message_type_e type, int value)
+{
+ camera_message_s *message = NULL;
+
+ if (!handle) {
+ LOGE("NULL handle");
+ return;
+ }
+
+ message = g_new0(camera_message_s, 1);
+
+ message->type = type;
+
+ switch (type) {
+ case CAMERA_MESSAGE_TYPE_FOCUS_CHANGED:
+ message->focus_state = (camera_focus_state_e)value;
+ break;
+ case CAMERA_MESSAGE_TYPE_CAPTURED:
+ break;
+ case CAMERA_MESSAGE_TYPE_HDR_PROGRESS:
+ message->hdr_progress = (uint32_t)value;
+ break;
+ case CAMERA_MESSAGE_TYPE_ERROR:
+ message->error_code = (camera_error_e)value;
+ break;
+ default:
+ LOGE("unknown type[%d]", type);
+ g_free(message);
+ return;
+ }
+
+ g_mutex_lock(&handle->msg_cb_lock);
+
+ LOGD("type[%d], value[0x%x]", type, value);
+
+ g_queue_push_tail(handle->msg_list, message);
+ g_cond_signal(&handle->msg_cb_cond);
+
+ g_mutex_unlock(&handle->msg_cb_lock);
+}
+
+
static int __camera_v4l2_wait_frame(int device_fd, int wait_time)
{
int ret = CAMERA_ERROR_NONE;
ret = v4l2_ioctl(device_fd, VIDIOC_DQBUF, &v4l2_buf);
if (ret < 0) {
- if (errno != EIO) {
- LOGE("dqbuf failed. [t: %d, m: %d] errno %d",
- type, memory, errno);
- return CAMERA_ERROR_DEVICE_READ;
- }
+ LOGE("dqbuf failed. [t: %d, m: %d] errno %d",
+ type, memory, errno);
+ return CAMERA_ERROR_DEVICE_READ;
}
*index = v4l2_buf.index;
static void *__camera_buffer_handler_func(gpointer data)
{
+ int error = CAMERA_ERROR_NONE;
int index = 0;
hal_camera_handle *handle = (hal_camera_handle *)data;
break;
}
- if (__camera_v4l2_dqbuf(handle->device_fd, handle->buffer_type, V4L2_MEMORY_MMAP, &index) != CAMERA_ERROR_NONE) {
- LOGE("dqbuf failed");
+ error = __camera_v4l2_dqbuf(handle->device_fd, handle->buffer_type, V4L2_MEMORY_MMAP, &index);
+ if (error != CAMERA_ERROR_NONE) {
+ LOGE("dqbuf failed[0x%x]", error);
break;
}
g_mutex_unlock(&handle->buffer_lock);
+ if (error != CAMERA_ERROR_NONE)
+ __camera_send_message(handle, CAMERA_MESSAGE_TYPE_ERROR, error);
+
LOGD("leave");
return NULL;
for (i = 0 ; i < MESSAGE_CALLBACK_MAX ; i++) {
if (handle->msg_cb[i]) {
- LOGD("call message callback type %d", message->type);
+ LOGD("call message callback[%d] type[%d]", i, message->type);
handle->msg_cb[i](message, handle->msg_cb_data[i]);
}
}
g_mutex_lock(&handle->lock);
- if (handle->state != CAMERA_STATE_OPENED) {
- LOGE("invalid state %d", handle->state);
- g_mutex_unlock(&handle->lock);
- return CAMERA_ERROR_INVALID_STATE;
- }
-
for (i = 0 ; i < MESSAGE_CALLBACK_MAX ; i++) {
if (handle->msg_cb[i] == NULL) {
handle->msg_cb[i] = callback;
g_mutex_lock(&handle->lock);
- if (handle->state != CAMERA_STATE_OPENED) {
- LOGE("invalid state %d", handle->state);
- g_mutex_unlock(&handle->lock);
- return CAMERA_ERROR_INVALID_STATE;
- }
-
if (handle->msg_cb[cb_id]) {
LOGD("remove message callback %p, user data %p - cb_id %u",
handle->msg_cb[cb_id], handle->msg_cb_data[cb_id], cb_id);