diff --git a/InputPipeMain/InputPipeMain.cpp b/InputPipeMain/InputPipeMain.cpp index 2e462e6..981656b 100644 --- a/InputPipeMain/InputPipeMain.cpp +++ b/InputPipeMain/InputPipeMain.cpp @@ -24,6 +24,12 @@ INPUT_PLUGIN_TABLE* g_winputPluginTable = nullptr; std::vector g_readVideoBuffer; std::vector g_readAudioBuffer; +#ifdef _WIN64 +#define LWINNPUT_NAME L"lwinput64.aui" +#else +#define LWINNPUT_NAME L"lwinput.aui" +#endif + // for Logger std::string LogFileName() { @@ -81,14 +87,21 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); +#ifdef _DEBUG + ATLTRACE(L"INPUT_INFO size: %d\n", sizeof(INPUT_INFO)); + ATLTRACE(L"INPUT_INFO32 size: %d\n", sizeof(INPUT_INFO32)); + ATLTRACE(L"INPUT_PLUGIN_TABLE size: %d\n", sizeof(INPUT_PLUGIN_TABLE)); + +#endif + g_hModule = hInstance; #if 1 std::wstring cmdLine = lpCmdLine;//::GetCommandLine(); // INFO_LOG << L"CommandLine: " << cmdLine; if (cmdLine.empty()) { - bool pluginExists = fs::exists((GetExeDirectory() / L"lwinput.aui")); - MessageBox(NULL, pluginExists ? L"lwinput.aui が同じフォルダに存在しています!" - : L"lwinput.aui が同じフォルダに存在しません...", L"InputPipeMain", MB_OK); + bool pluginExists = fs::exists((GetExeDirectory() / LWINNPUT_NAME)); + MessageBox(NULL, pluginExists ? LWINNPUT_NAME L" が同じフォルダに存在しています!" + : LWINNPUT_NAME L" が同じフォルダに存在しません...", L"InputPipeMain", MB_OK); return 0; } else if (cmdLine == L"-config") { int ret = Run(); @@ -117,7 +130,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, ::CloseHandle(hJob); { - g_hWinputDll = ::LoadLibrary((GetExeDirectory() /L"lwinput.aui").c_str()); + g_hWinputDll = ::LoadLibrary((GetExeDirectory() / LWINNPUT_NAME).c_str()); assert(g_hWinputDll); if (g_hWinputDll == NULL) { //WARN_LOG << L"LoadLibrary failed (lwinput.aui)"; @@ -126,7 +139,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, using GetInputPluginTableFunc = INPUT_PLUGIN_TABLE * (__stdcall*)(void); GetInputPluginTableFunc funcGetTable = (GetInputPluginTableFunc)::GetProcAddress(g_hWinputDll, "GetInputPluginTable"); - + ATLASSERT(funcGetTable); g_winputPluginTable = funcGetTable(); } @@ -154,6 +167,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, NamedPipe namedPipe; bool success = namedPipe.OpenNamedPipe(pipeName); if (!success) { + ATLASSERT(FALSE); return 0; } @@ -176,7 +190,11 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, case CallFunc::kOpen: { LPSTR file = (LPSTR)dataBody.data(); +#ifdef INPUT_PIPE_MAIN64 + INPUT_HANDLE32 ih = Plugin_func_open(file); +#else INPUT_HANDLE ih = Plugin_func_open(file); +#endif //INFO_LOG << L"kOpen: " << ih; auto fromData = GenerateFromInputData(CallFunc::kOpen, ih, 0); @@ -317,9 +335,12 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, { //INFO_LOG << L"kIsKeyframe"; +#ifdef INPUT_PIPE_MAIN64 + BOOL b = FALSE; +#else StandardParamPack* spp = (StandardParamPack*)dataBody.data(); BOOL b = g_winputPluginTable->func_is_keyframe(spp->ih, spp->param1); - +#endif auto fromData = GenerateFromInputData(CallFunc::kIsKeyframe, b, 0); namedPipe.Write((const BYTE*)fromData.get(), FromWinputDataTotalSize(*fromData)); } diff --git a/InputPipeMain/InputPipeMain.vcxproj b/InputPipeMain/InputPipeMain.vcxproj index d2a70d7..f6ec513 100644 --- a/InputPipeMain/InputPipeMain.vcxproj +++ b/InputPipeMain/InputPipeMain.vcxproj @@ -78,6 +78,9 @@ true + C:\Programing\#lib\boost_1_73_0\lib\include\boost-1_73;C:\Programing\#lib\WTL10_10320_Release\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + C:\Programing\#lib\boost_1_73_0\lib\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) + $(ProjectName)64 false @@ -87,6 +90,9 @@ false + C:\Programing\#lib\boost_1_73_0\lib\include\boost-1_73;C:\Programing\#lib\WTL10_10320_Release\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + C:\Programing\#lib\boost_1_73_0\lib\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) + $(ProjectName)64 @@ -112,8 +118,9 @@ Level3 Disabled true - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + INPUT_PIPE_MAIN;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true + MultiThreadedDebug Windows @@ -150,8 +157,9 @@ true true true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + INPUT_PIPE_MAIN;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true + MultiThreaded Windows @@ -161,6 +169,7 @@ + @@ -173,6 +182,7 @@ + diff --git a/InputPipeMain/InputPipeMain.vcxproj.filters b/InputPipeMain/InputPipeMain.vcxproj.filters index b27d7f3..4de35f8 100644 --- a/InputPipeMain/InputPipeMain.vcxproj.filters +++ b/InputPipeMain/InputPipeMain.vcxproj.filters @@ -48,6 +48,9 @@ ソース ファイル\Share + + ソース ファイル\Share + @@ -68,6 +71,9 @@ ソース ファイル\Share + + ソース ファイル\Share + diff --git a/InputPipePlugin/input.cpp b/InputPipePlugin/input.cpp index d41bf61..606470f 100644 --- a/InputPipePlugin/input.cpp +++ b/InputPipePlugin/input.cpp @@ -178,6 +178,10 @@ BOOL func_init( void ) } auto InputPipeMainPath = GetExeDirectory() / L"InputPipeMain.exe"; + auto lwinput64Path = GetExeDirectory() / L"lwinput64.aui"; + if (fs::exists(lwinput64Path)) { + InputPipeMainPath = GetExeDirectory() / L"InputPipeMain64.exe"; + } std::wstring commandLine = pipeName; if (m_config.bUseSharedMemory) { diff --git a/InputPipePlugin/input.h b/InputPipePlugin/input.h index 3530172..21c7071 100644 --- a/InputPipePlugin/input.h +++ b/InputPipePlugin/input.h @@ -7,6 +7,7 @@ #include #include +#include // ̓t@C\ typedef struct { @@ -25,6 +26,24 @@ typedef struct { DWORD handler; // 摜codecnh int reserve[7]; } INPUT_INFO; + +typedef struct { + int flag; // tO + // INPUT_INFO_FLAG_VIDEO : 摜f[^ + // INPUT_INFO_FLAG_AUDIO : f[^ + // INPUT_INFO_FLAG_VIDEO_RANDOM_ACCESS : L[t[Cɂfunc_read_video()Ăяo܂ + // Wł̓L[t[V[PVfunc_read_video()Ă΂悤ɐ䂳܂ + int rate, scale; // t[[g + int n; // t[ + uint32_t format; // 摜tH[}bgւ̃|C^(Ɋ֐Ă΂܂œeLɂĂ) [****_~[****] + int format_size; // 摜tH[}bg̃TCY + int audio_n; // Tv + uint32_t audio_format; // tH[}bgւ̃|C^(Ɋ֐Ă΂܂œeLɂĂ) [****_~[****] + int audio_format_size; // tH[}bg̃TCY + DWORD handler; // 摜codecnh + int reserve[7]; +} INPUT_INFO32; + #define INPUT_INFO_FLAG_VIDEO 1 #define INPUT_INFO_FLAG_AUDIO 2 #define INPUT_INFO_FLAG_VIDEO_RANDOM_ACCESS 8 @@ -34,6 +53,7 @@ typedef struct { // ̓t@Cnh typedef void* INPUT_HANDLE; +typedef uint32_t INPUT_HANDLE32; // ̓vOC\ typedef struct { diff --git a/Readme.md b/Readme.md index 5cee8b6..f2e4d04 100644 --- a/Readme.md +++ b/Readme.md @@ -39,6 +39,16 @@ InputPipePlugin.aui と InputPipeMain.exe をコピーするだけです "InputPipeMain.exe"を起動してみて、"lwinput.aui が同じフォルダに存在しています!"と表示されれば大丈夫です もしくは、[InputPipePluginの設定]から[プロセス間通信を有効にする]のチェックを外してください +## ■InputPipeMain64.exe について + +64bit版 L-SMASH_Works File Reader(lwinput64.aui)が InputPipePlugin.aui と同じフォルダ内に存在するとき、そちらを利用するようになります +リリース時に 64bit版L-SMASH_Works File Readerが存在しないので正常に動作するかは不明です + +- 想定している内部仕様について + +32bitと64bitでは INPUT_INFO や INPUT_HANDLE のサイズが異なりますが、InputPipeMain64.exeが内部で変換してからInputPipePlugin.auiへ伝えるので、lwinput64.aui側で特に何かする必要はありません + + ## ■設定 [ファイル]->[環境設定]->[入力プラグインの設定]->[InputPipePluginの設定]で プラグインの設定ができます @@ -151,6 +161,9 @@ http://sourceforge.net/projects/wtl/ ## ■更新履歴
 
