Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Spectator view dynamic camera config (load video frame settings at runtime) #286

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.TMP
# git ignore file
AppPackages/
BundleArtifacts/
Expand Down
14 changes: 10 additions & 4 deletions SpectatorView/Calibration/Calibration.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Calibration", "Calibration\Calibration.vcxproj", "{70239410-43FF-4F2B-ACBB-E640437F7289}"
ProjectSection(ProjectDependencies) = postProject
{16FA1D9F-8C62-4A94-9A47-EE2E153DC625} = {16FA1D9F-8C62-4A94-9A47-EE2E153DC625}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA8BAF72-3FE7-4F0C-B0E0-0C53C4CB5CD5}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -12,24 +15,27 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharedHeaders", "..\Compositor\SharedHeaders\SharedHeaders.vcxitems", "{0C2DFF51-C769-460F-B9D6-05C82FC60F56}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompositorDLL", "..\Compositor\CompositorDLL\CompositorDLL.vcxproj", "{16FA1D9F-8C62-4A94-9A47-EE2E153DC625}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\Compositor\SharedHeaders\SharedHeaders.vcxitems*{0c2dff51-c769-460f-b9d6-05c82fc60f56}*SharedItemsImports = 9
..\Compositor\SharedHeaders\SharedHeaders.vcxitems*{16fa1d9f-8c62-4a94-9a47-ee2e153dc625}*SharedItemsImports = 4
..\Compositor\SharedHeaders\SharedHeaders.vcxitems*{70239410-43ff-4f2b-acbb-e640437f7289}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{70239410-43FF-4F2B-ACBB-E640437F7289}.Debug|x64.ActiveCfg = Debug|x64
{70239410-43FF-4F2B-ACBB-E640437F7289}.Debug|x64.Build.0 = Debug|x64
{70239410-43FF-4F2B-ACBB-E640437F7289}.Debug|x86.ActiveCfg = Release|x64
{70239410-43FF-4F2B-ACBB-E640437F7289}.Release|x64.ActiveCfg = Release|x64
{70239410-43FF-4F2B-ACBB-E640437F7289}.Release|x64.Build.0 = Release|x64
{70239410-43FF-4F2B-ACBB-E640437F7289}.Release|x86.ActiveCfg = Release|x64
{16FA1D9F-8C62-4A94-9A47-EE2E153DC625}.Debug|x64.ActiveCfg = Debug|x64
{16FA1D9F-8C62-4A94-9A47-EE2E153DC625}.Debug|x64.Build.0 = Debug|x64
{16FA1D9F-8C62-4A94-9A47-EE2E153DC625}.Release|x64.ActiveCfg = Release|x64
{16FA1D9F-8C62-4A94-9A47-EE2E153DC625}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 6 additions & 4 deletions SpectatorView/Calibration/Calibration/Calibration.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@
<Link>
<SubSystem>NotSet</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d3d11.lib;dxgi.lib;dxguid.lib;uuid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;odbc32.lib;odbccp32.lib;</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)\</AdditionalLibraryDirectories>
<AdditionalDependencies>d3d11.lib;dxgi.lib;dxguid.lib;uuid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;odbc32.lib;odbccp32.lib;CompositorDLL.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)\;$(ProjectDir)\..\..\Compositor\x64\$(Configuration)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>xcopy /y "$(OpenCV_vc14)\bin\*.dll" "$(OutDir)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>if EXIST "$(decklink_inc)" xcopy /y "$(decklink_inc)"
xcopy /y "$(OpenCV_vc14)\bin\*.dll"
xcopy /y "$(ProjectDir)\..\..\Compositor\x64\$(Configuration)\CompositorDLL.dll"
if EXIST "$(Elgato_Filter)" xcopy /y "$(Elgato_Filter)" ..\..\Compositor\CompositorDLL\</Command>
</PreBuildEvent>
<PreLinkEvent>
Expand Down Expand Up @@ -117,15 +118,16 @@ if EXIST "$(Elgato_Filter)" xcopy /y "$(Elgato_Filter)" ..\..\Compositor\Composi
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>d3d11.lib;dxgi.lib;dxguid.lib;uuid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;odbc32.lib;odbccp32.lib;</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)\</AdditionalLibraryDirectories>
<AdditionalDependencies>d3d11.lib;dxgi.lib;dxguid.lib;uuid.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;odbc32.lib;odbccp32.lib;CompositorDLL.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)\;$(ProjectDir)\..\..\Compositor\x64\$(Configuration)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>xcopy /y "$(OpenCV_vc14)\bin\*.dll" "$(OutDir)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>if EXIST "$(decklink_inc)" xcopy /y "$(decklink_inc)"
xcopy /y "$(OpenCV_vc14)\bin\*.dll"
xcopy /y "$(ProjectDir)\..\..\Compositor\x64\$(Configuration)\CompositorDLL.dll"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This xcopy can fail if the calibration app is built before the compositor.

