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 | } audfmt_e;
|
---|
43 |
|
---|
44 | #define AUDIO_HOST_ENDIANNESS 0
|
---|
45 |
|
---|
46 | typedef struct {
|
---|
47 | int freq;
|
---|
48 | int nchannels;
|
---|
49 | audfmt_e fmt;
|
---|
50 | int endianness;
|
---|
51 | } audsettings_t;
|
---|
52 |
|
---|
53 | typedef enum {
|
---|
54 | AUD_CNOTIFY_ENABLE,
|
---|
55 | AUD_CNOTIFY_DISABLE
|
---|
56 | } audcnotification_e;
|
---|
57 |
|
---|
58 | typedef enum
|
---|
59 | {
|
---|
60 | AUD_MIXER_VOLUME,
|
---|
61 | AUD_MIXER_PCM,
|
---|
62 | AUD_MIXER_LINE_IN
|
---|
63 | } audmixerctl_t;
|
---|
64 |
|
---|
65 | typedef enum
|
---|
66 | {
|
---|
67 | AUD_REC_MIC,
|
---|
68 | AUD_REC_CD,
|
---|
69 | AUD_REC_VIDEO,
|
---|
70 | AUD_REC_AUX,
|
---|
71 | AUD_REC_LINE_IN,
|
---|
72 | AUD_REC_PHONE
|
---|
73 | } audrecsource_t;
|
---|
74 |
|
---|
75 | struct audio_capture_ops {
|
---|
76 | void (*notify) (void *opaque, audcnotification_e cmd);
|
---|
77 | void (*capture) (void *opaque, void *buf, int size);
|
---|
78 | void (*destroy) (void *opaque);
|
---|
79 | };
|
---|
80 |
|
---|
81 | struct capture_ops {
|
---|
82 | void (*info) (void *opaque);
|
---|
83 | void (*destroy) (void *opaque);
|
---|
84 | };
|
---|
85 |
|
---|
86 | typedef struct CaptureState {
|
---|
87 | void *opaque;
|
---|
88 | struct capture_ops ops;
|
---|
89 | LIST_ENTRY (CaptureState) entries;
|
---|
90 | } CaptureState;
|
---|
91 |
|
---|
92 | typedef struct AudioState AudioState;
|
---|
93 | typedef struct SWVoiceOut SWVoiceOut;
|
---|
94 | typedef struct CaptureVoiceOut CaptureVoiceOut;
|
---|
95 | typedef struct SWVoiceIn SWVoiceIn;
|
---|
96 |
|
---|
97 | typedef struct QEMUSoundCard {
|
---|
98 | AudioState *audio;
|
---|
99 | char *name;
|
---|
100 | LIST_ENTRY (QEMUSoundCard) entries;
|
---|
101 | } QEMUSoundCard;
|
---|
102 |
|
---|
103 | typedef struct QEMUAudioTimeStamp {
|
---|
104 | uint64_t old_ts;
|
---|
105 | } QEMUAudioTimeStamp;
|
---|
106 |
|
---|
107 | void AUD_vlog (const char *cap, const char *fmt, va_list ap);
|
---|
108 | void AUD_log (const char *cap, const char *fmt, ...)
|
---|
109 | #if defined (__GNUC__) && !defined (VBOX) /* VBox: oh, please, shut up. */
|
---|
110 | __attribute__ ((__format__ (__printf__, 2, 3)))
|
---|
111 | #endif
|
---|
112 | ;
|
---|
113 |
|
---|
114 | void AUD_register_card (const char *name, QEMUSoundCard *card);
|
---|
115 | void AUD_remove_card (QEMUSoundCard *card);
|
---|
116 |
|
---|
117 | CaptureVoiceOut *AUD_add_capture (
|
---|
118 | AudioState *s,
|
---|
119 | audsettings_t *as,
|
---|
120 | struct audio_capture_ops *ops,
|
---|
121 | void *opaque
|
---|
122 | );
|
---|
123 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
|
---|
124 |
|
---|
125 | SWVoiceOut *AUD_open_out (
|
---|
126 | QEMUSoundCard *card,
|
---|
127 | SWVoiceOut *sw,
|
---|
128 | const char *name,
|
---|
129 | void *callback_opaque,
|
---|
130 | audio_callback_fn_t callback_fn,
|
---|
131 | audsettings_t *settings
|
---|
132 | );
|
---|
133 |
|
---|
134 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
---|
135 | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
|
---|
136 | int AUD_get_buffer_size_out (SWVoiceOut *sw);
|
---|
137 | void AUD_set_active_out (SWVoiceOut *sw, int on);
|
---|
138 | int AUD_is_active_out (SWVoiceOut *sw);
|
---|
139 |
|
---|
140 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
---|
141 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
---|
142 |
|
---|
143 | SWVoiceIn *AUD_open_in (
|
---|
144 | QEMUSoundCard *card,
|
---|
145 | SWVoiceIn *sw,
|
---|
146 | const char *name,
|
---|
147 | void *callback_opaque,
|
---|
148 | audio_callback_fn_t callback_fn,
|
---|
149 | audsettings_t *settings
|
---|
150 | );
|
---|
151 |
|
---|
152 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
---|
153 | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
|
---|
154 | void AUD_set_active_in (SWVoiceIn *sw, int on);
|
---|
155 | int AUD_is_active_in (SWVoiceIn *sw);
|
---|
156 |
|
---|
157 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
---|
158 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
---|
159 |
|
---|
160 | void AUD_set_volume_out (SWVoiceOut *po, int mute, uint8_t lvol, uint8_t rvol);
|
---|
161 | void AUD_set_volume (audmixerctl_t mt, int *mute, uint8_t *lvol, uint8_t *rvol);
|
---|
162 | void AUD_set_record_source (audrecsource_t *ars, audrecsource_t *als);
|
---|
163 |
|
---|
164 | static inline void *advance (void *p, int incr)
|
---|
165 | {
|
---|
166 | #ifndef VBOX
|
---|
167 | uint8_t *d = p;
|
---|
168 | #else
|
---|
169 | uint8_t *d = (uint8_t*)p;
|
---|
170 | #endif
|
---|
171 | return (d + incr);
|
---|
172 | }
|
---|
173 |
|
---|
174 | uint32_t popcount (uint32_t u);
|
---|
175 | uint32_t lsbindex (uint32_t u);
|
---|
176 |
|
---|
177 | #ifdef __GNUC__
|
---|
178 | #define audio_MIN(a, b) ( __extension__ ({ \
|
---|
179 | __typeof (a) ta = a; \
|
---|
180 | __typeof (b) tb = b; \
|
---|
181 | ((ta)>(tb)?(tb):(ta)); \
|
---|
182 | }))
|
---|
183 |
|
---|
184 | #define audio_MAX(a, b) ( __extension__ ({ \
|
---|
185 | __typeof (a) ta = a; \
|
---|
186 | __typeof (b) tb = b; \
|
---|
187 | ((ta)<(tb)?(tb):(ta)); \
|
---|
188 | }))
|
---|
189 | #else
|
---|
190 | #define audio_MIN(a, b) ((a)>(b)?(b):(a))
|
---|
191 | #define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | #endif /* audio.h */
|
---|