ISampleGrabberCB question

Started by Russ Srole, April 16, 2016, 12:38:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Russ Srole

I'm working on some directshow code and have hit a bit of wall.  I'm building a graph with a video/audio capture card and want to implement to sample grabbers.  One for video to add text to the video & the other to just get the audio samples to show vu meters.  I've done this in c# so I know it works, but am hoping to use a real language like Powerbasic.  I've got the bulk of it working, but when I setcallback things go bad.  I clearly do not understand how this should be structured. 

What I've tried:
1 - in the class that builds the graph and keeps track of everything, I added another interface:
    INTERFACE ISampleGrabberCB $IID_ISampleGrabberCB:INHERIT IUNKNOWN
        ' this one is for the video
        METHOD SampleCB (BYVAL SampleTime AS DOUBLE,BYVAL pSample AS IMediaSample) AS LONG
            'dialog set text hmain&,str$(SampleTime)
           ' more code

            METHOD = 0
        END METHOD                                           ' HRESULT
        ' =====================================================================================
        ' this one is for the audio
        METHOD BufferCB (BYVAL SampleTime AS DOUBLE, BYVAL pBuffer AS BYTE PTR, BYVAL BufferLen AS LONG) AS LONG
            DIALOG SET TEXT hmain&,STR$(SampleTime)
           ' more code
            METHOD = 0
        END METHOD                                            ' HRESULT
    END INTERFACE

The interface for the bulk of the class is iRecordGraph and after getting the pAudSampGrab AS ISampleGrabber, I call pAudSampGrab.SetCallback(me, 1).  At that point the graph doesn't want to run.  So that's not right

My other attempt was to create a class with just the interface above and in my Recordgraph instance, make an instance of the other class (CallbackClass) and call pAudSampGrab.SetCallback(CallBackClass, 1).  That one lets the graph start, but crashes in a second or two.

Any ideas are welcome.

Thanks,
Russ

Patrice Terrier

IsampleGrabber is deprecated, and there seem to be no real replacement.

I am doing similar things, with audio capture and overlaying text on video, using transparent overlayed composited window,
but that is pure procedural SDK coding style.

This is what i am doing in BassBox64 in C++.
http://www.jose.it-berater.org/smfforum/index.php?topic=4932.msg20475#msg20475


You can also try this:
http://www.jose.it-berater.org/smfforum/index.php?topic=5067.msg21354#msg21354
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

José Roca

Quote
My other attempt was to create a class with just the interface above and in my Recordgraph instance, make an instance of the other class (CallbackClass) and call pAudSampGrab.SetCallback(CallBackClass, 1).  That one lets the graph start, but crashes in a second or two.

This is the way to do it.

Russ Srole

José,

It looks I didn't create my Callback class correctly.  I think this might work:

Class cCallBacks $CLSID_SampleGrabber as COM

   INTERFACE ISampleGrabberCB $IID_ISampleGrabberCB:INHERIT iUnknown
       ' this one is for the video
       METHOD SampleCB (BYVAL SampleTime AS DOUBLE,BYVAL pSample AS IMediaSample) AS LONG
           '   do stuff
           method = 0
       end method                                           ' HRESULT
       ' =====================================================================================
       ' this one is for the audio
       METHOD BufferCB (BYVAL SampleTime AS DOUBLE, BYVAL pBuffer AS BYTE PTR, BYVAL BufferLen AS LONG) AS LONG
           '   do stuff
         method = 0
       end method                                            ' HRESULT
   END INTERFACE
End Class

Does that look right to you?  I won't be in my office for a week, so I have no way to test this until then  :D

Patrice,
I'm always impressed and fascinated by your work.  I wish that Microsoft would hire you to design the OS UI.  I think we'd all be a lot happier.  But in this case I'm stuck with the depreciated Directshow.  It's so typical of MS to blow off an existing technology (flawed as Directshow is) and replace it with something completely inadequate.  Media Foundation is way too under powered for my needs.  The only way to not use Directshow is to go full api with blackmagic, which is not a big deal, as I've done some of the work already, thanks to Jose's TLB.  But the nasty part is using FFMPEG api for the rest.  And as good as it is, the api is really poorly documented.  If I had nothing but time on my hands, I'd work on it until I beat it, but ......

At any rate, I appreciate both of you responding & if my change above works, I'll report back. 

Thanks,
Russ

José Roca

> Class cCallBacks $CLSID_SampleGrabber as COM

You must not use $CLSID_SampleGrabber, which is the class ID for the ISampleGrabber interface. Choose any other unique guid, e.g. GUID$("{402BC9D5-2D72-430A-B346-78C727422ACE}"), or let the compiler to do it using Class cCallBacks AS COM.

Russ Srole

José,

Of course.  I should have known that since I used that CLSid to put the thing on the graph.

Thanks,
Russ

Russ Srole

Jose,

Thanks for your help on this.  Putting the call backs in it's own class was the answer & I had neglected to include the "as com".  All working now.

Russ