-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxstreamplugin.cpp
More file actions
157 lines (125 loc) · 3.17 KB
/
xstreamplugin.cpp
File metadata and controls
157 lines (125 loc) · 3.17 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "xstreamplugin.h"
#include <XPLMProcessing.h>
#include <XPLMMenus.h>
#include "videostream.h"
#include "displaymanager.h"
using namespace std;
XStreamPlugin g_ufcPlugin;
int XStreamPlugin::start(char* outName, char* outSig, char* outDesc)
{
setLogPrinter(&m_logPrinter);
strcpy(outName, "XStream Display Streamer");
strcpy(outSig, "com.geekprojects.xstream");
strcpy(outDesc, "XStream Display Streamer");
m_menuContainer = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "XStream", nullptr, 0);
m_menuId = XPLMCreateMenu("XStream", XPLMFindPluginsMenu(), m_menuContainer, menuCallback, this);
m_streamMenuIndex = XPLMAppendMenuItem(m_menuId, "Start Streaming", (void*)3, 1);
XPLMAppendMenuItem(m_menuId, "Dump Textures", (void*)2, 1);
XPLMCheckMenuItem(m_menuId, m_streamMenuIndex, xplm_Menu_Unchecked);
m_videoStream = make_shared<VideoStream>(this);
m_displayManager = make_shared<DisplayManager>();
return 1;
}
void XStreamPlugin::stop()
{
m_videoStream->stop();
m_displayManager->stop();
}
int XStreamPlugin::enable()
{
return 1;
}
void XStreamPlugin::disable()
{
m_videoStream->stop();
m_displayManager->stop();
}
void XStreamPlugin::startStream()
{
if (m_videoStream->isStreaming())
{
// We're already streaming!
return;
}
bool res;
res = m_displayManager->findDisplays();
if (!res)
{
return;
}
res = m_displayManager->start();
if (!res)
{
return;
}
res = m_videoStream->start();
if (!res)
{
return;
}
}
void XStreamPlugin::receiveMessage(XPLMPluginID inFrom, int inMsg, void* inParam)
{
#if 0
switch (inMsg)
{
case XPLM_MSG_PLANE_LOADED:
{
int index = (int)(intptr_t)inParam;
log(DEBUG, "receiveMessage: XPLM_MSG_PLANE_LOADED: index=%d", index);
break;
}
default:
log(DEBUG, "receiveMessage: Unhandled message: %d", inMsg);
}
#endif
}
void XStreamPlugin::menuCallback(void* menuRef, void* itemRef)
{
if (menuRef != nullptr)
{
((XStreamPlugin*)menuRef)->menu(itemRef);
}
}
void XStreamPlugin::menu(void* itemRef)
{
log(DEBUG, "menu: itemRef=%p", itemRef);
auto item = static_cast<int>(reinterpret_cast<intptr_t>(itemRef));
if (item == 2)
{
m_displayManager->dumpTextures();
}
else if (item == 3)
{
if (!m_videoStream->isStreaming())
{
startStream();
XPLMSetMenuItemName(m_menuId, m_streamMenuIndex, "Stop Streaming", 0);
}
else
{
XPLMSetMenuItemName(m_menuId, m_streamMenuIndex, "Start Streaming", 0);
stop();
}
}
}
PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc)
{
return g_ufcPlugin.start(outName, outSig, outDesc);
}
PLUGIN_API void XPluginStop()
{
g_ufcPlugin.stop();
}
PLUGIN_API int XPluginEnable()
{
return g_ufcPlugin.enable();
}
PLUGIN_API void XPluginDisable()
{
g_ufcPlugin.disable();
}
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, int inMsg, void * inParam)
{
g_ufcPlugin.receiveMessage(inFrom, inMsg, inParam);
}