Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-114630

QImage memory leak when called via QVideoSink

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 6.5.1
    • Multimedia
    • None
    • Visual Studio 2022, Windows.
    • Windows

    Description

      When running the following code, the memory used by the app increases over time quickly:

      Header file:

      #ifndef TESTY_H
      #define TEST_H

      #include <QMainWindow>
      #include <QMediaCaptureSession>
      #include <QVideoSink>
      #include <QVideoWidget>
      #include <QCamera>class Testy : public QMainWindow
      {
          Q_OBJECT

      public:
          Testy(QWidget* parent = nullptr);
          ~Testy();
          QCamera* camera;
          QMediaCaptureSession* capture;
          QVideoSink* sink;
          QVideoWidget* video;public {}
      slots:
          void videoFrame(const QVideoFrame& frame);
      };
      #endif

      Source File

      #include "testy.h"
      #include <QApplication>
      #include <QVideoFrame>
      #include <QMediaDevices>

      int main(int argc, char* argv[])
      {
          QApplication a(argc, argv);
          Testy w;
          w.show();
          return a.exec();
      }

      Testy::Testy(QWidget* parent)
          : QMainWindow(parent)
          , camera(nullptr)
          , capture(new QMediaCaptureSession(this))
          , sink(new QVideoSink(this))
          , video(new QVideoWidget(this))
      {

          this->setCentralWidget(video);
          capture->setVideoOutput(video);
          connect(video->videoSink(), &QVideoSink::videoFrameChanged, this, &Testy::videoFrame);    const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();    QCameraDevice camDevice;
          for (auto c : cameras)
          {
              // Set the name of an active webcam here
              if (c.description().contains("HD Pro Webcam")) {
                  camDevice = c;
                  break;
              }
          camera = new QCamera(camDevice);
          capture->setCamera(camera);
          camera->start();
          
      }

      Testy::~Testy()
      {}

      void Testy::videoFrame(const QVideoFrame& frame)
      {
          // This line appears to create the leak.
          QImage img = frame.toImage();
      }

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              padubsky Pavel Dubsky
              peeldev Alastair Macleod
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes