Browse Source

obs-qsv11: Remove Windows references from common files

This cleans up the fairly arbitrary Windows includes and types and
unused functions from the common code and replaces them with platform
independent equivalents, or platform specific implementations in
common_utils.

This removes the Windows 8 support to avoid adding an additional
platform function to query this. OBS only supports Windows 10
officially, so it's about time we removed it.
Kurt Kartaltepe 2 years ago
parent
commit
dc2f2f157b

+ 6 - 8
plugins/obs-qsv11/QSV_Encoder.cpp

@@ -59,13 +59,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 #include "QSV_Encoder.h"
 #include "QSV_Encoder.h"
 #include "QSV_Encoder_Internal.h"
 #include "QSV_Encoder_Internal.h"
+#include "common_utils.h"
 #include <obs-module.h>
 #include <obs-module.h>
 #include <string>
 #include <string>
 #include <atomic>
 #include <atomic>
-#include <intrin.h>
-#include <d3d11.h>
-#include <dxgi1_2.h>
-#include <wrl/client.h>
 
 
 #define do_log(level, format, ...) \
 #define do_log(level, format, ...) \
 	blog(level, "[qsv encoder: '%s'] " format, "msdk_impl", ##__VA_ARGS__)
 	blog(level, "[qsv encoder: '%s'] " format, "msdk_impl", ##__VA_ARGS__)
@@ -295,7 +292,7 @@ enum qsv_cpu_platform qsv_get_cpu_platform()
 	using std::string;
 	using std::string;
 
 
 	int cpuInfo[4];
 	int cpuInfo[4];
-	__cpuid(cpuInfo, 0);
+	util_cpuid(cpuInfo, 0);
 
 
 	string vendor;
 	string vendor;
 	vendor += string((char *)&cpuInfo[1], 4);
 	vendor += string((char *)&cpuInfo[1], 4);
@@ -305,9 +302,10 @@ enum qsv_cpu_platform qsv_get_cpu_platform()
 	if (vendor != "GenuineIntel")
 	if (vendor != "GenuineIntel")
 		return QSV_CPU_PLATFORM_UNKNOWN;
 		return QSV_CPU_PLATFORM_UNKNOWN;
 
 
-	__cpuid(cpuInfo, 1);
-	BYTE model = ((cpuInfo[0] >> 4) & 0xF) + ((cpuInfo[0] >> 12) & 0xF0);
-	BYTE family = ((cpuInfo[0] >> 8) & 0xF) + ((cpuInfo[0] >> 20) & 0xFF);
+	util_cpuid(cpuInfo, 1);
+	uint8_t model = ((cpuInfo[0] >> 4) & 0xF) + ((cpuInfo[0] >> 12) & 0xF0);
+	uint8_t family =
+		((cpuInfo[0] >> 8) & 0xF) + ((cpuInfo[0] >> 20) & 0xFF);
 
 
 	// See Intel 64 and IA-32 Architectures Software Developer's Manual,
 	// See Intel 64 and IA-32 Architectures Software Developer's Manual,
 	// Vol 3C Table 35-1
 	// Vol 3C Table 35-1

+ 1 - 1
plugins/obs-qsv11/QSV_Encoder.h

@@ -56,10 +56,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 #pragma once
 #pragma once
 
 
-#include <Windows.h>
 #include "mfxstructures.h"
 #include "mfxstructures.h"
 #include "mfxadapter.h"
 #include "mfxadapter.h"
 #include <stdint.h>
 #include <stdint.h>
+#include <stdbool.h>
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {

+ 17 - 42
plugins/obs-qsv11/QSV_Encoder_Internal.cpp

@@ -58,7 +58,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "QSV_Encoder.h"
 #include "QSV_Encoder.h"
 #include "mfxastructures.h"
 #include "mfxastructures.h"
 #include "mfxvideo++.h"
 #include "mfxvideo++.h"
-#include <VersionHelpers.h>
 #include <obs-module.h>
 #include <obs-module.h>
 
 
 #define do_log(level, format, ...) \
 #define do_log(level, format, ...) \
@@ -87,50 +86,25 @@ QSV_Encoder_Internal::QSV_Encoder_Internal(mfxIMPL &impl, mfxVersion &version,
 	mfxIMPL tempImpl;
 	mfxIMPL tempImpl;
 	mfxStatus sts;
 	mfxStatus sts;
 
 
-	m_bIsWindows8OrGreater = IsWindows8OrGreater();
-	m_bUseD3D11 = false;
+	m_bUseD3D11 = true;
 	m_bD3D9HACK = true;
 	m_bD3D9HACK = true;
-	m_bUseTexAlloc = (m_bUseD3D11 || m_bD3D9HACK);
-
-	if (m_bIsWindows8OrGreater) {
-		tempImpl = impl | MFX_IMPL_VIA_D3D11;
-		sts = m_session.Init(tempImpl, &version);
-		if (sts == MFX_ERR_NONE) {
-			m_session.QueryVersion(&version);
-			m_session.Close();
-
-			// Use D3D11 surface
-			// m_bUseD3D11 = ((version.Major > 1) ||
-			//	(version.Major == 1 && version.Minor >= 8));
-			m_bUseD3D11 = true;
-			if (m_bUseD3D11)
-				blog(LOG_INFO, "\timpl:           D3D11\n"
-					       "\tsurf:           D3D11");
-			else
-				blog(LOG_INFO, "\timpl:           D3D11\n"
-					       "\tsurf:           SysMem");
-
-			m_impl = tempImpl;
-			m_ver = version;
-			return;
-		}
-	} else if (m_bD3D9HACK) {
-		tempImpl = impl | MFX_IMPL_VIA_D3D9;
-		sts = m_session.Init(tempImpl, &version);
-		if (sts == MFX_ERR_NONE) {
-			m_session.QueryVersion(&version);
-			m_session.Close();
-
-			blog(LOG_INFO, "\timpl:           D3D09\n"
-				       "\tsurf:           Hack");
-
-			m_impl = tempImpl;
-			m_ver = version;
-			return;
-		}
+	m_bUseTexAlloc = true;
+
+	tempImpl = impl | MFX_IMPL_VIA_D3D11;
+	sts = m_session.Init(tempImpl, &version);
+	if (sts == MFX_ERR_NONE) {
+		m_session.QueryVersion(&version);
+		m_session.Close();
+
+		blog(LOG_INFO, "\timpl:           D3D11\n"
+			       "\tsurf:           D3D11");
+
+		m_impl = tempImpl;
+		m_ver = version;
+		return;
 	}
 	}
 
 
-	// Either windows 7 or D3D11 failed at this point.
+	// D3D11 failed at this point.
 	tempImpl = impl | MFX_IMPL_VIA_D3D9;
 	tempImpl = impl | MFX_IMPL_VIA_D3D9;
 	sts = m_session.Init(tempImpl, &version);
 	sts = m_session.Init(tempImpl, &version);
 	if (sts == MFX_ERR_NONE) {
 	if (sts == MFX_ERR_NONE) {
@@ -142,6 +116,7 @@ QSV_Encoder_Internal::QSV_Encoder_Internal(mfxIMPL &impl, mfxVersion &version,
 
 
 		m_impl = tempImpl;
 		m_impl = tempImpl;
 		m_ver = version;
 		m_ver = version;
+		m_bUseD3D11 = false;
 	}
 	}
 }
 }
 
 

+ 0 - 1
plugins/obs-qsv11/QSV_Encoder_Internal.h

@@ -129,7 +129,6 @@ private:
 	int m_nTaskIdx;
 	int m_nTaskIdx;
 	int m_nFirstSyncTask;
 	int m_nFirstSyncTask;
 	mfxBitstream m_outBitstream;
 	mfxBitstream m_outBitstream;
-	bool m_bIsWindows8OrGreater;
 	bool m_bUseD3D11;
 	bool m_bUseD3D11;
 	bool m_bD3D9HACK;
 	bool m_bD3D9HACK;
 	bool m_bUseTexAlloc;
 	bool m_bUseTexAlloc;

+ 1 - 0
plugins/obs-qsv11/common_utils.h

@@ -143,3 +143,4 @@ void mfxGetTime(mfxTime *timestamp);
 
 
 //void mfxInitTime();  might need this for Windows
 //void mfxInitTime();  might need this for Windows
 double TimeDiffMsec(mfxTime tfinish, mfxTime tstart);
 double TimeDiffMsec(mfxTime tfinish, mfxTime tstart);
+extern "C" void util_cpuid(int cpuinfo[4], int flags);

+ 7 - 0
plugins/obs-qsv11/common_utils_windows.cpp

@@ -9,6 +9,8 @@
 #include "common_directx9.h"
 #include "common_directx9.h"
 #endif
 #endif
 
 
+#include <intrin.h>
+
 /* =======================================================
 /* =======================================================
  * Windows implementation of OS-specific utility functions
  * Windows implementation of OS-specific utility functions
  */
  */
@@ -118,6 +120,11 @@ double TimeDiffMsec(mfxTime tfinish, mfxTime tstart)
 	       freq;
 	       freq;
 }
 }
 
 
+void util_cpuid(int cpuinfo[4], int flags)
+{
+	return __cpuid(cpuinfo, flags);
+}
+
 /* (Lain) Functions currently unused */
 /* (Lain) Functions currently unused */
 #if 0
 #if 0
 void ClearYUVSurfaceVMem(mfxMemId memId)
 void ClearYUVSurfaceVMem(mfxMemId memId)

+ 2 - 1
plugins/obs-qsv11/obs-qsv11-plugin-main.c

@@ -53,6 +53,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 */
+#include <inttypes.h>
 #include <obs-module.h>
 #include <obs-module.h>
 #include <util/windows/device-enum.h>
 #include <util/windows/device-enum.h>
 #include <util/config-file.h>
 #include <util/config-file.h>
@@ -85,7 +86,7 @@ size_t adapter_count = 0;
 static bool enum_luids(void *param, uint32_t idx, uint64_t luid)
 static bool enum_luids(void *param, uint32_t idx, uint64_t luid)
 {
 {
 	struct dstr *cmd = param;
 	struct dstr *cmd = param;
-	dstr_catf(cmd, " %llX", luid);
+	dstr_catf(cmd, " %" PRIx64, luid);
 	UNUSED_PARAMETER(idx);
 	UNUSED_PARAMETER(idx);
 	return true;
 	return true;
 }
 }

+ 16 - 35
plugins/obs-qsv11/obs-qsv11.c

@@ -55,21 +55,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 */
 
 
 #include <stdio.h>
 #include <stdio.h>
+#include <inttypes.h>
 #include <util/dstr.h>
 #include <util/dstr.h>
 #include <util/darray.h>
 #include <util/darray.h>
 #include <util/platform.h>
 #include <util/platform.h>
+#include <util/threading.h>
 #include <obs-module.h>
 #include <obs-module.h>
 #include <obs-hevc.h>
 #include <obs-hevc.h>
 #include <obs-avc.h>
 #include <obs-avc.h>
-#include <d3d11.h>
-#include <dxgi1_2.h>
-
-#ifndef _STDINT_H_INCLUDED
-#define _STDINT_H_INCLUDED
-#endif
 
 
 #include "QSV_Encoder.h"
 #include "QSV_Encoder.h"
-#include <Windows.h>
 
 
 #define do_log(level, format, ...)                 \
 #define do_log(level, format, ...)                 \
 	blog(level, "[qsv encoder: '%s'] " format, \
 	blog(level, "[qsv encoder: '%s'] " format, \
@@ -103,7 +98,7 @@ struct obs_qsv {
 
 
 /* ------------------------------------------------------------------------- */
 /* ------------------------------------------------------------------------- */
 
 
-static SRWLOCK g_QsvLock = SRWLOCK_INIT;
+static pthread_mutex_t g_QsvLock = PTHREAD_MUTEX_INITIALIZER;
 static unsigned short g_verMajor;
 static unsigned short g_verMajor;
 static unsigned short g_verMinor;
 static unsigned short g_verMinor;
 static int64_t g_pts2dtsShift;
 static int64_t g_pts2dtsShift;
@@ -139,10 +134,10 @@ static void obs_qsv_stop(void *data);
 static void clear_data(struct obs_qsv *obsqsv)
 static void clear_data(struct obs_qsv *obsqsv)
 {
 {
 	if (obsqsv->context) {
 	if (obsqsv->context) {
-		AcquireSRWLockExclusive(&g_QsvLock);
+		pthread_mutex_lock(&g_QsvLock);
 		qsv_encoder_close(obsqsv->context);
 		qsv_encoder_close(obsqsv->context);
 		obsqsv->context = NULL;
 		obsqsv->context = NULL;
-		ReleaseSRWLockExclusive(&g_QsvLock);
+		pthread_mutex_unlock(&g_QsvLock);
 
 
 		// bfree(obsqsv->sei);
 		// bfree(obsqsv->sei);
 		bfree(obsqsv->extra_data);
 		bfree(obsqsv->extra_data);
@@ -885,9 +880,9 @@ static void *obs_qsv_create(enum qsv_codec codec, obs_data_t *settings,
 	}
 	}
 
 
 	if (update_settings(obsqsv, settings)) {
 	if (update_settings(obsqsv, settings)) {
-		AcquireSRWLockExclusive(&g_QsvLock);
+		pthread_mutex_lock(&g_QsvLock);
 		obsqsv->context = qsv_encoder_open(&obsqsv->params, codec);
 		obsqsv->context = qsv_encoder_open(&obsqsv->params, codec);
-		ReleaseSRWLockExclusive(&g_QsvLock);
+		pthread_mutex_unlock(&g_QsvLock);
 
 
 		if (obsqsv->context == NULL)
 		if (obsqsv->context == NULL)
 			warn("qsv failed to load");
 			warn("qsv failed to load");
@@ -918,9 +913,9 @@ static void *obs_qsv_create(enum qsv_codec codec, obs_data_t *settings,
 			GopPicSize - (GopPicSize / interval) * interval;
 			GopPicSize - (GopPicSize / interval) * interval;
 
 
 		blog(LOG_INFO,
 		blog(LOG_INFO,
-		     "\tinterval:       %d\n"
-		     "\tGopPictSize:    %d\n"
-		     "\tg_pts2dtsShift: %d",
+		     "\tinterval:       %" PRId64 "\n"
+		     "\tGopPictSize:    %" PRId64 "\n"
+		     "\tg_pts2dtsShift: %" PRId64,
 		     interval, GopPicSize, g_pts2dtsShift);
 		     interval, GopPicSize, g_pts2dtsShift);
 	} else
 	} else
 		g_pts2dtsShift = -1;
 		g_pts2dtsShift = -1;
@@ -952,20 +947,6 @@ static void *obs_qsv_create_hevc(obs_data_t *settings, obs_encoder_t *encoder)
 	return obs_qsv_create(QSV_CODEC_HEVC, settings, encoder);
 	return obs_qsv_create(QSV_CODEC_HEVC, settings, encoder);
 }
 }
 
 
-static HANDLE get_lib(const char *lib)
-{
-	HMODULE mod = GetModuleHandleA(lib);
-	if (mod)
-		return mod;
-
-	mod = LoadLibraryA(lib);
-	if (!mod)
-		blog(LOG_INFO, "Failed to load %s", lib);
-	return mod;
-}
-
-typedef HRESULT(WINAPI *CREATEDXGIFACTORY1PROC)(REFIID, void **);
-
 static void *obs_qsv_create_tex(enum qsv_codec codec, obs_data_t *settings,
 static void *obs_qsv_create_tex(enum qsv_codec codec, obs_data_t *settings,
 				obs_encoder_t *encoder, const char *fallback_id)
 				obs_encoder_t *encoder, const char *fallback_id)
 {
 {
@@ -1376,7 +1357,7 @@ static bool obs_qsv_encode(void *data, struct encoder_frame *frame,
 	if (!frame || !packet || !received_packet)
 	if (!frame || !packet || !received_packet)
 		return false;
 		return false;
 
 
-	AcquireSRWLockExclusive(&g_QsvLock);
+	pthread_mutex_lock(&g_QsvLock);
 
 
 	video_t *video = obs_encoder_video(obsqsv->encoder);
 	video_t *video = obs_encoder_video(obsqsv->encoder);
 	const struct video_output_info *voi = video_output_get_info(video);
 	const struct video_output_info *voi = video_output_get_info(video);
@@ -1400,7 +1381,7 @@ static bool obs_qsv_encode(void *data, struct encoder_frame *frame,
 
 
 	if (ret < 0) {
 	if (ret < 0) {
 		warn("encode failed");
 		warn("encode failed");
-		ReleaseSRWLockExclusive(&g_QsvLock);
+		pthread_mutex_unlock(&g_QsvLock);
 		return false;
 		return false;
 	}
 	}
 
 
@@ -1411,7 +1392,7 @@ static bool obs_qsv_encode(void *data, struct encoder_frame *frame,
 	else if (obsqsv->codec == QSV_CODEC_HEVC)
 	else if (obsqsv->codec == QSV_CODEC_HEVC)
 		parse_packet_hevc(obsqsv, packet, pBS, voi, received_packet);
 		parse_packet_hevc(obsqsv, packet, pBS, voi, received_packet);
 
 
-	ReleaseSRWLockExclusive(&g_QsvLock);
+	pthread_mutex_unlock(&g_QsvLock);
 
 
 	return true;
 	return true;
 }
 }
@@ -1432,7 +1413,7 @@ static bool obs_qsv_encode_tex(void *data, uint32_t handle, int64_t pts,
 	if (!packet || !received_packet)
 	if (!packet || !received_packet)
 		return false;
 		return false;
 
 
-	AcquireSRWLockExclusive(&g_QsvLock);
+	pthread_mutex_lock(&g_QsvLock);
 
 
 	video_t *video = obs_encoder_video(obsqsv->encoder);
 	video_t *video = obs_encoder_video(obsqsv->encoder);
 	const struct video_output_info *voi = video_output_get_info(video);
 	const struct video_output_info *voi = video_output_get_info(video);
@@ -1448,7 +1429,7 @@ static bool obs_qsv_encode_tex(void *data, uint32_t handle, int64_t pts,
 
 
 	if (ret < 0) {
 	if (ret < 0) {
 		warn("encode failed");
 		warn("encode failed");
-		ReleaseSRWLockExclusive(&g_QsvLock);
+		pthread_mutex_unlock(&g_QsvLock);
 		return false;
 		return false;
 	}
 	}
 
 
@@ -1459,7 +1440,7 @@ static bool obs_qsv_encode_tex(void *data, uint32_t handle, int64_t pts,
 	else if (obsqsv->codec == QSV_CODEC_HEVC)
 	else if (obsqsv->codec == QSV_CODEC_HEVC)
 		parse_packet_hevc(obsqsv, packet, pBS, voi, received_packet);
 		parse_packet_hevc(obsqsv, packet, pBS, voi, received_packet);
 
 
-	ReleaseSRWLockExclusive(&g_QsvLock);
+	pthread_mutex_unlock(&g_QsvLock);
 
 
 	return true;
 	return true;
 }
 }