Waveform and video streams involve the continuous flow of real-time audio and video data. Typically, these streams involve a high data-transfer rate and require significant processor time.
The data-transfer model for streaming audio and video input is similar. If you have worked with waveform or video-capture device drivers, many of the concepts you already understand apply to the other type of driver.
The following sequence of operations occurs when streaming waveform or video data between a device driver and a client application:
Once the stream starts, the client application and the audio and video device driver do not communicate directly. The device driver fills the data buffers at the data rate specified by the client application. It fills the buffers without waiting for any synchronization signal from the application, as long as buffers are available and it is not paused or stopped by the application. The buffers are filled in the order that the driver receives them from the application. (If the device driver runs out of buffers, it should set an error flag. A client video application can use the DVM_STREAM_GETERROR message to test for this condition.)
The client application expects the buffers back in the order that it sends them to the device driver. When it is ready for more data, it checks the done bit of the next buffer it expects to receive from the device driver. If the done bit is set, the application continues operation with that buffer. If the done bit is not set, the application periodically checks the done bit while it waits for the buffer.
Streaming continues until it is stopped by the application. The following sequence of operations occurs when the application has finished capturing data:
Because audio and video data buffers must be accessed at interrupt time, the memory allocated for them is subject to the requirements mentioned in . Rather than have the client application prepare the memory before sending data blocks to the driver, the client requests that the driver make the preparations.
This request involves two messages, in the form of _PREPARE and _UNPREPARE. Most drivers can respond to these messages by returning a MMSYSERR_NOTSUPPORTED error. Then, MMSYSTEM prepares the data block by page-locking it so the driver can access it at interrupt time. For example, most drivers can respond to the DVM_STREAM_PREPAREHEADER and DVM_STREAM_UNPREPAREHEADER messages by returning a DV_ERR_UNSUPPORTED error. When a driver returns the DV_ERR_UNSUPPORTED error, MMSYSTEM prepares the data block by page-locking the header and data sections so the driver can access them at interrupt time.
If a device driver does not need page-locked data (for example, if the application immediately copies the data to an on-card buffer) or if the buffer requires additional preparation, the application can respond to these messages directly instead of letting MMSYSTEM handle them. An application should respond to both messages, or to neither.
The following table identifies the drivers that use these messages, and the name of the prepare and unprepare messages.
Driver type | Prepare/unprepare message |
---|---|
MIDI input | MIDM_PREPARE
MIDM_UNPREPARE |
MIDI output | MODM_PREPARE
MODM_UNPREPARE |
Waveform audio input | WIDM_PREPARE
WIDM_UNPREPARE |
Waveform audio output | WODM_PREPARE
WODM_UNPREPARE |
Video capture | DVM_STREAM_PREPAREHEADER
DVM_STREAM_UNPREPAREHEADER |
Audio compression and decompression | ACMDM_STREAMPREPARE
ACMDM_STREAMUNPREPARE |