source: roaraudio/libroareio/driver_oss.c @ 2138:1d4bfcfab077

Last change on this file since 2138:1d4bfcfab077 was 2138:1d4bfcfab077, checked in by phi, 15 years ago

unknown codec: error case

File size: 3.1 KB
Line 
1//driver_oss.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
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
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26#include "driver.h"
27
28#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
29
30#if defined(__OpenBSD__) || defined(__NetBSD__)
31#include <soundcard.h>
32#else
33#include <sys/soundcard.h>
34#endif
35#include <sys/ioctl.h>
36
37#define _err() roar_vio_close(calls); return -1
38
39int roar_cdriver_oss(struct roar_vio_calls * calls, char * name, char * dev, struct roar_audio_info * info, int dir) {
40 int fh;
41 int tmp, ctmp;
42
43 ROAR_DBG("roar_cdriver_oss(*) = ?");
44
45 if ( dev == NULL )
46  dev = ROAR_DEFAULT_OSS_DEV;
47
48 if ( dev == NULL )
49  return -1;
50
51 ROAR_DBG("roar_cdriver_oss(*) = ?");
52
53 switch (dir) {
54  case ROAR_DIR_PLAY:
55  case ROAR_DIR_MONITOR:
56  case ROAR_DIR_OUTPUT:
57    tmp = O_WRONLY;
58   break;
59  case ROAR_DIR_BIDIR:
60    tmp = O_RDWR;
61   break;
62  case ROAR_DIR_RECORD:
63    tmp = O_RDONLY;
64  default:
65    return -1;
66 }
67
68 if ( roar_vio_open_file(calls, dev, tmp, 0644) == -1 )
69  return -1;
70
71 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) {
72  _err();
73 }
74
75// channels:
76#ifdef SNDCTL_DSP_CHANNELS
77 tmp = info->channels;
78
79 if ( ioctl(fh, SNDCTL_DSP_CHANNELS, &tmp) == -1 ) {
80  _err();
81 }
82
83 if ( tmp != info->channels ) {
84  _err();
85 }
86#else
87 switch (info->channels) {
88  case  1: tmp = 0; break;
89  case  2: tmp = 1; break;
90  default: _err();
91 }
92
93 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
94  _err();
95 }
96#endif
97
98// codec/bits:
99 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
100  // other modes are currently not supported
101  _err();
102 }
103
104 switch (info->codec) {
105  case ROAR_CODEC_PCM_S_LE:
106    tmp = AFMT_S16_LE;
107   break;
108  case ROAR_CODEC_PCM_S_BE:
109    tmp = AFMT_S16_BE;
110   break;
111  case ROAR_CODEC_PCM_U_LE:
112    tmp = AFMT_U16_LE;
113   break;
114  case ROAR_CODEC_PCM_U_BE:
115    tmp = AFMT_U16_BE;
116   break;
117  case ROAR_CODEC_ALAW:
118    tmp = AFMT_A_LAW;
119   break;
120  case ROAR_CODEC_MULAW:
121    tmp = AFMT_MU_LAW;
122   break;
123  default:
124    _err();
125 }
126
127 ctmp = tmp;
128#ifdef SNDCTL_DSP_SETFMT
129 if ( ioctl(fh, SNDCTL_DSP_SETFMT, &tmp) == -1 ) {
130#else
131 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
132#endif
133  _err();
134 }
135
136 if ( tmp != ctmp ) {
137  _err();
138 }
139
140// rate:
141 tmp = info->rate;
142
143 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
144  _err();
145 }
146
147 if ( tmp != info->rate ) {
148  _err();
149 }
150
151 return 0;
152}
153
154#endif
155
156//ll
Note: See TracBrowser for help on using the repository browser.