source: roaraudio/libroareio/driver_oss.c @ 4889:579befd93a5f

Last change on this file since 4889:579befd93a5f was 4889:579befd93a5f, checked in by phi, 13 years ago

ignore internal calls

File size: 4.1 KB
RevLine 
[2131]1//driver_oss.c:
2
3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
[2131]5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[2131]23 *
24 */
25
[4889]26/* ckport options:
27 * ckport: ignore: ^roar_cdriver_oss$
28 */
29
[2131]30#include <roaraudio.h>
31#include "driver.h"
32
[2132]33#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
34
35#if defined(__OpenBSD__) || defined(__NetBSD__)
36#include <soundcard.h>
37#else
38#include <sys/soundcard.h>
39#endif
40#include <sys/ioctl.h>
41
[2569]42#ifdef SNDCTL_DSP_SETFRAGMENT
[3853]43static void roar_cdriver_oss_try_buf_setups(struct roar_vio_calls * calls) {
44 struct roar_vio_sysio_ioctl ctl;
[2569]45 int blocksizes[] = {11, 12, 13};
46 int blocks[]     = {4, 5, 6, 3, 7, 2, 8};
47 int bs, b;
48 int tmp;
49
[3853]50 ctl.cmd  = SNDCTL_DSP_SETFRAGMENT;
51 ctl.argp = &tmp;
52
[2569]53 for (bs = 0; bs < sizeof(blocksizes)/sizeof(int); bs++) {
54  for (b = 0; b  < sizeof(blocks)    /sizeof(int); b++ ) {
55   tmp = blocksizes[bs] | (blocks[b] << 16);
[3853]56   if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == 0 )
[2569]57    return;
58  }
59 }
60}
61#endif
62
[2132]63#define _err() roar_vio_close(calls); return -1
64
[4604]65int roar_cdriver_oss(struct roar_vio_calls * calls, const char * name, char * dev, struct roar_audio_info * info, int dir) {
[3853]66 struct roar_vio_sysio_ioctl ctl;
[2132]67 int tmp, ctmp;
68
[3853]69 // preinit ctl struct, we always pass ints in tmp.
70 ctl.argp = &tmp;
71
[2135]72 ROAR_DBG("roar_cdriver_oss(*) = ?");
73
[2217]74#ifdef ROAR_DEFAULT_OSS_DEV
[2132]75 if ( dev == NULL )
76  dev = ROAR_DEFAULT_OSS_DEV;
[2217]77#endif
[2132]78
79 if ( dev == NULL )
80  return -1;
81
[2135]82 ROAR_DBG("roar_cdriver_oss(*) = ?");
83
[2136]84 switch (dir) {
85  case ROAR_DIR_PLAY:
86  case ROAR_DIR_MONITOR:
87  case ROAR_DIR_OUTPUT:
88    tmp = O_WRONLY;
89   break;
90  case ROAR_DIR_BIDIR:
91    tmp = O_RDWR;
92   break;
93  case ROAR_DIR_RECORD:
94    tmp = O_RDONLY;
[2301]95   break;
[2136]96  default:
97    return -1;
98 }
99
[2301]100 ROAR_DBG("roar_cdriver_oss(*) = ?");
101
[2136]102 if ( roar_vio_open_file(calls, dev, tmp, 0644) == -1 )
[2132]103  return -1;
104
105// channels:
106#ifdef SNDCTL_DSP_CHANNELS
107 tmp = info->channels;
108
[3853]109 ctl.cmd  = SNDCTL_DSP_CHANNELS;
110
111 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
[2132]112  _err();
113 }
114
115 if ( tmp != info->channels ) {
116  _err();
117 }
118#else
119 switch (info->channels) {
120  case  1: tmp = 0; break;
121  case  2: tmp = 1; break;
122  default: _err();
123 }
124
[3853]125 ctl.cmd = SNDCTL_DSP_STEREO;
126
127 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
[2132]128  _err();
129 }
130#endif
131
132// codec/bits:
133 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
134  // other modes are currently not supported
135  _err();
136 }
137
138 switch (info->codec) {
139  case ROAR_CODEC_PCM_S_LE:
[2137]140    tmp = AFMT_S16_LE;
141   break;
[2132]142  case ROAR_CODEC_PCM_S_BE:
[2137]143    tmp = AFMT_S16_BE;
144   break;
[2132]145  case ROAR_CODEC_PCM_U_LE:
[2137]146    tmp = AFMT_U16_LE;
147   break;
[2132]148  case ROAR_CODEC_PCM_U_BE:
[2137]149    tmp = AFMT_U16_BE;
[2132]150   break;
151  case ROAR_CODEC_ALAW:
152    tmp = AFMT_A_LAW;
153   break;
154  case ROAR_CODEC_MULAW:
155    tmp = AFMT_MU_LAW;
156   break;
[2138]157  default:
158    _err();
[2132]159 }
160
161 ctmp = tmp;
162#ifdef SNDCTL_DSP_SETFMT
[3853]163 ctl.cmd = SNDCTL_DSP_SETFMT;
[2132]164#else
[3853]165 ctl.cmd = SNDCTL_DSP_SAMPLESIZE;
[2132]166#endif
[3853]167
168 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
[2132]169  _err();
170 }
171
172 if ( tmp != ctmp ) {
173  _err();
174 }
175
176// rate:
177 tmp = info->rate;
178
[3853]179 ctl.cmd = SNDCTL_DSP_SPEED;
180 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
[2132]181  _err();
182 }
183
184 if ( tmp != info->rate ) {
185  _err();
186 }
187
[2569]188#ifdef SNDCTL_DSP_SETFRAGMENT
[3853]189 roar_cdriver_oss_try_buf_setups(calls);
[2569]190#endif
191
[2132]192 return 0;
[2131]193}
194
[2132]195#endif
196
[2131]197//ll
Note: See TracBrowser for help on using the repository browser.