1

I have a DirectShow application written in Delphi 6 using the DSPACK component library. When I shut down my filter graphs (stop play), I get an access violation due to a callback from the Sample Grabber DirectShow filter occurring after the object that owns the callback method has been destroyed. It doesn't happen every time, but fairly often. Can someone point me to a code sample or document that tells me the steps I need to take to shut down my graphs in a way that that makes sure all pending Sample Grabber callbacks have been received or eliminated?

Robert Oschler
  • 14,153
  • 18
  • 94
  • 227

1 Answers1

1

What about issuing ISampleGrabber::SetCallback(NULL, ... prior to stopping/releasing the filter graph?

More to this, you can set an internal flag indicating termination and check it in the callbacks you have to immeditely return without further processing.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • I'll see if DSPACK is doing a SetCallback(NULL, ..) and if not, add it. In regards to setting an "exit-immediately" flag. That's the problem. The object that owns the callback method is having that method entered is no longer valid (destroyed). – Robert Oschler Nov 30 '11 at 15:24
  • 1
    It can't be right. As long as the method is called, this assumes that `SG` still holds a reference to the callback object. Or you are implementing the callback on a non-true COM object, which ignore reference counter, or you just have a bug with references. – Roman R. Nov 30 '11 at 15:56
  • How do you stop playing? SetCallback(Null, ...) isn't necessary except when you destroy your callback stuff too early... – klaus triendl Sep 03 '13 at 18:50
  • @klaustriendl: you stop using `IMediaControl::Stop`, see [ask] on asking your own question (incl. branching off existing one). – Roman R. Sep 03 '13 at 19:25
  • @roman-r: I think there's a misunderstanding here. I didn't intend to ask my own question, but wanted to find out how exactly Robert stops the graph (and whether he uses IMediaControl::Stop). Sorry for the confusion – klaus triendl Sep 03 '13 at 22:07
  • It had to be a sort of `IMediaControl::Stop`. There is a thread race condition there. It is "legal" to have a call back, such as a frame or a few, while Stop call is being processed, so one might want to make sure that callback is not longer called before even start stopping. This is where removal of the callback can help. – Roman R. Sep 03 '13 at 22:10