Gerd Hoffmann | cf2c183 | 2010-11-11 13:07:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 Red Hat, Inc. |
| 3 | * |
| 4 | * maintained by Gerd Hoffmann <kraxel@redhat.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 or |
| 9 | * (at your option) version 3 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
Peter Maydell | 6086a56 | 2016-01-18 17:33:52 +0000 | [diff] [blame] | 20 | #include "qemu/osdep.h" |
Paolo Bonzini | 87776ab | 2016-03-15 15:36:13 +0100 | [diff] [blame] | 21 | #include "qemu/host-utils.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 22 | #include "qemu/module.h" |
Markus Armbruster | d49b683 | 2015-03-17 18:29:20 +0100 | [diff] [blame] | 23 | #include "qemu/error-report.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 24 | #include "qemu/timer.h" |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 25 | #include "ui/qemu-spice.h" |
| 26 | |
| 27 | #define AUDIO_CAP "spice" |
| 28 | #include "audio.h" |
| 29 | #include "audio_int.h" |
| 30 | |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 31 | #if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3 |
| 32 | #define LINE_OUT_SAMPLES (480 * 4) |
| 33 | #else |
| 34 | #define LINE_OUT_SAMPLES (256 * 4) |
| 35 | #endif |
| 36 | |
| 37 | #if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3 |
| 38 | #define LINE_IN_SAMPLES (480 * 4) |
| 39 | #else |
| 40 | #define LINE_IN_SAMPLES (256 * 4) |
| 41 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 42 | |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 43 | typedef struct SpiceVoiceOut { |
| 44 | HWVoiceOut hw; |
| 45 | SpicePlaybackInstance sin; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 46 | RateCtl rate; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 47 | int active; |
| 48 | uint32_t *frame; |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 49 | uint32_t fpos; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 50 | uint32_t fsize; |
| 51 | } SpiceVoiceOut; |
| 52 | |
| 53 | typedef struct SpiceVoiceIn { |
| 54 | HWVoiceIn hw; |
| 55 | SpiceRecordInstance sin; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 56 | RateCtl rate; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 57 | int active; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 58 | } SpiceVoiceIn; |
| 59 | |
| 60 | static const SpicePlaybackInterface playback_sif = { |
| 61 | .base.type = SPICE_INTERFACE_PLAYBACK, |
| 62 | .base.description = "playback", |
| 63 | .base.major_version = SPICE_INTERFACE_PLAYBACK_MAJOR, |
| 64 | .base.minor_version = SPICE_INTERFACE_PLAYBACK_MINOR, |
| 65 | }; |
| 66 | |
| 67 | static const SpiceRecordInterface record_sif = { |
| 68 | .base.type = SPICE_INTERFACE_RECORD, |
| 69 | .base.description = "record", |
| 70 | .base.major_version = SPICE_INTERFACE_RECORD_MAJOR, |
| 71 | .base.minor_version = SPICE_INTERFACE_RECORD_MINOR, |
| 72 | }; |
| 73 | |
Kővágó, Zoltán | 7183022 | 2019-03-08 23:34:15 +0100 | [diff] [blame] | 74 | static void *spice_audio_init(Audiodev *dev) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 75 | { |
| 76 | if (!using_spice) { |
| 77 | return NULL; |
| 78 | } |
| 79 | return &spice_audio_init; |
| 80 | } |
| 81 | |
| 82 | static void spice_audio_fini (void *opaque) |
| 83 | { |
| 84 | /* nothing */ |
| 85 | } |
| 86 | |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 87 | /* playback */ |
| 88 | |
Kővágó, Zoltán | 5706db1 | 2015-06-03 23:03:47 +0200 | [diff] [blame] | 89 | static int line_out_init(HWVoiceOut *hw, struct audsettings *as, |
| 90 | void *drv_opaque) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 91 | { |
| 92 | SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); |
| 93 | struct audsettings settings; |
| 94 | |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 95 | #if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3 |
| 96 | settings.freq = spice_server_get_best_playback_rate(NULL); |
| 97 | #else |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 98 | settings.freq = SPICE_INTERFACE_PLAYBACK_FREQ; |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 99 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 100 | settings.nchannels = SPICE_INTERFACE_PLAYBACK_CHAN; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 101 | settings.fmt = AUDIO_FORMAT_S16; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 102 | settings.endianness = AUDIO_HOST_ENDIANNESS; |
| 103 | |
| 104 | audio_pcm_init_info (&hw->info, &settings); |
| 105 | hw->samples = LINE_OUT_SAMPLES; |
| 106 | out->active = 0; |
| 107 | |
| 108 | out->sin.base.sif = &playback_sif.base; |
Gerd Hoffmann | 05b5363 | 2020-10-19 09:52:15 +0200 | [diff] [blame] | 109 | qemu_spice.add_interface(&out->sin.base); |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 110 | #if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3 |
| 111 | spice_server_set_playback_rate(&out->sin, settings.freq); |
| 112 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static void line_out_fini (HWVoiceOut *hw) |
| 117 | { |
| 118 | SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); |
| 119 | |
| 120 | spice_server_remove_interface (&out->sin.base); |
| 121 | } |
| 122 | |
Volker Rümelin | 9032005 | 2022-09-23 20:36:34 +0200 | [diff] [blame] | 123 | static size_t line_out_get_free(HWVoiceOut *hw) |
| 124 | { |
| 125 | SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw); |
| 126 | |
| 127 | return audio_rate_peek_bytes(&out->rate, &hw->info); |
| 128 | } |
| 129 | |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 130 | static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 131 | { |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 132 | SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 133 | |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 134 | if (!out->frame) { |
| 135 | spice_server_playback_get_buffer(&out->sin, &out->frame, &out->fsize); |
| 136 | out->fpos = 0; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 139 | if (out->frame) { |
Volker Rümelin | aec6d0d | 2020-09-20 19:17:23 +0200 | [diff] [blame] | 140 | *size = MIN((out->fsize - out->fpos) << 2, *size); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 141 | } |
Volker Rümelin | aec6d0d | 2020-09-20 19:17:23 +0200 | [diff] [blame] | 142 | |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 143 | return out->frame + out->fpos; |
| 144 | } |
| 145 | |
| 146 | static size_t line_out_put_buffer(HWVoiceOut *hw, void *buf, size_t size) |
| 147 | { |
| 148 | SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw); |
| 149 | |
Volker Rümelin | 9032005 | 2022-09-23 20:36:34 +0200 | [diff] [blame] | 150 | audio_rate_add_bytes(&out->rate, size); |
| 151 | |
Volker Rümelin | d4b70fa | 2020-09-20 19:17:21 +0200 | [diff] [blame] | 152 | if (buf) { |
| 153 | assert(buf == out->frame + out->fpos && out->fpos <= out->fsize); |
| 154 | out->fpos += size >> 2; |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 155 | |
Volker Rümelin | d4b70fa | 2020-09-20 19:17:21 +0200 | [diff] [blame] | 156 | if (out->fpos == out->fsize) { /* buffer full */ |
| 157 | spice_server_playback_put_samples(&out->sin, out->frame); |
| 158 | out->frame = NULL; |
| 159 | } |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | return size; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 165 | static void line_out_enable(HWVoiceOut *hw, bool enable) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 166 | { |
| 167 | SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); |
| 168 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 169 | if (enable) { |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 170 | if (out->active) { |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 171 | return; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 172 | } |
| 173 | out->active = 1; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 174 | audio_rate_start(&out->rate); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 175 | spice_server_playback_start (&out->sin); |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 176 | } else { |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 177 | if (!out->active) { |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 178 | return; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 179 | } |
| 180 | out->active = 0; |
| 181 | if (out->frame) { |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 182 | memset(out->frame + out->fpos, 0, (out->fsize - out->fpos) << 2); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 183 | spice_server_playback_put_samples (&out->sin, out->frame); |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 184 | out->frame = NULL; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 185 | } |
| 186 | spice_server_playback_stop (&out->sin); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 187 | } |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 190 | #if ((SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && (SPICE_INTERFACE_PLAYBACK_MINOR >= 2)) |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 191 | static void line_out_volume(HWVoiceOut *hw, Volume *vol) |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 192 | { |
| 193 | SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw); |
| 194 | uint16_t svol[2]; |
| 195 | |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 196 | assert(vol->channels == 2); |
| 197 | svol[0] = vol->vol[0] * 257; |
| 198 | svol[1] = vol->vol[1] * 257; |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 199 | spice_server_playback_set_volume(&out->sin, 2, svol); |
| 200 | spice_server_playback_set_mute(&out->sin, vol->mute); |
| 201 | } |
| 202 | #endif |
| 203 | |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 204 | /* record */ |
| 205 | |
Kővágó, Zoltán | 5706db1 | 2015-06-03 23:03:47 +0200 | [diff] [blame] | 206 | static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 207 | { |
| 208 | SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw); |
| 209 | struct audsettings settings; |
| 210 | |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 211 | #if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3 |
| 212 | settings.freq = spice_server_get_best_record_rate(NULL); |
| 213 | #else |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 214 | settings.freq = SPICE_INTERFACE_RECORD_FREQ; |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 215 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 216 | settings.nchannels = SPICE_INTERFACE_RECORD_CHAN; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 217 | settings.fmt = AUDIO_FORMAT_S16; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 218 | settings.endianness = AUDIO_HOST_ENDIANNESS; |
| 219 | |
| 220 | audio_pcm_init_info (&hw->info, &settings); |
| 221 | hw->samples = LINE_IN_SAMPLES; |
| 222 | in->active = 0; |
| 223 | |
| 224 | in->sin.base.sif = &record_sif.base; |
Gerd Hoffmann | 05b5363 | 2020-10-19 09:52:15 +0200 | [diff] [blame] | 225 | qemu_spice.add_interface(&in->sin.base); |
Jeremy White | 795ca11 | 2014-01-02 09:25:56 -0600 | [diff] [blame] | 226 | #if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3 |
| 227 | spice_server_set_record_rate(&in->sin, settings.freq); |
| 228 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static void line_in_fini (HWVoiceIn *hw) |
| 233 | { |
| 234 | SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw); |
| 235 | |
| 236 | spice_server_remove_interface (&in->sin.base); |
| 237 | } |
| 238 | |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 239 | static size_t line_in_read(HWVoiceIn *hw, void *buf, size_t len) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 240 | { |
| 241 | SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw); |
Volker Rümelin | 613fe02 | 2022-09-23 20:36:36 +0200 | [diff] [blame] | 242 | uint64_t to_read = audio_rate_get_bytes(&in->rate, &hw->info, len) >> 2; |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 243 | size_t ready = spice_server_record_get_samples(&in->sin, buf, to_read); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 244 | |
Volker Rümelin | 70ded68 | 2022-09-23 20:36:35 +0200 | [diff] [blame] | 245 | /* |
| 246 | * If the client didn't send new frames, it most likely disconnected. |
| 247 | * Generate silence in this case to avoid a stalled audio stream. |
| 248 | */ |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 249 | if (ready == 0) { |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 250 | memset(buf, 0, to_read << 2); |
| 251 | ready = to_read; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 254 | return ready << 2; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 257 | static void line_in_enable(HWVoiceIn *hw, bool enable) |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 258 | { |
| 259 | SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw); |
| 260 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 261 | if (enable) { |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 262 | if (in->active) { |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 263 | return; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 264 | } |
| 265 | in->active = 1; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 266 | audio_rate_start(&in->rate); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 267 | spice_server_record_start (&in->sin); |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 268 | } else { |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 269 | if (!in->active) { |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 270 | return; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 271 | } |
| 272 | in->active = 0; |
| 273 | spice_server_record_stop (&in->sin); |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 274 | } |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 277 | #if ((SPICE_INTERFACE_RECORD_MAJOR >= 2) && (SPICE_INTERFACE_RECORD_MINOR >= 2)) |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 278 | static void line_in_volume(HWVoiceIn *hw, Volume *vol) |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 279 | { |
| 280 | SpiceVoiceIn *in = container_of(hw, SpiceVoiceIn, hw); |
| 281 | uint16_t svol[2]; |
| 282 | |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 283 | assert(vol->channels == 2); |
| 284 | svol[0] = vol->vol[0] * 257; |
| 285 | svol[1] = vol->vol[1] * 257; |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 286 | spice_server_record_set_volume(&in->sin, 2, svol); |
| 287 | spice_server_record_set_mute(&in->sin, vol->mute); |
| 288 | } |
| 289 | #endif |
| 290 | |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 291 | static struct audio_pcm_ops audio_callbacks = { |
| 292 | .init_out = line_out_init, |
| 293 | .fini_out = line_out_fini, |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 294 | .write = audio_generic_write, |
Volker Rümelin | 9032005 | 2022-09-23 20:36:34 +0200 | [diff] [blame] | 295 | .buffer_get_free = line_out_get_free, |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 296 | .get_buffer_out = line_out_get_buffer, |
| 297 | .put_buffer_out = line_out_put_buffer, |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 298 | .enable_out = line_out_enable, |
| 299 | #if (SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && \ |
| 300 | (SPICE_INTERFACE_PLAYBACK_MINOR >= 2) |
| 301 | .volume_out = line_out_volume, |
| 302 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 303 | |
| 304 | .init_in = line_in_init, |
| 305 | .fini_in = line_in_fini, |
Kővágó, Zoltán | 8c198ff | 2019-09-19 23:24:17 +0200 | [diff] [blame] | 306 | .read = line_in_read, |
Volker Rümelin | a2893c8 | 2021-01-10 11:02:24 +0100 | [diff] [blame] | 307 | .run_buffer_in = audio_generic_run_buffer_in, |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 308 | .enable_in = line_in_enable, |
| 309 | #if ((SPICE_INTERFACE_RECORD_MAJOR >= 2) && (SPICE_INTERFACE_RECORD_MINOR >= 2)) |
| 310 | .volume_in = line_in_volume, |
| 311 | #endif |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 312 | }; |
| 313 | |
Gerd Hoffmann | d3893a3 | 2018-03-06 08:40:47 +0100 | [diff] [blame] | 314 | static struct audio_driver spice_audio_driver = { |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 315 | .name = "spice", |
| 316 | .descr = "spice audio driver", |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 317 | .init = spice_audio_init, |
| 318 | .fini = spice_audio_fini, |
| 319 | .pcm_ops = &audio_callbacks, |
| 320 | .max_voices_out = 1, |
| 321 | .max_voices_in = 1, |
| 322 | .voice_size_out = sizeof (SpiceVoiceOut), |
| 323 | .voice_size_in = sizeof (SpiceVoiceIn), |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 324 | }; |
| 325 | |
Gerd Hoffmann | d3893a3 | 2018-03-06 08:40:47 +0100 | [diff] [blame] | 326 | static void register_audio_spice(void) |
| 327 | { |
| 328 | audio_driver_register(&spice_audio_driver); |
| 329 | } |
| 330 | type_init(register_audio_spice); |
Gerd Hoffmann | f6b12df | 2021-06-24 12:38:10 +0200 | [diff] [blame] | 331 | |
| 332 | module_dep("ui-spice-core"); |