Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Using QPixmap from converted QVideoFrame in graphics scene on android
Forum Updated to NodeBB v4.3 + New Features

Using QPixmap from converted QVideoFrame in graphics scene on android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Clemens 69er
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved