This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Expand file tree
/
Copy pathCompositorInterface.h
More file actions
134 lines (106 loc) · 3.43 KB
/
CompositorInterface.h
File metadata and controls
134 lines (106 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#include "stdafx.h"
#define DLLEXPORT __declspec(dllexport)
#include "IFrameProvider.h"
#include "DeckLinkManager.h"
#include "ElgatoFrameProvider.h"
#include "OpenCVFrameProvider.h"
#include "DirectXHelper.h"
#include "DirectoryHelper.h"
#include "Shlobj.h" // To get MyDocuments path
#include "ScreenGrab.h"
#include <wincodec.h>
#include "VideoEncoder.h"
#include "BufferedTextureFetch.h"
#include "PoseCache.h"
#include "TimeSynchronizer.h"
class CompositorInterface
{
#define NUM_VIDEO_BUFFERS 10
public:
DLLEXPORT CompositorInterface();
~CompositorInterface();
DLLEXPORT bool Initialize(ID3D11Device* device, ID3D11ShaderResourceView* colorSRV, ID3D11Texture2D* outputTexture);
DLLEXPORT void UpdateFrameProvider();
DLLEXPORT void Update();
DLLEXPORT void StopFrameProvider();
DLLEXPORT LONGLONG GetTimestamp(int frame);
DLLEXPORT LONGLONG GetColorDuration();
DLLEXPORT bool OutputYUV()
{
if (frameProvider == nullptr)
{
return true;
}
return frameProvider->OutputYUV();
}
// Recording
DLLEXPORT void TakePicture(ID3D11Texture2D* outputTexture);
DLLEXPORT bool InitializeVideoEncoder(ID3D11Device* device);
DLLEXPORT void StartRecording();
DLLEXPORT void StopRecording();
DLLEXPORT void RecordFrameAsync(byte* bytes, LONGLONG frameTime, int numFrames);
DLLEXPORT void RecordAudioFrameAsync(BYTE* audioFrame, LONGLONG frameTime);
DLLEXPORT void UpdateVideoRecordingFrame(ID3D11Texture2D* videoTexture);
// Poses
DLLEXPORT void GetPose(XMFLOAT3& position, XMFLOAT4& rotation, int frameOffset);
DLLEXPORT void AddPoseToPoseCache(XMFLOAT3 position, XMFLOAT4 rotation, float time)
{
poseCache.AddPose(position, rotation, time);
}
DLLEXPORT int GetCaptureFrameIndex()
{
if (frameProvider != nullptr)
{
return frameProvider->GetCaptureFrameIndex();
}
return 0;
}
DLLEXPORT int GetCurrentCompositeFrame()
{
return CurrentCompositeFrame;
}
DLLEXPORT int LastPoseSelectedIndex()
{
return poseCache.LastSelectedIndex;
}
DLLEXPORT void ResetPoseCache()
{
poseCache.Reset();
timeSynchronizer.Reset();
}
private:
IFrameProvider* frameProvider;
std::wstring outputPath;
ID3D11Device* _device;
// Recording
LONGLONG stubVideoTime = 0;
int photoIndex = -1;
int videoIndex = -1;
LONGLONG queuedVideoFrameTime;
int queuedVideoFrameCount = 0;
int lastRecordedVideoFrame = -1;
int lastVideoFrame = -1;
BufferedTextureFetch VideoTextureBuffer;
VideoEncoder* videoEncoder = nullptr;
byte* photoBytes = new byte[FrameProviderStaticConfig::getFrameBuffSize()];
byte** videoBytes = nullptr;
int videoBufferIndex = 0;
void AllocateVideoBuffers();
void FreeVideoBuffers();
// Pose
PoseCache poseCache;
TimeSynchronizer timeSynchronizer;
int CurrentCompositeFrame = 0;
// Abstracts time in seconds from frame index based on known duration.
float GetTimeFromFrame(int frame)
{
if (frameProvider != nullptr)
{
return (float)(0.0001f * frameProvider->GetDurationHNS() / 1000.0f) * frame;
}
return (1.0f / 30) * frame;
}
};