locked
Passing in a callback object to MediaCapture

    Question

  • Hi,

    I am writing an app that needs access to individual video frames, after searching the web for a while I found the "Media capture using capture device sample" (http://code.msdn.microsoft.com/windowsapps/media-capture-sample-adf87622) and I ran into the following problem:

    - How do I callback from the grayscale plugin to the managed c++ code? in c++ the plugin is instantiated this way:

     
    m_mediaCaptureMgr->AddEffectAsync(Windows::Media::Capture::MediaStreamType::VideoPreview,"GrayscaleTransform.GrayscaleEffect", nullptr)

    so I tried creating a new property to pass into the Grayscale transform object

    auto vc = ref new MyCallback::Class1( );
    auto properties = ref new Windows::Foundation::Collections::PropertySet( );
    properties->Insert( "{my random id goes here}", vc );

    Currently MyCallback::Class1 is an empty C# class that has no function in it, I'm still trying to figure out how that works

    and on the Grayscale plugin side, I have code in SetProperties (copied from another forum post)

        Microsoft::WRL::ComPtr< ABI::Windows::Foundation::Collections::IMap< HSTRING, IInspectable * > > spSetting;
        pConfiguration->QueryInterface( IID_PPV_ARGS( &spSetting ) );
    
        HSTRING key;
        boolean found;
        WindowsCreateString( L"{my random id goes here}", 38, &key );
        spSetting->HasKey( key, &found );
    
        if ( found )
        {
            IInspectable* value;
            if ( spSetting->Lookup( key, &value ) == S_OK )
            {
                // what do i do here?
            }
        }
     

    since c# has no header files, i can't really include that in grayscale.cpp. in the debugger i do see the type of value is MyCallback::Class1

    HSTRING name;
    value->GetRuntimeClassName( &name );

    but how do I get the value and cast that back to MyCallback::Class1* so that I can invoke functions in that class? Or do I need a c++ class for that?

    Or is there a better (and hopefully easier) way to call back from Grayscale.cpp to c++?

    thanks!

    Anthony

    edit:

    I also tried using delegates, in AdvancedCapture.xaml.h

            delegate void SomeCallback(char* arg);
        public:
            void SomeCallbackImp(char* arg);

    and in the cpp file:

    auto properties = ref new Windows::Foundation::Collections::PropertySet( );
            auto callback = ref new SomeCallback(this, &MediaCapture::AdvancedCapture::SomeCallbackImp);
            properties->Insert( "{my random id goes here}", callback);
            create_task(m_mediaCaptureMgr->AddEffectAsync(Windows::Media::Capture::MediaStreamType::VideoPreview,"GrayscaleTransform.GrayscaleEffect", properties))...
    and then i'm stuck at the same point in Grayscale.cpp, how do I get the delegate pointer out from IInspectable?




    • Edited by A. Sham Tuesday, August 7, 2012 8:38 PM
    Tuesday, August 7, 2012 6:37 PM

All replies

  • How about the Async function. IAsyncAction interface

    http://msdn.microsoft.com/en-us/library/hh750082(v=vs.110).aspx


    NEU_ShieldEdge

    Monday, August 13, 2012 8:34 AM
  • thanks for the reply, but the problem is that I do not have a handle to the plugin since it is created by MediaCapture:

    m_mediaCaptureMgr->AddEffectAsync(Windows::Media::Capture::MediaStreamType::VideoPreview,"GrayscaleTransform.GrayscaleEffect", nullptr)
    and there's no method for me to get the instance back from MediaCapture
    Monday, August 13, 2012 5:44 PM
  • Worked around this by using sockets to stream data back to the calling class... is there a better way?
    Wednesday, August 15, 2012 9:35 PM