Mercurial > audlegacy-plugins
comparison src/OSS4/audio.c @ 3048:c269a0351b53
ported OSS4
author | Michal Lipski <tallica@o2.pl> |
---|---|
date | Fri, 17 Apr 2009 17:31:14 +0200 |
parents | bd3a24b39058 |
children | 9ec8a613a1d6 |
comparison
equal
deleted
inserted
replaced
3047:4434b4c4a715 | 3048:c269a0351b53 |
---|---|
17 * You should have received a copy of the GNU General Public License | 17 * You should have received a copy of the GNU General Public License |
18 * along with this program; if not, write to the Free Software | 18 * along with this program; if not, write to the Free Software |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 extern void close_mixer_device(); | 22 static void oss_describe_error(); |
23 static void close_mixer_device(); | |
23 | 24 |
24 #include <glib.h> | 25 #include <glib.h> |
25 #include <string.h> | 26 #include <string.h> |
26 | 27 |
27 #include <unistd.h> | 28 #include <unistd.h> |
33 #include "OSS4.h" | 34 #include "OSS4.h" |
34 | 35 |
35 | 36 |
36 #define NFRAGS 32 | 37 #define NFRAGS 32 |
37 | 38 |
38 static gint fd = 0; | 39 static gint fd = -1, mixerfd = -1; |
40 static oss_sysinfo sysinfo; | |
39 static char *buffer; | 41 static char *buffer; |
40 static gboolean going, prebuffer, paused, unpause, do_pause, remove_prebuffer; | 42 static gboolean going, prebuffer, paused, unpause, do_pause, remove_prebuffer; |
41 static gint device_buffer_used, buffer_size, prebuffer_size, blk_size; | 43 static gint device_buffer_used, buffer_size, prebuffer_size, blk_size; |
42 static gint rd_index = 0, wr_index = 0; | 44 static gint rd_index = 0, wr_index = 0; |
43 static gint output_time_offset = 0; | 45 static gint output_time_offset = 0; |
81 * This might be different from effect if we need to resample or do | 83 * This might be different from effect if we need to resample or do |
82 * some other format conversion. | 84 * some other format conversion. |
83 */ | 85 */ |
84 struct format_info output; | 86 struct format_info output; |
85 | 87 |
88 int oss_hardware_present() | |
89 { | |
90 /* | |
91 * Open the mixer device used for calling SNDCTL_SYSINFO and | |
92 * SNDCTL_AUDIOINFO. | |
93 */ | |
94 if ((mixerfd = open("/dev/mixer", O_RDWR, 0)) == -1) | |
95 { | |
96 perror("/dev/mixer"); | |
97 oss_describe_error(); | |
98 close_mixer_device(); | |
99 | |
100 return 0; | |
101 } | |
102 | |
103 if (ioctl(mixerfd, SNDCTL_SYSINFO, &sysinfo) == -1) | |
104 { | |
105 perror("SNDCTL_SYSINFO"); | |
106 oss_describe_error(); | |
107 close_mixer_device(); | |
108 | |
109 return 0; | |
110 } | |
111 else | |
112 { | |
113 close_mixer_device(); | |
114 | |
115 if (sysinfo.numaudios > 0) | |
116 { | |
117 return 1; | |
118 } | |
119 else | |
120 { | |
121 return 0; | |
122 } | |
123 } | |
124 } | |
125 | |
126 static void | |
127 oss_describe_error() | |
128 { | |
129 switch (errno) | |
130 { | |
131 case ENXIO: | |
132 fprintf(stderr, "OSS has not detected any supported sound hardware in your system.\n"); | |
133 break; | |
134 | |
135 case EINVAL: | |
136 fprintf(stderr, "Error: OSS version 4.0 or later is required\n"); | |
137 break; | |
138 | |
139 case ENODEV: | |
140 fprintf(stderr, "The device file was found in /dev but\n" | |
141 "OSS is not loaded. You need to load it by executing\n" | |
142 "the soundon command.\n"); | |
143 break; | |
144 | |
145 case ENOSPC: | |
146 fprintf(stderr, "Your system cannot allocate memory for the device\n" | |
147 "buffers. Reboot your machine and try again.\n"); | |
148 break; | |
149 | |
150 case ENOENT: | |
151 fprintf(stderr, "The device file is missing from /dev.\n" | |
152 "Perhaps you have not installed and started Open Sound System yet\n"); | |
153 break; | |
154 | |
155 case EBUSY: | |
156 fprintf(stderr, "The device is busy. There is some other application\n" | |
157 "using it.\n"); | |
158 break; | |
159 | |
160 default: | |
161 fprintf(stderr, "Unknown OSS error.\n"); | |
162 } | |
163 } | |
86 | 164 |
87 static void | 165 static void |
88 oss_calc_device_buffer_used(void) | 166 oss_calc_device_buffer_used(void) |
89 { | 167 { |
90 audio_buf_info buf_info; | 168 audio_buf_info buf_info; |
732 } | 810 } |
733 | 811 |
734 void | 812 void |
735 close_mixer_device() | 813 close_mixer_device() |
736 { | 814 { |
737 } | 815 if (fd != -1) |
738 | 816 { |
739 | 817 close(fd); |
818 fd = -1; | |
819 } | |
820 | |
821 if (mixerfd != -1) | |
822 { | |
823 close(mixerfd); | |
824 mixerfd = -1; | |
825 } | |
826 } |