Redigera

Dela via


To Implement the OnSample Callback

[The feature associated with this page, Windows Media Format 11 SDK, is a legacy feature. It has been superseded by Source Reader and Sink Writer. Source Reader and Sink Writer have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader and Sink Writer instead of Windows Media Format 11 SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The asynchronous reader delivers samples to the controlling application in presentation-time order by making calls to the IWMReaderCallback::OnSample callback method. When you create an application using the asynchronous reader, you must implement OnSample to deal with uncompressed samples. Typically, functions or methods created to render content will be called from within OnSample.

Typical implementation of the OnSample callback includes the following steps.

  1. Retrieve the location and size of the buffer containing the sample by calling INSSBuffer::GetBufferAndLength on the buffer passed as pSample.
  2. Branch your logic depending upon the output number. The output number is passed to OnSample as dwOutputNumber.
  3. Include rendering logic for each output number you want to support. If you are rendering samples from multiple outputs, you may need to synchronize your rendering.

Applications that deliver compressed samples from ASF files need to implement the IWMReaderCallbackAdvanced::OnStreamSample callback method. OnStreamSample functions almost identically to OnSample, except that it receives compressed samples by stream number instead of uncompressed samples by output number.

IWMReaderCallback Interface

IWMReaderCallbackAdvanced Interface

Reading Files with the Asynchronous Reader

Using the Callback Methods