Skip to content

Commit

Permalink
・[change]設定で内部データの交換方式を選択できるようにした(デフォルトを名前付きパイプへ変更)
Browse files Browse the repository at this point in the history
共有メモリだと落ちる場合があるらしいが、再現しないのでエラーが起こりそうな場所にメッセージボックスを埋め込んどいた
・[fix]InputPipeMain.exeがboost::logに依存しないようにした
アンチウィルスがうるさいらしいのでその対策
  • Loading branch information
amate committed Jan 4, 2020
1 parent 3c8ad4d commit 93330b7
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 21 deletions.
27 changes: 17 additions & 10 deletions InputPipeMain/InputPipeMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <unordered_map>
#include <assert.h>
#include "..\Share\IPC.h"
#include "..\Share\Logger.h"
//#include "..\Share\Logger.h"
#include "..\Share\Common.h"
#include "..\InputPipePlugin\input.h"
#include "MainDlg.h"
Expand Down Expand Up @@ -119,7 +119,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
g_hWinputDll = ::LoadLibrary((GetExeDirectory() /L"lwinput.aui").c_str());
assert(g_hWinputDll);
if (g_hWinputDll == NULL) {
WARN_LOG << L"LoadLibrary failed (lwinput.aui)";
//WARN_LOG << L"LoadLibrary failed (lwinput.aui)";
return 0;
}

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

// for Debug
CallFunc lastCallFunc;

for (;;) {
std::vector<BYTE> readData = namedPipe.Read(kToWindDataHeaderSize);
if (readData.size() == 0) {
Expand All @@ -174,7 +173,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
{
LPSTR file = (LPSTR)dataBody.data();
INPUT_HANDLE ih = g_winputPluginTable->func_open(file);
INFO_LOG << L"kOpen: " << ih;
//INFO_LOG << L"kOpen: " << ih;

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

auto fromData = GenerateFromInputData(CallFunc::kClose, b, 0);
namedPipe.Write((const BYTE*)fromData.get(), FromWinputDataTotalSize(*fromData));
Expand All @@ -201,7 +200,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
INPUT_INFO inputInfo = {};
BOOL b = g_winputPluginTable->func_info_get(spp->ih, &inputInfo);
assert(b);
INFO_LOG << L"kInfoGet: " << spp->ih;
//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);
Expand Down Expand Up @@ -235,6 +234,11 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
videoSharedMemory.CloseHandle();
std::wstring sharedMemoryName = kVideoSharedMemoryPrefix + randomString + std::to_wstring(spp->perBufferSize);
videoSharedBuffer.first = videoSharedMemory.CreateSharedMemory(sharedMemoryName.c_str(), spp->perBufferSize);
if (!videoSharedBuffer.first) {
DWORD error = ::GetLastError();
std::wstring errorMsg = L"videoSharedMemory.CreateSharedMemoryに失敗\nsharedMemoryName: " + sharedMemoryName + L"\nGetLastError: " + std::to_wstring(error);
MessageBox(NULL, errorMsg.c_str(), L"InputPipeMainエラー", MB_ICONERROR);;
}
videoSharedBuffer.second = spp->perBufferSize;
sharedMemoryReopen = true;
}
Expand Down Expand Up @@ -262,7 +266,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
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";
//ERROR_LOG << L"readBytes == 0 : retry func_read_video failed";
}
}
//INFO_LOG << L"kReadVideo: " << spp->ih;
Expand Down Expand Up @@ -294,6 +298,11 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
audioSharedMemory.CloseHandle();
std::wstring sharedMemoryName = kAudioSharedMemoryPrefix + randomString + std::to_wstring(requestReadBytes);
audioSharedBuffer.first = audioSharedMemory.CreateSharedMemory(sharedMemoryName.c_str(), requestReadBytes);
if (!audioSharedBuffer.first) {
DWORD error = ::GetLastError();
std::wstring errorMsg = L"audioSharedMemory.CreateSharedMemoryに失敗\nsharedMemoryName: " + sharedMemoryName + L"\nGetLastError: " + std::to_wstring(error);
MessageBox(NULL, errorMsg.c_str(), L"InputPipeMainエラー", MB_ICONERROR);;
}
audioSharedBuffer.second = requestReadBytes;
sharedMemoryReopen = true;
}
Expand Down Expand Up @@ -327,7 +336,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,

