[QOpenGLWidget] flashing image where I use OpenCL



  • Hello!
    I have to output several network streams, now I use qt-5.5.1 and OpenGL.
    Because network streams in YUV420 I convert it to RGB (http://www.fourcc.org/fccyvrgb.php), it work, but not very quick.
    Now I try use OpenCL for convert streams, follow my code:
    QImage OCL::convert(const char *buf, quint16 width, quint16 height, ocl_queue queue)
    {
    QImage img;
    if (_ready && buf && width && height && queue < QUEUE_UNKNOWN) {
    const size_t stride = width * 4;
    const size_t sz = stride * height;
    const size_t dims[2] = {width, height};
    cl_mem in = NULL;
    cl_mem out = NULL;
    _rgb[queue].resize(sz);
    in = clCreateBuffer(_context, CL_MEM_READ_ONLY, width * height * 3 / 2, NULL, &_ret);
    if (IS_ERROR(_ret)) {
    qDebug() << "clCreateBuffer input, error" << _ret;
    goto EXIT;
    }
    out = clCreateBuffer(_context, CL_MEM_WRITE_ONLY, sz, NULL, &_ret);
    if (IS_ERROR(_ret)) {
    qDebug() << "clCreateBuffer out, error" << _ret;
    goto EXIT;
    }
    _ret = clSetKernelArg(_kernel, 0, sizeof(cl_mem), &in);
    if (IS_ERROR(_ret)) {
    qDebug() << "clSetKernelArg 0, error" << _ret;
    goto EXIT;
    }
    _ret = clSetKernelArg(_kernel, 1, sizeof(cl_mem), &out);
    if (IS_ERROR(_ret)) {
    qDebug() << "clSetKernelArg 1, error" << _ret;
    goto EXIT;
    }
    _ret = clEnqueueWriteBuffer(_command[queue], in, CL_TRUE, 0, width * height * 3 / 2, buf, 0, NULL, NULL);
    if (IS_ERROR(_ret)) {
    qDebug() << "clEnqueueWriteBuffer, error" << _ret;
    goto EXIT;
    }
    // FIXME: periodic clEnqueueNDRangeKernel, error -52
    _ret = clEnqueueNDRangeKernel(_command[queue], _kernel, 2, NULL, dims, NULL, 0, NULL, NULL);
    if (IS_ERROR(_ret)) {
    qDebug() << "clEnqueueNDRangeKernel, error" << _ret;
    goto EXIT;
    }
    _ret = clEnqueueReadBuffer(_command[queue], out, CL_TRUE, 0, sz, _rgb[queue].data(), 0, NULL, NULL);
    if (IS_ERROR(_ret)) {
    qDebug() << "clEnqueueReadBuffer, error" << _ret;
    goto EXIT;
    }
    img = QImage(reinterpret_cast<const uchar *>(_rgb[queue].constData()), width, height, stride, QImage::Format_ARGB32);
    EXIT:
    if (in != NULL)
    clReleaseMemObject(in);
    if (out != NULL)
    clReleaseMemObject(out);
    }
    return img;
    }
    This is work very quick, but I see flashing images.
    How can I solve this problem?
    Thank you and excuse my bad english.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.