]>
code.delx.au - pulseaudio/blob - polyp/oss-util.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/soundcard.h>
28 #include <sys/ioctl.h>
33 #include <sys/types.h>
41 int pa_oss_open(const char *device
, int *mode
, int* pcaps
) {
43 assert(device
&& mode
&& (*mode
== O_RDWR
|| *mode
== O_RDONLY
|| *mode
== O_WRONLY
));
45 if (*mode
== O_RDWR
) {
46 if ((fd
= open(device
, O_RDWR
|O_NDELAY
)) >= 0) {
48 ioctl(fd
, SNDCTL_DSP_SETDUPLEX
, 0);
50 tcaps
= pcaps
? pcaps
: &dcaps
;
52 if (ioctl(fd
, SNDCTL_DSP_GETCAPS
, tcaps
) < 0) {
53 pa_log(__FILE__
": SNDCTL_DSP_GETCAPS: %s\n", strerror(errno
));
57 if (*tcaps
& DSP_CAP_DUPLEX
)
63 if ((fd
= open(device
, (*mode
= O_WRONLY
)|O_NDELAY
)) < 0) {
64 if ((fd
= open(device
, (*mode
= O_RDONLY
)|O_NDELAY
)) < 0) {
65 pa_log(__FILE__
": open('%s'): %s\n", device
, strerror(errno
));
70 if ((fd
= open(device
, *mode
|O_NDELAY
)) < 0) {
71 pa_log(__FILE__
": open('%s'): %s\n", device
, strerror(errno
));
77 if (ioctl(fd
, SNDCTL_DSP_GETCAPS
, pcaps
) < 0) {
78 pa_log(__FILE__
": SNDCTL_DSP_GETCAPS: %s\n", strerror(errno
));
83 pa_fd_set_cloexec(fd
, 1);
93 int pa_oss_auto_format(int fd
, struct pa_sample_spec
*ss
) {
94 int format
, channels
, speed
, reqformat
;
95 static const int format_trans
[] = {
96 [PA_SAMPLE_U8
] = AFMT_U8
,
97 [PA_SAMPLE_ALAW
] = AFMT_A_LAW
,
98 [PA_SAMPLE_ULAW
] = AFMT_MU_LAW
,
99 [PA_SAMPLE_S16LE
] = AFMT_S16_LE
,
100 [PA_SAMPLE_S16BE
] = AFMT_S16_BE
,
101 [PA_SAMPLE_FLOAT32LE
] = AFMT_QUERY
, /* not supported */
102 [PA_SAMPLE_FLOAT32BE
] = AFMT_QUERY
, /* not supported */
105 assert(fd
>= 0 && ss
);
107 reqformat
= format
= format_trans
[ss
->format
];
108 if (reqformat
== AFMT_QUERY
|| ioctl(fd
, SNDCTL_DSP_SETFMT
, &format
) < 0 || format
!= reqformat
) {
109 format
= AFMT_S16_NE
;
110 if (ioctl(fd
, SNDCTL_DSP_SETFMT
, &format
) < 0 || format
!= AFMT_S16_NE
) {
111 int f
= AFMT_S16_NE
== AFMT_S16_LE
? AFMT_S16_BE
: AFMT_S16_LE
;
113 if (ioctl(fd
, SNDCTL_DSP_SETFMT
, &format
) < 0 || format
!= f
) {
115 if (ioctl(fd
, SNDCTL_DSP_SETFMT
, &format
) < 0 || format
!= AFMT_U8
) {
116 pa_log(__FILE__
": SNDCTL_DSP_SETFMT: %s\n", format
!= AFMT_U8
? "No supported sample format" : strerror(errno
));
119 ss
->format
= PA_SAMPLE_U8
;
121 ss
->format
= f
== AFMT_S16_LE
? PA_SAMPLE_S16LE
: PA_SAMPLE_S16BE
;
123 ss
->format
= PA_SAMPLE_S16NE
;
126 channels
= ss
->channels
;
127 if (ioctl(fd
, SNDCTL_DSP_CHANNELS
, &channels
) < 0) {
128 pa_log(__FILE__
": SNDCTL_DSP_CHANNELS: %s\n", strerror(errno
));
132 ss
->channels
= channels
;
135 if (ioctl(fd
, SNDCTL_DSP_SPEED
, &speed
) < 0) {
136 pa_log(__FILE__
": SNDCTL_DSP_SPEED: %s\n", strerror(errno
));
145 static int simple_log2(int v
) {
157 int pa_oss_set_fragments(int fd
, int nfrags
, int frag_size
) {
159 arg
= ((int) nfrags
<< 16) | simple_log2(frag_size
);
161 if (ioctl(fd
, SNDCTL_DSP_SETFRAGMENT
, &arg
) < 0) {
162 pa_log(__FILE__
": SNDCTL_DSP_SETFRAGMENT: %s\n", strerror(errno
));