-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp index 5319d97..db2d63f 100644 --- a/noncore/multimedia/opierec/device.cpp +++ b/noncore/multimedia/opierec/device.cpp | |||
@@ -13,42 +13,42 @@ using namespace Opie::Core; | |||
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | #include <stdlib.h> | 14 | #include <stdlib.h> |
15 | #include <sys/ioctl.h> | 15 | #include <sys/ioctl.h> |
16 | #include <sys/soundcard.h> | 16 | #include <sys/soundcard.h> |
17 | #include <unistd.h> | 17 | #include <unistd.h> |
18 | #include <sys/wait.h> | 18 | #include <sys/wait.h> |
19 | #include <unistd.h> | 19 | #include <unistd.h> |
20 | #include <errno.h> | 20 | #include <errno.h> |
21 | 21 | ||
22 | //extern QtRec *qperec; | 22 | //extern QtRec *qperec; |
23 | 23 | ||
24 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) | 24 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) |
25 | : QObject( parent) | 25 | : QObject( parent) |
26 | { | 26 | { |
27 | dspstr = (char *)dsp; | 27 | dspstr = (char *)dsp; |
28 | mixstr = (char *)mixr; | 28 | mixstr = (char *)mixr; |
29 | 29 | ||
30 | devForm=-1; | 30 | devForm=-1; |
31 | devCh=-1; | 31 | devCh=-1; |
32 | devRate=-1; | 32 | devRate=-1; |
33 | 33 | ||
34 | if( !record){ //playing | 34 | if( !record){ //playing |
35 | odebug << "setting up DSP for playing" << oendl; | 35 | odebug << "setting up DSP for playing" << oendl; |
36 | flags = O_WRONLY; | 36 | flags = O_WRONLY; |
37 | } else { //recording | 37 | } else { //recording |
38 | odebug << "setting up DSP for recording" << oendl; | 38 | odebug << "setting up DSP for recording" << oendl; |
39 | flags = O_RDWR; | 39 | flags = O_RDWR; |
40 | // flags = O_RDONLY; | 40 | // flags = O_RDONLY; |
41 | 41 | ||
42 | // selectMicInput(); | 42 | // selectMicInput(); |
43 | 43 | ||
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | bool Device::openDsp() { | 47 | bool Device::openDsp() { |
48 | if( openDevice( flags) == -1) { | 48 | if( openDevice( flags) == -1) { |
49 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); | 49 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); |
50 | return false; | 50 | return false; |
51 | } | 51 | } |
52 | return true; | 52 | return true; |
53 | } | 53 | } |
54 | 54 | ||
@@ -83,48 +83,48 @@ int Device::getInVolume() { | |||
83 | cfg.setGroup("Volume"); | 83 | cfg.setGroup("Volume"); |
84 | 84 | ||
85 | return cfg.readNumEntry("Mic"); | 85 | return cfg.readNumEntry("Mic"); |
86 | } | 86 | } |
87 | 87 | ||
88 | void Device::changedOutVolume(int vol) { | 88 | void Device::changedOutVolume(int vol) { |
89 | int level = (vol << 8) + vol; | 89 | int level = (vol << 8) + vol; |
90 | int fd = 0; | 90 | int fd = 0; |
91 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 91 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
92 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) | 92 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) |
93 | perror("ioctl(\"MIXER_IN_WRITE\")"); | 93 | perror("ioctl(\"MIXER_IN_WRITE\")"); |
94 | 94 | ||
95 | Config cfg("qpe"); | 95 | Config cfg("qpe"); |
96 | cfg.setGroup("Volume"); | 96 | cfg.setGroup("Volume"); |
97 | cfg.writeEntry("VolumePercent", QString::number( vol )); | 97 | cfg.writeEntry("VolumePercent", QString::number( vol )); |
98 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; | 98 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; |
99 | owarn << "changing output vol " << vol << "" << oendl; | 99 | owarn << "changing output vol " << vol << "" << oendl; |
100 | } | 100 | } |
101 | ::close(fd); | 101 | ::close(fd); |
102 | } | 102 | } |
103 | 103 | ||
104 | void Device::changedInVolume(int vol ) { | 104 | void Device::changedInVolume(int vol ) { |
105 | int level = (vol << 8) + vol; | 105 | int level = (vol << 8) + vol; |
106 | int fd = 0; | 106 | int fd = 0; |
107 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 107 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
108 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) | 108 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) |
109 | perror("ioctl(\"MIXER_IN_WRITE\")"); | 109 | perror("ioctl(\"MIXER_IN_WRITE\")"); |
110 | Config cfg("qpe"); | 110 | Config cfg("qpe"); |
111 | cfg.setGroup("Volume"); | 111 | cfg.setGroup("Volume"); |
112 | cfg.writeEntry("Mic", QString::number(vol )); | 112 | cfg.writeEntry("Mic", QString::number(vol )); |
113 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; | 113 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; |
114 | owarn << "changing input volume " << vol << "" << oendl; | 114 | owarn << "changing input volume " << vol << "" << oendl; |
115 | } | 115 | } |
116 | ::close(fd); | 116 | ::close(fd); |
117 | } | 117 | } |
118 | 118 | ||
119 | bool Device::selectMicInput() { | 119 | bool Device::selectMicInput() { |
120 | 120 | ||
121 | int md=0; | 121 | int md=0; |
122 | int info=MIXER_WRITE(SOUND_MIXER_MIC); | 122 | int info=MIXER_WRITE(SOUND_MIXER_MIC); |
123 | md = ::open( "/dev/mixer", O_RDWR ); | 123 | md = ::open( "/dev/mixer", O_RDWR ); |
124 | if ( md == -1) | 124 | if ( md == -1) |
125 | perror("open(\"/dev/mixer\")"); | 125 | perror("open(\"/dev/mixer\")"); |
126 | else { | 126 | else { |
127 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | 127 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) |
128 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | 128 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); |
129 | ::close(md); | 129 | ::close(md); |
130 | return false; | 130 | return false; |
@@ -136,139 +136,139 @@ bool Device::selectMicInput() { | |||
136 | 136 | ||
137 | int Device::openDevice( int flags) { | 137 | int Device::openDevice( int flags) { |
138 | /* pid_t pid; | 138 | /* pid_t pid; |
139 | int status; | 139 | int status; |
140 | int pipefd[2]; | 140 | int pipefd[2]; |
141 | char message[20]; | 141 | char message[20]; |
142 | if (pipe(pipefd) == -1){ | 142 | if (pipe(pipefd) == -1){ |
143 | perror ("Error creating pipe"); | 143 | perror ("Error creating pipe"); |
144 | exit(1); | 144 | exit(1); |
145 | } | 145 | } |
146 | switch (pid = fork()) { | 146 | switch (pid = fork()) { |
147 | case -1: | 147 | case -1: |
148 | perror("The fork failed!"); | 148 | perror("The fork failed!"); |
149 | break; | 149 | break; |
150 | case 0: { | 150 | case 0: { |
151 | */ | 151 | */ |
152 | odebug << "Opening " << dspstr << "" << oendl; | 152 | odebug << "Opening " << dspstr << "" << oendl; |
153 | if (( sd = ::open( dspstr, flags)) == -1) { | 153 | if (( sd = ::open( dspstr, flags)) == -1) { |
154 | perror("open(\"/dev/dsp\")"); | 154 | perror("open(\"/dev/dsp\")"); |
155 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | 155 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
156 | +(QString)strerror(errno); | 156 | +(QString)strerror(errno); |
157 | odebug << "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl; | 157 | odebug << "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl; |
158 | return -1; | 158 | return -1; |
159 | } | 159 | } |
160 | 160 | ||
161 | odebug << "Opening mixer" << oendl; | 161 | odebug << "Opening mixer" << oendl; |
162 | int mixerHandle=0; | 162 | int mixerHandle=0; |
163 | if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) { | 163 | if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) { |
164 | perror("open(\"/dev/mixer\")"); | 164 | perror("open(\"/dev/mixer\")"); |
165 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | 165 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
166 | +(QString)strerror(errno); | 166 | +(QString)strerror(errno); |
167 | odebug << "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl; | 167 | odebug << "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl; |
168 | } | 168 | } |
169 | 169 | ||
170 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ | 170 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ |
171 | perror("ioctl RESET"); | 171 | perror("ioctl RESET"); |
172 | } | 172 | } |
173 | // sprintf(message, "%d", sd); | 173 | // sprintf(message, "%d", sd); |
174 | 174 | ||
175 | /* QFile f1("/pid"); | 175 | /* QFile f1("/pid"); |
176 | f1.open(IO_WriteOnly ); | 176 | f1.open(IO_WriteOnly ); |
177 | f1.writeBlock(message, strlen(message)); | 177 | f1.writeBlock(message, strlen(message)); |
178 | f1.close(); | 178 | f1.close(); |
179 | */ | 179 | */ |
180 | /* close(pipefd[0]); | 180 | /* close(pipefd[0]); |
181 | write(pipefd[1], message, sizeof(message)); | 181 | write(pipefd[1], message, sizeof(message)); |
182 | close(pipefd[1]); | 182 | close(pipefd[1]); |
183 | // odebug << "" << soundDevice->sd << "" << oendl; | 183 | // odebug << "" << soundDevice->sd << "" << oendl; |
184 | _exit(0); | 184 | _exit(0); |
185 | } | 185 | } |
186 | default: | 186 | default: |
187 | // pid greater than zero is parent getting the child's pid | 187 | // pid greater than zero is parent getting the child's pid |
188 | printf("Child's pid is %d\n",pid); | 188 | printf("Child's pid is %d\n",pid); |
189 | QString s; | 189 | QString s; |
190 | close(pipefd[1]); | 190 | close(pipefd[1]); |
191 | read(pipefd[0], message, sizeof(message)); | 191 | read(pipefd[0], message, sizeof(message)); |
192 | s = message; | 192 | s = message; |
193 | close(pipefd[0]); | 193 | close(pipefd[0]); |
194 | 194 | ||
195 | // while(wait(NULL)!=pid) | 195 | // while(wait(NULL)!=pid) |
196 | // ; | 196 | // ; |
197 | printf("child %ld terminated normally, return status is zero\n", (long) pid); | 197 | printf("child %ld terminated normally, return status is zero\n", (long) pid); |
198 | */ | 198 | */ |
199 | // filePara.sd=(long) pid; | 199 | // filePara.sd=(long) pid; |
200 | /* QFile f2("/pid"); | 200 | /* QFile f2("/pid"); |
201 | f2.open(IO_ReadOnly); | 201 | f2.open(IO_ReadOnly); |
202 | QTextStream t(&f2); | 202 | QTextStream t(&f2); |
203 | // for(int f=0; f < t.atEnd() ;f++) { | 203 | // for(int f=0; f < t.atEnd() ;f++) { |
204 | s = t.readLine(); | 204 | s = t.readLine(); |
205 | // } | 205 | // } |
206 | */ | 206 | */ |
207 | // bool ok; | 207 | // bool ok; |
208 | // sd = s.toInt(&ok, 10); | 208 | // sd = s.toInt(&ok, 10); |
209 | // odebug << "<<<<<<<<<<<<<>>>>>>>>>>>>"+s << oendl; | 209 | // odebug << "<<<<<<<<<<<<<>>>>>>>>>>>>"+s << oendl; |
210 | 210 | ||
211 | // f2.close(); | 211 | // f2.close(); |
212 | // } | 212 | // } |
213 | ::close(mixerHandle ); | 213 | ::close(mixerHandle ); |
214 | // odebug << "open device " << dspstr << "" << oendl; | 214 | // odebug << "open device " << dspstr << "" << oendl; |
215 | // odebug << "success! " << sd << "" << oendl; | 215 | // odebug << "success! " << sd << "" << oendl; |
216 | return sd; | 216 | return sd; |
217 | } | 217 | } |
218 | 218 | ||
219 | bool Device::closeDevice( bool) { | 219 | bool Device::closeDevice( bool) { |
220 | // if(b) {//close now | 220 | // if(b) {//close now |
221 | // if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 221 | // if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
222 | // perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 222 | // perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
223 | // } | 223 | // } |
224 | // } else { //let play | 224 | // } else { //let play |
225 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { | 225 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { |
226 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); | 226 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); |
227 | // } | 227 | // } |
228 | // } | 228 | // } |
229 | 229 | ||
230 | ::close( sd); //close sound device | 230 | ::close( sd); //close sound device |
231 | // sdfd=0; | 231 | // sdfd=0; |
232 | // sd=0; | 232 | // sd=0; |
233 | // odebug << "closed dsp" << oendl; | 233 | // odebug << "closed dsp" << oendl; |
234 | return true; | 234 | return true; |
235 | } | 235 | } |
236 | 236 | ||
237 | bool Device::setDeviceFormat( int form) { | 237 | bool Device::setDeviceFormat( int form) { |
238 | odebug << "set device res " << form << " " << sd << "" << oendl; | 238 | odebug << "set device res " << form << " " << sd << "" << oendl; |
239 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format | 239 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format |
240 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 240 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
241 | return false; | 241 | return false; |
242 | } | 242 | } |
243 | devRes=form; | 243 | devRes=form; |
244 | return true; | 244 | return true; |
245 | } | 245 | } |
246 | 246 | ||
247 | bool Device::setDeviceChannels( int ch) { | 247 | bool Device::setDeviceChannels( int ch) { |
248 | odebug << "set channels " << ch << " " << sd << "" << oendl; | 248 | odebug << "set channels " << ch << " " << sd << "" << oendl; |
249 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { | 249 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { |
250 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 250 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
251 | return false; | 251 | return false; |
252 | } | 252 | } |
253 | devCh=ch; | 253 | devCh=ch; |
254 | return true; | 254 | return true; |
255 | } | 255 | } |
256 | 256 | ||
257 | bool Device::setDeviceRate( int rate) { | 257 | bool Device::setDeviceRate( int rate) { |
258 | odebug << "set rate " << rate << " " << sd << "" << oendl; | 258 | odebug << "set rate " << rate << " " << sd << "" << oendl; |
259 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { | 259 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { |
260 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 260 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
261 | return false; | 261 | return false; |
262 | } | 262 | } |
263 | 263 | ||
264 | devRate=rate; | 264 | devRate=rate; |
265 | 265 | ||
266 | return true; | 266 | return true; |
267 | } | 267 | } |
268 | 268 | ||
269 | int Device::getRes() { | 269 | int Device::getRes() { |
270 | return devRes; | 270 | return devRes; |
271 | } | 271 | } |
272 | 272 | ||
273 | int Device::getFormat() { | 273 | int Device::getFormat() { |
274 | return devForm; | 274 | return devForm; |
@@ -303,56 +303,56 @@ int Device::getDeviceBits() { | |||
303 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); | 303 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); |
304 | } | 304 | } |
305 | #endif | 305 | #endif |
306 | return dBits; | 306 | return dBits; |
307 | } | 307 | } |
308 | 308 | ||
309 | int Device::getDeviceChannels() { | 309 | int Device::getDeviceChannels() { |
310 | int dCh=0; | 310 | int dCh=0; |
311 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { | 311 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { |
312 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); | 312 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); |
313 | } | 313 | } |
314 | return dCh; | 314 | return dCh; |
315 | } | 315 | } |
316 | 316 | ||
317 | int Device::getDeviceFragSize() { | 317 | int Device::getDeviceFragSize() { |
318 | int frag_size; | 318 | int frag_size; |
319 | 319 | ||
320 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { | 320 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { |
321 | odebug << "no fragsize" << oendl; | 321 | odebug << "no fragsize" << oendl; |
322 | } else { | 322 | } else { |
323 | odebug << "driver says frag size is " << frag_size << "" << oendl; | 323 | odebug << "driver says frag size is " << frag_size << "" << oendl; |
324 | } | 324 | } |
325 | return frag_size; | 325 | return frag_size; |
326 | } | 326 | } |
327 | 327 | ||
328 | bool Device::setFragSize(int frag) { | 328 | bool Device::setFragSize(int frag) { |
329 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { | 329 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { |
330 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 330 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
331 | return false; | 331 | return false; |
332 | } | 332 | } |
333 | return true; | 333 | return true; |
334 | } | 334 | } |
335 | 335 | ||
336 | bool Device::reset() { | 336 | bool Device::reset() { |
337 | closeDevice(true); | 337 | closeDevice(true); |
338 | openDsp(); | 338 | openDsp(); |
339 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 339 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
340 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 340 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
341 | return false; | 341 | return false; |
342 | } | 342 | } |
343 | return true; | 343 | return true; |
344 | } | 344 | } |
345 | 345 | ||
346 | int Device::devRead(int soundDescriptor, short *buf, int size) { | 346 | int Device::devRead(int soundDescriptor, short *buf, int size) { |
347 | int number = 0; | 347 | int number = 0; |
348 | number = ::read( soundDescriptor, (char *)buf, size); | 348 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); |
349 | return number; | 349 | return number; |
350 | } | 350 | } |
351 | 351 | ||
352 | int Device::devWrite(int soundDescriptor, short * buf, int size) { | 352 | int Device::devWrite(int soundDescriptor, short * buf, int size) { |
353 | int bytesWritten = 0; | 353 | int bytesWritten = 0; |
354 | bytesWritten = ::write( soundDescriptor, buf, size); | 354 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); |
355 | return bytesWritten; | 355 | return bytesWritten; |
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||