Threading concerns with videoSurface->present and the QVideoFrame buffer?



  • Assume the following:

    unsigned char* data = NULL;
    int size = 0;
    encoder_sample_buffer_get_data(sampleBufferMap, &data, &size);
    
    if(size > 0) {
        QVideoFrame frame = QVideoFrame(new QMemoryVideoBuffer(reinterpret_cast<char*>(data), currentFormat.frameWidth()),
            currentFormat.frameSize(),
            currentFormat.pixelFormat());
    
        currentSurface->present(frame);
    }
    
    encoder_sample_buffer_unmap(sampleBuffer, sampleBufferMap);
    

    Am I safe here? I am calling "present", and the immediately releasing the buffer. Am I sure that the render thread will have a valid reference?

    What is the approach here? Subclass QAbstractVideoBuffer that handles the ref/unref internally?


  • Lifetime Qt Champion

    Hi,

    From a quick look at the sources, QMemoryVideoBuffer uses a QByteArray internally and the QByteArray constructor taking a char * array makes a deep copy. However, you should create it yourself and pass the size of your buffer otherwise the constructor will assume that it is a null terminated string which is not your case.


Log in to reply
 

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