Skip to content

Commit a4fdc5d

Browse files
authored
Merge pull request #1532 from balajiv113/vz-audio
Support audio device for vz driver
2 parents 23a8a7f + 9251db2 commit a4fdc5d

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

examples/default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ firmware:
246246

247247
audio:
248248
# QEMU audiodev, e.g., "none", "coreaudio", "pa", "alsa", "oss".
249+
# VZ driver, use "vz" as device name
249250
# Choosing "none" will mute the audio output, and not play any sound.
250251
# 🟢 Builtin default: ""
251252
device: null

pkg/vz/vm_darwin.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ func createVM(driver *driver.BaseDriver) (*vz.VirtualMachine, error) {
158158
return nil, err
159159
}
160160

161+
if err = attachAudio(driver, vmConfig); err != nil {
162+
return nil, err
163+
}
164+
161165
if err = attachOtherDevices(driver, vmConfig); err != nil {
162166
return nil, err
163167
}
@@ -556,6 +560,28 @@ func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineCo
556560
return nil
557561
}
558562

563+
func attachAudio(driver *driver.BaseDriver, config *vz.VirtualMachineConfiguration) error {
564+
if *driver.Yaml.Audio.Device == "vz" {
565+
outputStream, err := vz.NewVirtioSoundDeviceHostOutputStreamConfiguration()
566+
if err != nil {
567+
return err
568+
}
569+
inputStream, err := vz.NewVirtioSoundDeviceHostInputStreamConfiguration()
570+
if err != nil {
571+
return err
572+
}
573+
soundDeviceConfiguration, err := vz.NewVirtioSoundDeviceConfiguration()
574+
if err != nil {
575+
return err
576+
}
577+
soundDeviceConfiguration.SetStreams(outputStream, inputStream)
578+
config.SetAudioDevicesVirtualMachineConfiguration([]vz.AudioDeviceConfiguration{
579+
soundDeviceConfiguration,
580+
})
581+
}
582+
return nil
583+
}
584+
559585
func attachOtherDevices(_ *driver.BaseDriver, vmConfig *vz.VirtualMachineConfiguration) error {
560586
entropyConfig, err := vz.NewVirtioEntropyDeviceConfiguration()
561587
if err != nil {

pkg/vz/vz_driver_darwin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (l *LimaVzDriver) Validate() error {
6565
"CACertificates",
6666
"Rosetta",
6767
"AdditionalDisks",
68+
"Audio",
6869
); len(unknown) > 0 {
6970
logrus.Warnf("Ignoring: vmType %s: %+v", *l.Yaml.VMType, unknown)
7071
}
@@ -96,6 +97,11 @@ func (l *LimaVzDriver) Validate() error {
9697
logrus.Warnf("Ignoring: vmType %s: networks[%d]: %+v", *l.Yaml.VMType, i, unknown)
9798
}
9899
}
100+
101+
audioDevice := *l.Yaml.Audio.Device
102+
if audioDevice != "" && audioDevice != "vz" {
103+
logrus.Warnf("field `audio.device` must be %q for VZ driver , got %q", "vz", audioDevice)
104+
}
99105
return nil
100106
}
101107

0 commit comments

Comments
 (0)