decklink: Fix linking on MinGW
authorNirbheek Chauhan <nirbheek@centricular.com>
Thu, 4 May 2017 23:00:59 +0000 (04:30 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Fri, 5 May 2017 12:19:22 +0000 (17:49 +0530)
MinGW does not provide comsupp.lib, so there's no implementation of
_com_util::ConvertBSTRToString. Use a fallback implementation that
uses wcstombs() instead.

On MinGW we also truncate the name to 100 chars which should be fine.

sys/decklink/gstdecklink.cpp
sys/decklink/gstdecklink.h
sys/decklink/meson.build

index 1c79e3f..f39e2fc 100644 (file)
@@ -967,7 +967,7 @@ init_devices (gpointer data)
 
         GST_DEBUG ("Input %d supports:", i);
         while ((ret = mode_iter->Next (&mode)) == S_OK) {
-          const char *name;
+          char *name;
 
           mode->GetName ((COMSTR_T *) & name);
           CONVERT_COM_STRING (name);
@@ -1005,7 +1005,7 @@ init_devices (gpointer data)
 
         GST_DEBUG ("Output %d supports:", i);
         while ((ret = mode_iter->Next (&mode)) == S_OK) {
-          const char *name;
+          char *name;
 
           mode->GetName ((COMSTR_T *) & name);
           CONVERT_COM_STRING (name);
index 052f099..820fa44 100644 (file)
 #define bool BOOL
 
 #define COMSTR_T BSTR
-#define FREE_COM_STRING(s) delete[] s;
-#define CONVERT_COM_STRING(s) BSTR _s = (BSTR)s; s = _com_util::ConvertBSTRToString(_s); ::SysFreeString(_s);
+/* MinGW does not have comsuppw.lib, so no _com_util::ConvertBSTRToString */
+# ifdef __MINGW32__
+#  define CONVERT_COM_STRING(s) BSTR _s = (BSTR)s; s = (char*) malloc(100); wcstombs(s, _s, 100); ::SysFreeString(_s);
+#  define FREE_COM_STRING(s) free(s);
+# else
+#  define CONVERT_COM_STRING(s) BSTR _s = (BSTR)s; s = _com_util::ConvertBSTRToString(_s); ::SysFreeString(_s);
+#  define FREE_COM_STRING(s) delete[] s;
+# endif
 #else
 #define COMSTR_T const char*
-#define FREE_COM_STRING(s)
 #define CONVERT_COM_STRING(s)
-#endif /* _MSC_VER */
+#define FREE_COM_STRING(s)
+#endif /* G_OS_WIN32 */
 
 typedef enum {
   GST_DECKLINK_MODE_AUTO,
index 12e086e..a7e094f 100644 (file)
@@ -12,12 +12,15 @@ decklink_libs = []
 
 if host_machine.system() == 'windows'
   decklink_sources += ['win/DeckLinkAPIDispatch.cpp', 'win/DeckLinkAPI_i.c']
-  # Only used by MSVC. On MinGW, this is all inlined.
-  # FIXME: Use commsuppwd.lib for debug builds?
-  comutil_dep = cxx.find_library('comsuppw', required : false)
-  if comutil_dep.found()
+  if cxx.get_id() == 'msvc'
+    # FIXME: Use commsuppwd.lib for debug builds?
+    comutil_dep = cxx.find_library('comsuppw')
+    if comutil_dep.found()
+      build_decklink = true
+      decklink_libs = [comutil_dep]
+    endif
+  else
     build_decklink = true
-    decklink_libs = [comutil_dep]
   endif
 else
   libdl = cc.find_library('dl', required: false)