qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Volker Rümelin" <vr_qemu@t-online.de>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Howard Spoelstra" <hsp.cat7@gmail.com>
Subject: [PULL 3/7] coreaudio: always stop audio playback on shut down
Date: Tue, 15 Dec 2020 14:48:22 +0100	[thread overview]
Message-ID: <20201215134826.5504-4-kraxel@redhat.com> (raw)
In-Reply-To: <20201215134826.5504-1-kraxel@redhat.com>

From: Volker Rümelin <vr_qemu@t-online.de>

Always stop audio playback and remove the playback callback when
QEMU exits.

On shut down the function coreaudio_fini_out() destroys the
coreaudio mutex but fails to stop audio playback and to remove the
audio playback callback, because function audio_is_cleaning_up()
always returns true when called from coreaudio_fini_out(). Now
there is a time window from pthread_mutex_destroy() to program
exit where Core Audio may call the audio playback callback which
tries to lock the destroyed coreaudio mutex. This leads to the
following error.

coreaudio: Could not lock voice for audioDeviceIOProc
Reason: Invalid argument

This bug was reported on the qemu-discuss mailing list.
https://lists.nongnu.org/archive/html/qemu-discuss/2020-10/msg00018.html

Tested-by: Howard Spoelstra <hsp.cat7@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-id: 20201213130528.5863-3-vr_qemu@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 audio/coreaudio.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index a5df95051461..79a9d40bf8ef 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -593,22 +593,20 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
     int err;
     coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
 
-    if (!audio_is_cleaning_up()) {
-        /* stop playback */
-        if (isPlaying(core->outputDeviceID)) {
-            status = AudioDeviceStop(core->outputDeviceID, core->ioprocid);
-            if (status != kAudioHardwareNoError) {
-                coreaudio_logerr (status, "Could not stop playback\n");
-            }
-        }
-
-        /* remove callback */
-        status = AudioDeviceDestroyIOProcID(core->outputDeviceID,
-                                            core->ioprocid);
+    /* stop playback */
+    if (isPlaying(core->outputDeviceID)) {
+        status = AudioDeviceStop(core->outputDeviceID, core->ioprocid);
         if (status != kAudioHardwareNoError) {
-            coreaudio_logerr (status, "Could not remove IOProc\n");
+            coreaudio_logerr(status, "Could not stop playback\n");
         }
     }
+
+    /* remove callback */
+    status = AudioDeviceDestroyIOProcID(core->outputDeviceID,
+                                        core->ioprocid);
+    if (status != kAudioHardwareNoError) {
+        coreaudio_logerr(status, "Could not remove IOProc\n");
+    }
     core->outputDeviceID = kAudioDeviceUnknown;
 
     /* destroy mutex */
@@ -633,13 +631,11 @@ static void coreaudio_enable_out(HWVoiceOut *hw, bool enable)
         }
     } else {
         /* stop playback */
-        if (!audio_is_cleaning_up()) {
-            if (isPlaying(core->outputDeviceID)) {
-                status = AudioDeviceStop(core->outputDeviceID,
-                                         core->ioprocid);
-                if (status != kAudioHardwareNoError) {
-                    coreaudio_logerr (status, "Could not pause playback\n");
-                }
+        if (isPlaying(core->outputDeviceID)) {
+            status = AudioDeviceStop(core->outputDeviceID,
+                                     core->ioprocid);
+            if (status != kAudioHardwareNoError) {
+                coreaudio_logerr(status, "Could not pause playback\n");
             }
         }
     }
-- 
2.27.0



  parent reply	other threads:[~2020-12-15 13:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 13:48 [PULL 0/7] Audio 20201215 patches Gerd Hoffmann
2020-12-15 13:48 ` [PULL 1/7] coreaudio: rename misnamed variable fake_as Gerd Hoffmann
2020-12-15 13:48 ` [PULL 2/7] coreaudio: don't start playback in init routine Gerd Hoffmann
2020-12-15 13:48 ` Gerd Hoffmann [this message]
2020-12-15 13:48 ` [PULL 4/7] audio: remove unused function audio_is_cleaning_up() Gerd Hoffmann
2020-12-15 13:48 ` [PULL 5/7] cs4231: Get rid of empty property array Gerd Hoffmann
2020-12-15 13:48 ` [PULL 6/7] audio: Simplify audio_bug() removing old code Gerd Hoffmann
2020-12-15 13:48 ` [PULL 7/7] audio: add sanity check Gerd Hoffmann
2020-12-15 15:35 ` [PULL 0/7] Audio 20201215 patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201215134826.5504-4-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=hsp.cat7@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vr_qemu@t-online.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).