c++ - iSampleGrabber, callback method. Code works, but might need some love? -


okay. i've got isamplegrabber callback method work, , able data opencv. due fact totally new me, want feedback if code "correct", cause doesn't seem one..

at first in code (from internet) i've got:

#pragma region formerly located in qedit.h in windows sdk, obsoleted , defined within project  void createdirectshowgraph(void); struct __declspec(uuid("0579154a-2b53-4994-b0d0-e773148eff85")) isamplegrabbercb : iunknown {     //     // raw methods provided interface     //        virtual hresult __stdcall samplecb (double sampletime, struct imediasample * psample ) = 0;       virtual hresult __stdcall buffercb (double sampletime, unsigned char * pbuffer, long bufferlen ) = 0; }; static const iid iid_isamplegrabbercb = { 0x0579154a, 0x2b53, 0x4994, { 0xb0, 0xd0, 0xe7, 0x73, 0x14, 0x8e, 0xff, 0x85 } }; struct __declspec(uuid("6b652fff-11fe-4fce-92ad-0266b5d7c78f")) isamplegrabber : iunknown {     //     // raw methods provided interface     //       virtual hresult __stdcall setoneshot (long oneshot ) = 0;       virtual hresult __stdcall setmediatype (struct _ammediatype * ptype ) = 0;       virtual hresult __stdcall getconnectedmediatype (struct _ammediatype * ptype ) = 0;       virtual hresult __stdcall setbuffersamples (long bufferthem ) = 0;       virtual hresult __stdcall getcurrentbuffer (/*[in,out]*/ long * pbuffersize,         /*[out]*/ long * pbuffer ) = 0;       virtual hresult __stdcall getcurrentsample (/*[out,retval]*/ struct imediasample * * ppsample ) = 0;       virtual hresult __stdcall setcallback (struct isamplegrabbercb * pcallback,long whichmethodtocallback ) = 0; };  struct __declspec(uuid("c1f400a0-3f08-11d3-9f0b-006008039e37")) samplegrabber;     // [ default ] interface isamplegrabber  #pragma endregion 

and later, internet, inserted this:

class cfakecallback : public isamplegrabbercb  { public:     //some variables , stuff...      stdmethodimp_(ulong) addref()  { return 2; }     stdmethodimp_(ulong) release() { return 1; }      stdmethodimp queryinterface(refiid riid, void ** ppv)     {         //checkpointer(ppv, e_pointer);          if (riid == iid_isamplegrabbercb || riid == iid_iunknown)          {             *ppv = (void *) static_cast<isamplegrabbercb *>(this);             return noerror;         }             return e_nointerface;     }      stdmethodimp samplecb( double sampletime, imediasample * psample )     {           //the data grabbing frames.     }      stdmethodimp buffercb( double sampletime, byte * pbuffer, long bufferlen )     {          return 0;     }  };   cfakecallback callbackf; 

and use:

psamplegrabber->setcallback(&callbackf,0); 

everything works, wonder. need create new class callback method? can see methods in "#pragma region..." can't use methods callback?

question(s):

one: need have class "fakecallback" samplecb/buffercb method? or can in way use methods in first code-part?

two: "virtual" - method, means method can "overwritten"? doing when creating class fakecallback, methods samplecb & buffercb?

thanks!

if want grab frame filter graph using callback need implement isamplegrabbercb interface. have implemented cfakecallback required use isamplegrabbercb interface. can grab sample either using buffercb or samplecb. when implementing cfakecallback need override both samplecb , buffercb. 1 of them contain custom code grab sample while other return s_ok (0). in code using samplecb correct.

however if don't want use callback method samplegrabber present in windows sdk. need include qedit.h in application , done.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -