[SOLVED] Stuck on creating an IBMDSwitcherCallback

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

jhsware

  • Posts: 3
  • Joined: Fri Dec 10, 2021 10:24 pm
  • Real Name: Sebastian Ware

[SOLVED] Stuck on creating an IBMDSwitcherCallback

PostFri Dec 10, 2021 10:42 pm

I am attempting to do FFI from dart to the Blackmagic Switcher SDK. I can connect and perform simple tasks such as switching input and getting info about my ATEM mini switcher.

Next step is to register a callback and I have tried to adapt the Obj-C++ example SwitcherPanel to pure C++ but I am getting a compilation error when comparing the incoming REFIID with the const defined in BMDSwitcherAPI.h.

Code: Select all
 error: invalid operands to binary expression ('REFIID' (aka 'CFUUIDBytes') and 'const REFIID' (aka 'const CFUUIDBytes'))

My implementation at the end, and the error is in the implementation of QueryInterface on the line:
Code: Select all
if (iid == IID_IBMDSwitcherCallback)
.
I have looked att ten different examples and nothing gets me any closer to understanding what is going wrong. Any help would be much appreciated. Including pointers to functional C++ code. Google is falling short... /Sebastian

switcher_monitor.cpp
Code: Select all
#include "BMDSwitcherAPI.h"
#include "com_ptr.h"
#include <libkern/OSAtomic.h>
#include <map>
#include <string>

// Callback class to monitor switcher disconnection
class SwitcherMonitor : public IBMDSwitcherCallback
{
public:
   SwitcherMonitor(void (*callback)(char *)) :   mCallback(callback), mRefCount(1) { }

protected:
   virtual ~SwitcherMonitor() { }
   
public:
   // IBMDSwitcherCallback interface
   HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
   {
      if (!ppv)
         return E_POINTER;
      
      if (iid == IID_IBMDSwitcherCallback)
      {
         *ppv = static_cast<IBMDSwitcherCallback*>(this);
         AddRef();
         return S_OK;
      }
      
      if (CFEqual(&iid, IUnknownUUID))
      {
         *ppv = static_cast<IUnknown*>(this);
         AddRef();
         return S_OK;
      }
      
      *ppv = NULL;
      return E_NOINTERFACE;
   }

   ULONG STDMETHODCALLTYPE AddRef(void)
   {
      return ::OSAtomicIncrement32(&mRefCount);
   }

   ULONG STDMETHODCALLTYPE Release(void)
   {
      int newCount = ::OSAtomicDecrement32(&mRefCount);
      if (newCount == 0)
         delete this;
      return newCount;
   }
   
   // Switcher events ignored by this sample app
   HRESULT STDMETHODCALLTYPE   Notify(BMDSwitcherEventType eventType, BMDSwitcherVideoMode coreVideoMode)
   {
      if (eventType == bmdSwitcherEventTypeDisconnected)
      {
         mCallback((char*)"disconnected");
      }
    else {
      mCallback((char*)"other_event");
    }
      return S_OK;
   }
   
private:
   void (*mCallback)(char *);
   int                     mRefCount;
};
Last edited by jhsware on Tue Dec 14, 2021 8:14 am, edited 1 time in total.
Offline

jhsware

  • Posts: 3
  • Joined: Fri Dec 10, 2021 10:24 pm
  • Real Name: Sebastian Ware

[SOLVED] Re: Stuck on creating an IBMDSwitcherCallback

PostTue Dec 14, 2021 8:14 am

I solved the issue. Missed that there was an operator overload defined earlier in the code I used as a template:

Code: Select all
static inline bool   operator== (const REFIID& iid1, const REFIID& iid2)
{
   return CFEqual(&iid1, &iid2);
}


So now I only have to handle returning the message on my main Dart thread, but that is a Dart FFI-challenge.

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 6 guests