home *** CD-ROM | disk | FTP | other *** search
- Microsoft Multimedia Technical Notes: Multimedia Aware Applications
- Page 1
-
-
-
- Multimedia
-
- Technical Note
-
-
-
-
-
-
-
-
-
-
- Creating Multimedia Applications
- Covering
- Multimedia Aware Applications and
- General Application Techniques
-
-
-
-
-
-
-
-
- Multimedia Developer Support
- One Microsoft Way
- Redmond, WA 98052-6399 U.S.A.
-
- 03/92 Revision 1.30
-
-
- Information in this document is subject to change without notice and
- does not represent a commitment on the part of Microsoft Corporation.
- The software described in this document is furnished under license
- agreement or nondisclosure agreement. The software may be used or
- copied only in the accordance with the terms of the agreement. It is
- against the law to copy the software on any medium except as
- specifically allowed in the license or nondisclosure agreement.
-
- No part of this document may be reproduced or transmitted in any form
- or by any means, electronic or mechanical, including photocopying and
- recording, for any purpose without the express written permission of
- Microsoft Corporation.
-
- This technical note is for informational purposes only. MICROSOFT
- MAKES NO WARRANTIES, EXPRESSED OR IMPLIED, IN THIS TECHNICAL NOTE.
-
- Microsoft, MS-DOS, XENIX and the Microsoft logo are registered
- trademarks and Windows is a trademark of Microsoft Corporation. Other
- trade names mentioned herein are trademarks of their respective
- manufacturers.
-
- Copyright 1992, Microsoft Corporation. All Rights Reserved.
- Table of Contents
- Overview 2
- Current Version 2
- Intended Audience 2
- Questions? 2
- Classes of Applications 3
- Multimedia Dependent Applications. 3
- Multimedia Aware Applications. 3
- Different Levels of Awareness. 3
- General Programming Guidelines 4
- Coping with Resource Availability. 4
- Yielding Resources to Other Applications. 4
- Multimedia APIs Do Not Imply Multimedia Features 4
- Don't Assume Number of Drivers to be Constant 5
-
- Overview
-
- This tech note details how to design and optimize an application using
- the Multimedia APIs in Windows. It is meant for a developer working in
- C or a high-level language.
-
- This note covers three main areas of creating multimedia applications:
- applications which work with or without the Multimedia API
- extensions to Windows
- coping with unavailable resources
- yielding resources to other applications.
-
- Current Version
- The current version of this document can be obtained from the Microsoft
- Multimedia Systems BBS at (206) 936-4082 in the files library in the
- technotes section in the mmaware.zip file. BBS modem settings are 9600
- baud, no parity, 8 data bits, 1 stop bit. It is also available from
- the WINSDK forum on CompuServe.
- Intended Audience
- This document should be read by Multimedia Producers as well as
- programmers using all types of tools.
- Questions?
- Please direct all questions, requests and problems with this technical
- note to the sysop of the MM BBS, or via FAX or mail to:
-
- Multimedia Technical Support
- Microsoft Multimedia Group
- One Microsoft Way
- Redmond, WA 98052-6399
- FAX: 206 93MS-FAX
- Please let us know if you find this information useful.
-
-
- Classes of Applications
-
- Multimedia applications fall loosely into two classes: those totally
- dependent on the multimedia APIs, and those that use them if they are
- available. The latter is called being 'multimedia aware' because the
- application is 'aware' of the multimedia APIs and uses them if they are
- available. Applications that don't provide Multimedia capabilities
- won't be purchased.
- Multimedia Dependent Applications.
-
- An application that is 'multimedia dependent' requires the Multimedia
- APIs to be available.
-
- Some applications only make sense in a Multimedia environment. For
- example, a speak and spell tutor requires support for playing sounds.
- If the machine has no Multimedia support then the application cannot be
- run. Attempting to run the application on a basic Windows 3.0 platform
- results in a dialog box telling the user that Windows can't find
- MMSYSTEM.DLL. This isn't really a nice way to inform the user that we
- can't run his application, but it's the best we can do if it's linked
- with MMSYSTEM.LIB during creation. It would be nice if we could inform
- the user that they needed the Multimedia extensions to use the
- application. The best we can do is create applications which either
- fail gracefully or have reduced functionality if some feature they
- require is not available.
- Multimedia Aware Applications.
-
- An application that is 'multimedia aware' will use the Multimedia APIs
- if they are available.
-
- Instead of linking an application directly with the MMSYSTEM library,
- it can be linked with an intermediate library whose role is to
- determine the existence of a particular function in the system and link
- to it at run time if it exists. If the function is not present then
- some default action can take place. This may be as simple as returning
- an error code to inform the application that the call failed or it may
- be some code to emulate the required function. The MM Sys BBS
- currently includes such a library, complete with source code and notes
- on how to use it. See the Overview section for details on how to
- obtain this code. An application constructed with this library is
- capable of running under regular Windows as well as Windows with
- Multimedia API Extensions including Windows 3.1.
-
- Different Levels of Awareness.
-
- Applications can be sensitive to the presence of the extensions or to
- individual components. To illustrate this let's consider an
- application which displays text, has some animations, and uses
- waveform, MIDI and CD audio sounds in various places. At first sight,
- this application seems doomed if no Multimedia support is available.
- However, let's expand things a bit and say that the application is some
- sort of encyclopedia in which the majority of the application consists
- of displaying text which is occasionally augmented by Multimedia
- inserts. This application can provide most of its functionality on a
- regular Windows 3.0 platform since it only requires the normal Windows
- USER and GDI support to display its text.
-
- In creating a version of this application which runs both under regular
- Windows and with the extensions, we need to consider not only whether
- the Multimedia extensions exist but also what support there might be
- for each of the data types we will want to render. Is the CD audio
- device available? Can the wave device handle the format I want?
-
- In the simplest case, we could detect the presence of the extensions at
- run time and simply disable all the Multimedia features if the
- extensions were not found. However it is still not valid to assume
- that all the devices we want to use are present, even if the extensions
- are found to exist. It may well be that another application is
- running and is currently using one or more of the features we need.
- Coping with resource availability is discussed in the next section.
-
- General Programming Guidelines
-
- This section discusses important guidelines and issues in developing
- multimedia applications.
- Coping with Resource Availability.
-
- The ideal solution is to only attempt to use a device or feature when
- it's needed and close it when it's no longer required. If the resource
- is not available then either continue without it (gray out the button
- which plays sound etc.) or inform the user that they need to release it
- from some other application.
-
- Unfortunately, this solution produces some large timing delays if
- opening a device causes any code to be loaded. This is the case when
- applications use MCI to access devices. The MCI device handler DLL
- takes a little while to load and initialize. Often, this is
- unacceptable in the application.
-
- A good compromise is to open the device ahead of when it's required and
- release it when someone else needs it or when the application is
- terminated. This has the advantage that your application will know if
- the device is available or not well before it needs to use it, thus
- avoiding the delays associated with code being loaded. To do this
- well, your application must process any WM_ACTIVATEAPP messages it
- receives. If it receives WM_ACTIVATEAPP with wParam set to zero, then
- the application is no longer the active one and it should close any
- devices it has open. A subsequent WM_ACTIVATEAPP message with a non-
- zero wParam value indicates that the application is once more the
- active one and it should attempt to reopen any devices it needs.
-
- The application can determine if each Multimedia feature it uses is
- available and selectively disable those parts which are not going to
- work. It can also optionally notify the user of this reduced
- functionality.
-
- The key to creating a tolerant application in this environment is to be
- sure to check the error return code from every attempt to open a
- device. In this way your application will avoid failing as the system
- configuration changes and you will be able to inform the user in either
- a direct way (dialog box) or a more subtle way (ex., dimmed buttons) of
- the loss of a feature.
- Yielding Resources to Other Applications.
-
- It's important that applications which hold devices open for long
- periods process the WM_ACTIVATEAPP messages sent to them. This allows
- other applications to use the Multimedia facilities. For example,
- consider a game which allows the user to speak some of the parts by
- recording their own voice. While playing the game, they may decide to
- bring up Sound Recorder to alter one of the files they recorded
- previously. If the game won't yield the wave output device then the
- Sound Recorder won't function as the user expects.
-
- As a rule applications shouldn't do things while they aren't active
- such as playing animations or sounds. An exception to this rule might
- be an application like Music Box which plays audio CDs. In this case
- it would be unreasonable behavior to stop playing the CD just because
- the user wanted to run some other application! If your application
- needs to use the CD, and it's not available because some other
- application has it open, then you just have to tell the user about it.
-
- The application should also allow the user a method, usually through a
- menu selection, to turn off certain multimedia features. This
- particularly applies to sounds. The user may want a background
- application to play MIDI files while he works, just like he may want to
- play a CD-Audio disc while he uses your application. In addition, the
- user may get tired of hearing the same sounds from your application
- over and over again.
- Multimedia APIs Do Not Imply Multimedia Features
-
- Windows 3.1 will include the multimedia API extensions. What this
- means to an application is that the existence of MMSYSTEM.DLL does not
- necessarily mean the existence of any device drivers. It's quite
- possible that the system is installed on a machine with no sound card.
- In fact the machine may have no Multimedia features at all.
-
- Having Multimedia APIs does not imply that all the MPC standard
- features are available. In addition, just because there is a CD-ROM
- does not mean it meets MPC specifications. Your application should
- warn the user in the documentation that if he does not have MPC
- compatible hardware that application performance may suffer.
-
- To survive in this world, your application must either fail gracefully
- at start up with a message, or be tolerant at run time of support being
- unavailable.
-
- It is also important that you consider how your setup or installation
- program will be a part of this. If your setup program finds no
- Multimedia support and consequently disables features of your
- application, then it's important that there is a mechanism to enable
- these features if the user adds a sound card (for example) at a later
- time. This may simply mean re-running the setup program but you should
- consider putting this sort of detection into the start up code for the
- application itself. Remember that you don't need to worry about
- exactly which sound driver gets added, simply that those APIs are now
- supported and this is easy to detect at run time.
-
- Don't Assume Number of Drivers to be Constant
-
- One further complication when determining the number of available
- drivers is that at some point, the system will have the facility added
- to load and unload drivers on demand. This mechanism might be used to
- implement installable filters such as a 16 bit to 8 bit wave converter.
-
- What this means is that the number of available drivers during the run
- time of your application may vary and it will not be sufficient to
- simply enumerate them when the application starts if you wish to make
- use of every available driver.
-
-
-