4 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <sys/ioctl.h>
25 #include <sys/types.h>
36 #include "hal_camera_v4l2_private.h"
41 #define LOG_TAG "CAMERA_HAL"
43 #define TEST_JPEG_PATH "/home/owner/media/Images/test.jpg"
44 #define DEVICE_NODE_PATH_MAX 16
45 #define DEVICE_NODE_PATH_PREFIX "/dev/video"
46 #define FOURCC_FORMAT "%c%c%c%c"
47 #define FOURCC_CONVERT(fourcc) \
49 (fourcc >> 8) & 0xff,\
50 (fourcc >> 16) & 0xff,\
54 static camera_device_info_list_s *g_device_info_list;
55 static guint32 g_device_caps;
56 static GMutex g_device_info_lock;
59 static void __camera_hal_v4l2_destructor(void) __attribute__((destructor));
62 static void __camera_hal_v4l2_destructor(void)
64 LOGD("release device info list %p", g_device_info_list);
66 g_free(g_device_info_list);
67 g_device_info_list = NULL;
73 static int __camera_v4l2_wait_frame(int device_fd, int wait_time)
75 int ret = CAMERA_ERROR_NONE;
77 struct timeval timeout;
80 LOGE("invalid fd %d", device_fd);
81 return CAMERA_ERROR_INVALID_PARAMETER;
85 FD_SET(device_fd, &fds);
87 memset(&timeout, 0x0, sizeof(struct timeval));
89 timeout.tv_sec = wait_time;
92 /*LOGD("select : %d sec", wait_time);*/
94 ret = select(device_fd + 1, &fds, NULL, NULL, &timeout);
97 LOGD("select error : EINTR");
98 return CAMERA_ERROR_NONE;
100 LOGE("select failed. errno %d", errno);
101 return CAMERA_ERROR_INTERNAL;
105 LOGE("select timeout.");
106 return CAMERA_ERROR_INTERNAL;
109 /*LOGD("select done");*/
111 return CAMERA_ERROR_NONE;
115 static int __camera_v4l2_g_ctrl(int device_fd, int cid, int *value)
118 struct v4l2_control ctrl;
122 return CAMERA_ERROR_INVALID_PARAMETER;
125 memset(&ctrl, 0x0, sizeof(struct v4l2_control));
129 ret = ioctl(device_fd, VIDIOC_G_CTRL, &ctrl);
133 LOGD("G_CTRL id 0x%x, value %d, ret %d", cid, *value, ret);
139 static int __camera_v4l2_s_ctrl(int device_fd, int cid, int value)
142 struct v4l2_control ctrl;
144 memset(&ctrl, 0x0, sizeof(struct v4l2_control));
149 ret = ioctl(device_fd, VIDIOC_S_CTRL, &ctrl);
151 LOGD("S_CTRL id 0x%x, value %d, ret %d", cid, value, ret);
157 static int __camera_v4l2_stream(int device_fd, int type, gboolean onoff)
160 LOGE("invalid fd %d", device_fd);
161 return CAMERA_ERROR_INVALID_PARAMETER;
164 if (ioctl(device_fd, onoff ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type) < 0) {
165 LOGE("stream %d failed. [t:%d] errno %d", onoff, type, errno);
166 return CAMERA_ERROR_INTERNAL;
169 LOGD("stream %d done [t:%d]", onoff, type);
171 return CAMERA_ERROR_NONE;
175 static int __camera_v4l2_reqbufs(int device_fd, int type, int memory, uint32_t count, uint32_t *result_count)
177 struct v4l2_requestbuffers v4l2_reqbuf;
180 LOGE("invalid fd %d", device_fd);
181 return CAMERA_ERROR_INVALID_PARAMETER;
185 LOGE("NULL parameter");
186 return CAMERA_ERROR_INVALID_PARAMETER;
189 memset(&v4l2_reqbuf, 0x0, sizeof(struct v4l2_requestbuffers));
191 v4l2_reqbuf.type = type;
192 v4l2_reqbuf.memory = memory;
193 v4l2_reqbuf.count = count;
195 if (ioctl(device_fd, VIDIOC_REQBUFS, &v4l2_reqbuf) < 0) {
196 LOGE("REQBUFS[count %d] failed. errno %d", count, errno);
197 return CAMERA_ERROR_INTERNAL;
200 if (v4l2_reqbuf.count != count)
201 LOGW("different count [req:%d, result:%d]", count, v4l2_reqbuf.count);
203 *result_count = v4l2_reqbuf.count;
205 return CAMERA_ERROR_NONE;
209 static int __camera_v4l2_qbuf(int device_fd, int type, int memory, int index)
211 struct v4l2_buffer v4l2_buf;
212 struct v4l2_plane v4l2_planes[V4L2_PLANES_MAX];
215 LOGE("invalid fd %d", device_fd);
216 return CAMERA_ERROR_INVALID_PARAMETER;
219 memset(&v4l2_buf, 0x0, sizeof(struct v4l2_buffer));
220 memset(v4l2_planes, 0x0, sizeof(v4l2_planes));
222 v4l2_buf.index = index;
223 v4l2_buf.type = type;
224 v4l2_buf.memory = memory;
225 v4l2_buf.m.planes = v4l2_planes;
226 v4l2_buf.length = 460800;
227 v4l2_buf.bytesused = 460800;
229 if (ioctl(device_fd, VIDIOC_QBUF, &v4l2_buf) < 0) {
230 LOGE("qbuf failed. [i: %d, t: %d, m: %d] errno %d",
231 index, type, memory, errno);
232 return CAMERA_ERROR_INTERNAL;
235 /*LOGD("QBUF done [i: %d, t: %d, m: %d]", index, type, memory);*/
237 return CAMERA_ERROR_NONE;
241 static int __camera_v4l2_dqbuf(int device_fd, int type, int memory, int *index)
243 int ret = CAMERA_ERROR_NONE;
244 struct v4l2_buffer v4l2_buf;
245 struct v4l2_plane v4l2_planes[V4L2_PLANES_MAX];
248 LOGE("invalid fd %d", device_fd);
249 return CAMERA_ERROR_INVALID_PARAMETER;
253 LOGE("NULL parameter");
254 return CAMERA_ERROR_INVALID_PARAMETER;
257 memset(&v4l2_buf, 0x0, sizeof(struct v4l2_buffer));
258 memset(v4l2_planes, 0x0, sizeof(v4l2_planes));
260 v4l2_buf.type = type;
261 v4l2_buf.memory = memory;
262 v4l2_buf.m.planes = v4l2_planes;
264 ret = ioctl(device_fd, VIDIOC_DQBUF, &v4l2_buf);
267 LOGE("dqbuf failed. [t: %d, m: %d] errno %d",
268 type, memory, errno);
269 return CAMERA_ERROR_DEVICE_READ;
273 *index = v4l2_buf.index;
275 /*LOGD("dqbuf index %d", *index);*/
277 return CAMERA_ERROR_NONE;
281 static int __camera_get_format(guint32 fourcc, int *pixel_format)
284 LOGE("NULL parameter");
285 return CAMERA_ERROR_INVALID_PARAMETER;
289 case V4L2_PIX_FMT_NV12:
290 case V4L2_PIX_FMT_NV12M:
291 case V4L2_PIX_FMT_NV12MT:
292 *pixel_format = CAMERA_PIXEL_FORMAT_NV12;
294 case V4L2_PIX_FMT_NV21:
295 case V4L2_PIX_FMT_NV21M:
296 *pixel_format = CAMERA_PIXEL_FORMAT_NV21;
298 case V4L2_PIX_FMT_YUV420:
299 *pixel_format = CAMERA_PIXEL_FORMAT_I420;
301 case V4L2_PIX_FMT_YVU420:
302 *pixel_format = CAMERA_PIXEL_FORMAT_YV12;
304 case V4L2_PIX_FMT_YUYV:
305 *pixel_format = CAMERA_PIXEL_FORMAT_YUYV;
307 case V4L2_PIX_FMT_UYVY:
308 *pixel_format = CAMERA_PIXEL_FORMAT_UYVY;
310 case V4L2_PIX_FMT_JPEG:
311 *pixel_format = CAMERA_PIXEL_FORMAT_JPEG;
313 case V4L2_PIX_FMT_H264:
314 *pixel_format = CAMERA_PIXEL_FORMAT_H264;
317 LOGE("unknown fourcc "FOURCC_FORMAT, FOURCC_CONVERT(fourcc));
318 return CAMERA_ERROR_INTERNAL;
321 LOGD("fourcc "FOURCC_FORMAT" -> %d",
322 FOURCC_CONVERT(fourcc), *pixel_format);
324 return CAMERA_ERROR_NONE;
328 static int __camera_get_fourcc_plane_num(int pixel_format, guint32 *fourcc, guint32 *plane_num)
330 if (!fourcc || !plane_num) {
331 LOGE("NULL parameter %p %p", fourcc, plane_num);
332 return CAMERA_ERROR_INVALID_PARAMETER;
335 switch (pixel_format) {
336 case CAMERA_PIXEL_FORMAT_NV12:
337 *fourcc = V4L2_PIX_FMT_NV12;
340 case CAMERA_PIXEL_FORMAT_NV21:
341 *fourcc = V4L2_PIX_FMT_NV21;
344 case CAMERA_PIXEL_FORMAT_I420:
345 *fourcc = V4L2_PIX_FMT_YUV420;
348 case CAMERA_PIXEL_FORMAT_YV12:
349 *fourcc = V4L2_PIX_FMT_YVU420;
352 case CAMERA_PIXEL_FORMAT_YUYV:
353 *fourcc = V4L2_PIX_FMT_YUYV;
356 case CAMERA_PIXEL_FORMAT_UYVY:
357 *fourcc = V4L2_PIX_FMT_UYVY;
360 case CAMERA_PIXEL_FORMAT_JPEG:
361 *fourcc = V4L2_PIX_FMT_JPEG;
364 case CAMERA_PIXEL_FORMAT_H264:
365 *fourcc = V4L2_PIX_FMT_H264;
369 LOGE("unknown format %d", pixel_format);
370 return CAMERA_ERROR_INTERNAL;
373 LOGD("format %d -> fourcc "FOURCC_FORMAT,
374 pixel_format, FOURCC_CONVERT(*fourcc));
376 return CAMERA_ERROR_NONE;
380 static int __camera_get_device_info(int device_index, int device_fd, camera_device_info_s *device_info, char *node_path)
384 int format_count = 0;
385 int resolution_count = 0;
386 int camera_format = 0;
387 struct v4l2_fmtdesc v4l2_format;
388 struct v4l2_frmsizeenum v4l2_frame;
390 if (device_fd < 0 || !device_info || !node_path) {
391 LOGE("invalid param %d %p %p", device_fd, device_info, node_path);
392 return CAMERA_ERROR_INVALID_PARAMETER;
395 LOGD("Get Supported format and resolution");
397 for (i = 0 ; ; i++) {
398 memset(&v4l2_format, 0x0, sizeof(struct v4l2_fmtdesc));
400 v4l2_format.index = i;
401 v4l2_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
403 if (ioctl(device_fd, VIDIOC_ENUM_FMT, &v4l2_format) < 0) {
404 LOGW("\tformat : end of enumeration");
408 LOGD("\tformat[%d] "FOURCC_FORMAT, i, FOURCC_CONVERT(v4l2_format.pixelformat));
410 if (__camera_get_format(v4l2_format.pixelformat, &camera_format) != CAMERA_ERROR_NONE)
413 device_info->format_list.formats[format_count] = camera_format;
415 resolution_count = 0;
417 for (j = 0 ; ; j++) {
418 memset(&v4l2_frame, 0x0, sizeof(struct v4l2_frmsizeenum));
420 v4l2_frame.index = j;
421 v4l2_frame.pixel_format = v4l2_format.pixelformat;
423 if (ioctl(device_fd, VIDIOC_ENUM_FRAMESIZES, &v4l2_frame) < 0) {
424 LOGW("\t\tframe : end of enumeration ");
428 switch (v4l2_frame.type) {
429 case V4L2_FRMSIZE_TYPE_DISCRETE:
430 device_info->preview_list.resolutions[resolution_count].width = v4l2_frame.discrete.width;
431 device_info->preview_list.resolutions[resolution_count].height = v4l2_frame.discrete.height;
432 device_info->capture_list.resolutions[resolution_count].width = v4l2_frame.discrete.width;
433 device_info->capture_list.resolutions[resolution_count].height = v4l2_frame.discrete.height;
434 device_info->video_list.resolutions[resolution_count].width = v4l2_frame.discrete.width;
435 device_info->video_list.resolutions[resolution_count].height = v4l2_frame.discrete.height;
439 LOGD("\t\tsize[%d] %ux%u", j,
440 v4l2_frame.discrete.width,
441 v4l2_frame.discrete.height);
443 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
444 LOGW("\t\tsize[%d] %ux%u - %ux%u", j,
445 v4l2_frame.stepwise.min_width,
446 v4l2_frame.stepwise.min_height,
447 v4l2_frame.stepwise.max_width,
448 v4l2_frame.stepwise.max_height);
450 case V4L2_FRMSIZE_TYPE_STEPWISE:
451 LOGW("\t\tsize[%d] %ux%u - %ux%u (step %ux%u)", j,
452 v4l2_frame.stepwise.min_width,
453 v4l2_frame.stepwise.min_height,
454 v4l2_frame.stepwise.max_width,
455 v4l2_frame.stepwise.max_height,
456 v4l2_frame.stepwise.step_width,
457 v4l2_frame.stepwise.step_height);
460 LOGE("\t\tunknown frame type %d", v4l2_frame.type);
465 device_info->preview_list.count = resolution_count;
466 device_info->capture_list.count = resolution_count;
467 device_info->video_list.count = resolution_count;
469 LOGD("\t\tresolution count [%d]", resolution_count);
474 device_info->index = device_index;
475 device_info->format_list.count = format_count;
476 device_info->facing_direction = CAMERA_FACING_DIRECTION_EXTERNAL;
477 snprintf(device_info->name, sizeof(device_info->name), "V4L2_CAMERA");
478 snprintf(device_info->node_path, sizeof(device_info->node_path), "%s", node_path);
480 LOGD("\tformat count [%d]", format_count);
482 return CAMERA_ERROR_NONE;
486 static int __camera_get_device_info_list(void)
490 int device_count = 0;
491 int device_fd = CAMERA_HAL_INITIAL_FD;
493 struct v4l2_capability v4l2_cap;
494 camera_device_info_list_s *device_info_list = NULL;
496 g_mutex_lock(&g_device_info_lock);
498 if (g_device_info_list) {
499 LOGD("device info list is already existed");
500 ret = CAMERA_ERROR_NONE;
501 goto _GET_DEVICE_INFO_LIST_DONE;
504 device_info_list = g_new0(camera_device_info_list_s, 1);
505 if (!device_info_list) {
506 LOGE("failed to alloc device info structure");
507 ret = CAMERA_ERROR_OUT_OF_MEMORY;
508 goto _GET_DEVICE_INFO_LIST_DONE;
511 memset(&glob_buf, 0x0, sizeof(glob_t));
513 ret = glob(DEVICE_NODE_PATH_PREFIX"*", 0, 0, &glob_buf);
517 LOGE("out of memory");
518 ret = CAMERA_ERROR_OUT_OF_MEMORY;
519 goto _GET_DEVICE_INFO_LIST_DONE;
522 ret = CAMERA_ERROR_INTERNAL;
523 goto _GET_DEVICE_INFO_LIST_DONE;
525 LOGE("match not found");
526 ret = CAMERA_ERROR_INTERNAL;
527 goto _GET_DEVICE_INFO_LIST_DONE;
529 LOGE("unknown error : %d", ret);
530 ret = CAMERA_ERROR_INTERNAL;
531 goto _GET_DEVICE_INFO_LIST_DONE;
535 LOGD("device node count : %zu", glob_buf.gl_pathc);
537 for (i = 0 ; i < glob_buf.gl_pathc ; i++) {
538 LOGD("[%d] check device [%s]", i, glob_buf.gl_pathv[i]);
540 device_fd = open(glob_buf.gl_pathv[i], O_RDWR);
542 LOGE("open failed [%s] errno %d", glob_buf.gl_pathv[i], errno);
546 memset(&v4l2_cap, 0x0, sizeof(struct v4l2_capability));
548 if (ioctl(device_fd, VIDIOC_QUERYCAP, &v4l2_cap) < 0) {
549 LOGE("querycap failed. errno %d", errno);
554 if (v4l2_cap.capabilities & V4L2_CAP_DEVICE_CAPS)
555 g_device_caps = v4l2_cap.device_caps;
557 g_device_caps = v4l2_cap.capabilities;
559 if (!(g_device_caps & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) ||
560 (g_device_caps & (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE))) {
561 LOGW("[%s] is not a capture device 0x%x", glob_buf.gl_pathv[i], g_device_caps);
566 ret = __camera_get_device_info(device_count, device_fd,
567 &device_info_list->device_info[device_count], glob_buf.gl_pathv[i]);
571 if (ret == CAMERA_ERROR_NONE)
575 device_info_list->count = device_count;
576 g_device_info_list = device_info_list;
578 LOGD("new g_device_info_list %p - device count %d",
579 g_device_info_list, device_count);
581 _GET_DEVICE_INFO_LIST_DONE:
582 g_mutex_unlock(&g_device_info_lock);
583 LOGD("ret 0x%x", ret);
585 if (ret != CAMERA_ERROR_NONE)
586 g_free(device_info_list);
592 static int __camera_stop_stream(hal_camera_handle *handle, uint32_t buffer_count)
595 int ret = CAMERA_ERROR_NONE;
599 return CAMERA_ERROR_INVALID_PARAMETER;
602 LOGD("buffer count[%d]", buffer_count);
605 ret = __camera_v4l2_stream(handle->device_fd, handle->buffer_type, FALSE);
607 LOGD("stream off : 0x%x", ret);
610 for (i = 0 ; i < buffer_count ; i++) {
611 if (handle->camera_buffers[i].planes[0].data != NULL) {
612 LOGW("munmap %p", handle->camera_buffers[i].planes[0].data);
614 munmap(handle->camera_buffers[i].planes[0].data, handle->camera_buffers[i].planes[0].size);
616 handle->camera_buffers[i].planes[0].data = 0;
617 handle->camera_buffers[i].planes[0].size = 0;
619 LOGW("NULL data [index %d]", i);
624 ret = __camera_v4l2_reqbufs(handle->device_fd,
625 handle->buffer_type, V4L2_MEMORY_MMAP, 0, &buffer_count);
627 LOGD("reqbufs 0 : 0x%x", ret);
633 static int __camera_start_stream(hal_camera_handle *handle, camera_pixel_format_e pixel_format,
634 camera_resolution_s *resolution, uint32_t fps, uint32_t request_buffer_count)
637 int ret = CAMERA_ERROR_NONE;
638 camera_buffer_s *buffer = NULL;
639 struct v4l2_format v4l2_fmt;
640 struct v4l2_streamparm v4l2_parm;
641 struct v4l2_buffer v4l2_buf;
642 struct v4l2_plane v4l2_planes[V4L2_PLANES_MAX];;
644 guint32 plane_num = 0;
646 if (!handle || !resolution) {
647 LOGE("NULL param %p %p", handle, resolution);
648 return CAMERA_ERROR_INTERNAL;
652 ret = __camera_get_fourcc_plane_num(pixel_format, &fourcc, &plane_num);
653 if (ret != CAMERA_ERROR_NONE) {
654 LOGE("get fourcc failed [format %d]", pixel_format);
658 memset(&v4l2_fmt, 0x0, sizeof(struct v4l2_format));
660 v4l2_fmt.type = handle->buffer_type;
661 if (V4L2_TYPE_IS_MULTIPLANAR(handle->buffer_type)) {
662 v4l2_fmt.fmt.pix_mp.width = resolution->width;
663 v4l2_fmt.fmt.pix_mp.height = resolution->height;
664 v4l2_fmt.fmt.pix_mp.pixelformat = fourcc;
665 v4l2_fmt.fmt.pix_mp.num_planes = plane_num;
667 v4l2_fmt.fmt.pix.width = resolution->width;
668 v4l2_fmt.fmt.pix.height = resolution->height;
669 v4l2_fmt.fmt.pix.pixelformat = fourcc;
670 v4l2_fmt.fmt.pix.bytesperline = resolution->width;
673 if (ioctl(handle->device_fd, VIDIOC_S_FMT, &v4l2_fmt) < 0) {
674 LOGE("S_FMT failed. errno %d", errno);
675 return CAMERA_ERROR_INTERNAL;
678 if (V4L2_TYPE_IS_MULTIPLANAR(handle->buffer_type)) {
679 for (i = 0 ; i < v4l2_fmt.fmt.pix_mp.num_planes ; i++) {
680 LOGD("plane[%d] stride %u, sizeimage %u", i,
681 v4l2_fmt.fmt.pix_mp.plane_fmt[i].bytesperline,
682 v4l2_fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
685 LOGD("stride %d, sizeimage %d",
686 v4l2_fmt.fmt.pix.bytesperline,
687 v4l2_fmt.fmt.pix.sizeimage);
691 memset(&v4l2_parm, 0x0, sizeof(struct v4l2_streamparm));
693 v4l2_parm.type = handle->buffer_type;
695 if (ioctl(handle->device_fd, VIDIOC_G_PARM, &v4l2_parm) < 0) {
696 LOGE("G_PARM failed. errno %d", errno);
697 return CAMERA_ERROR_INTERNAL;
700 /* S_PARM to set fps */
701 v4l2_parm.parm.capture.timeperframe.numerator = 1;
702 v4l2_parm.parm.capture.timeperframe.denominator = fps;
704 if (ioctl(handle->device_fd, VIDIOC_S_PARM, &v4l2_parm) < 0) {
705 LOGE("S_PARM failed. errno %d", errno);
706 return CAMERA_ERROR_INTERNAL;
710 ret = __camera_v4l2_reqbufs(handle->device_fd,
711 handle->buffer_type, V4L2_MEMORY_MMAP, request_buffer_count, &handle->buffer_count);
712 if (ret != CAMERA_ERROR_NONE) {
716 LOGD("buffer count : request %d -> result %d",
717 request_buffer_count, handle->buffer_count);
719 /* query buffer, mmap and qbuf */
720 for (i = 0 ; i < handle->buffer_count ; i++) {
721 memset(&v4l2_buf, 0x0, sizeof(struct v4l2_buffer));
722 memset(v4l2_planes, 0x0, sizeof(v4l2_planes));
724 v4l2_buf.type = handle->buffer_type;
725 v4l2_buf.memory = V4L2_MEMORY_MMAP;
727 v4l2_buf.m.planes = v4l2_planes;
728 v4l2_buf.length = plane_num;
730 if (ioctl(handle->device_fd, VIDIOC_QUERYBUF, &v4l2_buf) < 0) {
731 LOGE("[%d] query buf failed. errno %d", i, errno);
732 goto _START_STREAM_FAILED;
735 buffer = &handle->camera_buffers[i];
738 buffer->format = pixel_format;
739 buffer->resolution.width = resolution->width;
740 buffer->resolution.height = resolution->height;
741 buffer->total_size = v4l2_buf.length;
742 buffer->num_planes = plane_num;
743 buffer->planes[0].size = v4l2_buf.length;
744 buffer->planes[0].data = mmap(0,
746 PROT_READ | PROT_WRITE,
751 if (buffer->planes[0].data == MAP_FAILED) {
752 LOGE("[%d] mmap failed (errno %d)", i, errno);
753 goto _START_STREAM_FAILED;
756 if (__camera_v4l2_qbuf(handle->device_fd, handle->buffer_type, V4L2_MEMORY_MMAP, i) != CAMERA_ERROR_NONE) {
757 LOGE("[%d] qbuf failed (errno %d)", i, errno);
758 goto _START_STREAM_FAILED;
763 ret = __camera_v4l2_stream(handle->device_fd, handle->buffer_type, TRUE);
764 if (ret != CAMERA_ERROR_NONE) {
765 LOGE("stream on failed");
766 goto _START_STREAM_FAILED;
769 return CAMERA_ERROR_NONE;
771 _START_STREAM_FAILED:
772 __camera_stop_stream(handle, handle->buffer_count);
777 static void __camera_do_capture(hal_camera_handle *handle)
779 int ret = CAMERA_ERROR_NONE;
780 int buffer_index = 0;
781 gint64 current_time = 0;
782 gint64 previous_time = 0;
783 gint64 interval_us = 0;
792 if (handle->capture_count > 1)
793 interval_us = handle->capture_interval_ms * 1000;
795 /* restart stream for capture */
796 if (handle->capture_restart_stream) {
797 ret = __camera_stop_stream(handle, handle->buffer_count);
798 if (ret != CAMERA_ERROR_NONE) {
799 LOGE("stop stream failed for capture[0x%x]", ret);
803 ret = __camera_start_stream(handle,
804 handle->preview_format.capture_format,
805 &handle->preview_format.capture_resolution,
806 handle->preview_format.stream_fps,
808 if (ret != CAMERA_ERROR_NONE) {
809 LOGE("start stream failed for capture[0x%x]", ret);
815 /* get capture buffer */
816 ret = __camera_v4l2_wait_frame(handle->device_fd, 5);
817 if (ret != CAMERA_ERROR_NONE) {
818 LOGE("frame wait failed for capture[0x%x]", ret);
822 ret = __camera_v4l2_dqbuf(handle->device_fd,
823 handle->buffer_type, V4L2_MEMORY_MMAP, &buffer_index);
824 if (ret != CAMERA_ERROR_NONE) {
825 LOGE("dqbuf failed for capture[0x%x]", ret);
829 if (handle->captured_count > 0) {
830 g_mutex_lock(&handle->buffer_lock);
831 if (handle->state != CAMERA_STATE_CAPTURING) {
832 LOGW("stop continuous capture");
833 handle->captured_count = handle->capture_count;
834 g_mutex_unlock(&handle->buffer_lock);
837 g_mutex_unlock(&handle->buffer_lock);
840 if (handle->capture_count > 1) {
841 current_time = g_get_monotonic_time();
843 LOGI("time[prev:%"PRId64", cur:%"PRId64"] interval[%"PRId64" us]",
844 previous_time, current_time, interval_us);
846 if (current_time < previous_time + interval_us)
850 g_mutex_lock(&handle->buffer_lock);
851 handle->captured_count++;
852 g_mutex_unlock(&handle->buffer_lock);
854 LOGD("capture cb[%p], buffer index[%d],count[%d]",
855 handle->capture_cb, buffer_index, handle->captured_count);
857 if (handle->capture_cb) {
858 handle->capture_cb(&handle->camera_buffers[buffer_index],
859 NULL, NULL, handle->capture_cb_data);
861 LOGW("capture callback is NULL");
862 /* Need to post error? */
865 previous_time = current_time;
868 ret = __camera_v4l2_qbuf(handle->device_fd,
869 handle->buffer_type, V4L2_MEMORY_MMAP, buffer_index);
870 if (ret != CAMERA_ERROR_NONE)
871 LOGE("qbuf failed for capture[0x%x]", ret);
872 } while (handle->captured_count < handle->capture_count);
874 g_mutex_lock(&handle->buffer_lock);
876 if (handle->state == CAMERA_STATE_CAPTURING) {
877 LOGD("wait for capture stop signal");
878 g_cond_wait(&handle->buffer_cond, &handle->buffer_lock);
879 LOGD("signal received");
881 LOGD("The state is already changed.");
884 g_mutex_unlock(&handle->buffer_lock);
887 /* restart stream for preview */
888 if (handle->capture_restart_stream) {
889 ret = __camera_stop_stream(handle, handle->buffer_count);
890 if (ret != CAMERA_ERROR_NONE)
891 LOGE("stop stream failed for preview[0x%x]", ret);
893 ret = __camera_start_stream(handle,
894 handle->preview_format.stream_format,
895 &handle->preview_format.stream_resolution,
896 handle->preview_format.stream_fps,
898 if (ret != CAMERA_ERROR_NONE)
899 LOGE("start stream failed for preview[0x%x]", ret);
906 static void *__camera_buffer_handler_func(gpointer data)
909 hal_camera_handle *handle = (hal_camera_handle *)data;
912 LOGE("NULL handle for buffer handler");
918 /* run buffer thread */
919 g_mutex_lock(&handle->buffer_lock);
921 while (handle->buffer_thread_run) {
922 g_mutex_unlock(&handle->buffer_lock);
924 if (__camera_v4l2_wait_frame(handle->device_fd, 5) != CAMERA_ERROR_NONE) {
925 LOGE("frame wait failed");
926 g_mutex_lock(&handle->buffer_lock);
930 g_mutex_lock(&handle->buffer_lock);
932 if (handle->buffer_thread_run == FALSE) {
933 LOGW("stop buffer handler thread");
937 if (__camera_v4l2_dqbuf(handle->device_fd, handle->buffer_type, V4L2_MEMORY_MMAP, &index) != CAMERA_ERROR_NONE) {
938 LOGE("dqbuf failed");
942 handle->buffer_dequeued_count++;
944 /*LOGD("dequeued buffer count %d", handle->buffer_dequeued_count);*/
946 g_mutex_unlock(&handle->buffer_lock);
948 if (handle->preview_cb) {
949 handle->preview_cb(&handle->camera_buffers[index], NULL, handle->preview_cb_data);
951 LOGW("preview callback is NULL");
952 camera_v4l2_release_preview_buffer((void *)handle, index);
955 g_mutex_lock(&handle->extra_preview_lock);
957 if (handle->extra_preview_cb) {
958 handle->extra_preview_cb(&handle->camera_buffers[index], NULL, 0, handle->extra_preview_cb_data);
959 handle->extra_preview_cb(&handle->camera_buffers[index], NULL, 1, handle->extra_preview_cb_data);
960 handle->extra_preview_cb(&handle->camera_buffers[index], NULL, 2, handle->extra_preview_cb_data);
961 handle->extra_preview_cb(&handle->camera_buffers[index], NULL, 3, handle->extra_preview_cb_data);
964 g_mutex_unlock(&handle->extra_preview_lock);
966 /* check capture request flag */
967 if (handle->capture_request) {
968 __camera_do_capture(handle);
969 handle->capture_request = FALSE;
974 g_mutex_lock(&handle->buffer_lock);
977 g_mutex_unlock(&handle->buffer_lock);
985 static void __camera_message_release_func(gpointer data)
987 camera_message_s *message = (camera_message_s *)data;
990 LOGW("NULL message");
994 LOGD("release message %p, type %d", message, message->type);
1002 static void *_camera_message_handler_func(gpointer data)
1005 camera_message_s *message = NULL;
1006 hal_camera_handle *handle = (hal_camera_handle *)data;
1009 LOGE("NULL handle for capture thread");
1013 LOGD("enter - message thread");
1015 g_mutex_lock(&handle->msg_cb_lock);
1017 while (handle->msg_cb_run) {
1018 if (g_queue_is_empty(handle->msg_list)) {
1019 LOGD("wait for message");
1020 g_cond_wait(&handle->msg_cb_cond, &handle->msg_cb_lock);
1021 LOGD("message signal received");
1024 if (!handle->msg_cb_run) {
1025 LOGW("break message thread");
1029 message = g_queue_pop_head(handle->msg_list);
1031 LOGW("NULL message");
1035 g_mutex_unlock(&handle->msg_cb_lock);
1037 for (i = 0 ; i < MESSAGE_CALLBACK_MAX ; i++) {
1038 if (handle->msg_cb[i]) {
1039 LOGD("call message callback type %d", message->type);
1040 handle->msg_cb[i](message, handle->msg_cb_data[i]);
1047 g_mutex_lock(&handle->msg_cb_lock);
1050 g_mutex_unlock(&handle->msg_cb_lock);
1052 LOGD("leave - message thread");
1058 static void __camera_release_handle(hal_camera_handle *handle)
1061 LOGW("NULL handle");
1065 if (handle->msg_thread) {
1066 g_mutex_lock(&handle->msg_cb_lock);
1067 handle->msg_cb_run = FALSE;
1068 g_cond_signal(&handle->msg_cb_cond);
1069 g_mutex_unlock(&handle->msg_cb_lock);
1070 g_thread_join(handle->msg_thread);
1071 g_queue_free_full(handle->msg_list, (GDestroyNotify)__camera_message_release_func);
1072 handle->msg_list = NULL;
1075 g_mutex_clear(&handle->lock);
1076 g_mutex_clear(&handle->buffer_lock);
1077 g_mutex_clear(&handle->msg_cb_lock);
1078 g_mutex_clear(&handle->extra_preview_lock);
1079 g_cond_clear(&handle->buffer_cond);
1080 g_cond_clear(&handle->msg_cb_cond);
1082 if (handle->bufmgr) {
1083 tbm_bufmgr_deinit(handle->bufmgr);
1084 handle->bufmgr = NULL;
1087 LOGD("camera HAL handle %p destroy", handle);
1095 int camera_v4l2_init(void **camera_handle)
1097 int ret = CAMERA_ERROR_NONE;
1098 hal_camera_handle *new_handle = NULL;
1099 tbm_bufmgr bufmgr = NULL;
1103 if (!camera_handle) {
1104 LOGE("NULL pointer for handle");
1105 return CAMERA_ERROR_INVALID_PARAMETER;
1108 bufmgr = tbm_bufmgr_init(-1);
1109 if (bufmgr == NULL) {
1110 LOGE("get tbm bufmgr failed");
1111 return CAMERA_ERROR_INTERNAL;
1114 new_handle = g_new0(hal_camera_handle, 1);
1116 LOGE("failed to alloc camera hal handle");
1117 tbm_bufmgr_deinit(bufmgr);
1118 return CAMERA_ERROR_OUT_OF_MEMORY;
1121 new_handle->bufmgr = bufmgr;
1123 g_mutex_init(&new_handle->lock);
1124 g_mutex_init(&new_handle->buffer_lock);
1125 g_mutex_init(&new_handle->msg_cb_lock);
1126 g_mutex_init(&new_handle->extra_preview_lock);
1127 g_cond_init(&new_handle->buffer_cond);
1128 g_cond_init(&new_handle->msg_cb_cond);
1130 /* message thread */
1131 new_handle->msg_list = g_queue_new();
1132 new_handle->msg_cb_run = TRUE;
1133 new_handle->msg_thread = g_thread_try_new("camera_hal_msg_thread",
1134 _camera_message_handler_func, (gpointer)new_handle, NULL);
1135 if (!new_handle->msg_thread) {
1136 LOGE("failed to create message thread");
1137 ret = CAMERA_ERROR_INTERNAL;
1141 new_handle->device_index = CAMERA_HAL_INITIAL_INDEX;
1142 new_handle->device_fd = CAMERA_HAL_INITIAL_FD;
1143 new_handle->state = CAMERA_STATE_INITIALIZED;
1145 ret = __camera_get_device_info_list();
1146 if (ret != CAMERA_ERROR_NONE) {
1147 LOGE("get device info failed");
1151 *camera_handle = new_handle;
1153 LOGD("camera HAL handle %p", new_handle);
1155 return CAMERA_ERROR_NONE;
1158 __camera_release_handle(new_handle);
1164 int camera_v4l2_deinit(void *camera_handle)
1166 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1169 LOGE("NULL handle");
1170 return CAMERA_ERROR_INVALID_PARAMETER;
1173 g_mutex_lock(&handle->lock);
1175 if (handle->state != CAMERA_STATE_INITIALIZED) {
1176 LOGE("invalid state %d, can not destroy handle", handle->state);
1177 g_mutex_unlock(&handle->lock);
1178 return CAMERA_ERROR_INVALID_STATE;
1181 g_mutex_unlock(&handle->lock);
1183 __camera_release_handle(handle);
1185 return CAMERA_ERROR_NONE;
1189 int camera_v4l2_get_device_info_list(camera_device_info_list_s *device_info_list)
1193 if (!device_info_list) {
1194 LOGE("NULL pointer for device_info_list");
1195 return CAMERA_ERROR_INVALID_PARAMETER;
1198 ret = __camera_get_device_info_list();
1199 if (ret != CAMERA_ERROR_NONE) {
1200 LOGE("get device info failed");
1204 memcpy(device_info_list, g_device_info_list, sizeof(camera_device_info_list_s));
1206 return CAMERA_ERROR_NONE;
1210 int camera_v4l2_open_device(void *camera_handle, int device_index)
1212 int ret = CAMERA_ERROR_NONE;
1213 int device_fd = CAMERA_HAL_INITIAL_FD;
1214 char *node_path = NULL;
1215 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1218 LOGE("NULL handle");
1219 return CAMERA_ERROR_INVALID_PARAMETER;
1222 g_mutex_lock(&handle->lock);
1224 if (handle->state != CAMERA_STATE_INITIALIZED) {
1225 LOGE("invalid state %d", handle->state);
1226 ret = CAMERA_ERROR_INVALID_STATE;
1227 goto _OPEN_DEVICE_DONE;
1230 if (!g_device_info_list) {
1231 LOGE("NO DEVICE INFO");
1232 ret = CAMERA_ERROR_INTERNAL;
1233 goto _OPEN_DEVICE_DONE;
1236 if (device_index >= g_device_info_list->count) {
1237 LOGE("invalid index %d [info:%d]", device_index, g_device_info_list->count);
1238 ret = CAMERA_ERROR_INVALID_PARAMETER;
1239 goto _OPEN_DEVICE_DONE;
1242 node_path = g_device_info_list->device_info[device_index].node_path;
1244 device_fd = open(node_path, O_RDWR);
1245 if (device_fd < 0) {
1249 ret = CAMERA_ERROR_PERMISSION_DENIED;
1252 ret = CAMERA_ERROR_DEVICE_NOT_FOUND;
1255 ret = CAMERA_ERROR_DEVICE_BUSY;
1258 ret = CAMERA_ERROR_DEVICE_OPEN;
1262 LOGE("open [%s] failed 0x%x [errno %d]",
1263 node_path, ret, errno);
1265 goto _OPEN_DEVICE_DONE;
1268 if (g_device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
1269 handle->buffer_type = V4L2_CAP_VIDEO_CAPTURE_MPLANE;
1271 handle->buffer_type = V4L2_CAP_VIDEO_CAPTURE;
1273 handle->state = CAMERA_STATE_OPENED;
1274 handle->device_index = device_index;
1275 handle->device_fd = device_fd;
1277 LOGD("[%d] device[%s] opened [fd %d, type %d]",
1278 device_index, node_path, device_fd, handle->buffer_type);
1281 g_mutex_unlock(&handle->lock);
1287 int camera_v4l2_open_device_ext(void *camera_handle, const char *device_name)
1289 LOGE("NOT SUPPORTED");
1290 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1294 int camera_v4l2_close_device(void *camera_handle)
1296 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1299 LOGE("NULL handle");
1300 return CAMERA_ERROR_INVALID_PARAMETER;
1303 g_mutex_lock(&handle->lock);
1305 if (handle->state != CAMERA_STATE_OPENED) {
1306 LOGE("invalid state %d", handle->state);
1307 g_mutex_unlock(&handle->lock);
1308 return CAMERA_ERROR_INVALID_STATE;
1311 if (handle->device_fd >= 0) {
1312 LOGD("close fd %d", handle->device_fd);
1314 close(handle->device_fd);
1315 handle->device_fd = CAMERA_HAL_INITIAL_FD;
1317 LOGW("invalid fd %d", handle->device_fd);
1320 handle->state = CAMERA_STATE_INITIALIZED;
1322 LOGD("device [%d] closed", handle->device_index);
1324 g_mutex_unlock(&handle->lock);
1326 return CAMERA_ERROR_NONE;
1330 int camera_v4l2_add_message_callback(void *camera_handle, hal_camera_message_cb callback, void *user_data, uint32_t *cb_id)
1333 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1336 LOGE("NULL handle");
1337 return CAMERA_ERROR_INVALID_PARAMETER;
1340 if (!callback || !cb_id) {
1341 LOGE("NULL pointer for callback %p or cb_id %p", callback, cb_id);
1342 return CAMERA_ERROR_INVALID_PARAMETER;
1345 g_mutex_lock(&handle->lock);
1347 if (handle->state != CAMERA_STATE_OPENED) {
1348 LOGE("invalid state %d", handle->state);
1349 g_mutex_unlock(&handle->lock);
1350 return CAMERA_ERROR_INVALID_STATE;
1353 for (i = 0 ; i < MESSAGE_CALLBACK_MAX ; i++) {
1354 if (handle->msg_cb[i] == NULL) {
1355 handle->msg_cb[i] = callback;
1356 handle->msg_cb_data[i] = user_data;
1358 LOGD("message cb [%p] added, user data %p - id %u", callback, user_data, i);
1359 g_mutex_unlock(&handle->lock);
1360 return CAMERA_ERROR_NONE;
1364 g_mutex_unlock(&handle->lock);
1366 LOGE("no available message cb slot");
1368 return CAMERA_ERROR_INTERNAL;
1372 int camera_v4l2_remove_message_callback(void *camera_handle, uint32_t cb_id)
1374 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1377 LOGE("NULL handle");
1378 return CAMERA_ERROR_INVALID_PARAMETER;
1381 if (cb_id >= MESSAGE_CALLBACK_MAX) {
1382 LOGE("invalid cb_id %u", cb_id);
1383 return CAMERA_ERROR_INVALID_PARAMETER;
1386 g_mutex_lock(&handle->lock);
1388 if (handle->state != CAMERA_STATE_OPENED) {
1389 LOGE("invalid state %d", handle->state);
1390 g_mutex_unlock(&handle->lock);
1391 return CAMERA_ERROR_INVALID_STATE;
1394 if (handle->msg_cb[cb_id]) {
1395 LOGD("remove message callback %p, user data %p - cb_id %u",
1396 handle->msg_cb[cb_id], handle->msg_cb_data[cb_id], cb_id);
1398 handle->msg_cb[cb_id] = NULL;
1399 handle->msg_cb_data[cb_id] = NULL;
1401 LOGE("already removed message cb");
1402 g_mutex_unlock(&handle->lock);
1403 return CAMERA_ERROR_INTERNAL;
1406 g_mutex_unlock(&handle->lock);
1408 return CAMERA_ERROR_NONE;
1412 int camera_v4l2_set_preview_stream_format(void *camera_handle, camera_format_s *format)
1416 int ret = CAMERA_ERROR_NONE;
1417 gboolean capability_check = FALSE;
1418 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1419 camera_device_info_s *device_info = NULL;
1421 if (!handle || !format) {
1422 LOGE("NULL param %p %p", handle, format);
1423 return CAMERA_ERROR_INVALID_PARAMETER;
1426 if (!g_device_info_list) {
1427 LOGE("no device info list");
1428 return CAMERA_ERROR_INTERNAL;
1431 g_mutex_lock(&handle->lock);
1433 if (handle->state != CAMERA_STATE_OPENED &&
1434 handle->state != CAMERA_STATE_PREVIEWING) {
1435 LOGE("invalid state %d", handle->state);
1436 g_mutex_unlock(&handle->lock);
1437 return CAMERA_ERROR_INVALID_STATE;
1440 /* check capability */
1441 device_info = &g_device_info_list->device_info[handle->device_index];
1444 for (i = 0 ; i < device_info->format_list.count ; i++) {
1445 if (format->stream_format == device_info->format_list.formats[i]) {
1446 LOGD("format matched %d, check resolution.", format->stream_format);
1449 for (j = 0 ; j < device_info->preview_list.count ; j++) {
1450 if (format->stream_resolution.width == device_info->preview_list.resolutions[j].width &&
1451 format->stream_resolution.height == device_info->preview_list.resolutions[j].height) {
1452 LOGD("resolution matched %dx%d",
1453 format->stream_resolution.width,
1454 format->stream_resolution.height);
1455 capability_check = TRUE;
1464 if (!capability_check) {
1465 LOGE("capability failed - %d, %dx%d",
1466 format->stream_format,
1467 format->stream_resolution.width,
1468 format->stream_resolution.height);
1469 g_mutex_unlock(&handle->lock);
1470 return CAMERA_ERROR_INVALID_PARAMETER;
1473 /* compare with current settings */
1474 if (handle->state == CAMERA_STATE_PREVIEWING) {
1475 if (handle->preview_format.stream_format == format->stream_format &&
1476 handle->preview_format.stream_resolution.width == format->stream_resolution.width &&
1477 handle->preview_format.stream_resolution.height == format->stream_resolution.height &&
1478 handle->preview_format.stream_fps == format->stream_fps &&
1479 handle->preview_format.stream_rotation == format->stream_rotation) {
1480 LOGD("no need to restart preview stream");
1481 goto _SET_PREVIEW_STREAM_FORMAT_DONE;
1484 LOGD("Preview setting is changed. Restart preview now.");
1486 /* stop preview stream to change it */
1487 ret = __camera_stop_stream(handle, handle->buffer_count);
1488 if (ret != CAMERA_ERROR_NONE) {
1489 LOGE("failed to stop stream");
1490 g_mutex_unlock(&handle->lock);
1494 /* restart preview stream to change it */
1495 ret = __camera_start_stream(handle,
1496 format->stream_format,
1497 &format->stream_resolution,
1500 if (ret != CAMERA_ERROR_NONE) {
1501 LOGE("failed to start stream");
1502 g_mutex_unlock(&handle->lock);
1507 _SET_PREVIEW_STREAM_FORMAT_DONE:
1508 /* set capture restart flag */
1509 if (format->stream_format == format->capture_format &&
1510 format->stream_resolution.width == format->capture_resolution.width &&
1511 format->stream_resolution.height == format->capture_resolution.height)
1512 handle->capture_restart_stream = FALSE;
1514 handle->capture_restart_stream = TRUE;
1516 memcpy(&handle->preview_format, format, sizeof(camera_format_s));
1518 LOGD("set format PREVIEW[%d:%dx%d,fps:%d], CAPTURE[%d:%dx%d,restart:%d]",
1519 format->stream_format,
1520 format->stream_resolution.width,
1521 format->stream_resolution.height,
1523 format->capture_format,
1524 format->capture_resolution.width,
1525 format->capture_resolution.height,
1526 handle->capture_restart_stream);
1528 g_mutex_unlock(&handle->lock);
1530 return CAMERA_ERROR_NONE;
1534 int camera_v4l2_get_preview_stream_format(void *camera_handle, camera_format_s *format)
1536 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1538 if (!handle || !format) {
1539 LOGE("NULL param %p %p", handle, format);
1540 return CAMERA_ERROR_INVALID_PARAMETER;
1543 g_mutex_lock(&handle->lock);
1545 memcpy(format, &handle->preview_format, sizeof(camera_format_s));
1547 LOGD("get stream format %d, %dx%d", format->stream_format,
1548 format->stream_resolution.width, format->stream_resolution.height);
1550 g_mutex_unlock(&handle->lock);
1552 return CAMERA_ERROR_NONE;
1556 int camera_v4l2_set_user_buffer_fd(void *camera_handle, int *fds, int number)
1558 LOGE("NOT SUPPORTED");
1559 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1563 int camera_v4l2_start_preview(void *camera_handle, hal_camera_preview_frame_cb callback, void *user_data)
1566 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1568 if (!handle || !callback) {
1569 LOGE("NULL param %p %p", handle, callback);
1570 return CAMERA_ERROR_INVALID_PARAMETER;
1573 g_mutex_lock(&handle->lock);
1575 if (handle->state != CAMERA_STATE_OPENED) {
1576 LOGE("invalid state %d", handle->state);
1577 g_mutex_unlock(&handle->lock);
1578 return CAMERA_ERROR_INVALID_STATE;
1581 ret = __camera_start_stream(handle,
1582 handle->preview_format.stream_format,
1583 &handle->preview_format.stream_resolution,
1584 handle->preview_format.stream_fps,
1586 if (ret != CAMERA_ERROR_NONE) {
1587 LOGE("__camera_start_stream failed[0x%x]", ret);
1588 g_mutex_unlock(&handle->lock);
1592 g_mutex_lock(&handle->buffer_lock);
1594 handle->buffer_thread_run = TRUE;
1596 handle->buffer_thread = g_thread_try_new("camera_hal_buffer_thread",
1597 __camera_buffer_handler_func, (gpointer)handle, NULL);
1598 if (!handle->buffer_thread) {
1599 LOGE("failed to create buffer handler thread");
1600 g_mutex_unlock(&handle->buffer_lock);
1602 __camera_stop_stream(handle, handle->buffer_count);
1604 g_mutex_unlock(&handle->lock);
1609 handle->preview_cb = callback;
1610 handle->preview_cb_data = user_data;
1612 g_mutex_unlock(&handle->buffer_lock);
1614 handle->state = CAMERA_STATE_PREVIEWING;
1616 LOGD("start preview done");
1618 g_mutex_unlock(&handle->lock);
1620 return CAMERA_ERROR_NONE;
1624 int camera_v4l2_release_preview_buffer(void *camera_handle, int buffer_index)
1626 int ret = CAMERA_ERROR_NONE;
1627 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1630 LOGE("NULL handle");
1631 return CAMERA_ERROR_INVALID_PARAMETER;
1634 if (buffer_index >= handle->buffer_count) {
1635 LOGE("invalid buffer index %d", buffer_index);
1636 return CAMERA_ERROR_INVALID_PARAMETER;
1639 ret = __camera_v4l2_qbuf(handle->device_fd,
1640 handle->buffer_type, V4L2_MEMORY_MMAP, buffer_index);
1642 g_mutex_lock(&handle->buffer_lock);
1644 if (ret == CAMERA_ERROR_NONE) {
1645 if (handle->buffer_dequeued_count > 0)
1646 handle->buffer_dequeued_count--;
1648 LOGW("invalid dequeued buffer count[%u]", handle->buffer_dequeued_count);
1650 /*LOGD("qbud done : index %d, dequeued buffer count %d",
1651 buffer_index, handle->buffer_dequeued_count);*/
1653 LOGE("qbuf failed [index %d]", buffer_index);
1656 g_cond_signal(&handle->buffer_cond);
1658 g_mutex_unlock(&handle->buffer_lock);
1664 int camera_v4l2_stop_preview(void *camera_handle)
1666 int ret = CAMERA_ERROR_NONE;
1668 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1671 LOGE("NULL handle");
1672 return CAMERA_ERROR_INVALID_PARAMETER;
1677 g_mutex_lock(&handle->lock);
1679 if (handle->state != CAMERA_STATE_PREVIEWING) {
1680 LOGE("invalid state %d", handle->state);
1681 g_mutex_unlock(&handle->lock);
1682 return CAMERA_ERROR_INVALID_STATE;
1685 g_mutex_lock(&handle->buffer_lock);
1687 handle->buffer_thread_run = FALSE;
1689 while (handle->buffer_dequeued_count > 0) {
1690 LOGD("wait for dequeued buffer [%d]", handle->buffer_dequeued_count);
1691 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
1692 if (!g_cond_wait_until(&handle->buffer_cond, &handle->buffer_lock, end_time)) {
1693 LOGE("buffer wait failed");
1696 LOGD("signal received. check again...");
1700 g_mutex_unlock(&handle->buffer_lock);
1702 ret = __camera_stop_stream(handle, handle->buffer_count);
1704 /* wait for preview thread exit */
1705 g_thread_join(handle->buffer_thread);
1706 handle->buffer_thread = NULL;
1708 handle->state = CAMERA_STATE_OPENED;
1710 LOGD("stop preview done [0x%x]", ret);
1712 g_mutex_unlock(&handle->lock);
1714 return CAMERA_ERROR_NONE;
1718 int camera_v4l2_start_auto_focus(void *camera_handle)
1720 if (!camera_handle) {
1721 LOGE("NULL handle");
1722 return CAMERA_ERROR_INVALID_PARAMETER;
1725 LOGE("NOT SUPPORTED");
1727 /* auto focus is not supported */
1728 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1732 int camera_v4l2_stop_auto_focus(void *camera_handle)
1734 if (!camera_handle) {
1735 LOGE("NULL handle");
1736 return CAMERA_ERROR_INVALID_PARAMETER;
1739 LOGE("NOT SUPPORTED");
1741 /* auto focus is not supported */
1742 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1746 int camera_v4l2_start_capture(void *camera_handle, hal_camera_capture_cb callback, void *user_data)
1748 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1750 if (!handle || !callback) {
1751 LOGE("NULL param %p %p", camera_handle, callback);
1752 return CAMERA_ERROR_INVALID_PARAMETER;
1755 g_mutex_lock(&handle->lock);
1757 if (handle->state != CAMERA_STATE_PREVIEWING) {
1758 LOGE("invalid state %d", handle->state);
1759 g_mutex_unlock(&handle->lock);
1760 return CAMERA_ERROR_INVALID_STATE;
1763 /* set callback and user data */
1764 handle->capture_cb = callback;
1765 handle->capture_cb_data = user_data;
1767 /* reset captured count */
1768 handle->captured_count = 0;
1770 LOGD("start capture - count %u", handle->capture_count);
1772 /* set capture request flag */
1773 handle->capture_request = TRUE;
1775 handle->state = CAMERA_STATE_CAPTURING;
1777 g_mutex_unlock(&handle->lock);
1779 return CAMERA_ERROR_NONE;
1783 int camera_v4l2_stop_capture(void *camera_handle)
1785 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1788 LOGE("NULL handle");
1789 return CAMERA_ERROR_INVALID_PARAMETER;
1792 g_mutex_lock(&handle->lock);
1794 if (handle->state != CAMERA_STATE_CAPTURING) {
1795 LOGE("invalid state %d", handle->state);
1796 g_mutex_unlock(&handle->lock);
1797 return CAMERA_ERROR_INVALID_STATE;
1800 g_mutex_lock(&handle->buffer_lock);
1802 if (handle->captured_count == 0) {
1803 LOGE("No captured image yet.");
1804 g_mutex_unlock(&handle->buffer_lock);
1805 g_mutex_unlock(&handle->lock);
1806 return CAMERA_ERROR_INTERNAL;
1809 LOGD("send signal to start preview after capture");
1811 g_cond_signal(&handle->buffer_cond);
1812 g_mutex_unlock(&handle->buffer_lock);
1814 handle->state = CAMERA_STATE_PREVIEWING;
1816 g_mutex_unlock(&handle->lock);
1818 return CAMERA_ERROR_NONE;
1822 int camera_v4l2_set_video_stream_format(void *camera_handle, camera_format_s *format)
1824 if (!camera_handle || !format) {
1825 LOGE("NULL param %p %p", camera_handle, format);
1826 return CAMERA_ERROR_INVALID_PARAMETER;
1829 LOGE("NOT SUPPORTED");
1831 /* single stream device can not support video stream */
1832 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1836 int camera_v4l2_get_video_stream_format(void *camera_handle, camera_format_s *format)
1838 if (!camera_handle || !format) {
1839 LOGE("NULL param %p %p", camera_handle, format);
1840 return CAMERA_ERROR_INVALID_PARAMETER;
1843 LOGE("NOT SUPPORTED");
1845 /* single stream device can not support video stream */
1846 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1850 int camera_v4l2_start_record(void *camera_handle, hal_camera_video_frame_cb callback, void *user_data)
1852 if (!camera_handle || !callback) {
1853 LOGE("NULL param %p %p", camera_handle, callback);
1854 return CAMERA_ERROR_INVALID_PARAMETER;
1857 LOGE("NOT SUPPORTED");
1859 /* single stream device can not support video stream */
1860 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1864 int camera_v4l2_release_video_buffer(void *camera_handle, int buffer_index)
1866 if (!camera_handle) {
1867 LOGE("NULL handle");
1868 return CAMERA_ERROR_INVALID_PARAMETER;
1871 LOGE("NOT SUPPORTED");
1873 /* single stream device can not support video stream */
1874 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1878 int camera_v4l2_stop_record(void *camera_handle)
1880 if (!camera_handle) {
1881 LOGE("NULL handle");
1882 return CAMERA_ERROR_INVALID_PARAMETER;
1885 LOGE("NOT SUPPORTED");
1887 /* single stream device can not support video stream */
1888 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1892 int camera_v4l2_set_extra_preview_frame_cb(void *camera_handle, hal_camera_extra_preview_frame_cb callback, void *user_data)
1894 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1897 LOGE("NULL handle");
1898 return CAMERA_ERROR_INVALID_PARAMETER;
1901 g_mutex_lock(&handle->extra_preview_lock);
1903 handle->extra_preview_cb = callback;
1904 handle->extra_preview_cb_data = user_data;
1906 g_mutex_unlock(&handle->extra_preview_lock);
1910 return CAMERA_ERROR_NONE;
1914 int camera_v4l2_unset_extra_preview_frame_cb(void *camera_handle)
1916 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1919 LOGE("NULL handle");
1920 return CAMERA_ERROR_INVALID_PARAMETER;
1923 g_mutex_lock(&handle->extra_preview_lock);
1925 handle->extra_preview_cb = NULL;
1926 handle->extra_preview_cb_data = NULL;
1928 g_mutex_unlock(&handle->extra_preview_lock);
1932 return CAMERA_ERROR_NONE;
1936 int camera_v4l2_release_extra_preview_buffer(void *camera_handle, int stream_id, int buffer_index)
1938 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
1941 LOGE("NULL handle");
1942 return CAMERA_ERROR_INVALID_PARAMETER;
1945 LOGI("done - stream_id[%d], index[%d]", stream_id, buffer_index);
1947 return CAMERA_ERROR_NONE;
1951 static int __set_command(hal_camera_handle *handle, int64_t command, void *value)
1957 if (!handle || !value) {
1958 LOGE("NULL param %p %p", handle, value);
1959 return CAMERA_ERROR_INVALID_PARAMETER;
1962 set_value = *(int *)value;
1964 if (handle->state < CAMERA_STATE_OPENED) {
1965 LOGE("invalid state %d", handle->state);
1966 return CAMERA_ERROR_INVALID_STATE;
1969 LOGD("set command %"PRIx64" - state %d", command, handle->state);
1972 case CAMERA_COMMAND_BRIGHTNESS:
1973 cid = V4L2_CID_BRIGHTNESS;
1975 case CAMERA_COMMAND_CONTRAST:
1976 cid = V4L2_CID_CONTRAST;
1978 case CAMERA_COMMAND_SATURATION:
1979 cid = V4L2_CID_SATURATION;
1981 case CAMERA_COMMAND_SHARPNESS:
1982 cid = V4L2_CID_SHARPNESS;
1984 case CAMERA_COMMAND_PTZ_TYPE:
1985 if (set_value != CAMERA_PTZ_TYPE_ELECTRONIC) {
1986 LOGE("not supported PTZ type %d", set_value);
1987 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
1989 return CAMERA_ERROR_NONE;
1990 case CAMERA_COMMAND_PAN:
1991 cid = V4L2_CID_PAN_ABSOLUTE;
1993 case CAMERA_COMMAND_TILT:
1994 cid = V4L2_CID_TILT_ABSOLUTE;
1996 case CAMERA_COMMAND_FLIP:
1997 if (set_value != CAMERA_FLIP_NONE) {
1998 LOGE("NOT_SUPPORTED flip %d", set_value);
1999 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
2001 return CAMERA_ERROR_NONE;
2002 case CAMERA_COMMAND_CAPTURE_COUNT:
2003 handle->capture_count = set_value;
2004 LOGI("capture count %u", handle->capture_count);
2005 return CAMERA_ERROR_NONE;
2006 case CAMERA_COMMAND_CAPTURE_INTERVAL:
2007 handle->capture_interval_ms = set_value;
2008 LOGI("capture interval %u ms", handle->capture_interval_ms);
2009 return CAMERA_ERROR_NONE;
2010 case CAMERA_COMMAND_FOCUS_MODE:
2011 LOGI("set focus mode [old:%d -> new:%d]", handle->focus_mode, set_value);
2012 handle->focus_mode = set_value;
2013 return CAMERA_ERROR_NONE;
2014 case CAMERA_COMMAND_FOCUS_RANGE:
2015 LOGI("set focus range [old:%d -> new:%d]", handle->focus_range, set_value);
2016 handle->focus_range = set_value;
2017 return CAMERA_ERROR_NONE;
2018 case CAMERA_COMMAND_FOCUS_LEVEL:
2019 LOGI("set focus level [old:%d -> new:%d]", handle->focus_level, set_value);
2020 handle->focus_level = set_value;
2021 return CAMERA_ERROR_NONE;
2023 LOGE("NOT_SUPPORTED command %"PRIx64, command);
2024 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
2027 ctrl_ret = __camera_v4l2_s_ctrl(handle->device_fd, cid, set_value);
2032 LOGE("Permission denied %d", errno);
2033 return CAMERA_ERROR_PERMISSION_DENIED;
2035 LOGE("Invalid argument");
2036 return CAMERA_ERROR_INVALID_PARAMETER;
2038 LOGE("Device busy");
2039 return CAMERA_ERROR_DEVICE_BUSY;
2041 LOGE("Not supported");
2042 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
2044 LOGE("Unknown errro %d", errno);
2045 return CAMERA_ERROR_INTERNAL;
2049 return CAMERA_ERROR_NONE;
2053 int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
2055 int ret = CAMERA_ERROR_NONE;
2056 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
2058 g_mutex_lock(&handle->lock);
2060 ret = __set_command(handle, command, value);
2062 g_mutex_unlock(&handle->lock);
2068 int camera_v4l2_get_command(void *camera_handle, int64_t command, void **value)
2070 int ret = CAMERA_ERROR_NONE;
2073 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
2075 if (!handle || !value) {
2076 LOGE("NULL param %p %p", handle, value);
2077 return CAMERA_ERROR_INVALID_PARAMETER;
2080 g_mutex_lock(&handle->lock);
2082 LOGD("get command %"PRIx64" - state %d", command, handle->state);
2085 case CAMERA_COMMAND_BRIGHTNESS:
2086 cid = V4L2_CID_BRIGHTNESS;
2088 case CAMERA_COMMAND_CONTRAST:
2089 cid = V4L2_CID_CONTRAST;
2091 case CAMERA_COMMAND_SATURATION:
2092 cid = V4L2_CID_SATURATION;
2094 case CAMERA_COMMAND_SHARPNESS:
2095 cid = V4L2_CID_SHARPNESS;
2097 case CAMERA_COMMAND_FOCUS_MODE:
2098 **(int **)value = handle->focus_mode;
2099 LOGI("get focus mode %d", **(int **)value);
2100 goto _GET_COMMAND_DONE;
2101 case CAMERA_COMMAND_FOCUS_RANGE:
2102 **(int **)value = handle->focus_range;
2103 LOGI("get focus range %d", **(int **)value);
2104 goto _GET_COMMAND_DONE;
2105 case CAMERA_COMMAND_FOCUS_LEVEL:
2106 **(int **)value = handle->focus_level;
2107 LOGI("get focus level %d", **(int **)value);
2108 goto _GET_COMMAND_DONE;
2110 LOGE("NOT_SUPPORTED %"PRIx64, command);
2111 g_mutex_unlock(&handle->lock);
2112 return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
2115 ctrl_ret = __camera_v4l2_g_ctrl(handle->device_fd, cid, (int *)*value);
2120 LOGE("Permission denied %d", errno);
2121 ret = CAMERA_ERROR_PERMISSION_DENIED;
2124 LOGE("Invalid argument");
2125 ret = CAMERA_ERROR_INVALID_PARAMETER;
2128 LOGE("Device busy");
2129 ret = CAMERA_ERROR_DEVICE_BUSY;
2132 LOGE("Not supported");
2133 ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
2136 LOGE("Unknown errro %d", errno);
2137 ret = CAMERA_ERROR_INTERNAL;
2143 g_mutex_unlock(&handle->lock);
2149 static void __dump_batch_command(camera_batch_command_control_s *batch_command)
2151 if (!batch_command) {
2152 LOGE("NULL batch command");
2156 LOGI("[WHITE_BALANCE] %d", batch_command->white_balance);
2157 LOGI("[ISO] %d", batch_command->iso);
2158 LOGI("[CONTRAST] %d", batch_command->contrast);
2159 LOGI("[HUE] %d", batch_command->hue);
2160 LOGI("[SATURATION] %d", batch_command->saturation);
2161 LOGI("[SHARPNESS] %d", batch_command->sharpness);
2162 LOGI("[BRIGHTNESS] %d", batch_command->brightness);
2163 LOGI("[EFFECT] %d", batch_command->effect);
2164 LOGI("[SCENE_MODE] %d", batch_command->scene_mode);
2165 LOGI("[EXPOSURE_MODE] %d", batch_command->exposure_mode);
2166 LOGI("[EXPOSURE] %d", batch_command->exposure);
2167 LOGI("[ROTATION] %d", batch_command->rotation);
2168 LOGI("[FLIP] %d", batch_command->flip);
2169 LOGI("[FOCUS_MODE] %d", batch_command->focus_mode);
2170 LOGI("[FOCUS_RANGE] %d", batch_command->focus_range);
2171 LOGI("[FOCUS_AREA] %d,%d,%dx%d", batch_command->focus_area.x, batch_command->focus_area.y,
2172 batch_command->focus_area.width, batch_command->focus_area.height);
2173 LOGI("[FOCUS_LEVEL] %d", batch_command->focus_level);
2174 LOGI("[SHOT_MODE] %d", batch_command->shot_mode);
2175 LOGI("[ANTI_SHAKE] %d", batch_command->anti_shake);
2176 LOGI("[DIGITAL_ZOOM] %d", batch_command->digital_zoom);
2177 LOGI("[OPTICAL_ZOOM] %d", batch_command->optical_zoom);
2178 LOGI("[RECORDING_HINT] %d", batch_command->recording_hint);
2179 LOGI("[WDR] %d", batch_command->wdr);
2180 LOGI("[SHUTTER_SPEED] %d/%d", batch_command->shutter_speed.numerator, batch_command->shutter_speed.denominator);
2181 LOGI("[FLASH_MODE] %d", batch_command->flash_mode);
2182 LOGI("[FLASH_BRIGHTNESS] %d", batch_command->flash_brightness);
2183 LOGI("[FACE_DETECTION] %d", batch_command->face_detection);
2184 LOGI("[PTZ_TYPE] %d", batch_command->ptz_type);
2185 LOGI("[PAN] %d", batch_command->pan);
2186 LOGI("[TILT] %d", batch_command->tilt);
2187 LOGI("[BITRATE] %d", batch_command->bitrate);
2188 LOGI("[GOP_INTERVAL] %d", batch_command->gop_interval);
2189 LOGI("[CAPTURE_COUNT] %d", batch_command->capture_count);
2190 LOGI("[CAPTURE_INTERVAL] %d", batch_command->capture_interval);
2194 int camera_v4l2_set_batch_command(void *camera_handle, camera_batch_command_control_s *batch_command, int64_t *error_command)
2196 int ret = CAMERA_ERROR_NONE;
2198 int support_count = 0;
2199 hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
2200 set_batch_table_s set_table[] = {
2201 {CAMERA_COMMAND_BRIGHTNESS, batch_command ? (void *)&batch_command->brightness : NULL},
2202 {CAMERA_COMMAND_CONTRAST, batch_command ? (void *)&batch_command->contrast : NULL},
2203 {CAMERA_COMMAND_SATURATION, batch_command ? (void *)&batch_command->saturation : NULL},
2204 {CAMERA_COMMAND_SHARPNESS, batch_command ? (void *)&batch_command->sharpness : NULL},
2205 {CAMERA_COMMAND_PTZ_TYPE, batch_command ? (void *)&batch_command->ptz_type : NULL},
2206 {CAMERA_COMMAND_PAN, batch_command ? (void *)&batch_command->pan : NULL},
2207 {CAMERA_COMMAND_TILT, batch_command ? (void *)&batch_command->tilt : NULL},
2208 {CAMERA_COMMAND_FLIP, batch_command ? (void *)&batch_command->flip : NULL},
2209 {CAMERA_COMMAND_CAPTURE_COUNT, batch_command ? (void *)&batch_command->capture_count : NULL},
2210 {CAMERA_COMMAND_CAPTURE_INTERVAL, batch_command ? (void *)&batch_command->capture_interval : NULL},
2211 {CAMERA_COMMAND_FOCUS_MODE, batch_command ? (void *)&batch_command->focus_mode : NULL},
2212 {CAMERA_COMMAND_FOCUS_RANGE, batch_command ? (void *)&batch_command->focus_range : NULL},
2213 {CAMERA_COMMAND_FOCUS_LEVEL, batch_command ? (void *)&batch_command->focus_level : NULL}
2216 if (!handle || !batch_command) {
2217 LOGE("NULL param %p %p", handle, batch_command);
2218 return CAMERA_ERROR_INVALID_PARAMETER;
2221 g_mutex_lock(&handle->lock);
2223 support_count = sizeof(set_table) / sizeof(set_batch_table_s);
2225 LOGD("set batch command - support count %d", support_count);
2227 __dump_batch_command(batch_command);
2229 for (i = 0 ; i < support_count ; i++) {
2230 if (!(batch_command->command_set_flag & set_table[i].command))
2233 ret = __set_command(handle, set_table[i].command, set_table[i].value);
2234 if (ret != CAMERA_ERROR_NONE) {
2235 LOGE("failed command %"PRIx64", ret 0x%x", set_table[i].command, ret);
2240 g_mutex_unlock(&handle->lock);
2246 static int camera_v4l2_backend_init(void **data)
2248 hal_backend_camera_funcs *funcs;
2250 funcs = calloc(1, sizeof(hal_backend_camera_funcs));
2252 return CAMERA_ERROR_OUT_OF_MEMORY;
2254 funcs->init = camera_v4l2_init;
2255 funcs->deinit = camera_v4l2_deinit;
2256 funcs->get_device_info_list = camera_v4l2_get_device_info_list;
2257 funcs->open_device = camera_v4l2_open_device;
2258 funcs->open_device_ext = camera_v4l2_open_device_ext;
2259 funcs->close_device = camera_v4l2_close_device;
2260 funcs->add_message_callback = camera_v4l2_add_message_callback;
2261 funcs->remove_message_callback = camera_v4l2_remove_message_callback;
2262 funcs->set_preview_stream_format = camera_v4l2_set_preview_stream_format;
2263 funcs->get_preview_stream_format = camera_v4l2_get_preview_stream_format;
2264 funcs->set_user_buffer_fd = camera_v4l2_set_user_buffer_fd;
2265 funcs->start_preview = camera_v4l2_start_preview;
2266 funcs->release_preview_buffer = camera_v4l2_release_preview_buffer;
2267 funcs->stop_preview = camera_v4l2_stop_preview;
2268 funcs->start_auto_focus = camera_v4l2_start_auto_focus;
2269 funcs->stop_auto_focus = camera_v4l2_stop_auto_focus;
2270 funcs->start_capture = camera_v4l2_start_capture;
2271 funcs->stop_capture = camera_v4l2_stop_capture;
2272 funcs->set_video_stream_format = camera_v4l2_set_video_stream_format;
2273 funcs->get_video_stream_format = camera_v4l2_get_video_stream_format;
2274 funcs->start_record = camera_v4l2_start_record;
2275 funcs->release_video_buffer = camera_v4l2_release_video_buffer;
2276 funcs->stop_record = camera_v4l2_stop_record;
2277 funcs->set_command = camera_v4l2_set_command;
2278 funcs->get_command = camera_v4l2_get_command;
2279 funcs->set_batch_command = camera_v4l2_set_batch_command;
2280 funcs->set_extra_preview_frame_cb = camera_v4l2_set_extra_preview_frame_cb;
2281 funcs->unset_extra_preview_frame_cb = camera_v4l2_unset_extra_preview_frame_cb;
2282 funcs->release_extra_preview_buffer = camera_v4l2_release_extra_preview_buffer;
2284 *data = (void *)funcs;
2290 static int camera_v4l2_backend_exit(void *data)
2301 hal_backend hal_backend_camera_data = {
2302 .name = "camera-v4l2",
2304 .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
2305 .init = camera_v4l2_backend_init,
2306 .exit = camera_v4l2_backend_exit,