Skip to content

Commit

Permalink
・[fix] IPC有効時、プラグインの終了時にInputPipeMain.exeをまともに終了させるようにした
Browse files Browse the repository at this point in the history
・[change] lwinput.auiの各種関数呼び出しにラッパーを噛ませた (例外も握り潰すようにしたので多少落ちなくなったはず)
・[add] 設定の保存に失敗した場合、メッセージボックスを表示するようにした (AviUtlフォルダを [Program Files]や[Program Files (x86)]フォルダ内に置かないでください)
・[fix] IPC有効時、名前付きパイプの準備やInputPipeMain.exeの起動に失敗した場合、IPCを無効化して動作させるようにした
・[fix] ConnectNamedPipeの呼び出しが、タイミングによって失敗することがあるのを修正
・[fix] 音声が存在しない動画ファイル読み込み時、iip->audio_formatが無効なアドレスを指していたのを修正
・[misc] 使用していないソースコードの削除や INPUT_INFO周りの処理を共通化
・[change] 名前付きパイプのバッファサイズを増加させた (512->4096)
  • Loading branch information
amate committed Mar 7, 2020
1 parent 93330b7 commit 11db9df
Show file tree
Hide file tree
Showing 15 changed files with 486 additions and 346 deletions.
50 changes: 14 additions & 36 deletions InputPipeMain/InputPipeMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "..\Share\IPC.h"
//#include "..\Share\Logger.h"
#include "..\Share\Common.h"
#include "..\Share\PluginWrapper.h"
#include "..\InputPipePlugin\input.h"
#include "MainDlg.h"

Expand Down Expand Up @@ -158,7 +159,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,

