Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAbstractVideoSurface::present not triggered



  • 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



  • @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


Log in to reply