annotate libao2/ao_oss.c @ 5214:dd79075bbd98

added a BMP file demuxer...yeah, that's right, a static image BMP file demuxer; what, is that so weird?...:)
author melanson
date Wed, 20 Mar 2002 05:15:53 +0000
parents 6bbf3271a694
children d141f1e9cc36
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>
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
10 #include <errno.h>
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
11 #include <string.h>
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
12 //#include <sys/soundcard.h>
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
13
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
14 #include "../config.h"
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
15 #include "../mixer.h"
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
16
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
17 #include "afmt.h"
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
18
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
19 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
20 #include "audio_out_internal.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
21
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
22 extern int verbose;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
23
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
24 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
25 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
26 "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
27 "oss",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
28 "A'rpi",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
29 ""
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
30 };
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
31
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
32 /* Support for >2 output channels added 2001-11-25 - Steve Davies <steve@daviesfam.org> */
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
33
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
34 LIBAO_EXTERN(oss)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
35
4803
5b4fd881200a using PATH_DEV_*
alex
parents: 4788
diff changeset
36 static char *dsp=PATH_DEV_DSP;
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
37 static audio_buf_info zz;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
38 static int audio_fd=-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
39
4803
5b4fd881200a using PATH_DEV_*
alex
parents: 4788
diff changeset
40 char *oss_mixer_device = PATH_DEV_MIXER;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
41
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
42 // to set/get/query special features/parameters
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
43 static int control(int cmd,int arg){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
44 switch(cmd){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
45 case AOCONTROL_SET_DEVICE:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 dsp=(char*)arg;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47 return CONTROL_OK;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
48 case AOCONTROL_QUERY_FORMAT:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
49 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
50 case AOCONTROL_GET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
51 case AOCONTROL_SET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
52 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
53 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
54 int fd, v, mcmd, devs;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
55
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
56 if(ao_data.format == AFMT_AC3)
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
57 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
58
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
59 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0)
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
60 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
61 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
62 if (devs & SOUND_MASK_PCM)
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
63 {
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
64 if (cmd == AOCONTROL_GET_VOLUME)
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
65 {
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
66 ioctl(fd, SOUND_MIXER_READ_PCM, &v);
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
67 vol->right = (v & 0xFF00) >> 8;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
68 vol->left = v & 0x00FF;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
69 }
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
70 else
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
71 {
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
72 v = ((int)vol->right << 8) | (int)vol->left;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
73 ioctl(fd, SOUND_MIXER_WRITE_PCM, &v);
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
74 }
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
75 }
1191
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 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
82 return CONTROL_OK;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
83 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
84 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
85 return CONTROL_ERROR;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
86 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
87 return CONTROL_UNKNOWN;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
88 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
89
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
90 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
91 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
92 static int init(int rate,int channels,int format,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
93
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
94 printf("ao2: %d Hz %d chans %s\n",rate,channels,
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
95 audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
96
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
97 if (ao_subdevice)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
98 dsp = ao_subdevice;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
99
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
100 if(mixer_device)
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
101 oss_mixer_device=mixer_device;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
102
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
103 if (verbose)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
104 printf("audio_setup: using '%s' dsp device\n", dsp);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
105
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
106 audio_fd=open(dsp, O_WRONLY | O_NONBLOCK);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
107 if(audio_fd<0){
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
108 printf("Can't open audio device %s: %s -> no sound\n", dsp, strerror(errno));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
109 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
110 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
111
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
112 /* Remove the non-blocking flag */
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
113 if(fcntl(audio_fd, F_SETFL, 0) < 0) {
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
114 printf("Can't make filedescriptor non-blocking: %s -> no sound\n", strerror(errno));
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
115 return 0;
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
116 }
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
117
3137
b9ee2d8d7279 Audio delay bugfix
anders
parents: 3095
diff changeset
118 ao_data.bps=channels*rate;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
119 if(format != AFMT_U8 && format != AFMT_S8)
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
120 ao_data.bps*=2;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
121
4184
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
122 if(format == AFMT_AC3) {
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
123 ao_data.samplerate=rate;
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
124 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
125 }
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
126
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
127 ao_data.format=format;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
128 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
129 if(format == AFMT_AC3 && ao_data.format != AFMT_AC3) {
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
130 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
131 return 0;
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
132 }
1079
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
133 printf("audio_setup: sample format: %s (requested: %s)\n",
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
134 audio_out_format_name(ao_data.format), audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
135
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
136 if(format != AFMT_AC3) {
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
137 // We only use SNDCTL_DSP_CHANNELS for >2 channels, in case some drivers don't have it
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
138 ao_data.channels = channels;
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
139 if (ao_data.channels > 2) {
3319
66134af21278 fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents: 3181
diff changeset
140 if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels) == -1 ||
66134af21278 fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents: 3181
diff changeset
141 ao_data.channels != channels ) {
66134af21278 fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents: 3181
diff changeset
142 printf("audio_setup: Failed to set audio device to %d channels\n", channels);
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
143 return 0;
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
144 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
145 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
146 else {
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
147 int c = ao_data.channels-1;
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
148 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) {
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
149 printf("audio_setup: Failed to set audio device to %d channels\n", ao_data.channels);
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
150 return 0;
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
151 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
152 }
3319
66134af21278 fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents: 3181
diff changeset
153 printf("audio_setup: using %d channels (requested: %d)\n", ao_data.channels, channels);
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
154 // set rate
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
155 ao_data.samplerate=rate;
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
156 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
157 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
158 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
159
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
160 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
161 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
162 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
163 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
164 printf("audio_setup: %d bytes/frag (config.h)\n",ao_data.outburst);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
165 } else {
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
166 ao_data.outburst=r;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
167 printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
168 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
169 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
170 printf("audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
171 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
172 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
173 ao_data.outburst=zz.fragsize;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
174 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
175
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
176 if(ao_data.buffersize==-1){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
177 // Measuring buffer size:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
178 void* data;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
179 ao_data.buffersize=0;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
180 #ifdef HAVE_AUDIO_SELECT
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
181 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
182 while(ao_data.buffersize<0x40000){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
183 fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
184 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
185 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
186 tv.tv_sec=0; tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
187 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
188 write(audio_fd,data,ao_data.outburst);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
189 ao_data.buffersize+=ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
190 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
191 free(data);
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
192 if(ao_data.buffersize==0){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
193 printf("\n *** Your audio driver DOES NOT support select() ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
194 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
195 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
196 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
197 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
198 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
199
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
200 return 1;
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 // close audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
204 static void uninit(){
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
205 #ifdef SNDCTL_DSP_RESET
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
206 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
207 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
208 close(audio_fd);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
209 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
210
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
211 // stop playing and empty buffers (for seeking/pause)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
212 static void reset(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
213 uninit();
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
214 audio_fd=open(dsp, O_WRONLY | O_NONBLOCK);
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
215 if(audio_fd < 0 || fcntl(audio_fd, F_SETFL, 0) < 0){
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
216 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE *** %s\n", strerror(errno));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
217 return;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
218 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
219
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
220 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
221 if(ao_data.format != AFMT_AC3) {
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
222 if (ao_data.channels > 2)
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
223 ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels);
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
224 else {
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
225 int c = ao_data.channels-1;
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
226 ioctl (audio_fd, SNDCTL_DSP_STEREO, &c);
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
227 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
228 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
229 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
230 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
231
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
232 // 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
233 static void audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
234 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
235 // 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
236 reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
237 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
238
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
239 // 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
240 static void audio_resume()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
241 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
242 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
243
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
244
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
245 // return: how many bytes can be played without blocking
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
246 static int get_space(){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
247 int playsize=ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
248
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
249 #ifdef SNDCTL_DSP_GETOSPACE
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
250 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
251 // calculate exact buffer space:
3455
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
252 playsize = zz.fragments*zz.fragsize;
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
253 if (playsize > MAX_OUTBURST)
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
254 playsize = (MAX_OUTBURST / zz.fragsize) * zz.fragsize;
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
255 return playsize;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
256 }
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
257 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
258
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
259 // check buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
260 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
261 { fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
262 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
263 FD_ZERO(&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
264 FD_SET(audio_fd, &rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
265 tv.tv_sec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
266 tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
267 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block!
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
268 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
269 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
270
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
271 return ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
272 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
273
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
274 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
275 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
276 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
277 static int play(void* data,int len,int flags){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
278 len/=ao_data.outburst;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
279 len=write(audio_fd,data,len*ao_data.outburst);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
280 return len;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
281 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
282
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
283 static int audio_delay_method=2;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
284
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
285 // return: delay in seconds between first and last sample in buffer
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
286 static float get_delay(){
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
287 /* Calculate how many bytes/second is sent out */
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
288 if(audio_delay_method==2){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
289 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
290 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1)
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
291 return ((float)r)/(float)ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
292 audio_delay_method=1; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
293 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
294 if(audio_delay_method==1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
295 // SNDCTL_DSP_GETOSPACE
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
296 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1)
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
297 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
298 audio_delay_method=0; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
299 }
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
300 return ((float)ao_data.buffersize)/(float)ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
301 }