All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Kletzander <mkletzan@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	libvir-list@redhat.com,
	"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Qiuhao Li" <Qiuhao.Li@outlook.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Bandan Das" <bsd@redhat.com>,
	qemu-arm@nongnu.org, "Jan Kiszka" <jan.kiszka@web.de>,
	"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Darren Kenny" <darren.kenny@oracle.com>,
	"Thomas Huth" <huth@tuxfamily.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-ppc@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH 15/18] audio: Be more strict during audio backend initialisation
Date: Mon, 25 Apr 2022 10:21:58 +0200	[thread overview]
Message-ID: <e9c251a6b45d01d4b1d59ce4c6295172f354b301.1650874791.git.mkletzan@redhat.com> (raw)
In-Reply-To: <cover.1650874791.git.mkletzan@redhat.com>

Now that audiodev= is required and audio_init() will not be called
without and AudioDev we can remove the fallback functionality and error
out in case audio drivers fail initialisation or when the driver does
not exist.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 audio/audio.c                   | 146 ++++++--------------------------
 docs/about/deprecated.rst       |   8 --
 docs/about/removed-features.rst |   8 ++
 3 files changed, 34 insertions(+), 128 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 97eb645764c1..c944cf817cf9 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -87,6 +87,8 @@ audio_driver *audio_driver_lookup(const char *name)
         }
     }
 
+    error_setg(&error_fatal, "Unknown audio driver `%s'", name);
+    /* Avoid compiler complaining that we do not return in non-void function */
     return NULL;
 }
 
@@ -104,8 +106,6 @@ const struct mixeng_volume nominal_volume = {
 #endif
 };
 
