]> 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 9fd27b9ed1fe3e246f420f092c7328ece1cf9f76..10561e3e2901e19a2d7c1b7edf00399ae3caa7c9 100644 (file)
@@ -61,20 +61,8 @@ struct co_init
 template<typename T>
 using com_ptr = CComPtr<T>;
 
-// MSVC 2013 crashes when this alias template is instantiated
-/*template<typename T>
-using com_iface_ptr = CComQIPtr<T>;*/
-
 template<typename T>
-class com_iface_ptr : public CComQIPtr<T>
-{
-public:
-       template<typename T2>
-       com_iface_ptr(const com_ptr<T2>& lp)
-               : CComQIPtr<T>(lp)
-       {
-       }
-};
+using com_iface_ptr = CComQIPtr<T>;
 
 template<template<typename> class P, typename T>
 static P<T> wrap_raw(T* ptr, bool already_referenced = false)
@@ -93,14 +81,19 @@ 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(const 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>
@@ -114,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>
 
@@ -167,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);
 }
@@ -177,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));