master
c 773 lines 19.9 KB
Raw
1 /*
2 * QEMU OSS audio driver
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
25 #include "qemu/osdep.h"
26 #include "qapi-types-audio.h"
27 #include <sys/ioctl.h>
28 #include <sys/soundcard.h>
29 #include "qemu/main-loop.h"
30 #include "qemu/module.h"
31 #include "qemu/host-utils.h"
32 #include "qapi/error.h"
33 #include "qemu/audio.h"
34 #include "qemu/error-report.h"
35 #include "qom/object.h"
36 #include "audio_int.h"
37 #include "trace.h"
38
39 #define TYPE_AUDIO_OSS "audio-oss"
40 OBJECT_DECLARE_SIMPLE_TYPE(AudioOss, AUDIO_OSS)
41
42 static AudioBackendClass *audio_oss_parent_class;
43
44 struct AudioOss {
45 AudioMixengBackend parent_obj;
46 };
47
48
49 #if defined OSS_GETVERSION && defined SNDCTL_DSP_POLICY
50 #define USE_DSP_POLICY
51 #endif
52
53 typedef struct OSSVoiceOut {
54 HWVoiceOut hw;
55 int fd;
56 int nfrags;
57 int fragsize;
58 int mmapped;
59 Audiodev *dev;
60 } OSSVoiceOut;
61
62 typedef struct OSSVoiceIn {
63 HWVoiceIn hw;
64 int fd;
65 int nfrags;
66 int fragsize;
67 Audiodev *dev;
68 } OSSVoiceIn;
69
70 struct oss_params {
71 int freq;
72 int fmt;
73 int nchannels;
74 int nfrags;
75 int fragsize;
76 };
77
78 static void G_GNUC_PRINTF(2, 3) oss_logerr(int err, const char *fmt, ...)
79 {
80 va_list ap;
81
82 error_printf("oss: ");
83 va_start(ap, fmt);
84 error_vprintf(fmt, ap);
85 va_end(ap);
86
87 error_printf(" Reason: %s\n", strerror(err));
88 }
89
90 static void G_GNUC_PRINTF(3, 4) oss_logerr2(int err, const char *typ,
91 const char *fmt, ...)
92 {
93 va_list ap;
94
95 error_printf("oss: Could not initialize %s: ", typ);
96
97 va_start(ap, fmt);
98 error_vprintf(fmt, ap);
99 va_end(ap);
100
101 error_printf(" Reason: %s\n", strerror(err));
102 }
103
104 static void oss_anal_close(int *fdp)
105 {
106 int err;
107
108 qemu_set_fd_handler(*fdp, NULL, NULL, NULL);
109 err = close(*fdp);
110 if (err) {
111 oss_logerr(errno, "Failed to close file(fd=%d)", *fdp);
112 }
113 *fdp = -1;
114 }
115
116 static void oss_helper_poll_out (void *opaque)
117 {
118 AudioMixengBackend *s = opaque;
119 audio_run(s, "oss_poll_out");
120 }
121
122 static void oss_helper_poll_in (void *opaque)
123 {
124 AudioMixengBackend *s = opaque;
125 audio_run(s, "oss_poll_in");
126 }
127
128 static void oss_poll_out (HWVoiceOut *hw)
129 {
130 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
131
132 qemu_set_fd_handler(oss->fd, NULL, oss_helper_poll_out, hw->s);
133 }
134
135 static void oss_poll_in (HWVoiceIn *hw)
136 {
137 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
138
139 qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
140 }
141
142 static int aud_to_ossfmt(AudioFormat fmt, bool big_endian)
143 {
144 switch (fmt) {
145 case AUDIO_FORMAT_S8:
146 return AFMT_S8;
147
148 case AUDIO_FORMAT_U8:
149 return AFMT_U8;
150
151 case AUDIO_FORMAT_S16:
152 return big_endian ? AFMT_S16_BE : AFMT_S16_LE;
153
154 case AUDIO_FORMAT_U16:
155 return big_endian ? AFMT_U16_BE : AFMT_U16_LE;
156
157 default:
158 error_report("oss: Internal logic error: Bad audio format %d", fmt);
159 return AFMT_U8;
160 }
161 }
162
163 static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, bool *big_endian)
164 {
165 switch (ossfmt) {
166 case AFMT_S8:
167 *big_endian = false;
168 *fmt = AUDIO_FORMAT_S8;
169 break;
170
171 case AFMT_U8:
172 *big_endian = false;
173 *fmt = AUDIO_FORMAT_U8;
174 break;
175
176 case AFMT_S16_LE:
177 *big_endian = false;
178 *fmt = AUDIO_FORMAT_S16;
179 break;
180
181 case AFMT_U16_LE:
182 *big_endian = false;
183 *fmt = AUDIO_FORMAT_U16;
184 break;
185
186 case AFMT_S16_BE:
187 *big_endian = true;
188 *fmt = AUDIO_FORMAT_S16;
189 break;
190
191 case AFMT_U16_BE:
192 *big_endian = true;
193 *fmt = AUDIO_FORMAT_U16;
194 break;
195
196 default:
197 error_report("oss: Unrecognized audio format %d", ossfmt);
198 return -1;
199 }
200
201 return 0;
202 }
203
204 #ifdef USE_DSP_POLICY
205 static int oss_get_version (int fd, int *version, const char *typ)
206 {
207 if (ioctl (fd, OSS_GETVERSION, &version)) {
208 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
209 /*
210 * Looks like atm (20100109) FreeBSD knows OSS_GETVERSION
211 * since 7.x, but currently only on the mixer device (or in
212 * the Linuxolator), and in the native version that part of
213 * the code is in fact never reached so the ioctl fails anyway.
214 * Until this is fixed, just check the errno and if its what
215 * FreeBSD's sound drivers return atm assume they are new enough.
216 */
217 if (errno == EINVAL) {
218 *version = 0x040000;
219 return 0;
220 }
221 #endif
222 oss_logerr2(errno, typ, "Failed to get OSS version");
223 return -1;
224 }
225 return 0;
226 }
227 #endif
228
229 static int oss_open(int in, struct oss_params *req, audsettings *as,
230 struct oss_params *obt, int *pfd, Audiodev *dev)
231 {
232 AudiodevOssOptions *oopts = &dev->u.oss;
233 AudiodevOssPerDirectionOptions *opdo = in ? oopts->in : oopts->out;
234 int fd;
235 int oflags = (oopts->has_exclusive && oopts->exclusive) ? O_EXCL : 0;
236 audio_buf_info abinfo;
237 int fmt, freq, nchannels;
238 int setfragment = 1;
239 const char *dspname = opdo->dev ?: "/dev/dsp";
240 const char *typ = in ? "ADC" : "DAC";
241 #ifdef USE_DSP_POLICY
242 int policy = oopts->has_dsp_policy ? oopts->dsp_policy : 5;
243 #endif
244
245 /* Kludge needed to have working mmap on Linux */
246 oflags |= (oopts->has_try_mmap && oopts->try_mmap) ?
247 O_RDWR : (in ? O_RDONLY : O_WRONLY);
248
249 fd = open (dspname, oflags | O_NONBLOCK);
250 if (-1 == fd) {
251 oss_logerr2(errno, typ, "Failed to open '%s'", dspname);
252 return -1;
253 }
254
255 freq = req->freq;
256 nchannels = req->nchannels;
257 fmt = req->fmt;
258 req->nfrags = opdo->has_buffer_count ? opdo->buffer_count : 4;
259 req->fragsize = audio_buffer_bytes(
260 qapi_AudiodevOssPerDirectionOptions_base(opdo), as, 23220);
261
262 if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
263 oss_logerr2(errno, typ, "Failed to set sample size %d", req->fmt);
264 goto err;
265 }
266
267 if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
268 oss_logerr2(errno, typ, "Failed to set number of channels %d",
269 req->nchannels);
270 goto err;
271 }
272
273 if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
274 oss_logerr2(errno, typ, "Failed to set frequency %d", req->freq);
275 goto err;
276 }
277
278 if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
279 oss_logerr2(errno, typ, "Failed to set non-blocking mode");
280 goto err;
281 }
282
283 #ifdef USE_DSP_POLICY
284 if (policy >= 0) {
285 int version;
286
287 if (!oss_get_version (fd, &version, typ)) {
288 trace_oss_version(version);
289
290 if (version >= 0x040000) {
291 int policy2 = policy;
292 if (ioctl(fd, SNDCTL_DSP_POLICY, &policy2)) {
293 oss_logerr2(errno, typ,
294 "Failed to set timing policy to %d",
295 policy);
296 goto err;
297 }
298 setfragment = 0;
299 }
300 }
301 }
302 #endif
303
304 if (setfragment) {
305 int mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
306 if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
307 oss_logerr2(errno, typ, "Failed to set buffer length (%d, %d)",
308 req->nfrags, req->fragsize);
309 goto err;
310 }
311 }
312
313 if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
314 oss_logerr2(errno, typ, "Failed to get buffer length");
315 goto err;
316 }
317
318 if (!abinfo.fragstotal || !abinfo.fragsize) {
319 error_report("oss: Returned bogus buffer information(%d, %d) for %s",
320 abinfo.fragstotal, abinfo.fragsize, typ);
321 goto err;
322 }
323
324 obt->fmt = fmt;
325 obt->nchannels = nchannels;
326 obt->freq = freq;
327 obt->nfrags = abinfo.fragstotal;
328 obt->fragsize = abinfo.fragsize;
329 *pfd = fd;
330
331 trace_oss_out_params(
332 req->fmt, obt->fmt,
333 req->nchannels, obt->nchannels,
334 req->freq, obt->freq,
335 req->nfrags, obt->nfrags,
336 req->fragsize, obt->fragsize);
337
338 return 0;
339
340 err:
341 oss_anal_close (&fd);
342 return -1;
343 }
344
345 static size_t oss_get_available_bytes(OSSVoiceOut *oss)
346 {
347 int err;
348 struct count_info cntinfo;
349 assert(oss->mmapped);
350
351 err = ioctl(oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);
352 if (err < 0) {
353 oss_logerr(errno, "SNDCTL_DSP_GETOPTR failed");
354 return 0;
355 }
356
357 return audio_ring_dist(cntinfo.ptr, oss->hw.pos_emul, oss->hw.size_emul);
358 }
359
360 static void oss_run_buffer_out(HWVoiceOut *hw)
361 {
362 OSSVoiceOut *oss = (OSSVoiceOut *)hw;
363
364 if (!oss->mmapped) {
365 audio_generic_run_buffer_out(hw);
366 }
367 }
368
369 static size_t oss_buffer_get_free(HWVoiceOut *hw)
370 {
371 OSSVoiceOut *oss = (OSSVoiceOut *)hw;
372
373 if (oss->mmapped) {
374 return oss_get_available_bytes(oss);
375 } else {
376 return audio_generic_buffer_get_free(hw);
377 }
378 }
379
380 static void *oss_get_buffer_out(HWVoiceOut *hw, size_t *size)
381 {
382 OSSVoiceOut *oss = (OSSVoiceOut *)hw;
383
384 if (oss->mmapped) {
385 *size = hw->size_emul - hw->pos_emul;
386 return hw->buf_emul + hw->pos_emul;
387 } else {
388 return audio_generic_get_buffer_out(hw, size);
389 }
390 }
391
392 static size_t oss_put_buffer_out(HWVoiceOut *hw, void *buf, size_t size)
393 {
394 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
395 if (oss->mmapped) {
396 assert(buf == hw->buf_emul + hw->pos_emul && size < hw->size_emul);
397
398 hw->pos_emul = (hw->pos_emul + size) % hw->size_emul;
399 return size;
400 } else {
401 return audio_generic_put_buffer_out(hw, buf, size);
402 }
403 }
404
405 static size_t oss_write(HWVoiceOut *hw, void *buf, size_t len)
406 {
407 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
408 size_t pos;
409
410 if (oss->mmapped) {
411 size_t total_len;
412 len = MIN(len, oss_get_available_bytes(oss));
413
414 total_len = len;
415 while (len) {
416 size_t to_copy = MIN(len, hw->size_emul - hw->pos_emul);
417 memcpy(hw->buf_emul + hw->pos_emul, buf, to_copy);
418
419 hw->pos_emul = (hw->pos_emul + to_copy) % hw->size_emul;
420 buf += to_copy;
421 len -= to_copy;
422 }
423 return total_len;
424 }
425
426 pos = 0;
427 while (len) {
428 ssize_t bytes_written;
429 void *pcm = advance(buf, pos);
430
431 bytes_written = write(oss->fd, pcm, len);
432 if (bytes_written < 0) {
433 if (errno != EAGAIN) {
434 oss_logerr(errno, "failed to write %zu bytes", len);
435 }
436 return pos;
437 }
438
439 pos += bytes_written;
440 if (bytes_written < len) {
441 break;
442 }
443 len -= bytes_written;
444 }
445 return pos;
446 }
447
448 static void oss_fini_out(HWVoiceOut *hw)
449 {
450 int err;
451 OSSVoiceOut *oss = (OSSVoiceOut *)hw;
452
453 trace_oss_fini_out();
454 oss_anal_close(&oss->fd);
455
456 if (oss->mmapped && hw->buf_emul) {
457 err = munmap(hw->buf_emul, hw->size_emul);
458 if (err) {
459 oss_logerr(errno, "Failed to unmap buffer %p, size %zu",
460 hw->buf_emul, hw->size_emul);
461 }
462 hw->buf_emul = NULL;
463 }
464 }
465
466 static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
467 {
468 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
469 struct oss_params req, obt;
470 int err;
471 int fd;
472 struct audsettings obt_as;
473 Audiodev *dev = hw->s->dev;
474 AudiodevOssOptions *oopts = &dev->u.oss;
475
476 oss->fd = -1;
477
478 req.fmt = aud_to_ossfmt (as->fmt, as->big_endian);
479 req.freq = as->freq;
480 req.nchannels = as->nchannels;
481
482 if (oss_open(0, &req, as, &obt, &fd, dev)) {
483 return -1;
484 }
485
486 err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.big_endian);
487 if (err) {
488 oss_anal_close (&fd);
489 return -1;
490 }
491
492 obt_as.freq = obt.freq;
493 obt_as.nchannels = obt.nchannels;
494
495 audio_pcm_init_info (&hw->info, &obt_as);
496 oss->nfrags = obt.nfrags;
497 oss->fragsize = obt.fragsize;
498
499 if (obt.nfrags * obt.fragsize % hw->info.bytes_per_frame) {
500 warn_report("oss: Misaligned DAC buffer, size %d, alignment %d",
501 obt.nfrags * obt.fragsize, hw->info.bytes_per_frame);
502 }
503
504 hw->samples = (obt.nfrags * obt.fragsize) / hw->info.bytes_per_frame;
505
506 oss->mmapped = 0;
507 if (oopts->has_try_mmap && oopts->try_mmap) {
508 hw->size_emul = hw->samples * hw->info.bytes_per_frame;
509 hw->buf_emul = mmap(
510 NULL,
511 hw->size_emul,
512 PROT_READ | PROT_WRITE,
513 MAP_SHARED,
514 fd,
515 0
516 );
517 if (hw->buf_emul == MAP_FAILED) {
518 oss_logerr(errno, "Failed to map %zu bytes of DAC", hw->size_emul);
519 hw->buf_emul = NULL;
520 } else {
521 int trig = 0;
522 if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
523 oss_logerr(errno, "SNDCTL_DSP_SETTRIGGER 0 failed");
524 } else {
525 trig = PCM_ENABLE_OUTPUT;
526 if (ioctl(fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
527 oss_logerr(errno, "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed");
528 } else {
529 oss->mmapped = 1;
530 }
531 }
532
533 if (!oss->mmapped) {
534 err = munmap(hw->buf_emul, hw->size_emul);
535 if (err) {
536 oss_logerr(errno, "Failed to unmap buffer %p size %zu",
537 hw->buf_emul, hw->size_emul);
538 }
539 hw->buf_emul = NULL;
540 }
541 }
542 }
543
544 oss->fd = fd;
545 oss->dev = dev;
546 return 0;
547 }
548
549 static void oss_enable_out(HWVoiceOut *hw, bool enable)
550 {
551 int trig;
552 OSSVoiceOut *oss = (OSSVoiceOut *)hw;
553 AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;
554
555 trace_oss_enable_out(enable);
556
557 if (enable) {
558 hw->poll_mode = opdo->try_poll;
559
560 if (hw->poll_mode) {
561 oss_poll_out(hw);
562 }
563
564 if (!oss->mmapped) {
565 return;
566 }
567
568 audio_pcm_info_clear_buf(&hw->info, hw->buf_emul, hw->samples);
569 trig = PCM_ENABLE_OUTPUT;
570 if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
571 oss_logerr(errno,
572 "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed");
573 return;
574 }
575 } else {
576 if (hw->poll_mode) {
577 qemu_set_fd_handler(oss->fd, NULL, NULL, NULL);
578 hw->poll_mode = 0;
579 }
580
581 if (!oss->mmapped) {
582 return;
583 }
584
585 trig = 0;
586 if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
587 oss_logerr(errno, "SNDCTL_DSP_SETTRIGGER 0 failed");
588 return;
589 }
590 }
591 }
592
593 static int oss_init_in(HWVoiceIn *hw, struct audsettings *as)
594 {
595 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
596 struct oss_params req, obt;
597 int err;
598 int fd;
599 struct audsettings obt_as;
600 Audiodev *dev = hw->s->dev;
601
602 oss->fd = -1;
603
604 req.fmt = aud_to_ossfmt (as->fmt, as->big_endian);
605 req.freq = as->freq;
606 req.nchannels = as->nchannels;
607 if (oss_open(1, &req, as, &obt, &fd, dev)) {
608 return -1;
609 }
610
611 err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.big_endian);
612 if (err) {
613 oss_anal_close (&fd);
614 return -1;
615 }
616
617 obt_as.freq = obt.freq;
618 obt_as.nchannels = obt.nchannels;
619
620 audio_pcm_init_info (&hw->info, &obt_as);
621 oss->nfrags = obt.nfrags;
622 oss->fragsize = obt.fragsize;
623
624 trace_oss_in_params(
625 req.fmt, obt.fmt,
626 req.nchannels, obt.nchannels,
627 req.freq, obt.freq,
628 req.nfrags, obt.nfrags,
629 req.fragsize, obt.fragsize);
630
631 if (obt.nfrags * obt.fragsize % hw->info.bytes_per_frame) {
632 warn_report("oss: Misaligned ADC buffer, size %d, alignment %d",
633 obt.nfrags * obt.fragsize, hw->info.bytes_per_frame);
634 }
635
636 hw->samples = (obt.nfrags * obt.fragsize) / hw->info.bytes_per_frame;
637
638 oss->fd = fd;
639 oss->dev = dev;
640 return 0;
641 }
642
643 static void oss_fini_in (HWVoiceIn *hw)
644 {
645 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
646
647 oss_anal_close (&oss->fd);
648 }
649
650 static size_t oss_read(HWVoiceIn *hw, void *buf, size_t len)
651 {
652 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
653 size_t pos = 0;
654
655 while (len) {
656 ssize_t nread;
657
658 void *dst = advance(buf, pos);
659 nread = read(oss->fd, dst, len);
660
661 if (nread == -1) {
662 switch (errno) {
663 case EINTR:
664 case EAGAIN:
665 break;
666 default:
667 oss_logerr(errno, "Failed to read %zu bytes of audio (to %p)",
668 len, dst);
669 break;
670 }
671 break;
672 }
673
674 pos += nread;
675 len -= nread;
676 }
677
678 return pos;
679 }
680
681 static void oss_enable_in(HWVoiceIn *hw, bool enable)
682 {
683 OSSVoiceIn *oss = (OSSVoiceIn *)hw;
684 AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;
685
686 trace_oss_enable_in(enable);
687
688 if (enable) {
689 hw->poll_mode = opdo->try_poll;
690
691 if (hw->poll_mode) {
692 oss_poll_in(hw);
693 }
694 } else {
695 if (hw->poll_mode) {
696 qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
697 hw->poll_mode = 0;
698 }
699 }
700 }
701
702 static void oss_init_per_direction(AudiodevOssPerDirectionOptions *opdo)
703 {
704 if (!opdo->has_try_poll) {
705 opdo->try_poll = true;
706 opdo->has_try_poll = true;
707 }
708 }
709
710 static bool
711 audio_oss_realize(AudioBackend *abe, Audiodev *dev, Error **errp)
712 {
713 AudiodevOssOptions *oopts;
714 assert(dev->driver == AUDIODEV_DRIVER_OSS);
715
716 oopts = &dev->u.oss;
717 oss_init_per_direction(oopts->in);
718 oss_init_per_direction(oopts->out);
719
720 if (access(oopts->in->dev ?: "/dev/dsp", R_OK | W_OK) < 0) {
721 error_setg_errno(errp, errno, "%s not accessible", oopts->in->dev ?: "/dev/dsp");
722 qapi_free_Audiodev(dev);
723 return false;
724 }
725 if (access(oopts->out->dev ?: "/dev/dsp", R_OK | W_OK) < 0) {
726 error_setg_errno(errp, errno, "%s not accessible", oopts->out->dev ?: "/dev/dsp");
727 qapi_free_Audiodev(dev);
728 return false;
729 }
730
731 return audio_oss_parent_class->realize(abe, dev, errp);
732 }
733
734 static void audio_oss_class_init(ObjectClass *klass, const void *data)
735 {
736 AudioBackendClass *b = AUDIO_BACKEND_CLASS(klass);
737 AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass);
738
739 audio_oss_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
740
741 b->realize = audio_oss_realize;
742 k->max_voices_out = INT_MAX;
743 k->max_voices_in = INT_MAX;
744 k->voice_size_out = sizeof(OSSVoiceOut);
745 k->voice_size_in = sizeof(OSSVoiceIn);
746
747 k->init_out = oss_init_out;
748 k->fini_out = oss_fini_out;
749 k->write = oss_write;
750 k->buffer_get_free = oss_buffer_get_free;
751 k->run_buffer_out = oss_run_buffer_out;
752 k->get_buffer_out = oss_get_buffer_out;
753 k->put_buffer_out = oss_put_buffer_out;
754 k->enable_out = oss_enable_out;
755
756 k->init_in = oss_init_in;
757 k->fini_in = oss_fini_in;
758 k->read = oss_read;
759 k->run_buffer_in = audio_generic_run_buffer_in;
760 k->enable_in = oss_enable_in;
761 }
762
763 static const TypeInfo audio_types[] = {
764 {
765 .name = TYPE_AUDIO_OSS,
766 .parent = TYPE_AUDIO_MIXENG_BACKEND,
767 .instance_size = sizeof(AudioOss),
768 .class_init = audio_oss_class_init,
769 },
770 };
771
772 DEFINE_TYPES(audio_types)
773 module_obj(TYPE_AUDIO_OSS);