-static bool legacy_config = true;
-
 int audio_bug (const char *funcname, int cond)
 {
     if (cond) {
@@ -1532,31 +1532,27 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
     return total;
 }
 
-static int audio_driver_init(AudioState *s, struct audio_driver *drv,
-                             bool msg, Audiodev *dev)
+static void audio_driver_init(AudioState *s, struct audio_driver *drv,
+                              Audiodev *dev)
 {
     s->drv_opaque = drv->init(dev);
 
-    if (s->drv_opaque) {
-        if (!drv->pcm_ops->get_buffer_in) {
-            drv->pcm_ops->get_buffer_in = audio_generic_get_buffer_in;
-            drv->pcm_ops->put_buffer_in = audio_generic_put_buffer_in;
-        }
-        if (!drv->pcm_ops->get_buffer_out) {
-            drv->pcm_ops->get_buffer_out = audio_generic_get_buffer_out;
-            drv->pcm_ops->put_buffer_out = audio_generic_put_buffer_out;
-        }
+    if (!s->drv_opaque) {
+        error_setg(&error_fatal, "Could not init `%s' audio driver", drv->name);
+    }
 
-        audio_init_nb_voices_out(s, drv);
-        audio_init_nb_voices_in(s, drv);
-        s->drv = drv;
-        return 0;
-    } else {
-        if (msg) {
-            dolog("Could not init `%s' audio driver\n", drv->name);
-        }
-        return -1;
+    if (!drv->pcm_ops->get_buffer_in) {
+        drv->pcm_ops->get_buffer_in = audio_generic_get_buffer_in;
+        drv->pcm_ops->put_buffer_in = audio_generic_put_buffer_in;
     }
+    if (!drv->pcm_ops->get_buffer_out) {
+        drv->pcm_ops->get_buffer_out = audio_generic_get_buffer_out;
+        drv->pcm_ops->put_buffer_out = audio_generic_put_buffer_out;
+    }
+
+    audio_init_nb_voices_out(s, drv);
+    audio_init_nb_voices_in(s, drv);
+    s->drv = drv;
 }
 
 static void audio_vm_change_state_handler (void *opaque, bool running,
@@ -1661,79 +1657,19 @@ static const VMStateDescription vmstate_audio = {
 
 static void audio_validate_opts(Audiodev *dev, Error **errp);
 
-static AudiodevListEntry *audiodev_find(
-    AudiodevListHead *head, const char *drvname)
-{
-    AudiodevListEntry *e;
-    QSIMPLEQ_FOREACH(e, head, next) {
-        if (strcmp(AudiodevDriver_str(e->dev->driver), drvname) == 0) {
-            return e;
-        }
-    }
-
-    return NULL;
-}
-
-/*
- * if we have dev, this function was called because of an -audiodev argument =>
- *   initialize a new state with it
- * if dev == NULL => legacy implicit initialization, return the already created
- *   state or create a new one
- */
-static AudioState *audio_init(Audiodev *dev, const char *name)
+static AudioState *audio_init(Audiodev *dev)
 {
     static bool atexit_registered;
-    size_t i;
-    int done = 0;
     const char *drvname = NULL;
     VMChangeStateEntry *e;
     AudioState *s;
-    struct audio_driver *driver;
-    /* silence gcc warning about uninitialized variable */
-    AudiodevListHead head = QSIMPLEQ_HEAD_INITIALIZER(head);
-
-    if (using_spice) {
-        /*
-         * When using spice allow the spice audio driver being picked
-         * as default.
-         *
-         * Temporary hack.  Using audio devices without explicit
-         * audiodev= property is already deprecated.  Same goes for
-         * the -soundhw switch.  Once this support gets finally
-         * removed we can also drop the concept of a default audio
-         * backend and this can go away.
-         */
-        driver = audio_driver_lookup("spice");
-        if (driver) {
-            driver->can_be_default = 1;
-        }
-    }
 
-    if (dev) {
-        /* -audiodev option */
-        legacy_config = false;
-        drvname = AudiodevDriver_str(dev->driver);
-    } else if (!QTAILQ_EMPTY(&audio_states)) {
-        if (!legacy_config) {
-            dolog("Device %s: audiodev default parameter is deprecated, please "
-                  "specify audiodev=%s\n", name,
-                  QTAILQ_FIRST(&audio_states)->dev->id);
-        }
-        return QTAILQ_FIRST(&audio_states);
-    } else {
-        /* legacy implicit initialization */
-        head = audio_handle_legacy_opts();
-        /*
-         * In case of legacy initialization, all Audiodevs in the list will have
-         * the same configuration (except the driver), so it doesn't matter which
-         * one we chose.  We need an Audiodev to set up AudioState before we can
-         * init a driver.  Also note that dev at this point is still in the
-         * list.
-         */
-        dev = QSIMPLEQ_FIRST(&head)->dev;
-        audio_validate_opts(dev, &error_abort);
+    if (!dev) {
+        error_setg(&error_abort, "Mandatory audiodev parameter required");
     }
 
+    drvname = AudiodevDriver_str(dev->driver);
+
     s = g_new0(AudioState, 1);
     s->dev = dev;
 
@@ -1763,37 +1699,7 @@ static AudioState *audio_init(Audiodev *dev, const char *name)
         s->nb_hw_voices_in = 0;
     }
 
-    if (drvname) {
-        driver = audio_driver_lookup(drvname);
-        if (driver) {
-            done = !audio_driver_init(s, driver, true, dev);
-        } else {
-            dolog ("Unknown audio driver `%s'\n", drvname);
-        }
-    } else {
-        for (i = 0; audio_prio_list[i]; i++) {
-            AudiodevListEntry *e = audiodev_find(&head, audio_prio_list[i]);
-            driver = audio_driver_lookup(audio_prio_list[i]);
-
-            if (e && driver) {
-                s->dev = dev = e->dev;
-                audio_validate_opts(dev, &error_abort);
-                done = !audio_driver_init(s, driver, false, dev);
-                if (done) {
-                    e->dev = NULL;
-                    break;
-                }
-            }
-        }
-    }
-    audio_free_audiodev_list(&head);
-
-    if (!done) {
-        driver = audio_driver_lookup("none");
-        done = !audio_driver_init(s, driver, false, dev);
-        assert(done);
-        dolog("warning: Using timer based audio emulation\n");
-    }
+    audio_driver_init(s, audio_driver_lookup(drvname), dev);
 
     if (dev->timer_period <= 0) {
         s->period_ticks = 1;
@@ -2120,7 +2026,7 @@ void audio_init_audiodevs(void)
     AudiodevListEntry *e;
 
     QSIMPLEQ_FOREACH(e, &audiodevs, next) {
-        audio_init(e->dev, NULL);
+        audio_init(e->dev);
     }
 }
 
@@ -2133,7 +2039,7 @@ static void audio_init_dummy(const char *id)
     dev->id = g_strdup(id);
 
     audio_validate_opts(dev, &error_abort);
-    audio_init(dev, NULL);
+    audio_init(dev);
 
     e->dev = dev;
     QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
index 7ba71ebd3435..b2255319e347 100644
--- a/docs/about/deprecated.rst
+++ b/docs/about/deprecated.rst
@@ -31,14 +31,6 @@ backend settings instead of environment variables.  To ease migration to
 the new format, the ``-audiodev-help`` option can be used to convert
 the current values of the environment variables to ``-audiodev`` options.
 
-Creating sound card devices and vnc without ``audiodev=`` property (since 4.2)
-''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
-When not using the deprecated legacy audio config, each sound card
-should specify an ``audiodev=`` property.  Additionally, when using
-vnc, you should specify an ``audiodev=`` property if you plan to
-transmit audio through the VNC protocol.
-
 ``-chardev`` backend aliases ``tty`` and ``parport`` (since 6.0)
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst
index 086ba3edb042..f9eea4dda327 100644
--- a/docs/about/removed-features.rst
+++ b/docs/about/removed-features.rst
@@ -346,6 +346,14 @@ needs two devices (``-device intel-hda -device hda-duplex``) and
 pcspk-audiodev=<name>``.  And ``AC97`` and ``ES1370`` now have to be
 specified in uppercase.
 
+Creating sound card devices and vnc without ``audiodev=`` property (removed in 7.1)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+When not using the deprecated legacy audio config, each sound card
+should specify an ``audiodev=`` property.  Additionally, when using
+vnc, you should specify an ``audiodev=`` property if you plan to
+transmit audio through the VNC protocol.
+
 
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
-- 
2.35.1



  parent reply	other threads:[~2022-04-25  8:43 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25  8:21 [PATCH 00/18] RFC: Remove deprecated audio features Martin Kletzander
2022-04-25  8:21 ` [PATCH 01/18] hw/audio: Remove -soundhw support Martin Kletzander
2022-04-25 13:16   ` Daniel P. Berrangé
2022-04-26  8:53   ` Stefan Hajnoczi
2022-04-27 10:10   ` Paolo Bonzini
2022-04-25  8:21 ` [PATCH 02/18] hw/input/tsc210x: Extract common init code into new function Martin Kletzander
2022-04-25 13:19   ` Daniel P. Berrangé
2022-04-25  8:21 ` [PATCH 03/18] hw/audio: Simplify hda audio init Martin Kletzander
2022-04-25 13:35   ` Daniel P. Berrangé
2022-04-25 14:06     ` Daniel P. Berrangé
2022-04-25  8:21 ` [PATCH 04/18] hw/audio/lm4549: Add errp error reporting to init function Martin Kletzander
2022-04-25 14:08   ` Daniel P. Berrangé
2022-04-25  8:21 ` [PATCH 05/18] tests/qtest: Specify audiodev= and -audiodev Martin Kletzander
2022-04-25 13:42   ` Daniel P. Berrangé
2022-04-29 10:37     ` Martin Kletzander
2022-04-25  8:21 ` [PATCH 06/18] ui/vnc: Require audiodev= Martin Kletzander
2022-04-25 13:48   ` Daniel P. Berrangé
2022-04-27  9:32   ` Paolo Bonzini
2022-04-27  9:41     ` Daniel P. Berrangé
2022-04-25  8:21 ` [PATCH 07/18] Introduce machine's default-audiodev property Martin Kletzander
2022-04-25 14:06   ` Daniel P. Berrangé
2022-04-29 11:36     ` Martin Kletzander
2022-04-25  8:21 ` [PATCH 08/18] audio: Add easy dummy audio initialiser Martin Kletzander
2022-04-25  8:21 ` [PATCH 09/18] hw/display/xlnx_dp.c: Add audiodev property Martin Kletzander
2022-04-25  8:21 ` [PATCH 10/18] hw/input/tsc210x.c: Support machine-default audiodev with fallback Martin Kletzander
2022-04-25  8:21 ` [PATCH 11/18] hw/arm: " Martin Kletzander
2022-04-25  8:21 ` [PATCH 12/18] hw/ppc: " Martin Kletzander
2022-04-25  8:21 ` [PATCH 13/18] audio: Make AUD_register_card fallible and require audiodev= Martin Kletzander
2022-04-25 13:34   ` Daniel P. Berrangé
2022-04-25 13:39     ` Daniel P. Berrangé
2022-04-25  8:21 ` [PATCH 14/18] audio: Require AudioState in AUD_add_capture Martin Kletzander
2022-04-25 14:11   ` Daniel P. Berrangé
2022-04-25  8:21 ` Martin Kletzander [this message]
2022-04-25 14:16   ` [PATCH 15/18] audio: Be more strict during audio backend initialisation Daniel P. Berrangé
2022-04-25  8:21 ` [PATCH 16/18] audio: Remove legacy audio environment variables and options Martin Kletzander
2022-04-25 14:19   ` Daniel P. Berrangé
2022-04-25  8:22 ` [PATCH 17/18] audio: Remove unused can_be_default Martin Kletzander
2022-04-25 14:19   ` Daniel P. Berrangé
2022-04-25  8:22 ` [PATCH 18/18] audio/spiceaudio: Fail initialisation when not using spice Martin Kletzander
2022-04-25 13:08   ` Daniel P. Berrangé
2022-04-25 17:05 ` [PATCH 00/18] RFC: Remove deprecated audio features Mark Cave-Ayland
2022-04-29 12:04   ` Martin Kletzander
2022-04-26  8:54 ` Stefan Hajnoczi
2023-09-15 11:47 ` Paolo Bonzini

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=e9c251a6b45d01d4b1d59ce4c6295172f354b301.1650874791.git.mkletzan@redhat.com \
    --to=mkletzan@redhat.com \
    --cc=Qiuhao.Li@outlook.com \
    --cc=alistair@alistair23.me \
    --cc=alxndr@bu.edu \
    --cc=berrange@redhat.com \
    --cc=bsd@redhat.com \
    --cc=darren.kenny@oracle.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=f4bug@amsat.org \
    --cc=hpoussin@reactos.org \
    --cc=huth@tuxfamily.org \
    --cc=jan.kiszka@web.de \
    --cc=kraxel@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=wangyanan55@huawei.com \
    /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 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.