aboutsummaryrefslogtreecommitdiff
path: root/multimedia/xmms/files/patch-oss
blob: a4a0d4ec95863442985dff0feef37352685b1b61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
--- Output/OSS/OSS.h.orig	Tue Jun 19 04:16:56 2007
+++ Output/OSS/OSS.h	Tue Jun 19 04:17:00 2007
@@ -37,7 +37,19 @@
 #include <stdio.h>
 #include <string.h>
 
+#ifdef __FreeBSD__
+#include <sys/soundcard.h>
+#else
 #include "soundcard.h"
+#endif
+
+#ifndef SNDCTL_DSP_GETPLAYVOL
+#define SNDCTL_DSP_GETPLAYVOL	SOUND_MIXER_READ_PCM
+#endif
+
+#ifndef SNDCTL_DSP_SETPLAYVOL
+#define SNDCTL_DSP_SETPLAYVOL	SOUND_MIXER_WRITE_PCM
+#endif
 
 #include "xmms/plugin.h"
 #include "libxmms/configfile.h"
@@ -81,6 +93,8 @@
 int oss_get_output_time(void);
 int oss_get_written_time(void);
 void oss_set_audio_params(void);
+
+int oss_get_fd(void);
 
 void oss_free_convert_buffer(void);
 int (*oss_get_convert_func(int output, int input))(void **, int);
--- Output/OSS/audio.c.orig	Tue Jun 19 04:17:17 2007
+++ Output/OSS/audio.c	Tue Jun 19 04:17:20 2007
@@ -23,7 +23,7 @@
 
 #define NFRAGS		32
 
-static gint fd = 0;
+static gint fd = -1;
 static char *buffer;
 static gboolean going, prebuffer, paused, unpause, do_pause, remove_prebuffer;
 static gint device_buffer_used, buffer_size, prebuffer_size, blk_size;
@@ -273,8 +273,10 @@
 	{
 		output_time_offset += (output_bytes * 1000) / output.bps;
 		output_bytes = 0;
+#ifndef __FreeBSD__
 		close(fd);
 		fd = open(device_name,O_WRONLY);
+#endif
 		oss_setup_format(new_format, new_frequency, new_channels);
 	}
 	if (effects_enabled() && ep && ep->mod_samples)
@@ -480,6 +482,7 @@
 	{
 		ioctl(fd, SNDCTL_DSP_RESET, 0);
 		close(fd);
+		fd = -1;
 	}
 	g_free(device_name);
 	oss_free_convert_buffer();
@@ -498,8 +501,10 @@
 	else
 	{
 		ioctl(fd, SNDCTL_DSP_RESET, 0);
+#ifndef __FreeBSD__
 		close(fd);
 		fd = open(device_name, O_WRONLY);
+#endif
 		oss_set_audio_params();
 		output_time_offset = time;
 		written = ((guint64)time * input.bps) / 1000;
@@ -568,8 +573,10 @@
 		else if (unpause && paused)
 		{
 			unpause = FALSE;
+#ifndef __FreeBSD__
 			close(fd);
 			fd = open(device_name, O_WRONLY);
+#endif
 			oss_set_audio_params();
 			paused = FALSE;
 		}
@@ -583,8 +590,10 @@
 			 */
 
 			ioctl(fd, SNDCTL_DSP_RESET, 0);
+#ifndef __FreeBSD__
 			close(fd);
 			fd = open(device_name, O_WRONLY);
+#endif
 			oss_set_audio_params();
 			output_time_offset = flush;
 			written = ((guint64)flush * input.bps) / 1000;
@@ -597,6 +606,7 @@
 
 	ioctl(fd, SNDCTL_DSP_RESET, 0);
 	close(fd);
+	fd = -1;
 	g_free(buffer);
 	pthread_exit(NULL);
 }
@@ -706,4 +716,9 @@
 	if (!realtime)
 		pthread_create(&buffer_thread, NULL, oss_loop, NULL);
 	return 1;
+}
+
+int oss_get_fd(void)
+{
+	return fd;
 }
--- Output/OSS/mixer.c.orig	Tue Jun 19 04:21:32 2007
+++ Output/OSS/mixer.c	Tue Jun 19 04:21:38 2007
@@ -34,13 +34,20 @@
 
 void oss_get_volume(int *l, int *r)
 {
-	int fd, v, devs;
+	int fd, v, devs, dspfd;
 	long cmd;
 	gchar *devname;
 
-	devname = get_mixer_device();
-	fd = open(devname, O_RDONLY);
-	g_free(devname);
+	dspfd = oss_get_fd();
+	if (oss_cfg.use_master == 0 && dspfd != -1) {
+		fd = dspfd;
+		dspfd = 1;
+	} else {
+		devname = get_mixer_device();
+		fd = open(devname, O_RDONLY);
+		g_free(devname);
+		dspfd = 0;
+	}
 
 	/*
 	 * We dont show any errors if this fails, as this is called
@@ -50,29 +57,40 @@
 	{
 		ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
 		if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master==0))
-			cmd = SOUND_MIXER_READ_PCM;
+			cmd = (dspfd != 0) ? SNDCTL_DSP_GETPLAYVOL :
+			    SOUND_MIXER_READ_PCM;
 		else if ((devs & SOUND_MASK_VOLUME) && (oss_cfg.use_master==1))
 			cmd = SOUND_MIXER_READ_VOLUME;
 		else
 		{
-			close(fd);
+			if (dspfd == 0)
+				close(fd);
 			return;
 		}
 		ioctl(fd, cmd, &v);
 		*r = (v & 0xFF00) >> 8;
 		*l = (v & 0x00FF);
-		close(fd);
+		if (dspfd == 0)
+			close(fd);
 	}
 }
 
 void oss_set_volume(int l, int r)
 {
-	int fd, v, devs;
+	int fd, v, devs, dspfd;
 	long cmd;
 	gchar *devname;
 
-	devname = get_mixer_device();
-	fd = open(devname, O_RDONLY);
+	dspfd = oss_get_fd();
+	if (oss_cfg.use_master == 0 && dspfd != -1) {
+		fd = dspfd;
+		dspfd = 1;
+		devname = g_strdup("<OSS FD>");
+	} else {
+		devname = get_mixer_device();
+		fd = open(devname, O_RDONLY);
+		dspfd = 0;
+	}
 
 	if (fd != -1)
 	{
@@ -83,12 +101,14 @@
 			cmd = SOUND_MIXER_WRITE_VOLUME;
 		else
 		{
-			close(fd);
+			if (dspfd == 0)
+				close(fd);
 			return;
 		}
 		v = (r << 8) | l;
 		ioctl(fd, cmd, &v);
-		close(fd);
+		if (dspfd == 0)
+			close(fd);
 	}
 	else
 		g_warning("oss_set_volume(): Failed to open mixer device (%s): %s",