Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QAbstractVideoSurface::present not triggered

QAbstractVideoSurface::present not triggered

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 511 Views
  • 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.
  • R Offline
    R Offline
    RyuShai
    wrote on last edited by
    #1

    i want grap frame from webcam to procees so i implement QAbstractVideoSurface
    But event camera state change to QCamera::ActiveState, i dont see present fucntion called
    implement surface

    QList<QVideoFrame::PixelFormat> AndroidFrame::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    {
        if (handleType == QAbstractVideoBuffer::NoHandle) {
               return QList<QVideoFrame::PixelFormat>()
                       << QVideoFrame::Format_RGB32;
           } else {
               return QList<QVideoFrame::PixelFormat>();
        }
    }
    
    bool AndroidFrame::present(const QVideoFrame &currentFrame)
    {
        qDebug()<<Q_FUNC_INFO;
        qDebug()<<currentFrame.pixelFormat()<<endl;
        if (currentFrame.isValid()) {
            QVideoFrame cloneFrame(currentFrame);
            cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
            const QImage img(cloneFrame.bits(),
                         cloneFrame.width(),
                         cloneFrame.height(),
                         QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
             emit frameChanged(img);
            return true;
        }
        return false;
    }
    
    

    call in main

    QCamera *camera;
        BindingFrame2QML *binding = new BindingFrame2QML();
        QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
        foreach (const QCameraInfo &cameraInfo, cameras) {
            qDebug()<<cameraInfo.deviceName()<<endl;
            if (cameraInfo.deviceName() == "/dev/video0")
                camera = new QCamera(cameraInfo);
        }
    
        AndroidFrame *viewFinder = new AndroidFrame;
        camera->setCaptureMode(QCamera::CaptureMode::CaptureViewfinder);
        camera->setViewfinder(viewFinder);
    
        QObject::connect(viewFinder,&AndroidFrame::frameChanged,binding,&BindingFrame2QML::onFrameUpdate);
        QObject::connect(camera,&QCamera::stateChanged,[=](QCamera::State state){
            qDebug()<<"state: "<<state;
    
        });
        camera->start();
    

    BindingFrame2QML is Qimageprovider to sent image from c++ to qml so it does't matter

    here log of QCameraState

    state: QCamera::ActiveState

    R 1 Reply Last reply
    0
    • R RyuShai

      i want grap frame from webcam to procees so i implement QAbstractVideoSurface
      But event camera state change to QCamera::ActiveState, i dont see present fucntion called
      implement surface

      QList<QVideoFrame::PixelFormat> AndroidFrame::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
      {
          if (handleType == QAbstractVideoBuffer::NoHandle) {
                 return QList<QVideoFrame::PixelFormat>()
                         << QVideoFrame::Format_RGB32;
             } else {
                 return QList<QVideoFrame::PixelFormat>();
          }
      }
      
      bool AndroidFrame::present(const QVideoFrame &currentFrame)
      {
          qDebug()<<Q_FUNC_INFO;
          qDebug()<<currentFrame.pixelFormat()<<endl;
          if (currentFrame.isValid()) {
              QVideoFrame cloneFrame(currentFrame);
              cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
              const QImage img(cloneFrame.bits(),
                           cloneFrame.width(),
                           cloneFrame.height(),
                           QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
               emit frameChanged(img);
              return true;
          }
          return false;
      }
      
      

      call in main

      QCamera *camera;
          BindingFrame2QML *binding = new BindingFrame2QML();
          QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
          foreach (const QCameraInfo &cameraInfo, cameras) {
              qDebug()<<cameraInfo.deviceName()<<endl;
              if (cameraInfo.deviceName() == "/dev/video0")
                  camera = new QCamera(cameraInfo);
          }
      
          AndroidFrame *viewFinder = new AndroidFrame;
          camera->setCaptureMode(QCamera::CaptureMode::CaptureViewfinder);
          camera->setViewfinder(viewFinder);
      
          QObject::connect(viewFinder,&AndroidFrame::frameChanged,binding,&BindingFrame2QML::onFrameUpdate);
          QObject::connect(camera,&QCamera::stateChanged,[=](QCamera::State state){
              qDebug()<<"state: "<<state;
      
          });
          camera->start();
      

      BindingFrame2QML is Qimageprovider to sent image from c++ to qml so it does't matter

      here log of QCameraState

      state: QCamera::ActiveState

      R Offline
      R Offline
      RyuShai
      wrote on last edited by
      #2

      @RyuShai Problem solve, look like root cause is my code in main.cpp call before

      QGuiApplication app(argc, argv);
      

      move line code above to the top of main function make it find

      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