Exemplo n.º 1
0
bool
IaIspAdaptor15::init (
    const ia_binary_data *cpf,
    unsigned int max_width,
    unsigned int max_height,
    ia_cmc_t *cmc,
    ia_mkn *mkn)
{
    xcam_mem_clear (&_input_params);
    _input_params.isp_vamem_type = 1;
    _handle = ia_isp_1_5_init (cpf, max_width, max_height, cmc, mkn);
    XCAM_FAIL_RETURN (ERROR, _handle, false, "ia_isp 1.5 init failed");
    return true;
}
Exemplo n.º 2
0
VKPipeline::VKPipeline (
    const SmartPtr<VKDevice> dev,
    const ShaderVec &shaders,
    const VKDescriptor::BindingArray &bindings,
    const VKConstRange::VKConstantArray &consts)
    : _pipe_id (VK_NULL_HANDLE)
    , _dev (dev)
    , _shaders (shaders)
    , _bindings (bindings)
    , _push_consts (consts)
{
    _allocator = _dev->get_allocation_cb ();
    xcam_mem_clear (_name);
}
Exemplo n.º 3
0
AiqAeHandler::AiqAeResult::AiqAeResult()
{
    xcam_mem_clear (&ae_result);
    xcam_mem_clear (&ae_exp_ret);
    xcam_mem_clear (&aiq_exp_param);
    xcam_mem_clear (&sensor_exp_param);
    xcam_mem_clear (&weight_grid);
    xcam_mem_clear (&flash_param);
}
Exemplo n.º 4
0
X3aAnalyzerAiq::X3aAnalyzerAiq (SmartPtr<IspController> &isp, const char *cpf_path)
    : X3aAnalyzer ("X3aAnalyzerAiq")
    , _isp (isp)
    , _sensor_data_ready (false)
    , _cpf_path (NULL)
{
    if (cpf_path)
        _cpf_path = strdup (cpf_path);

    _aiq_compositor = new AiqCompositor ();
    XCAM_ASSERT (_aiq_compositor.ptr());
    xcam_mem_clear (_sensor_mode_data);

    XCAM_LOG_DEBUG ("X3aAnalyzerAiq constructed");
}
Exemplo n.º 5
0
V4l2Device::V4l2Device (const char *name)
    : _name (NULL)
    , _fd (-1)
    , _sensor_id (0)
    , _capture_mode (0)
    , _capture_buf_type (V4L2_BUF_TYPE_VIDEO_CAPTURE)
    , _memory_type (V4L2_MEMORY_MMAP)
    , _fps_n (0)
    , _fps_d (0)
    , _active (false)
    , _buf_count (XCAM_V4L2_DEFAULT_BUFFER_COUNT)
{
    if (name)
        _name = strndup (name, XCAM_MAX_STR_SIZE);
    xcam_mem_clear (_format);
}
Exemplo n.º 6
0
XCamReturn
IspController::set_3a_focus (const XCam3aResultFocus &focus)
{
    int position = focus.position;
    struct v4l2_control control;

    xcam_mem_clear (&control);
    control.id = V4L2_CID_FOCUS_ABSOLUTE;
    control.value = position;

    if (_device->io_control (VIDIOC_S_CTRL, &control) < 0) {
        XCAM_LOG_WARNING (" set focus result failed to device");
        return XCAM_RETURN_ERROR_IOCTL;
    }
    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 7
0
bool
AiqCompositor::set_3a_stats (SmartPtr<X3aIspStatistics> &stats)
{
    ia_aiq_statistics_input_params aiq_stats_input;
    ia_aiq_rgbs_grid *rgbs_grids = NULL;
    ia_aiq_af_grid *af_grids = NULL;

    xcam_mem_clear (&aiq_stats_input);
    aiq_stats_input.frame_timestamp = stats->get_timestamp();
    aiq_stats_input.frame_id = stats->get_timestamp() + 1;
    aiq_stats_input.rgbs_grids = (const ia_aiq_rgbs_grid **)&rgbs_grids;
    aiq_stats_input.num_rgbs_grids = 1;
    aiq_stats_input.af_grids = (const ia_aiq_af_grid **)(&af_grids);
    aiq_stats_input.num_af_grids = 1;

    aiq_stats_input.frame_af_parameters = NULL;
    aiq_stats_input.external_histograms = NULL;
    aiq_stats_input.num_external_histograms = 0;
    aiq_stats_input.camera_orientation = ia_aiq_camera_orientation_unknown;

    if (_pa_result)
        aiq_stats_input.frame_pa_parameters = _pa_result;
    if (_ae_handler->is_started())
        aiq_stats_input.frame_ae_parameters = _ae_handler->get_result ();
    //if (_awb_handler->is_started())
    //    aiq_stats_input.frame_awb_parameters = _awb_handler->get_result();

    if (!_adaptor->convert_statistics (stats->get_3a_stats(), &rgbs_grids, &af_grids)) {
        XCAM_LOG_WARNING ("ia isp adaptor convert 3a stats failed");
        return false;
    }

    XCAM_LOG_DEBUG ("statistics grid info, width:%u, height:%u, blk_r:%u, blk_b:%u, blk_gr:%u, blk_gb:%u",
                    aiq_stats_input.rgbs_grids[0]->grid_width,
                    aiq_stats_input.rgbs_grids[0]->grid_height,
                    aiq_stats_input.rgbs_grids[0]->blocks_ptr->avg_r,
                    aiq_stats_input.rgbs_grids[0]->blocks_ptr->avg_b,
                    aiq_stats_input.rgbs_grids[0]->blocks_ptr->avg_gr,
                    aiq_stats_input.rgbs_grids[0]->blocks_ptr->avg_gb);

    if (ia_aiq_statistics_set(get_handle (), &aiq_stats_input) != ia_err_none) {
        XCAM_LOG_ERROR ("Aiq set statistic failed");
        return false;
    }
    return true;
}
Exemplo n.º 8
0
void
CommonHandler::reset_parameters ()
{
    xcam_mem_clear (&_params);

    _params.is_manual_gamma = false;
    _params.nr_level = 0.0;
    _params.tnr_level = 0.0;
    _params.brightness = 0.0;
    _params.contrast = 0.0;
    _params.hue = 0.0;
    _params.saturation = 0.0;
    _params.sharpness = 0.0;
    _params.enable_dvs = false;
    _params.enable_gbce = false;
    _params.enable_night_mode = false;
}
Exemplo n.º 9
0
XCamReturn
V4l2SubDevice::unsubscribe_event (int event)
{
    struct v4l2_event_subscription sub;
    int ret = 0;

    XCAM_ASSERT (is_opened());

    xcam_mem_clear (sub);
    sub.type = event;

    ret = this->io_control (VIDIOC_UNSUBSCRIBE_EVENT, &sub);
    if (ret < 0) {
        XCAM_LOG_DEBUG ("subdev(%s) unsubscribe event(%d) failed", XCAM_STR(_name), event);
        return XCAM_RETURN_ERROR_IOCTL;
    }
    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 10
0
void
HybridAnalyzer::x3a_calculation_done (XAnalyzer *analyzer, X3aResultList &results)
{
    XCAM_UNUSED (analyzer);

    static XCam3aResultHead *res_heads[XCAM_3A_MAX_RESULT_COUNT];
    xcam_mem_clear (res_heads);
    XCAM_ASSERT (results.size () < XCAM_3A_MAX_RESULT_COUNT);

    uint32_t result_count = translate_3a_results_to_xcam (results,
                            res_heads, XCAM_3A_MAX_RESULT_COUNT);
    convert_results (res_heads, result_count, results);
    for (uint32_t i = 0; i < result_count; ++i) {
        if (res_heads[i])
            free_3a_result (res_heads[i]);
    }

    notify_calculation_done (results);
}
Exemplo n.º 11
0
/*! \brief v4l2 set format
 *
 * \param[in]    width            format width
 * \param[in]    height           format height
 * \param[in]    pixelformat      fourcc
 * \param[in]    field            V4L2_FIELD_INTERLACED or V4L2_FIELD_NONE
 */
XCamReturn
V4l2Device::set_format (
    uint32_t width,  uint32_t height,
    uint32_t pixelformat, enum v4l2_field field, uint32_t bytes_perline)
{

    struct v4l2_format format;
    xcam_mem_clear (format);

    format.type = _capture_buf_type;
    format.fmt.pix.width = width;
    format.fmt.pix.height = height;
    format.fmt.pix.pixelformat = pixelformat;
    format.fmt.pix.field = field;

    if (bytes_perline != 0)
        format.fmt.pix.bytesperline = bytes_perline;
    return set_format (format);
}
Exemplo n.º 12
0
void
AwbHandler::reset_parameters ()
{
    xcam_mem_clear (&_params);
    _params.mode = XCAM_AWB_MODE_AUTO;
    _params.speed = 1.0;
    _params.cct_min = 0;
    _params.cct_max = 0;
    _params.gr_gain = 0.0;
    _params.r_gain = 0.0;
    _params.b_gain = 0.0;
    _params.gb_gain = 0.0;

    _params.window.x_start = 0;
    _params.window.y_start = 0;
    _params.window.x_end = 0;
    _params.window.y_end = 0;
    _params.window.weight = 0;
}
Exemplo n.º 13
0
int
V4l2Device::poll_event (int timeout_msec)
{
    struct pollfd poll_fd;
    int ret = 0;

    XCAM_ASSERT (_fd > 0);

    xcam_mem_clear (poll_fd);
    poll_fd.fd = _fd;
    poll_fd.events = (POLLPRI | POLLIN | POLLERR | POLLNVAL | POLLHUP);

    ret = poll (&poll_fd, 1, timeout_msec);
    if (ret > 0 && (poll_fd.revents & (POLLERR | POLLNVAL | POLLHUP))) {
        XCAM_LOG_DEBUG ("v4l2 subdev(%s) polled error", XCAM_STR(_name));
        return -1;
    }
    return ret;

}
Exemplo n.º 14
0
XCamReturn
CLPostImageProcessor::apply_3a_result (SmartPtr<X3aResult> &result)
{
    STREAM_LOCK;

    if (!result.ptr ())
        return XCAM_RETURN_BYPASS;

    uint32_t res_type = result->get_type ();

    switch (res_type) {
    case XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_YUV: {
        SmartPtr<X3aTemporalNoiseReduction> tnr_res = result.dynamic_cast_ptr<X3aTemporalNoiseReduction> ();
        XCAM_ASSERT (tnr_res.ptr ());
        if (_tnr.ptr ()) {
            if (_defog_mode != CLPostImageProcessor::DefogDisabled) {
                XCam3aResultTemporalNoiseReduction config;
                xcam_mem_clear (config);
                // isp processor
                // config.gain = 0.12;

                // cl processor
                config.gain = 0.22;

                config.threshold [0] = 0.00081;
                config.threshold [1] = 0.00072;
                _tnr->set_yuv_config (config);
            } else {
                _tnr->set_yuv_config (tnr_res->get_standard_result ());
            }
        }
        break;
    }
    default:
        XCAM_LOG_WARNING ("CLPostImageProcessor unknow 3a result: %d", res_type);
        break;
    }

    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 15
0
XCamReturn
V4l2Device::get_format (struct v4l2_format &format)
{
    if (is_activated ()) {
        format = _format;
        return XCAM_RETURN_NO_ERROR;
    }

    if (!is_opened ())
        return XCAM_RETURN_ERROR_IOCTL;

    xcam_mem_clear (format);
    format.type = _capture_buf_type;

    if (this->io_control (VIDIOC_G_FMT, &format) < 0) {
        // FIXME: also log the device name?
        XCAM_LOG_ERROR("Fail to get format via ioctl VIDVIO_G_FMT.");
        return XCAM_RETURN_ERROR_IOCTL;
    }

    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 16
0
XCamReturn
PollThread::init_3a_stats_pool ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    struct atomisp_parm parameters;

    xcam_mem_clear (parameters);
    ret = _isp_controller->get_isp_parameter (parameters);
    if (ret != XCAM_RETURN_NO_ERROR ) {
        XCAM_LOG_WARNING ("get isp parameters failed");
        return ret;
    }
    if (!parameters.info.width || !parameters.info.height) {
        XCAM_LOG_WARNING ("get isp parameters width or height wrong");
        return XCAM_RETURN_ERROR_ISP;
    }
    _3a_stats_pool.dynamic_cast_ptr<X3aStatisticsQueue>()->set_grid_info (parameters.info);
    if (!_3a_stats_pool->reserve (6)) {
        XCAM_LOG_WARNING ("init_3a_stats_pool failed to reserve stats buffer.");
        return XCAM_RETURN_ERROR_MEM;
    }
    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 17
0
std::list<struct v4l2_fmtdesc>
V4l2Device::enum_formats ()
{
    std::list<struct v4l2_fmtdesc> formats;
    struct v4l2_fmtdesc format;
    uint32_t i = 0;

    while (1) {
        xcam_mem_clear (format);
        format.index = i++;
        format.type = _capture_buf_type;
        if (this->io_control (VIDIOC_ENUM_FMT, &format) < 0) {
            if (errno == EINVAL)
                break;
            else { // error
                XCAM_LOG_DEBUG ("enum formats failed");
                return formats;
            }
        }
        formats.push_back (format);
    }

    return formats;
}
Exemplo n.º 18
0
void
AeHandler::reset_parameters ()
{
    // in case missing any parameters
    xcam_mem_clear (&_params);

    _params.mode = XCAM_AE_MODE_AUTO;
    _params.metering_mode = XCAM_AE_METERING_MODE_AUTO;
    _params.flicker_mode = XCAM_AE_FLICKER_MODE_AUTO;
    _params.speed = 1.0;
    _params.exposure_time_min = UINT64_C(0);
    _params.exposure_time_max = UINT64_C(0);
    _params.max_analog_gain = 0.0;
    _params.manual_exposure_time = UINT64_C (0);
    _params.manual_analog_gain = 0.0;
    _params.aperture_fn = 0.0;
    _params.ev_shift = 0.0;

    _params.window.x_start = 0;
    _params.window.y_start = 0;
    _params.window.x_end = 0;
    _params.window.y_end = 0;
    _params.window.weight = 0;
}
Exemplo n.º 19
0
CLWorkSize::CLWorkSize ()
    : dim (XCAM_DEFAULT_IMAGE_DIM)
{
    xcam_mem_clear (global);
    xcam_mem_clear (local);
}
Exemplo n.º 20
0
XCamReturn
X3aAnalyzerAiq::configure_3a ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    X3aResultList first_results;

    if (!_sensor_data_ready) {
        struct atomisp_sensor_mode_data sensor_mode_data;
        xcam_mem_clear (sensor_mode_data);
        XCAM_ASSERT (_isp.ptr());

        ret = _isp->get_sensor_mode_data (sensor_mode_data);
        XCAM_FAIL_RETURN (WARNING, ret == XCAM_RETURN_NO_ERROR, ret, "get sensor mode data failed");
        _sensor_mode_data = sensor_mode_data;
        _sensor_data_ready = true;
    }

    if (!_aiq_compositor->set_sensor_mode_data (&_sensor_mode_data)) {
        XCAM_LOG_WARNING ("AIQ configure 3a failed");
        return XCAM_RETURN_ERROR_AIQ;
    }

    XCAM_LOG_DEBUG ("X3aAnalyzerAiq got sensor mode data, coarse_time_min:%u, "
                    "coarse_time_max_margin:%u, "
                    "fine_time_min:%u, fine_time_max_margin:%u, "
                    "fine_time_def:%u, "
                    "frame_length_lines:%u, line_length_pck:%u, "
                    "vt_pix_clk_freq_mhz:%u, "
                    "crop_horizontal_start:%u, crop_vertical_start:%u, "
                    "crop_horizontal_end:%u, crop_vertical_end:%u, "
                    "output_width:%u, output_height:%u, "
                    "binning_factor_x:%u, binning_factor_y:%u",
                    _sensor_mode_data.coarse_integration_time_min,
                    _sensor_mode_data.coarse_integration_time_max_margin,
                    _sensor_mode_data.fine_integration_time_min,
                    _sensor_mode_data.fine_integration_time_max_margin,
                    _sensor_mode_data.fine_integration_time_def,
                    _sensor_mode_data.frame_length_lines,
                    _sensor_mode_data.line_length_pck,
                    _sensor_mode_data.vt_pix_clk_freq_mhz,
                    _sensor_mode_data.crop_horizontal_start,
                    _sensor_mode_data.crop_vertical_start,
                    _sensor_mode_data.crop_horizontal_end,
                    _sensor_mode_data.crop_vertical_end,
                    _sensor_mode_data.output_width,
                    _sensor_mode_data.output_height,
                    (uint32_t)_sensor_mode_data.binning_factor_x,
                    (uint32_t)_sensor_mode_data.binning_factor_y);

    // initialize ae and awb
    get_ae_handler ()->analyze (first_results);
    get_awb_handler ()->analyze (first_results);

    ret = _aiq_compositor->integrate (first_results);
    XCAM_FAIL_RETURN (WARNING, ret == XCAM_RETURN_NO_ERROR, ret, "AIQ configure_3a failed on integrate results");

    if (!first_results.empty()) {
        notify_calculation_done (first_results);
    }

    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 21
0
 IaIspAdaptor22 () {
     xcam_mem_clear (&_input_params);
 }
Exemplo n.º 22
0
XCamReturn
V4l2Device::allocate_buffer (
    SmartPtr<V4l2Buffer> &buf,
    const struct v4l2_format &format,
    const uint32_t index)
{
    struct v4l2_buffer v4l2_buf;

    xcam_mem_clear (v4l2_buf);
    v4l2_buf.index = index;
    v4l2_buf.type = _capture_buf_type;
    v4l2_buf.memory = _memory_type;

    switch (_memory_type) {
    case V4L2_MEMORY_DMABUF:
    {
        struct v4l2_exportbuffer expbuf;
        xcam_mem_clear (expbuf);
        expbuf.type = _capture_buf_type;
        expbuf.index = index;
        expbuf.flags = O_CLOEXEC;
        if (io_control (VIDIOC_EXPBUF, &expbuf) < 0) {
            XCAM_LOG_WARNING ("device(%s) get dma buf(%d) failed", XCAM_STR (_name), index);
            return XCAM_RETURN_ERROR_MEM;
        }
        v4l2_buf.m.fd = expbuf.fd;
        v4l2_buf.length = format.fmt.pix.sizeimage;
    }
    break;
    case V4L2_MEMORY_MMAP:
    {
        void *pointer;
        int map_flags = MAP_SHARED;
#ifdef NEED_MAP_32BIT
        map_flags |= MAP_32BIT;
#endif
        if (io_control (VIDIOC_QUERYBUF, &v4l2_buf) < 0) {
            XCAM_LOG_WARNING("device(%s) query MMAP buf(%d) failed", XCAM_STR(_name), index);
            return XCAM_RETURN_ERROR_MEM;
        }
        pointer = mmap (0, v4l2_buf.length, PROT_READ | PROT_WRITE, map_flags, _fd, v4l2_buf.m.offset);
        if (pointer == MAP_FAILED) {
            XCAM_LOG_WARNING("device(%s) mmap buf(%d) failed", XCAM_STR(_name), index);
            return XCAM_RETURN_ERROR_MEM;
        }
        v4l2_buf.m.userptr = (uintptr_t) pointer;
    }
    break;
    case V4L2_MEMORY_USERPTR:
    default:
        XCAM_ASSERT (false);
        XCAM_LOG_WARNING (
            "device(%s) allocated buffer mem_type(%d) doesn't support",
            XCAM_STR (_name), _memory_type);
        return XCAM_RETURN_ERROR_MEM;
    }

    buf = new V4l2Buffer (v4l2_buf, _format);

    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 23
0
cl_kernel
CLContext::generate_kernel_id (
    CLKernel *kernel,
    const uint8_t *source, size_t length,
    CLContext::KernelBuildType type)
{
    struct CLProgram {
        cl_program id;

        CLProgram ()
            : id (NULL)
        {}
        ~CLProgram () {
            if (id)
                clReleaseProgram (id);
        }
    };

    CLProgram program;
    cl_kernel kernel_id = NULL;
    cl_int error_code = CL_SUCCESS;
    cl_device_id device_id = _device->get_device_id ();
    const char * name = kernel->get_kernel_name ();

    XCAM_ASSERT (source && length);
    XCAM_ASSERT (name);

    switch (type) {
    case KERNEL_BUILD_SOURCE:
        program.id =
            clCreateProgramWithSource (
                _context_id, 1,
                (const char**)(&source), (const size_t *)&length,
                &error_code);
        break;
    case KERNEL_BUILD_BINARY:
        program.id =
            clCreateProgramWithBinary (
                _context_id, 1, &device_id,
                (const size_t *)&length, (const uint8_t**)(&source),
                NULL, &error_code);
        break;
    }

    XCAM_FAIL_RETURN (
        WARNING,
        error_code == CL_SUCCESS,
        NULL,
        "cl create program failed with error_cod:%d", error_code);
    XCAM_ASSERT (program.id);

    error_code = clBuildProgram (program.id, 1, &device_id, NULL, CLContext::program_pfn_notify, this);
    if (error_code != CL_SUCCESS) {
        char error_log [XCAM_CL_MAX_STR_SIZE];
        xcam_mem_clear (error_log);
        clGetProgramBuildInfo (program.id, device_id, CL_PROGRAM_BUILD_LOG, sizeof (error_log) - 1, error_log, NULL);
        XCAM_LOG_WARNING ("CL build program failed on %s, build log:%s", name, error_log);
        return NULL;
    }

    kernel_id = clCreateKernel (program.id, name, &error_code);
    XCAM_FAIL_RETURN (
        WARNING,
        error_code == CL_SUCCESS,
        NULL,
        "cl create kernel(%s) failed with error_cod:%d", name, error_code);

    return kernel_id;
}
Exemplo n.º 24
0
XCamReturn
V4l2Device::set_format (struct v4l2_format &format)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    XCAM_FAIL_RETURN (ERROR, !is_activated (), XCAM_RETURN_ERROR_PARAM,
                      "Cannot set format to v4l2 device while it is active.");

    XCAM_FAIL_RETURN (ERROR, is_opened (), XCAM_RETURN_ERROR_FILE,
                      "Cannot set format to v4l2 device while it is closed.");

    struct v4l2_format tmp_format = format;

    ret = pre_set_format (format);
    if (ret != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_WARNING ("device(%s) pre_set_format failed", XCAM_STR (_name));
        return ret;
    }

    if (io_control (VIDIOC_S_FMT, &format) < 0) {
        if (errno == EBUSY) {
            // TODO log device name
            XCAM_LOG_ERROR("Video device is busy, fail to set format.");
        } else {
            // TODO log format details and errno
            XCAM_LOG_ERROR("Fail to set format: %s", strerror(errno));
        }

        return XCAM_RETURN_ERROR_IOCTL;
    }

    if (tmp_format.fmt.pix.width != format.fmt.pix.width || tmp_format.fmt.pix.height != format.fmt.pix.height) {
        XCAM_LOG_ERROR (
            "device(%s) set v4l2 format failed, supported format: width:%d, height:%d",
            XCAM_STR (_name),
            format.fmt.pix.width,
            format.fmt.pix.height);

        return XCAM_RETURN_ERROR_PARAM;
    }

    while (_fps_n && _fps_d) {
        struct v4l2_streamparm param;
        xcam_mem_clear (param);
        param.type = _capture_buf_type;
        if (io_control (VIDIOC_G_PARM, &param) < 0) {
            XCAM_LOG_WARNING ("device(%s) set framerate failed on VIDIOC_G_PARM but continue", XCAM_STR (_name));
            break;
        }

        if (!(param.parm.capture.capability & V4L2_CAP_TIMEPERFRAME))
            break;

        param.parm.capture.timeperframe.numerator = _fps_d;
        param.parm.capture.timeperframe.denominator = _fps_n;

        if (io_control (VIDIOC_S_PARM, &param) < 0) {
            XCAM_LOG_WARNING ("device(%s) set framerate failed on VIDIOC_S_PARM but continue", XCAM_STR (_name));
            break;
        }
        _fps_n = param.parm.capture.timeperframe.denominator;
        _fps_d = param.parm.capture.timeperframe.numerator;
        XCAM_LOG_INFO ("device(%s) set framerate(%d/%d)", XCAM_STR (_name), _fps_n, _fps_d);

        // exit here, otherwise it is an infinite loop
        break;
    }

    ret = post_set_format (format);
    if (ret != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_WARNING ("device(%s) post_set_format failed", XCAM_STR (_name));
        return ret;
    }

    _format = format;
    XCAM_LOG_INFO (
        "device(%s) set format(w:%d, h:%d, pixelformat:%s, bytesperline:%d,image_size:%d)",
        XCAM_STR (_name),
        format.fmt.pix.width, format.fmt.pix.height,
        xcam_fourcc_to_string (format.fmt.pix.pixelformat),
        format.fmt.pix.bytesperline,
        format.fmt.pix.sizeimage);

    return XCAM_RETURN_NO_ERROR;
}
Exemplo n.º 25
0
XCamReturn
X3aCiqTnrTuningHandler::analyze (X3aResultList &output)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    const X3aCiqTnrTuningStaticData* tuning = imx185_tuning;
    if (NULL != _tuning_data) {
        tuning = (X3aCiqTnrTuningStaticData*)_tuning_data;;
    }

    XCam3aResultTemporalNoiseReduction config;
    SmartPtr<X3aTemporalNoiseReduction> rgb_result = new X3aTemporalNoiseReduction (XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_RGB);
    SmartPtr<X3aTemporalNoiseReduction> yuv_result = new X3aTemporalNoiseReduction (XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_YUV);

    double analog_gain = get_current_analog_gain ();
    double max_analog_gain = get_max_analog_gain ();
    XCAM_LOG_DEBUG ("get current AG = (%f), max AG = (%f)", analog_gain, max_analog_gain);

    uint8_t i_curr = 0;
    uint8_t i_prev = 0;
    for (i_curr = 0; i_curr < X3A_CIQ_GAIN_STEPS; i_curr++) {
        if (analog_gain <= tuning[i_curr].analog_gain) {
            break;
        }
        i_prev = i_curr;
    }
    if (i_curr >= X3A_CIQ_GAIN_STEPS) {
        i_curr = X3A_CIQ_GAIN_STEPS - 1;
    }

    //Calculate YUV config
    xcam_mem_clear (config);
    config.gain = linear_interpolate_p2 (tuning[i_prev].yuv_gain, tuning[i_curr].yuv_gain,
                                         tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].y_threshold, tuning[i_curr].y_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].uv_threshold, tuning[i_curr].uv_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[2] = 0.0;
    XCAM_LOG_DEBUG ("Calculate YUV temporal noise reduction config: yuv_gain(%f), y_threshold(%f), uv_threshold(%f)",
                    config.gain, config.threshold[0], config.threshold[1]);

    yuv_result->set_standard_result (config);
    output.push_back (yuv_result);

    //Calculate RGB config
    xcam_mem_clear (config);
    config.gain = linear_interpolate_p2 (tuning[i_prev].rgb_gain, tuning[i_curr].rgb_gain,
                                         tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].r_threshold, tuning[i_curr].r_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].g_threshold, tuning[i_curr].g_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[2] = linear_interpolate_p2 (tuning[i_prev].b_threshold, tuning[i_curr].b_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    XCAM_LOG_DEBUG ("Calculate RGB temporal noise reduction config: rgb_gain(%f), r_threshold(%f), g_threshold(%f), b_threshold(%f)",
                    config.gain, config.threshold[0], config.threshold[1], config.threshold[2]);

    rgb_result->set_standard_result (config);
    output.push_back (rgb_result);

    return ret;
}
Exemplo n.º 26
0
XCamReturn
CLKernel::build_kernel (const XCamKernelInfo& info, const char* options)
{
    KernelMap::iterator i_kernel;
    SmartPtr<CLKernel> single_kernel;
    char key_str[1024];
    uint8_t body_key[8];
    std::string key;
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    XCAM_FAIL_RETURN (ERROR, info.kernel_name, XCAM_RETURN_ERROR_PARAM, "build kernel failed since kernel name null");

    xcam_mem_clear (body_key);
    get_string_key_id (info.kernel_body, info.kernel_body_len, body_key);
    snprintf (
        key_str, sizeof(key_str),
        "%s#%02x%02x%02x%02x%02x%02x%02x%02x#%s",
        info.kernel_name,
        body_key[0], body_key[1], body_key[2], body_key[3], body_key[4], body_key[5], body_key[6], body_key[7],
        XCAM_STR(options));
    key = key_str;

    char temp_filename[XCAM_MAX_STR_SIZE] = {0};
    char cache_filename[XCAM_MAX_STR_SIZE] = {0};
    FileHandle temp_file;
    FileHandle cache_file;
    size_t read_cache_size = 0;
    size_t write_cache_size = 0;
    uint8_t *kernel_cache = NULL;
    bool load_cache = false;
    struct timeval ts;

    std::string cache_path = _kernel_cache_path;
    const char *env = std::getenv ("XCAM_CL_KERNEL_CACHE_PATH");
    if (env)
        cache_path.assign (env, strlen (env));

    snprintf (
        cache_filename, XCAM_MAX_STR_SIZE - 1,
        "%s/%s",
        cache_path.c_str (), key_str);

    {
        SmartLock locker (_kernel_map_mutex);

        i_kernel = _kernel_map.find (key);
        if (i_kernel == _kernel_map.end ()) {
            SmartPtr<CLContext>  context = get_context ();
            single_kernel = new CLKernel (context, info.kernel_name);
            XCAM_ASSERT (single_kernel.ptr ());

            if (access (cache_path.c_str (), F_OK) == -1) {
                mkdir (cache_path.c_str (), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
            }

            ret = cache_file.open (cache_filename, "r");
            if (ret == XCAM_RETURN_NO_ERROR) {
                cache_file.get_file_size (read_cache_size);
                if (read_cache_size > 0) {
                    kernel_cache = (uint8_t*) xcam_malloc0 (sizeof (uint8_t) * (read_cache_size + 1));
                    if (NULL != kernel_cache) {
                        cache_file.read_file (kernel_cache, read_cache_size);
                        cache_file.close ();

                        ret = single_kernel->load_from_binary (kernel_cache, read_cache_size);
                        xcam_free (kernel_cache);
                        kernel_cache = NULL;

                        XCAM_FAIL_RETURN (
                            ERROR, ret == XCAM_RETURN_NO_ERROR, ret,
                            "build kernel(%s) from binary failed", key_str);

                        load_cache = true;
                    }
                }
            } else {
                XCAM_LOG_DEBUG ("open kernel cache file to read failed ret(%d)", ret);
            }

            if (load_cache == false) {
                ret = single_kernel->load_from_source (info.kernel_body, strlen (info.kernel_body), &kernel_cache, &write_cache_size, options);
                XCAM_FAIL_RETURN (
                    ERROR, ret == XCAM_RETURN_NO_ERROR, ret,
                    "build kernel(%s) from source failed", key_str);
            }

            _kernel_map.insert (std::make_pair (key, single_kernel));
            //_kernel_map[key] = single_kernel;
        } else {
            single_kernel = i_kernel->second;
        }
    }

    if (load_cache == false && NULL != kernel_cache) {
        gettimeofday (&ts, NULL);
        snprintf (
            temp_filename, XCAM_MAX_STR_SIZE - 1,
            "%s." XCAM_TIMESTAMP_FORMAT,
            cache_filename, XCAM_TIMESTAMP_ARGS (XCAM_TIMEVAL_2_USEC (ts)));

        ret = temp_file.open (temp_filename, "wb");
        if (ret == XCAM_RETURN_NO_ERROR) {
            ret = temp_file.write_file (kernel_cache, write_cache_size);
            temp_file.close ();
            if (ret == XCAM_RETURN_NO_ERROR && write_cache_size > 0) {
                rename (temp_filename, cache_filename);
            } else {
                remove (temp_filename);
            }
        } else {
            XCAM_LOG_ERROR ("open kernel cache file to write failed ret(%d)", ret);
        }
        xcam_free (kernel_cache);
        kernel_cache = NULL;
    }

    XCAM_FAIL_RETURN (
        ERROR, (single_kernel.ptr () && single_kernel->is_valid ()), XCAM_RETURN_ERROR_UNKNOWN,
        "build kernel(%s) failed, unknown error", key_str);

    ret = this->clone (single_kernel);
    XCAM_FAIL_RETURN (
        ERROR, ret == XCAM_RETURN_NO_ERROR, ret,
        "load kernel(%s) from kernel failed", key_str);
    return ret;
}