Skip to content

Commit 5f88077

Browse files
tabs -> Spaces
1 parent f1e3207 commit 5f88077

File tree

5 files changed

+246
-246
lines changed

5 files changed

+246
-246
lines changed

SpectatorView/Compositor/CompositorDLL/OpenCVFrameProvider.cpp

+114-114
Original file line numberDiff line numberDiff line change
@@ -13,149 +13,149 @@ OpenCVFrameProvider::OpenCVFrameProvider()
1313

1414
OpenCVFrameProvider::~OpenCVFrameProvider()
1515
{
16-
DeleteCriticalSection(&lock);
16+
DeleteCriticalSection(&lock);
1717
}
1818

1919
HRESULT OpenCVFrameProvider::Initialize(ID3D11ShaderResourceView* colorSRV, ID3D11Texture2D* outputTexture)
2020
{
21-
if (IsEnabled())
22-
{
23-
return S_OK;
24-
}
25-
26-
InitializeCriticalSection(&lock);
27-
InitializeCriticalSection(&frameAccessCriticalSection);
28-
29-
_colorSRV = colorSRV;
30-
if (colorSRV != nullptr)
31-
{
32-
colorSRV->GetDevice(&_device);
33-
}
34-
35-
HRESULT hr = E_PENDING;
36-
videoCapture = new cv::VideoCapture(CAMERA_ID);
37-
38-
// Attempt to update camera resolution to desired resolution.
39-
// Note: This may fail, and your capture will resume at the camera's native resolution.
40-
// In this case, the Update loop will print an error with the expected frame resolution.
41-
videoCapture->set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
42-
videoCapture->set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);
43-
44-
videoCapture->open(CAMERA_ID);
45-
if (IsEnabled())
46-
{
47-
hr = S_OK;
48-
}
49-
50-
return hr;
21+
if (IsEnabled())
22+
{
23+
return S_OK;
24+
}
25+
26+
InitializeCriticalSection(&lock);
27+
InitializeCriticalSection(&frameAccessCriticalSection);
28+
29+
_colorSRV = colorSRV;
30+
if (colorSRV != nullptr)
31+
{
32+
colorSRV->GetDevice(&_device);
33+
}
34+
35+
HRESULT hr = E_PENDING;
36+
videoCapture = new cv::VideoCapture(CAMERA_ID);
37+
38+
// Attempt to update camera resolution to desired resolution.
39+
// Note: This may fail, and your capture will resume at the camera's native resolution.
40+
// In this case, the Update loop will print an error with the expected frame resolution.
41+
videoCapture->set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
42+
videoCapture->set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);
43+
44+
videoCapture->open(CAMERA_ID);
45+
if (IsEnabled())
46+
{
47+
hr = S_OK;
48+
}
49+
50+
return hr;
5151
}
5252

