From fc277224fd32d2dbef86d98c05fcbaa38c2c3573 Mon Sep 17 00:00:00 2001 From: Lynn Jarvis Date: Mon, 12 Oct 2020 16:23:29 +1030 Subject: [PATCH] Version 2.020 CreateInstance - SetProcessDPIAware() for clear options dialog put_Settings simplify code for flags Introduce ReleaseCamReceiver() Remove connect/disconnect test Showstatic if user and filter resolutions are different Update verison.h - Version 2.020 --- source/cam.cpp | 133 ++++++++++++++++++++++---------------------- source/cam.h | 2 +- source/camprops.cpp | 17 +++++- source/version.h | 2 +- 4 files changed, 82 insertions(+), 72 deletions(-) diff --git a/source/cam.cpp b/source/cam.cpp index 82d25be..8631ebe 100644 --- a/source/cam.cpp +++ b/source/cam.cpp @@ -245,6 +245,13 @@ Verson 2.018 09.10.20 Valentin Schmidt: added Mirror/Flip/Swap options to dialog Verson 2.019 + 12.10.20 CVCam::CreateInstance - SetProcessDPIAware() for clear options dialog + put_Settings simplify code for flags + Introduce ReleaseCamReceiver() + Remove connect/disconnect test + Showstatic if user and filter resolutions are different + Update verison.h - Version 2.020 + */ #pragma warning(disable:4244) @@ -283,6 +290,9 @@ CUnknown * WINAPI CVCam::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) // EnableSpoutLog(); // Show error logs // printf("SpoutCamDX ~~ Vers 2.017\n"); + // For clear options dialog for scaled display + SetProcessDPIAware(); + CUnknown *punk = new CVCam(lpunk, phr); return punk; @@ -483,21 +493,9 @@ HRESULT CVCamStream::put_Settings(DWORD dwFps, DWORD dwResolution, DWORD dwMirro SetFps(dwFps); SetResolution(dwResolution); - - if (dwMirror > 0) - receiver.m_bMirror = true; - else - receiver.m_bMirror = false; - - if (dwSwap > 0) - receiver.m_bSwapRB = true; - else - receiver.m_bSwapRB = false; - - if (dwFlip > 0) - bInvert = false; - else - bInvert = true; + receiver.m_bMirror = (dwMirror > 0); + receiver.m_bSwapRB = (dwSwap > 0); + bInvert = (dwFlip > 0); return GetMediaType(0, &m_mt); } @@ -818,65 +816,56 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms) if(width == 0 || height == 0) return NOERROR; - // Don't do anything if disconnected because it will already have connected - // previously and something has changed. It can only disconnect after it has connected. - if(!bDisconnected) { - // If connected, sizes should be OK, but check again - unsigned int size = (unsigned int)pms->GetSize(); - imagesize = width*height*3; // Retrieved above - if(size != imagesize) { - receiver.ReleaseReceiver(); - bDisconnected = true; // don't try again - return NOERROR; - } + // Sizes should be OK, but check again + unsigned int size = (unsigned int)pms->GetSize(); + imagesize = width*height*3; // Retrieved above + if(size != imagesize) { + ReleaseCamReceiver(); + goto ShowStatic; + } - // Quit if nothing running at all - if(!receiver.GetActiveSender(g_ActiveSender)) { - receiver.ReleaseReceiver(); - goto ShowStatic; - } + // Quit if nothing running at all + if(!receiver.GetActiveSender(g_ActiveSender)) { + ReleaseCamReceiver(); + goto ShowStatic; + } - // Initialize DirectX if is has not been done - if(!bDXinitialized) { - if (receiver.OpenDirectX11()) { - g_pd3dDevice = receiver.GetDevice(); - } - else { - bDXinitialized = false; - bDisconnected = true; // don't try again - return NOERROR; - } - } // endif !bDXinitialized - bDXinitialized = true; - - // Get bgr pixels from the sender bgra shared texture - // ReceiveImage handles sender detection, connection and copy of pixels - if (receiver.ReceiveImage(pData, g_Width, g_Height, true, bInvert)) { - // rgb(not rgba) = true, invert = true - // If IsUpdated() returns true, the sender has changed - if (receiver.IsUpdated()) { - if (strcmp(g_SenderName, receiver.GetSenderName()) != 0) { - // Only test for change of sender name. - // The pixel buffer (pData) remains the same size and - // ReceiveImage uses resampling for a different texture size - strcpy_s(g_SenderName, 256, receiver.GetSenderName()); - // Set the sender name to the registry for SpoutCamSettings - WritePathToRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "sendername", g_SenderName); - } - } - bInitialized = true; - NumFrames++; - return NOERROR; + // Initialize DirectX if is has not been done + if(!bDXinitialized) { + if (receiver.OpenDirectX11()) { + g_pd3dDevice = receiver.GetDevice(); + bDXinitialized = true; } else { - if (bInitialized) { - receiver.ReleaseReceiver(); - bInitialized = false; - } + bDXinitialized = false; + return NOERROR; } + } // endif !bDXinitialized + - } // endif not disconnected + // Get bgr pixels from the sender bgra shared texture + // ReceiveImage handles sender detection, connection and copy of pixels + if (receiver.ReceiveImage(pData, g_Width, g_Height, true, bInvert)) { + // rgb(not rgba) = true, invert = true + // If IsUpdated() returns true, the sender has changed + if (receiver.IsUpdated()) { + if (strcmp(g_SenderName, receiver.GetSenderName()) != 0) { + // Only test for change of sender name. + // The pixel buffer (pData) remains the same size and + // ReceiveImage uses resampling for a different texture size + strcpy_s(g_SenderName, 256, receiver.GetSenderName()); + // Set the sender name to the registry for SpoutCamSettings + WritePathToRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "sendername", g_SenderName); + } + } + bInitialized = true; + NumFrames++; + return NOERROR; + } + else { + ReleaseCamReceiver(); + } ShowStatic : @@ -893,6 +882,16 @@ ShowStatic : } // FillBuffer +// Conditionally release receiver and reset flag +void CVCamStream::ReleaseCamReceiver() +{ + if (bInitialized) { + receiver.ReleaseReceiver(); + bInitialized = false; + } +} + + // // Notify // Ignore quality management messages sent from the downstream filter diff --git a/source/cam.h b/source/cam.h index cc58aea..4482634 100644 --- a/source/cam.h +++ b/source/cam.h @@ -201,9 +201,9 @@ class CVCamStream : public CSourceStream, public IAMStreamConfig, public IKsProp bool m_bLock; HRESULT put_Settings(DWORD dwFps, DWORD dwResolution, DWORD dwMirror, DWORD dwSwap, DWORD dwFlip); //VS - void SetFps(DWORD dwFps); void SetResolution(DWORD dwResolution); + void ReleaseCamReceiver(); // ============== IPC functions ============== // diff --git a/source/camprops.cpp b/source/camprops.cpp index cb204f3..a1dc0dd 100644 --- a/source/camprops.cpp +++ b/source/camprops.cpp @@ -228,12 +228,23 @@ HRESULT CSpoutCamProperties::OnApplyChanges() HWND hwndCtl; DWORD dwFps, dwResolution, dwMirror, dwSwap, dwFlip; - hwndCtl = GetDlgItem(this->m_Dlg, IDC_FPS); + // Get old fps and resolution for user warning + DWORD dwOldFps, dwOldResolution; + ReadDwordFromRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "fps", &dwOldFps); + ReadDwordFromRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "resolution", &dwOldResolution); dwFps = ComboBox_GetCurSel(hwndCtl); + dwResolution = ComboBox_GetCurSel(hwndCtl); + if (dwOldFps != dwFps || dwOldResolution != dwResolution) { + if (MessageBoxA(NULL, "For change of resolution or fps\nyou have to stop and re-start SpoutCam\nDo you want to change ? ", "Warning", MB_YESNO | MB_TOPMOST | MB_ICONQUESTION) == IDNO) + return -1; + } + + + + hwndCtl = GetDlgItem(this->m_Dlg, IDC_FPS); WriteDwordToRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "fps", dwFps); hwndCtl = GetDlgItem(this->m_Dlg, IDC_RESOLUTION); - dwResolution = ComboBox_GetCurSel(hwndCtl); WriteDwordToRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "resolution", dwResolution); hwndCtl = GetDlgItem(this->m_Dlg, IDC_MIRROR); @@ -247,7 +258,7 @@ HRESULT CSpoutCamProperties::OnApplyChanges() hwndCtl = GetDlgItem(this->m_Dlg, IDC_FLIP); dwFlip = Button_GetCheck(hwndCtl); WriteDwordToRegistry(HKEY_CURRENT_USER, "Software\\Leading Edge\\SpoutCam", "flip", dwFlip); - + if (m_pCamSettings) m_pCamSettings->put_Settings(dwFps, dwResolution, dwMirror, dwSwap, dwFlip); diff --git a/source/version.h b/source/version.h index e81933c..618e43d 100644 --- a/source/version.h +++ b/source/version.h @@ -9,7 +9,7 @@ #define _VER_MAJORVERSION_STRING "2" #define _VER_MINORVERSION 1 -#define _VER_MINORVERSION_STRING "018" +#define _VER_MINORVERSION_STRING "020" #define _VER_BUGFIXVERSION 0 #define _VER_BUGFIXVERSION_STRING "0"