Page 1 of 1

Delphi FMX on OSX

PostPosted: Mon Apr 03, 2017 1:10 am
by Bill Florac
I'm trying get the Decklink interface to work with Delphi (FMX) on OSX. I ported over the DeckLinkAPIDispatch.cpp file and it seems to initiate property via InitDeckLinkAPI but calls to create an Iterator instance return nil (NULL) [via function pointer "CreateDeckLinkIteratorInstance_0002"]. I have included parsed down version of my code. Anyone have a clue as to why this returns nil (NULL)?

Code: Select all
unit FMX.DeckLinkAPIDispatch;

interface

Uses
  FMX.DeckLinkAPI;

procedure InitDeckLinkAPI; cdecl;
function CreateDeckLinkIteratorInstance: IDeckLinkIterator;

implementation

uses
  Posix.Dlfcn, Posix.SysTypes, MacApi.CoreFoundation, Posix.Pthread;

type
  CreateIteratorFunc = function: IDeckLinkIterator;  cdecl ;

var
   gDeckLinkOnceControl : pthread_once_t   = (__sig: $30B1BCBA);//PTHREAD_ONCE_INIT;  // <pthread.h>
  gDeckLinkAPIBundleRef: CFBundleRef  = nil;
  gCreateIteratorFunc: CreateIteratorFunc = nil;

const
  kDeckLinkAPI_BundlePath = '/Library/Frameworks/DeckLinkAPI.framework';

// this seems to work
procedure InitDeckLinkAPI;
var
  bundleURL: CFURLRef;
begin
  bundleURL := CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
   if (bundleURL <> nil) then begin
     gDeckLinkAPIBundleRef := CFBundleCreate(kCFAllocatorDefault, bundleURL);
    if gDeckLinkAPIBundleRef <> nil then begin
      gCreateIteratorFunc         := CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR('CreateDeckLinkIteratorInstance_0002'));
      // at this point @gCreateIteratorFunc is not nil (good!)
    end;
    CFRelease(bundleURL);
  end;
end;

function CreateDeckLinkIteratorInstance: IDeckLinkIterator;
begin
   pthread_once(gDeckLinkOnceControl, InitDeckLinkAPI);
   if @gCreateIteratorFunc = nil // same as: if not Assigned(gCreateIteratorFunc)
   then exit(nil);
 
   result := gCreateIteratorFunc(); // <HERE!> this always return nil??
end;

end.