]> git.sesse.net Git - casparcg/blobdiff - modules/decklink/decklink_api.h
#430 Fixed bug where it was assumed that all Decklink devices implements the IDeckLin...
[casparcg] / modules / decklink / decklink_api.h
index f7ad079512f0dd48fc002c753ef555a4ddcf727f..10561e3e2901e19a2d7c1b7edf00399ae3caa7c9 100644 (file)
@@ -25,7 +25,7 @@
 
 #if defined(_MSC_VER)
 
-#include "interop/DeckLinkAPI_h.h"
+#include "interop/DeckLinkAPI.h"
 
 #pragma warning(push)
 #pragma warning(disable : 4996)
@@ -40,7 +40,7 @@
 namespace caspar { namespace decklink {
 
 typedef BSTR String;
-typedef unsigned long UINT32;
+typedef unsigned int UINT32;
 
 static void com_initialize()
 {
@@ -70,25 +70,30 @@ static P<T> wrap_raw(T* ptr, bool already_referenced = false)
     if (already_referenced)
     {
         P<T> p;
-        &p = ptr;
+        p.Attach(ptr);
         return p;
     }
     else
         return P<T>(ptr);
 }
 
-static com_ptr<IDecklinkIterator> create_iterator()
+static com_ptr<IDeckLinkIterator> create_iterator()
 {
     CComPtr<IDeckLinkIterator> pDecklinkIterator;
     if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))
-        CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink drivers not found."));
+        CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Decklink drivers not found."));
     return pDecklinkIterator;
 }
 
 template<typename I, typename T>
-static com_iface_ptr<I> iface_cast(com_ptr<T> ptr)
+static com_iface_ptr<I> iface_cast(const com_ptr<T>& ptr, bool optional = false)
 {
-    return com_iface_ptr<I>(ptr);
+       com_iface_ptr<I> result = ptr;
+
+       if (!optional && !result)
+               CASPAR_THROW_EXCEPTION(not_supported() << msg_info(std::string("Could not cast from ") + typeid(T).name() + " to " + typeid(I).name() + ". This is probably due to old Decklink drivers."));
+
+       return result;
 }
 
 template<typename T>
@@ -102,6 +107,7 @@ T* get_raw(const CComPtr<T>& ptr)
 #else
 
 #include "linux_interop/DeckLinkAPI.h"
+#include "linux_interop/DeckLinkAPIConfiguration_v10_2.h"
 #include <memory>
 #include <typeinfo>
 
@@ -155,7 +161,7 @@ static com_ptr<IDeckLinkIterator> create_iterator()
     IDeckLinkIterator* iterator = CreateDeckLinkIteratorInstance();
 
     if (iterator == nullptr)
-        CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink drivers not found."));
+        CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Decklink drivers not found."));
 
        return wrap_raw<com_ptr>(iterator, true);
 }
@@ -165,12 +171,13 @@ template<>              REFIID iface_id<IDeckLink>() { return IID_IDeckLink; }
 template<>              REFIID iface_id<IDeckLinkOutput>() { return IID_IDeckLinkOutput; }
 template<>              REFIID iface_id<IDeckLinkAPIInformation>() { return IID_IDeckLinkAPIInformation; }
 template<>              REFIID iface_id<IDeckLinkConfiguration>() { return IID_IDeckLinkConfiguration; }
+template<>              REFIID iface_id<IDeckLinkConfiguration_v10_2>() { return IID_IDeckLinkConfiguration_v10_2; }
 template<>              REFIID iface_id<IDeckLinkKeyer>() { return IID_IDeckLinkKeyer; }
 template<>              REFIID iface_id<IDeckLinkAttributes>() { return IID_IDeckLinkAttributes; }
 template<>              REFIID iface_id<IDeckLinkInput>() { return IID_IDeckLinkInput; }
 
 template<typename I, typename T>
-static com_iface_ptr<I> iface_cast(com_ptr<T> ptr)
+static com_iface_ptr<I> iface_cast(com_ptr<T> ptr, bool optional = false)
 {
     I* iface;
     ptr->QueryInterface(iface_id<I>(), reinterpret_cast<void**>(&iface));