diff --git a/ECTrainer2/BitalMonitor.cpp b/ECTrainer2/BitalMonitor.cpp index 87e88df..2bb7e9a 100644 --- a/ECTrainer2/BitalMonitor.cpp +++ b/ECTrainer2/BitalMonitor.cpp @@ -1,4 +1,6 @@ -#include "common.h" +#include "BitalMonitor.h" +#include "ECTrainer.h" +#include "myWinUtils.h" // �R���X�g���N�^ BitalMonitor::BitalMonitor(ECTrainer* pEct) @@ -22,7 +24,6 @@ char comBuf[BUF_LEN] = { '\0' }; DWORD readBytes = _Com.Receive((BYTE*)comBuf, BUF_LEN - 1); if (readBytes < 1) continue; - std::cout << "com " << com << " '" << comBuf << "'" << std::endl; //mwut::DebugPrintf(_T("check com %d\n"), com); if ((*comBuf >= '0' && *comBuf <= '9') || *comBuf == '#' || *comBuf == LF) { mwut::DebugPrintf(_T("Bital device found on com%d\n"), com); @@ -45,7 +46,7 @@ char comBuf[BUF_LEN] = { '\0' }; DWORD readBytes = _Com.Receive((BYTE*)comBuf, BUF_LEN / 2); // �O��̎c�蕶����ɒlj����邽�ߓǂݍ��ݗʂ�}������ if (readBytes > 0) { - std::cout << "readBytes:" << readBytes << std::endl; + //std::cout << "readBytes:" << readBytes << std::endl; comBuf[readBytes] = '\0'; //std::cout << "comBuf:" << comBuf << std::endl; strcat_s(lastBuf, BUF_LEN - 1, comBuf); diff --git a/ECTrainer2/BitalMonitor.h b/ECTrainer2/BitalMonitor.h index db931dc..2332d91 100644 --- a/ECTrainer2/BitalMonitor.h +++ b/ECTrainer2/BitalMonitor.h @@ -7,7 +7,6 @@ class BitalMonitor : public BaseProcess { - //const int COM_PORT = 4; const char LF = 10; const DWORD NO_SIGNAL_TIMEOUT = 5000; // ���M���Ɣ��肷�鎞�� (ms) static const int BUF_LEN = 256; diff --git a/ECTrainer2/DShowMovie.cpp b/ECTrainer2/DShowMovie.cpp new file mode 100644 index 0000000..cb19002 --- /dev/null +++ b/ECTrainer2/DShowMovie.cpp @@ -0,0 +1,154 @@ +#include "DShowMovie.h" + +#pragma comment(lib, "dxguid.lib") +#pragma comment(lib, "d3d9.lib") +#pragma comment(lib, "Strmiids.lib") +#define _WIN32_DCOM // CoInitializeEx�֐��̌Ăяo���ɕK�v + +// �R���X�g���N�^ +DShowMovie::DShowMovie() + : _pD3D(NULL) + , _pD3DDev(NULL) + , _pGB(NULL) + , _pVMR9(NULL) + , _pSource(NULL) + , _pCGB2(NULL) + , _pMediaCont(NULL) + , _pMediaEvent(NULL) + , _hWnd(NULL) +{ + +} + +// �f�X�g���N�^ +DShowMovie::~DShowMovie() { + SAFE_RELEASE(_pMediaPosition); + SAFE_RELEASE(_pMediaEvent); + SAFE_RELEASE(_pMediaCont); + SAFE_RELEASE(_pCGB2); + SAFE_RELEASE(_pSource); + SAFE_RELEASE(_pVMR9); + SAFE_RELEASE(_pGB); + SAFE_RELEASE(_pD3DDev); + SAFE_RELEASE(_pD3D); + CoUninitialize(); +} + +// DirectX�̏����� +bool DShowMovie::InitDx(HINSTANCE hInstance, RECT dispRect) { + _DispRect = dispRect; + TCHAR gName[100] = _T("Video Window"); + WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance, NULL, NULL, + (HBRUSH)(COLOR_WINDOW + 1), NULL, (TCHAR*)gName, NULL }; + if (!RegisterClassEx(&wcex)) return 0; + + // �t���X�N���[���p�Ƀ|�b�v�A�b�v�E�B���h�E���쐬 + if (!(_hWnd = CreateWindow(gName, gName, WS_POPUPWINDOW, _DispRect.left, _DispRect.top, + _DispRect.right - _DispRect.left, _DispRect.bottom - _DispRect.top, + NULL, NULL, hInstance, NULL))) + return false; + + // Direct3D�̏����� + if (!(_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return false; + + // �t���X�N���[���p�ɏ������p�����[�^��ݒ� + D3DPRESENT_PARAMETERS d3dpp = { (UINT)(_DispRect.right - _DispRect.left), + (UINT)(_DispRect.bottom - _DispRect.top), D3DFMT_A8R8G8B8, 0, D3DMULTISAMPLE_NONE, 0, + D3DSWAPEFFECT_DISCARD, _hWnd, FALSE, 0, D3DFMT_UNKNOWN, D3DPRESENT_RATE_DEFAULT, 0 }; + + if (FAILED(_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _hWnd, + D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &_pD3DDev))) { + + CHECK(_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _hWnd, + D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &_pD3DDev)); + printf("Software DirectX\n"); + } else { + printf("Hardware DirectX\n"); + } + + // COM�̏����� + CHECK(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); + + return true; +} + +// ����Đ� +bool DShowMovie::PlayMovie(std::wstring movie) { + //if (_PlayIndex < 0 || _PlayIndex >= _MovieFiles.size()) return false; + + // �t�B���^�O���t�}�l�[�W���̍쐬 + CHECK(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_pGB)); + + // VRM9�t�B���^�̍쐬�Ɠo�^ + CHECK(CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&_pVMR9)); + CHECK(_pGB->AddFilter(_pVMR9, L"VMR9")); // �t�B���^�O���t�ɓo�^ + + // VRM9���E�B���h�E���X���[�h�ɂ��� + IVMRFilterConfig* pVMRCfg = NULL; + CHECK(_pVMR9->QueryInterface(IID_IVMRFilterConfig9, (void**)&pVMRCfg)); + CHECK(pVMRCfg->SetRenderingMode(VMRMode_Windowless)); + pVMRCfg->Release(); // IVMRFilterConfig�͂����K�v�Ȃ� + + // �`��E�B���h�E�̎w�� + IVMRWindowlessControl9* pVMRWndCont = NULL; + CHECK(_pVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void**)&pVMRWndCont)); + CHECK(pVMRWndCont->SetVideoClippingWindow(_hWnd)); + + // �\�[�X�t�B���^�̐����Ɠo�^ + CHECK(_pGB->AddSourceFilter(movie.c_str(), movie.c_str(), &_pSource)); + + // CaptureGraphBuilder2�C���^�[�t�F�C�X�̎擾 + CHECK(CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&_pCGB2)); + CHECK(_pCGB2->SetFiltergraph(_pGB)); + + // �t�B���^�̐ڑ� + CHECK(_pCGB2->RenderStream(0, 0, _pSource, 0, _pVMR9)); + CHECK(_pCGB2->RenderStream(0, &MEDIATYPE_Audio, _pSource, 0, 0)); + + // �`��̈�̐ݒ�i�ڑ���łȂ��ƃG���[�ɂȂ�j + LONG W, H; + CHECK(pVMRWndCont->GetNativeVideoSize(&W, &H, NULL, NULL)); + RECT SrcR, DestR; + SetRect(&SrcR, 0, 0, W, H); + GetClientRect(_hWnd, &DestR); + CHECK(pVMRWndCont->SetVideoPosition(&SrcR, &DestR)); + pVMRWndCont->Release(); // �E�B���h�E���X�R���g���[���͂����K�v�Ȃ� + + // ���f�B�A�R���g���[���C���^�[�t�F�C�X�̎擾 + CHECK(_pGB->QueryInterface(IID_IMediaControl, (void**)&_pMediaCont)); + + // ���f�B�A�C�x���g�C���^�[�t�F�C�X�̎擾 + CHECK(_pGB->QueryInterface(IID_IMediaEvent, (void**)&_pMediaEvent)); + + // ���f�B�A�|�W�V�����C���^�[�t�F�C�X�̎擾 + CHECK(_pGB->QueryInterface(IID_IMediaPosition, (void**)&_pMediaPosition)); + + ShowWindow(_hWnd, SW_SHOWNORMAL); + _pMediaCont->Run(); + + return true; +} + +// �����~ +bool DShowMovie::StopMovie() { + if (!IsPlaying()) return false; + _pMediaCont->Stop(); + SAFE_RELEASE(_pMediaPosition); + SAFE_RELEASE(_pMediaEvent); + SAFE_RELEASE(_pMediaCont); + SAFE_RELEASE(_pCGB2); + SAFE_RELEASE(_pSource); + SAFE_RELEASE(_pVMR9); + SAFE_RELEASE(_pGB); + ShowWindow(_hWnd, SW_HIDE); + + return true; +} + +// �Đ���Ԃ̊m�F +bool DShowMovie::IsPlaying() { + if (!_pMediaCont) return false; + FILTER_STATE fs; + _pMediaCont->GetState(100, (OAFilterState*)&fs); + return (fs == State_Running); +} diff --git a/ECTrainer2/DShowMovie.h b/ECTrainer2/DShowMovie.h new file mode 100644 index 0000000..22b721f --- /dev/null +++ b/ECTrainer2/DShowMovie.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +#define SAFE_RELEASE(x) if (x) { x->Release(); x = NULL; } +#define CHECK(x) { if(((HRESULT)(x)) < 0) return false; } + +class DShowMovie { + RECT _DispRect; // DirectShow����\���ʒu + HWND _hWnd; + LPDIRECT3D9 _pD3D; + LPDIRECT3DDEVICE9 _pD3DDev; + IGraphBuilder* _pGB; + IBaseFilter* _pVMR9; + IBaseFilter* _pSource; + ICaptureGraphBuilder2* _pCGB2; + IMediaControl* _pMediaCont; + IMediaEvent* _pMediaEvent; + IMediaPosition* _pMediaPosition; + +public: + DShowMovie(); + ~DShowMovie(); + bool InitDx(HINSTANCE hInstance, RECT dispRect); + bool PlayMovie(std::wstring movie); + bool StopMovie(); + bool IsPlaying(); +}; diff --git a/ECTrainer2/ECTrainer2.vcxproj b/ECTrainer2/ECTrainer2.vcxproj index 324cb13..f6e73a1 100644 --- a/ECTrainer2/ECTrainer2.vcxproj +++ b/ECTrainer2/ECTrainer2.vcxproj @@ -145,6 +145,7 @@ + @@ -165,8 +166,8 @@ - + diff --git a/ECTrainer2/ECTrainer2.vcxproj.filters b/ECTrainer2/ECTrainer2.vcxproj.filters index 1d84d96..68eaed4 100644 --- a/ECTrainer2/ECTrainer2.vcxproj.filters +++ b/ECTrainer2/ECTrainer2.vcxproj.filters @@ -69,6 +69,9 @@ ソース ファイル + + ソース ファイル + @@ -134,7 +137,7 @@ ヘッダー ファイル - + ヘッダー ファイル diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index 1a82cf3..9a62f55 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -1,128 +1,75 @@ -#include "common.h" +#include "DShowMovie.h" +#include "ECTrainerGUI.h" +#include "ECTrainer.h" +#include "Worker.h" +#include "EyeTrack.h" +#include "ImageProc.h" +#include "BitalMonitor.h" +#include "TobiiREST.h" +#include "Marker.h" +#include "myWinUtils.h" +#include "myOpenCVutil.h" #include #pragma comment(lib,"winmm.lib") #include -#pragma comment(lib, "dxguid.lib") -#pragma comment(lib, "d3d9.lib") -#pragma comment(lib, "Strmiids.lib") -#define _WIN32_DCOM // CoInitializeEx�֐��̌Ăяo���ɕK�v #define CVUI_IMPLEMENTATION #include "cvui.h" -#ifdef _DEBUG -#include -#endif +//#ifdef _DEBUG +//#include +//#endif // �R���X�g���N�^ -ECTrainerGUI::ECTrainerGUI(ECTrainer* pEct) - : BaseProcess(pEct) - , _pD3D(NULL) - , _pD3DDev(NULL) - , _pGB(NULL) - , _pVMR9(NULL) - , _pSource(NULL) - , _pCGB2(NULL) - , _pMediaCont(NULL) - , _pMediaEvent(NULL) - , _hWnd(NULL) +ECTrainerGUI::ECTrainerGUI(ECTrainer* pEct) : BaseProcess(pEct) , _SceneBufferHeight(0) , _DispImageHeight(0) , _SceneBufferScale(1.F) , _hWndMain(NULL) , _AppRunning(true) + , _dsm(NULL) { -} - -// �f�X�g���N�^ -ECTrainerGUI::~ECTrainerGUI() { - SAFE_RELEASE(_pMediaPosition); - SAFE_RELEASE(_pMediaEvent); - SAFE_RELEASE(_pMediaCont); - SAFE_RELEASE(_pCGB2); - SAFE_RELEASE(_pSource); - SAFE_RELEASE(_pVMR9); - SAFE_RELEASE(_pGB); - SAFE_RELEASE(_pD3DDev); - SAFE_RELEASE(_pD3D); - CoUninitialize(); + _dsm = new DShowMovie(); } // ������ bool ECTrainerGUI::Init() { // ���s�‹��̏��擾 - std::vector _Displays = mwut::GetDisplayInfo(); + std::vector displays = mwut::GetDisplayInfo(); // GUI�E�C���h�E cvui::init(WIN_MAIN); _MainFrame.create(MAIN_FRAME_SIZE, CV_8UC3); // �h���񎦃E�C���h�E - if (_Displays.size() > 1) { + if (displays.size() > 1) { // �}���`���j�^�̏ꍇ // �T�u��ʂɑ���p�l���\�� - cv::moveWindow(WIN_MAIN, _Displays[1].left, _Displays[1].top); + cv::moveWindow(WIN_MAIN, displays[1].left, displays[1].top); _hWndMain = ::FindWindowA(NULL, WIN_MAIN.c_str()); // ���C����ʂɔ팱�҉f���񎦁iDirectShow���悪�T�u��ʂɏo�͂ł��Ȃ����߁j cv::namedWindow(WIN_DISP, cv::WINDOW_NORMAL | cv::WINDOW_OPENGL); - cv::moveWindow(WIN_DISP, _Displays[0].left, _Displays[0].top); + cv::moveWindow(WIN_DISP, displays[0].left, displays[0].top); cv::resizeWindow(WIN_DISP, cv::Size(640, 400)); cv::setWindowProperty(WIN_DISP, cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN); - _DispBuffer.create(cv::Size(_Displays[0].right - _Displays[0].left, - _Displays[0].bottom - _Displays[0].top), CV_8UC3); - _DispRect = _Displays[0]; + _DispBuffer.create(cv::Size(displays[0].right - displays[0].left, + displays[0].bottom - displays[0].top), CV_8UC3); + //_DispRect = _Displays[0]; } else { // �V���O�����j�^�̏ꍇ cv::namedWindow(WIN_DISP, cv::WINDOW_AUTOSIZE); - cv::moveWindow(WIN_DISP, _Displays[0].left, _Displays[0].top); + cv::moveWindow(WIN_DISP, displays[0].left, displays[0].top); _DispBuffer.create(cv::Size(640, 480), CV_8UC3); - cv::moveWindow(WIN_MAIN, _Displays[0].left + 100, _Displays[0].top + 100); - _DispRect = _Displays[0]; + cv::moveWindow(WIN_MAIN, displays[0].left + 100, displays[0].top + 100); + //_DispRect = _Displays[0]; } _blank = cv::Mat(DISP_SIZE, CV_8UC3, cv::Scalar(0)); //blank.copyTo(_SceneBuffer); _blank.copyTo(_DispImage); _Logo = cv::imread("../images/ECTLogo2_1480l.png"); - return InitDx(_pEct->GetInstance()); -} - -// DirectX�̏����� -bool ECTrainerGUI::InitDx(HINSTANCE hInstance) { - TCHAR gName[100] = _T("Video Window"); - WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance, NULL, NULL, - (HBRUSH)(COLOR_WINDOW + 1), NULL, (TCHAR*)gName, NULL }; - if (!RegisterClassEx(&wcex)) return 0; - - // �t���X�N���[���p�Ƀ|�b�v�A�b�v�E�B���h�E���쐬 - if (!(_hWnd = CreateWindow(gName, gName, WS_POPUPWINDOW, _DispRect.left, _DispRect.top, - _DispRect.right - _DispRect.left, _DispRect.bottom - _DispRect.top, - NULL, NULL, hInstance, NULL))) - return false; - - // Direct3D�̏����� - if (!(_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return false; - - // �t���X�N���[���p�ɏ������p�����[�^��ݒ� - D3DPRESENT_PARAMETERS d3dpp = { (UINT)(_DispRect.right - _DispRect.left), - (UINT)(_DispRect.bottom - _DispRect.top), D3DFMT_A8R8G8B8, 0, D3DMULTISAMPLE_NONE, 0, - D3DSWAPEFFECT_DISCARD, _hWnd, FALSE, 0, D3DFMT_UNKNOWN, D3DPRESENT_RATE_DEFAULT, 0}; - - if (FAILED(_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _hWnd, - D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &_pD3DDev))) { - - CHECK(_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _hWnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &_pD3DDev)); - printf("Software DirectX\n"); - } else { - printf("Hardware DirectX\n"); - } - - // COM�̏����� - CHECK(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); - - return true; + return _dsm->InitDx(_pEct->GetInstance(), displays[0]); } // �񃁃b�Z�[�W���̏��� @@ -164,7 +111,7 @@ break; case APP_STATUS::STIM: if (cvui::button(140, 30, "STOP")) { - if (!StopMovie()) _pEct->StopApp(); + if (!_dsm->StopMovie()) _pEct->StopApp(); //fKeepContact = false; ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::STIM_STOP); //_pEct->PWorker()->StopStim(); @@ -181,10 +128,10 @@ //cvui::printf("Img Gaze %.2f, %.2f", _pEct->GetGazeI().x, _pEct->GetGazeI().y); cvui::text(_pEct->PMarker()->IsDetected() ? "AR Markers OK" : "AR Markers NG"); cvui::printf("Battery %d %%", _pEct->PTobiiREST()->GetBatteryLevel()); - if (IsPlaying()) { - REFTIME tm; - _pMediaPosition->get_CurrentPosition(&tm); - cvui::printf("Movie pos: %.1f", tm); + if (_dsm->IsPlaying()) { + //REFTIME tm; + //_pMediaPosition->get_CurrentPosition(&tm); + //cvui::printf("Movie pos: %.1f", tm); } bool snapshot = cvui::button(140, 30, "SNAPSHOT"); if (cvui::button(140, 30, "QUIT")) _pEct->StopApp(); @@ -210,9 +157,9 @@ if (movieToShow.size() > 0) { _pEct->SetMovieToShow(L""); if (movieToShow == L"STOP") { - if (!StopMovie()) _pEct->StopApp(); + if (!_dsm->StopMovie()) _pEct->StopApp(); } else { - if (!PlayMovie(movieToShow)) { + if (!_dsm->PlayMovie(movieToShow)) { mwut::DebugPrintf(_T("Can't play movie: %s\n"), movieToShow.c_str()); _pEct->StopApp(); } @@ -220,15 +167,15 @@ } // �Đ��I���̃`�F�b�N - if (_pMediaEvent) { - long eventCode; - _pMediaEvent->WaitForCompletion(1, &eventCode);//����̏�Ԃ�⑫ - if (eventCode != 0) { - if (!StopMovie()) _pEct->StopApp(); - //_PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); - //if (!PlayMovie()) _pEct->Stop(); - } - } + //if (_pMediaEvent) { + // long eventCode; + // _pMediaEvent->WaitForCompletion(1, &eventCode);//����̏�Ԃ�⑫ + // if (eventCode != 0) { + // if (!_dsm->StopMovie()) _pEct->StopApp(); + // //_PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); + // //if (!PlayMovie()) _pEct->Stop(); + // } + //} // ��ʕ\�� cvui::update(); @@ -283,87 +230,6 @@ return true; } -// ����Đ� -bool ECTrainerGUI::PlayMovie(std::wstring movie) { - //if (_PlayIndex < 0 || _PlayIndex >= _MovieFiles.size()) return false; - - // �t�B���^�O���t�}�l�[�W���̍쐬 - CHECK(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_pGB)); - - // VRM9�t�B���^�̍쐬�Ɠo�^ - CHECK(CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&_pVMR9)); - CHECK(_pGB->AddFilter(_pVMR9, L"VMR9")); // �t�B���^�O���t�ɓo�^ - - // VRM9���E�B���h�E���X���[�h�ɂ��� - IVMRFilterConfig* pVMRCfg = NULL; - CHECK(_pVMR9->QueryInterface(IID_IVMRFilterConfig9, (void**)&pVMRCfg)); - CHECK(pVMRCfg->SetRenderingMode(VMRMode_Windowless)); - pVMRCfg->Release(); // IVMRFilterConfig�͂����K�v�Ȃ� - - // �`��E�B���h�E�̎w�� - IVMRWindowlessControl9* pVMRWndCont = NULL; - CHECK(_pVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void**)&pVMRWndCont)); - CHECK(pVMRWndCont->SetVideoClippingWindow(_hWnd)); - - // �\�[�X�t�B���^�̐����Ɠo�^ - CHECK(_pGB->AddSourceFilter(movie.c_str(), movie.c_str(), &_pSource)); - - // CaptureGraphBuilder2�C���^�[�t�F�C�X�̎擾 - CHECK(CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&_pCGB2)); - CHECK(_pCGB2->SetFiltergraph(_pGB)); - - // �t�B���^�̐ڑ� - CHECK(_pCGB2->RenderStream(0, 0, _pSource, 0, _pVMR9)); - CHECK(_pCGB2->RenderStream(0, &MEDIATYPE_Audio, _pSource, 0, 0)); - - // �`��̈�̐ݒ�i�ڑ���łȂ��ƃG���[�ɂȂ�j - LONG W, H; - CHECK(pVMRWndCont->GetNativeVideoSize(&W, &H, NULL, NULL)); - RECT SrcR, DestR; - SetRect(&SrcR, 0, 0, W, H); - GetClientRect(_hWnd, &DestR); - CHECK(pVMRWndCont->SetVideoPosition(&SrcR, &DestR)); - pVMRWndCont->Release(); // �E�B���h�E���X�R���g���[���͂����K�v�Ȃ� - - // ���f�B�A�R���g���[���C���^�[�t�F�C�X�̎擾 - CHECK(_pGB->QueryInterface(IID_IMediaControl, (void**)&_pMediaCont)); - - // ���f�B�A�C�x���g�C���^�[�t�F�C�X�̎擾 - CHECK(_pGB->QueryInterface(IID_IMediaEvent, (void**)&_pMediaEvent)); - - // ���f�B�A�|�W�V�����C���^�[�t�F�C�X�̎擾 - CHECK(_pGB->QueryInterface(IID_IMediaPosition, (void**)&_pMediaPosition)); - - ShowWindow(_hWnd, SW_SHOWNORMAL); - _pMediaCont->Run(); - - return true; -} - -// �����~ -bool ECTrainerGUI::StopMovie() { - if (!IsPlaying()) return false; - _pMediaCont->Stop(); - SAFE_RELEASE(_pMediaPosition); - SAFE_RELEASE(_pMediaEvent); - SAFE_RELEASE(_pMediaCont); - SAFE_RELEASE(_pCGB2); - SAFE_RELEASE(_pSource); - SAFE_RELEASE(_pVMR9); - SAFE_RELEASE(_pGB); - ShowWindow(_hWnd, SW_HIDE); - - return true; -} - -// �Đ���Ԃ̊m�F -bool ECTrainerGUI::IsPlaying() { - if (!_pMediaCont) return false; - FILTER_STATE fs; - _pMediaCont->GetState(100, (OAFilterState*)&fs); - return (fs == State_Running); -} - // ����摜�o�b�t�@�ɉ摜��ݒ� //void ECTrainerGUI::SetSceneBuffer(cv::Mat& img) { // _SceneBufferScale = (float)IMAGE_WIDTH / img.cols; diff --git a/ECTrainer2/ECTrainerGUI.h b/ECTrainer2/ECTrainerGUI.h index b67f56f..e13bc95 100644 --- a/ECTrainer2/ECTrainerGUI.h +++ b/ECTrainer2/ECTrainerGUI.h @@ -1,18 +1,11 @@ #pragma once -#include -#include +#include "BaseProcess.h" #include "myOpenCV.h" #include -#include "BaseProcess.h" -#include -#include -#include - -LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -#define SAFE_RELEASE(x) if (x) { x->Release(); x = NULL; } -#define CHECK(x) { if(((HRESULT)(x)) < 0) return false; } +class DShowMovie; +class ECTrainer; class ECTrainerGUI : public BaseProcess { @@ -26,10 +19,10 @@ const cv::Point DISP_IMAGE_POS = cv::Point(820, 120); const int KEY_ESC = 27; + DShowMovie* _dsm; cv::Mat _MainFrame; // ���C���E�C���h�E�t���[�� cv::Mat _DispImage; // �h���摜�i����җp�j cv::Mat _DispBuffer; // �h����ʁi�팱�җp�j - //cv::Mat _SceneBuffer; // ����摜 cv::Mat _Logo; // ���S cv::Mat _blank; // �u�����N int _SceneBufferHeight; @@ -38,28 +31,11 @@ HWND _hWndMain; bool _AppRunning; // ���s���t���O - RECT _DispRect; // DirectShow����\���ʒu - HWND _hWnd; - LPDIRECT3D9 _pD3D; - LPDIRECT3DDEVICE9 _pD3DDev; - IGraphBuilder* _pGB; - IBaseFilter* _pVMR9; - IBaseFilter* _pSource; - ICaptureGraphBuilder2* _pCGB2; - IMediaControl* _pMediaCont; - IMediaEvent* _pMediaEvent; - IMediaPosition* _pMediaPosition; - - bool InitDx(HINSTANCE hInstance); - bool PlayMovie(std::wstring movie); - bool StopMovie(); - bool IsPlaying(); bool Routine(); bool MainLoop(); public: ECTrainerGUI(ECTrainer* pEct); - ~ECTrainerGUI(); bool Init(); bool Tell(ECTMSG msg, WPARAM wp = 0, LPARAM lp = 0); HWND GetMainHWnd() { return _hWndMain; } diff --git a/ECTrainer2/EyeTrack.cpp b/ECTrainer2/EyeTrack.cpp index 715ecb0..487d24b 100644 --- a/ECTrainer2/EyeTrack.cpp +++ b/ECTrainer2/EyeTrack.cpp @@ -1,6 +1,7 @@ #include #include -#include "common.h" +#include "EyeTrack.h" +#include "ECTrainer.h" #pragma comment(lib, "ws2_32.lib") #include diff --git a/ECTrainer2/common.h b/ECTrainer2/common.h deleted file mode 100644 index 11dec7c..0000000 --- a/ECTrainer2/common.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "ECTrainer.h" -#include "ECTrainerGUI.h" -#include "BitalMonitor.h" -#include "EyeTrack.h" -#include "ImageProc.h" -#include "KeepAlive.h" -#include "Marker.h" -#include "SceneCamera.h" -#include "Stimulus.h" -#include "TobiiREST.h" -#include "Worker.h" -#include "myOpenCV.h" -#include "myOpenCVutil.h" -#include "myWinUtils.h" -#include -#include -#include -#include