+v2.0
+・[add] InputPipeMain64.exeを追加 (64bit版 L-SMASH_Works File Reader(lwinput64.aui)が存在するときはそちらを利用するようにした)
+
 v1.10
 ・[fix] 動画ファイルの幅、高さが4の倍数でないときに強制終了するバグを修正 #5
 
diff --git a/Share/Common.cpp b/Share/Common.cpp
index 843e8f3..39c0207 100644
--- a/Share/Common.cpp
+++ b/Share/Common.cpp
@@ -38,33 +38,49 @@ std::unique_ptr SerializeInputInfo(INPUT_INFO* iip)
 	const int infoGetDataSize = CalcTotalInputInfoSize(iip);
 	auto infoGetData = std::make_unique(infoGetDataSize);
 	// INPUT_INFO Rs[
+#ifndef _WIN64
 	memcpy_s(infoGetData.get(), infoGetDataSize, iip, sizeof(INPUT_INFO));
-	auto igData = reinterpret_cast(infoGetData.get());
+#else
+	INPUT_INFO32* pinfo = reinterpret_cast(infoGetData.get());
+	pinfo->flag = iip->flag;
+	pinfo->rate = iip->rate;
+	pinfo->scale = iip->scale;
+	pinfo->n = iip->n;
+	pinfo->format_size = iip->format_size;
+	pinfo->audio_n = iip->audio_n;
+	pinfo->audio_format_size = iip->audio_format_size;
+	pinfo->handler = iip->handler;
+#endif
+	auto igData = reinterpret_cast(infoGetData.get());
 
 	// formataudio_formatꂼ mۂ̌ɃRs[
