commit 520371f9cc749b3f96faf14e52861e3d30c42405 parent a8d1468fd6ce4eee3c183c6069b79da31c8780bd Author: Marco Simonelli <msimonelli@protonmail.com> Date: Fri, 10 Mar 2023 11:50:33 +0000 BB 41459: WebRTC fails to build under mingw (Part 2) - fixes required to build third_party/libwebrtc Diffstat:
11 files changed, 55 insertions(+), 16 deletions(-)
diff --git a/dom/media/webrtc/libwebrtc_overrides/modules/desktop_capture/desktop_capture_types.h b/dom/media/webrtc/libwebrtc_overrides/modules/desktop_capture/desktop_capture_types.h @@ -7,9 +7,12 @@ #ifndef DOM_MEDIA_WEBRTC_LIBWEBRTCOVERRIDES_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_TYPES_H_ #define DOM_MEDIA_WEBRTC_LIBWEBRTCOVERRIDES_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_TYPES_H_ -#ifdef XP_WIN // Moving this into the global namespace -typedef int pid_t; // matching what used to be in -#endif // video_capture_defines.h +// pid_t +#if !defined(XP_WIN) || defined(__MINGW32__) +# include <sys/types.h> +#else +typedef int pid_t; +#endif #include "../../third_party/libwebrtc/modules/desktop_capture/desktop_capture_types.h" diff --git a/third_party/libwebrtc/modules/audio_coding/codecs/isac/main/source/os_specific_inline.h b/third_party/libwebrtc/modules/audio_coding/codecs/isac/main/source/os_specific_inline.h @@ -11,7 +11,7 @@ #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ -#if defined(WEBRTC_POSIX) +#if (defined(WEBRTC_POSIX) || defined(__MINGW32__)) #define WebRtcIsac_lrint lrint #elif (defined(WEBRTC_ARCH_X86) && defined(WIN32)) static __inline long int WebRtcIsac_lrint(double x_dbl) { diff --git a/third_party/libwebrtc/modules/desktop_capture/win/desktop_capture_utils.cc b/third_party/libwebrtc/modules/desktop_capture/win/desktop_capture_utils.cc @@ -12,7 +12,9 @@ #include <string> -#include "rtc_base/strings/string_builder.h" +#include <cstdio> +#include <cstdlib> +#include "stringapiset.h" namespace webrtc { namespace desktop_capture { @@ -22,11 +24,16 @@ namespace utils { std::string ComErrorToString(const _com_error& error) { char buffer[1024]; webrtc::SimpleStringBuilder string_builder(buffer); - // Use _bstr_t to simplify the wchar to char conversion for ErrorMessage(). - _bstr_t error_message(error.ErrorMessage()); - string_builder.AppendFormat("HRESULT: 0x%08X, Message: %s", error.Error(), - static_cast<const char*>(error_message)); - return string_builder.str(); + string_builder.AppendFormat("HRESULT: 0x%08X, Message: ", error.Error()); +#ifdef _UNICODE + WideCharToMultiByte(CP_UTF8, 0, error.ErrorMessage(), -1, + buffer + string_builder.size(), + sizeof(buffer) - string_builder.size(), nullptr, nullptr); + buffer[sizeof(buffer) - 1] = 0; +#else + string_builder << error.ErrorMessage(); +#endif + return buffer; } } // namespace utils diff --git a/third_party/libwebrtc/modules/desktop_capture/win/wgc_capture_session.cc b/third_party/libwebrtc/modules/desktop_capture/win/wgc_capture_session.cc @@ -11,6 +11,8 @@ #include <DispatcherQueue.h> #include <windows.graphics.capture.interop.h> #include <windows.graphics.directX.direct3d11.interop.h> +#include <windows.graphics.h> +#include <wrl/client.h> #include <wrl/event.h> #include <algorithm> diff --git a/third_party/libwebrtc/modules/desktop_capture/win/window_capture_utils.h b/third_party/libwebrtc/modules/desktop_capture/win/window_capture_utils.h @@ -11,7 +11,7 @@ #ifndef MODULES_DESKTOP_CAPTURE_WIN_WINDOW_CAPTURE_UTILS_H_ #define MODULES_DESKTOP_CAPTURE_WIN_WINDOW_CAPTURE_UTILS_H_ -#include <shlobj_core.h> +#include <shlobj.h> #include <windows.h> #include <wrl/client.h> diff --git a/third_party/libwebrtc/modules/video_capture/windows/device_info_ds.h b/third_party/libwebrtc/modules/video_capture/windows/device_info_ds.h @@ -12,7 +12,7 @@ #define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_WINDOWS_DEVICE_INFO_DS_H_ #include <dshow.h> -#include <Ks.h> +#include <ks.h> #include <dbt.h> #include "modules/video_capture/device_info_impl.h" diff --git a/third_party/libwebrtc/rtc_base/cpu_info.cc b/third_party/libwebrtc/rtc_base/cpu_info.cc @@ -97,7 +97,7 @@ uint64_t xgetbv(uint32_t xcr) { } #endif // WEBRTC_ENABLE_AVX2 -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(__MINGW32__) // Intrinsic for "cpuid". #if defined(__pic__) && defined(__i386__) static inline void __cpuid(int cpu_info[4], int info_type) { diff --git a/third_party/libwebrtc/rtc_base/platform_thread_types.cc b/third_party/libwebrtc/rtc_base/platform_thread_types.cc @@ -101,6 +101,8 @@ void SetCurrentThreadName(const char* name) { set_thread_description_func(::GetCurrentThread(), wide_thread_name); } +#if defined(_MSC_VER) + // SEH is only impelmented for the MSVC compiler // For details see: // https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code #pragma pack(push, 8) @@ -120,6 +122,7 @@ void SetCurrentThreadName(const char* name) { } __except (EXCEPTION_EXECUTE_HANDLER) { // NOLINT } #pragma warning(pop) +#endif // _MSC_VER #elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name)); // NOLINT #elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS) diff --git a/third_party/libwebrtc/rtc_base/socket.h b/third_party/libwebrtc/rtc_base/socket.h @@ -64,6 +64,20 @@ #define EHOSTUNREACH WSAEHOSTUNREACH #undef ENETUNREACH #define ENETUNREACH WSAENETUNREACH +#undef ENOTEMPTY +#define ENOTEMPTY WSAENOTEMPTY +#undef EPROCLIM +#define EPROCLIM WSAEPROCLIM +#undef EUSERS +#define EUSERS WSAEUSERS +#undef EDQUOT +#define EDQUOT WSAEDQUOT +#undef ESTALE +#define ESTALE WSAESTALE +#undef EREMOTE +#define EREMOTE WSAEREMOTE +#undef EACCES +#define EACCES WSAEACCES #define SOCKET_EACCES WSAEACCES #endif // WEBRTC_WIN diff --git a/third_party/libwebrtc/rtc_base/system/file_wrapper.cc b/third_party/libwebrtc/rtc_base/system/file_wrapper.cc @@ -23,7 +23,7 @@ #include "rtc_base/numerics/safe_conversions.h" #ifdef _WIN32 -#include <Windows.h> +#include <windows.h> #else #endif diff --git a/third_party/libwebrtc/rtc_base/win/create_direct3d_device.h b/third_party/libwebrtc/rtc_base/win/create_direct3d_device.h @@ -11,8 +11,18 @@ #ifndef RTC_BASE_WIN_CREATE_DIRECT3D_DEVICE_H_ #define RTC_BASE_WIN_CREATE_DIRECT3D_DEVICE_H_ -#include <windows.graphics.directX.direct3d11.h> -#include <windows.graphics.directX.direct3d11.interop.h> +#include <windows.graphics.directx.direct3d11.h> +#include <windows.graphics.directx.direct3d11.interop.h> +#ifdef __MINGW32__ +# include <dxgi.h> +# include <inspectable.h> +extern "C" { +// This function is only used in decltype(..) +HRESULT __stdcall CreateDirect3D11DeviceFromDXGIDevice( + ::IDXGIDevice* dxgiDevice, ::IInspectable** graphicsDevice); +} +#endif + #include <winerror.h> #include <wrl/client.h>