Exemple #1
0
XCamReturn
PipeManager::start ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    if (_smart_analyzer.ptr ()) {
        if (_smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
            XCAM_LOG_INFO ("prepare smart analyzer handler failed");
        }

        _smart_analyzer->set_results_callback (this);
        if (_smart_analyzer->init (1920, 1080, 25) != XCAM_RETURN_NO_ERROR) {
            XCAM_LOG_INFO ("initialize smart analyzer failed");
        }
        if (_smart_analyzer->start () != XCAM_RETURN_NO_ERROR) {
            XCAM_LOG_INFO ("start smart analyzer failed");
        }
    }

    if (!_processor_center->has_processors ()) {
        XCAM_LOG_ERROR ("image processors empty");
    }
    _processor_center->set_image_callback (this);
    XCAM_FAILED_STOP (ret = _processor_center->start (), "3A process center start failed");

    _is_running = true;

    XCAM_LOG_DEBUG ("pipe manager started");
    return XCAM_RETURN_NO_ERROR;
}
Exemple #2
0
XCamReturn
V4l2Device::request_buffer ()
{
    struct v4l2_requestbuffers request_buf;

    XCAM_ASSERT (!is_activated());

    xcam_mem_clear (request_buf);
    request_buf.type = _capture_buf_type;
    request_buf.count = _buf_count;
    request_buf.memory = _memory_type;

    if (io_control (VIDIOC_REQBUFS, &request_buf) < 0) {
        XCAM_LOG_INFO ("device(%s) starts failed on VIDIOC_REQBUFS", XCAM_STR (_name));
        return XCAM_RETURN_ERROR_IOCTL;
    }

    if (request_buf.count != _buf_count) {
        XCAM_LOG_DEBUG (
            "device(%s) request buffer count doesn't match user settings, reset buffer count to %d",
            XCAM_STR (_name), request_buf.count);
        _buf_count = request_buf.count;
    }
    return XCAM_RETURN_NO_ERROR;
}
SmartPtr<X3aAnalyzer>
X3aAnalyzerManager::find_analyzer ()
{
    char lib_path[512];
    const char *dir_path = NULL;
    DIR  *dir_3a = NULL;
    struct dirent *dirent_3a = NULL;
    SmartPtr<X3aAnalyzer> analyzer;

    dir_path = getenv ("XCAM_3A_LIB");
    if (!dir_path) {
        dir_path = XCAM_DEFAULT_3A_LIB_DIR;
        XCAM_LOG_INFO ("doesn't find environment=>XCAM_3A_LIB, change to default dir:%s", dir_path);
    }
    dir_3a = opendir (dir_path);
    if (dir_3a) {
        while ((dirent_3a = readdir (dir_3a)) != NULL) {
            if (dirent_3a->d_type != DT_LNK &&
                    dirent_3a->d_type != DT_REG)
                continue;
            snprintf (lib_path, sizeof(lib_path), "%s/%s", dir_path, dirent_3a->d_name);
            analyzer = load_analyzer_from_binary (lib_path);
            if (analyzer.ptr())
                break;
        }
    }
    if (dir_3a)
        closedir (dir_3a);
    return analyzer;
}
bool
CLBayer3AStatsThread::loop ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    SmartPtr<BayerPostData> data;
    data = _stats_process_list.pop ();
    if (!data.ptr ()) {
        XCAM_LOG_INFO ("cl bayer 3a-stats thread is going to stop, processing data empty");
        return false;
    }

    XCAM_ASSERT (data->image_buffer.ptr ());
    XCAM_ASSERT (data->stats_cl_buf.ptr ());
    XCAM_ASSERT (_handler);

    ret = _handler->process_stats_buffer (data->image_buffer, data->stats_cl_buf);
    XCAM_FAIL_RETURN (
        WARNING,
        ret == XCAM_RETURN_NO_ERROR,
        false,
        "cl bayer 3a-stats thread has error buffer on kernel post processing");

    XCAM_FAIL_RETURN (
        ERROR,
        _buffer_done_list.push (data->image_buffer),
        false,
        "cl bayer 3a-stats thread failed to queue done-buffers");
    return true;
}
Exemple #5
0
XCamReturn
X3aAnalyzer::init (uint32_t width, uint32_t height, double framerate)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;


    if (!_ae_handler.ptr() || !_awb_handler.ptr() ||
            !_af_handler.ptr() || !_common_handler.ptr()) {
        XCAM_LOG_WARNING (
            "analyzer:%s init failed, <prepare_handlers> need called first",
            XCAM_STR(get_name ()));
        return XCAM_RETURN_ERROR_PARAM;
    }

    XCAM_ASSERT (!_width && !_height);
    _width = width;
    _height = height;
    _framerate = framerate;

    ret = internal_init (width, height, _framerate);
    if (ret != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_WARNING ("analyzer init failed");
        deinit ();
        return ret;
    }

    XCAM_LOG_INFO (
        "Analyzer(%s) initialized(w:%d, h:%d).",
        XCAM_STR(get_name()), _width, _height);
    return XCAM_RETURN_NO_ERROR;
}
Exemple #6
0
XCamReturn
X3aAnalyzer::stop ()
{
    _3a_analyzer_thread->triger_stop ();
    _3a_analyzer_thread->stop ();

    XCAM_LOG_INFO ("Analyzer(%s) stopped.", XCAM_STR(get_name()));
    return XCAM_RETURN_NO_ERROR;
}
Exemple #7
0
bool CpfReader::read (ia_binary_data &binary)
{
    if (!xcam_cpf_read (_name, _aiq_cpf, NULL)) {
        XCAM_LOG_ERROR ("parse CPF(%s) failed", XCAM_STR (_name));
        return false;
    }
    binary.data  = _aiq_cpf->data;
    binary.size = _aiq_cpf->size;
    XCAM_LOG_INFO ("read cpf(%s) ok", XCAM_STR (_name));
    return true;
}
Exemple #8
0
XCamReturn
X3aAnalyzer::start ()
{
    if (_3a_analyzer_thread->start () == false) {
        XCAM_LOG_WARNING ("analyzer thread start failed");
        stop ();
        return XCAM_RETURN_ERROR_THREAD;
    }

    XCAM_LOG_INFO ("Analyzer(%s) started.", XCAM_STR(get_name()));
    return XCAM_RETURN_NO_ERROR;
}
Exemple #9
0
XCamReturn
V4l2Device::stop ()
{
    // stream off
    if (_active) {
        if (io_control (VIDIOC_STREAMOFF, &_capture_buf_type) < 0) {
            XCAM_LOG_WARNING ("device(%s) steamoff failed", XCAM_STR (_name));
        }
        _active = false;
    }

    fini_buffer_pool ();

    XCAM_LOG_INFO ("device(%s) stopped", XCAM_STR (_name));
    return XCAM_RETURN_NO_ERROR;
}
Exemple #10
0
XCamReturn
X3aAnalyzer::deinit ()
{
    internal_deinit();

    _ae_handler.release ();
    _awb_handler.release ();
    _af_handler.release ();
    _common_handler.release ();

    _width = 0;
    _height = 0;

    XCAM_LOG_INFO ("Analyzer(%s) deinited.", XCAM_STR(get_name()));
    return XCAM_RETURN_NO_ERROR;
}
SmartPtr<X3aAnalyzer>
X3aAnalyzerLoader::load_dynamic_analyzer (SmartPtr<X3aAnalyzerLoader> &self)
{
    XCAM_ASSERT (self.ptr () == this);

    SmartPtr<X3aAnalyzer> analyzer;
    XCam3ADescription *desc = (XCam3ADescription*)load_library (get_lib_path ());

    analyzer = new DynamicAnalyzer (desc, self);
    if (!analyzer.ptr ()) {
        XCAM_LOG_WARNING ("create DynamicAnalyzer from lib failed");
        close_handle ();
        return NULL;
    }

    XCAM_LOG_INFO ("analyzer(%s) created from 3a lib", XCAM_STR (analyzer->get_name()));
    return analyzer;
}
Exemple #12
0
XCamReturn
V4l2Device::start ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    // request buffer first
    ret = request_buffer ();
    XCAM_FAIL_RETURN (
        ERROR, ret == XCAM_RETURN_NO_ERROR, ret,
        "device(%s) start failed", XCAM_STR (_name));

    //alloc buffers
    ret = init_buffer_pool ();
    XCAM_FAIL_RETURN (
        ERROR, ret == XCAM_RETURN_NO_ERROR, ret,
        "device(%s) start failed", XCAM_STR (_name));

    //queue all buffers
    for (uint32_t i = 0; i < _buf_count; ++i) {
        SmartPtr<V4l2Buffer> &buf = _buf_pool [i];
        XCAM_ASSERT (buf.ptr());
        XCAM_ASSERT (buf->get_buf().index == i);
        ret = queue_buffer (buf);
        if (ret != XCAM_RETURN_NO_ERROR) {
            XCAM_LOG_ERROR (
                "device(%s) start failed on queue index:%d",
                XCAM_STR (_name), i);
            stop ();
            return ret;
        }
    }

    // stream on
    if (io_control (VIDIOC_STREAMON, &_capture_buf_type) < 0) {
        XCAM_LOG_ERROR (
            "device(%s) start failed on VIDIOC_STREAMON",
            XCAM_STR (_name));
        stop ();
        return XCAM_RETURN_ERROR_IOCTL;
    }
    _active = true;
    XCAM_LOG_INFO ("device(%s) started successfully", XCAM_STR (_name));
    return XCAM_RETURN_NO_ERROR;
}
SmartPtr<SmartAnalysisHandler>
SmartAnalyzerLoader::load_smart_handler (SmartPtr<SmartAnalyzerLoader> &self)
{
    XCAM_ASSERT (self.ptr () == this);

    SmartPtr<SmartAnalysisHandler> handler;
    XCamSmartAnalysisDescription *desc = (XCamSmartAnalysisDescription*)load_library (get_lib_path ());
    if (NULL == desc) {
        XCAM_LOG_WARNING ("load smart handler lib symbol failed");
        return NULL;
    }

    handler = new SmartAnalysisHandler (desc, self, _name);
    if (!handler.ptr ()) {
        XCAM_LOG_WARNING ("create smart handler failed");
        close_handle ();
        return NULL;
    }

    XCAM_LOG_INFO ("smart handler(%s) created from lib", XCAM_STR (handler->get_name()));
    return handler;
}
SmartPtr<X3aAnalyzer>
X3aAnalyzerLoader::load_hybrid_analyzer (SmartPtr<X3aAnalyzerLoader> &self,
        SmartPtr<IspController> &isp,
        const char *cpf_path)
{
    XCAM_ASSERT (self.ptr () == this);

    SmartPtr<X3aAnalyzer> analyzer;

#if HAVE_IA_AIQ
    XCam3ADescription *desc = (XCam3ADescription*)load_library (get_lib_path ());
    analyzer = new HybridAnalyzer (desc, self, isp, cpf_path);
#endif

    if (!analyzer.ptr ()) {
        XCAM_LOG_WARNING ("create HybridAnalyzer from lib failed");
        close_handle ();
        return NULL;
    }

    XCAM_LOG_INFO ("analyzer(%s) created from 3a lib", XCAM_STR (analyzer->get_name()));
    return analyzer;
}
Exemple #15
0
XCamReturn
DeviceManager::start ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    // start device
    XCAM_ASSERT (_device->is_opened());
    if (!_device.ptr() || !_device->is_opened()) {
        XCAM_FAILED_STOP (ret = XCAM_RETURN_ERROR_FILE, "capture device not ready");
    }
    XCAM_FAILED_STOP (ret = _device->start(), "capture device start failed");

    //start subdevice
    //XCAM_ASSERT (_subdevice->is_opened());
    if (_subdevice.ptr()) {
        if (!_subdevice->is_opened())
            XCAM_FAILED_STOP (ret = XCAM_RETURN_ERROR_FILE, "event device not ready");
        XCAM_FAILED_STOP (ret = _subdevice->start(), "start event device failed");
    }

    //suppose _device and _subdevice already started
    if (!_isp_controller.ptr ())
        _isp_controller = new IspController (_device);
    XCAM_ASSERT (_isp_controller.ptr());

    if (_has_3a) {
        // Initialize and start analyzer
        uint32_t width = 0, height = 0;
        uint32_t fps_n = 0, fps_d = 0;
        double framerate = 30.0;

        if (!_3a_analyzer.ptr()) {
            _3a_analyzer = X3aAnalyzerManager::instance()->create_analyzer();
            if (!_3a_analyzer.ptr()) {
                XCAM_FAILED_STOP (ret = XCAM_RETURN_ERROR_PARAM, "create analyzer failed");
            }
        }
        if (_3a_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
            XCAM_FAILED_STOP (ret = XCAM_RETURN_ERROR_PARAM, "prepare analyzer handler failed");
        }
        _3a_analyzer->set_results_callback (this);

        _device->get_size (width, height);
        _device->get_framerate (fps_n, fps_d);
        if (fps_d)
            framerate = (double)fps_n / (double)fps_d;
        XCAM_FAILED_STOP (
            ret = _3a_analyzer->init (width, height, framerate),
            "initialize analyzer failed");

        XCAM_FAILED_STOP (ret = _3a_analyzer->start (), "start analyzer failed");

        if (_smart_analyzer.ptr()) {
            if (_smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
                XCAM_LOG_INFO ("prepare smart analyzer handler failed");
            }
            //_smart_analyzer->set_results_callback (this);
            if (_smart_analyzer->init (width, height, framerate) != XCAM_RETURN_NO_ERROR) {
                XCAM_LOG_INFO ("initialize smart analyzer failed");
            }
            if (_smart_analyzer->start () != XCAM_RETURN_NO_ERROR) {
                XCAM_LOG_INFO ("start smart analyzer failed");
            }
        }

        // Initialize and start image processors
        if (!_3a_process_center->has_processors()) {
            // default processor
            SmartPtr<ImageProcessor> default_processor = new IspImageProcessor (_isp_controller);
            XCAM_ASSERT (default_processor.ptr ());
            _3a_process_center->insert_processor (default_processor);
        }

        _3a_process_center->set_image_callback(this);
        XCAM_FAILED_STOP (ret = _3a_process_center->start (), "3A process center start failed");

    }

    //Initialize and start poll thread
    _poll_thread = new PollThread;
    _poll_thread->set_capture_device (_device);
    if (_subdevice.ptr ())
        _poll_thread->set_event_device (_subdevice);
    _poll_thread->set_isp_controller (_isp_controller);
    _poll_thread->set_poll_callback (this);
    _poll_thread->set_stats_callback (this);

    XCAM_FAILED_STOP (ret = _poll_thread->start(), "start poll failed");

    _is_running = true;

    XCAM_LOG_DEBUG ("Device manager started");
    return XCAM_RETURN_NO_ERROR;
}
Exemple #16
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;
}
Exemple #17
0
bool
CLDevice::init ()
{
    cl_platform_id platform_id = NULL;
    cl_device_id   device_id = NULL;
    cl_uint num_platform = 0;
    cl_uint num_device = 0;
    CLDevieInfo device_info;

    if (clGetPlatformIDs (1, &platform_id, &num_platform) != CL_SUCCESS)
    {
        XCAM_LOG_WARNING ("get cl platform ID failed");
        return false;
    }
    XCAM_ASSERT (num_platform >= 1);

    if (clGetDeviceIDs (platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &num_device) != CL_SUCCESS)
    {
        XCAM_LOG_WARNING ("get cl device ID failed");
        return false;
    }
    XCAM_ASSERT (num_device >= 1);

    // only query first device info
    if (!query_device_info (device_id, device_info)) {
        //continue
        XCAM_LOG_WARNING ("cl get device info failed but continue");
    } else {
        XCAM_LOG_INFO (
            "cl get device info,\n"
            "\tmax_compute_unit:%" PRIu32
            "\tmax_work_item_dims:%" PRIu32
            "\tmax_work_item_sizes:{%" PRIuS ", %" PRIuS ", %" PRIuS "}"
            "\tmax_work_group_size:%" PRIuS
            "\timage_pitch_alignment:%" PRIu32,
            device_info.max_compute_unit,
            device_info.max_work_item_dims,
            device_info.max_work_item_sizes[0], device_info.max_work_item_sizes[1], device_info.max_work_item_sizes[2],
            device_info.max_work_group_size,
            device_info.image_pitch_alignment);
    }

    // get platform name string length
    size_t sz = 0;
    if (clGetPlatformInfo(platform_id, CL_PLATFORM_NAME, 0, 0, &sz) != CL_SUCCESS)
    {
        XCAM_LOG_WARNING ("get cl platform name failed");
        return false;
    }

    // get platform name string
    if (sz >= XCAM_CL_MAX_STR_SIZE) {
        sz = XCAM_CL_MAX_STR_SIZE - 1;
    }
    if (clGetPlatformInfo(platform_id, CL_PLATFORM_NAME, sz, _platform_name, 0) != CL_SUCCESS)
    {
        XCAM_LOG_WARNING ("get cl platform name failed");
        return false;
    }

    _platform_id = platform_id;
    _device_id = device_id;
    _device_info = device_info;
    _platform_name[sz] = 0;
    _inited = true;
    return true;
}