-	::memcpy_s(infoGetData.get() + sizeof(INPUT_INFO),
+	::memcpy_s(infoGetData.get() + sizeof(INPUT_INFO32),
 		iip->format_size,
 		iip->format, iip->format_size);
-	::memcpy_s(infoGetData.get() + sizeof(INPUT_INFO) + iip->format_size,
+	::memcpy_s(infoGetData.get() + sizeof(INPUT_INFO32) + iip->format_size,
 		iip->audio_format_size,
 		iip->audio_format, iip->audio_format_size);
 
-	// ꂼ̃tH[}bg̎wAmۂݒ
+	// ꂼ̃tH[}bg̎wAmۂݒ	(ӖȂ k|ƖɂȂ邩Ȃ)
 	if (igData->format_size > 0) {
-		igData->format = (BITMAPINFOHEADER*)(infoGetData.get() + sizeof(INPUT_INFO));
+		igData->format = reinterpret_cast((BITMAPINFOHEADER*)(infoGetData.get() + sizeof(INPUT_INFO)));
 	} else {
-		igData->format = nullptr;
+		igData->format = 0;	// nullptr;
 	}
 	if (igData->audio_format_size > 0) {
-		igData->audio_format = (WAVEFORMATEX*)(infoGetData.get() + sizeof(INPUT_INFO) + igData->format_size);
+		igData->audio_format = reinterpret_cast((WAVEFORMATEX*)(infoGetData.get() + sizeof(INPUT_INFO) + igData->format_size));
 	} else {
-		igData->audio_format = nullptr;
+		igData->audio_format = 0;	// nullptr;
 	}
 	return infoGetData;
 }
 
 std::unique_ptr DeserializeInputInfo(const BYTE* serializedData, INPUT_INFO* iip)
 {
+#ifdef _WIN64
+	assert(FALSE);	// 64bitłł̓fVACY͌Ă΂Ȃ͂
+#endif
+
 	auto tempInputInfo = (INPUT_INFO*)serializedData;
 	if (tempInputInfo->format_size > 0) {
 		tempInputInfo->format = (BITMAPINFOHEADER*)(reinterpret_cast(tempInputInfo) + sizeof(INPUT_INFO));
diff --git a/Share/Common.h b/Share/Common.h
index 42eb800..6f23259 100644
--- a/Share/Common.h
+++ b/Share/Common.h
@@ -24,7 +24,7 @@ BOOL func_config(HWND hwnd, HINSTANCE dll_hinst);
 
 ////////////////////////////////////////////////////////////////
 
-#define		PLUGIN_VERSION	"1.10"
+#define		PLUGIN_VERSION	"2.0"
 
 
 constexpr	int kVideoBufferSurplusBytes = 0x3FF;
@@ -59,7 +59,7 @@ struct Config
 ////////////////////////////////////////////////////////////////
 
 inline int CalcTotalInputInfoSize(INPUT_INFO* iip) { 
-	return sizeof(INPUT_INFO) + iip->format_size + iip->audio_format_size;
+	return sizeof(INPUT_INFO32) + iip->format_size + iip->audio_format_size;
 }
 
 std::unique_ptr SerializeInputInfo(INPUT_INFO* iip);
@@ -83,7 +83,11 @@ enum class CallFunc : std::int32_t
 
 struct StandardParamPack
 {
+#ifdef _WIN64
+	INPUT_HANDLE32 ih;
+#else
 	INPUT_HANDLE ih;
+#endif
 	int param1;
 	int param2;
 	int perBufferSize;
@@ -143,7 +147,7 @@ std::shared_ptr GenerateFromInputData(CallFunc callFunc, RetT re
 		delete[] (BYTE*)p;  
 	});
 	fromData->callFunc = callFunc;
-	fromData->returnSize = returnSize;
+	fromData->returnSize = static_cast(returnSize);
 	memcpy_s(fromData->returnData, sizeof(ret), &ret, sizeof(ret));
 	memcpy_s(fromData->returnData + sizeof(ret), sizeof(retParam), &retParam, sizeof(retParam));
 	return fromData;
@@ -158,7 +162,7 @@ std::shared_ptr GenerateFromInputData(CallFunc callFunc, RetT re
 			delete[](BYTE*)p;
 		});
 	fromData->callFunc = callFunc;
-	fromData->returnSize = returnSize;
+	fromData->returnSize = static_cast(returnSize);
 	memcpy_s(fromData->returnData, sizeof(ret), &ret, sizeof(ret));
 	memcpy_s(fromData->returnData + sizeof(ret), retParamSize, retParam, retParamSize);
 	return fromData;
diff --git a/Share/IPC.cpp b/Share/IPC.cpp
index 9ab2063..a2e04b7 100644
--- a/Share/IPC.cpp
+++ b/Share/IPC.cpp
@@ -48,8 +48,8 @@ void BindProcess::StopProcess()
 	::CloseHandle(m_hEventKillSwitch);
 
 #ifdef _WIN64
-	::SetEvent(m_hEventAPIHookTrapper64);
-	::CloseHandle(m_hEventAPIHookTrapper64);
+	//::SetEvent(m_hEventAPIHookTrapper64);
+	//::CloseHandle(m_hEventAPIHookTrapper64);
 #endif
 
 	::CloseHandle(m_hJob);
diff --git a/Share/PluginWrapper.cpp b/Share/PluginWrapper.cpp
index 534a38c..8c9504a 100644
--- a/Share/PluginWrapper.cpp
+++ b/Share/PluginWrapper.cpp
@@ -1,12 +1,30 @@
 
 #include "PluginWrapper.h"
-
+#include 
 #include "CodeConvert.h"
 
+
 #ifndef INPUT_PIPE_MAIN
 #include "Logger.h"
 #endif
 
+#ifdef INPUT_PIPE_MAIN64
+#include 
+#include 
+
+std::mutex		m_mtxInputHandle;
+std::unordered_map	g_mapInputHandle;
+
+INPUT_HANDLE32	GenerateInputHandle32()
+{
+	static INPUT_HANDLE32	src = 0;
+	++src;
+	return src;
+}
+
+
+#endif
+
 extern INPUT_PLUGIN_TABLE* g_winputPluginTable;
 
 BOOL Plugin_func_init()
@@ -31,6 +49,130 @@ BOOL Plugin_func_exit()
 	}
 }
 
