-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
audio.go
141 lines (119 loc) · 4.61 KB
/
audio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package vz
/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization_11.h"
# include "virtualization_12.h"
*/
import "C"
import (
"github.com/Code-Hex/vz/v3/internal/objc"
)
// AudioDeviceConfiguration interface for an audio device configuration.
type AudioDeviceConfiguration interface {
objc.NSObject
audioDeviceConfiguration()
}
type baseAudioDeviceConfiguration struct{}
func (*baseAudioDeviceConfiguration) audioDeviceConfiguration() {}
// VirtioSoundDeviceConfiguration is a struct that defines a Virtio sound device configuration.
//
// Use a VirtioSoundDeviceConfiguration to configure an audio device for your VM. After creating
// this struct, assign appropriate values via the SetStreams method which defines the behaviors of
// the underlying audio streams for this audio device.
//
// After creating and configuring a VirtioSoundDeviceConfiguration struct, assign it to the
// SetAudioDevicesVirtualMachineConfiguration method of your VM’s configuration.
type VirtioSoundDeviceConfiguration struct {
*pointer
*baseAudioDeviceConfiguration
}
var _ AudioDeviceConfiguration = (*VirtioSoundDeviceConfiguration)(nil)
// NewVirtioSoundDeviceConfiguration creates a new sound device configuration.
//
// This is only supported on macOS 12 and newer, error will be returned
// on older versions.
func NewVirtioSoundDeviceConfiguration() (*VirtioSoundDeviceConfiguration, error) {
if err := macOSAvailable(12); err != nil {
return nil, err
}
config := &VirtioSoundDeviceConfiguration{
pointer: objc.NewPointer(
C.newVZVirtioSoundDeviceConfiguration(),
),
}
objc.SetFinalizer(config, func(self *VirtioSoundDeviceConfiguration) {
objc.Release(self)
})
return config, nil
}
// SetStreams sets the list of audio streams exposed by this device.
func (v *VirtioSoundDeviceConfiguration) SetStreams(streams ...VirtioSoundDeviceStreamConfiguration) {
ptrs := make([]objc.NSObject, len(streams))
for i, val := range streams {
ptrs[i] = val
}
array := objc.ConvertToNSMutableArray(ptrs)
C.setStreamsVZVirtioSoundDeviceConfiguration(
objc.Ptr(v), objc.Ptr(array),
)
}
// VirtioSoundDeviceStreamConfiguration interface for Virtio Sound Device Stream Configuration.
type VirtioSoundDeviceStreamConfiguration interface {
objc.NSObject
virtioSoundDeviceStreamConfiguration()
}
type baseVirtioSoundDeviceStreamConfiguration struct{}
func (*baseVirtioSoundDeviceStreamConfiguration) virtioSoundDeviceStreamConfiguration() {}
// VirtioSoundDeviceHostInputStreamConfiguration is a PCM stream of input audio data,
// such as from a microphone via host.
type VirtioSoundDeviceHostInputStreamConfiguration struct {
*pointer
*baseVirtioSoundDeviceStreamConfiguration
}
var _ VirtioSoundDeviceStreamConfiguration = (*VirtioSoundDeviceHostInputStreamConfiguration)(nil)
// NewVirtioSoundDeviceHostInputStreamConfiguration creates a new PCM stream configuration of input audio data from host.
//
// This is only supported on macOS 12 and newer, error will be returned
// on older versions.
func NewVirtioSoundDeviceHostInputStreamConfiguration() (*VirtioSoundDeviceHostInputStreamConfiguration, error) {
if err := macOSAvailable(12); err != nil {
return nil, err
}
config := &VirtioSoundDeviceHostInputStreamConfiguration{
pointer: objc.NewPointer(
C.newVZVirtioSoundDeviceHostInputStreamConfiguration(),
),
}
objc.SetFinalizer(config, func(self *VirtioSoundDeviceHostInputStreamConfiguration) {
objc.Release(self)
})
return config, nil
}
// VirtioSoundDeviceHostOutputStreamConfiguration is a struct that
// defines a Virtio host sound device output stream configuration.
//
// A PCM stream of output audio data, such as to a speaker from host.
type VirtioSoundDeviceHostOutputStreamConfiguration struct {
*pointer
*baseVirtioSoundDeviceStreamConfiguration
}
var _ VirtioSoundDeviceStreamConfiguration = (*VirtioSoundDeviceHostOutputStreamConfiguration)(nil)
// NewVirtioSoundDeviceHostOutputStreamConfiguration creates a new sounds device output stream configuration.
//
// This is only supported on macOS 12 and newer, error will be returned
// on older versions.
func NewVirtioSoundDeviceHostOutputStreamConfiguration() (*VirtioSoundDeviceHostOutputStreamConfiguration, error) {
if err := macOSAvailable(12); err != nil {
return nil, err
}
config := &VirtioSoundDeviceHostOutputStreamConfiguration{
pointer: objc.NewPointer(
C.newVZVirtioSoundDeviceHostOutputStreamConfiguration(),
),
}
objc.SetFinalizer(config, func(self *VirtioSoundDeviceHostOutputStreamConfiguration) {
objc.Release(self)
})
return config, nil
}