5353
void OpenCVFrameProvider::Update()
5454
{
55-
if (!IsEnabled() ||
56-
_colorSRV == nullptr ||
57-
_device == nullptr)
58-
{
59-
return;
60-
}
61-
62-
// Get frame time.
63-
LARGE_INTEGER time;
64-
QueryPerformanceCounter(&time);
65-
66-
if (videoCapture->grab())
67-
{
68-
cachedTimestamp = time.QuadPart;
69-
70-
concurrency::create_task([=]
71-
{
72-
cv::Mat frame;
73-
videoCapture->retrieve(frame);
74-
75-
double width = videoCapture->get(cv::CAP_PROP_FRAME_WIDTH);
76-
double height = videoCapture->get(cv::CAP_PROP_FRAME_HEIGHT);
77-
78-
if (width != FRAME_WIDTH)
79-
{
80-
OutputDebugString(L"ERROR: captured width does not equal FRAME_WIDTH. Expecting: ");
81-
OutputDebugString(std::to_wstring(width).c_str());
82-
OutputDebugString(L"\n");
83-
}
84-
85-
if (height != FRAME_HEIGHT)
86-
{
87-
OutputDebugString(L"ERROR: captured height does not equal FRAME_HEIGHT. Expecting: ");
88-
OutputDebugString(std::to_wstring(height).c_str());
89-
OutputDebugString(L"\n");
90-
}
91-
92-
// OpenCV returns frames in RGB, convert to BGRA
93-
DirectXHelper::ConvertRGBtoBGRA(frame.data, tmpData, width, height, true);
94-
EnterCriticalSection(&lock);
95-
dirtyFrame = false;
96-
97-
memcpy(cachedFrame, tmpData, FRAME_BUFSIZE);
98-
99-
LeaveCriticalSection(&lock);
100-
});
101-
102-
if (_device != nullptr && _colorSRV != nullptr)
103-
{
104-
EnterCriticalSection(&lock);
105-
if (!dirtyFrame)
106-
{
107-
DirectXHelper::UpdateSRV(_device, _colorSRV, cachedFrame, FRAME_WIDTH * FRAME_BPP);
108-
dirtyFrame = true;
109-
}
110-
LeaveCriticalSection(&lock);
111-
112-
EnterCriticalSection(&frameAccessCriticalSection);
113-
isVideoFrameReady = true;
114-
LeaveCriticalSection(&frameAccessCriticalSection);
115-
}
116-
}
55+
if (!IsEnabled() ||
56+
_colorSRV == nullptr ||
57+
_device == nullptr)
58+
{
59+
return;
60+
}
61+
62+
// Get frame time.
63+
LARGE_INTEGER time;
64+
QueryPerformanceCounter(&time);
65+
66+
if (videoCapture->grab())
67+
{
68+
cachedTimestamp = time.QuadPart;
69+
70+
concurrency::create_task([=]
71+
{
72+
cv::Mat frame;
73+
videoCapture->retrieve(frame);
74+
75+
double width = videoCapture->get(cv::CAP_PROP_FRAME_WIDTH);
76+
double height = videoCapture->get(cv::CAP_PROP_FRAME_HEIGHT);
77+
78+
if (width != FRAME_WIDTH)
79+
{
80+
OutputDebugString(L"ERROR: captured width does not equal FRAME_WIDTH. Expecting: ");
81+
OutputDebugString(std::to_wstring(width).c_str());
82+
OutputDebugString(L"\n");
83+
}
84+
85+
if (height != FRAME_HEIGHT)
86+
{
87+
OutputDebugString(L"ERROR: captured height does not equal FRAME_HEIGHT. Expecting: ");
88+
OutputDebugString(std::to_wstring(height).c_str());
89+
OutputDebugString(L"\n");
90+
}
91+
92+
// OpenCV returns frames in RGB, convert to BGRA
93+
DirectXHelper::ConvertRGBtoBGRA(frame.data, tmpData, width, height, true);
94+
EnterCriticalSection(&lock);
95+
dirtyFrame = false;
96+
97+
memcpy(cachedFrame, tmpData, FRAME_BUFSIZE);
98+
99+
LeaveCriticalSection(&lock);
100+
});
101+
102+
if (_device != nullptr && _colorSRV != nullptr)
103+
{
104+
EnterCriticalSection(&lock);
105+
if (!dirtyFrame)
106+
{
107+
DirectXHelper::UpdateSRV(_device, _colorSRV, cachedFrame, FRAME_WIDTH * FRAME_BPP);
108+
dirtyFrame = true;
109+
}
110+
LeaveCriticalSection(&lock);
111+
112+
EnterCriticalSection(&frameAccessCriticalSection);
113+
isVideoFrameReady = true;
114+
LeaveCriticalSection(&frameAccessCriticalSection);
115+
}
116+
}
117117
}
118118

119119
bool OpenCVFrameProvider::IsVideoFrameReady()
120120
{
121-
EnterCriticalSection(&frameAccessCriticalSection);
122-
bool ret = isVideoFrameReady;
123-
if (isVideoFrameReady)
124-
{
125-
isVideoFrameReady = false;
126-
}
127-
LeaveCriticalSection(&frameAccessCriticalSection);
128-
129-
return ret;
121+
EnterCriticalSection(&frameAccessCriticalSection);
122+
bool ret = isVideoFrameReady;
123+
if (isVideoFrameReady)
124+
{
125+
isVideoFrameReady = false;
126+
}
127+
LeaveCriticalSection(&frameAccessCriticalSection);
128+
129+
return ret;
130130
}
131131

132132
LONGLONG OpenCVFrameProvider::GetTimestamp()
133133
{
134-
return cachedTimestamp;
134+
return cachedTimestamp;
135135
}
136136

137137
LONGLONG OpenCVFrameProvider::GetDurationHNS()
138138
{
139-
return (1.0f / 60.0f) * QPC_MULTIPLIER;
139+
return (1.0f / 60.0f) * QPC_MULTIPLIER;
140140
}
141141

142142
bool OpenCVFrameProvider::IsEnabled()
143143
{
144-
if (videoCapture != nullptr)
145-
{
146-
return videoCapture->isOpened();
147-
}
144+
if (videoCapture != nullptr)
145+
{
146+
return videoCapture->isOpened();
147+
}
148148

149-
return false;
149+
return false;
150150
}
151151

152152
void OpenCVFrameProvider::Dispose()
153153
{
154-
if (videoCapture != nullptr)
155-
{
156-
videoCapture->release();
157-
videoCapture = nullptr;
158-
}
154+
if (videoCapture != nullptr)
155+
{
156+
videoCapture->release();
157+
videoCapture = nullptr;
158+
}
159159
}
160160

161161
#endif

