Skip to content

Commit

Permalink
・[add] InputPipeMain64.exeを追加 (64bit版 L-SMASH_Works File Reader(lwinp…
Browse files Browse the repository at this point in the history
…ut64.aui)が存在するときはそちらを利用するようにした)
  • Loading branch information
amate committed Jun 25, 2023
1 parent 54c8d25 commit 99c1693
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 24 deletions.
33 changes: 27 additions & 6 deletions InputPipeMain/InputPipeMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ INPUT_PLUGIN_TABLE* g_winputPluginTable = nullptr;
std::vector<BYTE> g_readVideoBuffer;
std::vector<BYTE> g_readAudioBuffer;

#ifdef _WIN64
#define LWINNPUT_NAME L"lwinput64.aui"
#else
#define LWINNPUT_NAME L"lwinput.aui"
#endif

// for Logger
std::string LogFileName()
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)";
Expand All @@ -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();
}

Expand Down Expand Up @@ -154,6 +167,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
NamedPipe namedPipe;
bool success = namedPipe.OpenNamedPipe(pipeName);
if (!success) {
ATLASSERT(FALSE);
return 0;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
14 changes: 12 additions & 2 deletions InputPipeMain/InputPipeMain.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Programing\#lib\boost_1_73_0\lib\include\boost-1_73;C:\Programing\#lib\WTL10_10320_Release\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Programing\#lib\boost_1_73_0\lib\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
Expand All @@ -87,6 +90,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\Programing\#lib\boost_1_73_0\lib\include\boost-1_73;C:\Programing\#lib\WTL10_10320_Release\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Programing\#lib\boost_1_73_0\lib\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand All @@ -112,8 +118,9 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>INPUT_PIPE_MAIN;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -150,8 +157,9 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>INPUT_PIPE_MAIN;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -161,6 +169,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\Share\CodeConvert.h" />
<ClInclude Include="..\Share\Common.h" />
<ClInclude Include="..\Share\IPC.h" />
<ClInclude Include="..\Share\Logger.h" />
Expand All @@ -173,6 +182,7 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Share\CodeConvert.cpp" />
<ClCompile Include="..\Share\Common.cpp" />
<ClCompile Include="..\Share\IPC.cpp" />
<ClCompile Include="..\Share\Logger.cpp">
Expand Down
6 changes: 6 additions & 0 deletions InputPipeMain/InputPipeMain.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<ClInclude Include="..\Share\PluginWrapper.h">
<Filter>ソース ファイル\Share</Filter>
</ClInclude>
<ClInclude Include="..\Share\CodeConvert.h">
<Filter>ソース ファイル\Share</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="InputPipeMain.cpp">
Expand All @@ -68,6 +71,9 @@
<ClCompile Include="..\Share\PluginWrapper.cpp">
<Filter>ソース ファイル\Share</Filter>
</ClCompile>
<ClCompile Include="..\Share\CodeConvert.cpp">
<Filter>ソース ファイル\Share</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="InputPipeMain.rc">
Expand Down
4 changes: 4 additions & 0 deletions InputPipePlugin/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions InputPipePlugin/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <Windows.h>
#include <Mmreg.h>
#include <stdint.h>

// 入力ファイル情報構造体
typedef struct {
Expand All @@ -25,6 +26,24 @@ typedef struct {
DWORD handler; // 画像codecハンドラ
int reserve[7];
} INPUT_INFO;

typedef struct {
int flag; // フラグ
// INPUT_INFO_FLAG_VIDEO : 画像データあり
// INPUT_INFO_FLAG_AUDIO : 音声データあり
// INPUT_INFO_FLAG_VIDEO_RANDOM_ACCESS : キーフレームを気にせずにfunc_read_video()を呼び出します
// ※標準ではキーフレームからシーケンシャルにfunc_read_video()が呼ばれるように制御されます
int rate, scale; // フレームレート
int n; // フレーム数
uint32_t format; // 画像フォーマットへのポインタ(次に関数が呼ばれるまで内容を有効にしておく) [****ダミー****]
int format_size; // 画像フォーマットのサイズ
int audio_n; // 音声サンプル数
uint32_t audio_format; // 音声フォーマットへのポインタ(次に関数が呼ばれるまで内容を有効にしておく) [****ダミー****]
int audio_format_size; // 音声フォーマットのサイズ
DWORD handler; // 画像codecハンドラ
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
Expand All @@ -34,6 +53,7 @@ typedef struct {

// 入力ファイルハンドル
typedef void* INPUT_HANDLE;
typedef uint32_t INPUT_HANDLE32;

// 入力プラグイン構造体
typedef struct {
Expand Down
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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の設定]
プラグインの設定ができます
Expand Down Expand Up @@ -151,6 +161,9 @@ http://sourceforge.net/projects/wtl/
## ■更新履歴
<pre>

v2.0
・[add] InputPipeMain64.exeを追加 (64bit版 L-SMASH_Works File Reader(lwinput64.aui)が存在するときはそちらを利用するようにした)

v1.10
・[fix] 動画ファイルの幅、高さが4の倍数でないときに強制終了するバグを修正 #5

Expand Down
32 changes: 24 additions & 8 deletions Share/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,49 @@ std::unique_ptr<BYTE[]> SerializeInputInfo(INPUT_INFO* iip)
const int infoGetDataSize = CalcTotalInputInfoSize(iip);
auto infoGetData = std::make_unique<BYTE[]>(infoGetDataSize);
// INPUT_INFO をコピー
#ifndef _WIN64
memcpy_s(infoGetData.get(), infoGetDataSize, iip, sizeof(INPUT_INFO));
auto igData = reinterpret_cast<INPUT_INFO*>(infoGetData.get());
#else
INPUT_INFO32* pinfo = reinterpret_cast<INPUT_INFO32*>(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<INPUT_INFO32*>(infoGetData.get());

// formatとaudio_formatをそれぞれ 確保したメモリの後ろにコピー
::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);

// それぞれのフォーマットの指し示す先を、確保したメモリから設定
// それぞれのフォーマットの指し示す先を、確保したメモリから設定 (意味ないけど ヌルポだと問題になるかもしれない)
if (igData->format_size > 0) {
igData->format = (BITMAPINFOHEADER*)(infoGetData.get() + sizeof(INPUT_INFO));
igData->format = reinterpret_cast<uint32_t>((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<uint32_t>((WAVEFORMATEX*)(infoGetData.get() + sizeof(INPUT_INFO) + igData->format_size));
} else {
igData->audio_format = nullptr;
igData->audio_format = 0; // nullptr;
}
return infoGetData;
}

std::unique_ptr<BYTE[]> DeserializeInputInfo(const BYTE* serializedData, INPUT_INFO* iip)
{
#ifdef _WIN64
assert(FALSE); // 64bit版ではデシリアライズは呼ばないはず
#endif

auto tempInputInfo = (INPUT_INFO*)serializedData;
if (tempInputInfo->format_size > 0) {
tempInputInfo->format = (BITMAPINFOHEADER*)(reinterpret_cast<BYTE*>(tempInputInfo) + sizeof(INPUT_INFO));
Expand Down
12 changes: 8 additions & 4 deletions Share/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<BYTE[]> SerializeInputInfo(INPUT_INFO* iip);
Expand All @@ -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;
Expand Down Expand Up @@ -143,7 +147,7 @@ std::shared_ptr<FromWinputData> GenerateFromInputData(CallFunc callFunc, RetT re
delete[] (BYTE*)p;
});
fromData->callFunc = callFunc;
fromData->returnSize = returnSize;
fromData->returnSize = static_cast<std::int32_t>(returnSize);
memcpy_s(fromData->returnData, sizeof(ret), &ret, sizeof(ret));
memcpy_s(fromData->returnData + sizeof(ret), sizeof(retParam), &retParam, sizeof(retParam));
return fromData;
Expand All @@ -158,7 +162,7 @@ std::shared_ptr<FromWinputData> GenerateFromInputData(CallFunc callFunc, RetT re
delete[](BYTE*)p;
});
fromData->callFunc = callFunc;
fromData->returnSize = returnSize;
fromData->returnSize = static_cast<std::int32_t>(returnSize);
memcpy_s(fromData->returnData, sizeof(ret), &ret, sizeof(ret));
memcpy_s(fromData->returnData + sizeof(ret), retParamSize, retParam, retParamSize);
return fromData;
Expand Down
4 changes: 2 additions & 2 deletions Share/IPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 99c1693

Please sign in to comment.