-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColourThread.cpp
More file actions
261 lines (237 loc) · 6.55 KB
/
ColourThread.cpp
File metadata and controls
261 lines (237 loc) · 6.55 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
/*******************************************
A Docile Sloth 2017 (adocilesloth@gmail.com)
*******************************************/
#include "LCDThreads.h"
using namespace std;
void Colour(atomic<bool>& close)
{
wstring scene;
bool leftlast = false;
bool rightlast = false;
bool uplast = false;
bool downlast = false;
bool oklast = false;
bool cancellast = false;
//fps
int fps = 0;
time_t tlastime;
int fpslastime;
int lastframes;
wstringstream sfps;
//bit rate
float bitrate = 0.0;
int bpslastime;
int lastbytes;
wstringstream sbyte;
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;
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)
{
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)
{
//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
LogiLcdColorSetText(1, name, 255, 255, 255);
delete [] name; //delete temp crap
scene = L"";
if(obs_frontend_streaming_active() || obs_frontend_recording_active()) //streaming
{
//live
LogiLcdColorSetText(0, L"Live \u25CF", 255, 0, 0);
if(firstime == true)
{
firstime = false;
time(&tstartime);
time(&tlastime);
startime = int(tstartime);
fpslastime = int(tlastime);
bpslastime = int(tlastime);
lastframes = 0;
lastbytes = 0;
}
//fps
sfps << L"FPS: ";
getFPS(fps, lastframes, fpslastime);
if(fps < 10)
{
sfps << L"0";
}
sfps << fps;
wchar_t *wfps = new wchar_t[sfps.str().length() +1];
wcscpy(wfps, sfps.str().c_str()); //copy string
//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 to lcd
//}
delete [] wfps;
sfps.str(L"");
//bitrate
sbyte << L"Bitrate: ";
getbps(bitrate, lastbytes, bpslastime);
sbyte << int(bitrate) << L"kb/s";
wchar_t *wbit = new wchar_t[sbyte.str().length() +1];
wcscpy(wbit, sbyte.str().c_str()); //copy string
LogiLcdColorSetText(3, wbit, 255, 255, 255); //print to lcd
delete [] wbit;
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
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
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 to lcd
}
delete [] droppedframes;
frames.str(L"");
//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
LogiLcdColorSetText(5, streamtime, 255, 255, 255); //print to lcd
delete [] streamtime;
stime.str(L"");
}
else
{
LogiLcdColorSetText(0, L"", 0, 0, 0);
LogiLcdColorSetText(2, L"FPS: --", 255, 255, 255);
LogiLcdColorSetText(3, L"Bitrate: ----kb/s", 255, 255, 255);
LogiLcdColorSetText(4, L"Dropped Frames: -(-.--%)", 255, 255, 255);
LogiLcdColorSetText(5, L"Stream Uptime: -:--:--", 255, 255, 255);
}
if(getMute() && getDeaf())
{
LogiLcdColorSetText(6, L"Muted and Deafened", 255, 0, 0);
}
else if(getMute() && !getDeaf())
{
LogiLcdColorSetText(6, L"Muted", 255, 126, 0);
}
else if(!getMute() && getDeaf())
{
LogiLcdColorSetText(6, L"Deafened", 255, 126, 0);
}
else
{
LogiLcdColorSetText(6, L"", 0, 0, 0);
}
//update screen
LogiLcdUpdate();
Sleep(16);
}
LogiLcdShutdown();
return;
}