source: sbliveos2/trunk/drv16/dwavestrm.cpp@ 176

Last change on this file since 176 was 174, checked in by sandervl, 24 years ago

makefile updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: dwavestrm.cpp 174 2001-04-14 16:26:09Z 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#include "malloc.h"
34
35void 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->hSem) {
51 rc = DevHelp_PostEventSem(pStream->hSem);
52 if(rc != 0) {
53 dprintf(("DevHlp_PostEventSem returned %d", rc));
54 }
55 }
56 DevHelp_VMFree((LIN)temp->pBuffptr);
57 DevHelp_VMUnLock(temp->linLock);
58 delete temp;
59
60 temp = (PSTREAMBUFFEREX)pStream->qhReturn.PopHead();
61 }
62 return;
63}
64
65
66ULONG DWAVESTREAM::Write(PSTREAMBUF pbuf, ULONG uLength)
67{
68 PSTREAMBUFFEREX pStreamBuf;
69 LIN linAddr;
70 PULONG pLock;
71 ULONG PageListCount;
72 LIN linLock;
73 int rc;
74
75 pStreamBuf = new STREAMBUFFEREX(uLength, (PSTREAMBUF)0);
76 if(pStreamBuf == NULL) {
77 DebugInt3();
78 return 1;
79 }
80
81 pLock = &pStreamBuf->lock[0];
82
83 rc = DevHelp_VirtToLin(SELECTOROF(pLock), OFFSETOF(pLock), &linLock);
84 if(rc) {
85 DebugInt3();
86 delete pStreamBuf;
87 return rc;
88 }
89
90 rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE, (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
110void DWAVESTREAM::ReturnBuffer(void)
111{
112 PSTREAMBUFFEREX temp = (PSTREAMBUFFEREX)qhDone.PopHead();
113
114 if(temp)
115 {
116 if(ulStreamState == STREAM_STREAMING) {//means we're called during an interrupt
117 qhReturn.PushOnTail((PQUEUEELEMENT)temp);
118 DevHelp_ArmCtxHook(ulSysFileNum, hCtxHook);
119 }
120 else {
121 DevHelp_VMFree((LIN)temp->pBuffptr);
122 DevHelp_VMUnLock(temp->linLock);
123 delete temp;
124 }
125 }
126}
127
128ULONG DWAVESTREAM::Register(PDDCMDREGISTER pReg)
129{
130 hSem = pReg->hStream;
131
132 if(DevHelp_OpenEventSem(hSem) != 0) {
133 dprintf(("DevHlp_OpenEventSem %lx failed!", hSem));
134 hSem = 0;
135 return 1;
136 }
137 return WAVESTREAM::Register(pReg);
138}
139
140void DWAVESTREAM::DeRegister(void)
141{
142 if(DevHelp_CloseEventSem(hSem) != 0) {
143 dprintf(("DevHlp_CloseEventSemaphore %lx failed!", hSem));
144 return;
145 }
146 hSem = 0;
147 WAVESTREAM::DeRegister();
148}
149
150
151DWAVESTREAM::DWAVESTREAM(ULONG streamtype, LPMCI_AUDIO_INIT pinit, USHORT filesysnum):
152 WAVESTREAM(streamtype, pinit, filesysnum), fError(FALSE), hCtxHook(0), hSem(0)
153{
154 if(DevHelp_AllocateCtxHook((NPFN)HookHandlerAsm, &hCtxHook)) {
155 DebugInt3();
156 fError = TRUE;
157 }
158}
159
160DWAVESTREAM::~DWAVESTREAM()
161{
162 if (ulStreamState == STREAM_STREAMING) {
163 CONTROL_PARM cParm;
164 StopStream(&cParm);
165 }
166 else ReturnBuffers();
167
168 if(hSem) {
169 APIRET rc = DevHelp_PostEventSem(hSem);
170 if(rc != 0) {
171 dprintf(("DevHlp_PostEventSem returned %d", rc));
172 }
173 if(DevHelp_CloseEventSem(hSem) != 0) {
174 dprintf(("DevHlp_CloseEventSemaphore %lx failed!", hSem));
175 }
176 }
177 if(hCtxHook) {
178 DevHelp_FreeCtxHook(hCtxHook);
179 }
180}
181
Note: See TracBrowser for help on using the repository browser.