You have added the CompositorDLL project to the Calibration sln, so you should instead right click on the References under the calibration project and add CompositorDLL as a reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to go to bed now, so I'll look into your remarks tomorow (I'm in france).

Project is set to depend on CompositorDLL on that solution, so it should be built after. (maybe I forgot to commit the changes in the SLN file)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calibration SLN contains a ref to the compositor project, and it's set as a build dependency. Visual Studio will always build them in the right order. So the DLL will always be available to copy.

image
image

if EXIST "$(Elgato_Filter)" xcopy /y "$(Elgato_Filter)" ..\..\Compositor\CompositorDLL\</Command>
</PreBuildEvent>
<PreLinkEvent>
Expand Down
26 changes: 13 additions & 13 deletions SpectatorView/Calibration/Calibration/CalibrationApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CalibrationApp::CalibrationApp() :
InitializeCriticalSection(&calibrationPictureCriticalSection);

boardDimensions = cv::Size(GRID_CELLS_X - 1, GRID_CELLS_Y - 1);
colorBytes = new BYTE[FRAME_BUFSIZE];
colorBytes = new BYTE[FrameProviderStaticConfig::getFrameBuffSize()];

// Force 60fps
timer.SetFixedTimeStep(true);
Expand Down Expand Up @@ -79,11 +79,11 @@ void CalibrationApp::Initialize(HWND window, int width, int height)
CreateWindowSizeDependentResources();

// Calibration Images.
colorImage_cam = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, CV_8UC4);
colorImage_cam = cv::Mat(FrameProviderStaticConfig::height, FrameProviderStaticConfig::width, CV_8UC4);
resizedColorImage_cam = cv::Mat(HOLO_HEIGHT, HOLO_WIDTH, CV_8UC4);
colorImage_holo = cv::Mat(HOLO_HEIGHT, HOLO_WIDTH, CV_8UC4);
latestColorMat = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, CV_8UC4);
cachedColorMat = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, CV_8UC4);
latestColorMat = cv::Mat(FrameProviderStaticConfig::height, FrameProviderStaticConfig::width, CV_8UC4);
cachedColorMat = cv::Mat(FrameProviderStaticConfig::height, FrameProviderStaticConfig::width, CV_8UC4);

// Create an http_client to use REST APIs on the Hololens.
http_client_config client_config;
Expand All @@ -97,7 +97,7 @@ void CalibrationApp::Initialize(HWND window, int width, int height)

// Create textures, RT's and SRV's
auto device = deviceResources->GetD3DDevice();
CD3D11_TEXTURE2D_DESC rtDesc(DXGI_FORMAT_R8G8B8A8_UNORM, FRAME_WIDTH, FRAME_HEIGHT,
CD3D11_TEXTURE2D_DESC rtDesc(DXGI_FORMAT_R8G8B8A8_UNORM, FrameProviderStaticConfig::width, FrameProviderStaticConfig::height,
1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);

device->CreateTexture2D(&rtDesc, nullptr, &colorTexture);
Expand Down Expand Up @@ -134,8 +134,8 @@ void CalibrationApp::Initialize(HWND window, int width, int height)
}
}

