4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * This library is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; either version 2.1 of the License, or (at your option)
13 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 * License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "camerasrc-internal.h"
27 /*#define USE_IOCTL_DEBUG*/
28 #if defined (USE_IOCTL_DEBUG)
29 static char* get_request_name(int request, char* res_str) {
32 sprintf(res_str, "[VIDIOC_QBUF]");
35 sprintf(res_str, "[VIDIOC_DQBUF]");
38 sprintf(res_str, "[VIDIOC_S_INPUT]");
41 sprintf(res_str, "[VIDIOC_G_INPUT]");
44 sprintf(res_str, "[VIDIOC_S_PARM]");
47 sprintf(res_str, "[VIDIOC_G_PARM]");
50 sprintf(res_str, "[VIDIOC_S_FMT]");
53 sprintf(res_str, "[VIDIOC_G_FMT]");
56 sprintf(res_str, "[VIDIOC_REQBUFS]");
59 sprintf(res_str, "[VIDIOC_QUERYBUF]");
62 sprintf(res_str, "[VIDIOC_STREAMON]");
64 case VIDIOC_STREAMOFF:
65 sprintf(res_str, "[VIDIOC_STREAMOFF]");
68 sprintf(res_str, "[VIDIOC_S_CTRL] ");
71 sprintf(res_str, "[VIDIOC_G_CTRL]");
73 case VIDIOC_ENUMINPUT:
74 sprintf(res_str, "[VIDIOC_ENUMINPUT]");
76 case VIDIOC_S_JPEGCOMP:
77 sprintf(res_str, "[VIDIOC_S_JPEGCOMP]");
79 case VIDIOC_G_JPEGCOMP:
80 sprintf(res_str, "[VIDIOC_G_JPEGCOMP]");
84 sprintf(res_str, "[VIDIOC_S_STROBE]");
87 sprintf(res_str, "[VIDIOC_G_STROBE]");
89 case VIDIOC_S_RECOGNITION:
90 sprintf(res_str, "[VIDIOC_S_RECOGNITION]");
92 case VIDIOC_G_RECOGNITION:
93 sprintf(res_str, "[VIDIOC_G_RECOGNITION]");
96 sprintf(res_str, "[VIDIOC_G_EXIF]");
99 sprintf(res_str, "[UNKNOWN IOCTL(%x)]", request);
106 #define PRINT_IOCTL_INFO(request, arg) {\
108 get_request_name(request, res_str);\
109 camsrc_info("[request : %s, argument address : %x]", res_str, arg);\
113 #define PRINT_IOCTL_INFO(request, arg)
119 if(0 != pthread_mutex_lock(&(x->mutex))) {\
120 camsrc_error("Mutex lock error");\
126 if(0 != pthread_mutex_unlock(&(x->mutex))) {\
127 camsrc_error("Mutex unlock error");\
132 #define AF_MUT_LOCK(p) {\
133 if(0 != pthread_mutex_lock(&(p->af_mutex))) {\
134 camsrc_error("AF Mutex locking error");\
139 #define AF_MUT_UNLOCK(p) {\
140 if(0 != pthread_mutex_unlock(&(p->af_mutex))) {\
141 camsrc_error("AF Mutex unlocking error");\
146 #define SET_CTRL_VAL(cid, in_value) {\
147 int err = CAMERASRC_ERR_UNKNOWN;\
148 struct v4l2_control control;\
150 control.value = in_value;\
151 camsrc_info("[VIDIOC_S_CTRL] >> [%x] request with value %d", cid, in_value); \
152 err = _camerasrc_ioctl(handle, VIDIOC_S_CTRL, &control);\
153 if(err != CAMERASRC_SUCCESS) {\
158 #define GET_CTRL_VAL(cid, ret_value) {\
159 int err = CAMERASRC_ERR_UNKNOWN;\
160 struct v4l2_control control;\
162 err = _camerasrc_ioctl(handle, VIDIOC_G_CTRL, &control);\
163 if(err != CAMERASRC_SUCCESS) {\
166 ret_value = control.value;\
167 camsrc_info("[VIDIOC_G_CTRL] << [%x] request with value %d", cid, ret_value); \
170 #define SET_CTRL_VAL_ERR(cid, in_value, err) {\
171 struct v4l2_control control;\
173 control.value = in_value;\
174 camsrc_info("[VIDIOC_S_CTRL] >> [%x] request with value %d", cid, in_value); \
175 _camerasrc_ioctl_with_err(handle, VIDIOC_S_CTRL, &control, &err);\
178 #define GET_CTRL_VAL_ERR(cid, ret_value, err) {\
179 struct v4l2_control control;\
181 _camerasrc_ioctl_with_err(handle, VIDIOC_G_CTRL, &control, &err);\
182 ret_value = control.value;\
183 camsrc_info("[VIDIOC_G_CTRL] << [%x] request with value %d", cid, ret_value); \
187 static int _camerasrc_start_autofocusing(camerasrc_handle_t *handle);
188 static int _camerasrc_stop_autofocusing(camerasrc_handle_t *handle);
189 static int _camerasrc_destroy_autofocusing(camerasrc_handle_t *handle);
190 static int _camerasrc_release_autofocusing(camerasrc_handle_t *handle);
193 int static af_retry_cnt = 0;
195 static int _camerasrc_ioctl(camerasrc_handle_t *handle, int request, void *arg)
197 int fd = handle->dev_fd;
200 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
204 if (handle->check_esd == 1) {
205 camsrc_warning("ESD shock occured. All device control will success");
207 return CAMERASRC_SUCCESS;
210 if (handle->dev_fd == CAMERASRC_DEV_FD_EMERGENCY_CLOSED) {
211 camsrc_warning("Device emergency closed. All device control will success");
213 return CAMERASRC_SUCCESS;
216 PRINT_IOCTL_INFO(request, arg);
220 err = ioctl (fd, request, arg);
221 } while (-1 == err && EINTR == errno);
224 handle->errnum = errno;
226 strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
227 camsrc_error("ioctl[%x] err : %s", request, err_msg);
229 camsrc_info("EEXIST occured, but can go.");
231 } else if (err == ENOENT) {
232 camsrc_info("ENOENT occured, but can go.");
234 #if defined (ENABLE_Q_ERROR)
235 #warning "ENABLE_Q_ERROR enabled"
236 } else if (request == VIDIOC_DQBUF) {
238 } else if (request == VIDIOC_QBUF) {
241 } else if (err == EINVAL) {
242 camsrc_error("EINVAL occured, Shutdown");
244 return CAMERASRC_ERR_INVALID_PARAMETER;
245 } else if (err == EBUSY) {
246 camsrc_error("EBUSY occured, Shutdown");
248 return CAMERASRC_ERR_PRIVILEGE;
249 } else if (err == EAGAIN && nAgain--) {
252 /* Why does this return SUCCESS? */
253 camsrc_error("Unhandled exception occured on IOCTL");
259 return CAMERASRC_SUCCESS;
261 #if defined (ENABLE_Q_ERROR)
263 camsrc_error("DQ Frame error occured");
264 printf("DQ Frame error occured");
266 return CAMERASRC_ERR_INTERNAL;
269 camsrc_error("Q Frame error occured");
270 printf("Q Frame error occured");
272 return CAMERASRC_ERR_INTERNAL;
277 static int _camerasrc_ioctl_with_err(camerasrc_handle_t *handle, int request, void *arg, int *error)
279 int fd = handle->dev_fd;
281 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
287 if (handle->check_esd == 1) {
288 camsrc_warning("ESD shock occured. All device control will success");
290 return CAMERASRC_SUCCESS;
293 if (handle->dev_fd == CAMERASRC_DEV_FD_EMERGENCY_CLOSED) {
294 camsrc_warning("Device emergency closed. All device control will success");
296 return CAMERASRC_SUCCESS;
299 PRINT_IOCTL_INFO(request, arg);
302 err = ioctl (fd, request, arg);
303 } while (-1 == err && EINTR == errno);
306 handle->errnum = errno;
308 strerror_r(*error, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
309 camsrc_error("ioctl[%x] err : %s", request, err_msg);
311 return CAMERASRC_ERR_IO_CONTROL;
316 return CAMERASRC_SUCCESS;
320 static int _camerasrc_ioctl_once(camerasrc_handle_t *handle, int request, void *arg)
322 int fd = handle->dev_fd;
325 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
329 if (handle->check_esd == 1) {
330 camsrc_warning("ESD shock occured. All device control will success");
332 return CAMERASRC_SUCCESS;
335 if (handle->dev_fd == CAMERASRC_DEV_FD_EMERGENCY_CLOSED) {
336 camsrc_warning("Device emergency closed. All device control will success");
338 return CAMERASRC_SUCCESS;
341 PRINT_IOCTL_INFO(request, arg);
344 err = ioctl (fd, request, arg);
347 handle->errnum = errno;
349 strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
350 camsrc_error("ioctl[%x] err : %s", request, err_msg);
352 camsrc_info("EEXIST occured, but can go.");
354 } else if (err == ENOENT) {
355 camsrc_info("ENOENT occured, but can go.");
357 #if defined (ENABLE_Q_ERROR)
358 #warning "ENABLE_Q_ERROR enabled"
359 } else if (request == VIDIOC_DQBUF) {
361 } else if (request == VIDIOC_QBUF) {
364 } else if (err == EINVAL) {
365 camsrc_error("EINVAL occured, Shutdown");
367 return CAMERASRC_ERR_INVALID_PARAMETER;
368 } else if (err == EAGAIN && nAgain--) {
371 camsrc_error("Unhandled exception occured on IOCTL");
377 return CAMERASRC_SUCCESS;
379 #if defined (ENABLE_Q_ERROR)
381 camsrc_error("DQ Frame error occured");
382 printf("DQ Frame error occured");
384 return CAMERASRC_ERR_INTERNAL;
387 camsrc_error("Q Frame error occured");
388 printf("Q Frame error occured");
390 return CAMERASRC_ERR_INTERNAL;
395 static int _camerasrc_skip_frame(camerasrc_handle_t *handle, long int timeout, int skip_frame)
397 camerasrc_handle_t *p = NULL;
398 int err = CAMERASRC_ERR_UNKNOWN;
402 int skip_frame_num = skip_frame;
404 camsrc_error("enter");
408 while (skip_frame_num--) {
409 camsrc_error("SKIP FRAME #%d", skip_frame-skip_frame_num+1);
411 struct v4l2_buffer buf;
414 FD_SET (p->dev_fd, &fds);
416 camsrc_error("************Still capture wait frame start");
419 tv.tv_sec = (long int)timeout/1000;
420 tv.tv_usec = timeout - tv.tv_sec * 1000;
422 r = select (p->dev_fd + 1, &fds, NULL, NULL, &tv);
425 if (EINTR == errno) {
426 return CAMERASRC_SUCCESS;
428 camsrc_error("select() failed.");
429 return CAMERASRC_ERR_INTERNAL;
433 camsrc_error("select() timeout.");
434 return CAMERASRC_ERR_DEVICE_WAIT_TIMEOUT;
437 /**@note from samsung camera sample. *****************************************/
440 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
441 buf.memory = V4L2_MEMORY_MMAP;
442 buf.index = p->buffer_idx;
444 if (-1 == _camerasrc_ioctl (p, VIDIOC_DQBUF, &buf)) {
447 camsrc_info("VIDIOC_DQBUF [EAGAIN]");
448 return CAMERASRC_SUCCESS;
450 /* Could ignore EIO, see spec. */
452 camsrc_info("VIDIOC_DQBUF [EIO]");
454 camsrc_info("VIDIOC_DQBUF [%d]", errno);
455 return CAMERASRC_ERR_IO_CONTROL;
459 if (-1 == _camerasrc_ioctl (p, VIDIOC_QBUF, &buf)) {
460 return CAMERASRC_ERR_IO_CONTROL;
464 camsrc_error("leave");
465 err = CAMERASRC_SUCCESS;
470 static int _camerasrc_init_autofocusing_mode(camerasrc_handle_t *handle)
472 int ctrl_id = V4L2_CID_FOCUS_AUTO_MODE;
475 camsrc_info("enter");
477 if (handle->af_status == CAMERASRC_AUTO_FOCUS_STATUS_ONGOING) {
478 camsrc_info("Dev BUSY. Init failed.");
479 return CAMERASRC_ERR_INVALID_STATE;
482 switch (handle->cur_af_mode) {
483 case CAMERASRC_AF_MODE_AUTO:
484 mode = V4L2_FOCUS_AUTO_NORMAL;
485 camsrc_info("ON AUTOFOCUSING...BY AUTO");
487 case CAMERASRC_AF_MODE_MANUAL:
488 ctrl_id = V4L2_CID_FOCUS_MODE;
489 mode = V4L2_FOCUS_MODE_MANUAL;
490 camsrc_info("ON AUTOFOCUSING...BY MANUAL");
492 case CAMERASRC_AF_MODE_CONTINUOUS:
493 mode = V4L2_FOCUS_AUTO_CONTINUOUS;
494 camsrc_info("ON AUTOFOCUSING...BY CONTINUOUS");
495 if (handle->format.pix_format != CAMERASRC_PIX_NV12 &&
496 handle->format.pix_format != CAMERASRC_PIX_SN12) {
497 camsrc_info("DO NOT CONTINUOUS AF when NV12 or SN12 format");
498 return CAMERASRC_SUCCESS;
501 case CAMERASRC_AF_MODE_TOUCH_AUTO:
502 mode = V4L2_FOCUS_AUTO_RECTANGLE;
503 camsrc_info("ON AUTOFOCUSING...BY TOUCH AUTO");
505 case CAMERASRC_AF_MODE_PAN:
506 camsrc_warning("PAN MODE focusing is not supported.");
508 camsrc_warning("Unsupported AF mode[%d]", handle->cur_af_mode );
509 return CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
512 /* MACRO is prior than other setting. FIXME */
513 if (handle->cur_af_range == CAMERASRC_AF_RANGE_MACRO) {
514 mode = V4L2_FOCUS_AUTO_MACRO;
515 camsrc_info("ON AUTOFOCUSING...BY MACRO");
518 SET_CTRL_VAL(ctrl_id, mode);
520 /* Start AF if continuous mode and preview is running */
521 if (mode == V4L2_FOCUS_AUTO_CONTINUOUS &&
522 handle->cur_state >= CAMERASRC_STATE_PREVIEW) {
523 _camerasrc_start_autofocusing(handle);
526 return CAMERASRC_SUCCESS;
529 static void __CAMERASRC_FUJITSU_GET_AF_CTRL_VAL(camerasrc_handle_t* handle, int* status)
533 if (af_retry_cnt >= (int)CAMERASRC_AF_TOTALTIME/CAMERASRC_AF_INTERVAL) {
534 *status = CAMERASRC_SENSOR_AF_STATUS_FAILED;
539 camsrc_info("retry count = %d", af_retry_cnt);
542 SET_CTRL_VAL_ERR(V4L2_CID_CAMERA_SET_AUTO_FOCUS, 1, err);
545 camsrc_info("Succeeded");
546 *status = CAMERASRC_SENSOR_AF_STATUS_FOCUSED;
551 *status = CAMERASRC_SENSOR_AF_STATUS_ONGOING;
554 camsrc_info("Failed");
555 *status = CAMERASRC_SENSOR_AF_STATUS_FAILED;
563 static void* _camerasrc_run_autofocusing(camerasrc_handle_t *handle)
566 int sensor_status = 0;
568 camsrc_info("enter");
572 switch (handle->af_cmd) {
573 case CAMERASRC_AUTO_FOCUS_CMD_START:
575 camsrc_info("AF CMD:START");
576 __CAMERASRC_FUJITSU_GET_AF_CTRL_VAL(handle, &sensor_status);
578 switch (sensor_status) {
579 case CAMERASRC_SENSOR_AF_STATUS_ONGOING:
580 camsrc_info("FOCUSING. IN PROGRESS...");
581 handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_ONGOING;
583 case CAMERASRC_SENSOR_AF_STATUS_FOCUSED: /* focus operation success. Go to Null. */
584 camsrc_info("FOCUSED. stop autofocusing...");
586 handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED;
587 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL;
589 CAMERASRC_SET_STATE(handle, CAMERASRC_STATE_PREVIEW);
591 if (handle->af_cb != NULL) {
592 if (handle->af_usr_data != NULL) {
593 handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED, handle->af_usr_data);
595 handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED, NULL);
599 AF_MUT_UNLOCK(handle);
601 case CAMERASRC_SENSOR_AF_STATUS_FAILED: /* focus operation failed. Set stop and go to NULL. */
602 camsrc_info("FOCUSING FAILED");
604 if (handle->cur_af_mode != CAMERASRC_AF_MODE_CONTINUOUS ) {
605 SET_CTRL_VAL_ERR(V4L2_CID_CAMERA_SET_AUTO_FOCUS, 0, err);
606 camsrc_info("Stopping AF done. err = %d", err);
609 handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED;
610 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL;
612 CAMERASRC_SET_STATE(handle, CAMERASRC_STATE_PREVIEW);
614 if (handle->af_cb != NULL) {
615 if(handle->af_usr_data != NULL) {
616 handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FAILED, handle->af_usr_data);
618 handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FAILED, NULL);
622 AF_MUT_UNLOCK(handle);
625 camsrc_error("Unrecognizable status");
630 case CAMERASRC_AUTO_FOCUS_CMD_STOP:
632 camsrc_info("AF CMD:STOP");
633 SET_CTRL_VAL_ERR(V4L2_CID_CAMERA_SET_AUTO_FOCUS, 0, err);
634 handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED;
635 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL;
636 camsrc_info("Stopping AF done. err = %d", err);
637 AF_MUT_UNLOCK(handle);
640 case CAMERASRC_AUTO_FOCUS_CMD_KILL:
642 camsrc_info("AF CMD:KILL");
644 SET_CTRL_VAL_ERR(V4L2_CID_CAMERA_SET_AUTO_FOCUS, 0, err);
645 camsrc_info("Stopping AF done. err = %d", err);
647 handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED;
648 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL;
650 AF_MUT_UNLOCK(handle);
653 case CAMERASRC_AUTO_FOCUS_CMD_NULL:
656 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
657 camsrc_info("AF CMD:NULL....");
658 err = pthread_cond_wait(&handle->af_wait_cond, &handle->af_mutex);
660 strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
661 camsrc_error("AF CMD pthread_cond_wait - err:(%s)", err_msg);
666 /* Start AF delay for AE */
667 if (handle->af_cmd == CAMERASRC_AUTO_FOCUS_CMD_START) {
668 struct timeval cur_time;
671 int diff = 0; /* msec */
672 int sleep_time = 0; /* usec */
674 SET_CTRL_VAL_ERR(V4L2_CID_CAMERA_SET_AUTO_FOCUS, 0, err);
676 camsrc_info("Check set AF area Time(Delay:%d)", CAMERASRC_AF_DELAY_AFTER_SET_AF_AREA);
678 if (handle->set_af_area_time.tv_sec != 0) {
679 gettimeofday(&cur_time, NULL);
680 sec = cur_time.tv_sec - handle->set_af_area_time.tv_sec;
681 usec = cur_time.tv_usec - handle->set_af_area_time.tv_usec;
683 camsrc_info("diff sec:%d, usec:%d", sec, usec);
684 diff = (sec * 1000) + (usec / 1000);
686 /* Skip sleep if diff is less than zero or greater than minimum exposure time */
687 if (diff < 0 || diff > CAMERASRC_AF_DELAY_AFTER_SET_AF_AREA) {
688 camsrc_info("no need to sleep(diff: %d ms)", diff);
690 sleep_time = (CAMERASRC_AF_DELAY_AFTER_SET_AF_AREA - diff) * 1000;
691 camsrc_info("usleep(%d)", sleep_time);
697 AF_MUT_UNLOCK(handle);
702 AF_MUT_UNLOCK(handle);
703 usleep(CAMERASRC_AF_INTERVAL);
707 camsrc_info("AF thread is finished.");
711 static int _camerasrc_start_autofocusing(camerasrc_handle_t *handle)
714 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
715 camsrc_info("enter");
719 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_START;
720 err = pthread_cond_signal(&handle->af_wait_cond);
722 strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
723 camsrc_info("AF wait cond err(%s)", err_msg);
726 AF_MUT_UNLOCK(handle);
728 return CAMERASRC_SUCCESS;
731 static int _camerasrc_stop_autofocusing(camerasrc_handle_t *handle)
734 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
736 camsrc_info("enter");
740 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_STOP;
741 err = pthread_cond_signal(&handle->af_wait_cond);
743 strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
744 camsrc_info("AF wait cond err(%s)", err_msg);
747 AF_MUT_UNLOCK(handle);
749 return CAMERASRC_SUCCESS;
752 static int _camerasrc_destroy_autofocusing(camerasrc_handle_t *handle)
755 char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
756 camsrc_info("enter");
760 handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_KILL;
761 err = pthread_cond_signal(&handle->af_wait_cond);
763 strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
764 camsrc_info("AF wait cond err(%s)", err_msg);
767 AF_MUT_UNLOCK(handle);
769 return CAMERASRC_SUCCESS;
772 static int _camerasrc_release_autofocusing(camerasrc_handle_t *handle)
775 camsrc_info("enter");
777 SET_CTRL_VAL_ERR(V4L2_CID_CAMERA_SET_AUTO_FOCUS, 0, err);
779 return CAMERASRC_SUCCESS;
782 static int _camerasrc_copy_frame(camerasrc_handle_t *handle, camerasrc_buffer_t *src_buffer, camerasrc_buffer_t *dst_buffer, int isThumbnail)
784 if (handle == NULL || src_buffer == NULL || dst_buffer == NULL) {
785 camsrc_error("handle[%p], src_buffer[%p], dst_buffer[%p]",
786 handle, src_buffer, dst_buffer);
787 return CAMERASRC_ERR_NULL_POINTER;
790 if (src_buffer->start == NULL || dst_buffer->start == NULL) {
791 camsrc_error("src_buffer->start[%p], dst_buffer->start[%p]",
792 src_buffer->start, dst_buffer->start);
793 return CAMERASRC_ERR_NULL_POINTER;
796 if (handle->format.colorspace == CAMERASRC_COL_RAW) {
799 if (handle->format.pix_format == CAMERASRC_PIX_YUV422P ||
800 handle->format.pix_format == CAMERASRC_PIX_YUY2 ||
801 handle->format.pix_format == CAMERASRC_PIX_UYVY) {
802 cpy_len = (YUV422_SIZE(handle)>=src_buffer->length)?src_buffer->length:YUV422_SIZE(handle);
803 } else if (handle->format.pix_format == CAMERASRC_PIX_YUV420P ||
804 handle->format.pix_format == CAMERASRC_PIX_YUV420 ||
805 handle->format.pix_format == CAMERASRC_PIX_NV12) {
806 cpy_len = (YUV420_SIZE(handle)>=src_buffer->length)?src_buffer->length:YUV420_SIZE(handle);
808 camsrc_error("UNSUPPORTED format [%x]", handle->format.pix_format );
809 return CAMERASRC_ERR_INVALID_FORMAT;
812 #if defined (USE_FRAME_COPY_BOUNDARY_CHECK)
813 camsrc_info("Boundary check %p ~ %p ... [length = %d] ", dst_buffer->start, dst_buffer->start+cpy_len, cpy_len);
814 memset(dst_buffer->start, 0, cpy_len);
815 camsrc_info("Boundary check OK");
818 camsrc_info("RAW frame dequeing...");
819 dst_buffer->length = cpy_len;
821 if (handle->format.pix_format == CAMERASRC_PIX_SN12) {
822 camsrc_error("Can't copy the frame with SN12 option");
823 return CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
824 } else if (handle->format.pix_format == CAMERASRC_PIX_ST12) {
825 camsrc_error("Can't copy the frame with ST12 option");
826 return CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
829 camsrc_error("format[%d] copy occured. copy len = %d", handle->format.pix_format, cpy_len);
830 memcpy(dst_buffer->start, src_buffer->start, cpy_len );
831 } else if (handle->format.colorspace == CAMERASRC_COL_JPEG) {
832 #if defined (USE_FRAME_COPY_BOUNDARY_CHECK)
833 camsrc_info("Boundary check %p ~ %p ...", dst_buffer->start, dst_buffer->start+src_buffer->length);
834 memset(dst_buffer->start, 0, src_buffer->length);
835 camsrc_info("Boundary check OK");
839 if (src_buffer->length <= 0) {
840 camsrc_error("length[%d] is too small", src_buffer->length );
841 return CAMERASRC_ERR_INVALID_VALUE;
844 dst_buffer->length = src_buffer->length;
845 camsrc_info("JPEG main frame copy... img length = %d", dst_buffer->length);
846 memcpy(dst_buffer->start, src_buffer->start, dst_buffer->length);
847 camsrc_info("JPEG main frame copy done.");
849 if (handle->format.pix_format == CAMERASRC_PIX_RGGB8) {
851 if (src_buffer->length <= 0) {
852 camsrc_error("length[%d] is too small", src_buffer->length );
853 return CAMERASRC_ERR_INVALID_VALUE;
856 dst_buffer->length = src_buffer->length;
857 camsrc_info("JPEG thm frame(JPEG) copy... img length = %d", dst_buffer->length);
858 memcpy(dst_buffer->start, src_buffer->start, dst_buffer->length);
859 camsrc_info("JPEG thm frame(JPEG) copy done.");
860 } else if (handle->format.pix_format == CAMERASRC_PIX_RGGB10) {
862 dst_buffer->length = CAMERASRC_YUV_THMBNL_SIZE;
863 camsrc_info("JPEG thm frame(YUV) copy... img length = %d", CAMERASRC_YUV_THMBNL_SIZE);
864 memcpy(dst_buffer->start, src_buffer->start, CAMERASRC_YUV_THMBNL_SIZE);
865 camsrc_info("JPEG thm frame(YUV) copy done.");
867 camsrc_info("Unknown format [%d]", handle->format.pix_format );
868 return CAMERASRC_ERR_INVALID_FORMAT;
873 return CAMERASRC_SUCCESS;
877 static int _camerasrc_set_thumbnail_size(camerasrc_handle_t *handle)
879 camsrc_info("enter");
881 return CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
884 static int _camerasrc_start_facedetection (camerasrc_handle_t *handle)
886 camsrc_info("enter");
887 camsrc_info("FACE DETECTION START!");
888 SET_CTRL_VAL(V4L2_CID_FACE_DETECTION, CAM_FACE_DETECTION_ON);
889 camsrc_info("leave");
890 return CAMERASRC_SUCCESS;
894 static int _camerasrc_stop_facedetection (camerasrc_handle_t *handle)
896 camsrc_info("enter");
897 camsrc_info("FACE DETECTION STOP!");
898 SET_CTRL_VAL(V4L2_CID_FACE_DETECTION, CAM_FACE_DETECTION_OFF);
899 camsrc_info("leave");
900 return CAMERASRC_SUCCESS;
904 static int _camerasrc_check_emp_shock(camerasrc_handle_t *handle, int *check_val)
906 camsrc_info("enter");
909 GET_CTRL_VAL(V4L2_CID_ESD_INT, ret_value);
910 *check_val = ret_value;
912 camsrc_info("leave");
913 return CAMERASRC_SUCCESS;
917 static int _camerasrc_get_frame_data(camerasrc_handle_t *handle, camerasrc_frame_data_t *data)
919 /*camsrc_info("enter");*/
920 int err = CAMERASRC_ERR_UNKNOWN;
921 struct v4l2_control control;
923 /* Get Y physical address */
924 /*camsrc_info("[VIDIOC_G_CTRL] << [V4L2_CID_PADDR_Y] request with value");*/
925 control.id = V4L2_CID_PADDR_Y;
926 control.value = data->index;
927 err = _camerasrc_ioctl(handle, VIDIOC_S_CTRL, &control);
928 if (err != CAMERASRC_SUCCESS) {
932 data->phyAddrY = control.value;
934 /* Get CbCr physical address */
935 /*camsrc_info("[VIDIOC_G_CTRL] << [V4L2_CID_PADDR_CBCR] request with value");*/
936 control.id = V4L2_CID_PADDR_CBCR;
937 control.value = data->index;
938 err = _camerasrc_ioctl(handle, VIDIOC_S_CTRL, &control);
939 if (err != CAMERASRC_SUCCESS) {
943 data->phyAddrCbCr = control.value;
945 /* Distance between Y ptr and CbCr ptr of virtual address is same with that of Physical one. */
946 data->virAddrY = (unsigned int)handle->buffer[data->index].start;
947 data->virAddrCbCr = data->virAddrY + (data->phyAddrCbCr - data->phyAddrY);
949 /*camsrc_info("virAddrY(%p), virAddrCbCr(%p)", data->virAddrY, data->virAddrCbCr);*/
951 return CAMERASRC_SUCCESS;
955 static void _dump_exif_info(camerasrc_exif_t *exif_struct)
957 camsrc_info("== Dynamic value ==");
958 camsrc_info("unsigned int exposure_time_numerator = %d", exif_struct->exposure_time_numerator);
959 camsrc_info("unsigned int exposure_time_denominator = %d", exif_struct->exposure_time_denominator);
960 camsrc_info("int shutter_speed_numerator = %d", exif_struct->shutter_speed_numerator);
961 camsrc_info("int shutter_speed_denominator = %d", exif_struct->shutter_speed_denominator);
962 camsrc_info("int brigtness_numerator = %d", exif_struct->brigtness_numerator);
963 camsrc_info("int brightness_denominator = %d", exif_struct->brightness_denominator);
964 camsrc_info("unsigned short int iso = %d", exif_struct->iso);
965 camsrc_info("unsigned short int flash = %d", exif_struct->flash);
966 camsrc_info("int metering_mode = %d", exif_struct->metering_mode);
967 camsrc_info("int exif_image_width = %d", exif_struct->exif_image_width);
968 camsrc_info("int exif_image_height = %d", exif_struct->exif_image_height);
969 camsrc_info("int exposure_bias_in_APEX = %d", exif_struct->exposure_bias_in_APEX);
970 camsrc_info("int software_used = %d", exif_struct->software_used);
971 camsrc_info("int focal_len_numerator = %d", exif_struct->focal_len_numerator);
972 camsrc_info("int focal_len_denominator = %d", exif_struct->focal_len_denominator);
973 camsrc_info("int aperture_f_num_numerator = %d", exif_struct->aperture_f_num_numerator);
974 camsrc_info("int aperture_f_num_denominator = %d", exif_struct->aperture_f_num_denominator);
975 camsrc_info("int aperture_in_APEX = %d", exif_struct->aperture_in_APEX);
976 camsrc_info("int max_lens_aperture_in_APEX = %d", exif_struct->max_lens_aperture_in_APEX);
978 camsrc_info("== Fixed value ==");
979 camsrc_info("int component_configuration = %x", exif_struct->component_configuration);
980 camsrc_info("int colorspace = %d", exif_struct->colorspace);
986 static int _camerasrc_get_exif_info (camerasrc_handle_t *handle, camerasrc_exif_t *exif_struct)
988 int photometry_mode = V4L2_PHOTOMETRY_MULTISEG;
990 if (exif_struct == NULL) {
991 return CAMERASRC_ERR_INVALID_PARAMETER;
994 /** Dynamic value **/
997 GET_CTRL_VAL(V4L2_CID_CAMERA_EXIF_EXPTIME, exif_struct->exposure_time_numerator);
998 exif_struct->exposure_time_denominator = 1;
1001 GET_CTRL_VAL(V4L2_CID_CAMERA_EXIF_TV, exif_struct->shutter_speed_numerator);
1002 exif_struct->shutter_speed_denominator = 1;
1005 GET_CTRL_VAL(V4L2_CID_CAMERA_EXIF_BV, exif_struct->brigtness_numerator);
1006 exif_struct->brightness_denominator = 1;
1009 GET_CTRL_VAL(V4L2_CID_CAMERA_EXIF_ISO, exif_struct->iso);
1010 ISO_APPROXIMATE_VALUE(exif_struct->iso, exif_struct->iso);
1013 GET_CTRL_VAL(V4L2_CID_CAMERA_EXIF_FLASH, exif_struct->flash);
1016 exif_struct->exif_image_width = handle->format.img_size.dim.width;
1017 exif_struct->exif_image_height = handle->format.img_size.dim.height;
1019 /*FIXME focal length - Set fixed value at gst_camerasrc_control_get_exif_info function */
1020 exif_struct->focal_len_numerator = 1;
1021 exif_struct->focal_len_denominator = 1;
1023 /*FIXME f number - Set fixed value at gst_camerasrc_control_get_exif_info function */
1024 exif_struct->aperture_f_num_numerator = 1;
1025 exif_struct->aperture_f_num_denominator = 1;
1028 exif_struct->aperture_in_APEX \
1029 = CAMERASRC_EXIF_APERTURE_VALUE_IN_APEX(exif_struct->aperture_f_num_numerator, exif_struct->aperture_f_num_denominator);
1030 exif_struct->max_lens_aperture_in_APEX = 1;
1031 /*= CAMERASRC_EXIF_APERTURE_VALUE_IN_APEX(exif_info.max_aperture_f_num_numerator, exif_info.max_aperture_f_num_denominator);*/
1032 exif_struct->exposure_bias_in_APEX = exif_struct->aperture_in_APEX \
1033 + CAMERASRC_EXIF_SHUTTERSPEED_VALUE_IN_APEX(exif_struct->exposure_time_numerator, exif_struct->exposure_time_denominator);
1035 /* Get the value using CID */
1036 /* Not implemented yet
1037 GET_CTRL_VAL(V4L2_CID_FW_VERSION, exif_struct->software_used);
1039 GET_CTRL_VAL(V4L2_CID_PHOTOMETRY, photometry_mode);
1040 PHOTOMETRY_MODE_TO_METERING_MODE(photometry_mode, exif_struct->metering_mode);
1043 exif_struct->component_configuration = _CAMERASRC_EXIF_COMP_CONF;
1044 exif_struct->colorspace = _CAMERASRC_EXIF_COLORSPACE;
1046 _dump_exif_info(exif_struct);
1048 return CAMERASRC_SUCCESS;
1051 static int fd_on = 0;
1053 static int _camerasrc_set_cmd(camerasrc_handle_t *handle, _camsrc_cmd_t cmd, void *value)
1055 int err = CAMERASRC_ERR_UNKNOWN;
1056 struct v4l2_jpegcompression comp_arg;
1059 case _CAMERASRC_CMD_STROBE_MODE:
1061 camerasrc_strobe_mode_t *mode = (camerasrc_strobe_mode_t*)value;
1063 camsrc_info("[_CAMERASRC_CMD_STROBE_MODE] cmd set value %d", *mode );
1065 SET_CTRL_VAL(V4L2_CID_CAMERA_FLASH_MODE, *mode);
1068 case _CAMERASRC_CMD_FACEDETECTION:
1070 int err = CAMERASRC_ERR_UNKNOWN;
1071 struct v4l2_recognition recog;
1073 camsrc_info("[_CAMERASRC_CMD_FACEDETECTION] cmd set");
1074 if (((int)value) == _CAMERASRC_FACEDETECTION_START) {
1075 camsrc_info("[_CAMERASRC_CMD_FACEDETECTION] start");
1076 recog.mode = V4L2_RECOGNITION_MODE_ON;
1077 recog.pattern = V4L2_RECOG_PATTERN_FACE;
1079 /*recog.detect_idx = 0;*/
1080 recog.action= V4L2_RECOGNITION_ACTION_NONE;
1082 } else if (((int)value) == _CAMERASRC_FACEDETECTION_STOP) {
1083 camsrc_error("[_CAMERASRC_CMD_FACEDETECTION] stop");
1084 recog.mode = V4L2_RECOGNITION_MODE_OFF;
1085 recog.pattern = V4L2_RECOG_PATTERN_FACE;
1087 /*recog.detect_idx = 0;*/
1088 recog.action= V4L2_RECOGNITION_ACTION_NONE;
1091 camsrc_error("[_CAMERASRC_CMD_FACEDETECTION] not support cmd");
1094 err = _camerasrc_ioctl(handle, VIDIOC_S_RECOGNITION, &recog);
1095 if (err != CAMERASRC_SUCCESS) {
1100 case _CAMERASRC_CMD_SHUTTER_SPEED:
1102 camsrc_info("[_CAMERASRC_CMD_SHUTTER_SPEED] cmd set");
1104 case _CAMERASRC_CMD_JPEG_LENGTH:
1106 camsrc_info("[_CAMERASRC_CMD_JPEG_LENGTH] cmd set");
1108 case _CAMERASRC_CMD_JPEG_THMBNL_LENGTH:
1109 camsrc_info("[_CAMERASRC_CMD_JPEG_THMBNL_LENGTH] cmd set");
1110 err = _camerasrc_set_thumbnail_size(handle);
1111 if (err != CAMERASRC_SUCCESS) {
1115 case _CAMERASRC_CMD_EXPOSURE_VALUE:
1116 camsrc_info("[_CAMERASRC_CMD_EXPOSURE_VALUE] cmd set");
1119 case _CAMERASRC_CMD_ESD_CHECK:
1120 camsrc_info("[_CAMERASRC_CMD_ESD_CHECK] cmd set");
1123 case _CAMERASRC_CMD_CTRL:
1124 camsrc_info("[_CAMERASRC_CMD_CTRL] cmd set");
1125 SET_CTRL_VAL(_CAMERASRC_GET_CID(((_camerasrc_ctrl_t *) value)->cid, handle->cur_dev_id), ((_camerasrc_ctrl_t *) value)->value);
1127 case _CAMERASRC_CMD_SUPPORT_EMBED_EXIF:
1129 camsrc_info("[_CAMERASRC_CMD_SUPPORT_EMBED_EXIF] cmd set");
1131 case _CAMERASRC_CMD_SUPPORT_JPEG_ENCODING:
1132 camsrc_warning("[_CAMERASRC_CMD_SUPPORT_JPEG_ENCODING] cmd set isn't supported");
1134 case _CAMERASRC_CMD_AF_CONTROL:
1136 camsrc_info("[_CAMERASRC_CMD_AF_CONTROL] cmd set(value=%d)", value);
1138 /* FIXME : Please fix whole AF implementation!!! */
1139 switch ((int)value) {
1140 case _CAMERASRC_AF_START:
1141 _camerasrc_start_autofocusing(handle);
1143 case _CAMERASRC_AF_STOP:
1144 _camerasrc_stop_autofocusing(handle);
1146 case _CAMERASRC_AF_DESTROY:
1147 _camerasrc_destroy_autofocusing(handle);
1149 case _CAMERASRC_AF_RELEASE:
1150 case _CAMERASRC_AF_INIT:
1152 _camerasrc_init_autofocusing_mode(handle);
1156 case _CAMERASRC_CMD_AF_AREA:
1158 camerasrc_rect_t *rect = (camerasrc_rect_t *)value;
1160 camsrc_info("[_CAMERASRC_CMD_AF_AREA] cmd set (%d,%d,%dx%d)",
1161 rect->x, rect->y, rect->width, rect->height);
1163 SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_LEFT, rect->x);
1164 SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_TOP, rect->y);
1165 SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_WIDTH, 0);/*rect->width); Not supported */
1166 SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_HEIGHT, 0);/*rect->height); Not supported */
1168 if (gettimeofday(&handle->set_af_area_time, NULL) == 0) {
1169 camsrc_info("[_CAMERASRC_CMD_AF_AREA] Get Time Success" );
1171 handle->set_af_area_time.tv_sec = 0;
1172 handle->set_af_area_time.tv_usec = 0;
1173 camsrc_warning("[_CAMERASRC_CMD_AF_AREA] Get Time Failed" );
1177 case _CAMERASRC_CMD_FRAME_DATA:
1179 camsrc_info("[_CAMERASRC_CMD_FRAME_DATA] cmd set");
1181 case _CAMERASRC_CMD_EXIF_INFO:
1183 camsrc_info("[_CAMERASRC_CMD_EXIF_INFO] cmd set");
1185 case _CAMERASRC_CMD_CHECK_ESD:
1187 camsrc_info("[_CAMERASRC_CMD_CHECK_ESD] cmd set");
1189 case _CAMERASRC_CMD_JPEG_COMPRESS_RATIO:
1191 camsrc_info("[_CAMERASRC_CMD_JPEG_COMPRESS_RATIO] cmd set, val = %d", (int)(*((unsigned int*) value)));
1192 if (handle->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
1193 comp_arg.quality = (int)(*((unsigned int*) value));
1194 err = _camerasrc_ioctl(handle, VIDIOC_S_JPEGCOMP, &comp_arg);
1195 if (err != CAMERASRC_SUCCESS) {
1198 } else if (handle->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY) {
1199 err = CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
1203 case _CAMERASRC_CMD_ROTATION:
1205 int *rotate = (int *)value;
1206 camsrc_info("[_CAMERASRC_CMD_ROTATION] cmd set : %d", *rotate);
1207 SET_CTRL_VAL(V4L2_CID_ROTATION, (int)*rotate);
1210 case _CAMERASRC_CMD_SENSOR_MODE:
1212 camerasrc_sensor_mode_t *mode = (camerasrc_sensor_mode_t *)value;
1213 camsrc_info("[_CAMERASRC_CMD_SENSOR_MODE] cmd set : %d", *mode);
1214 SET_CTRL_VAL(V4L2_CID_CAMERA_SENSOR_MODE, (int)*mode);
1217 case _CAMERASRC_CMD_VFLIP:
1219 int *vflip = (int *)value;
1220 camsrc_info("[_CAMERASRC_CMD_VFLIP] cmd set : %d", *vflip);
1221 SET_CTRL_VAL(V4L2_CID_VFLIP, (int)*vflip);
1224 case _CAMERASRC_CMD_HFLIP:
1226 int *hflip = (int *)value;
1227 camsrc_info("[_CAMERASRC_CMD_HFLIP] cmd set : %d", *hflip);
1228 SET_CTRL_VAL(V4L2_CID_HFLIP, (int)*hflip);
1232 camsrc_error("[_CAMERASRC_CMD_UNKNOWN] cmd set");
1233 err = CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
1237 return CAMERASRC_SUCCESS;
1240 camsrc_error("cmd execution error occured");
1245 static int _camerasrc_get_cmd(camerasrc_handle_t *handle, _camsrc_cmd_t cmd, void *value)
1247 int err = CAMERASRC_ERR_UNKNOWN;
1248 struct v4l2_jpegcompression comp_arg;
1251 camsrc_error("value is NULL");
1252 return CAMERASRC_ERR_NULL_POINTER;
1256 case _CAMERASRC_CMD_SUPPORT_EMBED_EXIF:
1257 camsrc_info("[_CAMERASRC_CMD_SUPPORT_EMBED_EXIF] cmd get");
1258 *((int*)value) = _CAMERASRC_CMD_SUPPORT_EMBED_EXIF_DEF;
1260 case _CAMERASRC_CMD_SUPPORT_JPEG_ENCODING:
1261 camsrc_info("[_CAMERASRC_CMD_SUPPORT_JPEG_ENCODING] cmd get(cur_dev_id=%d)", handle->cur_dev_id);
1262 if (handle->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
1268 case _CAMERASRC_CMD_STROBE_MODE:
1270 camerasrc_strobe_mode_t mode;
1272 GET_CTRL_VAL(V4L2_CID_CAMERA_FLASH_MODE, mode);
1273 *((camerasrc_strobe_mode_t*)value) = mode;
1275 camsrc_info("[_CAMERASRC_CMD_STROBE_MODE] cmd get - %d", mode);
1278 case _CAMERASRC_CMD_FACEDETECTION:
1279 camsrc_info("[_CAMERASRC_CMD_FACEDETECTION] cmd get - %d", fd_on);
1280 *(int *)value = fd_on;
1282 case _CAMERASRC_CMD_SHUTTER_SPEED:
1284 camsrc_info("[_CAMERASRC_CMD_SHUTTER_SPEED] cmd get");
1286 case _CAMERASRC_CMD_JPEG_LENGTH:
1288 int err = CAMERASRC_ERR_UNKNOWN;
1289 struct v4l2_control ctrl;
1291 ctrl.id = V4L2_CID_CAM_JPEG_MAIN_SIZE;
1292 err = _camerasrc_ioctl( handle, VIDIOC_G_CTRL, &ctrl );
1293 if (err != CAMERASRC_SUCCESS) {
1298 *((int*)value) = ctrl.value;
1299 camsrc_info("[_CAMERASRC_CMD_JPEG_LENGTH] cmd get");
1302 case _CAMERASRC_CMD_JPEG_THMBNL_LENGTH:
1304 int err = CAMERASRC_ERR_UNKNOWN;
1305 struct v4l2_control ctrl;
1307 ctrl.id = V4L2_CID_CAM_JPEG_THUMB_SIZE;
1308 err = _camerasrc_ioctl( handle, VIDIOC_G_CTRL, &ctrl );
1309 if (err != CAMERASRC_SUCCESS) {
1314 *((int*)value) = ctrl.value;
1315 camsrc_info("[_CAMERASRC_CMD_JPEG_THMBNL_LENGTH] cmd get : %d", *((int*)value));
1318 case _CAMERASRC_CMD_JPEG_THMBNL_OFFSET:
1320 int err = CAMERASRC_ERR_UNKNOWN;
1321 struct v4l2_control ctrl;
1322 ctrl.id = V4L2_CID_CAM_JPEG_THUMB_OFFSET;
1324 err = _camerasrc_ioctl( handle, VIDIOC_G_CTRL, &ctrl );
1325 if(err != CAMERASRC_SUCCESS)
1331 *((int*)value) = ctrl.value;
1332 camsrc_info("[_CAMERASRC_CMD_JPEG_THMBNL_OFFSET] cmd get : %x", *((int*)value));
1335 case _CAMERASRC_CMD_JPEG_SCRNL_LENGTH:
1337 int err = CAMERASRC_ERR_UNKNOWN;
1338 struct v4l2_control ctrl;
1339 ctrl.id = V4L2_CID_CAM_JPEG_POSTVIEW_SIZE;
1341 err = _camerasrc_ioctl(handle, VIDIOC_G_CTRL, &ctrl);
1342 if (err != CAMERASRC_SUCCESS) {
1347 *((int*)value) = ctrl.value;
1348 camsrc_info("[_CAMERASRC_CMD_JPEG_SCRNL_LENGTH] cmd get : %x", *((int*)value));
1351 case _CAMERASRC_CMD_JPEG_SCRNL_OFFSET:
1353 int err = CAMERASRC_ERR_UNKNOWN;
1354 struct v4l2_control ctrl;
1355 ctrl.id = V4L2_CID_CAM_JPEG_POSTVIEW_OFFSET;
1357 err = _camerasrc_ioctl( handle, VIDIOC_G_CTRL, &ctrl );
1358 if (err != CAMERASRC_SUCCESS) {
1363 *((int*)value) = ctrl.value;
1364 camsrc_info("[_CAMERASRC_CMD_JPEG_SCRNL_OFFSET] cmd get : %x", *((int*)value));
1367 case _CAMERASRC_CMD_EXPOSURE_VALUE:
1369 camsrc_info("[_CAMERASRC_CMD_EXPOSURE_VALUE] cmd get");
1371 case _CAMERASRC_CMD_ESD_CHECK:
1373 camsrc_info("[_CAMERASRC_CMD_ESD_CHECK] cmd get");
1375 case _CAMERASRC_CMD_CTRL:
1376 camsrc_info("[_CAMERASRC_CMD_CTRL] cmd get");
1377 GET_CTRL_VAL(_CAMERASRC_GET_CID(((_camerasrc_ctrl_t *) value)->cid, handle->cur_dev_id), ((_camerasrc_ctrl_t *) value)->value);
1379 case _CAMERASRC_CMD_AF_CONTROL:
1381 camsrc_info("[_CAMERASRC_CMD_AF_CONTROL] cmd get");
1383 case _CAMERASRC_CMD_AF_AREA:
1385 camerasrc_rect_t* rect = (camerasrc_rect_t*)value;
1387 GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_LEFT, rect->x);
1388 GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_TOP, rect->y);
1389 GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_WIDTH, rect->width);
1390 GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_HEIGHT, rect->height);
1392 camsrc_info("[_CAMERASRC_CMD_AF_AREA] cmd get (%d,%d,%dx%d)",
1393 rect->x, rect->y, rect->width, rect->height);
1396 case _CAMERASRC_CMD_FRAME_DATA:
1398 /*camsrc_info("[_CAMERASRC_CMD_FRAME_DATA] cmd get");*/
1399 err = _camerasrc_get_frame_data(handle, (camerasrc_frame_data_t*)value);
1400 if (err != CAMERASRC_SUCCESS) {
1404 case _CAMERASRC_CMD_EXIF_INFO:
1405 camsrc_info("[_CAMERASRC_CMD_EXIF_INFO] cmd get");
1406 err = _camerasrc_get_exif_info (handle, (camerasrc_exif_t*)value);
1407 if (err != CAMERASRC_SUCCESS) {
1411 case _CAMERASRC_CMD_CHECK_ESD:
1412 camsrc_info("[_CAMERASRC_CMD_CHECK_ESD] cmd get");
1413 GET_CTRL_VAL(V4L2_CID_ESD_INT, *((int *) value));
1415 case _CAMERASRC_CMD_JPEG_COMPRESS_RATIO:
1416 camsrc_info("[_CAMERASRC_CMD_JPEG_COMPRESS_RATIO] cmd get");
1417 err = _camerasrc_ioctl(handle, VIDIOC_G_JPEGCOMP, &comp_arg);
1418 if (err != CAMERASRC_SUCCESS) {
1421 *((unsigned int*)value) = (int)comp_arg.quality;
1423 case _CAMERASRC_CMD_ROTATION:
1424 camsrc_info("[_CAMERASRC_CMD_ROTATION] cmd get");
1425 GET_CTRL_VAL(V4L2_CID_ROTATION, *(int*)value);
1427 case _CAMERASRC_CMD_SENSOR_MODE:
1428 camsrc_info("[_CAMERASRC_CMD_SENSOR_MODE] cmd get");
1429 GET_CTRL_VAL(V4L2_CID_CAMERA_SENSOR_MODE, *(int*)value);
1431 case _CAMERASRC_CMD_VFLIP:
1432 camsrc_info("[_CAMERASRC_CMD_VFLIP] cmd get");
1433 GET_CTRL_VAL(V4L2_CID_VFLIP, *(int*)value);
1435 case _CAMERASRC_CMD_HFLIP:
1436 camsrc_info("[_CAMERASRC_CMD_HFLIP] cmd get");
1437 GET_CTRL_VAL(V4L2_CID_HFLIP, *(int*)value);
1440 camsrc_error("[_CAMERASRC_CMD_UNKNOWN] cmd get");
1441 err = CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
1445 return CAMERASRC_SUCCESS;
1448 camsrc_error("cmd execution error occured");
1453 static const CAMERASRC_DEV_DEPENDENT_MISC_FUNC dev_misc_functions = {
1454 ._ioctl = _camerasrc_ioctl,
1455 ._ioctl_once = _camerasrc_ioctl_once,
1456 ._run_autofocusing = _camerasrc_run_autofocusing,
1457 ._skip_frame = _camerasrc_skip_frame,
1458 ._copy_frame = _camerasrc_copy_frame,
1459 ._set_cmd = _camerasrc_set_cmd,
1460 ._get_cmd = _camerasrc_get_cmd,
1463 const CAMERASRC_DEV_DEPENDENT_MISC_FUNC *dev_misc_func = &dev_misc_functions;