Skip to content

Commit

Permalink
Version 2.020
Browse files Browse the repository at this point in the history
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
  • Loading branch information
leadedge committed Oct 12, 2020
1 parent b15f07f commit fc27722
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 72 deletions.
133 changes: 66 additions & 67 deletions source/cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 :

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/cam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==============
//
Expand Down
17 changes: 14 additions & 3 deletions source/camprops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion source/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fc27722

Please sign in to comment.