annotate libao2/ao_oss.c @ 2051:596653943fa1

tired
author gabucino
date Tue, 02 Oct 2001 21:59:43 +0000
parents cb9bc07f3d4c
children f91ad6d23ce9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
3
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
4 #include <sys/ioctl.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
7 #include <sys/types.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
8 #include <sys/stat.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
9 #include <fcntl.h>
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
10 //#include <sys/soundcard.h>
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
11
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
12 #include "../config.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
13
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
14 #include "afmt.h"
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
15
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
16 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
17 #include "audio_out_internal.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
18
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
19 extern int verbose;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
20
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
21 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
22 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
23 "OSS/ioctl audio output",
956
a6cecd9a1bad '-ao' switch (including '-ao help'), fixing Arpi's bug (short name 'null' for both of oss and null driver ;)
lgb
parents: 954
diff changeset
24 "oss",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
25 "A'rpi",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
26 ""
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
27 };
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
28
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
29 LIBAO_EXTERN(oss)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
30
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
31 // there are some globals:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
32 // ao_samplerate
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
33 // ao_channels
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
34 // ao_format
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
35 // ao_bps
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
36 // ao_outburst
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
37 // ao_buffersize
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
38
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
39 static char *dsp="/dev/dsp";
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
40 static audio_buf_info zz;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
41 static int audio_fd=-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
42
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
43 char *oss_mixer_device = "/dev/mixer";
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
44 int oss_mixer_usemaster = 0;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
45
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 // to set/get/query special features/parameters
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47 static int control(int cmd,int arg){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
48 switch(cmd){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
49 case AOCONTROL_SET_DEVICE:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
50 dsp=(char*)arg;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
51 return CONTROL_OK;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
52 case AOCONTROL_QUERY_FORMAT:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
53 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
54 case AOCONTROL_GET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
55 case AOCONTROL_SET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
56 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
57 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
58 int fd, v, mcmd, devs;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
59
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
60 if(ao_format == AFMT_AC3)
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
61 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
62
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
63 if ((fd = open("/dev/mixer", O_RDONLY)) > 0)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
64 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
65 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
66 if ((devs & SOUND_MASK_PCM) && (oss_mixer_usemaster == 0))
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
67 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
68 mcmd = SOUND_MIXER_READ_PCM;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
69 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
70 mcmd = SOUND_MIXER_WRITE_PCM;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
71 else if ((devs & SOUND_MASK_VOLUME) && (oss_mixer_usemaster == 1))
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
72 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
73 mcmd = SOUND_MIXER_READ_VOLUME;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
74 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
75 mcmd = SOUND_MIXER_WRITE_VOLUME;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
76 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
77 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
78 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
79 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
80 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
81
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
82 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
83 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
84 ioctl(fd, cmd, &v);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
85 vol->right = (v & 0xFF00) >> 8;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
86 vol->left = v & 0x00FF;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
87 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
88 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
89 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
90 v = ((int)vol->right << 8) | (int)vol->left;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
91 ioctl(fd, cmd, &v);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
92 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
93 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
94 return CONTROL_OK;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
95 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
96 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
97 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
98 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
99 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
100 default:
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
101 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
102 return CONTROL_UNKNOWN;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
103 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
104
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
105 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
106 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
107 static int init(int rate,int channels,int format,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
108
1456
8c57a5a3c645 printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents: 1191
diff changeset
109 // printf("ao2: %d Hz %d chans %s\n",rate,channels,
8c57a5a3c645 printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents: 1191
diff changeset
110 // audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
111
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
112 if (ao_subdevice)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
113 dsp = ao_subdevice;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
114
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
115 if (verbose)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
116 printf("audio_setup: using '%s' dsp device\n", dsp);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
117
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
118 audio_fd=open(dsp, O_WRONLY);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
119 if(audio_fd<0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
120 printf("Can't open audio device %s -> nosound\n",dsp);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
121 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
122 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
123
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
124 ao_format=format;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
125 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
126 if(format == AFMT_AC3 && ao_format != AFMT_AC3) {
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
127 printf("Can't set audio device %s to AC3 output\n", dsp);
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
128 return 0;
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
129 }
1079
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
130 printf("audio_setup: sample format: %s (requested: %s)\n",
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
131 audio_out_format_name(ao_format), audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
132
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
133 if(format != AFMT_AC3) {
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
134 ao_channels=channels-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
135 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
136
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
137 // set rate
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
138 ao_samplerate=rate;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
139 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
140 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
141 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
142
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
143 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
144 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
145 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
146 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
147 printf("audio_setup: %d bytes/frag (config.h)\n",ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
148 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
149 ao_outburst=r;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
150 printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
151 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
152 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
153 printf("audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
154 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
155 if(ao_buffersize==-1) ao_buffersize=zz.bytes;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
156 ao_outburst=zz.fragsize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
157 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
158
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
159 if(ao_buffersize==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
160 // Measuring buffer size:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
161 void* data;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
162 ao_buffersize=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
163 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
164 data=malloc(ao_outburst); memset(data,0,ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
165 while(ao_buffersize<0x40000){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
166 fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
167 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
168 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
169 tv.tv_sec=0; tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
170 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
171 write(audio_fd,data,ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
172 ao_buffersize+=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
173 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
174 free(data);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
175 if(ao_buffersize==0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
176 printf("\n *** Your audio driver DOES NOT support select() ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
177 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
178 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
179 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
180 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
181 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
182
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
183 return 1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
184 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
185
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
186 // close audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
187 static void uninit(){
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
188 #ifdef SNDCTL_DSP_RESET
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
189 ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
190 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
191 close(audio_fd);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
192 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
193
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
194 // stop playing and empty buffers (for seeking/pause)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
195 static void reset(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
196 uninit();
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
197 audio_fd=open(dsp, O_WRONLY);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
198 if(audio_fd<0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
199 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
200 return;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
201 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
202
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
203 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
204 if(ao_format != AFMT_AC3) {
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
205 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
206 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
207 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
208 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
209
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
210 // stop playing, keep buffers (for pause)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
211 static void audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
212 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
213 // for now, just call reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
214 reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
215 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
216
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
217 // resume playing, after audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
218 static void audio_resume()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
219 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
220 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
221
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
222
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
223 // return: how many bytes can be played without blocking
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
224 static int get_space(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
225 int playsize=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
226
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
227 #ifdef SNDCTL_DSP_GETOSPACE
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
228 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
229 // calculate exact buffer space:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
230 return zz.fragments*zz.fragsize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
231 }
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
232 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
233
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
234 // check buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
235 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
236 { fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
237 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
238 FD_ZERO(&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
239 FD_SET(audio_fd, &rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
240 tv.tv_sec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
241 tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
242 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block!
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
243 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
244 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
245
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
246 return ao_outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
247 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
248
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
249 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
250 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
251 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
252 static int play(void* data,int len,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
253 len/=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
254 len=write(audio_fd,data,len*ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
255 return len;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
256 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
257
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
258 static int audio_delay_method=2;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
259
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
260 // return: how many unplayed bytes are in the buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
261 static int get_delay(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
262 if(audio_delay_method==2){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
263 //
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
264 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
265 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
266 return r;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
267 audio_delay_method=1; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
268 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
269 if(audio_delay_method==1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
270 // SNDCTL_DSP_GETOSPACE
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
271 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
272 return ao_buffersize-zz.bytes;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
273 audio_delay_method=0; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
274 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
275 return ao_buffersize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
276 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
277