1 | /* $Id: dwavestrm.cpp 166 2001-03-22 18:13:01Z sandervl $ */
|
---|
2 |
|
---|
3 | /* SCCSID = %W% %E% */
|
---|
4 | /****************************************************************************
|
---|
5 | * *
|
---|
6 | * Copyright (c) IBM Corporation 1994 - 1997. *
|
---|
7 | * *
|
---|
8 | * The following IBM OS/2 source code is provided to you solely for the *
|
---|
9 | * the purpose of assisting you in your development of OS/2 device drivers. *
|
---|
10 | * You may use this code in accordance with the IBM License Agreement *
|
---|
11 | * provided in the IBM Device Driver Source Kit for OS/2. *
|
---|
12 | * *
|
---|
13 | ****************************************************************************/
|
---|
14 | /**@internal %W%
|
---|
15 | * @notes
|
---|
16 | * @version %I%
|
---|
17 | * @context Unless otherwise noted, all interfaces are Ring-0, 16-bit,
|
---|
18 | * <stack context>.
|
---|
19 | * @history
|
---|
20 | *
|
---|
21 | */
|
---|
22 | #define INCL_NOPMAPI
|
---|
23 | #include <os2.h>
|
---|
24 | #include <os2me.h>
|
---|
25 | #include <audio.h>
|
---|
26 |
|
---|
27 | #include <devhelp.h>
|
---|
28 |
|
---|
29 | #include "dwavestrm.hpp"
|
---|
30 | #include "memutil.h"
|
---|
31 | #include <dbgos2.h>
|
---|
32 | #include "ioctl.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | void cdecl HookHandler(ULONG ulSysFileNum)
|
---|
36 | {
|
---|
37 | PDWAVESTREAM pStream;
|
---|
38 | PSTREAMBUFFEREX temp;
|
---|
39 | int rc;
|
---|
40 |
|
---|
41 | pStream = (PDWAVESTREAM)FindStream_fromFile(ulSysFileNum);
|
---|
42 | if(pStream == NULL) {
|
---|
43 | dprintf(("HookHandler stream %lx not found!", (ULONG) ulSysFileNum));
|
---|
44 | DebugInt3();
|
---|
45 | return;
|
---|
46 | }
|
---|
47 |
|
---|
48 | temp = (PSTREAMBUFFEREX)pStream->qhReturn.PopHead();
|
---|
49 | while(temp) {
|
---|
50 | if(pStream->hstream) {
|
---|
51 | rc = DevHelp_PostEventSem(pStream->hstream);
|
---|
52 | if(rc != 0) {
|
---|
53 | dprintf(("DevHlp_PostEventSem returned %d", rc));
|
---|
54 | }
|
---|
55 | }
|
---|
56 | DevHelp_VMFree((LIN)temp->pBuffptr);
|
---|
57 | DevHelp_VMUnLock(temp->hLock);
|
---|
58 | delete temp;
|
---|
59 | }
|
---|
60 | return;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | ULONG DWAVESTREAM::Write(PSTREAMBUF pbuf, ULONG uLength)
|
---|
65 | {
|
---|
66 | PSTREAMBUFFEREX pStreamBuf;
|
---|
67 | ULONG pGlobalAddr;
|
---|
68 | LIN linAddr = (LIN)&pGlobalAddr;
|
---|
69 | ULONG lock;
|
---|
70 | LIN linLock = (LIN)&lock;
|
---|
71 | int rc;
|
---|
72 |
|
---|
73 | rc = DevHelp_VirtToLin(SELECTOROF(linAddr), OFFSETOF(linAddr), &linAddr);
|
---|
74 | if(rc) {
|
---|
75 | DebugInt3();
|
---|
76 | return rc;
|
---|
77 | }
|
---|
78 |
|
---|
79 | rc = DevHelp_VirtToLin(SELECTOROF(linLock), OFFSETOF(linLock), &linLock);
|
---|
80 | if(rc) {
|
---|
81 | DebugInt3();
|
---|
82 | return rc;
|
---|
83 | }
|
---|
84 |
|
---|
85 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE, (LIN)pbuf, uLength, -1L, linLock, (PULONG)-1L);
|
---|
86 | if(rc) {
|
---|
87 | DebugInt3();
|
---|
88 | return rc;
|
---|
89 | }
|
---|
90 |
|
---|
91 | rc = DevHelp_VMProcessToGlobal(VMDHGP_WRITE, (LIN)pbuf, uLength, (PLIN)linAddr);
|
---|
92 | if(rc) {
|
---|
93 | return rc;
|
---|
94 | }
|
---|
95 |
|
---|
96 | pStreamBuf = new STREAMBUFFEREX(uLength, (PSTREAMBUF)pGlobalAddr, lock);
|
---|
97 |
|
---|
98 | return WAVESTREAM::Write((STREAMBUFFER *)pStreamBuf);
|
---|
99 | }
|
---|
100 |
|
---|
101 | void DWAVESTREAM::ReturnBuffer(void)
|
---|
102 | {
|
---|
103 | PSTREAMBUFFEREX temp = (PSTREAMBUFFEREX)qhDone.PopHead();
|
---|
104 |
|
---|
105 | if(temp)
|
---|
106 | {
|
---|
107 | if(ulStreamState == STREAM_STREAMING) {//means we're called during an interrupt
|
---|
108 | qhReturn.PushOnTail((PQUEUEELEMENT)temp);
|
---|
109 | DevHelp_ArmCtxHook(hCtxHook, ulSysFileNum);
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | DevHelp_VMFree((LIN)temp->pBuffptr);
|
---|
113 | DevHelp_VMUnLock(temp->hLock);
|
---|
114 | delete temp;
|
---|
115 | }
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | DWAVESTREAM::DWAVESTREAM(ULONG streamtype, LPMCI_AUDIO_INIT pinit, USHORT filesysnum):
|
---|
120 | WAVESTREAM(streamtype, pinit, filesysnum), fError(FALSE), hCtxHook(0)
|
---|
121 | {
|
---|
122 | if(DevHelp_AllocateCtxHook((NPFN)HookHandlerAsm, &hCtxHook)) {
|
---|
123 | DebugInt3();
|
---|
124 | fError = TRUE;
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | DWAVESTREAM::~DWAVESTREAM()
|
---|
129 | {
|
---|
130 | if (ulStreamState == STREAM_STREAMING) {
|
---|
131 | CONTROL_PARM cParm;
|
---|
132 | StopStream(&cParm);
|
---|
133 | }
|
---|
134 | if(hCtxHook) {
|
---|
135 | DevHelp_FreeCtxHook(hCtxHook);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|