Exemplo n.º 1
0
int ff_opencl_deshake_init(AVFilterContext *ctx)
{
    int ret = 0;
    DeshakeContext *deshake = ctx->priv;
    ret = av_opencl_init(NULL);
    if (ret < 0)
        return ret;
    deshake->opencl_ctx.plane_num = PLANE_NUM;
    deshake->opencl_ctx.command_queue = av_opencl_get_command_queue();
    if (!deshake->opencl_ctx.command_queue) {
        av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in filter 'deshake'\n");
        return AVERROR(EINVAL);
    }
    deshake->opencl_ctx.program = av_opencl_compile("avfilter_transform", NULL);
    if (!deshake->opencl_ctx.program) {
        av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program 'avfilter_transform'\n");
        return AVERROR(EINVAL);
    }
    if (!deshake->opencl_ctx.kernel_luma) {
        deshake->opencl_ctx.kernel_luma = clCreateKernel(deshake->opencl_ctx.program,
                                                         "avfilter_transform_luma", &ret);
        if (ret != CL_SUCCESS) {
            av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform_luma'\n");
            return AVERROR(EINVAL);
        }
    }
    if (!deshake->opencl_ctx.kernel_chroma) {
        deshake->opencl_ctx.kernel_chroma = clCreateKernel(deshake->opencl_ctx.program,
                                                           "avfilter_transform_chroma", &ret);
        if (ret != CL_SUCCESS) {
            av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform_chroma'\n");
            return AVERROR(EINVAL);
        }
    }
    return ret;
}
Exemplo n.º 2
0
int ff_opencl_deshake_init(AVFilterContext *ctx)
{
    int ret = 0;
    DeshakeContext *deshake = ctx->priv;
    ret = av_opencl_init(NULL);
    if (ret < 0)
        return ret;
    deshake->opencl_ctx.matrix_size = MATRIX_SIZE;
    deshake->opencl_ctx.plane_num   = PLANE_NUM;
    ret = av_opencl_buffer_create(&deshake->opencl_ctx.cl_matrix_y,
        deshake->opencl_ctx.matrix_size*sizeof(cl_float), CL_MEM_READ_ONLY, NULL);
    if (ret < 0)
        return ret;
    ret = av_opencl_buffer_create(&deshake->opencl_ctx.cl_matrix_uv,
        deshake->opencl_ctx.matrix_size*sizeof(cl_float), CL_MEM_READ_ONLY, NULL);
    if (ret < 0)
        return ret;
    deshake->opencl_ctx.command_queue = av_opencl_get_command_queue();
    if (!deshake->opencl_ctx.command_queue) {
        av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in filter 'deshake'\n");
        return AVERROR(EINVAL);
    }
    deshake->opencl_ctx.program = av_opencl_compile("avfilter_transform", NULL);
    if (!deshake->opencl_ctx.program) {
        av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program 'avfilter_transform'\n");
        return AVERROR(EINVAL);
    }
    if (!deshake->opencl_ctx.kernel) {
        deshake->opencl_ctx.kernel = clCreateKernel(deshake->opencl_ctx.program, "avfilter_transform", &ret);
        if (ret != CL_SUCCESS) {
            av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform'\n");
            return AVERROR(EINVAL);
        }
    }
    return ret;
}
int ff_opencl_unsharp_init(AVFilterContext *ctx)
{
    int ret = 0;
    char build_opts[96];
    UnsharpContext *unsharp = ctx->priv;
    ret = av_opencl_init(NULL);
    if (ret < 0)
        return ret;
    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_luma_mask,
                                  sizeof(uint32_t) * (2 * unsharp->luma.steps_x + 1) * (2 * unsharp->luma.steps_y + 1),
                                  CL_MEM_READ_ONLY, NULL);
    if (ret < 0)
        return ret;
    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_chroma_mask,
                                  sizeof(uint32_t) * (2 * unsharp->chroma.steps_x + 1) * (2 * unsharp->chroma.steps_y + 1),
                                  CL_MEM_READ_ONLY, NULL);
    if (ret < 0)
        return ret;
    ret = generate_mask(ctx);
    if (ret < 0)
        return ret;
    unsharp->opencl_ctx.plane_num = PLANE_NUM;
    unsharp->opencl_ctx.command_queue = av_opencl_get_command_queue();
    if (!unsharp->opencl_ctx.command_queue) {
        av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in filter 'unsharp'\n");
        return AVERROR(EINVAL);
    }
    snprintf(build_opts, 96, "-D LU_RADIUS_X=%d -D LU_RADIUS_Y=%d -D CH_RADIUS_X=%d -D CH_RADIUS_Y=%d",
            2*unsharp->luma.steps_x+1, 2*unsharp->luma.steps_y+1, 2*unsharp->chroma.steps_x+1, 2*unsharp->chroma.steps_y+1);
    unsharp->opencl_ctx.program = av_opencl_compile("unsharp", build_opts);
    if (!unsharp->opencl_ctx.program) {
        av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program 'unsharp'\n");
        return AVERROR(EINVAL);
    }
    if (unsharp->opencl_ctx.use_fast_kernels) {
        if (!unsharp->opencl_ctx.kernel_luma) {
            unsharp->opencl_ctx.kernel_luma = clCreateKernel(unsharp->opencl_ctx.program, "unsharp_luma", &ret);
            if (ret != CL_SUCCESS) {
                av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'unsharp_luma'\n");
                return ret;
            }
        }
        if (!unsharp->opencl_ctx.kernel_chroma) {
            unsharp->opencl_ctx.kernel_chroma = clCreateKernel(unsharp->opencl_ctx.program, "unsharp_chroma", &ret);
            if (ret < 0) {
                av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'unsharp_chroma'\n");
                return ret;
            }
        }
    }
    else {
        if (!unsharp->opencl_ctx.kernel_default) {
            unsharp->opencl_ctx.kernel_default = clCreateKernel(unsharp->opencl_ctx.program, "unsharp_default", &ret);
            if (ret < 0) {
                av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'unsharp_default'\n");
                return ret;
            }
        }
    }
    return ret;
}