tags:

views:

455

answers:

1

I have a DirectShow graph with the SampleGrabber filter doing some processing. The processing takes up to 50ms so often the playback speed is slower. The processing can be turned on and off.

My problem is that if the processing has been on for a while, when I turn it off the video plays as fast as possible until it reaches a certain point. Presumably this point is where the frame time matches the stream time and there is no longer any lag.

How can I stop this from happening, so that when I turn processing off playback is at normal speed? Can I turn off the stream clock while processing the data? Or perhaps timestamp the samples coming out of the SampleGrabber filter again, with the extra lag added?

Does anyone know the proper way to do this?

Edit:

I used the method of changing the sample times as shown in the answer below, but had some problems with seeking as well as calculating the sample timestamps.

I found a better way was to implement my own reference clock and to stop the clock if the processing took too long.

A: 

As long as you're using ISampleGrabberCB::SampleCB and not ISampleGrabberCB::BufferCallback you can simply update the IMediaSample presentation timestamps to be whatever you want using IMediaSample::SetTime. You need to use SampleCB as it gives you a pointer to the actual samples whereas BufferCB copies the samples before you get them, which would mean you were only updating the copy.

Turning off the clock probably won't help you because it'll just make the graph run as fast as possible. You could try changing the playback rate using IMediaSeeking::SetRate, but bear in mind that many filters do not support rate changes. You could also implement a custom clock that varies accoring to your exact requirements.

Stu Mackellar
thanks - timestamp fix works well. It is what I thought might be the case but I thought there might be a more elegant solution such as a function etc. But its really simple to implement anyway.
geometrikal