yuv2rgbParameters.width = FRAME_WIDTH;
yuv2rgbParameters.height = FRAME_HEIGHT;
yuv2rgbParameters.width = FrameProviderStaticConfig::width;
yuv2rgbParameters.height = FrameProviderStaticConfig::height;

CD3D11_BUFFER_DESC cbDesc(sizeof(CONVERSION_PARAMETERS), D3D11_BIND_CONSTANT_BUFFER);
device->CreateBuffer(&cbDesc, nullptr, conversionParamBuffer.ReleaseAndGetAddressOf());
Expand Down Expand Up @@ -218,7 +218,7 @@ void CalibrationApp::TakeCalibrationPicture()

// Cache the latest color frame so we do not stall the UI thread while checking if there is a chess board in frame.
EnterCriticalSection(&photoTextureCriticalSection);
memcpy(cachedColorMat.data, latestColorMat.data, FRAME_BUFSIZE);
memcpy(cachedColorMat.data, latestColorMat.data, FrameProviderStaticConfig::getFrameBuffSize());
LeaveCriticalSection(&photoTextureCriticalSection);

if (!HasChessBoard(cachedColorMat, grayscaleImage, corners))
Expand All @@ -232,7 +232,7 @@ void CalibrationApp::TakeCalibrationPicture()

// Lock the latest camera image immediately after the hololens picture has been taken.
EnterCriticalSection(&photoTextureCriticalSection);
memcpy(cachedColorMat.data, latestColorMat.data, FRAME_BUFSIZE);
memcpy(cachedColorMat.data, latestColorMat.data, FrameProviderStaticConfig::getFrameBuffSize());
LeaveCriticalSection(&photoTextureCriticalSection);

cv::imwrite(cv::String(StringHelper::ws2s(camPath)), cachedColorMat);
Expand Down Expand Up @@ -653,8 +653,8 @@ void CalibrationApp::OnWindowSizeChanged(int width, int height)
// Properties
void CalibrationApp::GetDefaultSize(int& width, int& height) const
{
width = FRAME_WIDTH;
height = FRAME_HEIGHT;
width = FrameProviderStaticConfig::width;
height = FrameProviderStaticConfig::height;
}

// These are the resources that depend on the device.
Expand All @@ -667,8 +667,8 @@ void CalibrationApp::CreateDeviceDependentResources()
// Camera
colorSourceRect.left = 0;
colorSourceRect.top = 0;
colorSourceRect.right = FRAME_WIDTH;
colorSourceRect.bottom = FRAME_HEIGHT;
colorSourceRect.right = FrameProviderStaticConfig::width;
colorSourceRect.bottom = FrameProviderStaticConfig::height;

auto device = deviceResources->GetD3DDevice();
auto blob = DX::ReadData(L"YUV2RGB.cso");
Expand Down
5 changes: 3 additions & 2 deletions SpectatorView/Calibration/Calibration/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "stdafx.h"
#include "DeviceResources.h"
#include "FrameProviderStaticConfig.h"

using namespace DirectX;

Expand Down Expand Up @@ -226,8 +227,8 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()

// Determine the render target size in pixels.
// Force backbuffer to captured image dimensions.
UINT backBufferWidth = FRAME_WIDTH;// std::max<UINT>(m_outputSize.right - m_outputSize.left, 1);
UINT backBufferHeight = FRAME_HEIGHT;// std::max<UINT>(m_outputSize.bottom - m_outputSize.top, 1);
UINT backBufferWidth = FrameProviderStaticConfig::width;// std::max<UINT>(m_outputSize.right - m_outputSize.left, 1);
UINT backBufferHeight = FrameProviderStaticConfig::height;// std::max<UINT>(m_outputSize.bottom - m_outputSize.top, 1);

