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. Segmentation fault while using QMedialpayer in qt 6.7 on i.MX8QXP custom board
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault while using QMedialpayer in qt 6.7 on i.MX8QXP custom board

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 192 Views 2 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.
  • A Offline
    A Offline
    adnan_14
    wrote on last edited by
    #1

    Hi,

    We are encountering random segmentation faults when deleting the QMediaPlayer pointer after audio playback. audio file duration is approximately 1.5 second and it will be called continously from frontend.

    I’ve attached the relevant section of the audio-related code, along with GDB logs captured from the target device. From the debugging session, it appears the crash occurs because the QMediaPlayer instance is being freed while still in use—likely by internal GStreamer callbacks.

    I also tried replacing the delete call with deleteLater(), but the issue persists and results in a similar segmentation fault.

    Please review the attached code and logs, and let me know how this can be resolved or what changes are recommended.

    audioPaly will be called from front end based on the data recieved continously.

    void serial::audioPaly(const QString value)
    {
        // qDebug()<<"audio value : " << value;
    
        audiovalue =  value.toInt();
        try{
            QString pathBuzzer1 = "qrc:/audio/sound_1.mp3";
            QString pathBuzzer2 =  "qrc:/audio/sound_5.mp3";
            if(flgAudioPlay==false){
                if (audiovalue >= currentaudio)
                {
                if(audiovalue == 2)
                    {
                        // continuous tone
                        currentaudio = 2;
                        mplayer  = new QMediaPlayer;
                        audioOutput = new QAudioOutput;
    
                        mplayer -> setAudioOutput(audioOutput);
    
                        mplayer -> setSource(QUrl(pathBuzzer2));
                        audioOutput -> setVolume(50);
                        mplayer -> play();
    
                        flgAudioPlay = true;
                        pkt1secAudio = new QTimer(this);
                        connect(pkt1secAudio,SIGNAL(timeout()),SLOT(slotAudioPlay()));
                        pkt1secAudio -> start(2500);
                    }
                    else{}
                }
            }else{}
        }
        catch (...){
            errorlogger("Error on audioPaly()!");
            flgError = true;
        }
    }
    
    
    void serial::slotAudioPlay()
    {
        try{
            mplayer -> stop();
            pkt1secAudio -> stop();
            flgAudioPlay = false;
            currentaudio = 0;
            m_audiocounter =0;
            delete mplayer;
            delete audioOutput;
        }
        catch (...){
            errorlogger("Error on slotAudioPlay()!");
            flgError = true;
        }
    }
    

    LOGS:-

    ===!!! Current pulsesink device is alsa_output.platform-sound.stereo-fallback !!!===
     
    [Thread 0xffffa17aefa0 (LWP 7976) exited]
     
    Thread 1 "LP_OCIP_KAVACH" received signal SIGSEGV, Segmentation fault.
    0x0000ffffeab840ac in QGstreamerMediaPlayer::decoderPadRemoved(QGstElement const&, QGstPad const&) () from /usr/lib/plugins/multimedia/libgstreamermediaplugin.so
    (gdb) bt
    #0  0x0000ffffeab840ac in QGstreamerMediaPlayer::decoderPadRemoved(QGstElement const&, QGstPad const&) () from /usr/lib/plugins/multimedia/libgstreamermediaplugin.so
    #1  0x0000ffffeab88f34 in ?? () from /usr/lib/plugins/multimedia/libgstreamermediaplugin.so
    #2  0x0000ffffea61b7fc in g_cclosure_marshal_VOID__OBJECTv () from /usr/lib/libgobject-2.0.so.0
    #3  0x0000ffffea617e4c in ?? () from /usr/lib/libgobject-2.0.so.0
    #4  0x0000ffffea62e56c in ?? () from /usr/lib/libgobject-2.0.so.0
    #5  0x0000ffffea633dc4 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
    #6  0x0000ffffea633e84 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
    #7  0x0000ffffea6ff3d8 in gst_element_remove_pad () from /usr/lib/libgstreamer-1.0.so.0
    #8  0x0000ffffea6ff610 in ?? () from /usr/lib/libgstreamer-1.0.so.0
    #9  0x0000ffffea61d9cc in g_object_unref () from /usr/lib/libgobject-2.0.so.0
    #10 0x0000ffffea6d945c in ?? () from /usr/lib/libgstreamer-1.0.so.0
    #11 0x0000ffffea6d85a8 in gst_bin_remove () from /usr/lib/libgstreamer-1.0.so.0
    #12 0x0000ffffea6d891c in ?? () from /usr/lib/libgstreamer-1.0.so.0
    #13 0x0000ffffea61d9cc in g_object_unref () from /usr/lib/libgobject-2.0.so.0
    #14 0x0000ffffeab8a94c in QGstreamerVideoOutput::~QGstreamerVideoOutput() () from /usr/lib/plugins/multimedia/libgstreamermediaplugin.so
    #15 0x0000ffffeab8a9e8 in QGstreamerVideoOutput::~QGstreamerVideoOutput() () from /usr/lib/plugins/multimedia/libgstreamermediaplugin.so
    #16 0x0000fffff6bddc54 in QObjectPrivate::deleteChildren() () from /usr/lib/libQt6Core.so.6
    #17 0x0000fffff6be2b98 in QObject::~QObject() () from /usr/lib/libQt6Core.so.6
    #18 0x0000ffffeab87dcc in non-virtual thunk to QGstreamerMediaPlayer::~QGstreamerMediaPlayer() () from /usr/lib/plugins/multimedia/libgstreamermediaplugin.so
    #19 0x0000fffff7764164 in QMediaPlayer::~QMediaPlayer() () from /usr/lib/libQt6Multimedia.so.6
    #20 0x0000fffff77641a8 in QMediaPlayer::~QMediaPlayer() () from /usr/lib/libQt6Multimedia.so.6
    #21 0x0000aaaaaaaa9d1c in serial::slotAudioPlay (this=0xfffffffff5a0) at serial.cpp:1814
    #22 0x0000fffff6be6274 in ?? () from /usr/lib/libQt6Core.so.6
    #23 0x0000fffff6bf4fd4 in QTimer::timeout(QTimer::QPrivateSignal) () from /usr/lib/libQt6Core.so.6
    #24 0x0000fffff6bd77bc in QObject::event(QEvent*) () from /usr/lib/libQt6Core.so.6
    #25 0x0000fffff79b2af8 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/libQt6Widgets.so.6
    #26 0x0000fffff6b7f49c in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib/libQt6Core.so.6
    #27 0x0000fffff6d30828 in QTimerInfoList::activateTimers() () from /usr/lib/libQt6Core.so.6
    #28 0x0000fffff6e5ee84 in ?? () from /usr/lib/libQt6Core.so.6
    #29 0x0000fffff52499e4 in ?? () from /usr/lib/libglib-2.0.so.0
    #30 0x0000fffff524d318 in ?? () from /usr/lib/libglib-2.0.so.0
    #31 0x0000fffff524dae8 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
    #32 0x0000fffff6e5f128 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQt6Core.so.6
    #33 0x0000fffff6b8c6bc in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQt6Core.so.6
    #34 0x0000fffff6b88640 in QCoreApplication::exec() () from /usr/lib/libQt6Core.so.6
    #35 0x0000aaaaaaaa4e84 in main (argc=<optimized out>, argv=<optimized out>) at main.cpp:30
    (gdb) frame 21
    #21 0x0000aaaaaaaa9d1c in serial::slotAudioPlay (this=0xfffffffff5a0) at serial.cpp:1814
    1814	        delete mplayer;
    

    Regards,
    Adnan

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

      Hi and welcome to devnet,

      Does calling GStreamer on the command line with these files also trigger such crashes ?

      Beside that, why are you deleting and recreating the player object all the time rather than playing the adequate file when time has come ?

      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
      • A Offline
        A Offline
        adnan_14
        wrote on last edited by
        #3

        Hi,

        Using gstreamer from command line does not cause any crash.

        So are saying rather than creating a new instance every-time and deleting it i can just reusing the same instance and avoid deleting it entirely?

        Regards,
        Adnan

        1 Reply Last reply
        0
        • A Offline
          A Offline
          adnan_14
          wrote on last edited by
          #4

          Hi,

          are you suggesting something like below?

          void serial::audioPaly(const QString value)
          {
              // qDebug()<<"audio value : " << value;
          
              audiovalue =  value.toInt();
              try{
                  QString pathBuzzer1 = "qrc:/audio/sound_1.mp3";
                  QString pathBuzzer2 =  "qrc:/audio/sound_5.mp3";
                  if(flgAudioPlay==false){
                      if (audiovalue >= currentaudio)
                      {
                      if(audiovalue == 2)
                          {
                              // continuous tone
                              currentaudio = 2;
                              if (!mplayer) {
                                    mplayer = new QMediaPlayer(this);
                               }
                              if (!audioOutput) {
                                    audioOutput = new QAudioOutput(this);
                              }               
          
                              mplayer -> setSource(QUrl(pathBuzzer2));
                              audioOutput -> setVolume(50);
                              mplayer -> play();
          
                              flgAudioPlay = true;
                              pkt1secAudio = new QTimer(this);
                              connect(pkt1secAudio,SIGNAL(timeout()),SLOT(slotAudioPlay()));
                              pkt1secAudio -> start(2500);
                          }
                          else{}
                      }
                  }else{}
              }
              catch (...){
                  errorlogger("Error on audioPaly()!");
                  flgError = true;
              }
          }
          
          
          void serial::slotAudioPlay()
          {
              try{
                  mplayer -> stop();
                  pkt1secAudio -> stop();
                  flgAudioPlay = false;
                  currentaudio = 0;
                  m_audiocounter =0;
                  if (mplayer) {
                        mplayer->stop();
                   }
                   if (audioOutput) {
                         audioOutput->stop();
                   }    
          }
            catch (...){
                  errorlogger("Error on slotAudioPlay()!");
                  flgError = true;
              }
          }
          
          

          We were using delete since if we don't delete memory usage kept increasing.

          Regards,
          Adnan

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

            You are recreating pkt1secAudio every time.
            You should really check the lifetime of all your objects.

            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