diff --git a/pcsx2/USB/USB.cpp b/pcsx2/USB/USB.cpp index f3b8863b38..d8a02ec47e 100644 --- a/pcsx2/USB/USB.cpp +++ b/pcsx2/USB/USB.cpp @@ -19,6 +19,7 @@ #include #include +#include "PrecompiledHeader.h" #include "Utilities/pxStreams.h" #include "USB.h" #include "osdebugout.h" @@ -189,7 +190,11 @@ s32 USBinit() if (conf.Log && !usbLog) { +#ifdef _WIN32 + usbLog = wfopen(LogDir.c_str(), L"wb"); // L"wb,ccs=UNICODE"); +#else usbLog = wfopen(LogDir.c_str(), "wb"); // L"wb,ccs=UNICODE"); +#endif //if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); USB_LOG("USBinit\n"); } diff --git a/pcsx2/USB/Win32/Config.cpp b/pcsx2/USB/Win32/Config.cpp index fb5ffe4210..6e4a2887bd 100644 --- a/pcsx2/USB/Win32/Config.cpp +++ b/pcsx2/USB/Win32/Config.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "AppCoreThread.h" #include "../USB.h" #include "resource.h" diff --git a/pcsx2/USB/configuration.cpp b/pcsx2/USB/configuration.cpp index d87669ba47..cf3fa07c00 100644 --- a/pcsx2/USB/configuration.cpp +++ b/pcsx2/USB/configuration.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "osdebugout.h" #include "deviceproxy.h" #include "configuration.h" @@ -30,13 +31,21 @@ CIniFile ciniFile; void USBsetSettingsDir(const char* dir) { +#ifdef _WIN32 + IniPath = str_to_wstr(dir); +#else IniPath = dir; +#endif IniPath.append(iniFile); } void USBsetLogDir(const char* dir) { +#ifdef _WIN32 + LogDir = str_to_wstr(dir); +#else LogDir = dir; +#endif } std::string GetSelectedAPI(const std::pair& pair) @@ -50,18 +59,37 @@ std::string GetSelectedAPI(const std::pair& pair) bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, TSTDSTRING& value) { CIniKey* key; +#ifdef _WIN32 + auto sect = ciniFile.GetSection(section); + if (sect && (key = sect->GetKey(param))) + { + value = key->GetValue(); + return true; + } +#else auto sect = ciniFile.GetSection(str_to_wstr(section)); if (sect && (key = sect->GetKey(str_to_wstr(param)))) { value = wstr_to_str(key->GetValue()); return true; } +#endif return false; } bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, int32_t& value) { CIniKey* key; +#ifdef _WIN32 + auto sect = ciniFile.GetSection(section); + if (sect && (key = sect->GetKey(param))) + { + try + { + value = std::stoi(key->GetValue()); + return true; + } +#else auto sect = ciniFile.GetSection(str_to_wstr(section)); if (sect && (key = sect->GetKey(str_to_wstr(param)))) { @@ -70,6 +98,7 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC value = std::stoi(key->GetValue()); return true; } +#endif catch (std::exception& err) { OSDebugOut(TEXT("%" SFMTs "\n"), err.what()); @@ -80,20 +109,32 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, const TSTDSTRING& value) { +#ifdef _WIN32 + ciniFile.SetKeyValue(section, param, value); +#else ciniFile.SetKeyValue(str_to_wstr(section), str_to_wstr(param), str_to_wstr(value)); +#endif return true; } bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, int32_t value) { +#ifdef _WIN32 + ciniFile.SetKeyValue(section, param, TSTDTOSTRING(value)); +#else ciniFile.SetKeyValue(str_to_wstr(section), str_to_wstr(param), str_to_wstr(TSTDTOSTRING(value))); +#endif return true; } void SaveConfig() { +#ifdef _WIN32 + SaveSetting(L"MAIN", L"log", conf.Log); +#else SaveSetting("MAIN", "log", conf.Log); +#endif SaveSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, conf.Port[0]); SaveSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, conf.Port[1]); @@ -106,17 +147,27 @@ void SaveConfig() SaveSetting(nullptr, k.first.first, k.first.second, N_DEVICE_API, k.second); } - ciniFile.Save(str_to_wstr(IniPath)); +#ifdef _WIN32 + bool ret = ciniFile.Save(IniPath); OSDebugOut(_T("ciniFile.Save: %d [%s]\n"), ret, IniPath.c_str()); +#else + bool ret = ciniFile.Save(str_to_wstr(IniPath)); + OSDebugOut(_T("ciniFile.Save: %d [%s]\n"), ret, IniPath.c_str()); +#endif } void LoadConfig() { std::cerr << "USB load config\n" << std::endl; - ciniFile.Load(str_to_wstr(IniPath)); +#ifdef _WIN32 + ciniFile.Load(IniPath); + LoadSetting(L"MAIN", L"log", conf.Log); +#else + ciniFile.Load(str_to_wstr(IniPath)); LoadSetting("MAIN", "log", conf.Log); +#endif LoadSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, conf.Port[0]); LoadSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, conf.Port[1]); @@ -155,7 +206,11 @@ void LoadConfig() void ClearSection(const TCHAR* section) { +#ifdef _WIN32 + auto s = ciniFile.GetSection(section); +#else auto s = ciniFile.GetSection(str_to_wstr(section)); +#endif if (s) { s->RemoveAllKeys(); @@ -173,5 +228,9 @@ void RemoveSection(const char* dev_type, int port, const std::string& key) section << tkey << _T(" ") << port; TSTDSTRING str = section.str(); +#ifdef _WIN32 + ciniFile.RemoveSection(section.str()); +#else ciniFile.RemoveSection(str_to_wstr(section.str())); +#endif } diff --git a/pcsx2/USB/device_init.cpp b/pcsx2/USB/device_init.cpp index 3259056e50..5b6e93e5e0 100644 --- a/pcsx2/USB/device_init.cpp +++ b/pcsx2/USB/device_init.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "deviceproxy.h" #include "usb-pad/usb-pad.h" #include "usb-msd/usb-msd.h" diff --git a/pcsx2/USB/deviceproxy.cpp b/pcsx2/USB/deviceproxy.cpp index ffd24bf110..42dd85f802 100644 --- a/pcsx2/USB/deviceproxy.cpp +++ b/pcsx2/USB/deviceproxy.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "deviceproxy.h" #include "usb-pad/padproxy.h" #include "usb-mic/audiodeviceproxy.h" diff --git a/pcsx2/USB/osdebugout.cpp b/pcsx2/USB/osdebugout.cpp index 8053ba4b45..bd5e8a2428 100644 --- a/pcsx2/USB/osdebugout.cpp +++ b/pcsx2/USB/osdebugout.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "osdebugout.h" std::wostream& operator<<(std::wostream& os, const std::string& s) diff --git a/pcsx2/USB/platcompat.h b/pcsx2/USB/platcompat.h index 7cd69e3405..e908d01a2e 100644 --- a/pcsx2/USB/platcompat.h +++ b/pcsx2/USB/platcompat.h @@ -57,9 +57,10 @@ #define TSTDTOSTRING std::to_wstring #ifdef _MSC_VER -typedef SSIZE_T ssize_t; +//typedef SSIZE_T ssize_t; #endif + //FIXME narrow string fmt #define SFMTs "S" diff --git a/pcsx2/USB/qemu-usb/bus.cpp b/pcsx2/USB/qemu-usb/bus.cpp index e53a68e1d4..989b9e5534 100644 --- a/pcsx2/USB/qemu-usb/bus.cpp +++ b/pcsx2/USB/qemu-usb/bus.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "USBinternal.h" #include "vl.h" diff --git a/pcsx2/USB/qemu-usb/core.cpp b/pcsx2/USB/qemu-usb/core.cpp index fd45dcb315..9fdbd1875d 100644 --- a/pcsx2/USB/qemu-usb/core.cpp +++ b/pcsx2/USB/qemu-usb/core.cpp @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "PrecompiledHeader.h" #include "../osdebugout.h" #include "../platcompat.h" #include "vl.h" diff --git a/pcsx2/USB/qemu-usb/desc.cpp b/pcsx2/USB/qemu-usb/desc.cpp index b45596e7c1..d44285ce1a 100644 --- a/pcsx2/USB/qemu-usb/desc.cpp +++ b/pcsx2/USB/qemu-usb/desc.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "vl.h" #include "desc.h" #include "glib.h" diff --git a/pcsx2/USB/qemu-usb/glib.cpp b/pcsx2/USB/qemu-usb/glib.cpp index 727e4c6899..e89c7ceb62 100644 --- a/pcsx2/USB/qemu-usb/glib.cpp +++ b/pcsx2/USB/qemu-usb/glib.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "glib.h" #include #include diff --git a/pcsx2/USB/qemu-usb/hid.cpp b/pcsx2/USB/qemu-usb/hid.cpp index 22d5d5b4f3..afab63dc73 100644 --- a/pcsx2/USB/qemu-usb/hid.cpp +++ b/pcsx2/USB/qemu-usb/hid.cpp @@ -22,6 +22,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "PrecompiledHeader.h" #include "hid.h" #include "input-keymap.h" #include "../osdebugout.h" diff --git a/pcsx2/USB/qemu-usb/input-keymap-qcode-to-qnum.cpp b/pcsx2/USB/qemu-usb/input-keymap-qcode-to-qnum.cpp index d22b091ed9..0cd5cdf476 100644 --- a/pcsx2/USB/qemu-usb/input-keymap-qcode-to-qnum.cpp +++ b/pcsx2/USB/qemu-usb/input-keymap-qcode-to-qnum.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "input-keymap.h" //TODO how much does std::map kill perf if any? diff --git a/pcsx2/USB/qemu-usb/input-keymap-win32-to-qcode.cpp b/pcsx2/USB/qemu-usb/input-keymap-win32-to-qcode.cpp index c204e997a7..3bedb6e5f6 100644 --- a/pcsx2/USB/qemu-usb/input-keymap-win32-to-qcode.cpp +++ b/pcsx2/USB/qemu-usb/input-keymap-win32-to-qcode.cpp @@ -18,6 +18,7 @@ * To re-generate, run: * keymap-gen --lang=stdc++ --varname=qemu_input_map_win32_to_qcode code-map keymaps.csv win32 qcode */ +#include "PrecompiledHeader.h" #include "input-keymap-win32-to-qcode.h" const std::array qemu_input_map_win32_to_qcode = { Q_KEY_CODE_UNMAPPED, /* win32:0 (unnamed) -> linux:None (unnamed) -> qcode:None (unnamed) */ diff --git a/pcsx2/USB/qemu-usb/iov.cpp b/pcsx2/USB/qemu-usb/iov.cpp index f7a47a232e..ad428f557c 100644 --- a/pcsx2/USB/qemu-usb/iov.cpp +++ b/pcsx2/USB/qemu-usb/iov.cpp @@ -16,6 +16,7 @@ * GNU GPL, version 2 or (at your option) any later version. */ +#include "PrecompiledHeader.h" #include "vl.h" //#include "qemu-common.h" #include "iov.h" diff --git a/pcsx2/USB/qemu-usb/iov.h b/pcsx2/USB/qemu-usb/iov.h index 99b68b6c6c..acb3f5b8e1 100644 --- a/pcsx2/USB/qemu-usb/iov.h +++ b/pcsx2/USB/qemu-usb/iov.h @@ -11,6 +11,8 @@ * the COPYING file in the top-level directory. */ +#include "../platcompat.h" + #ifndef IOV_H #define IOV_H diff --git a/pcsx2/USB/qemu-usb/usb-ohci.cpp b/pcsx2/USB/qemu-usb/usb-ohci.cpp index 9c092e7b9f..94b11e327d 100644 --- a/pcsx2/USB/qemu-usb/usb-ohci.cpp +++ b/pcsx2/USB/qemu-usb/usb-ohci.cpp @@ -28,6 +28,7 @@ //typedef CPUReadMemoryFunc +#include "PrecompiledHeader.h" #include "vl.h" #include "queue.h" #include "USBinternal.h" diff --git a/pcsx2/USB/qemu-usb/vl.cpp b/pcsx2/USB/qemu-usb/vl.cpp index 0b52a551aa..01971a233e 100644 --- a/pcsx2/USB/qemu-usb/vl.cpp +++ b/pcsx2/USB/qemu-usb/vl.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "vl.h" /* compute with 96 bit intermediate result: (a*b)/c */ diff --git a/pcsx2/USB/shared/hidapi.cpp b/pcsx2/USB/shared/hidapi.cpp index e2d96c1d0a..888bc4209b 100644 --- a/pcsx2/USB/shared/hidapi.cpp +++ b/pcsx2/USB/shared/hidapi.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include #include #include "hidapi.h" diff --git a/pcsx2/USB/shared/hidapi.h b/pcsx2/USB/shared/hidapi.h index 444ce4b9a2..2d5c798e32 100644 --- a/pcsx2/USB/shared/hidapi.h +++ b/pcsx2/USB/shared/hidapi.h @@ -18,6 +18,8 @@ #include +#define NTSTATUS int + typedef USHORT USAGE, *PUSAGE; #define HID_USAGE_PAGE_GENERIC ((USAGE)0x01) diff --git a/pcsx2/USB/shared/inifile.cpp b/pcsx2/USB/shared/inifile.cpp index a2c0a8fd14..f355621198 100644 --- a/pcsx2/USB/shared/inifile.cpp +++ b/pcsx2/USB/shared/inifile.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "inifile.h" #include #include diff --git a/pcsx2/USB/shared/rawinput.cpp b/pcsx2/USB/shared/rawinput.cpp index 927dab2fe1..e83ba9f35b 100644 --- a/pcsx2/USB/shared/rawinput.cpp +++ b/pcsx2/USB/shared/rawinput.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "rawinput.h" #include #include diff --git a/pcsx2/USB/shared/ringbuffer.cpp b/pcsx2/USB/shared/ringbuffer.cpp index 57bfee0480..b522d2fa25 100644 --- a/pcsx2/USB/shared/ringbuffer.cpp +++ b/pcsx2/USB/shared/ringbuffer.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "ringbuffer.h" #include #include diff --git a/pcsx2/USB/shared/shared.cpp b/pcsx2/USB/shared/shared.cpp index e9c7479091..8d1fa6206d 100644 --- a/pcsx2/USB/shared/shared.cpp +++ b/pcsx2/USB/shared/shared.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "shared.h" #include diff --git a/pcsx2/USB/usb-eyetoy/api_init_win32.cpp b/pcsx2/USB/usb-eyetoy/api_init_win32.cpp index 6b1b45e7c9..6f41feb1d4 100644 --- a/pcsx2/USB/usb-eyetoy/api_init_win32.cpp +++ b/pcsx2/USB/usb-eyetoy/api_init_win32.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "videodeviceproxy.h" #include "cam-windows.h" diff --git a/pcsx2/USB/usb-eyetoy/cam-windows.cpp b/pcsx2/USB/usb-eyetoy/cam-windows.cpp index 229b0691d8..98559df7f9 100644 --- a/pcsx2/USB/usb-eyetoy/cam-windows.cpp +++ b/pcsx2/USB/usb-eyetoy/cam-windows.cpp @@ -13,7 +13,7 @@ * If not, see . */ -#include +#include "PrecompiledHeader.h" #include "videodev.h" #include "cam-windows.h" #include "usb-eyetoy-webcam.h" @@ -22,104 +22,6 @@ #include "../Win32/Config.h" #include "../Win32/resource.h" -#ifndef DIBSIZE -#define WIDTHBYTES(BTIS) ((DWORD)(((BTIS) + 31) & (~31)) / 8) -#define DIBWIDTHBYTES(BI) (DWORD)(BI).biBitCount) * (DWORD)WIDTHBYTES((DWORD)(BI).biWidth -#define _DIBSIZE(BI) (DIBWIDTHBYTES(BI) * (DWORD)(BI).biHeight) -#define DIBSIZE(BI) ((BI).biHeight < 0 ? (-1) * (_DIBSIZE(BI)) : _DIBSIZE(BI)) -#endif - -constexpr GUID make_guid(const char* const spec) -{ -#define nybble_from_hex(c) ((c >= '0' && c <= '9') ? (c - '0') : ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) : 0))) -#define byte_from_hex(c1, c2) ((nybble_from_hex(c1) << 4) | nybble_from_hex(c2)) - - return { - // Data1 - ((((((((((((( - static_cast(nybble_from_hex(spec[0])) - << 4) | - nybble_from_hex(spec[1])) - << 4) | - nybble_from_hex(spec[2])) - << 4) | - nybble_from_hex(spec[3])) - << 4) | - nybble_from_hex(spec[4])) - << 4) | - nybble_from_hex(spec[5])) - << 4) | - nybble_from_hex(spec[6])) - << 4) | - nybble_from_hex(spec[7]), - // Data2 - static_cast( - ((((( - static_cast(nybble_from_hex(spec[9])) - << 4) | - nybble_from_hex(spec[10])) - << 4) | - nybble_from_hex(spec[11])) - << 4) | - nybble_from_hex(spec[12])), - // Data 3 - static_cast( - ((((( - static_cast(nybble_from_hex(spec[14])) - << 4) | - nybble_from_hex(spec[15])) - << 4) | - nybble_from_hex(spec[16])) - << 4) | - nybble_from_hex(spec[17])), - // Data 4 - { - static_cast(byte_from_hex(spec[19], spec[20])), - static_cast(byte_from_hex(spec[21], spec[22])), - static_cast(byte_from_hex(spec[24], spec[25])), - static_cast(byte_from_hex(spec[26], spec[27])), - static_cast(byte_from_hex(spec[28], spec[29])), - static_cast(byte_from_hex(spec[30], spec[31])), - static_cast(byte_from_hex(spec[32], spec[33])), - static_cast(byte_from_hex(spec[34], spec[35]))}}; -} - -#if defined(_MSC_VER) -#define CPPX_MSVC_UUID_FOR(name, spec) \ - class __declspec(uuid(spec)) name -#else -#define CPPX_GNUC_UUID_FOR(name, spec) \ - template <> \ - inline auto __mingw_uuidof() \ - ->GUID const& \ - { \ - static constexpr GUID the_uuid = make_guid(spec); \ - \ - return the_uuid; \ - } \ - \ - template <> \ - inline auto __mingw_uuidof() \ - ->GUID const& \ - { \ - return __mingw_uuidof(); \ - } \ - \ - static_assert(true, "") -#endif - -#if !defined(CPPX_UUID_FOR) -#if defined(_MSC_VER) -#define CPPX_UUID_FOR CPPX_MSVC_UUID_FOR -#elif defined(__GNUC__) -#define CPPX_UUID_FOR CPPX_GNUC_UUID_FOR -#endif -#endif - -CPPX_UUID_FOR(ISampleGrabber, "6b652fff-11fe-4fce-92ad-0266b5d7c78f"); -CPPX_UUID_FOR(ISampleGrabberCB, "0579154a-2b53-4994-b0d0-e773148eff85"); -//CPPX_UUID_FOR(SampleGrabber, "c1f400a0-3f08-11d3-9f0b-006008039e37"); - namespace usb_eyetoy { namespace windows_api @@ -134,8 +36,8 @@ namespace usb_eyetoy if (hr != S_OK) return S_OK; - if (parent) - std::invoke(&DirectShow::dshow_callback, parent, buffer, sample->GetActualDataLength(), BITS_PER_PIXEL); + if (callback) + callback(buffer, sample->GetActualDataLength(), BITS_PER_PIXEL); return S_OK; } @@ -152,7 +54,6 @@ namespace usb_eyetoy std::vector getDevList() { std::vector devList; - devList.push_back(L"None"); ICreateDevEnum* pCreateDevEnum = 0; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCreateDevEnum)); @@ -163,484 +64,486 @@ namespace usb_eyetoy } IEnumMoniker* pEnum = 0; - hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); - if (hr == S_FALSE || FAILED(hr)) + hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, NULL); + if (FAILED(hr)) { + fprintf(stderr, "You have no video capture hardware"); + return devList; + }; + + IMoniker* pMoniker = NULL; + while (pEnum->Next(1, &pMoniker, NULL) == S_OK) + { + IPropertyBag* pPropBag; + HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); + if (FAILED(hr)) { - fprintf(stderr, "You have no video capture hardware"); - return devList; - }; - - IMoniker* pMoniker = NULL; - while (pEnum->Next(1, &pMoniker, NULL) == S_OK) - { - IPropertyBag* pPropBag; - HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); - if (FAILED(hr)) - { - pMoniker->Release(); - continue; - } - - VARIANT var; - VariantInit(&var); - hr = pPropBag->Read(L"Description", &var, 0); - if (FAILED(hr)) - { - hr = pPropBag->Read(L"FriendlyName", &var, 0); - } - if (SUCCEEDED(hr)) - { - devList.push_back(var.bstrVal); - VariantClear(&var); - } - - pPropBag->Release(); pMoniker->Release(); + continue; } - pEnum->Release(); - CoUninitialize(); + VARIANT var; + VariantInit(&var); + hr = pPropBag->Read(L"Description", &var, 0); + if (FAILED(hr)) + { + hr = pPropBag->Read(L"FriendlyName", &var, 0); + } + if (SUCCEEDED(hr)) + { + devList.push_back(var.bstrVal); + VariantClear(&var); + } - return devList; + pPropBag->Release(); + pMoniker->Release(); } - int DirectShow::InitializeDevice(std::wstring selectedDevice) + pEnum->Release(); + CoUninitialize(); + + return devList; + } + + int DirectShow::InitializeDevice(std::wstring selectedDevice) + { + + // Create the Capture Graph Builder. + HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraphBuilder)); + if (FAILED(hr)) { + fprintf(stderr, "CoCreateInstance CLSID_CaptureGraphBuilder2 err : %x\n", hr); + return -1; + } - // Create the Capture Graph Builder. - HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraphBuilder)); + // Create the Filter Graph Manager. + hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraph)); + if (FAILED(hr)) + { + fprintf(stderr, "CoCreateInstance CLSID_FilterGraph err : %x\n", hr); + return -1; + } + + hr = pGraphBuilder->SetFiltergraph(pGraph); + if (FAILED(hr)) + { + fprintf(stderr, "SetFiltergraph err : %x\n", hr); + return -1; + } + + hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl); + if (FAILED(hr)) + { + fprintf(stderr, "QueryInterface IID_IMediaControl err : %x\n", hr); + return -1; + } + + // enumerate all video capture devices + ICreateDevEnum* pCreateDevEnum = 0; + hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCreateDevEnum)); + if (FAILED(hr)) + { + fprintf(stderr, "Error Creating Device Enumerator"); + return -1; + } + + IEnumMoniker* pEnum = 0; + hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, NULL); + if (FAILED(hr)) + { + fprintf(stderr, "You have no video capture hardware"); + return -1; + }; + + pEnum->Reset(); + + IMoniker* pMoniker; + while (pEnum->Next(1, &pMoniker, NULL) == S_OK && sourcefilter == NULL) + { + IPropertyBag* pPropBag = 0; + hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); if (FAILED(hr)) { - fprintf(stderr, "CoCreateInstance CLSID_CaptureGraphBuilder2 err : %x\n", hr); - return -1; + fprintf(stderr, "BindToStorage err : %x\n", hr); + goto freeMoniker; } - // Create the Filter Graph Manager. - hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraph)); + VARIANT var; + VariantInit(&var); + + hr = pPropBag->Read(L"Description", &var, 0); if (FAILED(hr)) { - fprintf(stderr, "CoCreateInstance CLSID_FilterGraph err : %x\n", hr); - return -1; + hr = pPropBag->Read(L"FriendlyName", &var, 0); } - - hr = pGraphBuilder->SetFiltergraph(pGraph); if (FAILED(hr)) { - fprintf(stderr, "SetFiltergraph err : %x\n", hr); - return -1; + fprintf(stderr, "Read name err : %x\n", hr); + goto freeVar; + } + fprintf(stderr, "Camera: '%ls'\n", var.bstrVal); + if (!selectedDevice.empty() && selectedDevice != var.bstrVal) + { + goto freeVar; } - hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl); + //add a filter for the device + hr = pGraph->AddSourceFilterForMoniker(pMoniker, NULL, L"sourcefilter", &sourcefilter); if (FAILED(hr)) { - fprintf(stderr, "QueryInterface IID_IMediaControl err : %x\n", hr); - return -1; + fprintf(stderr, "AddSourceFilterForMoniker err : %x\n", hr); + goto freeVar; } - // enumerate all video capture devices - ICreateDevEnum* pCreateDevEnum = 0; - hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCreateDevEnum)); - if (FAILED(hr)) + hr = pGraphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, sourcefilter, IID_IAMStreamConfig, (void**)&pSourceConfig); + if (SUCCEEDED(hr)) { - fprintf(stderr, "Error Creating Device Enumerator"); - return -1; - } + int iCount = 0, iSize = 0; + hr = pSourceConfig->GetNumberOfCapabilities(&iCount, &iSize); - IEnumMoniker* pEnum = 0; - hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); - if (hr == S_FALSE || FAILED(hr)) - { + // Check the size to make sure we pass in the correct structure. + if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) { - fprintf(stderr, "You have no video capture hardware"); - return -1; - }; - - pEnum->Reset(); - - IMoniker* pMoniker; - while (pEnum->Next(1, &pMoniker, NULL) == S_OK && sourcefilter == NULL) - { - IPropertyBag* pPropBag = 0; - hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); - if (FAILED(hr)) + // Use the video capabilities structure. + for (int iFormat = 0; iFormat < iCount; iFormat++) { - fprintf(stderr, "BindToStorage err : %x\n", hr); - goto freeMoniker; - } + VIDEO_STREAM_CONFIG_CAPS scc; + AM_MEDIA_TYPE* pmtConfig; + hr = pSourceConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc); + fprintf(stderr, "GetStreamCaps min=%dx%d max=%dx%d, fmt=%x\n", + scc.MinOutputSize.cx, scc.MinOutputSize.cy, + scc.MaxOutputSize.cx, scc.MaxOutputSize.cy, + pmtConfig->subtype); - VARIANT var; - VariantInit(&var); - - hr = pPropBag->Read(L"Description", &var, 0); - if (FAILED(hr)) - { - hr = pPropBag->Read(L"FriendlyName", &var, 0); - } - if (FAILED(hr)) - { - fprintf(stderr, "Read name err : %x\n", hr); - goto freeVar; - } - fprintf(stderr, "Camera: '%ls'\n", var.bstrVal); - if (!selectedDevice.empty() && selectedDevice != var.bstrVal) - { - goto freeVar; - } - - //add a filter for the device - hr = pGraph->AddSourceFilterForMoniker(pMoniker, NULL, L"sourcefilter", &sourcefilter); - if (FAILED(hr)) - { - fprintf(stderr, "AddSourceFilterForMoniker err : %x\n", hr); - goto freeVar; - } - - hr = pGraphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, sourcefilter, IID_IAMStreamConfig, (void**)&pSourceConfig); - if (SUCCEEDED(hr)) - { - int iCount = 0, iSize = 0; - hr = pSourceConfig->GetNumberOfCapabilities(&iCount, &iSize); - - // Check the size to make sure we pass in the correct structure. - if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) + if (SUCCEEDED(hr)) { - // Use the video capabilities structure. - for (int iFormat = 0; iFormat < iCount; iFormat++) + if ((pmtConfig->majortype == MEDIATYPE_Video) && + (pmtConfig->formattype == FORMAT_VideoInfo) && + (pmtConfig->cbFormat >= sizeof(VIDEOINFOHEADER)) && + (pmtConfig->pbFormat != NULL)) { - VIDEO_STREAM_CONFIG_CAPS scc; - AM_MEDIA_TYPE* pmtConfig; - hr = pSourceConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc); - fprintf(stderr, "GetStreamCaps min=%dx%d max=%dx%d, fmt=%x\n", - scc.MinOutputSize.cx, scc.MinOutputSize.cy, - scc.MaxOutputSize.cx, scc.MaxOutputSize.cy, - pmtConfig->subtype); - if (SUCCEEDED(hr)) - { - if ((pmtConfig->majortype == MEDIATYPE_Video) && - (pmtConfig->formattype == FORMAT_VideoInfo) && - (pmtConfig->cbFormat >= sizeof(VIDEOINFOHEADER)) && - (pmtConfig->pbFormat != NULL)) - { - - VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat; - pVih->bmiHeader.biWidth = 320; - pVih->bmiHeader.biHeight = 240; - pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader); - hr = pSourceConfig->SetFormat(pmtConfig); - } - //DeleteMediaType(pmtConfig); - } + VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat; + pVih->bmiHeader.biWidth = 320; + pVih->bmiHeader.biHeight = 240; + pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader); + hr = pSourceConfig->SetFormat(pmtConfig); } + //DeleteMediaType(pmtConfig); } } - - // Create the Sample Grabber filter. - hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&samplegrabberfilter)); - if (FAILED(hr)) - { - fprintf(stderr, "CoCreateInstance CLSID_SampleGrabber err : %x\n", hr); - goto freeVar; - } - - hr = pGraph->AddFilter(samplegrabberfilter, L"samplegrabberfilter"); - if (FAILED(hr)) - { - fprintf(stderr, "AddFilter samplegrabberfilter err : %x\n", hr); - goto freeVar; - } - - //set mediatype on the samplegrabber - hr = samplegrabberfilter->QueryInterface(IID_PPV_ARGS(&samplegrabber)); - if (FAILED(hr)) - { - fprintf(stderr, "QueryInterface err : %x\n", hr); - goto freeVar; - } - - AM_MEDIA_TYPE mt; - ZeroMemory(&mt, sizeof(mt)); - mt.majortype = MEDIATYPE_Video; - mt.subtype = MEDIASUBTYPE_RGB24; - hr = samplegrabber->SetMediaType(&mt); - if (FAILED(hr)) - { - fprintf(stderr, "SetMediaType err : %x\n", hr); - goto freeVar; - } - - //add the callback to the samplegrabber - hr = samplegrabber->SetCallback(callbackhandler, 0); - if (hr != S_OK) - { - fprintf(stderr, "SetCallback err : %x\n", hr); - goto freeVar; - } - - //set the null renderer - hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&nullrenderer)); - if (FAILED(hr)) - { - fprintf(stderr, "CoCreateInstance CLSID_NullRenderer err : %x\n", hr); - goto freeVar; - } - - hr = pGraph->AddFilter(nullrenderer, L"nullrenderer"); - if (FAILED(hr)) - { - fprintf(stderr, "AddFilter nullrenderer err : %x\n", hr); - goto freeVar; - } - - //set the render path - hr = pGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, sourcefilter, samplegrabberfilter, nullrenderer); - if (FAILED(hr)) - { - fprintf(stderr, "RenderStream err : %x\n", hr); - goto freeVar; - } - - // if the stream is started, start capturing immediatly - LONGLONG start, stop; - start = 0; - stop = MAXLONGLONG; - hr = pGraphBuilder->ControlStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, sourcefilter, &start, &stop, 1, 2); - if (FAILED(hr)) - { - fprintf(stderr, "ControlStream err : %x\n", hr); - goto freeVar; - } - - freeVar: - VariantClear(&var); - pPropBag->Release(); - - freeMoniker: - pMoniker->Release(); - } - pEnum->Release(); - if (sourcefilter == NULL) - { - return -1; - } - return 0; - } - - void DirectShow::Start() - { - HRESULT hr = nullrenderer->Run(0); - if (FAILED(hr)) - throw hr; - - hr = samplegrabberfilter->Run(0); - if (FAILED(hr)) - throw hr; - - hr = sourcefilter->Run(0); - if (FAILED(hr)) - throw hr; - } - - void DirectShow::Stop() - { - if (!sourcefilter) - return; - HRESULT hr = sourcefilter->Stop(); - if (FAILED(hr)) - throw hr; - - hr = samplegrabberfilter->Stop(); - if (FAILED(hr)) - throw hr; - - hr = nullrenderer->Stop(); - if (FAILED(hr)) - throw hr; - } - void DirectShow::store_mpeg_frame(const std::vector& data) - { - std::lock_guard lk(mpeg_mutex); - mpeg_buffer = data; - } - - void DirectShow::dshow_callback(unsigned char* data, int len, int bitsperpixel) - { - if (bitsperpixel == 24) - { - std::vector mpegData(320 * 240 * 2); - int mpegLen = jo_write_mpeg(mpegData.data(), data, 320, 240, JO_RGB24, JO_FLIP_X, JO_FLIP_Y); - //OSDebugOut(_T("MPEG: alloced: %d, got: %d\n"), mpegData.size(), mpegLen); - mpegData.resize(mpegLen); - store_mpeg_frame(mpegData); - } - else - { - fprintf(stderr, "dshow_callback: unk format: len=%d bpp=%d\n", len, bitsperpixel); } } - void DirectShow::create_dummy_frame() + // Create the Sample Grabber filter. + hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&samplegrabberfilter)); + if (FAILED(hr)) { - const int width = 320; - const int height = 240; - const int bytesPerPixel = 3; - - std::vector rgbData(width * height * bytesPerPixel, 0); - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - unsigned char* ptr = &rgbData[(y * width + x) * bytesPerPixel]; - int c = (255 * y) / height; - ptr[0] = 255 - c; - ptr[1] = c; - ptr[2] = 255 - c; - } - } - std::vector mpegData(width * height * bytesPerPixel, 255); - int mpegLen = jo_write_mpeg(mpegData.data(), rgbData.data(), width, height, JO_RGB24, JO_NONE, JO_NONE); - mpegData.resize(mpegLen); - store_mpeg_frame(mpegData); + fprintf(stderr, "CoCreateInstance CLSID_SampleGrabber err : %x\n", hr); + goto freeVar; } - DirectShow::DirectShow(int port) + hr = pGraph->AddFilter(samplegrabberfilter, L"samplegrabberfilter"); + if (FAILED(hr)) { - mPort = port; - pGraphBuilder = NULL; - pGraph = NULL; - pControl = NULL; - sourcefilter = NULL; - samplegrabberfilter = NULL; - nullrenderer = NULL; - pSourceConfig = NULL; - samplegrabber = NULL; - callbackhandler = new CallbackHandler(this); - CoInitialize(NULL); + fprintf(stderr, "AddFilter samplegrabberfilter err : %x\n", hr); + goto freeVar; } - int DirectShow::Open() + //set mediatype on the samplegrabber + hr = samplegrabberfilter->QueryInterface(IID_PPV_ARGS(&samplegrabber)); + if (FAILED(hr)) { - mpeg_buffer.resize(320 * 240 * 2); - std::fill(mpeg_buffer.begin(), mpeg_buffer.end(), 0); + fprintf(stderr, "QueryInterface err : %x\n", hr); + goto freeVar; + } - create_dummy_frame(); + AM_MEDIA_TYPE mt; + ZeroMemory(&mt, sizeof(mt)); + mt.majortype = MEDIATYPE_Video; + mt.subtype = MEDIASUBTYPE_RGB24; + hr = samplegrabber->SetMediaType(&mt); + if (FAILED(hr)) + { + fprintf(stderr, "SetMediaType err : %x\n", hr); + goto freeVar; + } + + //add the callback to the samplegrabber + hr = samplegrabber->SetCallback(callbackhandler, 0); + if (hr != S_OK) + { + fprintf(stderr, "SetCallback err : %x\n", hr); + goto freeVar; + } + + //set the null renderer + hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&nullrenderer)); + if (FAILED(hr)) + { + fprintf(stderr, "CoCreateInstance CLSID_NullRenderer err : %x\n", hr); + goto freeVar; + } + + hr = pGraph->AddFilter(nullrenderer, L"nullrenderer"); + if (FAILED(hr)) + { + fprintf(stderr, "AddFilter nullrenderer err : %x\n", hr); + goto freeVar; + } + + //set the render path + hr = pGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, sourcefilter, samplegrabberfilter, nullrenderer); + if (FAILED(hr)) + { + fprintf(stderr, "RenderStream err : %x\n", hr); + goto freeVar; + } + + // if the stream is started, start capturing immediatly + LONGLONG start = 0, stop = MAXLONGLONG; + hr = pGraphBuilder->ControlStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, sourcefilter, &start, &stop, 1, 2); + if (FAILED(hr)) + { + fprintf(stderr, "ControlStream err : %x\n", hr); + goto freeVar; + } + + freeVar: + VariantClear(&var); + pPropBag->Release(); + + freeMoniker: + pMoniker->Release(); + } + pEnum->Release(); + if (sourcefilter == NULL) + { + return -1; + } + return 0; + } + + void DirectShow::Start() + { + HRESULT hr = nullrenderer->Run(0); + if (FAILED(hr)) + throw hr; + + hr = samplegrabberfilter->Run(0); + if (FAILED(hr)) + throw hr; + + hr = sourcefilter->Run(0); + if (FAILED(hr)) + throw hr; + } + + void DirectShow::Stop() + { + HRESULT hr = sourcefilter->Stop(); + if (FAILED(hr)) + throw hr; + + hr = samplegrabberfilter->Stop(); + if (FAILED(hr)) + throw hr; + + hr = nullrenderer->Stop(); + if (FAILED(hr)) + throw hr; + } + + buffer_t mpeg_buffer{}; + std::mutex mpeg_mutex; + + void store_mpeg_frame(unsigned char* data, unsigned int len) + { + mpeg_mutex.lock(); + memcpy(mpeg_buffer.start, data, len); + mpeg_buffer.length = len; + mpeg_mutex.unlock(); + } + + void dshow_callback(unsigned char* data, int len, int bitsperpixel) + { + if (bitsperpixel == 24) + { + unsigned char* mpegData = (unsigned char*)calloc(1, 320 * 240 * 2); + int mpegLen = jo_write_mpeg(mpegData, data, 320, 240, JO_RGB24, JO_FLIP_X, JO_FLIP_Y); + store_mpeg_frame(mpegData, mpegLen); + free(mpegData); + } + else + { + fprintf(stderr, "dshow_callback: unk format: len=%d bpp=%d\n", len, bitsperpixel); + } + } + + void create_dummy_frame() + { + const int width = 320; + const int height = 240; + const int bytesPerPixel = 3; + + unsigned char* rgbData = (unsigned char*)calloc(1, width * height * bytesPerPixel); + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + unsigned char* ptr = rgbData + (y * width + x) * bytesPerPixel; + ptr[0] = 255 - y; + ptr[1] = y; + ptr[2] = 255 - y; + } + } + unsigned char* mpegData = (unsigned char*)calloc(1, width * height * bytesPerPixel); + int mpegLen = jo_write_mpeg(mpegData, rgbData, width, height, JO_RGB24, JO_NONE, JO_NONE); + free(rgbData); + + store_mpeg_frame(mpegData, mpegLen); + free(mpegData); + } + + DirectShow::DirectShow(int port) + { + mPort = port; + pGraphBuilder = NULL; + pGraph = NULL; + pControl = NULL; + sourcefilter = NULL; + samplegrabberfilter = NULL; + nullrenderer = NULL; + pSourceConfig = NULL; + samplegrabber = NULL; + callbackhandler = new CallbackHandler(); + CoInitialize(NULL); + } + + int DirectShow::Open() + { + mpeg_buffer.start = calloc(1, 320 * 240 * 2); + create_dummy_frame(); + + std::wstring selectedDevice; + LoadSetting(EyeToyWebCamDevice::TypeName(), Port(), APINAME, N_DEVICE, selectedDevice); + + int ret = InitializeDevice(selectedDevice); + if (ret < 0) + { + fprintf(stderr, "Camera: cannot find '%ls'\n", selectedDevice.c_str()); + return -1; + } + + pControl->Run(); + this->Stop(); + this->SetCallback(dshow_callback); + this->Start(); + + return 0; + }; + + int DirectShow::Close() + { + if (sourcefilter != NULL) + { + this->Stop(); + pControl->Stop(); + + sourcefilter->Release(); + pSourceConfig->Release(); + samplegrabberfilter->Release(); + samplegrabber->Release(); + nullrenderer->Release(); + } + + pGraphBuilder->Release(); + pGraph->Release(); + pControl->Release(); + + if (mpeg_buffer.start != NULL) + { + free(mpeg_buffer.start); + mpeg_buffer.start = NULL; + } + return 0; + }; + + int DirectShow::GetImage(uint8_t* buf, int len) + { + mpeg_mutex.lock(); + int len2 = mpeg_buffer.length; + if (len < mpeg_buffer.length) + len2 = len; + memcpy(buf, mpeg_buffer.start, len2); + mpeg_mutex.unlock(); + return len2; + }; + + BOOL CALLBACK DirectShowDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) + { + int port; + + switch (uMsg) + { + case WM_CREATE: + SetWindowLongPtr(hW, GWLP_USERDATA, (LONG)lParam); + break; + case WM_INITDIALOG: + { + port = (int)lParam; + SetWindowLongPtr(hW, GWLP_USERDATA, (LONG)lParam); std::wstring selectedDevice; - LoadSetting(EyeToyWebCamDevice::TypeName(), Port(), APINAME, N_DEVICE, selectedDevice); + LoadSetting(EyeToyWebCamDevice::TypeName(), port, APINAME, N_DEVICE, selectedDevice); + SendDlgItemMessage(hW, IDC_COMBO1, CB_RESETCONTENT, 0, 0); - int ret = InitializeDevice(selectedDevice); - if (ret < 0) + std::vector devList = getDevList(); + for (auto i = 0; i != devList.size(); i++) { - fprintf(stderr, "Camera: cannot find '%ls'\n", selectedDevice.c_str()); - return -1; - } - - pControl->Run(); - this->Stop(); - this->Start(); - - return 0; - }; - - int DirectShow::Close() - { - if (!sourcefilter) - return 0; - - this->Stop(); - pControl->Stop(); - - sourcefilter->Release(); - pSourceConfig->Release(); - samplegrabberfilter->Release(); - samplegrabber->Release(); - nullrenderer->Release(); - sourcefilter = nullptr; - - pGraphBuilder->Release(); - pGraph->Release(); - pControl->Release(); - - std::lock_guard lck(mpeg_mutex); - mpeg_buffer.resize(0); - return 0; - }; - - int DirectShow::GetImage(uint8_t * buf, int len) - { - std::lock_guard lck(mpeg_mutex); - int len2 = mpeg_buffer.size(); - if (len < mpeg_buffer.size()) - len2 = len; - memcpy(buf, mpeg_buffer.data(), len2); - return len2; - }; - - BOOL CALLBACK DirectShowDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) - { - int port; - - switch (uMsg) - { - case WM_CREATE: - SetWindowLongPtr(hW, GWLP_USERDATA, (LONG)lParam); - break; - case WM_INITDIALOG: + SendDlgItemMessageW(hW, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)devList[i].c_str()); + if (selectedDevice == devList.at(i)) { - port = (int)lParam; - SetWindowLongPtr(hW, GWLP_USERDATA, (LONG)lParam); - - std::wstring selectedDevice; - LoadSetting(EyeToyWebCamDevice::TypeName(), port, APINAME, N_DEVICE, selectedDevice); - SendDlgItemMessage(hW, IDC_COMBO1, CB_RESETCONTENT, 0, 0); - - std::vector devList = getDevList(); - for (auto i = 0; i != devList.size(); i++) - { - SendDlgItemMessageW(hW, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)devList[i].c_str()); - if (selectedDevice == devList.at(i)) - { - SendDlgItemMessage(hW, IDC_COMBO1, CB_SETCURSEL, i, i); - } - } - return TRUE; + SendDlgItemMessage(hW, IDC_COMBO1, CB_SETCURSEL, i, i); } - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED) - { - switch (LOWORD(wParam)) - { - case IDOK: - { - INT_PTR res = RESULT_OK; - static wchar_t selectedDevice[500] = {0}; - GetWindowTextW(GetDlgItem(hW, IDC_COMBO1), selectedDevice, countof(selectedDevice)); - port = (int)GetWindowLongPtr(hW, GWLP_USERDATA); - if (!SaveSetting(EyeToyWebCamDevice::TypeName(), port, APINAME, N_DEVICE, selectedDevice)) - { - res = RESULT_FAILED; - } - EndDialog(hW, res); - return TRUE; - } - case IDCANCEL: - EndDialog(hW, RESULT_CANCELED); - return TRUE; - } - } } - return FALSE; + return TRUE; } + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED) + { + switch (LOWORD(wParam)) + { + case IDOK: + { + INT_PTR res = RESULT_OK; + static wchar_t selectedDevice[500] = {0}; + GetWindowTextW(GetDlgItem(hW, IDC_COMBO1), selectedDevice, countof(selectedDevice)); + port = (int)GetWindowLongPtr(hW, GWLP_USERDATA); + if (!SaveSetting(EyeToyWebCamDevice::TypeName(), port, APINAME, N_DEVICE, selectedDevice)) + { + res = RESULT_FAILED; + } + EndDialog(hW, res); + return TRUE; + } + case IDCANCEL: + EndDialog(hW, RESULT_CANCELED); + return TRUE; + } + } + } + return FALSE; + } - int DirectShow::Configure(int port, const char* dev_type, void* data) - { - Win32Handles handles = *(Win32Handles*)data; - return DialogBoxParam(handles.hInst, - MAKEINTRESOURCE(IDD_DLG_EYETOY), - handles.hWnd, - (DLGPROC)DirectShowDlgProc, port); - }; + int DirectShow::Configure(int port, const char* dev_type, void* data) + { + Win32Handles handles = *(Win32Handles*)data; + return DialogBoxParam(handles.hInst, + MAKEINTRESOURCE(IDD_DLG_EYETOY), + handles.hWnd, + (DLGPROC)DirectShowDlgProc, port); + }; - } // namespace windows_api - } // namespace usb_eyetoy + } // namespace windows_api +} // namespace usb_eyetoy diff --git a/pcsx2/USB/usb-eyetoy/cam-windows.h b/pcsx2/USB/usb-eyetoy/cam-windows.h index 05d6c78a84..b9e3b224cd 100644 --- a/pcsx2/USB/usb-eyetoy/cam-windows.h +++ b/pcsx2/USB/usb-eyetoy/cam-windows.h @@ -28,14 +28,14 @@ extern GUID CLSID_NullRenderer; } #pragma region qedit.h -struct //__declspec(uuid("0579154a-2b53-4994-b0d0-e773148eff85")) +struct __declspec(uuid("0579154a-2b53-4994-b0d0-e773148eff85")) ISampleGrabberCB : IUnknown { virtual HRESULT __stdcall SampleCB(double SampleTime, struct IMediaSample* pSample) = 0; virtual HRESULT __stdcall BufferCB(double SampleTime, unsigned char* pBuffer, long BufferLen) = 0; }; -struct //__declspec(uuid("6b652fff-11fe-4fce-92ad-0266b5d7c78f")) +struct __declspec(uuid("6b652fff-11fe-4fce-92ad-0266b5d7c78f")) ISampleGrabber : IUnknown { virtual HRESULT __stdcall SetOneShot(long OneShot) = 0; @@ -47,8 +47,8 @@ struct //__declspec(uuid("6b652fff-11fe-4fce-92ad-0266b5d7c78f")) virtual HRESULT __stdcall SetCallback(struct ISampleGrabberCB* pCallback, long WhichMethodToCallback) = 0; }; -//struct __declspec(uuid("c1f400a0-3f08-11d3-9f0b-006008039e37")) -// SampleGrabber; +struct __declspec(uuid("c1f400a0-3f08-11d3-9f0b-006008039e37")) + SampleGrabber; #pragma endregion @@ -72,6 +72,12 @@ namespace usb_eyetoy typedef void (*DShowVideoCaptureCallback)(unsigned char* data, int len, int bitsperpixel); + typedef struct + { + void* start = NULL; + size_t length = 0; + } buffer_t; + static const char* APINAME = "DirectShow"; class DirectShow : public VideoDevice @@ -94,12 +100,10 @@ namespace usb_eyetoy void Port(int port) { mPort = port; } protected: + void SetCallback(DShowVideoCaptureCallback cb) { callbackhandler->SetCallback(cb); } void Start(); void Stop(); int InitializeDevice(std::wstring selectedDevice); - void store_mpeg_frame(const std::vector& data); - void create_dummy_frame(); - void dshow_callback(unsigned char* data, int len, int bitsperpixel); private: int mPort; @@ -114,16 +118,10 @@ namespace usb_eyetoy ISampleGrabber* samplegrabber; IBaseFilter* nullrenderer; - std::vector mpeg_buffer{}; - std::mutex mpeg_mutex; - class CallbackHandler : public ISampleGrabberCB { public: - CallbackHandler(DirectShow* parent_) - : parent(parent_) - { - } + CallbackHandler() { callback = 0; } ~CallbackHandler() {} void SetCallback(DShowVideoCaptureCallback cb) { callback = cb; } @@ -135,7 +133,7 @@ namespace usb_eyetoy virtual ULONG __stdcall Release() { return 2; } private: - DirectShow* parent; + DShowVideoCaptureCallback callback; } * callbackhandler; }; diff --git a/pcsx2/USB/usb-eyetoy/jo_mpeg.cpp b/pcsx2/USB/usb-eyetoy/jo_mpeg.cpp index e8bf00a658..bec0394696 100644 --- a/pcsx2/USB/usb-eyetoy/jo_mpeg.cpp +++ b/pcsx2/USB/usb-eyetoy/jo_mpeg.cpp @@ -27,6 +27,7 @@ * http://www.cs.cornell.edu/dali/api/mpegvideo-c.html * */ +#include "PrecompiledHeader.h" #include #include #include diff --git a/pcsx2/USB/usb-eyetoy/jpgd/jpgd.cpp b/pcsx2/USB/usb-eyetoy/jpgd/jpgd.cpp index f27767d293..849de47b04 100644 --- a/pcsx2/USB/usb-eyetoy/jpgd/jpgd.cpp +++ b/pcsx2/USB/usb-eyetoy/jpgd/jpgd.cpp @@ -26,6 +26,8 @@ // Important: // #define JPGD_USE_SSE2 to 0 to completely disable SSE2 usage. // + +#include "PrecompiledHeader.h" #include "jpgd.h" #include #include diff --git a/pcsx2/USB/usb-eyetoy/usb-eyetoy-webcam.cpp b/pcsx2/USB/usb-eyetoy/usb-eyetoy-webcam.cpp index d0262f9a1f..bcf3b10757 100644 --- a/pcsx2/USB/usb-eyetoy/usb-eyetoy-webcam.cpp +++ b/pcsx2/USB/usb-eyetoy/usb-eyetoy-webcam.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "videodeviceproxy.h" #include "../osdebugout.h" #include "usb-eyetoy-webcam.h" diff --git a/pcsx2/USB/usb-hid/api_init_win32.cpp b/pcsx2/USB/usb-hid/api_init_win32.cpp index 4c313cc683..3894519d8f 100644 --- a/pcsx2/USB/usb-hid/api_init_win32.cpp +++ b/pcsx2/USB/usb-hid/api_init_win32.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "hidproxy.h" #include "raw/rawinput.h" #include "noop.h" diff --git a/pcsx2/USB/usb-hid/raw/rawinput.cpp b/pcsx2/USB/usb-hid/raw/rawinput.cpp index 14517f4334..9fb49b547d 100644 --- a/pcsx2/USB/usb-hid/raw/rawinput.cpp +++ b/pcsx2/USB/usb-hid/raw/rawinput.cpp @@ -13,10 +13,11 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "rawinput.h" #include "../../Win32/Config.h" -#include "qemu-usb/input-keymap.h" -#include "qemu-usb/input-keymap-win32-to-qcode.h" +#include "../../qemu-usb/input-keymap.h" +#include "../../qemu-usb/input-keymap-win32-to-qcode.h" namespace usb_hid { diff --git a/pcsx2/USB/usb-hid/raw/rawinput.h b/pcsx2/USB/usb-hid/raw/rawinput.h index 3c8f2f1099..94df323116 100644 --- a/pcsx2/USB/usb-hid/raw/rawinput.h +++ b/pcsx2/USB/usb-hid/raw/rawinput.h @@ -13,7 +13,7 @@ * If not, see . */ -#include "shared/rawinput.h" +#include "../../shared/rawinput.h" #include "../hidproxy.h" #include "../usb-hid.h" diff --git a/pcsx2/USB/usb-hid/usb-hid.cpp b/pcsx2/USB/usb-hid/usb-hid.cpp index ca8316bc73..df1ca9cca3 100644 --- a/pcsx2/USB/usb-hid/usb-hid.cpp +++ b/pcsx2/USB/usb-hid/usb-hid.cpp @@ -22,6 +22,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "PrecompiledHeader.h" #include "../deviceproxy.h" #include "hidproxy.h" #include "../qemu-usb/desc.h" diff --git a/pcsx2/USB/usb-mic/api_init_win32.cpp b/pcsx2/USB/usb-mic/api_init_win32.cpp index 099984d375..87dc7a0214 100644 --- a/pcsx2/USB/usb-mic/api_init_win32.cpp +++ b/pcsx2/USB/usb-mic/api_init_win32.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "audiodeviceproxy.h" #include "audiodev-noop.h" #include "audiodev-wasapi.h" diff --git a/pcsx2/USB/usb-mic/audiodev-wasapi.cpp b/pcsx2/USB/usb-mic/audiodev-wasapi.cpp index af9b89797a..34080bbb03 100644 --- a/pcsx2/USB/usb-mic/audiodev-wasapi.cpp +++ b/pcsx2/USB/usb-mic/audiodev-wasapi.cpp @@ -15,6 +15,7 @@ // Used OBS as example +#include "PrecompiledHeader.h" #include #include #include diff --git a/pcsx2/USB/usb-mic/audiodev-wasapi.h b/pcsx2/USB/usb-mic/audiodev-wasapi.h index 31273a2eeb..8af3cacee0 100644 --- a/pcsx2/USB/usb-mic/audiodev-wasapi.h +++ b/pcsx2/USB/usb-mic/audiodev-wasapi.h @@ -17,7 +17,7 @@ #include "audiodeviceproxy.h" #include "../libsamplerate/samplerate.h" -#include "shared/ringbuffer.h" +#include "../shared/ringbuffer.h" #include #include diff --git a/pcsx2/USB/usb-mic/usb-headset.cpp b/pcsx2/USB/usb-mic/usb-headset.cpp index 6a9c544858..a9f81af944 100644 --- a/pcsx2/USB/usb-mic/usb-headset.cpp +++ b/pcsx2/USB/usb-mic/usb-headset.cpp @@ -24,6 +24,7 @@ // Most stuff is based on Qemu 1.7 USB soundcard passthrough code. +#include "PrecompiledHeader.h" #include "../qemu-usb/vl.h" #include "../qemu-usb/desc.h" #include @@ -666,6 +667,7 @@ namespace usb_mic int length, uint8_t* data) { uint8_t cs = cscn >> 8; + uint8_t cn = cscn - 1; /* -1 for the non-present master control */ uint32_t aid = ATTRIB_ID(cs, attrib, ep); int ret = USB_RET_STALL; diff --git a/pcsx2/USB/usb-mic/usb-mic-logitech.cpp b/pcsx2/USB/usb-mic/usb-mic-logitech.cpp index 42a17324be..a0297c02a4 100644 --- a/pcsx2/USB/usb-mic/usb-mic-logitech.cpp +++ b/pcsx2/USB/usb-mic/usb-mic-logitech.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "usb-mic-singstar.h" #include "audio.h" #include "../qemu-usb/desc.h" diff --git a/pcsx2/USB/usb-mic/usb-mic-singstar.cpp b/pcsx2/USB/usb-mic/usb-mic-singstar.cpp index 0c08357a0a..5f69fd7ee2 100644 --- a/pcsx2/USB/usb-mic/usb-mic-singstar.cpp +++ b/pcsx2/USB/usb-mic/usb-mic-singstar.cpp @@ -24,6 +24,7 @@ // Most stuff is based on Qemu 1.7 USB soundcard passthrough code. +#include "PrecompiledHeader.h" #include "../qemu-usb/vl.h" #include "../qemu-usb/desc.h" #include "usb-mic-singstar.h" diff --git a/pcsx2/USB/usb-msd/usb-msd-win32.cpp b/pcsx2/USB/usb-msd/usb-msd-win32.cpp index 009649f42d..42e08acc26 100644 --- a/pcsx2/USB/usb-msd/usb-msd-win32.cpp +++ b/pcsx2/USB/usb-msd/usb-msd-win32.cpp @@ -13,6 +13,8 @@ * If not, see . */ +#include "PrecompiledHeader.h" +#include #include "usb-msd.h" #include "../Win32/Config.h" #include "../Win32/resource.h" diff --git a/pcsx2/USB/usb-msd/usb-msd.cpp b/pcsx2/USB/usb-msd/usb-msd.cpp index f2f1e4d583..64f84c5b23 100644 --- a/pcsx2/USB/usb-msd/usb-msd.cpp +++ b/pcsx2/USB/usb-msd/usb-msd.cpp @@ -7,6 +7,7 @@ * This code is licenced under the LGPL. */ +#include "PrecompiledHeader.h" #include #include #include diff --git a/pcsx2/USB/usb-pad/api_init_win32.cpp b/pcsx2/USB/usb-pad/api_init_win32.cpp index 17e20d5033..4f3eb5d285 100644 --- a/pcsx2/USB/usb-pad/api_init_win32.cpp +++ b/pcsx2/USB/usb-pad/api_init_win32.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "padproxy.h" #include "raw/usb-pad-raw.h" #include "dx/usb-pad-dx.h" diff --git a/pcsx2/USB/usb-pad/dx/dinput-config.cpp b/pcsx2/USB/usb-pad/dx/dinput-config.cpp index c139656b05..e0d0376007 100644 --- a/pcsx2/USB/usb-pad/dx/dinput-config.cpp +++ b/pcsx2/USB/usb-pad/dx/dinput-config.cpp @@ -13,6 +13,8 @@ * If not, see . */ +#include "PrecompiledHeader.h" + #pragma warning(push) // floats to int #pragma warning(disable : 4244) diff --git a/pcsx2/USB/usb-pad/dx/dinput.cpp b/pcsx2/USB/usb-pad/dx/dinput.cpp index a8c72c7c3d..cb7ebfbf86 100644 --- a/pcsx2/USB/usb-pad/dx/dinput.cpp +++ b/pcsx2/USB/usb-pad/dx/dinput.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include #include "dx.h" diff --git a/pcsx2/USB/usb-pad/dx/dx.h b/pcsx2/USB/usb-pad/dx/dx.h index 3972183762..f6e87048a0 100644 --- a/pcsx2/USB/usb-pad/dx/dx.h +++ b/pcsx2/USB/usb-pad/dx/dx.h @@ -29,7 +29,7 @@ #include "../usb-pad.h" #include "../../configuration.h" #include "../../osdebugout.h" -#include "usb-pad/lg/lg_ff.h" +#include "../../usb-pad/lg/lg_ff.h" #define DINPUT_AXES_COUNT 32 diff --git a/pcsx2/USB/usb-pad/dx/usb-pad-dx.cpp b/pcsx2/USB/usb-pad/dx/usb-pad-dx.cpp index 4869728817..a5c59b165b 100644 --- a/pcsx2/USB/usb-pad/dx/usb-pad-dx.cpp +++ b/pcsx2/USB/usb-pad/dx/usb-pad-dx.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "usb-pad-dx.h" #include "dx.h" #include diff --git a/pcsx2/USB/usb-pad/lg/lg_ff.cpp b/pcsx2/USB/usb-pad/lg/lg_ff.cpp index 6a63bba145..7b1789ec45 100644 --- a/pcsx2/USB/usb-pad/lg/lg_ff.cpp +++ b/pcsx2/USB/usb-pad/lg/lg_ff.cpp @@ -3,6 +3,7 @@ License: GPLv3 */ +#include "PrecompiledHeader.h" #include "lg_ff.h" typedef struct diff --git a/pcsx2/USB/usb-pad/raw/raw-config.cpp b/pcsx2/USB/usb-pad/raw/raw-config.cpp index 1e9870c69e..2e4759df12 100644 --- a/pcsx2/USB/usb-pad/raw/raw-config.cpp +++ b/pcsx2/USB/usb-pad/raw/raw-config.cpp @@ -13,6 +13,8 @@ * If not, see . */ +#include "PrecompiledHeader.h" + #define _WIN32_WINNT 0x0502 #include #include diff --git a/pcsx2/USB/usb-pad/raw/usb-pad-raw.cpp b/pcsx2/USB/usb-pad/raw/usb-pad-raw.cpp index 5763025b63..119f33536a 100644 --- a/pcsx2/USB/usb-pad/raw/usb-pad-raw.cpp +++ b/pcsx2/USB/usb-pad/raw/usb-pad-raw.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "../../USB.h" #include "../../Win32/Config.h" #include "usb-pad-raw.h" diff --git a/pcsx2/USB/usb-pad/raw/usb-pad-raw.h b/pcsx2/USB/usb-pad/raw/usb-pad-raw.h index 4cf2915d68..bdc556b4d3 100644 --- a/pcsx2/USB/usb-pad/raw/usb-pad-raw.h +++ b/pcsx2/USB/usb-pad/raw/usb-pad-raw.h @@ -20,8 +20,8 @@ #include #include "../padproxy.h" #include "../usb-pad.h" -#include "shared/rawinput.h" -#include "readerwriterqueue/readerwriterqueue.h" +#include "../../shared/rawinput.h" +#include "../../readerwriterqueue/readerwriterqueue.h" namespace usb_pad { diff --git a/pcsx2/USB/usb-pad/usb-pad-ff.cpp b/pcsx2/USB/usb-pad/usb-pad-ff.cpp index d5c0a9ade6..60abe9bf97 100644 --- a/pcsx2/USB/usb-pad/usb-pad-ff.cpp +++ b/pcsx2/USB/usb-pad/usb-pad-ff.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "usb-pad.h" #include "lg/lg_ff.h" #include "../osdebugout.h" diff --git a/pcsx2/USB/usb-pad/usb-pad.cpp b/pcsx2/USB/usb-pad/usb-pad.cpp index 07b728d46f..a056fa04e4 100644 --- a/pcsx2/USB/usb-pad/usb-pad.cpp +++ b/pcsx2/USB/usb-pad/usb-pad.cpp @@ -13,6 +13,7 @@ * If not, see . */ +#include "PrecompiledHeader.h" #include "padproxy.h" #include "usb-pad.h" #include "../qemu-usb/desc.h" diff --git a/pcsx2/USB/usb-pad/usb-seamic.cpp b/pcsx2/USB/usb-pad/usb-seamic.cpp index 1a58a4efd1..da6fd8ad1c 100644 --- a/pcsx2/USB/usb-pad/usb-seamic.cpp +++ b/pcsx2/USB/usb-pad/usb-seamic.cpp @@ -1,3 +1,19 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2020 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#include "PrecompiledHeader.h" #include "padproxy.h" #include "usb-pad.h" #include "../qemu-usb/desc.h"