On-Demand application are generally pull implementations.
· Standard Pull Model (exists in previous version of the driver) - Driver asks for data when it is needed. When no data is available, the drivers just wait until the application gives a new buffer.
In the case of buffered streams, the user is responsible for providing valid data.
Use the open command (FMP_OPEN with the flag FMPF_BUFFERS, pg.Error! Bookmark not defined.) to open a buffered stream.
If a callback function is installed for the driver, it will be called with the FMPF_BUF_CREATE message with the parameter you gave with FMP_OPEN. (If no callback function is defined for the stream initially, then FMPF_BUF_CREATE message will be sent once the callback function is installed .)
A buffered stream will use a buffer in user’s application. No copy of buffer data will be made, so user should be careful not to overwrite data not yet read from the buffer. A buffer is a segment of linear memory anywhere in the physical memory space. You give the driver the address, the size, the mode of access of your buffer, by using FMP_SET command. You can use the FMP_GET command to get status as to how many bytes are left (or have not been read) in the buffer. The driver uses a message (see callback function) to tell the user when all of his buffer has been read (FMPM_BUF_EMPTY). At this time, you can use the FMP_SET command to give new buffer parameters to the driver. If the user decides to ignore the callback message, the buffer will be read again from the start if the flag FMPF_BUF_LOOP is set in FMPI_BUF_MODE.
You can specify a position that will generate a FMPM_BUF_POS message. This can be used to implement a FIFO or to begin preparing data for a ping pong buffer. For example, your buffer has a size of 10kb. You can tell the driver to signal when there are less than 1kb left in the buffer ( pos=1024 ). The message FMPM_BUF_POS will be issued when the position is r7eached. (see Callback functions).
If you write a zero value for the size, the driver will assume the stream has ended and will then set the size of the stream.
The callback function can receive the message FMPM_BUF_SEEK indicating that your next packet of data will have to start at the given offset (specified in bytes) within your stream file.
You don't need to pre-fill your buffers, because at the beginning, the FMPM_BUF_POS message (when you normally prepare the next buffer) will be sent before the FMPM_BUF_EMPTY (where you give a prepared buffer).
With the messages defined, you can manage your buffers inside the callback function, without external initialization or destruction or pre-fill.
Moreover, streams have a user information field FMPI_STM_USER that you can use to store information about the streams buffers, so you can use this and a single callback function for all your streams.