// for Debug
CallFunc lastCallFunc;
for (;;) {
bool activeLoop = true;
while (activeLoop) {
std::vector<BYTE> readData = namedPipe.Read(kToWindDataHeaderSize);
if (readData.size() == 0) {
assert(false);
Expand All @@ -172,7 +174,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
case CallFunc::kOpen:
{
LPSTR file = (LPSTR)dataBody.data();
INPUT_HANDLE ih = g_winputPluginTable->func_open(file);
INPUT_HANDLE ih = Plugin_func_open(file);
//INFO_LOG << L"kOpen: " << ih;

auto fromData = GenerateFromInputData(CallFunc::kOpen, ih, 0);
Expand All @@ -184,7 +186,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
case CallFunc::kClose:
{
StandardParamPack* spp = (StandardParamPack*)dataBody.data();
BOOL b = g_winputPluginTable->func_close(spp->ih);
BOOL b = Plugin_func_close(spp->ih);
//INFO_LOG << L"kClose: " << spp->ih;

auto fromData = GenerateFromInputData(CallFunc::kClose, b, 0);
Expand All @@ -198,21 +200,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,

StandardParamPack* spp = (StandardParamPack*)dataBody.data();
INPUT_INFO inputInfo = {};
BOOL b = g_winputPluginTable->func_info_get(spp->ih, &inputInfo);
BOOL b = Plugin_func_info_get(spp->ih, &inputInfo);
assert(b);
//INFO_LOG << L"kInfoGet: " << spp->ih;
if (b) {
int totalInputInfoSize = sizeof(INPUT_INFO) + inputInfo.format_size + inputInfo.audio_format_size;
std::vector<BYTE> entireInputInfo(totalInputInfoSize);
errno_t e = ::memcpy_s(entireInputInfo.data(), totalInputInfoSize, &inputInfo, sizeof(INPUT_INFO));
e = ::memcpy_s(entireInputInfo.data() + sizeof(INPUT_INFO),
inputInfo.format_size,
inputInfo.format, inputInfo.format_size);
e = ::memcpy_s(entireInputInfo.data() + sizeof(INPUT_INFO) + inputInfo.format_size,
inputInfo.audio_format_size,
inputInfo.audio_format, inputInfo.audio_format_size);

auto fromData = GenerateFromInputData(CallFunc::kInfoGet, b, entireInputInfo.data(), totalInputInfoSize);
const int totalInputInfoSize = CalcTotalInputInfoSize(&inputInfo);
auto infoGetData = SerializeInputInfo(&inputInfo);

auto fromData = GenerateFromInputData(CallFunc::kInfoGet, b, infoGetData.get(), totalInputInfoSize);
namedPipe.Write((const BYTE*)fromData.get(), FromWinputDataTotalSize(*fromData));
//INFO_LOG << L"Write: " << FromWinputDataTotalSize(*fromData) << L" bytes";

Expand Down Expand Up @@ -249,26 +244,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
}
buf = g_readVideoBuffer.data();
}
INPUT_INFO inputInfo = {};
const int frame = spp->param1;
int readBytes = g_winputPluginTable->func_read_video(spp->ih, spp->param1, buf);
if (readBytes == 0) {
// 画像の取得に失敗したので、前のフレームを取得して目的のフレームの生成を促す
int prevFrame = frame - 1;
if (prevFrame < 0) {
prevFrame = frame + 1;
}
int prevReadBytes = g_winputPluginTable->func_read_video(spp->ih, prevFrame, g_readVideoBuffer.data());
if (prevReadBytes == 0) {
assert(false);
//ERROR_LOG << L"prevReadBytes == 0";
}
readBytes = g_winputPluginTable->func_read_video(spp->ih, frame, g_readVideoBuffer.data());
if (readBytes == 0) {
assert(false);
//ERROR_LOG << L"readBytes == 0 : retry func_read_video failed";
}
}
int readBytes = Plugin_func_read_video(spp->ih, spp->param1, buf);
//INFO_LOG << L"kReadVideo: " << spp->ih;

namedPipe.Write((const BYTE*)&toData->header.callFunc, sizeof(toData->header.callFunc));
Expand Down Expand Up @@ -314,8 +291,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
buf = g_readAudioBuffer.data();
}

int readSample = g_winputPluginTable->func_read_audio(spp->ih, spp->param1, spp->param2, buf);
assert(readSample > 0);
int readSample = Plugin_func_read_audio(spp->ih, spp->param1, spp->param2, buf);
//assert(readSample > 0);
//INFO_LOG << L"kReadAudio: " << spp->ih << L" readSample: " << readSample;
const int readBufferSize = PerAudioSampleBufferSize * readSample;

Expand Down Expand Up @@ -350,6 +327,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
{
//INFO_LOG << L"kExit";
namedPipe.Disconnect();
activeLoop = false;
}
break;

Expand Down
6 changes: 4 additions & 2 deletions InputPipeMain/InputPipeMain.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;INPUT_PIPE_MAIN;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
Expand Down Expand Up @@ -124,7 +124,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;INPUT_PIPE_MAIN;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand Down Expand Up @@ -160,6 +160,7 @@
<ClInclude Include="..\Share\Common.h" />
<ClInclude Include="..\Share\IPC.h" />
<ClInclude Include="..\Share\Logger.h" />
<ClInclude Include="..\Share\PluginWrapper.h" />
<ClInclude Include="..\Share\ptreeWrapper.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="InputPipeMain.h" />
Expand All @@ -174,6 +175,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Share\PluginWrapper.cpp" />
<ClCompile Include="InputPipeMain.cpp" />
<ClCompile Include="MainDlg.cpp" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions InputPipeMain/InputPipeMain.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<ClInclude Include="MainDlg.h">
<Filter>ソース ファイル</Filter>
</ClInclude>
<ClInclude Include="..\Share\PluginWrapper.h">
<Filter>ソース ファイル\Share</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="InputPipeMain.cpp">
Expand All @@ -62,6 +65,9 @@
<ClCompile Include="..\Share\Common.cpp">
<Filter>ソース ファイル\Share</Filter>
</ClCompile>
<ClCompile Include="..\Share\PluginWrapper.cpp">
<Filter>ソース ファイル\Share</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="InputPipeMain.rc">
Expand Down
10 changes: 9 additions & 1 deletion InputPipeMain/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /
}
m_config.bUseSharedMemory = m_radioNamedPipeOrSharedMemory == 1 ? true : false;

m_config.SaveConfig();
if (!m_config.SaveConfig()) {
CString errorMsg = L"設定の保存に失敗しました。";
CString exeFolderPath = GetExeDirectory().wstring().c_str();
exeFolderPath.MakeLower();
if (exeFolderPath.Find(LR"(\program files (x86)\)") != -1 || exeFolderPath.Find(LR"(\program files\)") != -1) {
errorMsg += L"\nAviUtlフォルダを [Program Files]や[Program Files (x86)]フォルダ内に置かないでください";
}
MessageBox(errorMsg, L"InputPipeMain - エラー", MB_ICONERROR);
}

CloseDialog(0);
return 0;
Expand Down
5 changes: 5 additions & 0 deletions InputPipePlugin/InputPipePlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<ClInclude Include="..\Share\Common.h" />
<ClInclude Include="..\Share\IPC.h" />
<ClInclude Include="..\Share\Logger.h" />
<ClInclude Include="..\Share\PluginWrapper.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="input.h" />
<ClInclude Include="pch.h" />
Expand All @@ -186,6 +187,10 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\Share\PluginWrapper.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="input.cpp" />
<ClCompile Include="pch.cpp">
Expand Down
6 changes: 6 additions & 0 deletions InputPipePlugin/InputPipePlugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<ClInclude Include="..\Share\CodeConvert.h">
<Filter>ソース ファイル\Share</Filter>
</ClInclude>
<ClInclude Include="..\Share\PluginWrapper.h">
<Filter>ソース ファイル\Share</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand All @@ -62,6 +65,9 @@
<ClCompile Include="..\Share\Common.cpp">
<Filter>ソース ファイル\Share</Filter>
</ClCompile>
<ClCompile Include="..\Share\PluginWrapper.cpp">
<Filter>ソース ファイル\Share</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="input.def">
Expand Down
Loading

0 comments on commit 11db9df

Please sign in to comment.