All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] coreaudio bug fix and clean up
@ 2020-12-13 13:03 Volker Rümelin
  2020-12-13 13:05 ` [PATCH 1/4] coreaudio: rename misnamed variable fake_as Volker Rümelin
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Volker Rümelin @ 2020-12-13 13:03 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel, Howard Spoelstra

Fix a bug reported on the qemu-discuss mailing list. The error
message was:

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

While being there, do some clean up.

Howard was kind enough to test the patches.

Volker Rümelin (4):
  coreaudio: rename misnamed variable fake_as
  coreaudio: don't start playback in init routine
  coreaudio: always stop audio playback on shut down
  audio: remove unused function audio_is_cleaning_up()

 audio/audio.c     |  8 -------
 audio/audio.h     |  1 -
 audio/coreaudio.c | 53 +++++++++++++++++------------------------------
 3 files changed, 19 insertions(+), 43 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] coreaudio: rename misnamed variable fake_as
  2020-12-13 13:03 [PATCH 0/4] coreaudio bug fix and clean up Volker Rümelin
@ 2020-12-13 13:05 ` Volker Rümelin
  2020-12-15  8:16   ` Gerd Hoffmann
  2020-12-13 13:05 ` [PATCH 2/4] coreaudio: don't start playback in init routine Volker Rümelin
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Volker Rümelin @ 2020-12-13 13:05 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU

While the variable once was used to fake audio settings, since
commit ed2a4a7941 "audio: proper support for float samples in
mixeng" this is no longer true. Rename the variable to obt_as.
This is the same naming scheme as in audio/sdlaudio.c

Tested-by: Howard Spoelstra <hsp.cat7@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/coreaudio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 4b4365660f..0ee85052c4 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -482,7 +482,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
     Audiodev *dev = drv_opaque;
     AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
     int frames;
-    struct audsettings fake_as;
+    struct audsettings obt_as;
 
     /* create mutex */
     err = pthread_mutex_init(&core->mutex, NULL);
@@ -491,8 +491,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
-    fake_as = *as;
-    as = &fake_as;
+    obt_as = *as;
+    as = &obt_as;
     as->fmt = AUDIO_FORMAT_F32;
     audio_pcm_init_info (&hw->info, as);
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] coreaudio: don't start playback in init routine
  2020-12-13 13:03 [PATCH 0/4] coreaudio bug fix and clean up Volker Rümelin
  2020-12-13 13:05 ` [PATCH 1/4] coreaudio: rename misnamed variable fake_as Volker Rümelin
@ 2020-12-13 13:05 ` Volker Rümelin
  2020-12-13 13:05 ` [PATCH 3/4] coreaudio: always stop audio playback on shut down Volker Rümelin
  2020-12-13 13:05 ` [PATCH 4/4] audio: remove unused function audio_is_cleaning_up() Volker Rümelin
  3 siblings, 0 replies; 6+ messages in thread
From: Volker Rümelin @ 2020-12-13 13:05 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU

Every emulated audio device has a way to enable audio playback. Don't
start playback until the guest enables the audio device to keep the
Core Audio device run state in sync with hw->enabled.

Tested-by: Howard Spoelstra <hsp.cat7@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/coreaudio.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 0ee85052c4..a5df950514 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -584,17 +584,6 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
-    /* start Playback */
-    if (!isPlaying(core->outputDeviceID)) {
-        status = AudioDeviceStart(core->outputDeviceID, core->ioprocid);
-        if (status != kAudioHardwareNoError) {
-            coreaudio_logerr2 (status, typ, "Could not start playback\n");
-            AudioDeviceDestroyIOProcID(core->outputDeviceID, core->ioprocid);
-            core->outputDeviceID = kAudioDeviceUnknown;
-            return -1;
-        }
-    }
-
     return 0;
 }
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] coreaudio: always stop audio playback on shut down
  2020-12-13 13:03 [PATCH 0/4] coreaudio bug fix and clean up Volker Rümelin
  2020-12-13 13:05 ` [PATCH 1/4] coreaudio: rename misnamed variable fake_as Volker Rümelin
  2020-12-13 13:05 ` [PATCH 2/4] coreaudio: don't start playback in init routine Volker Rümelin