if (m_swapChain)
{
Expand Down
29 changes: 29 additions & 0 deletions SpectatorView/Calibration/Calibration/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include "stdafx.h"
#include "CalibrationApp.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look in CalibrationApp.cpp, there are a few cv::Mat's still using FRAME_WIDTH, FRAME_HEIGHT, and FRAME_BUFSIZE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix that and ping you when fixed later friday 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


#define CAMERA_CFG_STATIC_IMPL
#include "CameraConfigurationFile.h"

#include <string>
using namespace std::string_literals;
using namespace DirectX;

namespace
Expand All @@ -16,6 +21,30 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// Entry point
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{

auto const filePath = CameraConfigurationFile::getMyDocumentPath() + "\\camera.cfg"s;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the config file read for the UnityCompositorDLL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"current user's document folder"\camera.cfg

Right next of where the calibration files and the holograms capture folders are. Since the user will be messing around with files in "My documents", why not putting it here.

Relative path would be from the current process, here when the DLL is loaded it's the Unity editor, so using an user's folder is the best solution I think.

CameraConfigurationFile::getMyDocumentPath() return the path to the user's "document" folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you mean, it's on the plugin load callback, before everything else is done

Copy link
Contributor Author

@Ybalrid Ybalrid Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
	try
	{
		const auto configFilePath = CameraConfigurationFile::getMyDocumentPath() + "\\camera.cfg";
		CameraConfigurationFile configFile(configFilePath);
		configFile.readConfig();

		FrameProviderStaticConfig::width = int(configFile.getWidth());
		FrameProviderStaticConfig::height = int(configFile.getHeight());
		FrameProviderStaticConfig::fps = float(configFile.getFrameRate());
	}
	catch(std::exception& e)
	{
		(void)e;
		//Will just use the hardcoded values

		FrameProviderStaticConfig::width = FRAME_HEIGHT;
		FrameProviderStaticConfig::height = FRAME_WIDTH;
		FrameProviderStaticConfig::fps = VIDEO_FPS;
	}
        //[...]
}

in UnityCompositorInterface.cpp, line 568


OutputDebugStringA(filePath.c_str());

try
{
CameraConfigurationFile cfg(filePath);
cfg.readConfig();

FrameProviderStaticConfig::width = int(cfg.getWidth());
FrameProviderStaticConfig::height = int(cfg.getHeight());
FrameProviderStaticConfig::fps = float(cfg.getFrameRate());
}
catch(const std::exception& e)
{
OutputDebugStringA(e.what());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a fallback to the previously defined constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statics are initialized with the values in the header. but now that I look at it, if the file is missformed ( = has width, but not height); it may leave the thing broken.

I should reset the original values in the catch{} scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


//fallback to default values
FrameProviderStaticConfig::width = FRAME_WIDTH;
FrameProviderStaticConfig::height = FRAME_HEIGHT;
FrameProviderStaticConfig::fps = VIDEO_FPS;
}

UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

Expand Down
Binary file modified SpectatorView/Compositor/CompositorDLL/CompositorDLL.cpp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "stdafx.h"
#include "CompositorInterface.h"
#include "FrameProviderStaticConfig.h"


CompositorInterface::CompositorInterface()
Expand Down Expand Up @@ -172,7 +173,7 @@ void CompositorInterface::TakePicture(ID3D11Texture2D* outputTexture)

// Get bytes from texture because screengrab does not support texture format provided by Unity.
DirectXHelper::GetBytesFromTexture(_device, outputTexture, FRAME_BPP, photoBytes);
ID3D11Texture2D* tex = DirectXHelper::CreateTexture(_device, photoBytes, FRAME_WIDTH, FRAME_HEIGHT, FRAME_BPP, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
ID3D11Texture2D* tex = DirectXHelper::CreateTexture(_device, photoBytes, FrameProviderStaticConfig::width, FrameProviderStaticConfig::height, FRAME_BPP, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these dimensions fall back to FRAME_WIDTH/ FRAME_HEIGHT if the config file is not present?
Looks like width and height will be undefined.

Can you make width and height private, then the function get_width() and get_height() should return the cached loaded value (if file existed) or the fallback constant if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables are initialized to FRAME_WIDTH/FRAME_HEIGHT inside CompositorDLL. They are __declspec(dllexport/importd)ed from that DLL. So if they aren't touched by the code that load the config file, they are set to whatever was set in the header.

Also, the configuration file loader class throws exceptions when it cannot read the file. I should explicitly reset theses values to FRAME_WIDTH/FRAME_HEIGHT/VIDEO_FPS in the catch() statements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the source files have been encoded in Unicode (2byte per character on windows). Git thinks they are binary so GitHub doesn't really show diff correctly on theses files.

Compositor.DLL contains the static initialization of theses files

#include "FrameProviderStaticConfig.h"

int FrameProviderStaticConfig::width = FRAME_WIDTH;
int FrameProviderStaticConfig::height = FRAME_HEIGHT;
float FrameProviderStaticConfig::fps = VIDEO_FPS;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In either case, now this is specifically handled when catching an exception if there's any problem with reading the config file


photoIndex++;
std::wstring photoPath = DirectoryHelper::FindUniqueFileName(outputPath, L"Photo", L".png", photoIndex);
Expand All @@ -183,7 +184,7 @@ void CompositorInterface::TakePicture(ID3D11Texture2D* outputTexture)

bool CompositorInterface::InitializeVideoEncoder(ID3D11Device* device)
{
videoEncoder = new VideoEncoder(FRAME_WIDTH, FRAME_HEIGHT, FRAME_WIDTH * FRAME_BPP, VIDEO_FPS,
videoEncoder = new VideoEncoder(FrameProviderStaticConfig::width, FrameProviderStaticConfig::height, FrameProviderStaticConfig::width * FRAME_BPP, UINT(std::ceil(FrameProviderStaticConfig::fps)),
AUDIO_BUFSIZE, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, AUDIO_BPS);

return videoEncoder->Initialize(device);
Expand Down Expand Up @@ -254,7 +255,7 @@ void CompositorInterface::AllocateVideoBuffers()

for (int i = 0; i < NUM_VIDEO_BUFFERS; i++)
{
videoBytes[i] = new byte[(int)(1.5f * FRAME_WIDTH * FRAME_HEIGHT)];
videoBytes[i] = new byte[(int)(1.5f * FrameProviderStaticConfig::width * FrameProviderStaticConfig::height)];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CompositorInterface
int lastVideoFrame = -1;
BufferedTextureFetch VideoTextureBuffer;
VideoEncoder* videoEncoder = nullptr;
byte* photoBytes = new byte[FRAME_BUFSIZE];
byte* photoBytes = new byte[FrameProviderStaticConfig::getFrameBuffSize()];
byte** videoBytes = nullptr;
int videoBufferIndex = 0;

Expand Down
22 changes: 12 additions & 10 deletions SpectatorView/Compositor/CompositorDLL/DeckLinkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include <comutil.h>
#include "DeckLinkDevice.h"
#include "FrameProviderStaticConfig.h"


using namespace std;

Expand All @@ -44,7 +46,7 @@ DeckLinkDevice::DeckLinkDevice(IDeckLink* device) :
{
for (int i = 0; i < MAX_NUM_CACHED_BUFFERS; i++)
{
bufferCache[i].buffer = new BYTE[FRAME_BUFSIZE];
bufferCache[i].buffer = new BYTE[FrameProviderStaticConfig::getFrameBuffSize()];
bufferCache[i].timeStamp = 0;
}

Expand Down Expand Up @@ -156,13 +158,13 @@ bool DeckLinkDevice::Init(ID3D11ShaderResourceView* colorSRV)
IDeckLinkDisplayMode* displayMode = NULL;
BSTR deviceNameBSTR = NULL;

ZeroMemory(rawBuffer, FRAME_BUFSIZE_RAW);
ZeroMemory(latestBuffer, FRAME_BUFSIZE);
ZeroMemory(outputBuffer, FRAME_BUFSIZE);
ZeroMemory(rawBuffer, FrameProviderStaticConfig::getFrameBuffSizeRaw());
ZeroMemory(latestBuffer, FrameProviderStaticConfig::getFrameBuffSize());
ZeroMemory(outputBuffer, FrameProviderStaticConfig::getFrameBuffSize());

for (int i = 0; i < MAX_NUM_CACHED_BUFFERS; i++)
{
ZeroMemory(bufferCache[i].buffer, FRAME_BUFSIZE);
ZeroMemory(bufferCache[i].buffer, FrameProviderStaticConfig::getFrameBuffSize());
}

captureFrameIndex = 0;
Expand Down Expand Up @@ -200,7 +202,7 @@ bool DeckLinkDevice::Init(ID3D11ShaderResourceView* colorSRV)
// 1080i output causes horizontal artifacts on screen.
if (m_deckLinkOutput != NULL)
{
m_deckLinkOutput->CreateVideoFrame(FRAME_WIDTH, FRAME_HEIGHT, FRAME_WIDTH * FRAME_BPP, bmdFormat8BitBGRA, bmdFrameFlagDefault, &outputFrame);
m_deckLinkOutput->CreateVideoFrame(FrameProviderStaticConfig::width, FrameProviderStaticConfig::height, FrameProviderStaticConfig::width * FRAME_BPP, bmdFormat8BitBGRA, bmdFrameFlagDefault, &outputFrame);
outputFrame->GetBytes((void**)&outputBuffer);
}

Expand Down Expand Up @@ -294,7 +296,7 @@ HRESULT DeckLinkDevice::VideoInputFormatChanged(/* in */ BMDVideoInputFormatChan
OutputDebugString(L"\n");

// If we do not have the correct dimension frames - loop until user changes camera settings.
if (newMode->GetWidth() != FRAME_WIDTH || newMode->GetHeight() != FRAME_HEIGHT)
if (newMode->GetWidth() != FrameProviderStaticConfig::width || newMode->GetHeight() != FrameProviderStaticConfig::height)
{
OutputDebugString(L"Invalid frame dimensions detected.\n");
OutputDebugString(L"Actual Frame Dimensions: ");
Expand All @@ -304,9 +306,9 @@ HRESULT DeckLinkDevice::VideoInputFormatChanged(/* in */ BMDVideoInputFormatChan
OutputDebugString(L"\n");

OutputDebugString(L"Expected Frame Dimensions: ");
OutputDebugString(std::to_wstring(FRAME_WIDTH).c_str());
OutputDebugString(std::to_wstring(FrameProviderStaticConfig::width).c_str());
OutputDebugString(L", ");
OutputDebugString(std::to_wstring(FRAME_HEIGHT).c_str());
OutputDebugString(std::to_wstring(FrameProviderStaticConfig::height).c_str());
OutputDebugString(L"\n");

LeaveCriticalSection(&m_captureCardCriticalSection);
Expand Down Expand Up @@ -417,7 +419,7 @@ void DeckLinkDevice::Update(int compositeFrameIndex)
const BufferCache& buffer = bufferCache[compositeFrameIndex % MAX_NUM_CACHED_BUFFERS];
if (buffer.buffer != nullptr)
{
DirectXHelper::UpdateSRV(device, _colorSRV, buffer.buffer, FRAME_WIDTH * FRAME_BPP);
DirectXHelper::UpdateSRV(device, _colorSRV, buffer.buffer, FrameProviderStaticConfig::width * FRAME_BPP);
}

if (supportsOutput && device != nullptr && _outputTexture != nullptr)
Expand Down
6 changes: 3 additions & 3 deletions SpectatorView/Compositor/CompositorDLL/DeckLinkDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class DeckLinkDevice : public IDeckLinkInputCallback
CRITICAL_SECTION m_outputCriticalSection;

BYTE* localFrameBuffer;
BYTE* rawBuffer = new BYTE[FRAME_BUFSIZE_RAW];
BYTE* rawBuffer = new BYTE[FrameProviderStaticConfig::getFrameBuffSizeRaw()];

BYTE* latestBuffer = new BYTE[FRAME_BUFSIZE];
BYTE* outputBuffer = new BYTE[FRAME_BUFSIZE];
BYTE* latestBuffer = new BYTE[FrameProviderStaticConfig::getFrameBuffSize()];
BYTE* outputBuffer = new BYTE[FrameProviderStaticConfig::getFrameBuffSize()];

IDeckLinkMutableVideoFrame* outputFrame = NULL;

Expand Down
Loading