case CallFunc::kIsKeyframe:
{
INFO_LOG << L"kIsKeyframe";
//INFO_LOG << L"kIsKeyframe";

StandardParamPack* spp = (StandardParamPack*)dataBody.data();
BOOL b = g_winputPluginTable->func_is_keyframe(spp->ih, spp->param1);
Expand All @@ -350,7 +359,6 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
}

};

::FreeLibrary(g_hWinputDll);
g_hWinputDll = NULL;

Expand All @@ -367,6 +375,5 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
}
#endif
return 0;

}

Binary file modified InputPipeMain/InputPipeMain.rc
Binary file not shown.
13 changes: 10 additions & 3 deletions InputPipeMain/InputPipeMain.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -169,7 +170,10 @@
<ItemGroup>
<ClCompile Include="..\Share\Common.cpp" />
<ClCompile Include="..\Share\IPC.cpp" />
<ClCompile Include="..\Share\Logger.cpp" />
<ClCompile Include="..\Share\Logger.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="InputPipeMain.cpp" />
<ClCompile Include="MainDlg.cpp" />
</ItemGroup>
Expand All @@ -180,6 +184,9 @@
<Image Include="InputPipeMain.ico" />
<Image Include="small.ico" />
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
5 changes: 5 additions & 0 deletions InputPipeMain/InputPipeMain.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@
<Filter>リソース ファイル</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint">
<Filter>ソース ファイル</Filter>
</None>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions InputPipeMain/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam

//
m_config.LoadConfig();
m_radioNamedPipeOrSharedMemory = m_config.bUseSharedMemory ? 1 : 0;
DoDataExchange(DDX_LOAD);

return TRUE;
Expand All @@ -45,6 +46,8 @@ LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /
MessageBox(L"少なくとも、どちらか一方にチェックを入れてください。");
return 0;
}
m_config.bUseSharedMemory = m_radioNamedPipeOrSharedMemory == 1 ? true : false;

m_config.SaveConfig();

CloseDialog(0);
Expand Down
2 changes: 2 additions & 0 deletions InputPipeMain/MainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CMainDlg :
BEGIN_DDX_MAP(CMainDlg)
DDX_CHECK(IDC_CHECK_ENABLE_HANDLECACHE, m_config.bEnableHandleCache)
DDX_CHECK(IDC_CHECK_ENABLE_IPC, m_config.bEnableIPC)
DDX_RADIO(IDC_RADIO_NAMEDPIPE, m_radioNamedPipeOrSharedMemory);
END_DDX_MAP()

BEGIN_MSG_MAP_EX(CMainDlg)
Expand All @@ -66,6 +67,7 @@ class CMainDlg :

private:
Config m_config;
int m_radioNamedPipeOrSharedMemory;
};


Expand Down
5 changes: 4 additions & 1 deletion InputPipeMain/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#define IDD_MAINDLG 129
#define IDC_CHECK_ENABLE_HANDLECACHE 1000
#define IDC_CHECK_ENABLE_IPC 1001
#define IDC_RADIO_NAMEDPIPE 1002
#define IDC_RADIO2 1003
#define IDC_RADIO_SHAREDMEMORY 1003
#define IDC_STATIC -1

// Next default values for new objects
Expand All @@ -25,7 +28,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif
8 changes: 8 additions & 0 deletions InputPipeMain/cpp.hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ヒント ファイルは、Visual Studio IDE が Visual C++ 識別子を解釈するのに役立ちます
// 関数およびマクロの名前などです。
// 詳細については次を参照してください https://go.microsoft.com/fwlink/?linkid=865984
#define BEGIN_MSG_MAP_EX(theClass) @<
#define END_MSG_MAP() @>
#define BEGIN_DDX_MAP(theClass) @<
#define END_DDX_MAP() @>
#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) static ATL::CWndClassInfo& GetWndClassInfo() { static ATL::CWndClassInfo wc = { { sizeof(WNDCLASSEX), style, StartWindowProc, 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName, NULL }, NULL, NULL, IDC_ARROW, TRUE, 0, _T("") }; return wc; }
14 changes: 13 additions & 1 deletion InputPipePlugin/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ BOOL func_init( void )
}

m_config.LoadConfig();
m_config.bUseSharedMemory = true;
//m_config.bUseSharedMemory = true;

