-
Notifications
You must be signed in to change notification settings - Fork 287
Spectator view dynamic camera config (load video frame settings at runtime) #286
base: master
Are you sure you want to change the base?
Changes from all commits
2053bb8
076eefb
256cb6b
edd30d8
73e5a67
19d194f
0f6cd56
397faff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.TMP | ||
# git ignore file | ||
AppPackages/ | ||
BundleArtifacts/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
#include "stdafx.h" | ||
#include "CalibrationApp.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix that and ping you when fixed later friday 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the config file read for the UnityCompositorDLL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a fallback to the previously defined constants? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
#include "stdafx.h" | ||
#include "CompositorInterface.h" | ||
#include "FrameProviderStaticConfig.h" | ||
|
||
|
||
CompositorInterface::CompositorInterface() | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variables are initialized to FRAME_WIDTH/FRAME_HEIGHT inside CompositorDLL. They are 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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; There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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); | ||
|
@@ -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)]; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.