Debian Codegraph @

src/libout123/modules/os2.c

raw
1 /*
2 os2: OS/2 RealTime DART Engine
3
4 copyright 1998-2020 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 initially written by Samuel Audet
7 */
8
9 #include "../out123_int.h"
10
11 #undef VERSION /* The VERSION macro conflicts with the OS/2 multimedia headers */
12
13 #define INCL_OS2MM
14 #define INCL_DOS
15 #define INCL_VIO
16 #define INCL_KBD
17 #include <os2safe.h>
18 #include <os2.h>
19 #include <os2me.h>
20 #include <stdlib.h>
21 #include <ctype.h>
22
23 #include "../../common/debug.h"
24
25 // Only one instance at a time! This all needs to go into userptr!
26 static BOOL opened = FALSE;
27
28 /* complementary audio parameters */
29 static int numbuffers = 8; /* total audio buffers, _bare_ minimum = 4 (cuz of prio boost check) */
30 #define audiobufsize 4096
31 static int lockdevice = FALSE;
32 static USHORT volume = 100;
33 static char *boostprio = NULL;
34 static char *normalprio = NULL;
35 static unsigned char boostclass = 3, normalclass = 2;
36 static signed char boostdelta = 0, normaldelta = 31;
37 static unsigned char mmerror[160] = {0};
38 static int playingframe;
39
40 /* audio buffers */
41 static ULONG ulMCIBuffers;
42
43 static MCI_AMP_OPEN_PARMS maop = {0};
44 static MCI_MIXSETUP_PARMS mmp = {0};
45 static MCI_BUFFER_PARMS mbp = {0};
46 static MCI_GENERIC_PARMS mgp = {0};
47 static MCI_SET_PARMS msp = {0};
48 static MCI_STATUS_PARMS mstatp = {0};
49 static MCI_MIX_BUFFER *MixBuffers = NULL;
50
51 struct prebuf
52 {
53 unsigned char d[audiobufsize]; // data area
54 int fill; // number of bytes in there
55 };
56 // Being lazy for draining.
57 static unsigned char zbuf[audiobufsize] = {0};
58
59 typedef struct
60 {
61 MCI_MIX_BUFFER *NextBuffer;
62 int frameNum;
63 } BUFFERINFO;
64
65 // This static business is EVIL!
66 // All this needs to go into userptr to allow multiple instances.
67
68 static BUFFERINFO *bufferinfo = NULL;
69
70
71 static HEV dataplayed = 0;
72 static ULONG resetcount;
73 static BOOL paused = FALSE;
74
75 static MCI_MIX_BUFFER *tobefilled, *playingbuffer = NULL, playedbuffer;
76 static void *pBufferplayed;
77
78 static BOOL nomoredata,nobuffermode,justflushed;
79
80 static TIB *mainthread; /* thread info to set thread priority */
81
82 static ULONG keyboardtid;
83
84
85 static LONG APIENTRY DARTEvent(ULONG ulStatus, MCI_MIX_BUFFER *PlayedBuffer, ULONG ulFlags)
86 {
87 switch(ulFlags)
88 {
89 case MIX_STREAM_ERROR | MIX_WRITE_COMPLETE: /* error occur in device */
90
91 if ( ulStatus == ERROR_DEVICE_UNDERRUN)
92 /* Write buffers to rekick off the amp mixer. */
93 mmp.pmixWrite( mmp.ulMixHandle, MixBuffers, ulMCIBuffers );
94 break;
95
96 case MIX_WRITE_COMPLETE: /* for playback */
97
98 playingbuffer = ((BUFFERINFO *) PlayedBuffer->ulUserParm)->NextBuffer;
99
100 /* the next three lines are only useful to audio_playing_samples() */
101 playedbuffer = *PlayedBuffer;
102 playedbuffer.pBuffer = pBufferplayed;
103 memcpy(playedbuffer.pBuffer, PlayedBuffer->pBuffer, PlayedBuffer->ulBufferLength);
104
105 /* just too bad, the decoder fell behind... here we just keep the
106 buffer to be filled in front of the playing one so that when the
107 decoder kicks back in, we'll hear it in at the right time */
108 if(tobefilled == playingbuffer)
109 {
110 tobefilled = ((BUFFERINFO *) playingbuffer->ulUserParm)->NextBuffer;
111 nomoredata = TRUE;
112 }
113 else
114 {
115 playingframe = ((BUFFERINFO *) playingbuffer->ulUserParm)->frameNum;
116
117 /* if we're about to be short of decoder's data
118 (2nd ahead buffer not filled), let's boost its priority! */
119 if(tobefilled == ( (BUFFERINFO *) ((BUFFERINFO *) playingbuffer->ulUserParm)->NextBuffer->ulUserParm)->NextBuffer)
120 DosSetPriority(PRTYS_THREAD,boostclass,boostdelta,mainthread->tib_ptib2->tib2_ultid);
121 }
122
123 /* empty the played buffer in case it doesn't get filled back */
124 memset(PlayedBuffer->pBuffer,0,PlayedBuffer->ulBufferLength);
125
126 DosPostEventSem(dataplayed);
127
128 mmp.pmixWrite( mmp.ulMixHandle, PlayedBuffer, 1 );
129 break;
130
131 } /* end switch */
132
133 return( TRUE );
134
135 } /* end DARTEvent */
136
137
138 static void MciError(ULONG ulError, int quiet)
139 {
140 unsigned char buffer[128];
141 ULONG rc;
142
143 rc = mciGetErrorString(ulError, buffer, sizeof(buffer));
144
145 if (rc == MCIERR_SUCCESS)
146 sprintf(mmerror,"MCI Error %d: %s",ULONG_LOWD(ulError),buffer);
147 else
148 sprintf(mmerror,"MCI Error %d: Cannot query error message.",ULONG_LOWD(rc));
149 if(!quiet)
150 error1("%s",mmerror);
151 }
152
153
154 static int set_volume(out123_handle *ao, USHORT setvolume)
155 {
156 if(setvolume > 100) setvolume = 100;
157 volume = setvolume; /* useful when device is closed and reopened */
158
159 if(maop.usDeviceID)
160 {
161 memset(&msp,0,sizeof(msp));
162 msp.ulAudio = MCI_SET_AUDIO_ALL;
163 msp.ulLevel = setvolume;
164
165 mciSendCommand(maop.usDeviceID, MCI_SET,
166 MCI_WAIT | MCI_SET_AUDIO | MCI_SET_VOLUME,
167 &msp, 0);
168 }
169 return setvolume;
170 }
171
172
173 int open_os2(out123_handle *ao)
174 {
175 if(opened)
176 return -1;
177
178 ULONG rc,i;
179 char *temp;
180 ULONG openflags;
181 PPIB ppib;
182 USHORT bits;
183 const char *dev = ao->device;
184 struct prebuf *pb = NULL;
185
186 if(maop.usDeviceID) return (maop.usDeviceID);
187
188 if(!ao) return -1;
189
190 if(!dev) dev = "0";
191
192 if(ao->rate < 0) ao->rate = 44100;
193 if(ao->channels < 0) ao->channels = 2;
194 if(ao->format < 0) ao->format = MPG123_ENC_SIGNED_16;
195
196 if(ao->format == MPG123_ENC_SIGNED_16)
197 bits = 16;
198 else if(ao->format == MPG123_ENC_UNSIGNED_8)
199 bits = 8;
200 else return -1;
201
202 ao->userptr = malloc(sizeof(struct prebuf));
203 if(!ao->userptr)
204 return -1;
205 pb = (struct prebuf*)ao->userptr;
206 pb->fill = 0;
207
208 /* open the mixer device */
209 memset (&maop, 0, sizeof(maop));
210 maop.usDeviceID = 0;
211 maop.pszDeviceType = (PSZ) MAKEULONG(MCI_DEVTYPE_AUDIO_AMPMIX, atoi(dev));
212
213 openflags = MCI_WAIT | MCI_OPEN_TYPE_ID;
214 if(!lockdevice) openflags |= MCI_OPEN_SHAREABLE;
215
216 rc = mciSendCommand(0, MCI_OPEN, openflags, &maop, 0);
217
218 if (ULONG_LOWD(rc) != MCIERR_SUCCESS)
219 {
220 MciError(rc, AOQUIET);
221 maop.usDeviceID = 0;
222 return(-1);
223 }
224
225 /* volume in ao->gain ?? */
226
227 /* Set the MCI_MIXSETUP_PARMS data structure to match the audio stream. */
228
229 memset(&mmp, 0, sizeof(mmp));
230
231 mmp.ulBitsPerSample = bits;
232 mmp.ulFormatTag = MCI_WAVE_FORMAT_PCM;
233 mmp.ulSamplesPerSec = ao->rate;
234 mmp.ulChannels = ao->channels;
235
236 /* Setup the mixer for playback of wave data */
237 mmp.ulFormatMode = MCI_PLAY;
238 mmp.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
239 mmp.pmixEvent = DARTEvent;
240
241 rc = mciSendCommand( maop.usDeviceID,
242 MCI_MIXSETUP,
243 MCI_WAIT | MCI_MIXSETUP_INIT,
244 &mmp,
245 0 );
246
247 if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
248 {
249 MciError(rc, AOQUIET);
250 maop.usDeviceID = 0;
251 return(-1);
252 }
253
254 volume = set_volume(ao,volume);
255
256 /* Set up the BufferParms data structure and allocate
257 * device buffers from the Amp-Mixer */
258
259 memset(&mbp, 0, sizeof(mbp));
260 free(MixBuffers);
261 free(bufferinfo);
262 if(numbuffers < 5) numbuffers = 5;
263 if(numbuffers > 200) numbuffers = 200;
264 MixBuffers = calloc(numbuffers, sizeof(*MixBuffers));
265 bufferinfo = calloc(numbuffers, sizeof(*bufferinfo));
266
267 ulMCIBuffers = numbuffers;
268 mbp.ulNumBuffers = ulMCIBuffers;
269 /* mbp.ulBufferSize = mmp.ulBufferSize; */
270 /* I don't like this... they must be smaller than 64KB or else the
271 engine needs major rewrite */
272 mbp.ulBufferSize = audiobufsize;
273 mbp.pBufList = MixBuffers;
274
275 rc = mciSendCommand( maop.usDeviceID,
276 MCI_BUFFER,
277 MCI_WAIT | MCI_ALLOCATE_MEMORY,
278 (PVOID) &mbp,
279 0 );
280
281 if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
282 {
283 MciError(rc, AOQUIET);
284 maop.usDeviceID = 0;
285 return(-1);
286 }
287
288 pBufferplayed = playedbuffer.pBuffer = calloc(1,audiobufsize);
289
290 ulMCIBuffers = mbp.ulNumBuffers; /* never know! */
291
292 /* Fill all device buffers with zeros and set linked list */
293
294 for(i = 0; i < ulMCIBuffers; i++)
295 {
296 MixBuffers[i].ulFlags = 0;
297 MixBuffers[i].ulBufferLength = mbp.ulBufferSize;
298 memset(MixBuffers[i].pBuffer, 0, MixBuffers[i].ulBufferLength);
299
300 MixBuffers[i].ulUserParm = (ULONG) &bufferinfo[i];
301 bufferinfo[i].NextBuffer = &MixBuffers[i+1];
302 }
303
304 bufferinfo[i-1].NextBuffer = &MixBuffers[0];
305
306 /* Create a semaphore to know when data has been played by the DART thread */
307 DosCreateEventSem(NULL,&dataplayed,0,FALSE);
308
309 playingbuffer = &MixBuffers[0];
310 tobefilled = &MixBuffers[1];
311 playingframe = 0;
312 nomoredata = TRUE;
313 nobuffermode = FALSE;
314 justflushed = FALSE;
315
316 if(boostprio)
317 {
318 temp = alloca(strlen(boostprio)+1);
319 strcpy(temp,boostprio);
320
321 boostdelta = atoi(temp+1);
322 *(temp+1) = 0;
323 boostclass = atoi(temp);
324 }
325 if(boostclass > 4) boostdelta = 3;
326 if(boostdelta > 31) boostdelta = 31;
327 if(boostdelta < -31) boostdelta = -31;
328
329
330 if(normalprio)
331 {
332 temp = alloca(strlen(normalprio)+1);
333 strcpy(temp,normalprio);
334
335 normaldelta = atoi(temp+1);
336 *(temp+1) = 0;
337 normalclass = atoi(temp);
338 }
339 if(normalclass > 4) normaldelta = 3;
340 if(normaldelta > 31) normaldelta = 31;
341 if(normaldelta < -31) normaldelta = -31;
342
343
344 DosGetInfoBlocks(&mainthread,&ppib); /* ppib not needed, but makes some DOSCALLS.DLL crash */
345 DosSetPriority(PRTYS_THREAD,boostclass,boostdelta,mainthread->tib_ptib2->tib2_ultid);
346
347 /* Write buffers to kick off the amp mixer. see DARTEvent() */
348 rc = mmp.pmixWrite( mmp.ulMixHandle,
349 MixBuffers,
350 ulMCIBuffers );
351
352 opened = TRUE;
353 return maop.usDeviceID;
354 }
355
356 // Always write full blocks of audiobufsize. The engine does not like
357 // things otherwise. Using a local prebuffer for the leftovers.
358
359 static int write_os2(out123_handle *ao,unsigned char *buf,int len)
360 {
361 int written = 0;
362 struct prebuf *pb = ao->userptr;
363 mdebug("write_os2(%p, %p, %d)", ao, buf, len);
364 while(len > 0)
365 {
366 if(len + pb->fill < audiobufsize)
367 {
368 mdebug("storing into pb %p @ %p, %d on top of %d", pb->d, pb->d+pb->fill, len, pb->fill);
369 // just collect until we got a full buffer
370 memcpy(pb->d + pb->fill, buf, len);
371 pb->fill += len;
372 written += len;
373 break;
374 }
375 // Now, we at least got one full buffer to serve.
376
377 /* if we're too quick, let's wait */
378 if(nobuffermode)
379 {
380 MCI_MIX_BUFFER *temp = playingbuffer;
381
382 while(
383 (tobefilled != (temp = ((BUFFERINFO *) temp->ulUserParm)->NextBuffer)) &&
384 (tobefilled != (temp = ((BUFFERINFO *) temp->ulUserParm)->NextBuffer)) &&
385 (tobefilled != (temp = ((BUFFERINFO *) temp->ulUserParm)->NextBuffer)) )
386 {
387 DosResetEventSem(dataplayed,&resetcount);
388 DosWaitEventSem(dataplayed, -1);
389 temp = playingbuffer;
390 }
391
392 } else {
393 while(tobefilled == playingbuffer)
394 {
395 DosResetEventSem(dataplayed,&resetcount);
396 DosWaitEventSem(dataplayed, -1);
397 }
398 }
399
400 if (justflushed) {
401 justflushed = FALSE;
402 } else {
403 nomoredata = FALSE;
404 int got = 0;
405 // First the rest from the prebuffer, then the remaining part from the new stuff.
406 if(pb->fill)
407 {
408 mdebug("copy all %d bytes of prebuffer from %p to %p", pb->fill, pb->d, tobefilled->pBuffer);
409 memcpy(tobefilled->pBuffer, pb->d, pb->fill);
410 got = pb->fill;
411 pb->fill = 0;
412 }
413 int therest = audiobufsize - got;
414 // len + got >= audiobufsize!!
415 mdebug("copy therest %d from %p to %p", therest, buf, ((unsigned char*)tobefilled->pBuffer)+got);
416 memcpy(((unsigned char*)tobefilled->pBuffer)+got, buf, therest);
417 debug("done with buffer writes");
418 buf += therest;
419 len -= therest;
420 written += therest;
421 tobefilled->ulBufferLength = got+therest; // always == audiobufsize!
422 // ((BUFFERINFO *) tobefilled->ulUserParm)->frameNum = fr->frameNum;
423
424 /* if we're out of the water (3rd ahead buffer filled),
425 let's reduce our priority */
426 if(tobefilled == ( (BUFFERINFO *) ( (BUFFERINFO *) ((BUFFERINFO *) playingbuffer->ulUserParm)->NextBuffer->ulUserParm)->NextBuffer->ulUserParm)->NextBuffer)
427 DosSetPriority(PRTYS_THREAD,normalclass,normaldelta,mainthread->tib_ptib2->tib2_ultid);
428
429 tobefilled = ((BUFFERINFO *) tobefilled->ulUserParm)->NextBuffer;
430 }
431 }
432 return written;
433 }
434
435 #if 0
436 static int write_os2(out123_handle *ao,unsigned char *buf,int len)
437 {
438 if(len > audiobufsize || !playingbuffer) return -1;
439
440 if(mmp.ulBitsPerSample == 16)
441 ao->format = MPG123_ENC_SIGNED_16;
442 else if(mmp.ulBitsPerSample == 8)
443 ao->format = MPG123_ENC_UNSIGNED_8;
444 else return -1;
445
446 ao->rate = mmp.ulSamplesPerSec;
447 ao->channels = mmp.ulChannels;
448
449 if(buf && len)
450 {
451 ULONG rc;
452 int upto;
453
454 mstatp.ulItem = MCI_STATUS_POSITION;
455
456 rc = mciSendCommand( maop.usDeviceID,
457 MCI_STATUS,
458 MCI_STATUS_ITEM | MCI_WAIT,
459 &mstatp,
460 0 );
461
462 if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
463 {
464 MciError(rc, AOQUIET);
465 maop.usDeviceID = 0;
466 return(-1);
467 }
468
469 /* this is hypocrite...
470 DART returns the value in ulReturn instead of ulValue,
471 also it returns in milliseconds and not MMTIME... arg */
472
473 upto = (mstatp.ulReturn-playedbuffer.ulTime) * mmp.ulSamplesPerSec / 1000;
474 upto *= mmp.ulChannels * (mmp.ulBitsPerSample>>3);
475
476 /* if a timing problem occurs, let's at least not crash */
477 if(upto > playingbuffer->ulBufferLength)
478 upto = playingbuffer->ulBufferLength;
479
480 if(len < upto) {
481 memcpy(buf,(char *) (playingbuffer->pBuffer)+upto-len, len);
482 } else {
483 memcpy(buf,(char *) playedbuffer.pBuffer+playedbuffer.ulBufferLength-(len-upto),len-upto);
484 memcpy(buf+(len-upto),playingbuffer->pBuffer,upto);
485 }
486 }
487
488 return 0;
489 }
490 #endif
491
492 /*
493 static int audio_nobuffermode(out123_handle *ao, int setnobuffermode)
494 {
495 nobuffermode = setnobuffermode;
496 return TRUE;
497 }
498
499 int audio_trash_buffers(out123_handle *ao)
500 {
501 int i;
502
503 justflushed = TRUE;
504
505 // Fill all device buffers with zeros
506 for(i = 0; i < ulMCIBuffers; i++)
507 memset(MixBuffers[i].pBuffer, 0, MixBuffers[i].ulBufferLength);
508
509 tobefilled = ((BUFFERINFO *) playingbuffer->ulUserParm)->NextBuffer;
510 nomoredata = TRUE;
511
512 return TRUE;
513 }
514 */
515
516 static int close_os2(out123_handle *ao)
517 {
518 opened = FALSE;
519 if(ao && ao->userptr)
520 {
521 free(ao->userptr);
522 ao->userptr = NULL;
523 }
524 ULONG rc;
525
526 if(!maop.usDeviceID)
527 return 0;
528
529 while(!nomoredata)
530 {
531 DosResetEventSem(dataplayed,&resetcount);
532 DosWaitEventSem(dataplayed, -1);
533 }
534
535 playingbuffer = NULL;
536
537 DosCloseEventSem(dataplayed);
538 dataplayed = 0;
539
540 free(pBufferplayed);
541
542 rc = mciSendCommand( maop.usDeviceID,
543 MCI_BUFFER,
544 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
545 &mbp,
546 0 );
547
548 if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
549 {
550 MciError(rc, AOQUIET);
551 return(-1);
552 }
553
554 free(bufferinfo);
555 free(MixBuffers);
556 bufferinfo = NULL;
557 MixBuffers = NULL;
558
559 memset(&mbp, 0, sizeof(mbp));
560
561 rc = mciSendCommand( maop.usDeviceID,
562 MCI_CLOSE,
563 MCI_WAIT ,
564 &mgp,
565 0 );
566
567 if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
568 {
569 MciError(rc, AOQUIET);
570 return(-1);
571 }
572
573 memset(&maop, 0, sizeof(maop));
574
575 return 0;
576 }
577
578
579 /*
580 * get formats for specific channel/rate parameters
581 */
582 int get_formats_os2(out123_handle *ao)
583 {
584 int fmts = 0;
585 ULONG rc;
586 MCI_MIXSETUP_PARMS mmptemp = {0};
587
588 mmp.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
589 mmp.pmixEvent = DARTEvent;
590
591 mmptemp.ulFormatMode = MCI_PLAY;
592 mmptemp.ulSamplesPerSec = ao->rate;
593 mmptemp.ulChannels = ao->channels;
594
595 mmptemp.ulFormatTag = MCI_WAVE_FORMAT_PCM;
596 mmptemp.ulBitsPerSample = 16;
597 rc = mciSendCommand( maop.usDeviceID,
598 MCI_MIXSETUP,
599 MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
600 &mmptemp,
601 0 );
602
603 if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
604 fmts = fmts | MPG123_ENC_SIGNED_16;
605
606 mmptemp.ulFormatTag = MCI_WAVE_FORMAT_PCM;
607 mmptemp.ulBitsPerSample = 8;
608 rc = mciSendCommand( maop.usDeviceID,
609 MCI_MIXSETUP,
610 MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
611 &mmptemp,
612 0 );
613
614 if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
615 fmts = fmts | MPG123_ENC_UNSIGNED_8;
616
617 mmptemp.ulFormatTag = MCI_WAVE_FORMAT_ALAW;
618 mmptemp.ulBitsPerSample = 8;
619 rc = mciSendCommand( maop.usDeviceID,
620 MCI_MIXSETUP,
621 MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
622 &mmptemp,
623 0 );
624
625 if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
626 fmts = fmts | MPG123_ENC_ALAW_8;
627
628 mmptemp.ulFormatTag = MCI_WAVE_FORMAT_MULAW;
629 mmptemp.ulBitsPerSample = 8;
630 rc = mciSendCommand( maop.usDeviceID,
631 MCI_MIXSETUP,
632 MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
633 &mmptemp,
634 0 );
635
636 if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
637 fmts = fmts | MPG123_ENC_ULAW_8;
638
639 return fmts;
640 }
641
642 static int get_devices_os2(char *info, int deviceid)
643 {
644 char buffer[128];
645 MCI_SYSINFO_PARMS mip;
646
647 if(deviceid && info)
648 {
649 MCI_SYSINFO_LOGDEVICE mid;
650
651 mip.pszReturn = buffer;
652 mip.ulRetSize = sizeof(buffer);
653 mip.usDeviceType = MCI_DEVTYPE_AUDIO_AMPMIX;
654 mip.ulNumber = deviceid;
655
656 mciSendCommand(0,
657 MCI_SYSINFO,
658 MCI_WAIT | MCI_SYSINFO_INSTALLNAME,
659 &mip,
660 0);
661
662 mip.ulItem = MCI_SYSINFO_QUERY_DRIVER;
663 mip.pSysInfoParm = &mid;
664 strcpy(mid.szInstallName,buffer);
665
666 mciSendCommand(0,
667 MCI_SYSINFO,
668 MCI_WAIT | MCI_SYSINFO_ITEM,
669 &mip,
670 0);
671
672 strcpy(info,mid.szProductInfo);
673 return deviceid;
674
675 } else {
676 int number;
677
678 mip.pszReturn = buffer;
679 mip.ulRetSize = sizeof(buffer);
680 mip.usDeviceType = MCI_DEVTYPE_AUDIO_AMPMIX;
681
682 mciSendCommand(0,
683 MCI_SYSINFO,
684 MCI_WAIT | MCI_SYSINFO_QUANTITY,
685 &mip,
686 0);
687
688 number = atoi(mip.pszReturn);
689 return number;
690 }
691 }
692
693 // at least drain out our prebuffer, proper draining
694 // should be (re?)enabled, too
695 static void drain_os2(out123_handle *ao)
696 {
697 if(!ao)
698 return;
699 ao->write(ao, zbuf, audiobufsize);
700 if(ao->userptr)
701 ((struct prebuf*)ao->userptr)->fill = 0;
702 while(!nomoredata)
703 {
704 DosResetEventSem(dataplayed,&resetcount);
705 DosWaitEventSem(dataplayed, -1);
706 }
707 }
708
709 static void flush_os2(out123_handle *ao)
710 {
711 if(ao && ao->userptr)
712 ((struct prebuf*)ao->userptr)->fill = 0;
713 }
714
715
716 static int init_os2(out123_handle* ao)
717 {
718 if (ao==NULL) return -1;
719
720 /* Set callbacks */
721 ao->open = open_os2;
722 ao->flush = flush_os2;
723 ao->write = write_os2;
724 ao->get_formats = get_formats_os2;
725 ao->close = close_os2;
726 ao->drain = drain_os2;
727
728 /* Success */
729 return 0;
730 }
731
732
733
734
735
736 /*
737 Module information data structure
738 */
739 mpg123_module_t mpg123_output_module_info = {
740 /* api_version */ MPG123_MODULE_API_VERSION,
741 /* name */ "os2",
742 /* description */ "Audio output for OS2.",
743 /* revision */ "$Rev:$",
744 /* handle */ NULL,
745
746 /* init_output */ init_os2,
747 };
748
749