+#ifdef INPUT_PIPE_MAIN64
+
+INPUT_HANDLE32 Plugin_func_open(LPSTR file)
+{
+	try {
+		INPUT_HANDLE ih = g_winputPluginTable->func_open(file);
+		if (ih) {
+			std::lock_guard	lock(m_mtxInputHandle);
+			INPUT_HANDLE32 ih32 = GenerateInputHandle32();
+			g_mapInputHandle[ih32] = ih;
+			return ih32;
+		}
+		return 0;
+	}
+	catch (...) {
+#ifndef INPUT_PIPE_MAIN
+		ERROR_LOG << L"Plugin_func_open failed\nfile: " << CodeConvert::UTF16fromShiftJIS(file);
+#endif
+	}
+	return 0;
+}
+
+BOOL Plugin_func_close(INPUT_HANDLE32 ih32)
+{
+	std::lock_guard	lock(m_mtxInputHandle);
+	auto it = g_mapInputHandle.find(ih32);
+	if (it == g_mapInputHandle.end()) {
+		assert(FALSE);
+		return FALSE;
+	}
+
+	try {
+		BOOL b = g_winputPluginTable->func_close(it->second);
+		g_mapInputHandle.erase(it);
+		return b;
+	}
+	catch (...) {
+#ifndef INPUT_PIPE_MAIN
+		ERROR_LOG << L"Plugin_func_close failed - ih: " << ih32;
+#endif
+	}
+	return FALSE;
+}
+
+BOOL Plugin_func_info_get(INPUT_HANDLE32 ih32, INPUT_INFO* iip)
+{
+	std::lock_guard	lock(m_mtxInputHandle);
+	auto it = g_mapInputHandle.find(ih32);
+	if (it == g_mapInputHandle.end()) {
+		assert(FALSE);
+		return FALSE;
+	}
+	try {
+		BOOL b = g_winputPluginTable->func_info_get(it->second, iip);
+		return b;
+	}
+	catch (...) {
+#ifndef INPUT_PIPE_MAIN
+		ERROR_LOG << L"Plugin_func_info_get failed - ih: " << ih32;
+#endif
+	}
+	return FALSE;
+}
+
+int Plugin_func_read_video(INPUT_HANDLE32 ih32, int frame, void* buf)
+{
+	std::lock_guard	lock(m_mtxInputHandle);
+	auto it = g_mapInputHandle.find(ih32);
+	if (it == g_mapInputHandle.end()) {
+		assert(FALSE);
+		return 0;
+	}
+	try {
+		int readBytes = g_winputPluginTable->func_read_video(it->second, frame, buf);
+		if (readBytes == 0) {
+			// 摜̎擾ɎŝŁAÕt[擾ĖړĨt[̐𑣂
+			int prevFrame = frame - 1;
+			if (prevFrame < 0) {
+				prevFrame = frame + 1;
+			}
+			int prevReadBytes = g_winputPluginTable->func_read_video(it->second, prevFrame, buf);
+			if (prevReadBytes == 0) {
+				//assert(false);
+				//ERROR_LOG << L"prevReadBytes == 0";
+			}
+			readBytes = g_winputPluginTable->func_read_video(it->second, frame, buf);
+			if (readBytes == 0) {
+				//assert(false);
+#ifndef INPUT_PIPE_MAIN
+				ERROR_LOG << L"retry func_read_video failed : readBytes == 0 - frame: " << frame;
+#endif
+			}
+		}
+		return readBytes;
+	}
+	catch (...) {
+#ifndef INPUT_PIPE_MAIN
+		ERROR_LOG << L"Plugin_func_read_video failed - ih: " << ih32 << L" frame: " << frame;
+#endif
+	}
+	return 0;
+}
+
+int Plugin_func_read_audio(INPUT_HANDLE32 ih32, int start, int length, void* buf)
+{
+	std::lock_guard	lock(m_mtxInputHandle);
+	auto it = g_mapInputHandle.find(ih32);
+	if (it == g_mapInputHandle.end()) {
+		assert(FALSE);
+		return 0;
+	}
+	try {
+		int n = g_winputPluginTable->func_read_audio(it->second, start, length, buf);
+		return n;
+	}
+	catch (...) {
+#ifndef INPUT_PIPE_MAIN
+		ERROR_LOG << L"Plugin_func_read_audio failed - ih: " << ih32 << " start: " << start;
+#endif
+	}
+	return 0;
+}
+
+#else
 
 INPUT_HANDLE Plugin_func_open(LPSTR file)
 {
@@ -119,4 +261,6 @@ int Plugin_func_read_audio(INPUT_HANDLE ih, int start, int length, void* buf)
 #endif
 	}
 	return 0;