@ 2020-12-13 13:05 ` Volker Rümelin
  2020-12-13 13:05 ` [PATCH 4/4] audio: remove unused function audio_is_cleaning_up() Volker Rümelin
  3 siblings, 0 replies; 6+ messages in thread
From: Volker Rümelin @ 2020-12-13 13:05 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU

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>
---
 audio/coreaudio.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index a5df950514..79a9d40bf8 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.26.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] audio: remove unused function audio_is_cleaning_up()
  2020-12-13 13:03 [PATCH 0/4] coreaudio bug fix and clean up Volker Rümelin
                   ` (2 preceding siblings ...)
  2020-12-13 13:05 ` [PATCH 3/4] coreaudio: always stop audio playback on shut down Volker Rümelin
@ 2020-12-13 13:05 ` Volker Rümelin
  3 siblings, 0 replies; 6+ messages in thread
From: Volker Rümelin @ 2020-12-13 13:05 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU

The previous commit removed the last call site of
audio_is_cleaning_up(). Remove the now unused function.

Tested-by: Howard Spoelstra <hsp.cat7@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/audio.c | 8 --------
 audio/audio.h | 1 -
 2 files changed, 9 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 46578e4a58..a213409270 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1588,13 +1588,6 @@ static void audio_vm_change_state_handler (void *opaque, int running,
     audio_reset_timer (s);
 }
 
-static bool is_cleaning_up;
-
-bool audio_is_cleaning_up(void)
-{
-    return is_cleaning_up;
-}
-
 static void free_audio_state(AudioState *s)
 {
     HWVoiceOut *hwo, *hwon;
@@ -1647,7 +1640,6 @@ static void free_audio_state(AudioState *s)
 
 void audio_cleanup(void)
 {
-    is_cleaning_up = true;
     while (!QTAILQ_EMPTY(&audio_states)) {
         AudioState *s = QTAILQ_FIRST(&audio_states);
         QTAILQ_REMOVE(&audio_states, s, list);
diff --git a/audio/audio.h b/audio/audio.h
index b883ebfb1f..41b3ef04ea 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -160,7 +160,6 @@ static inline void *advance (void *p, int incr)
 int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
                       int freq, int bits, int nchannels);
 
-bool audio_is_cleaning_up(void);
 void audio_cleanup(void);
 
 void audio_sample_to_uint64(const void *samples, int pos,
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] coreaudio: rename misnamed variable fake_as
  2020-12-13 13:05 ` [PATCH 1/4] coreaudio: rename misnamed variable fake_as Volker Rümelin
@ 2020-12-15  8:16   ` Gerd Hoffmann
  0 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2020-12-15  8:16 UTC (permalink / raw)
  To: Volker Rümelin; +Cc: QEMU

On Sun, Dec 13, 2020 at 02:05:25PM +0100, Volker Rümelin wrote:
> While the variable once was used to fake audio settings, since
> commit ed2a4a7941 "audio: proper support for float samples in
> mixeng" this is no longer true. Rename the variable to obt_as.
> This is the same naming scheme as in audio/sdlaudio.c
> 
> Tested-by: Howard Spoelstra <hsp.cat7@gmail.com>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>

Added all to audio queue.

thanks,
  Gerd



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-15  8:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-13 13:03 [PATCH 0/4] coreaudio bug fix and clean up Volker Rümelin
2020-12-13 13:05 ` [PATCH 1/4] coreaudio: rename misnamed variable fake_as Volker Rümelin
2020-12-15  8:16   ` Gerd Hoffmann
2020-12-13 13:05 ` [PATCH 2/4] coreaudio: don't start playback in init routine Volker Rümelin
2020-12-13 13:05 ` [PATCH 3/4] coreaudio: always stop audio playback on shut down Volker Rümelin
2020-12-13 13:05 ` [PATCH 4/4] audio: remove unused function audio_is_cleaning_up() Volker Rümelin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.