Пример #1
0
void xcam_cpf_blob_free (XCamCpfBlob *blob)
{
    XCAM_FAIL_RETURN (blob);

    if (blob->data)
        xcam_free (blob->data);

    xcam_free (blob);
}
Пример #2
0
X3aAnalyzerAiq::~X3aAnalyzerAiq()
{
    if (_cpf_path)
        xcam_free (_cpf_path);

    XCAM_LOG_DEBUG ("~X3aAnalyzerAiq destructed");
}
Пример #3
0
CpfReader::~CpfReader()
{
    if (_aiq_cpf)
        xcam_cpf_blob_free (_aiq_cpf);
    if (_name)
        xcam_free (_name);
}
Пример #4
0
static int32_t
read_cpf_file (const char *cpf_file, uint8_t **buf)
{
    int32_t size = 0;
    FILE *fp = fopen (cpf_file, "rb");
    XCAM_FAIL_RETURN_VAL (fp, -1);

    *buf = NULL;

    if (fseek (fp, 0, SEEK_END) < 0)
        goto read_error;
    if ((size = ftell (fp)) <= 0)
        goto read_error;
    if (fseek( fp, 0, SEEK_SET) < 0)
        goto read_error;

    *buf = (uint8_t*) xcam_new0 (size);
    if (fread (*buf, 1, size, fp) != size)
        goto read_error;

    fclose (fp);
    return size;

read_error:
    XCAM_LOG_ERROR ("read cpf(%s) failed", cpf_file);
    fclose (fp);
    if (*buf) {
        xcam_free (*buf);
        *buf = NULL;
    }
    return -1;

}
Пример #5
0
FakePollThread::~FakePollThread ()
{
    if (_raw_path)
        xcam_free (_raw_path);

    if (_raw)
        fclose (_raw);
}
Пример #6
0
bool
V4l2Device::set_device_name (const char *name)
{
    XCAM_ASSERT (name);

    if (is_opened()) {
        XCAM_LOG_WARNING ("can't set device name since device opened");
        return false;
    }
    if (_name)
        xcam_free (_name);
    _name = strndup (name, XCAM_MAX_STR_SIZE);
    return true;
}
Пример #7
0
X3aStatsData::~X3aStatsData ()
{
    if (_data)
        xcam_free (_data);
}
Пример #8
0
CLKernel::~CLKernel ()
{
    destroy ();
    if (_name)
        xcam_free (_name);
}
Пример #9
0
V4l2Device::~V4l2Device ()
{
    close();
    if (_name)
        xcam_free (_name);
}
Пример #10
0
SmartAnalyzerLoader::~SmartAnalyzerLoader ()
{
    if (_name)
        xcam_free (_name);
}
Пример #11
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;
}
Пример #12
0
X3aAnalyzer::~X3aAnalyzer()
{
    if (_name)
        xcam_free (_name);
}
Пример #13
0
XCamMessage::~XCamMessage ()
{
    if (msg)
        xcam_free (msg);
}
Пример #14
0
void
free_3a_result (XCam3aResultHead *result)
{
    xcam_free (result);
}
Пример #15
0
boolean
xcam_cpf_read (const char *cpf_file, XCamCpfBlob *aiq_cpf, XCamCpfBlob *hal_cpf)
{
    uint8_t *cpf_buf;
    int32_t cpf_size;

    uint8_t *blob;
    int32_t blob_size;

    XCAM_FAIL_RETURN_VAL (cpf_file, FALSE);
    XCAM_FAIL_RETURN_VAL (aiq_cpf, FALSE);

    /* read cpf */
    if ((cpf_size = read_cpf_file(cpf_file, &cpf_buf)) <= 0) {
        XCAM_LOG_ERROR ("read cpf_file(%s) failed.", cpf_file);
        return FALSE;
    }

    /* check sum */
    if (tbd_validate (cpf_buf, cpf_size, tbd_tag_cpff) != tbd_err_none) {
        XCAM_LOG_ERROR ("tbd validate cpf file(%s) failed.", cpf_file);
        goto free_buf;
    }

    /* fetch AIQ */
    if ( (tbd_get_record (cpf_buf, tbd_class_aiq, tbd_format_any,
                          (void**)&blob, (size_t*)&blob_size) != tbd_err_none) ||
            !blob || blob_size <= 0) {
        XCAM_LOG_ERROR ("CPF parse AIQ record failed.");
        goto free_buf;
    }
    aiq_cpf->data = (uint8_t*) malloc (blob_size);
    aiq_cpf->size = blob_size;
    memcpy (aiq_cpf->data, blob, blob_size);


#if 0 //DRV not necessary
    /* fetch DRV */
    if (tbd_get_record (cpf_buf, tbd_class_drv, tbd_format_any,
                        &drv_blob.data, &drv_blob.size) != tbd_err_none) {
        XCAM_LOG_ERROR ("CPF parse DRV record failed.");
        return FALSE;
    }
#endif


    /* fetch HAL */
    if (hal_cpf) {
        if (tbd_get_record (cpf_buf, tbd_class_hal, tbd_format_any,
                            (void**)&blob, (size_t*)&blob_size) != tbd_err_none) {
            XCAM_LOG_WARNING ("CPF doesn't have HAL record.");
            // ignore HAL, not necessary
        } else if (blob && blob_size > 0) {
            hal_cpf->data = (uint8_t*) malloc (blob_size);
            hal_cpf->size = blob_size;
            memcpy (hal_cpf->data, blob, blob_size);
        }
    }

    xcam_free (cpf_buf);
    return TRUE;

free_buf:
    xcam_free (cpf_buf);
    return FALSE;

}
Пример #16
0
CLImageHandler::~CLImageHandler ()
{
    if (_name)
        xcam_free (_name);
}