Step 5. Transform the Image

The upstream filter delivers media samples to the transform filter by calling the IMemInputPin::Receive method on the transform filter's input pin. To process the data, the transform filter calls the Transform method, which is pure virtual. The CTransformFilter and CTransInPlaceFilter classes use two different versions of this method:

CTransformFilter::Transform takes a pointer to the input sample and a pointer to the output sample. Before the filter calls the method, it copies the sample properties from the input sample to the output sample, including the time stamps.

This example assumes that EncodeFrame is a private method that implements the RLE encoding. The encoding algorithm itself is not described here; for details, see the topic "Bitmap Compression" in the Platform SDK documentation.

First, the example calls IMediaSample::GetPointer to retrieve the addresses of the underlying buffers. It passes these to the private EncoderFrame method. Then it calls IMediaSample::SetActualDataLength to specify the length of the encoded data. The downstream filter needs this information so that it can manage the buffer properly. Finally, the method calls IMediaSample::SetSyncPoint to set the key frame flag to TRUE. Run-length encoding does not use any delta frames, so every frame is a key frame. For delta frames, set the value to FALSE.

Other issues that you must consider include:

Time stamps. The CTransformFilter class timestamps the output sample before calling the Transform method. It copies the time stamp values from the input sample, without modifying them. If your filter needs to change the time stamps, call IMediaSample::SetTime on the output sample.

Format changes. The upstream filter can change formats mid-stream by attaching a media type to the sample. Before doing so, it calls IPin::QueryAccept on your filter's input pin. In the CTransformFilter class, this results in a call to CheckInputType followed by CheckTransform. The downstream filter can also change media types, using the same mechanism. In your own filter, there are two things to watch for:

Make sure that QueryAccept does not return false acceptances.

If your filter does accept format changes, check for them inside the Transform method by calling IMediaSample::GetMediaType. If that method returns S_OK, your filter must respond to the format change.

Threads. In both CTransformFilter and CTransInPlaceFilter, the transform filter delivers output samples synchronously inside the Receive method. The filter does not create any worker threads to process the data. Typically, there is no reason for a transform filter to create worker threads.