Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 1 | /* |
| 2 | * atomisp_device.cpp - atomisp device |
| 3 | * |
| 4 | * Copyright (c) 2014-2015 Intel Corporation |
| 5 | * |
| 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 |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 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. |
| 17 | * |
| 18 | * Author: Wind Yuan <feng.yuan@intel.com> |
| 19 | */ |
| 20 | |
| 21 | #include "atomisp_device.h" |
| 22 | #include "v4l2_buffer_proxy.h" |
| 23 | #include <linux/v4l2-subdev.h> |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 24 | |
| 25 | namespace XCam { |
| 26 | |
| 27 | AtomispDevice::AtomispDevice (const char *name) |
| 28 | : V4l2Device (name) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | AtomispDevice::~AtomispDevice () |
| 33 | { |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | XCamReturn |
| 37 | AtomispDevice::pre_set_format (struct v4l2_format &format) |
| 38 | { |
| 39 | uint32_t fps_n = 0, fps_d = 0; |
| 40 | struct v4l2_subdev_format subdev_fmt; |
| 41 | |
| 42 | // set framerate by subdev |
| 43 | this->get_framerate (fps_n, fps_d); |
| 44 | if (fps_n != 0 && fps_d != 0) { |
| 45 | struct v4l2_subdev_frame_interval frame_intvl; |
| 46 | |
| 47 | xcam_mem_clear (&frame_intvl); |
| 48 | if (io_control (VIDIOC_SUBDEV_G_FRAME_INTERVAL, &frame_intvl) < 0) { |
| 49 | XCAM_LOG_WARNING ("atomisp device(%s) get framerate failed ", XCAM_STR (get_device_name())); |
| 50 | } else { |
| 51 | frame_intvl.interval.denominator = fps_n; |
| 52 | frame_intvl.interval.numerator = fps_d; |
| 53 | if (io_control (VIDIOC_SUBDEV_S_FRAME_INTERVAL, &frame_intvl) < 0) { |
| 54 | XCAM_LOG_WARNING ("atomisp device(%s) set framerate failed", XCAM_STR (get_device_name())); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | xcam_mem_clear (&subdev_fmt); |
| 60 | subdev_fmt.pad = 0; |
| 61 | subdev_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; |
| 62 | subdev_fmt.format.width = format.fmt.pix.width + 32; |
| 63 | subdev_fmt.format.height = format.fmt.pix.height + 17; |
| 64 | subdev_fmt.format.code = V4L2_MBUS_FMT_SRGGB10_1X10; //depends on sensor V4L2_MBUS_FMT_UYVY8_1X16; |
| 65 | subdev_fmt.format.field = V4L2_FIELD_NONE; |
| 66 | |
| 67 | if (io_control(VIDIOC_SUBDEV_S_FMT, &subdev_fmt) < 0) { |
| 68 | XCAM_LOG_ERROR ("atomisp device(%s) set subdev format failed", XCAM_STR (get_device_name())); |
| 69 | return XCAM_RETURN_ERROR_IOCTL; |
| 70 | } |
| 71 | return XCAM_RETURN_NO_ERROR; |
| 72 | } |
| 73 | |
| 74 | XCamReturn |
| 75 | AtomispDevice::allocate_buffer ( |
| 76 | SmartPtr<V4l2Buffer> &buf, |
| 77 | const struct v4l2_format &format, |
| 78 | const uint32_t index) |
| 79 | { |
| 80 | #if HAVE_LIBDRM |
Jia Meng | 8adc164 | 2015-04-08 08:59:28 +0000 | [diff] [blame] | 81 | if (!_drm_disp.ptr()) { |
| 82 | _drm_disp = DrmDisplay::instance (); |
| 83 | } |
| 84 | |
Wind Yuan | 7eae2d8 | 2015-02-11 16:57:30 +0800 | [diff] [blame] | 85 | if (get_mem_type () == V4L2_MEMORY_DMABUF && _drm_disp.ptr () != NULL) { |
Wind Yuan | 50f5e9e | 2015-03-26 16:57:13 +0800 | [diff] [blame] | 86 | buf = _drm_disp->create_drm_buf (format, index, get_capture_buf_type ()); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 87 | if (!buf.ptr()) { |
| 88 | XCAM_LOG_WARNING ("atomisp device(%s) allocate buffer failed", XCAM_STR (get_device_name())); |
| 89 | return XCAM_RETURN_ERROR_MEM; |
| 90 | } |
| 91 | return XCAM_RETURN_NO_ERROR; |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | return V4l2Device::allocate_buffer (buf, format, index); |
| 96 | } |
| 97 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 98 | }; |