audacious-media-player / audacious

A lightweight and versatile audio player
https://audacious-media-player.org
Other
872 stars 116 forks source link

Qt Audio plugin freeze/crash conditions #1473

Open mschwendt opened 1 month ago

mschwendt commented 1 month ago

In two corner-case situations, the Qt 6 based "QtMultimedia Output" plugin either freezes or crashes Audacious 4.4.1.

1) Start playback using an output plugin other than QtMultimedia. 2) While audio is playing, switch to QtMultimedia output. Playback continues. 3) While audio is still playing, return from QtMultimedia output to a different output plugin. Audacious freezes.

Or with an alternative step 3:

3) While audio is still playing, don't return from QtMultimedia output to a different output plugin, but simply stop playback. Audacious crashes. QObject::killTimer: Timers cannot be stopped from another thread QObject::~QObject: Timers cannot be stopped from another thread Segmentation fault (core dumped)

radioactiveman commented 1 month ago

I can't reproduce this, neither the freeze nor the crash. What is your Qt 6 version and does this occur also when compiling Audacious for Qt 5?

mschwendt commented 1 month ago

$ rpm -qa|grep -i ^qt6|sort qt6-filesystem-6.7.2-3.fc41.x86_64 qt6-qtbase-6.7.2-6.fc41.x86_64 qt6-qtbase-common-6.7.2-6.fc41.noarch qt6-qtbase-gui-6.7.2-6.fc41.x86_64 qt6-qtdeclarative-6.7.2-3.fc41.x86_64 qt6-qtmultimedia-6.7.2-2.fc41.x86_64 qt6-qtquick3d-6.7.2-3.fc41.x86_64 qt6-qtquicktimeline-6.7.2-2.fc41.x86_64 qt6-qtshadertools-6.7.2-2.fc41.x86_64 qt6-qtsvg-6.7.2-2.fc41.x86_64 qt6-qttranslations-6.7.2-2.fc41.noarch qt6-qtwayland-6.7.2-4.fc41.x86_64 qt6-srpm-macros-6.7.2-3.fc41.noarch

Current testbed is Fedora 41 beta (x86_64).

Simplified test-case for the freeze is:

  1. Start Audacious.
  2. Select Qt Multimedia Output.
  3. Start playback.
  4. Select any other audio output.
  5. Total freeze.
radioactiveman commented 1 month ago

I don't know if this might be related, but with a Ubuntu VM and Qt 6 I could reproduce lagging/stuttering audio output when seeking intensively. Like when moving the time slider fast and a lot. On my main setup with Arch Linux it works fine though.

This patch helps for this case. Can you please try it as well @mschwendt?

diff --git a/src/qtaudio/qtaudio.cc b/src/qtaudio/qtaudio.cc
index ee7c0f002..7428adca8 100644
--- a/src/qtaudio/qtaudio.cc
+++ b/src/qtaudio/qtaudio.cc
@@ -92,7 +92,7 @@ const char * const QtAudioOutput::defaults[] = {
     nullptr
 };

-static const timespec fifty_ms = {0, 50000000};
+static const timespec ten_ms = {0, 10000000};

 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
@@ -248,7 +248,7 @@ void QtAudioOutput::period_wait ()

     while (output_instance->bytesFree () == 0)
     {
-        timespec ts = calc_abs_time (fifty_ms);
+        timespec ts = calc_abs_time (ten_ms);
         pthread_cond_timedwait (& cond, & mutex, & ts);
     }

@@ -274,7 +274,7 @@ void QtAudioOutput::drain ()

     while (output_instance->bytesFree () < output_instance->bufferSize ())
     {
-        timespec ts = calc_abs_time (fifty_ms);
+        timespec ts = calc_abs_time (ten_ms);
         pthread_cond_timedwait (& cond, & mutex, & ts);
     }
mschwendt commented 1 month ago

Seeking is instant here. Can't break it in any way.

I don't use the Qt output plugin normally, though.