static camera_device_info_list_t *g_device_info_list;
-static guint32 device_caps;
+static guint32 g_device_caps;
static GMutex g_device_info_lock;
-static void _camera_hal_v4l2_destructor(void) __attribute__((destructor));
+static void __camera_hal_v4l2_destructor(void) __attribute__((destructor));
-static void _camera_hal_v4l2_destructor(void)
+static void __camera_hal_v4l2_destructor(void)
{
LOGD("release device info list %p", g_device_info_list);
g_free(g_device_info_list);
+ g_device_info_list = NULL;
return;
}
-static int _camera_v4l2_wait_frame(int device_fd, int wait_time)
+static int __camera_v4l2_wait_frame(int device_fd, int wait_time)
{
int ret = CAMERA_ERROR_NONE;
fd_set fds;
timeout.tv_sec = wait_time;
timeout.tv_usec = 0;
- LOGD("select : %d sec", wait_time);
+ /*LOGD("select : %d sec", wait_time);*/
ret = select(device_fd + 1, &fds, NULL, NULL, &timeout);
if (ret == -1) {
return CAMERA_ERROR_INTERNAL;
}
- LOGD("select done");
+ /*LOGD("select done");*/
return CAMERA_ERROR_NONE;
}
-static int _camera_v4l2_g_ctrl(int device_fd, int cid, int *value)
+static int __camera_v4l2_g_ctrl(int device_fd, int cid, int *value)
{
int ret = 0;
struct v4l2_control ctrl;
}
-static int _camera_v4l2_s_ctrl(int device_fd, int cid, int value)
+static int __camera_v4l2_s_ctrl(int device_fd, int cid, int value)
{
int ret = 0;
struct v4l2_control ctrl;
}
-static int _camera_v4l2_stream(int device_fd, int type, gboolean onoff)
+static int __camera_v4l2_stream(int device_fd, int type, gboolean onoff)
{
if (device_fd < 0) {
LOGE("invalid fd %d", device_fd);
}
-static int _camera_v4l2_reqbufs(int device_fd, int type, int memory, int count, int *result_count)
+static int __camera_v4l2_reqbufs(int device_fd, int type, int memory, uint32_t count, uint32_t *result_count)
{
struct v4l2_requestbuffers v4l2_reqbuf;
}
-static int _camera_v4l2_qbuf(int device_fd, int type, int memory, int index)
+static int __camera_v4l2_qbuf(int device_fd, int type, int memory, int index)
{
struct v4l2_buffer v4l2_buf;
struct v4l2_plane v4l2_planes[V4L2_PLANES_MAX];
return CAMERA_ERROR_INTERNAL;
}
- LOGD("QBUF done [i: %d, t: %d, m: %d]",
- index, type, memory);
+ /*LOGD("QBUF done [i: %d, t: %d, m: %d]", index, type, memory);*/
return CAMERA_ERROR_NONE;
}
-static int _camera_v4l2_dqbuf(int device_fd, int type, int memory, int *index)
+static int __camera_v4l2_dqbuf(int device_fd, int type, int memory, int *index)
{
int ret = CAMERA_ERROR_NONE;
struct v4l2_buffer v4l2_buf;
*index = v4l2_buf.index;
- LOGD("dqbuf index %d", *index);
+ /*LOGD("dqbuf index %d", *index);*/
return CAMERA_ERROR_NONE;
}
-static int _camera_get_format(guint32 fourcc, int *pixel_format)
+static int __camera_get_format(guint32 fourcc, int *pixel_format)
{
if (!pixel_format) {
LOGE("NULL parameter");
return CAMERA_ERROR_NONE;
}
-static int _camera_get_fourcc_plane_num(int pixel_format, guint32 *fourcc, uint8_t *plane_num)
+static int __camera_get_fourcc_plane_num(int pixel_format, guint32 *fourcc, uint8_t *plane_num)
{
if (!fourcc || !plane_num) {
LOGE("NULL parameter %p %p", fourcc, plane_num);
}
-static int _camera_get_device_info(int device_index, int device_fd, camera_device_info_t *device_info, char *node_path)
+static int __camera_get_device_info(int device_index, int device_fd, camera_device_info_t *device_info, char *node_path)
{
int i = 0;
int j = 0;
LOGD("\tformat[%d] "FOURCC_FORMAT, i, FOURCC_CONVERT(v4l2_format.pixelformat));
- if (_camera_get_format(v4l2_format.pixelformat, &camera_format) != CAMERA_ERROR_NONE)
+ if (__camera_get_format(v4l2_format.pixelformat, &camera_format) != CAMERA_ERROR_NONE)
continue;
device_info->format_list.formats[format_count] = camera_format;
return CAMERA_ERROR_NONE;
}
-static int _camera_get_device_info_list(void)
+static int __camera_get_device_info_list(void)
{
int i = 0;
int ret = 0;
}
if (v4l2_cap.capabilities & V4L2_CAP_DEVICE_CAPS)
- device_caps = v4l2_cap.device_caps;
+ g_device_caps = v4l2_cap.device_caps;
else
- device_caps = v4l2_cap.capabilities;
+ g_device_caps = v4l2_cap.capabilities;
- if (!(device_caps & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) ||
- (device_caps & (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE))) {
- LOGW("[%s] is not a capture device 0x%x", glob_buf.gl_pathv[i], device_caps);
+ if (!(g_device_caps & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) ||
+ (g_device_caps & (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE))) {
+ LOGW("[%s] is not a capture device 0x%x", glob_buf.gl_pathv[i], g_device_caps);
close(device_fd);
continue;
}
- ret = _camera_get_device_info(device_count, device_fd,
+ ret = __camera_get_device_info(device_count, device_fd,
&device_info_list->device_info[device_count], glob_buf.gl_pathv[i]);
close(device_fd);
}
-static void *_camera_preview_handler_func(gpointer data)
+static int __camera_stop_stream(camera_hal_handle *handle, uint32_t buffer_count)
+{
+ int i = 0;
+ int ret = CAMERA_ERROR_NONE;
+
+ if (!handle) {
+ LOGE("NULL handle");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ LOGD("buffer count[%d]", buffer_count);
+
+ /* stream off */
+ ret = __camera_v4l2_stream(handle->device_fd, handle->v4l2_type, FALSE);
+
+ LOGD("stream off : 0x%x", ret);
+
+ /* munmap */
+ for (i = 0 ; i < buffer_count ; i++) {
+ if (handle->camera_buffers[i].planes[0].data != NULL) {
+ LOGW("munmap %p", handle->camera_buffers[i].planes[0].data);
+
+ munmap(handle->camera_buffers[i].planes[0].data, handle->camera_buffers[i].planes[0].size);
+
+ handle->camera_buffers[i].planes[0].data = 0;
+ handle->camera_buffers[i].planes[0].size = 0;
+ } else {
+ LOGW("NULL data [index %d]", i);
+ }
+ }
+
+ /* reqbufs 0 */
+ ret = __camera_v4l2_reqbufs(handle->device_fd,
+ handle->v4l2_type, V4L2_MEMORY_MMAP, 0, &buffer_count);
+
+ LOGD("reqbufs 0 : 0x%x", ret);
+
+ return ret;
+}
+
+
+static int __camera_start_stream(camera_hal_handle *handle, camera_format_t *format,
+ uint32_t request_buffer_count, uint32_t *result_buffer_count)
+{
+ int i = 0;
+ int ret = CAMERA_ERROR_NONE;
+ camera_buffer_t *buffer = NULL;
+ struct v4l2_buffer v4l2_buf;
+ struct v4l2_plane v4l2_planes[V4L2_PLANES_MAX];
+
+ if (!handle || !format || !result_buffer_count) {
+ LOGE("NULL param %p %p", handle, result_buffer_count);
+ return CAMERA_ERROR_INTERNAL;
+ }
+
+ /* request buffer */
+ ret = __camera_v4l2_reqbufs(handle->device_fd,
+ handle->v4l2_type, V4L2_MEMORY_MMAP, request_buffer_count, result_buffer_count);
+ if (ret != CAMERA_ERROR_NONE) {
+ g_mutex_unlock(&handle->lock);
+ return ret;
+ }
+
+ LOGD("buffer count : request %d -> result %d",
+ request_buffer_count, *result_buffer_count);
+
+ /* query buffer, mmap and qbuf */
+ for (i = 0 ; i < *result_buffer_count ; i++) {
+ memset(&v4l2_buf, 0x0, sizeof(struct v4l2_buffer));
+ memset(v4l2_planes, 0x0, sizeof(v4l2_planes));
+
+ v4l2_buf.type = handle->v4l2_type;
+ v4l2_buf.memory = V4L2_MEMORY_MMAP;
+ v4l2_buf.index = i;
+ v4l2_buf.m.planes = v4l2_planes;
+ v4l2_buf.length = handle->plane_num;
+
+ LOGD("%d", i);
+
+ if (ioctl(handle->device_fd, VIDIOC_QUERYBUF, &v4l2_buf) < 0) {
+ LOGE("[%d] query buf failed. errno %d", i, errno);
+ goto _START_STREAM_FAILED;
+ }
+
+ LOGD("%d", i);
+
+ buffer = &handle->camera_buffers[i];
+
+ LOGD("%d", i);
+
+ buffer->index = i;
+ buffer->format = format->stream_format;
+ buffer->resolution = format->stream_resolution;
+ buffer->total_size = v4l2_buf.length;
+ buffer->num_planes = handle->plane_num;
+ buffer->planes[0].size = v4l2_buf.length;
+ buffer->planes[0].data = mmap(0,
+ v4l2_buf.length,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ handle->device_fd,
+ v4l2_buf.m.offset);
+
+ LOGD("%d", i);
+
+ if (buffer->planes[0].data == MAP_FAILED) {
+ LOGE("[%d] mmap failed (errno %d)", i, errno);
+ goto _START_STREAM_FAILED;
+ }
+
+ LOGD("%d", i);
+
+ if (__camera_v4l2_qbuf(handle->device_fd, handle->v4l2_type, V4L2_MEMORY_MMAP, i) != CAMERA_ERROR_NONE) {
+ LOGE("[%d] qbuf failed (errno %d)", i, errno);
+ goto _START_STREAM_FAILED;
+ }
+
+ LOGD("%d", i);
+ }
+
+ /* stream on */
+ ret = __camera_v4l2_stream(handle->device_fd, handle->v4l2_type, TRUE);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("stream on failed");
+ goto _START_STREAM_FAILED;
+ }
+
+ return CAMERA_ERROR_NONE;
+
+_START_STREAM_FAILED:
+ __camera_stop_stream(handle, *result_buffer_count);
+ return ret;
+}
+
+
+static void *__camera_buffer_handler_func(gpointer data)
{
int index = 0;
camera_hal_handle *handle = (camera_hal_handle *)data;
/* run buffer thread */
g_mutex_lock(&handle->preview_cb_lock);
- while (handle->preview_cb_run) {
+ while (handle->buffer_thread_run) {
g_mutex_unlock(&handle->preview_cb_lock);
- if (_camera_v4l2_wait_frame(handle->device_fd, 5) != CAMERA_ERROR_NONE) {
+ if (__camera_v4l2_wait_frame(handle->device_fd, 5) != CAMERA_ERROR_NONE) {
LOGE("frame wait failed");
g_mutex_lock(&handle->preview_cb_lock);
break;
g_mutex_lock(&handle->preview_cb_lock);
- if (handle->preview_cb_run == FALSE) {
+ if (handle->buffer_thread_run == FALSE) {
LOGW("stop preview handler thread");
break;
}
- if (_camera_v4l2_dqbuf(handle->device_fd, handle->v4l2_type, V4L2_MEMORY_MMAP, &index) != CAMERA_ERROR_NONE) {
+ if (__camera_v4l2_dqbuf(handle->device_fd, handle->v4l2_type, V4L2_MEMORY_MMAP, &index) != CAMERA_ERROR_NONE) {
LOGE("dqbuf failed");
break;
}
handle->live_buffer_num++;
- LOGD("live buffer num %d", handle->live_buffer_num);
+ /*LOGD("live buffer num %d", handle->live_buffer_num);*/
g_mutex_unlock(&handle->preview_cb_lock);
if (handle->preview_cb) {
- ((camera_preview_frame_cb)handle->preview_cb)(&handle->preview_buffer[index], NULL, handle->preview_cb_data);
+ ((camera_preview_frame_cb)handle->preview_cb)(&handle->camera_buffers[index], NULL, handle->preview_cb_data);
} else {
LOGW("preview callback is NULL");
camera_release_preview_buffer((void *)handle, index);
}
-static void _camera_message_release_func(gpointer data)
+static void __camera_message_release_func(gpointer data)
{
camera_message_t *message = (camera_message_t *)data;
}
-void _camera_release_handle(camera_hal_handle *handle)
+static void __camera_release_handle(camera_hal_handle *handle)
{
if (!handle) {
LOGW("NULL handle");
g_cond_signal(&handle->message_cb_cond);
g_mutex_unlock(&handle->message_cb_lock);
g_thread_join(handle->message_thread);
- g_queue_free_full(handle->message_list, (GDestroyNotify)_camera_message_release_func);
+ g_queue_free_full(handle->message_list, (GDestroyNotify)__camera_message_release_func);
handle->message_list = NULL;
}
new_handle->device_fd = CAMERA_HAL_INITIAL_FD;
new_handle->state = CAMERA_STATE_INITIALIZED;
- ret = _camera_get_device_info_list();
+ ret = __camera_get_device_info_list();
if (ret != CAMERA_ERROR_NONE) {
LOGE("get device info failed");
goto _INIT_ERROR;
return CAMERA_ERROR_NONE;
_INIT_ERROR:
- _camera_release_handle(new_handle);
+ __camera_release_handle(new_handle);
return ret;
}
int camera_deinit(void *camera_handle)
{
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_INITIALIZED) {
g_mutex_unlock(&handle->lock);
- _camera_release_handle(handle);
+ __camera_release_handle(handle);
return CAMERA_ERROR_NONE;
}
return CAMERA_ERROR_INVALID_PARAMETER;
}
- ret = _camera_get_device_info_list();
+ ret = __camera_get_device_info_list();
if (ret != CAMERA_ERROR_NONE) {
LOGE("get device info failed");
return ret;
int ret = CAMERA_ERROR_NONE;
int device_fd = CAMERA_HAL_INITIAL_FD;
char *node_path = NULL;
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_INITIALIZED) {
goto _OPEN_DEVICE_DONE;
}
- if (device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
+ if (g_device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
handle->v4l2_type = V4L2_CAP_VIDEO_CAPTURE_MPLANE;
else
handle->v4l2_type = V4L2_CAP_VIDEO_CAPTURE;
int camera_close_device(void *camera_handle)
{
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_OPENED) {
int camera_add_message_callback(void *camera_handle, camera_message_cb callback, void *user_data, uint32_t *cb_id)
{
uint32_t i = 0;
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_OPENED) {
int camera_remove_message_callback(void *camera_handle, uint32_t cb_id)
{
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_OPENED) {
int ret = CAMERA_ERROR_NONE;
gboolean capability_check = FALSE;
guint32 fourcc = 0;
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
camera_device_info_t *device_info = NULL;
struct v4l2_format v4l2_fmt;
struct v4l2_streamparm v4l2_parm;
- if (!camera_handle) {
- LOGE("NULL handle");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- if (!format) {
- LOGE("NULL format");
+ if (!handle || !format) {
+ LOGE("NULL param %p %p", handle, format);
return CAMERA_ERROR_INVALID_PARAMETER;
}
return CAMERA_ERROR_INTERNAL;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_OPENED) {
}
/* S_FMT */
- ret = _camera_get_fourcc_plane_num(format->stream_format, &fourcc, &handle->plane_num);
+ ret = __camera_get_fourcc_plane_num(format->stream_format, &fourcc, &handle->plane_num);
if (ret != CAMERA_ERROR_NONE) {
LOGE("get fourcc failed [format %d]", format->stream_format);
g_mutex_unlock(&handle->lock);
int camera_get_preview_stream_format(void *camera_handle, camera_format_t *format)
{
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
- LOGE("NULL handle");
+ if (!handle || !format) {
+ LOGE("NULL param %p %p", handle, format);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- if (!format) {
- LOGE("NULL format");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
memcpy(format, &handle->preview_format, sizeof(camera_format_t));
int camera_start_preview(void *camera_handle, camera_preview_frame_cb callback, void *user_data)
{
- int i = 0;
int ret = 0;
- int result_count = 0;
- camera_hal_handle *handle = NULL;
- camera_buffer_t *buffer = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- struct v4l2_buffer v4l2_buf;
- struct v4l2_plane v4l2_planes[V4L2_PLANES_MAX];
-
- if (!camera_handle) {
- LOGE("NULL handle");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- if (!callback) {
- LOGE("NULL callback for preview");
+ if (!handle || !callback) {
+ LOGE("NULL param %p %p", handle, callback);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
if (handle->state != CAMERA_STATE_OPENED) {
return CAMERA_ERROR_INVALID_STATE;
}
- /* request buffer */
- ret = _camera_v4l2_reqbufs(handle->device_fd,
- handle->v4l2_type, V4L2_MEMORY_MMAP, PREVIEW_BUFFER_MAX, &result_count);
+ ret = __camera_start_stream(handle, &handle->preview_format, BUFFER_MAX, &handle->buffer_count);
if (ret != CAMERA_ERROR_NONE) {
+ LOGE("__camera_start_stream failed[0x%x]", ret);
g_mutex_unlock(&handle->lock);
return ret;
}
- LOGD("REQUESTED buffer count %d", result_count);
-
- handle->preview_buffer_num = result_count;
-
- /* query buffer, mmap and qbuf */
- for (i = 0 ; i < handle->preview_buffer_num ; i++) {
- memset(&v4l2_buf, 0x0, sizeof(struct v4l2_buffer));
- memset(v4l2_planes, 0x0, sizeof(v4l2_planes));
-
- v4l2_buf.type = handle->v4l2_type;
- v4l2_buf.memory = V4L2_MEMORY_MMAP;
- v4l2_buf.index = i;
- v4l2_buf.m.planes = v4l2_planes;
- v4l2_buf.length = handle->plane_num;
-
- if (ioctl(handle->device_fd, VIDIOC_QUERYBUF, &v4l2_buf) < 0) {
- LOGE("[%d] query buf failed. errno %d", i, errno);
- goto _START_PREVIEW_FAILED;
- }
-
- buffer = &handle->preview_buffer[i];
-
- buffer->index = i;
- buffer->format = handle->preview_format.stream_format;
- buffer->resolution = handle->preview_format.stream_resolution;
- buffer->total_size = v4l2_buf.length;
- buffer->num_planes = handle->plane_num;
- buffer->planes[0].size = v4l2_buf.length;
- buffer->planes[0].data = mmap(0,
- v4l2_buf.length,
- PROT_READ | PROT_WRITE,
- MAP_SHARED,
- handle->device_fd,
- v4l2_buf.m.offset);
- if (buffer->planes[0].data == MAP_FAILED) {
- LOGE("[%d] mmap failed. errno %d", i, errno);
- goto _START_PREVIEW_FAILED;
- }
- }
+ g_mutex_lock(&handle->preview_cb_lock);
- for (i = 0 ; i < handle->preview_buffer_num ; i++) {
- if (_camera_v4l2_qbuf(handle->device_fd, handle->v4l2_type, V4L2_MEMORY_MMAP, i) != CAMERA_ERROR_NONE) {
- LOGE("qbuf failed");
- goto _START_PREVIEW_FAILED;
- }
- }
+ handle->buffer_thread_run = TRUE;
- /* stream on */
- ret = _camera_v4l2_stream(handle->device_fd, handle->v4l2_type, TRUE);
- if (ret != CAMERA_ERROR_NONE) {
- LOGE("stream on failed");
- goto _START_PREVIEW_FAILED;
- }
+ handle->buffer_thread = g_thread_try_new("camera_hal_buffer_thread",
+ __camera_buffer_handler_func, (gpointer)handle, NULL);
+ if (!handle->buffer_thread) {
+ LOGE("failed to create buffer handler thread");
+ g_mutex_unlock(&handle->preview_cb_lock);
- g_mutex_lock(&handle->preview_cb_lock);
+ __camera_stop_stream(handle, handle->buffer_count);
- handle->preview_cb_run = TRUE;
+ g_mutex_unlock(&handle->lock);
- handle->preview_thread = g_thread_try_new("camera_hal_preview_thread",
- _camera_preview_handler_func, (gpointer)handle, NULL);
- if (!handle->preview_thread) {
- LOGE("failed to create preview callback thread");
- g_mutex_unlock(&handle->preview_cb_lock);
- goto _START_PREVIEW_FAILED;
+ return ret;
}
handle->preview_cb = callback;
g_mutex_unlock(&handle->lock);
return CAMERA_ERROR_NONE;
-
-_START_PREVIEW_FAILED:
- /* stream off */
- if (ioctl(handle->device_fd, VIDIOC_STREAMOFF, &handle->v4l2_type) < 0)
- LOGE("stream off failed. errno %d", errno);
-
- /* munmap */
- for (i = 0 ; i < handle->preview_buffer_num ; i++) {
- buffer = &handle->preview_buffer[i];
- if (buffer->planes[0].data != NULL &&
- buffer->planes[0].data != MAP_FAILED) {
- LOGW("munmap %p", buffer->planes[0].data);
- munmap(buffer->planes[0].data, buffer->planes[0].size);
- }
- memset(buffer, 0x0, sizeof(camera_buffer_t));
- }
-
- /* reqbufs 0 */
- if (_camera_v4l2_reqbufs(handle->device_fd,
- handle->v4l2_type, V4L2_MEMORY_MMAP, 0, &result_count) != CAMERA_ERROR_NONE)
- LOGE("reqbufs 0 failed");
-
- g_mutex_unlock(&handle->lock);
-
- return ret;
}
int camera_release_preview_buffer(void *camera_handle, int buffer_index)
{
int ret = CAMERA_ERROR_NONE;
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
- if (buffer_index >= handle->preview_buffer_num) {
+ if (buffer_index >= handle->buffer_count) {
LOGE("invalid buffer index %d", buffer_index);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- ret = _camera_v4l2_qbuf(handle->device_fd,
+ ret = __camera_v4l2_qbuf(handle->device_fd,
handle->v4l2_type, V4L2_MEMORY_MMAP, buffer_index);
g_mutex_lock(&handle->preview_cb_lock);
return ret;
}
+
int camera_stop_preview(void *camera_handle)
{
int ret = CAMERA_ERROR_NONE;
- int i = 0;
- int result_count = 0;
gint64 end_time;
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
+ if (!handle) {
LOGE("NULL handle");
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
LOGD("start");
g_mutex_lock(&handle->lock);
g_mutex_lock(&handle->preview_cb_lock);
- handle->preview_cb_run = FALSE;
+ handle->buffer_thread_run = FALSE;
while (handle->live_buffer_num > 0) {
LOGD("wait for live buffer [num %d]", handle->live_buffer_num);
g_mutex_unlock(&handle->preview_cb_lock);
- /* stream off */
- ret = _camera_v4l2_stream(handle->device_fd, handle->v4l2_type, FALSE);
-
- LOGD("stream off : 0x%x", ret);
-
- /* munmap */
- for (i = 0 ; i < handle->preview_buffer_num ; i++) {
- if (handle->preview_buffer[i].planes[0].data != NULL) {
- LOGW("munmap %p", handle->preview_buffer[i].planes[0].data);
-
- munmap(handle->preview_buffer[i].planes[0].data, handle->preview_buffer[i].planes[0].size);
-
- handle->preview_buffer[i].planes[0].data = 0;
- handle->preview_buffer[i].planes[0].size = 0;
- } else {
- LOGW("NULL data [index %d]", i);
- }
- }
-
- /* reqbufs 0 */
- ret = _camera_v4l2_reqbufs(handle->device_fd,
- handle->v4l2_type, V4L2_MEMORY_MMAP, 0, &result_count);
-
- LOGD("reqbufs 0 : 0x%x", ret);
+ ret = __camera_stop_stream(handle, handle->buffer_count);
/* wait for preview thread exit */
- g_thread_join(handle->preview_thread);
- handle->preview_thread = NULL;
+ g_thread_join(handle->buffer_thread);
+ handle->buffer_thread = NULL;
handle->state = CAMERA_STATE_OPENED;
- LOGD("stop preview done");
+ LOGD("stop preview done [0x%x]", ret);
g_mutex_unlock(&handle->lock);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* auto focus is not supported */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* auto focus is not supported */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
int camera_start_capture(void *camera_handle, camera_capture_cb callback, void *user_data)
{
if (!camera_handle || !callback) {
- LOGE("NULL handle %p or callback %p", camera_handle, callback);
+ LOGE("NULL param %p %p", camera_handle, callback);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* capture function is not supported */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* capture function is not supported */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
int camera_set_video_stream_format(void *camera_handle, camera_format_t *format)
{
- if (!camera_handle) {
- LOGE("NULL handle");
+ if (!camera_handle || !format) {
+ LOGE("NULL param %p %p", camera_handle, format);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- if (!format) {
- LOGE("NULL format");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* single stream device can not support video stream */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
int camera_get_video_stream_format(void *camera_handle, camera_format_t *format)
{
- if (!camera_handle) {
- LOGE("NULL handle");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- if (!format) {
- LOGE("NULL format");
+ if (!camera_handle || !format) {
+ LOGE("NULL param %p %p", camera_handle, format);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* single stream device can not support video stream */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
int camera_start_record(void *camera_handle, camera_video_frame_cb callback, void *user_data)
{
- if (!camera_handle) {
- LOGE("NULL handle");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- if (!callback) {
- LOGE("NULL callback for video");
+ if (!camera_handle || !callback) {
+ LOGE("NULL param %p %p", camera_handle, callback);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* single stream device can not support video stream */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* single stream device can not support video stream */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
return CAMERA_ERROR_INVALID_PARAMETER;
}
- LOGD("NOT SUPPORTED");
+ LOGE("NOT SUPPORTED");
/* single stream device can not support video stream */
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
int cid = 0;
int ctrl_ret = 0;
int set_value = 0;
- camera_hal_handle *handle = NULL;
-
- if (!camera_handle) {
- LOGE("NULL handle");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!value) {
- LOGE("invalid pointer : value");
+ if (!handle || !value) {
+ LOGE("NULL param %p %p", handle, value);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
set_value = *(int *)value;
g_mutex_lock(&handle->lock);
case CAMERA_COMMAND_TILT:
cid = V4L2_CID_TILT_ABSOLUTE;
break;
+ case CAMERA_COMMAND_FLIP:
+ g_mutex_unlock(&handle->lock);
+ if (set_value != CAMERA_FLIP_NONE) {
+ LOGE("NOT_SUPPORTED flip %d", set_value);
+ return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
+ } else {
+ return CAMERA_ERROR_NONE;
+ }
+ break;
default:
LOGE("NOT_SUPPORTED %"PRId64, command);
g_mutex_unlock(&handle->lock);
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
}
- ctrl_ret = _camera_v4l2_s_ctrl(handle->device_fd, cid, set_value);
+ ctrl_ret = __camera_v4l2_s_ctrl(handle->device_fd, cid, set_value);
if (ctrl_ret < 0) {
switch (errno) {
case EACCES:
int ret = CAMERA_ERROR_NONE;
int cid = 0;
int ctrl_ret = 0;
- camera_hal_handle *handle = NULL;
-
- if (!camera_handle) {
- LOGE("NULL handle");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!value) {
- LOGE("invalid pointer for value");
+ if (!handle || !value) {
+ LOGE("NULL param %p %p", handle, value);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
LOGD("get command %"PRId64" - state %d", command, handle->state);
return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
}
- ctrl_ret = _camera_v4l2_g_ctrl(handle->device_fd, cid, (int *)value);
+ ctrl_ret = __camera_v4l2_g_ctrl(handle->device_fd, cid, (int *)value);
if (ctrl_ret < 0) {
switch (errno) {
case EACCES:
int camera_set_batch_command(void *camera_handle, camera_batch_command_control_t *batch_command, int64_t *error_command)
{
- camera_hal_handle *handle = NULL;
+ camera_hal_handle *handle = (camera_hal_handle *)camera_handle;
- if (!camera_handle) {
- LOGE("NULL handle");
+ if (!handle || !batch_command) {
+ LOGE("NULL param %p %p", handle, batch_command);
return CAMERA_ERROR_INVALID_PARAMETER;
}
- if (!batch_command) {
- LOGE("invalid pointer for batch_command");
- return CAMERA_ERROR_INVALID_PARAMETER;
- }
-
- handle = (camera_hal_handle *)camera_handle;
-
g_mutex_lock(&handle->lock);
LOGD("set batch command - flag %"PRIx64", state %d",