Using QPixmap from converted QVideoFrame in graphics scene on android



  • Hello,

    I have written a simple test UI that shall display a pixmap from a converted video frame within a QGraphicsView. On Ubuntu everything runs fine - the frames taken from a WebCam are shown correctly. But when it runs on Android, after some frames an out-of-memory happens.
    Here's the regarding method:

    void MainWindow::handleFrame(QVideoFrame frame)
    {
        qDebug("enter handle frame");
        if (frame.isValid())
        {
            QVideoFrame cloneFrame(frame);
            if (cloneFrame.map(QAbstractVideoBuffer::ReadOnly))
            {
                QImage image = qt_imageFromVideoFrame(cloneFrame);
                if (image.byteCount())
                {
                    if (!m_scene)
                    {
                        m_scene = new QGraphicsScene(this);
                        ui->graphicsView->setScene(m_scene);
                    }
                    m_scene->addPixmap(QPixmap::fromImage(image));
                }
                else
                {
                    qDebug("converted image empty!");
                }
                cloneFrame.unmap();
            }
            else
            {
                qDebug("frame could not be mapped");
            }
        }
        else
        {
            qDebug("frame invalid!");
        }
    }
    

    A hint: when I comment out m_scene->addPixmap(QPixmap::fromImage(image)); no exception occurs, although the images are still mapped and converted!
    So the question is - why does it happen on Android only? Do I have to take care manually for the pixmap allocated memory?

    Hope someone can help out here :)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From the looks of it, you are leaking pixmap object each time there's a new QVideoFrame. Why not keep a pointer on the QGraphicsPixmapItem created the first round and then only update it ?


Log in to reply
 

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