Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

Perhaps the problem i have is a bit specific but I'm sure the solution would be interesting for a lot of people.

Now to the point. I have an ActiveX control that plays streaming video. My goal is to get to every frame it plays and display them in external c# application over some windows control, a panel, for instance.

Here is the sample DirectShow transform filter:
C++
STDMETHODIMP CTransform::Transform(BSTR bsResource, struct U_VideoFrame *pInFrame, struct U_VideoFrameData **pOutFrameData)
    {
        //Must allocate memory this way, the output size must be equal to input size
        *pOutFrameData = (U_VideoFrameData*)CoTaskMemAlloc(sizeof(U_VideoFrameData));
        (*pOutFrameData)->pFrame = (BYTE*)CoTaskMemAlloc(pInFrame->Frame.nLength);
        (*pOutFrameData)->nLength = pInFrame->Frame.nLength;

        //Now transform data contained in (*pOutFrameData)->pFrame; 
        //We simply copy data here
        memcpy((*pOutFrameData)->pFrame, pInFrame->Frame.pFrame, pInFrame->Frame.nLength);

        return S_OK;
    }

My idea is that somewhere inside this method I should place a callback function that will call my managed code and pass pInFrame to it. How can I do it? Please help

P.S. I have read the great article Howto implement callback interface from unmanaged DLL to .net app. It works as described (of course). However, when I modify the code above to this:
C++
typedef int (__stdcall * Callback)(const char* text);
Callback Handler = 0;

extern "C" __declspec(dllexport)
void __stdcall SetCallback(Callback handler) {
  Handler = handler;
}

extern "C" __declspec(dllexport)
void __stdcall TestCallback() {
  int retval = Handler("hello world");
}


// CTransform

STDMETHODIMP CTransform::Transform(BSTR bsResource, struct U_VideoFrame *pInFrame, struct U_VideoFrameData **pOutFrameData)
{
    //Must allocate memory this way, the output size must be equal to input size
    *pOutFrameData = (U_VideoFrameData*)CoTaskMemAlloc(sizeof(U_VideoFrameData));
    (*pOutFrameData)->pFrame = (BYTE*)CoTaskMemAlloc(pInFrame->Frame.nLength);
    (*pOutFrameData)->nLength = pInFrame->Frame.nLength;

    //Now transform data contained in (*pOutFrameData)->pFrame; 
    //We simply copy data here
    memcpy((*pOutFrameData)->pFrame, pInFrame->Frame.pFrame, pInFrame->Frame.nLength);
    if (Handler != 0)
        int retval = Handler("Transform");
    return S_OK;
}

then the event does not fire from Transform method. TestCallback() method works

I'm stuck. Any help will be greatly appreciated.
Posted
Updated 16-Dec-11 5:24am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900