1 | /*
|
---|
2 | * QEMU Audio subsystem header
|
---|
3 | *
|
---|
4 | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
---|
5 | *
|
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
7 | * of this software and associated documentation files (the "Software"), to deal
|
---|
8 | * in the Software without restriction, including without limitation the rights
|
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
10 | * copies of the Software, and to permit persons to whom the Software is
|
---|
11 | * furnished to do so, subject to the following conditions:
|
---|
12 | *
|
---|
13 | * The above copyright notice and this permission notice shall be included in
|
---|
14 | * all copies or substantial portions of the Software.
|
---|
15 | *
|
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
---|
22 | * THE SOFTWARE.
|
---|
23 | */
|
---|
24 | #ifndef QEMU_AUDIO_H
|
---|
25 | #define QEMU_AUDIO_H
|
---|
26 |
|
---|
27 | #include "sys-queue.h"
|
---|
28 |
|
---|
29 | #if defined __STDC_VERSION__ && __STDC_VERSION__ > 199901L
|
---|
30 | #define FMTZ "z"
|
---|
31 | #else
|
---|
32 | #define FMTZ
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | typedef void (*audio_callback_fn_t) (void *opaque, int avail);
|
---|
36 |
|
---|
37 | typedef enum {
|
---|
38 | AUD_FMT_U8,
|
---|
39 | AUD_FMT_S8,
|
---|
40 | AUD_FMT_U16,
|
---|
41 | AUD_FMT_S16,
|
---|
42 | AUD_FMT_U32,
|
---|
43 | AUD_FMT_S32
|
---|
44 | } audfmt_e;
|
---|
45 |
|
---|
46 | #define AUDIO_HOST_ENDIANNESS 0
|
---|
47 |
|
---|
48 | typedef struct {
|
---|
49 | int freq;
|
---|
50 | int nchannels;
|
---|
51 | audfmt_e fmt;
|
---|
52 | int endianness;
|
---|
53 | } audsettings_t;
|
---|
54 |
|
---|
55 | typedef enum {
|
---|
56 | AUD_CNOTIFY_ENABLE,
|
---|
57 | AUD_CNOTIFY_DISABLE
|
---|
58 | } audcnotification_e;
|
---|
59 |
|
---|
60 | typedef enum
|
---|
61 | {
|
---|
62 | AUD_MIXER_VOLUME,
|
---|
63 | AUD_MIXER_PCM,
|
---|
64 | AUD_MIXER_LINE_IN
|
---|
65 | } audmixerctl_t;
|
---|
66 |
|
---|
67 | typedef enum
|
---|
68 | {
|
---|
69 | AUD_REC_MIC,
|
---|
70 | AUD_REC_CD,
|
---|
71 | AUD_REC_VIDEO,
|
---|
72 | AUD_REC_AUX,
|
---|
73 | AUD_REC_LINE_IN,
|
---|
74 | AUD_REC_PHONE
|
---|
75 | } audrecsource_t;
|
---|
76 |
|
---|
77 | struct audio_capture_ops {
|
---|
78 | void (*notify) (void *opaque, audcnotification_e cmd);
|
---|
79 | void (*capture) (void *opaque, void *buf, int size);
|
---|
80 | void (*destroy) (void *opaque);
|
---|
81 | };
|
---|
82 |
|
---|
83 | struct capture_ops {
|
---|
84 | void (*info) (void *opaque);
|
---|
85 | void (*destroy) (void *opaque);
|
---|
86 | };
|
---|
87 |
|
---|
88 | typedef struct CaptureState {
|
---|
89 | void *opaque;
|
---|
90 | struct capture_ops ops;
|
---|
91 | LIST_ENTRY (CaptureState) entries;
|
---|
92 | } CaptureState;
|
---|
93 |
|
---|
94 | typedef struct AudioState AudioState;
|
---|
95 | typedef struct SWVoiceOut SWVoiceOut;
|
---|
96 | typedef struct CaptureVoiceOut CaptureVoiceOut;
|
---|
97 | typedef struct SWVoiceIn SWVoiceIn;
|
---|
98 |
|
---|
99 | typedef struct QEMUSoundCard {
|
---|
100 | AudioState *audio;
|
---|
101 | char *name;
|
---|
102 | LIST_ENTRY (QEMUSoundCard) entries;
|
---|
103 | } QEMUSoundCard;
|
---|
104 |
|
---|
105 | typedef struct QEMUAudioTimeStamp {
|
---|
106 | uint64_t old_ts;
|
---|
107 | } QEMUAudioTimeStamp;
|
---|
108 |
|
---|
109 | void AUD_vlog (const char *cap, const char *fmt, va_list ap);
|
---|
110 | void AUD_log (const char *cap, const char *fmt, ...)
|
---|
111 | #if defined (__GNUC__) && !defined (VBOX) /* VBox: oh, please, shut up. */
|
---|
112 | __attribute__ ((__format__ (__printf__, 2, 3)))
|
---|
113 | #endif
|
---|
114 | ;
|
---|
115 |
|
---|
116 | void AUD_register_card (const char *name, QEMUSoundCard *card);
|
---|
117 | void AUD_remove_card (QEMUSoundCard *card);
|
---|
118 |
|
---|
119 | CaptureVoiceOut *AUD_add_capture (
|
---|
120 | AudioState *s,
|
---|
121 | audsettings_t *as,
|
---|
122 | struct audio_capture_ops *ops,
|
---|
123 | void *opaque
|
---|
124 | );
|
---|
125 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
|
---|
126 |
|
---|
127 | SWVoiceOut *AUD_open_out (
|
---|
128 | QEMUSoundCard *card,
|
---|
129 | SWVoiceOut *sw,
|
---|
130 | const char *name,
|
---|
131 | void *callback_opaque,
|
---|
132 | audio_callback_fn_t callback_fn,
|
---|
133 | audsettings_t *settings
|
---|
134 | );
|
---|
135 |
|
---|
136 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
---|
137 | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
|
---|
138 | int AUD_get_buffer_size_out (SWVoiceOut *sw);
|
---|
139 | void AUD_set_active_out (SWVoiceOut *sw, int on);
|
---|
140 | int AUD_is_active_out (SWVoiceOut *sw);
|
---|
141 |
|
---|
142 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
---|
143 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
---|
144 |
|
---|
145 | SWVoiceIn *AUD_open_in (
|
---|
146 | QEMUSoundCard *card,
|
---|
147 | SWVoiceIn *sw,
|
---|
148 | const char *name,
|
---|
149 | void *callback_opaque,
|
---|
150 | audio_callback_fn_t callback_fn,
|
---|
151 | audsettings_t *settings
|
---|
152 | );
|
---|
153 |
|
---|
154 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
---|
155 | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
|
---|
156 | void AUD_set_active_in (SWVoiceIn *sw, int on);
|
---|
157 | int AUD_is_active_in (SWVoiceIn *sw);
|
---|
158 |
|
---|
159 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
---|
160 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
---|
161 |
|
---|
162 | void AUD_set_volume_out (SWVoiceOut *po, int mute, uint8_t lvol, uint8_t rvol);
|
---|
163 | void AUD_set_volume (audmixerctl_t mt, int *mute, uint8_t *lvol, uint8_t *rvol);
|
---|
164 | void AUD_set_record_source (audrecsource_t *ars, audrecsource_t *als);
|
---|
165 |
|
---|
166 | int AUD_init_null(void);
|
---|
167 |
|
---|
168 | static inline void *advance (void *p, int incr)
|
---|
169 | {
|
---|
170 | #ifndef VBOX
|
---|
171 | uint8_t *d = p;
|
---|
172 | #else
|
---|
173 | uint8_t *d = (uint8_t*)p;
|
---|
174 | #endif
|
---|
175 | return (d + incr);
|
---|
176 | }
|
---|
177 |
|
---|
178 | uint32_t popcount (uint32_t u);
|
---|
179 | uint32_t lsbindex (uint32_t u);
|
---|
180 |
|
---|
181 | #ifdef __GNUC__
|
---|
182 | #define audio_MIN(a, b) ( __extension__ ({ \
|
---|
183 | __typeof (a) ta = a; \
|
---|
184 | __typeof (b) tb = b; \
|
---|
185 | ((ta)>(tb)?(tb):(ta)); \
|
---|
186 | }))
|
---|
187 |
|
---|
188 | #define audio_MAX(a, b) ( __extension__ ({ \
|
---|
189 | __typeof (a) ta = a; \
|
---|
190 | __typeof (b) tb = b; \
|
---|
191 | ((ta)<(tb)?(tb):(ta)); \
|
---|
192 | }))
|
---|
193 | #else
|
---|
194 | #define audio_MIN(a, b) ((a)>(b)?(b):(a))
|
---|
195 | #define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
---|
196 | #endif
|
---|
197 |
|
---|
198 | #ifdef VBOX
|
---|
199 | const char *audio_get_stream_name(void);
|
---|
200 | #endif
|
---|
201 |
|
---|
202 | int AUD_is_host_voice_in_ok(SWVoiceIn *hw);
|
---|
203 | int AUD_is_host_voice_out_ok(SWVoiceOut *hw);
|
---|
204 |
|
---|
205 | #endif /* audio.h */
|
---|