ASF Web Stream Playback in DirectShow

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Microsoft DirectShow supports web streams in file playback scenarios through the WM ASF Reader filter, but you must write your own DirectShow filter to capture and persist the stream.

Note

To play back web streams in content that is being streamed from a server running Windows Media Services, use the Windows Media Player 9 Series ActiveX® control embedded in a web page.

 

When given a file containing streams of type WMMEDIATYPE_FileTransfer, the WM ASF Reader will create an output pin for it. The format block will be a WMT_WEBSTREAM_FORMAT structure. (This structure is documented in the Windows Media Format SDK documentation.) If no downstream filter is available that can handle that media type, then the pin will remain unconnected, but the file will still play the audio and/or video streams.

Each media sample in a web stream contains a WMT_WEBSTREAM_SAMPLE_HEADER structure, which is documented in the Windows Media Format SDK documentation. The structure has a variable length depending on the length of its wszURL member. The pointer to the sample data initially points to this structure, and you must advance the pointer past the structure in order to access the actual data in the stream.

Your web stream handler filter should be based on the CBaseRenderer class. In the CBaseRenderer::DoRenderSample method, the filter will need to parse the structure for information about the web stream, and then perform the appropriate action. Typically, this will involve saving the file to disk, and then calling the CreateUrlCacheEntry and CommitUrlCacheEntryW or CommitUrlCacheEntryA functions to place the files into the Internet Explorer cache. The filter must handle multipart files, that is, files that are larger than one sample, and also must handle render commands, which are specified by the WMT_WEBSTREAM_SAMPLE_HEADER.wSampleType member. The filter sends an EC_OLE_EVENT event to the application, along with the text of the WMT_WEBSTREAM_SAMPLE_HEADER.wszURL string which contains the name of the file to be rendered. The application then causes the browser to display the specified page. If the web stream has been authored correctly, the file should already be in the cache.

For more information on WMT_WEBSTREAM_FORMAT and WMT_WEBSTREAM_SAMPLE_HEADER, see the Windows Media Format SDK documentation.

Reading ASF Files in DirectShow