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

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

update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: dwavestrm.cpp 167 2001-03-22 23:33:12Z 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
35
36void cdecl HookHandler(ULONG ulSysFileNum)
37{
38 PDWAVESTREAM pStream;
39 PSTREAMBUFFEREX temp;
40 int rc;
41
42 pStream = (PDWAVESTREAM)FindStream_fromFile(ulSysFileNum);
43 if(pStream == NULL) {
44 dprintf(("HookHandler stream %lx not found!", (ULONG) ulSysFileNum));
45 DebugInt3();
46 return;
47 }
48
49 temp = (PSTREAMBUFFEREX)pStream->qhReturn.PopHead();
50 while(temp) {
51 if(pStream->hstream) {
52 rc = DevHelp_PostEventSem(pStream->hstream);
53 if(rc != 0) {
54 dprintf(("DevHlp_PostEventSem returned %d", rc));
55 }
56 }
57 DevHelp_VMFree((LIN)temp->pBuffptr);
58 DevHelp_VMUnLock(temp->linLock);
59 free(temp->pLock);
60 delete temp;
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 pLock = (PULONG)malloc(12);
76 if(pLock == NULL) {
77 DebugInt3();
78 return 1;
79 }
80
81 rc = DevHelp_VirtToLin(SELECTOROF(pLock), OFFSETOF(pLock), &linLock);
82 if(rc) {
83 DebugInt3();
84 return rc;
85 }
86
87 rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE, (LIN)pbuf, uLength, -1L, linLock, (PULONG)&PageListCount);
88 if(rc) {
89 DebugInt3();
90 DevHelp_VMFree(linAddr);
91 return rc;
92 }
93
94 rc = DevHelp_VMProcessToGlobal(VMDHGP_WRITE, (LIN)pbuf, uLength, (PLIN)&linAddr);
95 if(rc) {
96 DebugInt3();
97 return rc;
98 }
99
100 pStreamBuf = new STREAMBUFFEREX(uLength, (PSTREAMBUF)linAddr, linLock, pLock);
101
102 return WAVESTREAM::Write((PSTREAMBUFFER)pStreamBuf);
103}
104
105void DWAVESTREAM::ReturnBuffer(void)
106{
107 PSTREAMBUFFEREX temp = (PSTREAMBUFFEREX)qhDone.PopHead();
108
109 if(temp)
110 {
111 if(ulStreamState == STREAM_STREAMING) {//means we're called during an interrupt
112 qhReturn.PushOnTail((PQUEUEELEMENT)temp);
113 DevHelp_ArmCtxHook(hCtxHook, ulSysFileNum);
114 }
115 else {
116 DevHelp_VMFree((LIN)temp->pBuffptr);
117 DevHelp_VMUnLock(temp->linLock);
118 free(temp->pLock);
119 delete temp;
120 }
121 }
122}
123
124ULONG DWAVESTREAM::Register(PDDCMDREGISTER pReg)
125{
126 hSem = pReg->hStream;
127
128 if(DevHelp_OpenEventSem(hSem) != 0) {
129 dprintf(("DevHlp_OpenEventSem %lx failed!", hSem));
130 hSem = 0;
131 return 1;
132 }
133 return WAVESTREAM::Register(pReg);
134}
135
136void DWAVESTREAM::DeRegister(void)
137{
138 if(DevHelp_CloseEventSem(hSem) != 0) {
139 dprintf(("DevHlp_CloseEventSemaphore %lx failed!", hSem));
140 return;
141 }
142 hSem = 0;
143 WAVESTREAM::DeRegister();
144}
145
146
147DWAVESTREAM::DWAVESTREAM(ULONG streamtype, LPMCI_AUDIO_INIT pinit, USHORT filesysnum):
148 WAVESTREAM(streamtype, pinit, filesysnum), fError(FALSE), hCtxHook(0), hSem(0)
149{
150 if(DevHelp_AllocateCtxHook((NPFN)HookHandlerAsm, &hCtxHook)) {
151 DebugInt3();
152 fError = TRUE;
153 }
154}
155
156DWAVESTREAM::~DWAVESTREAM()
157{
158 if (ulStreamState == STREAM_STREAMING) {
159 CONTROL_PARM cParm;
160 StopStream(&cParm);
161 }
162 else ReturnBuffers();
163
164 if(hSem) {
165 if(DevHelp_CloseEventSem(hSem) != 0) {
166 dprintf(("DevHlp_CloseEventSemaphore %lx failed!", hSem));
167 }
168 }
169 if(hCtxHook) {
170 DevHelp_FreeCtxHook(hCtxHook);
171 }
172}
173
Note: See TracBrowser for help on using the repository browser.