1 | /* $Id: dwavestrm.cpp,v 1.5 2001/04/30 21:07:57 sandervl Exp $ */
|
---|
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 | #include <include.h>
|
---|
29 |
|
---|
30 | #include "dwavestrm.hpp"
|
---|
31 | #include "memutil.h"
|
---|
32 | #include <dbgos2.h>
|
---|
33 | #include "ioctl.h"
|
---|
34 | #include "malloc.h"
|
---|
35 | #include <ossidc.h>
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | int DWAVESTREAM::numFreeStreams = 1; // we can only handle one !!
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | ULONG DWAVESTREAM::StartStream(void)
|
---|
44 | {
|
---|
45 | ULONG rc;
|
---|
46 |
|
---|
47 | if (numFreeStreams > 0) {
|
---|
48 | if ((rc = WAVESTREAM::StartStream()) == NO_ERROR) numFreeStreams--;
|
---|
49 | } else rc = 1;
|
---|
50 |
|
---|
51 | return rc;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | ULONG DWAVESTREAM::StopStream(PCONTROL_PARM pControl)
|
---|
56 | {
|
---|
57 | USHORT usLastStreamState = usStreamState;
|
---|
58 | ULONG rc = WAVESTREAM::StopStream(pControl);
|
---|
59 |
|
---|
60 | if (usLastStreamState != STREAM_STOPPED) numFreeStreams++;
|
---|
61 | return rc;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | ULONG DWAVESTREAM::Write(PSTREAMBUF pbuf, ULONG uLength, BOOL fLooping)
|
---|
66 | {
|
---|
67 | PSTREAMBUFFER pStreamBuf;
|
---|
68 | LIN linAddr;
|
---|
69 | PULONG pLock;
|
---|
70 | ULONG PageListCount;
|
---|
71 | LIN linLock;
|
---|
72 | int rc;
|
---|
73 |
|
---|
74 | pStreamBuf = new STREAMBUFFER(uLength, (PSTREAMBUF)0, fLooping);
|
---|
75 | if(pStreamBuf == NULL) {
|
---|
76 | DebugInt3();
|
---|
77 | return 1;
|
---|
78 | }
|
---|
79 |
|
---|
80 | pLock = &pStreamBuf->lock[0];
|
---|
81 |
|
---|
82 | rc = DevHelp_VirtToLin(SELECTOROF(pLock), OFFSETOF(pLock), &linLock);
|
---|
83 | if(rc) {
|
---|
84 | DebugInt3();
|
---|
85 | delete pStreamBuf;
|
---|
86 | return rc;
|
---|
87 | }
|
---|
88 |
|
---|
89 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
|
---|
90 | (LIN)pbuf, uLength, -1L, linLock, (PULONG)&PageListCount);
|
---|
91 | if(rc) {
|
---|
92 | DebugInt3();
|
---|
93 | delete pStreamBuf;
|
---|
94 | return rc;
|
---|
95 | }
|
---|
96 |
|
---|
97 | rc = DevHelp_VMProcessToGlobal(VMDHGP_WRITE, (LIN)pbuf, uLength, (PLIN)&linAddr);
|
---|
98 | if(rc) {
|
---|
99 | DebugInt3();
|
---|
100 | DevHelp_VMUnLock(linLock);
|
---|
101 | delete pStreamBuf;
|
---|
102 | return rc;
|
---|
103 | }
|
---|
104 | pStreamBuf->pBuffptr = (PSTREAMBUF)linAddr;
|
---|
105 | pStreamBuf->linLock = linLock;
|
---|
106 |
|
---|
107 | return WAVESTREAM::Write((PSTREAMBUFFER)pStreamBuf);
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | void DWAVESTREAM::ReturnBuffer(void)
|
---|
112 | {
|
---|
113 | PSTREAMBUFFER temp = (PSTREAMBUFFER)qhDone.PopHead();
|
---|
114 | int rc;
|
---|
115 |
|
---|
116 | if(temp)
|
---|
117 | {
|
---|
118 | if(usStreamState == STREAM_STREAMING) {
|
---|
119 | if(hSem) {
|
---|
120 | rc = DevHelp_PostEventSem(hSem);
|
---|
121 | if(rc != 0) {
|
---|
122 | dprintf(("DevHlp_PostEventSem returned %d", rc));
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | DevHelp_VMUnLock(temp->linLock);
|
---|
128 | DevHelp_VMFree((LIN)temp->pBuffptr);
|
---|
129 | delete temp;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | ULONG DWAVESTREAM::Register(PDDCMDREGISTER pReg)
|
---|
135 | {
|
---|
136 | hSem = pReg->hStream;
|
---|
137 |
|
---|
138 | if(DevHelp_OpenEventSem(hSem) != 0) {
|
---|
139 | dprintf(("DevHlp_OpenEventSem %lx failed!", hSem));
|
---|
140 | hSem = 0;
|
---|
141 | return 1;
|
---|
142 | }
|
---|
143 |
|
---|
144 | return WAVESTREAM::Register(pReg);
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | void DWAVESTREAM::DeRegister(void)
|
---|
149 | {
|
---|
150 | if(DevHelp_CloseEventSem(hSem) != 0) {
|
---|
151 | dprintf(("DevHlp_CloseEventSemaphore %lx failed!", hSem));
|
---|
152 | return;
|
---|
153 | }
|
---|
154 |
|
---|
155 | hSem = 0;
|
---|
156 | WAVESTREAM::DeRegister();
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | void DWAVESTREAM::AddBuffers(BOOL fFirst)
|
---|
161 | {
|
---|
162 | PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhDone.Tail();
|
---|
163 | ULONG space, Buff_left, byteswritten;
|
---|
164 |
|
---|
165 | if(!pTemp) pTemp = (PSTREAMBUFFER)qhInProcess.Tail();
|
---|
166 |
|
---|
167 | if(usStreamType & STREAM_WRITE && pTemp && pTemp->looping)
|
---|
168 | {
|
---|
169 | Buff_left = pTemp->ulBuffsz - pTemp->ulBuffpos;
|
---|
170 |
|
---|
171 | space = OSS16_StreamGetSpace(this);
|
---|
172 | if(fFirst) {
|
---|
173 | space = min(space, 4*fragsize);
|
---|
174 | }
|
---|
175 | else space = min(space, fragsize);
|
---|
176 |
|
---|
177 | if(space) {
|
---|
178 | if(space >= Buff_left) {
|
---|
179 | byteswritten = AddBuffer(Buff_left);
|
---|
180 | if(byteswritten == Buff_left) {
|
---|
181 | pTemp->ulBuffpos = 0; //reset fill position
|
---|
182 | AddBuffer(space - Buff_left);
|
---|
183 | }
|
---|
184 | }
|
---|
185 | else AddBuffer(space);
|
---|
186 | }
|
---|
187 | pTemp->ulDonepos = 0; //make sure it ::Process never thinks it's done
|
---|
188 | }
|
---|
189 | else WAVESTREAM::AddBuffers(fFirst);
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | BOOL DWAVESTREAM::SetProperty(int type, ULONG value, ULONG reserved)
|
---|
194 | {
|
---|
195 | PSTREAMBUFFER pTemp;
|
---|
196 |
|
---|
197 | switch(type) {
|
---|
198 | case PROPERTY_LOOPING:
|
---|
199 | cli2();
|
---|
200 |
|
---|
201 | pTemp = (PSTREAMBUFFER)qhInProcess.Head();
|
---|
202 | if(!pTemp) pTemp = (PSTREAMBUFFER)qhDone.Head();
|
---|
203 |
|
---|
204 | if(pTemp) {
|
---|
205 | pTemp->looping = (BOOL)value;
|
---|
206 | if(!pTemp->looping) {
|
---|
207 | //calculate current play position
|
---|
208 | pTemp->ulDonepos = (_ulBytesProcessed % pTemp->ulBuffsz);
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | popf();
|
---|
213 |
|
---|
214 | return TRUE;
|
---|
215 |
|
---|
216 | case PROPERTY_FREQUENCY:
|
---|
217 | return TRUE;
|
---|
218 | }
|
---|
219 |
|
---|
220 | return WAVESTREAM::SetProperty(type, value, reserved);
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | ULONG DWAVESTREAM::GetProperty(int type)
|
---|
225 | {
|
---|
226 | PSTREAMBUFFER pTemp;
|
---|
227 | ULONG ret;
|
---|
228 |
|
---|
229 | switch(type) {
|
---|
230 | case PROPERTY_LOOPING:
|
---|
231 | cli2();
|
---|
232 |
|
---|
233 | pTemp = (PSTREAMBUFFER)qhInProcess.Head();
|
---|
234 | if(!pTemp) pTemp = (PSTREAMBUFFER)qhDone.Head();
|
---|
235 | ret = ( pTemp ) ? pTemp->looping : FALSE;
|
---|
236 |
|
---|
237 | popf();
|
---|
238 |
|
---|
239 | return ret;
|
---|
240 | }
|
---|
241 |
|
---|
242 | return WAVESTREAM::GetProperty(type);
|
---|
243 | }
|
---|
244 |
|
---|
245 |
|
---|
246 | DWAVESTREAM::DWAVESTREAM(USHORT streamtype, LPMCI_AUDIO_INIT pinit, USHORT filesysnum):
|
---|
247 | WAVESTREAM(streamtype, pinit, filesysnum)
|
---|
248 | {
|
---|
249 | dprintf(("DWAVESTREAM ctor called."));
|
---|
250 | hSem = 0;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | DWAVESTREAM::~DWAVESTREAM()
|
---|
255 | {
|
---|
256 | dprintf(("DWAVESTREAM dtor called."));
|
---|
257 |
|
---|
258 | if (usStreamState == STREAM_STREAMING) {
|
---|
259 | CONTROL_PARM cParm;
|
---|
260 | StopStream(&cParm);
|
---|
261 | }
|
---|
262 | else ReturnBuffers();
|
---|
263 |
|
---|
264 | if(hSem) {
|
---|
265 | APIRET rc = DevHelp_PostEventSem(hSem);
|
---|
266 | if(rc != 0) {
|
---|
267 | dprintf(("DevHlp_PostEventSem returned %d", rc));
|
---|
268 | }
|
---|
269 | if(DevHelp_CloseEventSem(hSem) != 0) {
|
---|
270 | dprintf(("DevHlp_CloseEventSemaphore %lx failed!", hSem));
|
---|
271 | }
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|