-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDualThread.cpp
More file actions
369 lines (342 loc) · 9.7 KB
/
DualThread.cpp
File metadata and controls
369 lines (342 loc) · 9.7 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*******************************************
A Docile Sloth 2017 (adocilesloth@gmail.com)
*******************************************/
#include "LCDThreads.h"
#include "mono_background.h"
using namespace std;
void Dual(atomic<bool>& close)
{
bool live = false;
wstring scene;
//mono buttons
bool miclast = false;
bool desklast = false;
bool livelast = false;
bool altdisplast = false;
bool altdisplay = false;
//colour buttons
bool leftlast = false;
bool rightlast = false;
bool uplast = false;
bool downlast = false;
bool oklast = false;
bool cancellast = false;
//fps and bitrate
int fps = 0;
time_t tlastime;
int fpslastime;
int lastframes;
float bitrate = 0.0;
int bpslastime;
int lastbytes;
wstringstream fpsbyte;
wstringstream sfps;
wstringstream sbyte;
//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;
LogiLcdColorSetTitle(L"OBS", 255, 255, 255);
//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...");
LogiLcdColorSetText(0, L"Open Broadcasting Software", 255, 255, 255);
LogiLcdColorSetText(2, L" Loading...", 255, 255, 255);
LogiLcdUpdate();
sceneUsed = obs_frontend_get_current_scene();
Sleep(16);
}
obs_source_release(sceneUsed);
while (!close)
{
/*MONO*/
//mono 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);
//mono 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);
//mute and deafen buttons
if(leftlast == true && LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_LEFT) == false) //button released
{
toggleMute();
}
if(rightlast == true && LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_RIGHT) == false) //button rleased
{
toggleDeaf();
}
leftlast = LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_LEFT);
rightlast = LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_RIGHT);
if(uplast == true && LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_UP) == false) //button released
{
toggleMute();
}
if(downlast == true && LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_DOWN) == false) //button rleased
{
toggleDeaf();
}
uplast = LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_UP);
downlast = LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_DOWN);
//stream and preview buttons
if(oklast == true && LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_OK) == false) //button released
{
if(obs_frontend_streaming_active())
{
obs_frontend_streaming_stop();
}
else
{
obs_frontend_streaming_start();
}
}
if(cancellast == true && LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_CANCEL) == false) //button released
{
//OBSStartStopPreview();
}
oklast = LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_OK);
cancellast = LogiLcdIsButtonPressed(LOGI_LCD_COLOR_BUTTON_CANCEL);
//get 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);
LogiLcdColorSetText(1, name, 255, 255, 255);
delete [] name; //delete temp crap
scene = L"";
if(obs_frontend_streaming_active() || obs_frontend_recording_active()) //streaming
{
LogiLcdMonoSetBackground(mono_background_started); //button help bitmap for mono
if(firstime == true)
{
firstime = false;
time(&tstartime);
time(&tlastime);
startime = int(tstartime);
fpslastime = int(tlastime);
bpslastime = int(tlastime);
lastframes = 0;
lastbytes = 0;
}
if(getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute||Deaf \u25CF");
LogiLcdColorSetText(6, L"Muted and Deafened", 255, 0, 0);
}
else if(getMute() && !getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute| \u25CF");
LogiLcdColorSetText(6, L"Muted", 255, 126, 0);
}
else if(!getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS |Deaf \u25CF");
LogiLcdColorSetText(6, L"Deafened", 255, 126, 0);
}
else
{
LogiLcdMonoSetText(0, L"OBS \u25CF");
LogiLcdColorSetText(6, L"", 0, 0, 0);
}
//fps and bitrate
fpsbyte << L"FPS: ";
sfps << L"FPS: ";
getFPS(fps, lastframes, fpslastime);
if(fps < 10)
{
fpsbyte << L"0";
sfps << L"0";
}
fpsbyte << fps << L" Bitrate: ";
sfps << fps;
sbyte << L"Bitrate: ";
getbps(bitrate, lastbytes, bpslastime); //get as kb/s
fpsbyte << int(bitrate);
sbyte << int(bitrate) << L"kb/s";
//mono fps and bitrate
wchar_t *fpsbit = new wchar_t[fpsbyte.str().length() +1];
wcscpy(fpsbit, fpsbyte.str().c_str()); //copy string
//colour fps
wchar_t *wfps = new wchar_t[sfps.str().length() +1];
wcscpy(wfps, sfps.str().c_str()); //copy string
//colour bitrate
wchar_t *wbit = new wchar_t[sbyte.str().length() +1];
wcscpy(wbit, sbyte.str().c_str()); //copy string
//print to LCDs
LogiLcdMonoSetText(2, fpsbit); //print to mono lcd
//fpspercent = double(fps)/OBSGetMaxFPS();
/*if(fpspercent >= 0.83 && fpspercent < 0.96)
{
LogiLcdColorSetText(2, wfps, 255, 126, 0); //print to lcd as yellow
}
else if(fpspercent < 0.83)
{
LogiLcdColorSetText(2, wfps, 255, 0, 0); //print to lcd as red
}
else
{*/
LogiLcdColorSetText(2, wfps, 255, 255, 255); //print colour to lcd
//}
LogiLcdColorSetText(3, wbit, 255, 255, 255); //print colour to lcd
//clear up
delete [] fpsbit;
delete [] wfps;
delete [] wbit;
fpsbyte.str(L"");
sfps.str(L"");
sbyte.str(L"");
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 calculations
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
//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*/
if(altdisplay)
{
//dropped frames
LogiLcdMonoSetText(3, droppedframes); //print to lcd
}
else
{
//stream time
LogiLcdMonoSetText(3, streamtime); //print to lcd
}
if(percent >= 5 && percent < 10) //between 5% and 10% dropped frames
{
LogiLcdColorSetText(4, droppedframes, 225, 126, 0); //print to lcd as yellow
}
else if(percent >= 10) //over 10% dropped
{
LogiLcdColorSetText(4, droppedframes, 225, 0, 0); //print to lcd as red
}
else
{
LogiLcdColorSetText(4, droppedframes, 225, 225, 225); //print colour to lcd
}
LogiLcdColorSetText(5, streamtime, 255, 255, 255); //print to lcd
delete [] droppedframes;
delete [] streamtime;
frames.str(L"");
stime.str(L"");
}
else
{
LogiLcdMonoSetBackground(mono_background_stopped); //button help bitmap for mono
LogiLcdColorSetText(0, L"", 0, 0, 0);
if(getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute||Deaf \u25CB");
LogiLcdColorSetText(6, L"Muted and Deafened", 255, 0, 0);
}
else if(getMute() && !getDeaf())
{
LogiLcdMonoSetText(0, L"OBS Mute| \u25CB");
LogiLcdColorSetText(6, L"Muted", 255, 126, 0);
}
else if(!getMute() && getDeaf())
{
LogiLcdMonoSetText(0, L"OBS |Deaf \u25CB");
LogiLcdColorSetText(6, L"Deafened", 255, 126, 0);
}
else
{
LogiLcdMonoSetText(0, L"OBS \u25CB");
LogiLcdColorSetText(6, L"", 0, 0, 0);
}
LogiLcdColorSetText(0, L"", 0, 0, 0);
LogiLcdMonoSetText(2, L"FPS: -- Bitrate: ----");
LogiLcdColorSetText(2, L"FPS: --");
LogiLcdColorSetText(3, L"Bitrate: ----kb/s", 255, 255, 255);
if(altdisplay)
{
LogiLcdMonoSetText(3, L"Dropped Frames: -(-.--%)");
}
else
{
LogiLcdMonoSetText(3, L"Stream Uptime: -:--:--");
}
LogiLcdColorSetText(4, L"Dropped Frames: -(-.--%)", 255, 255, 255);
LogiLcdColorSetText(5, L"Stream Uptime: -:--:--", 255, 255, 255);
}
//update screen
LogiLcdUpdate();
Sleep(16);
}
LogiLcdShutdown();
return;
}