-
Notifications
You must be signed in to change notification settings - Fork 1
/
MonoThread.cpp
254 lines (231 loc) · 5.96 KB
/
MonoThread.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*******************************************
A Docile Sloth 2017 ([email protected])
*******************************************/
#include "LCDThreads.h"
#include "mono_background.h"
//#include <fstream>
using namespace std;
void Mono(atomic<bool>& close)
{
wstring scene;
bool miclast = false;
bool desklast = false;
bool livelast = false;
bool altdisplast = false;
//fps and bitrate
int fps = 0;
time_t tlastime;
int fpslastime;
int lastframes;
float bitrate = 0.0;
int bpslastime;
int lastbytes;
wstringstream fpsbyte;
bool altdisplay = false;
//dropped frames
int dropped;
int total;
double percent;
wstringstream frames;
//stream time
time_t tstartime;
int startime;
int uptime;
int sec;
int min;
int hour;
wstringstream stime;
//stream info
bool firstime = true;
obs_output_t* output;
//Wait for stuff to load or obs_frontend_streaming_active() causes a crash
obs_source_t* sceneUsed = obs_frontend_get_current_scene();
while(!sceneUsed)
{
LogiLcdMonoSetText(0, L"Open Broadcasting Software");
LogiLcdMonoSetText(1, L" Loading...");
LogiLcdUpdate();
sceneUsed = obs_frontend_get_current_scene();
Sleep(16);
}
obs_source_release(sceneUsed);
while(!close) //Text line length is 26 characters
{
//mute and deafen buttons
if(miclast == true && LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_1) == false) //button released
{
toggleMute();
}
if(desklast == true && LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_2) == false) //button rleased
{
toggleDeaf();
}
miclast = LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_1);
desklast = LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_2);
//stream and preview buttons
if(livelast == true && LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_0) == false)
{
if(obs_frontend_streaming_active())
{
obs_frontend_streaming_stop();
}
else
{
obs_frontend_streaming_start();
}
}
if(altdisplast == true && LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_3) == false)
{
if(altdisplay)
{
altdisplay = false;
}
else
{
altdisplay = true;
}
}
livelast = LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_0);
altdisplast = LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_3);
//scene information
scene = L"Scene: ";
scene.append(getScene());
wchar_t *name = new wchar_t[scene.length() + 1];
wcscpy(name, scene.c_str()); //convert to wchar_t
LogiLcdMonoSetText(1, name); //print
delete[] name; //delete temp crap
scene = L"";
if(obs_frontend_streaming_active() || obs_frontend_recording_active()) //streaming
{
LogiLcdMonoSetBackground(mono_background_started);
if(getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute||Deaf live\u25CF");
}
else if(getMute() && !getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute| live\u25CF");
}
else if(!getMute() && getDeaf())
{
LogiLcdMonoSetText(0,L"OBS |Deaf live\u25CF");
}
else
{
LogiLcdMonoSetText(0, L"OBS live\u25CF");
}
if(firstime == true)
{
firstime = false;
time(&tstartime);
time(&tlastime);
startime = int(tstartime);
fpslastime = int(tlastime);
bpslastime = int(tlastime);
lastframes = 0;
lastbytes = 0;
}
//fps and bitrate
fpsbyte << L"FPS: ";
getFPS(fps, lastframes, fpslastime);//, streamName[indx]);
if(fps < 10)
{
fpsbyte << L"0";
}
fpsbyte << fps << L" Bitrate: ";
getbps(bitrate, lastbytes, bpslastime);//, streamName[indx]);
fpsbyte << int(bitrate);
wchar_t *fpsbit = new wchar_t[fpsbyte.str().length() + 1];
wcscpy(fpsbit, fpsbyte.str().c_str()); //copy string
LogiLcdMonoSetText(2, fpsbit); //print to lcd
delete[] fpsbit;
fpsbyte.str(L"");
if(altdisplay)
{
if(obs_frontend_streaming_active())
{
output = obs_frontend_get_streaming_output();
}
else if(obs_frontend_recording_active())
{
output = obs_frontend_get_recording_output();
}
//dropped frames
frames << L"Dropped Frames: ";
dropped = obs_output_get_frames_dropped(output);
frames << dropped << L"(";
total = obs_output_get_total_frames(output);
percent = (double(dropped) / total) * 100;
frames << fixed << setprecision(2) << percent << L"%)";
wchar_t *droppedframes = new wchar_t[frames.str().length() +1];
wcscpy(droppedframes, frames.str().c_str()); //copy string
LogiLcdMonoSetText(3, droppedframes); //print to lcd
delete[] droppedframes;
frames.str(L"");
}
else
{
//stream time
stime << L"Stream Uptime: ";
uptime = streamTime(startime);
hour = (uptime / (60 * 60)) % 60;
min = (uptime / 60) % 60;
sec = (uptime % 60);
stime << hour << L":";
if (min < 10)
{
stime << L"0";
}
stime << min << L":";
if (sec < 10)
{
stime << L"0";
}
stime << sec;
wchar_t *streamtime = new wchar_t[stime.str().length() + 1];
wcscpy(streamtime, stime.str().c_str()); //copy string
LogiLcdMonoSetText(3, streamtime); //print to lcd
delete[] streamtime;
stime.str(L"");
}
}//end of streaming
else
{
LogiLcdMonoSetBackground(mono_background_stopped);
if(getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute||Deaf \u25CB");
}
else if(getMute() && !getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute| \u25CB");
}
else if(!getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS |Deaf \u25CB");
}
else
{//-------------------------------------------------------------------------------------------
LogiLcdMonoSetText(0, L"OBS \u25CB");
}
LogiLcdMonoSetText(2, L"FPS: -- Bitrate: ----");
if(firstime == false)
{
firstime =true;
}
if(altdisplay)
{
LogiLcdMonoSetText(3, L"Dropped Frames: -(-.--%)");
}
else
{
LogiLcdMonoSetText(3, L"Stream Uptime: -:--:--");
}
}
//update screen
LogiLcdUpdate();
Sleep(16);
}
LogiLcdShutdown();
return;
}