-}
\ No newline at end of file
+}
+
+#endif
diff --git a/Share/PluginWrapper.h b/Share/PluginWrapper.h
index 119b9d7..9be3652 100644
--- a/Share/PluginWrapper.h
+++ b/Share/PluginWrapper.h
@@ -6,11 +6,25 @@
 
 #include "..\InputPipePlugin\input.h"
 
+#if defined(INPUT_PIPE_MAIN) && defined(_WIN64)
+#define	INPUT_PIPE_MAIN64
+#endif
+
+
 BOOL Plugin_func_init();
 BOOL Plugin_func_exit();
+#ifdef INPUT_PIPE_MAIN64
+INPUT_HANDLE32 Plugin_func_open(LPSTR file);
+BOOL Plugin_func_close(INPUT_HANDLE32 ih);
+BOOL Plugin_func_info_get(INPUT_HANDLE32 ih, INPUT_INFO* iip);
+int Plugin_func_read_video(INPUT_HANDLE32 ih, int frame, void* buf);
+int Plugin_func_read_audio(INPUT_HANDLE32 ih, int start, int length, void* buf);
+#else
 INPUT_HANDLE Plugin_func_open(LPSTR file);
 BOOL Plugin_func_close(INPUT_HANDLE ih);
 BOOL Plugin_func_info_get(INPUT_HANDLE ih, INPUT_INFO* iip);
 int Plugin_func_read_video(INPUT_HANDLE ih, int frame, void* buf);
 int Plugin_func_read_audio(INPUT_HANDLE ih, int start, int length, void* buf);
+#endif
+