if (m_config.bEnableIPC) {
INFO_LOG << "EnableIPC";
Expand Down Expand Up @@ -446,6 +446,12 @@ int func_read_video( INPUT_HANDLE ih,int frame,void *buf )
std::wstring sharedMemoryName = kVideoSharedMemoryPrefix + g_randamString + std::to_wstring(spp.perBufferSize);
sharedBufferView = g_videoSharedMemory.OpenSharedMemory(sharedMemoryName.c_str(), true);
assert(sharedBufferView);
if (!sharedBufferView) {
DWORD error = ::GetLastError();
std::wstring errorMsg = L"g_videoSharedMemory.OpenSharedMemoryに失敗\nsharedMemoryName: " + sharedMemoryName + L"\nGetLastError: " + std::to_wstring(error);
MessageBox(NULL, errorMsg.c_str(), L"InputPipePluginエラー", MB_ICONERROR);
return 0;
}
} else {
sharedBufferView = g_videoSharedMemory.GetPointer();
}
Expand Down Expand Up @@ -568,6 +574,12 @@ int func_read_audio(INPUT_HANDLE ih, int start, int length, void* buf)
g_audioSharedMemory.CloseHandle();
std::wstring sharedMemoryName = kAudioSharedMemoryPrefix + g_randamString + std::to_wstring(audioBufferSize);
sharedBufferView = g_audioSharedMemory.OpenSharedMemory(sharedMemoryName.c_str(), true);
if (!sharedBufferView) {
DWORD error = ::GetLastError();
std::wstring errorMsg = L"g_audioSharedMemory.OpenSharedMemoryに失敗\nsharedMemoryName: " + sharedMemoryName + L"\nGetLastError: " + std::to_wstring(error);
MessageBox(NULL, errorMsg.c_str(), L"InputPipePluginエラー", MB_ICONERROR);
return 0;
}
assert(sharedBufferView);
} else {
sharedBufferView = g_audioSharedMemory.GetPointer();
Expand Down
8 changes: 7 additions & 1 deletion Readme.txt
2 changes: 2 additions & 0 deletions Share/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bool Config::LoadConfig()
auto ptree = ptreeWrapper::LoadIniPtree(kConfigFileName);
bEnableHandleCache = ptree.get<bool>(L"Config.bEnableHandleCache", true);
bEnableIPC = ptree.get<bool>(L"Config.bEnableIPC", true);
bUseSharedMemory = ptree.get<bool>(L"Config.bUseSharedMemory", false);

return true;
}
Expand All @@ -25,6 +26,7 @@ bool Config::SaveConfig()
ptreeWrapper::wptree ptree;
ptree.put(L"Config.bEnableHandleCache", bEnableHandleCache);
ptree.put(L"Config.bEnableIPC", bEnableIPC);
ptree.put(L"Config.bUseSharedMemory", bUseSharedMemory);

bool success = ptreeWrapper::SaveIniPtree(kConfigFileName, ptree);
return success;
Expand Down
2 changes: 1 addition & 1 deletion 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.5"
#define PLUGIN_VERSION "1.6"


constexpr int kVideoBufferSurplusBytes = 0x3FF;
Expand Down
8 changes: 4 additions & 4 deletions Share/IPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <memory>
#include <atldef.h>
#include <assert.h>
#include "Logger.h"
//#include "Logger.h"


std::wstring GetLastErrorMessage(DWORD error)
Expand Down Expand Up @@ -178,9 +178,9 @@ int NamedPipe::Read(BYTE* data, const int length)
}

if (error == ERROR_BROKEN_PIPE) {
ERROR_LOG << L"NamedPipe::Read failed: client disconnected.";
//ERROR_LOG << L"NamedPipe::Read failed: client disconnected.";
} else {
ERROR_LOG << L"NamedPipe::Read failed: GetLastError: " << GetLastErrorMessage(error) << L" [" << error << L"]";
//ERROR_LOG << L"NamedPipe::Read failed: GetLastError: " << GetLastErrorMessage(error) << L" [" << error << L"]";
}
assert(false);
return totalReadBytes;
Expand All @@ -207,7 +207,7 @@ void NamedPipe::Write(const BYTE* data, int length)
if (!bSuccess || length != writtenSize) {
DWORD error = GetLastError();
assert(false);
ERROR_LOG << L"NamedPipe::Write failed: GetLastError: " << GetLastErrorMessage(error)<< L" [" << error << L"]";
//ERROR_LOG << L"NamedPipe::Write failed: GetLastError: " << GetLastErrorMessage(error)<< L" [" << error << L"]";
}
//BOOL bFlushSuccess = ::FlushFileBuffers(m_hPipe);
}
Expand Down

0 comments on commit 93330b7

Please sign in to comment.