Skip to content

Commit 2e16ec0

Browse files
committed
audio: deprecate -soundhw pcspk
Add deprecation message to the audio init function. Factor out audio initialization and call that from both audio init and realize, so setting the audiodev property is enough to properly initialize pcspk. Add a property alias to the machine type to set the audio device, so pcspk can be initialized using: "-machine pcspk-audiodev=<name>" Using "-global isa-pcspk.audiodev=<name>" works too but is not recommended. Signed-off-by: Gerd Hoffmann <[email protected]> Message-id: [email protected]
1 parent 6b8d141 commit 2e16ec0

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

hw/audio/pcspk.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "audio/audio.h"
2929
#include "qemu/module.h"
3030
#include "qemu/timer.h"
31+
#include "qemu/error-report.h"
3132
#include "hw/timer/i8254.h"
3233
#include "migration/vmstate.h"
3334
#include "hw/audio/pcspk.h"
@@ -112,11 +113,15 @@ static void pcspk_callback(void *opaque, int free)
112113
}
113114
}
114115

115-
static int pcspk_audio_init(ISABus *bus)
116+
static int pcspk_audio_init(PCSpkState *s)
116117
{
117-
PCSpkState *s = pcspk_state;
118118
struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUDIO_FORMAT_U8, 0};
119119

120+
if (s->voice) {
121+
/* already initialized */
122+
return 0;
123+
}
124+
120125
AUD_register_card(s_spk, &s->card);
121126

122127
s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
@@ -185,6 +190,10 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
185190

186191
isa_register_ioport(isadev, &s->ioport, s->iobase);
187192

193+
if (s->card.state) {
194+
pcspk_audio_init(s);
195+
}
196+
188197
pcspk_state = s;
189198
}
190199

@@ -236,9 +245,18 @@ static const TypeInfo pcspk_info = {
236245
.class_init = pcspk_class_initfn,
237246
};
238247

248+
static int pcspk_audio_init_soundhw(ISABus *bus)
249+
{
250+
PCSpkState *s = pcspk_state;
251+
252+
warn_report("'-soundhw pcspk' is deprecated, "
253+
"please set a backend using '-machine pcspk-audiodev=<name>' instead");
254+
return pcspk_audio_init(s);
255+
}
256+
239257
static void pcspk_register(void)
240258
{
241259
type_register_static(&pcspk_info);
242-
isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init);
260+
isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init_soundhw);
243261
}
244262
type_init(pcspk_register)

hw/i386/pc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,8 @@ static void pc_machine_initfn(Object *obj)
18921892

18931893
pc_system_flash_create(pcms);
18941894
pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
1895+
object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
1896+
OBJECT(pcms->pcspk), "audiodev");
18951897
}
18961898

18971899
static void pc_machine_reset(MachineState *machine)

0 commit comments

Comments
 (0)