admin管理员组

文章数量:1277347

Im working on a c++app using the QMediaPlayer Qt6.2 which comes with Ubuntu22.04.

Selecting Audiochannel other than '0' often causes a lockup and freezes the MainWindow and I got stuck here.

This is the simplified example:

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMediaPlayer>
#include <QVideoWidget>
#include <QAudioOutput>


QMediaPlayer *Player;
QVideoWidget *VideoWidg;
QAudioOutput *AudioOutp;
int audio = 0;


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    Player  = new QMediaPlayer(this);
    VideoWidg = new QVideoWidget(this);
    VideoWidg->setFixedSize(640, 480);
    AudioOutp = new QAudioOutput(this);
    Player->setVideoOutput(VideoWidg);
    Player->setAudioOutput(AudioOutp);
    Player->setSource(QUrl::fromLocalFile("/home/wappler/movie.mkv"));
//    Player->setActiveAudioTrack(1); // <<<< does nothing here !!!!
    Player->play();
//    Player->setActiveAudioTrack(0); // <<<<  does nothing here !!!!
//    qt.multimedia.player: Attempt to set an incorrect index 0 for the track type 1
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    if (audio == 0) {
        audio = 1;
    }
    else {
        audio = 0;
    }
    Player->setActiveAudioTrack(audio);    //sometimes (!) works / sometimes disables sound / sometimes locks
    qDebug () << audio << Player->activeAudioTrack();   //looks ok
}

Changing the ActiveAudioTrack via PushButton (while Player is in 'playing mode') sometimes it is playing the correct track. Sometimes sound disappears, and sometimes the whole thing ends up in a deadlock. Pausing the Debugger I end up here:

0x7ffff60912a5  <+   21>        85 c0                    test   %eax,%eax
0x7ffff60912a7  <+   23>        74 47                    je     0x7ffff60912f0 <__GI___lll_lock_wait+96>
        48 [1]  in ./nptl/lowlevellock.c
0x7ffff60912a9  <+   25>        90                       nop
        ../sysdeps/nptl/futex-internal.h:
0x7ffff60912aa  <+   26>        44 89 c6                 mov    %r8d,%esi
0x7ffff60912ad  <+   29>        45 31 d2                 xor    %r10d,%r10d
0x7ffff60912b0  <+   32>        ba 02 00 00 00           mov    $0x2,%edx
0x7ffff60912b5  <+   37>        b8 ca 00 00 00           mov    $0xca,%eax
0x7ffff60912ba  <+   42>        40 80 f6 80              xor    $0x80,%sil
0x7ffff60912be  <+   46>        0f 05                    syscall
0x7ffff60912c0  <+   48>        48 3d 00 f0 ff ff        cmp    $0xfffffffffffff000,%rax
0x7ffff60912c6  <+   54>        76 d6                    jbe    0x7ffff609129e <__GI___lll_lock_wait+14>
        147 [1] in ../sysdeps/nptl/futex-internal.h
0x7ffff60912c8  <+   56>        83 c0 0b                 add    $0xb,%eax
0x7ffff60912cb  <+   59>        83 f8 0b                 cmp    $0xb,%eax
0x7ffff60912ce  <+   62>        77 0b                    ja     0x7ffff60912db <__GI___lll_lock_wait+75>
0x7ffff60912d0  <+   64>        ba 81 08 00 00           mov    $0x881,%edx
0x7ffff60912d5  <+   69>        48 0f a3 c2              bt     %rax,%rdx
0x7ffff60912d9  <+   73>        72 c3                    jb     0x7ffff609129e <__GI___lll_lock_wait+14>
        87 [1]  in ../sysdeps/nptl/futex-internal.h
0x7ffff60912db  <+   75>        50                       push   %rax

Many thanks for your appreciated help!

本文标签: cQMediaPlayer setActiveAudioTrack() often locks main threadStack Overflow