SpectatorView/Compositor/SharedHeaders/DirectXHelper.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class DirectXHelper
5656
// Create a texture with the given bytes.
5757
static ID3D11Texture2D* CreateTexture(ID3D11Device* device, const byte* bytes, int width, int height, int bpp, DXGI_FORMAT textureFormat = DXGI_FORMAT_R8G8B8A8_UNORM)
5858
{
59-
if (device == nullptr)
60-
{
61-
return nullptr;
62-
}
59+
if (device == nullptr)
60+
{
61+
return nullptr;
62+
}
6363

6464
ID3D11Texture2D* tex;
6565

SpectatorView/Compositor/UnityCompositorInterface/PluginAPI/IUnityGraphics.h

+24-24
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33

44
typedef enum UnityGfxRenderer
55
{
6-
//kUnityGfxRendererOpenGL = 0, // Legacy OpenGL, removed
7-
kUnityGfxRendererD3D9 = 1, // Direct3D 9
8-
kUnityGfxRendererD3D11 = 2, // Direct3D 11
9-
kUnityGfxRendererGCM = 3, // PlayStation 3
10-
kUnityGfxRendererNull = 4, // "null" device (used in batch mode)
11-
kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0
12-
kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0
13-
kUnityGfxRendererGXM = 12, // PlayStation Vita
14-
kUnityGfxRendererPS4 = 13, // PlayStation 4
15-
kUnityGfxRendererXboxOne = 14, // Xbox One
16-
kUnityGfxRendererMetal = 16, // iOS Metal
17-
kUnityGfxRendererOpenGLCore = 17, // OpenGL core
18-
kUnityGfxRendererD3D12 = 18, // Direct3D 12
19-
kUnityGfxRendererVulkan = 21, // Vulkan
6+
//kUnityGfxRendererOpenGL = 0, // Legacy OpenGL, removed
7+
kUnityGfxRendererD3D9 = 1, // Direct3D 9
8+
kUnityGfxRendererD3D11 = 2, // Direct3D 11
9+
kUnityGfxRendererGCM = 3, // PlayStation 3
10+
kUnityGfxRendererNull = 4, // "null" device (used in batch mode)
11+
kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0
12+
kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0
13+
kUnityGfxRendererGXM = 12, // PlayStation Vita
14+
kUnityGfxRendererPS4 = 13, // PlayStation 4
15+
kUnityGfxRendererXboxOne = 14, // Xbox One
16+
kUnityGfxRendererMetal = 16, // iOS Metal
17+
kUnityGfxRendererOpenGLCore = 17, // OpenGL core
18+
kUnityGfxRendererD3D12 = 18, // Direct3D 12
19+
kUnityGfxRendererVulkan = 21, // Vulkan
2020
} UnityGfxRenderer;
2121

2222
typedef enum UnityGfxDeviceEventType
2323
{
24-
kUnityGfxDeviceEventInitialize = 0,
25-
kUnityGfxDeviceEventShutdown = 1,
26-
kUnityGfxDeviceEventBeforeReset = 2,
27-
kUnityGfxDeviceEventAfterReset = 3,
24+
kUnityGfxDeviceEventInitialize = 0,
25+
kUnityGfxDeviceEventShutdown = 1,
26+
kUnityGfxDeviceEventBeforeReset = 2,
27+
kUnityGfxDeviceEventAfterReset = 3,
2828
} UnityGfxDeviceEventType;
2929

3030
typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType);
3131

3232
// Should only be used on the rendering thread unless noted otherwise.
3333
UNITY_DECLARE_INTERFACE(IUnityGraphics)
3434
{
35-
UnityGfxRenderer (UNITY_INTERFACE_API * GetRenderer)(); // Thread safe
35+
UnityGfxRenderer (UNITY_INTERFACE_API * GetRenderer)(); // Thread safe
3636

37-
// This callback will be called when graphics device is created, destroyed, reset, etc.
38-
// It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time,
39-
// when the graphics device is already created.
40-
void (UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback);
41-
void (UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback);
37+
// This callback will be called when graphics device is created, destroyed, reset, etc.
38+
// It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time,
39+
// when the graphics device is already created.
40+
void (UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback);
41+
void (UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback);
4242
};
4343
UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL,0x8C5AD4926EB17B11ULL,IUnityGraphics)
4444

SpectatorView/Compositor/UnityCompositorInterface/PluginAPI/IUnityGraphicsD3D11.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ typedef struct RenderSurfaceBase* UnityRenderBuffer;
77
// Should only be used on the rendering thread unless noted otherwise.
88
UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D11)
99
{
10-
ID3D11Device* (UNITY_INTERFACE_API * GetDevice)();
10+
ID3D11Device* (UNITY_INTERFACE_API * GetDevice)();
1111

12-
ID3D11Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer);
12+
ID3D11Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer);
1313
};
1414
UNITY_REGISTER_INTERFACE_GUID(0xAAB37EF87A87D748ULL,0xBF76967F07EFB177ULL,IUnityGraphicsD3D11)

0 commit comments

Comments
 (0)