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. Qt6 Android QVideoFrame map crash after resume
QtWS25 Last Chance

Qt6 Android QVideoFrame map crash after resume

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt6androidqtquickqmlc++
3 Posts 2 Posters 672 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.
  • T Offline
    T Offline
    tm_sx
    wrote on 16 Jun 2023, 11:53 last edited by
    #1

    Hi everyone,

    I do have a Qt6 (6.5.0) Quick Android application. The application uses the Qt Camera and shows the stream to the VideoOutput element that fills the screen. When the Take frame button is pressed, the backend method setVideoSink is called. There I get a QVideoFrame from the QVideoSink, make a non-const copy, map it (call method map), do some work (or nothing in the case), and unmap (call method 'unmap`).

    Everything fine until the app goes to background and is restored (resumed): when the map method is called on the copy frame, the application crashes, with the log:

    E libEGL  : call to OpenGL ES API with no current context (logged once per thread)
    W libappCameraProcessor_arm64-v8a.so: Failed to compile shader:
    W libappCameraProcessor_arm64-v8a.so: Source was:
    W libappCameraProcessor_arm64-v8a.so: #version 100
    06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so:
    W libappCameraProcessor_arm64-v8a.so: struct buf
    W libappCameraProcessor_arm64-v8a.so: {
    W libappCameraProcessor_arm64-v8a.so:     mat4 matrix;
    W libappCameraProcessor_arm64-v8a.so:     mat4 colorMatrix;
    W libappCameraProcessor_arm64-v8a.so:     float opacity;
    W libappCameraProcessor_arm64-v8a.so:     float width;
    W libappCameraProcessor_arm64-v8a.so:     float masteringWhite;
    W libappCameraProcessor_arm64-v8a.so:     float maxLum;
    W libappCameraProcessor_arm64-v8a.so: };
    06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so:
    W libappCameraProcessor_arm64-v8a.so: uniform buf ubuf;
    06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so:
    W libappCameraProcessor_arm64-v8a.so: varying vec2 texCoord;
    W libappCameraProcessor_arm64-v8a.so: attribute vec2 vertexTexCoord;
    W libappCameraProcessor_arm64-v8a.so: attribute vec4 vertexPosition;
    06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so:
    W libappCameraProcessor_arm64-v8a.so: void main()
    W libappCameraProcessor_arm64-v8a.so: {
    W libappCameraProcessor_arm64-v8a.so:     texCoord = vertexTexCoord;
    W libappCameraProcessor_arm64-v8a.so:     gl_Position = ubuf.matrix * vertexPosition;
    W libappCameraProcessor_arm64-v8a.so: }
    06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so:
    06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so:
    W CameraProcesso: 0xebadde09 skipped times: 0
    F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x78 in tid 18394 (qtMainLoopThrea), pid 18373 (CameraProcessor)
    

    Now, the source code of the application:

    Main.qml

    import QtQuick.Window
    import QtMultimedia
    import QtQuick.Controls
    
    import Backend
    
    Window {
        width: 1920
        height: 1024
        visible: true
    
        Camera {
           id: userCamera
           focusMode: Camera.FocusModeAuto
        }
    
        CaptureSession {
           id: viewFinderCaptureSession
           videoOutput: viewfinder
           camera: userCamera
        }
    
        VideoOutput {
            id: viewfinder
            anchors.fill: parent
        }
    
        Backend{
            id: backend
            objectName: "backend"
        }
    
        Component.onCompleted: userCamera.start()
    
        Button {
            id: processButton
            onClicked: backend.videSink = viewfinder.videoSink
    
            width: 200
            height: 50
            text: "Take frame"
    
            x: 20
            y: 20
        }
    
    }
    

    backend.h

    #include <QObject>
    #include <QVideoSink>
    #include <QVideoFrame>
    #include <QVariant>
    
    class backend : public QObject
    {
        Q_OBJECT
    public:
        backend(QObject* _parent = nullptr);
    
        Q_INVOKABLE void setVideoSink(QVideoSink* _videoSink);
        void disconnectSink();
    };
    

    backend.cpp

    #include "backend.h"
    
    #include <QDebug>
    
    backend::backend(QObject* _parent):
        QObject(_parent)
    {
        // noting to do...
    }
    
    
    void backend::setVideoSink(QVideoSink* _videoSink)
    {
        auto myFrame = _videoSink->videoFrame();
        qDebug() << "map frame; is valid: " << myFrame.isValid() << "isMapped: " << myFrame.isMapped();
        myFrame.map(QVideoFrame::MapMode::ReadOnly);
        // TODO here comes some work ...
        myFrame.unmap();
    }
    

    The Backend is a C++ class registered in the 'main()' function.

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    #include "backend.h"
    
    int main(int argc, char *argv[])
    {
        qmlRegisterType< backend >( "Backend", 1, 0, "Backend" );
    
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
    
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
            &app, []() { QCoreApplication::exit(-1); },
            Qt::QueuedConnection);
    
        engine.loadFromModule("CameraProcessor", "Main");
    
        QObject::connect(&app, &QGuiApplication::applicationStateChanged, [](Qt::ApplicationState _state){
            qDebug() << "State changed to: " << _state;
        });
    
        return app.exec();
    }
    

    What is the problem here? Any idea to fix it? Examples or suggestions?

    Thank you!

    1 Reply Last reply
    2
    • A Offline
      A Offline
      alexander.weidemann
      wrote on 9 Aug 2023, 11:08 last edited by
      #2

      I am facing the exact same issue in a similar setup. Also tried with Qt6.2.8 and the newest Qt6.6, but same issue. @tm_sx Did you find a solution in the meantime?

      A 1 Reply Last reply 11 Aug 2023, 11:34
      1
      • A alexander.weidemann
        9 Aug 2023, 11:08

        I am facing the exact same issue in a similar setup. Also tried with Qt6.2.8 and the newest Qt6.6, but same issue. @tm_sx Did you find a solution in the meantime?

        A Offline
        A Offline
        alexander.weidemann
        wrote on 11 Aug 2023, 11:34 last edited by
        #3

        UPDATE: This is a known bug in Qt https://bugreports.qt.io/browse/QTBUG-113616

        1 Reply Last reply
        1

        • Login

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