source: cmedia/trunk/Vsd/AudioIF/vsdman.c@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 13.9 KB
Line 
1/************************* START OF SPECIinCATIONS ***
2*
3* SOURCE FILE NAME: VSDMAN.C
4*
5* DESCRIPTIVE NAME: Contains resource management functions.
6*
7* COPYRIGHT: IBM Confidential
8* Copyright (c) IBM Corporation 1991, 1993
9* All Rights Reserved
10*
11* STATUS: OS/2 Release 2.x
12*
13* FUNCTION: This source module contains routines to process vsd resource
14* management issues (such as save/restore etc.)
15*
16* NOTES:
17* The following conecpts are illustrated in these source files:
18* 1. VSD_CLOSE (close the device). This also shows how to save
19* the state of the device in an .ini file.
20* 2. VSD_RESTORE (active the VSD).
21* 3. VSD_SAVE (deactivate the VSD). Shows how to use the AUDIO_INIT
22* IOCTL to save device state.
23* 4. VSD_RESOURCE (VsdResource). Returns the number of resource units
24* that a particular mode consumes (i.e. PCM takes x % of the card
25* etc.)
26* 5. VsdDevUnits
27*
28* Change History:
29* DATE DEVELOPER CHANGE DESCRIPTION
30* 07/21/93 Linden deCarmo File created
31* 06/19/94 Linden deCarmo Improved comments.
32* 06/29/95 Linden deCarmo Cleanup Hardware mixer support (15552).
33*
34************************** END OF SPECIFICATIONS **************************/
35
36#define INCL_DOS
37#define INCL_WINSHELLDATA
38//#define INCL_WINWINDOWMGR
39#define INCL_WINATOM
40#define INCL_WIN
41#define INCL_AUDIO_VSD
42
43
44#include <os2.h>
45#include <os2me.h>
46#include <mcd.h>
47#include <audio.h>
48#include <stdio.h>
49#include <string.h>
50#include <hhpheap.h>
51
52#include <vsdcmds.h>
53#include <vsdaud.h>
54#include <os2mixer.h>
55#include <vsdmix.h>
56
57
58/************************ START OF SPECIFICATIONS **************************
59*
60* SUBROUTINE NAME: VSDClose()
61*
62* FUNCTION: Closes the audio vsd and associated device driver.
63* VSDs should perform all cleanup activity here, since the
64* instance is now TERMINATED!!!!!!
65*
66* INPUT: pInstance - pointer to VSD instance
67*
68* OUTPUT: returns VSDERR_SUCCESS if successful, otherwise it returns an
69* MCI error code.
70*
71* OS/2 CALLS: DosClose()
72*
73* C CALLS: None
74*
75* INTERNAL CALLS: RemoveDevice(), MCI_Error()
76* *
77*************************** END OF SPECIFICATIONS *************************/
78
79LONG VSDClose( PVSD_INSTANCE pInstance )
80{
81
82 LONG rc;
83 LONG lError = VSDERR_SUCCESS;
84
85 /*-------------------------------------------------
86 * If we successfully opened a device, ensure that
87 * the file handle is closed.
88 *------------------------------------------------*/
89
90 if ( pInstance->ulDosOpened )
91 {
92 rc = CloseDevice( pInstance );
93 lError = MCI_Error(rc);
94 }
95
96 return(lError);
97
98} /* CloseDriver */
99
100
101
102
103
104/************************ START OF SPECIFICATIONS **************************
105*
106* SUBROUTINE NAME: VSDSave
107*
108* FUNCTION: Saves state of device in VSD structure
109*
110* INPUT: prInstance - pointer to AMP/Mixer instance structure
111*
112* OUTPUT: returns VSDERR_SUCCESS if successful, otherwise it returns an
113* MCI error code.
114*
115* OS/2 CALLS: DosDevIOCtl()
116*
117* C CALLS: None.
118*
119* INTERNAL CALLS: MCI_Error()
120*
121*************************** END OF SPECIFICATIONS *************************/
122
123LONG VSDSave( PVSD_INSTANCE pInstance )
124 {
125
126// LONG rc;
127 LONG lError = VSDERR_SUCCESS;
128
129 /*---------------------------------------------------------*
130 * If the instance has already been saved, just succeed
131 *---------------------------------------------------------*/
132
133 if ( !pInstance->ulActive )
134 {
135 return ( VSDERR_HARDWARE );
136 }
137
138
139 /*-----------------------------------------------------------------*
140 * Send AUDIO_INIT IOCTL request to instance to inactive
141 *
142 * But, if we opened a real mixer (i.e no AUDIODD), then the
143 * IOCTLs will not be necessary.
144 *----------------------------------------------------*/
145
146//-----------------------------------------------------------------------------
147#ifdef INCL_MM_OS2
148// if ( !( !pInstance->ulDefaultsSet && pInstance->fHardwareMix ) )
149 lError = DoIOCTLLoad( pInstance, IDLE );
150#endif
151//-----------------------------------------------------------------------------
152
153 if ( !lError )
154 {
155 pInstance->ulActive = FALSE;
156 }
157
158 return(lError);
159
160
161 } /* VSDSave */
162
163
164/************************ START OF SPECIFICATIONS **************************
165*
166* SUBROUTINE NAME: VSDRestore
167*
168* FUNCTION: Restores state of device saved in VSD structure
169*
170* INPUT: pInstance - pointer to VSD instance
171*
172* SUCCESS : VSDERR_SUCCESS
173*
174* FAILURE : VSD error code.
175*
176* OS/2 CALLS: DosDevIOCtl()
177*
178* C CALLS: None.
179*
180* INTERNAL CALLS: VSDError()
181*
182*************************** END OF SPECIFICATIONS *************************/
183// latest version of MDM and amp-mixer will foward master volume to VSD.
184
185#ifdef INCL_MM_OS2
186LONG VSDRestore( PVSD_INSTANCE pInstance )
187#else
188LONG VSDRestore( PVSD_INSTANCE pInstance,
189 PVSD_RESTORE_PARMS pRestore )
190#endif
191{
192
193 LONG lError = VSDERR_SUCCESS;
194// LONG rc;
195
196// ULONG ulOpenIt = TRUE;
197// ULONG ulFileSize;
198// ULONG ulAction;
199// ULONG ulKeepTrying = 0;
200
201// MCI_AUDIO_INIT *pAudioInit;
202 MCI_MASTERAUDIO_PARMS mciMasterAudio;
203
204#ifdef PERFORMANCE_TRACE
205// console_printf("VSD Restore called" );
206#endif
207 /*---------------------------------------------------------*
208 * If the instance has already been restored, just succeed
209 *---------------------------------------------------------*/
210
211 if ( pInstance->ulActive )
212 {
213 return ( VSDERR_SUCCESS );
214 }
215
216 /*---------------------------------------------------------*
217 * Do Audio Init IOCtl call
218 *
219 * if we opened a real mixer (i.e no AUDIODD), then the
220 * IOCTLs will not be necessary.
221 *----------------------------------------------------*/
222// lAD
223// if ( !( !pInstance->ulDefaultsSet && pInstance->fHardwareMix ) )
224// {
225// }
226// else
227#ifdef INCL_MM_OS2
228 lError = DoIOCTLLoad( pInstance, pInstance->ulHardwareMode );
229#endif
230#ifdef INCL_MM_WPOS
231 if (pInstance->sMode == DATATYPE_MIDI)
232 lError = DoIOCTLLoad( pInstance, pInstance->sMode );
233 else
234 lError = DoIOCTLLoad( pInstance, pInstance->ulHardwareMode );
235#endif
236
237 if ( !lError )
238 {
239#ifdef INCL_MM_WPOS
240 // MDM has been optimized to pass this info directly to mixer on
241 // the open. This will be on Intel in the next release.
242 pInstance->ulMasterVolume = pRestore->ulMasterVolume;
243 {
244
245#else
246 /*------------------------------------------------
247 * Once the VSD is active, set up the
248 * appropriate volume settings.
249 * To accomplish this, ask MDM the current volume
250 * state.
251 *-----------------------------------------------*/
252
253 lError = mciSendCommand( pInstance->usDeviceID,
254 MCI_MASTERAUDIO,
255 MCI_QUERYCURRENTSETTING | MCI_MASTERVOL | MCI_WAIT,
256 ( DWORD ) &mciMasterAudio,
257 0 );
258
259 if ( ( DWORD_LOWD( lError ) == VSDERR_SUCCESS ) )
260 {
261
262 // set our instance's master vol. to the system master volume
263
264 pInstance->ulMasterVolume = mciMasterAudio.dwReturn;
265#endif
266
267 pInstance->ulDosOpened = TRUE;
268 pInstance->ulActive = TRUE;
269
270 /*-----------------------------------------------------
271 * if we opened a real mixer (i.e no AUDIODD), then we
272 * must ensure that the connectors are in the state
273 * that the instance thinks they are (i.e. since they
274 * are now global, we must ensure that each instance
275 * gets the state that they expect.
276 *----------------------------------------------------*/
277// 15552
278
279#ifndef INCL_MM_WPOS
280 lError = ModifyAudioAttributes(pInstance, VSD_SET_ALL ); //@LP17168 ACPT
281#else
282 ModifyAudioAttributes(pInstance, VSD_SET_MASTER | VSD_SET_VOLUME );
283#endif
284 // indicate that we are aware of the current volume
285 pInstance->ulVSDFlags |= VSD_VOLUME_KNOWN;
286 if ( pInstance->fHardwareMix )
287 {
288 EnsureValidConnections( pInstance );
289 }
290// 15552
291
292 } /* if send command was a success */
293
294 } /* if no error on load */
295
296
297 return(lError);
298
299} /* VSDRestore */
300
301
302
303/************************ START OF SPECIFICATIONS **************************
304*
305* SUBROUTINE NAME: VSDDevUnits
306*
307* FUNCTION: Returns the number of devices supported by the VSD.
308*
309* INPUT: pInstance - pointer to VSD instance
310*
311* SUCCESS : VSDERR_SUCCESS
312*
313* FAILURE : VSD error code.
314*
315* OS/2 CALLS: DosDevIOCtl()
316*
317* C CALLS: None.
318*
319* INTERNAL CALLS: VSDError()
320*
321*************************** END OF SPECIFICATIONS *************************/
322
323LONG VSDDevUnits( PVSD_INSTANCE pInstance,
324 PVSD_DEVUNITS_PARMS pRequest )
325
326{
327 pRequest->VSD_Unit[0].ulDevType = MCI_DEVTYPE_AUDIO_AMPMIX;
328 return ( VSDERR_SUCCESS );
329
330} /* VSDDevUnits */
331
332
333/************************ START OF SPECIFICATIONS **************************
334*
335* SUBROUTINE NAME: VSDDevUnits
336*
337* FUNCTION: Returns the number of devices supported by the VSD.
338*
339* INPUT: pInstance - pointer to VSD instance
340*
341* SUCCESS : VSDERR_SUCCESS
342*
343* FAILURE : VSD error code.
344*
345* OS/2 CALLS: DosDevIOCtl()
346*
347* C CALLS: None.
348*
349* INTERNAL CALLS: VSDError()
350*
351*************************** END OF SPECIFICATIONS *************************/
352
353LONG VSDResource( PVSD_INSTANCE pInstance,
354 PVSD_RESOURCE_PARMS pRequest )
355
356{
357 VSD_INSTANCE TempInst;
358 ULONG rc;
359
360
361
362// if ( pInstance->fHardwareMix && !pInstance->ulDefaultsSet )
363// {
364// /* True hardware mixer--right now, not really taking resource */
365// // LAD--must add new mixer class, only one active at a time.
366//
367// pRequest->ulResUnits = 0;
368// pRequest->ulClass = PCM_CLASS;
369// rc = VSDERR_SUCCESS;
370// }
371// else
372// {
373// 15552--performance fix. Don't call the driver
374// we already know this information.
375//
376// memmove ( &TempInst, pInstance, sizeof ( VSD_INSTANCE ) );
377// /*-----------------------------------------------------------------*
378// * Return the resource class and number of resource units for the
379// * mode that the caller has specified.
380// *-----------------------------------------------------------------*/
381//
382// rc = GetClassInformation( &TempInst );
383//
384// /*-------------------------------------------------
385// * Work around ACPA problems. Since we cannot ask
386// * the device driver if it can best fit until after
387// * the MCIDRV_RESTORE, perform the best fit on
388// * the open.
389// *-------------------------------------------------*/
390//
391// if ( TempInst.ulDeviceID == MACPA &&
392// rc == VSDERR_UNSUPP_SAMPLESPERSEC )
393// {
394// ACPABestFit( &TempInst );
395// rc = VSDERR_SUCCESS;
396// }
397//
398 /* Return the resource management info to the caller */
399
400// pRequest->ulResUnits = TempInst.ulResourcesUsed;
401// pRequest->ulClass = TempInst.ulClass;
402 pRequest->ulResUnits = pInstance->ulResourcesUsed;
403 pRequest->ulClass = pInstance->ulClass;
404
405// 15552--performance fix. Don't call the driver
406// } /* if we are not using a true hardware mixer */
407
408 return ( MCIERR_SUCCESS );
409
410} /* VSDDevUnits */
411
412
413// 15552--performance fix. Don't call the driver
414
415/************************** START OF SPECIFICATIONS ************************
416* *
417* SUBROUTINE NAME: EnsureValidConnections *
418* *
419* DESCRIPTIVE NAME: Ensures that the connections for a given instance *
420* remain in affect when becoming active. *
421* *
422*************************** END OF SPECIFICATIONS **************************/
423void EnsureValidConnections( PVSD_INSTANCE pInstance )
424
425{
426 extern ULONG ulOutputDevice;
427 extern ULONG ulInputDevice;
428 extern HMTX hmtxProcessSemVSD; // Semaphore global to all processes
429 LINECONNECTIONS mixinfo;
430
431
432 DosRequestMutexSem( hmtxProcessSemVSD, -1 );
433 if ( pInstance->sMode != DATATYPE_MIDI)
434 {
435 mixinfo.ulLength = sizeof ( LINECONNECTIONS );
436 // if another instance changed the input connector, ensure
437 // that the instance that we are currently activating
438 // returns the input connector to the previous state.
439 if ( pInstance->ulInputDev != ulInputDevice )
440 {
441 mixinfo.ulConnection = SINK_WAVE;
442 mixinfo.ulLine = pInstance->ulInputDev;
443
444 mixSetConnections ( pInstance->hMix,
445 &mixinfo );
446
447 // update global memory
448
449 ulInputDevice = pInstance->ulInputDev;
450 }
451
452 // if another instance changed an output connector, ensure
453 // that the instance that we are currently activating
454 // returns the output connector to the previous state.
455
456 if ( !OutputConnectionMatch(pInstance->ulOutputDev, TRUE) )
457 {
458 mixinfo.ulConnection = pInstance->ulOutputDev;
459 mixinfo.ulLine = SOURCE_WAVE;
460 mixSetConnections ( pInstance->hMix,
461 &mixinfo );
462 // update global memory
463
464 ulOutputDevice = pInstance->ulOutputDev;
465 }
466
467 } // if not in MIDI mode
468
469 DosReleaseMutexSem( hmtxProcessSemVSD );
470
471 return;
472} // EnsureValidConnections
Note: See TracBrowser for help on using the repository browser.