Mercurial > mplayer.hg
annotate mixer.c @ 1163:ac1341d4a2a7
According an idea, mplayer now can use external setuid root wrapper to do FIBMAP ioctl (requires root priv). Also, a serious bug was fixed in dvdauth.c made by some guy when mixing old and new style CSS API into dvdauth.c ;-)
author | lgb |
---|---|
date | Mon, 18 Jun 2001 23:56:19 +0000 |
parents | 0f7be115a4db |
children | d75b24bda7ce |
rev | line source |
---|---|
441 | 1 |
2 #include <string.h> | |
3 #include <sys/ioctl.h> | |
4 #include <fcntl.h> | |
5 #include <stdio.h> | |
605 | 6 #include <unistd.h> |
441 | 7 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
8 #include "config.h" |
441 | 9 #include "mixer.h" |
10 | |
1061 | 11 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
12 #if defined(USE_OSS_AUDIO) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
13 |
1061 | 14 /* |
15 * Mixer interface using OSS style soundcard commands. | |
16 */ | |
17 | |
18 #include <sys/soundcard.h> | |
19 | |
20 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
21 char * mixer_device=DEV_MIXER; |
441 | 22 int mixer_usemaster=0; |
23 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
24 void mixer_getvolume( float *l,float *r ) |
441 | 25 { |
26 int fd,v,cmd,devs; | |
27 | |
512 | 28 fd=open( mixer_device,O_RDONLY ); |
441 | 29 if ( fd != -1 ) |
30 { | |
31 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); | |
32 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM; | |
33 else | |
34 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME; | |
35 else | |
36 { | |
37 close( fd ); | |
38 return; | |
39 } | |
40 ioctl( fd,cmd,&v ); | |
41 *r=( v & 0xFF00 ) >> 8; | |
42 *l=( v & 0x00FF ); | |
43 close( fd ); | |
44 } | |
45 } | |
46 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
47 void mixer_setvolume( float l,float r ) |
441 | 48 { |
49 int fd,v,cmd,devs; | |
50 | |
512 | 51 fd=open( mixer_device,O_RDONLY ); |
441 | 52 if ( fd != -1 ) |
53 { | |
54 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); | |
55 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM; | |
56 else | |
57 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME; | |
58 else | |
59 { | |
60 close( fd ); | |
61 return; | |
62 } | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
63 v=( (int)r << 8 ) | (int)l; |
441 | 64 ioctl( fd,cmd,&v ); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
65 close( fd ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
66 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
67 } |
1061 | 68 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
69 #elif defined(USE_SUN_AUDIO) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
70 |
1061 | 71 /* |
72 * Mixer interface using Sun style soundcard commands. | |
73 */ | |
74 | |
75 #include <sys/audioio.h> | |
76 | |
77 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
78 char * mixer_device="/dev/audioctl"; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
79 int mixer_usemaster=0; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
80 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
81 void mixer_getvolume( float *l,float *r ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
82 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
83 int fd,v,cmd,devs; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
84 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
85 fd=open( mixer_device,O_RDONLY ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
86 if ( fd != -1 ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
87 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
88 struct audio_info info; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
89 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
90 ioctl( fd,AUDIO_GETINFO,&info); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
91 *r=info.play.gain * 100. / AUDIO_MAX_GAIN; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
92 *l=info.play.gain * 100. / AUDIO_MAX_GAIN; |
441 | 93 close( fd ); |
94 } | |
95 } | |
96 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
97 void mixer_setvolume( float l,float r ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
98 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
99 int fd,v,cmd,devs; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
100 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
101 fd=open( mixer_device,O_RDONLY ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
102 if ( fd != -1 ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
103 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
104 struct audio_info info; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
105 AUDIO_INITINFO(&info); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
106 info.play.gain = (r+l) * AUDIO_MAX_GAIN / 100 / 2; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
107 ioctl( fd,AUDIO_SETINFO,&info ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
108 close( fd ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
109 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
110 } |
1061 | 111 |
112 #else | |
113 | |
114 /* | |
115 * No usable Mixer interface selected. | |
116 * Just some stub routines. | |
117 */ | |
118 | |
119 char * mixer_device=NULL; | |
120 int mixer_usemaster=0; | |
121 | |
122 void mixer_getvolume( float *l,float *r ){ | |
123 *l = *r = 50.0; | |
124 } | |
125 void mixer_setvolume( float l,float r ){ | |
126 } | |
127 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
128 #endif |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
129 |
441 | 130 |
131 void mixer_incvolume( void ) | |
132 { | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
133 float mixer_l, mixer_r; |
441 | 134 mixer_getvolume( &mixer_l,&mixer_r ); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
135 mixer_l++; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
136 if ( mixer_l > 100 ) mixer_l = 100; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
137 mixer_r++; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
138 if ( mixer_r > 100 ) mixer_r = 100; |
441 | 139 mixer_setvolume( mixer_l,mixer_r ); |
140 } | |
141 | |
142 void mixer_decvolume( void ) | |
143 { | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
144 float mixer_l, mixer_r; |
441 | 145 mixer_getvolume( &mixer_l,&mixer_r ); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
146 mixer_l--; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
147 if ( mixer_l < 0 ) mixer_l = 0; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
148 mixer_r--; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
149 if ( mixer_r < 0 ) mixer_r = 0; |
441 | 150 mixer_setvolume( mixer_l,mixer_r ); |
151 } | |
152 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
153 float mixer_getbothvolume( void ) |
441 | 154 { |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
155 float mixer_l, mixer_r; |
441 | 156 mixer_getvolume( &mixer_l,&mixer_r ); |
157 return ( mixer_l + mixer_r ) / 2; | |
158 } |