Skip to content

Commit 5b2384f

Browse files
Migrate performance statistics to new API (#1526)
* Update performance statistics to new API Formatting Formatting, null checks, and destroy CPU usage object * Bug fix and test update
1 parent 89fd524 commit 5b2384f

23 files changed

+602
-34
lines changed

js/module.d.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ export interface IGlobal {
362362
locale: string;
363363
multipleRendering: boolean;
364364
readonly version: number;
365+
readonly cpuPercentage: number;
366+
readonly currentFrameRate: number;
367+
readonly averageFrameRenderTime: number;
368+
readonly diskSpaceAvailable: number;
369+
readonly memoryUsage: number;
365370
}
366371
export interface IBooleanProperty extends IProperty {
367372
}
@@ -799,6 +804,10 @@ export interface IStreaming {
799804
signalHandler: (signal: EOutputSignal) => void;
800805
start(): void;
801806
stop(force?: boolean): void;
807+
droppedFrames: number;
808+
totalFrames: number;
809+
kbitsPerSec: number;
810+
dataOutput: number;
802811
}
803812
export interface EOutputSignal {
804813
type: string;
@@ -943,10 +952,10 @@ export interface IAudioTrackFactory {
943952
saveLegacySettings(): void;
944953
}
945954
export declare const enum VCamOutputType {
946-
Invalid,
947-
SceneOutput,
948-
SourceOutput,
949-
ProgramView,
950-
PreviewOutput,
951-
};
955+
Invalid = 0,
956+
SceneOutput = 1,
957+
SourceOutput = 2,
958+
ProgramView = 3,
959+
PreviewOutput = 4
960+
}
952961
export declare const NodeObs: any;

js/module.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,31 @@ export interface IGlobal {
575575
* Last 4 bytes are patch.
576576
*/
577577
readonly version: number;
578+
579+
/**
580+
* Percentage of CPU being used
581+
*/
582+
readonly cpuPercentage: number;
583+
584+
/**
585+
* Current FPS
586+
*/
587+
readonly currentFrameRate: number;
588+
589+
/**
590+
* Average time to render a frame
591+
*/
592+
readonly averageFrameRenderTime: number;
593+
594+
/**
595+
* Disk space currentlky available
596+
*/
597+
readonly diskSpaceAvailable: number;
598+
599+
/**
600+
* Current memory usage
601+
*/
602+
readonly memoryUsage: number;
578603
}
579604

580605
export interface IBooleanProperty extends IProperty {
@@ -1686,6 +1711,10 @@ export interface IStreaming {
16861711
signalHandler: (signal: EOutputSignal) => void,
16871712
start(): void,
16881713
stop(force?: boolean): void,
1714+
droppedFrames: number;
1715+
totalFrames: number;
1716+
kbitsPerSec: number;
1717+
dataOutput: number;
16891718
}
16901719

16911720
export interface EOutputSignal {

obs-studio-client/source/advanced-streaming.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Napi::Object osn::AdvancedStreaming::Init(Napi::Env env, Napi::Object exports)
3030
Napi::HandleScope scope(env);
3131
Napi::Function func = DefineClass(
3232
env, "AdvancedStreaming",
33-
{StaticMethod("create", &osn::AdvancedStreaming::Create), StaticMethod("destroy", &osn::AdvancedStreaming::Destroy),
33+
{StaticMethod("create", &osn::AdvancedStreaming::Create),
34+
StaticMethod("destroy", &osn::AdvancedStreaming::Destroy),
3435

3536
InstanceAccessor("videoEncoder", &osn::AdvancedStreaming::GetVideoEncoder, &osn::AdvancedStreaming::SetVideoEncoder),
3637
InstanceAccessor("service", &osn::AdvancedStreaming::GetService, &osn::AdvancedStreaming::SetService),
@@ -41,14 +42,19 @@ Napi::Object osn::AdvancedStreaming::Init(Napi::Env env, Napi::Object exports)
4142
InstanceAccessor("reconnect", &osn::AdvancedStreaming::GetReconnect, &osn::AdvancedStreaming::SetReconnect),
4243
InstanceAccessor("network", &osn::AdvancedStreaming::GetNetwork, &osn::AdvancedStreaming::SetNetwork),
4344
InstanceAccessor("video", &osn::AdvancedStreaming::GetCanvas, &osn::AdvancedStreaming::SetCanvas),
45+
InstanceAccessor("droppedFrames", &osn::AdvancedStreaming::GetDroppedFrames, nullptr),
46+
InstanceAccessor("totalFrames", &osn::AdvancedStreaming::GetTotalFrames, nullptr),
47+
InstanceAccessor("kbitsPerSec", &osn::AdvancedStreaming::GetKBitsPerSec, nullptr),
48+
InstanceAccessor("dataOutput", &osn::AdvancedStreaming::GetDataOutput, nullptr),
4449

4550
InstanceAccessor("audioTrack", &osn::AdvancedStreaming::GetAudioTrack, &osn::AdvancedStreaming::SetAudioTrack),
4651
InstanceAccessor("twitchTrack", &osn::AdvancedStreaming::GetTwitchTrack, &osn::AdvancedStreaming::SetTwitchTrack),
4752
InstanceAccessor("rescaling", &osn::AdvancedStreaming::GetRescaling, &osn::AdvancedStreaming::SetRescaling),
4853
InstanceAccessor("outputWidth", &osn::AdvancedStreaming::GetOutputWidth, &osn::AdvancedStreaming::SetOutputWidth),
4954
InstanceAccessor("outputHeight", &osn::AdvancedStreaming::GetOutputHeight, &osn::AdvancedStreaming::SetOutputHeight),
5055

51-
InstanceMethod("start", &osn::AdvancedStreaming::Start), InstanceMethod("stop", &osn::AdvancedStreaming::Stop),
56+
InstanceMethod("start", &osn::AdvancedStreaming::Start),
57+
InstanceMethod("stop", &osn::AdvancedStreaming::Stop),
5258

5359
StaticAccessor("legacySettings", &osn::AdvancedStreaming::GetLegacySettings, &osn::AdvancedStreaming::SetLegacySettings)});
5460

obs-studio-client/source/global.cpp

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ Napi::Object osn::Global::Init(Napi::Env env, Napi::Object exports)
4242

4343
StaticMethod("getOutputFlagsFromId", &osn::Global::getOutputFlagsFromId),
4444

45-
StaticAccessor("laggedFrames", &osn::Global::laggedFrames, nullptr),
46-
StaticAccessor("totalFrames", &osn::Global::totalFrames, nullptr),
47-
45+
StaticAccessor("laggedFrames", &osn::Global::GetLaggedFrames, nullptr),
46+
StaticAccessor("totalFrames", &osn::Global::GetTotalFrames, nullptr),
4847
StaticAccessor("locale", &osn::Global::getLocale, &osn::Global::setLocale),
4948
StaticAccessor("multipleRendering", &osn::Global::getMultipleRendering, &osn::Global::setMultipleRendering),
49+
50+
StaticAccessor("cpuPercentage", &osn::Global::GetCPUPercentage, nullptr),
51+
StaticAccessor("currentFrameRate", &osn::Global::GetCurrentFrameRate, nullptr),
52+
StaticAccessor("averageFrameRenderTime", &osn::Global::GetAverageTimeToRenderFrame, nullptr),
53+
StaticAccessor("diskSpaceAvailable", &osn::Global::GetDiskSpaceAvailable, nullptr),
54+
StaticAccessor("memoryUsage", &osn::Global::GetMemoryUsage, nullptr),
5055
});
5156
exports.Set("Global", func);
5257
osn::Global::constructor = Napi::Persistent(func);
@@ -154,27 +159,27 @@ Napi::Value osn::Global::getOutputFlagsFromId(const Napi::CallbackInfo &info)
154159
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
155160
}
156161

157-
Napi::Value osn::Global::laggedFrames(const Napi::CallbackInfo &info)
162+
Napi::Value osn::Global::GetLaggedFrames(const Napi::CallbackInfo &info)
158163
{
159164
auto conn = GetConnection(info);
160165
if (!conn)
161166
return info.Env().Undefined();
162167

163-
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "LaggedFrames", {});
168+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetLaggedFrames", {});
164169

165170
if (!ValidateResponse(info, response))
166171
return info.Env().Undefined();
167172

168173
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
169174
}
170175

171-
Napi::Value osn::Global::totalFrames(const Napi::CallbackInfo &info)
176+
Napi::Value osn::Global::GetTotalFrames(const Napi::CallbackInfo &info)
172177
{
173178
auto conn = GetConnection(info);
174179
if (!conn)
175180
return info.Env().Undefined();
176181

177-
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "TotalFrames", {});
182+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetTotalFrames", {});
178183

179184
if (!ValidateResponse(info, response))
180185
return info.Env().Undefined();
@@ -227,3 +232,73 @@ void osn::Global::setMultipleRendering(const Napi::CallbackInfo &info, const Nap
227232

228233
conn->call("Global", "SetMultipleRendering", {ipc::value(value.ToBoolean().Value())});
229234
}
235+
236+
Napi::Value osn::Global::GetCPUPercentage(const Napi::CallbackInfo &info)
237+
{
238+
auto conn = GetConnection(info);
239+
if (!conn)
240+
return info.Env().Undefined();
241+
242+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetCPUPercentage", {});
243+
244+
if (!ValidateResponse(info, response))
245+
return info.Env().Undefined();
246+
247+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
248+
}
249+
250+
Napi::Value osn::Global::GetCurrentFrameRate(const Napi::CallbackInfo &info)
251+
{
252+
auto conn = GetConnection(info);
253+
if (!conn)
254+
return info.Env().Undefined();
255+
256+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetCurrentFrameRate", {});
257+
258+
if (!ValidateResponse(info, response))
259+
return info.Env().Undefined();
260+
261+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
262+
}
263+
264+
Napi::Value osn::Global::GetAverageTimeToRenderFrame(const Napi::CallbackInfo &info)
265+
{
266+
auto conn = GetConnection(info);
267+
if (!conn)
268+
return info.Env().Undefined();
269+
270+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetAverageTimeToRenderFrame", {});
271+
272+
if (!ValidateResponse(info, response))
273+
return info.Env().Undefined();
274+
275+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
276+
}
277+
278+
Napi::Value osn::Global::GetDiskSpaceAvailable(const Napi::CallbackInfo &info)
279+
{
280+
auto conn = GetConnection(info);
281+
if (!conn)
282+
return info.Env().Undefined();
283+
284+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetDiskSpaceAvailable", {});
285+
286+
if (!ValidateResponse(info, response))
287+
return info.Env().Undefined();
288+
289+
return Napi::String::New(info.Env(), response[1].value_str);
290+
}
291+
292+
Napi::Value osn::Global::GetMemoryUsage(const Napi::CallbackInfo &info)
293+
{
294+
auto conn = GetConnection(info);
295+
if (!conn)
296+
return info.Env().Undefined();
297+
298+
std::vector<ipc::value> response = conn->call_synchronous_helper("Global", "GetMemoryUsage", {});
299+
300+
if (!ValidateResponse(info, response))
301+
return info.Env().Undefined();
302+
303+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
304+
}

obs-studio-client/source/global.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ class Global : public Napi::ObjectWrap<osn::Global> {
3131
static Napi::Value addSceneToBackstage(const Napi::CallbackInfo &info);
3232
static Napi::Value removeSceneFromBackstage(const Napi::CallbackInfo &info);
3333
static Napi::Value getOutputFlagsFromId(const Napi::CallbackInfo &info);
34-
static Napi::Value laggedFrames(const Napi::CallbackInfo &info);
35-
static Napi::Value totalFrames(const Napi::CallbackInfo &info);
34+
static Napi::Value GetLaggedFrames(const Napi::CallbackInfo &info);
35+
static Napi::Value GetTotalFrames(const Napi::CallbackInfo &info);
3636
static Napi::Value getLocale(const Napi::CallbackInfo &info);
3737
static void setLocale(const Napi::CallbackInfo &info, const Napi::Value &value);
3838
static Napi::Value getMultipleRendering(const Napi::CallbackInfo &info);
3939
static void setMultipleRendering(const Napi::CallbackInfo &info, const Napi::Value &value);
40+
static Napi::Value GetCPUPercentage(const Napi::CallbackInfo &info);
41+
static Napi::Value GetCurrentFrameRate(const Napi::CallbackInfo &info);
42+
static Napi::Value GetAverageTimeToRenderFrame(const Napi::CallbackInfo &info);
43+
static Napi::Value GetDiskSpaceAvailable(const Napi::CallbackInfo &info);
44+
static Napi::Value GetMemoryUsage(const Napi::CallbackInfo &info);
4045
};
4146
}

obs-studio-client/source/simple-streaming.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Napi::Object osn::SimpleStreaming::Init(Napi::Env env, Napi::Object exports)
3131
Napi::HandleScope scope(env);
3232
Napi::Function func = DefineClass(
3333
env, "SimpleStreaming",
34-
{StaticMethod("create", &osn::SimpleStreaming::Create), StaticMethod("destroy", &osn::SimpleStreaming::Destroy),
34+
{StaticMethod("create", &osn::SimpleStreaming::Create),
35+
StaticMethod("destroy", &osn::SimpleStreaming::Destroy),
3536

3637
InstanceAccessor("videoEncoder", &osn::SimpleStreaming::GetVideoEncoder, &osn::SimpleStreaming::SetVideoEncoder),
3738
InstanceAccessor("audioEncoder", &osn::SimpleStreaming::GetAudioEncoder, &osn::SimpleStreaming::SetAudioEncoder),
@@ -46,8 +47,13 @@ Napi::Object osn::SimpleStreaming::Init(Napi::Env env, Napi::Object exports)
4647
InstanceAccessor("reconnect", &osn::SimpleStreaming::GetReconnect, &osn::SimpleStreaming::SetReconnect),
4748
InstanceAccessor("network", &osn::SimpleStreaming::GetNetwork, &osn::SimpleStreaming::SetNetwork),
4849
InstanceAccessor("video", &osn::SimpleStreaming::GetCanvas, &osn::SimpleStreaming::SetCanvas),
50+
InstanceAccessor("droppedFrames", &osn::SimpleStreaming::GetDroppedFrames, nullptr),
51+
InstanceAccessor("totalFrames", &osn::SimpleStreaming::GetTotalFrames, nullptr),
52+
InstanceAccessor("kbitsPerSec", &osn::SimpleStreaming::GetKBitsPerSec, nullptr),
53+
InstanceAccessor("dataOutput", &osn::SimpleStreaming::GetDataOutput, nullptr),
4954

50-
InstanceMethod("start", &osn::SimpleStreaming::Start), InstanceMethod("stop", &osn::SimpleStreaming::Stop),
55+
InstanceMethod("start", &osn::SimpleStreaming::Start),
56+
InstanceMethod("stop", &osn::SimpleStreaming::Stop),
5157

5258
StaticAccessor("legacySettings", &osn::SimpleStreaming::GetLegacySettings, &osn::SimpleStreaming::SetLegacySettings)});
5359

obs-studio-client/source/streaming.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,59 @@ void osn::Streaming::Stop(const Napi::CallbackInfo &info)
305305

306306
conn->call(className, "Stop", {ipc::value(this->uid), ipc::value(force)});
307307
}
308+
309+
Napi::Value osn::Streaming::GetDroppedFrames(const Napi::CallbackInfo &info)
310+
{
311+
auto conn = GetConnection(info);
312+
if (!conn)
313+
return info.Env().Undefined();
314+
315+
std::vector<ipc::value> response = conn->call_synchronous_helper(className, "GetDroppedFrames", {ipc::value(this->uid)});
316+
317+
if (!ValidateResponse(info, response))
318+
return info.Env().Undefined();
319+
320+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
321+
}
322+
323+
Napi::Value osn::Streaming::GetTotalFrames(const Napi::CallbackInfo &info)
324+
{
325+
auto conn = GetConnection(info);
326+
if (!conn)
327+
return info.Env().Undefined();
328+
329+
std::vector<ipc::value> response = conn->call_synchronous_helper(className, "GetTotalFrames", {ipc::value(this->uid)});
330+
331+
if (!ValidateResponse(info, response))
332+
return info.Env().Undefined();
333+
334+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
335+
}
336+
337+
Napi::Value osn::Streaming::GetKBitsPerSec(const Napi::CallbackInfo &info)
338+
{
339+
auto conn = GetConnection(info);
340+
if (!conn)
341+
return info.Env().Undefined();
342+
343+
std::vector<ipc::value> response = conn->call_synchronous_helper(className, "GetKBitsPerSec", {ipc::value(this->uid)});
344+
345+
if (!ValidateResponse(info, response))
346+
return info.Env().Undefined();
347+
348+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
349+
}
350+
351+
Napi::Value osn::Streaming::GetDataOutput(const Napi::CallbackInfo &info)
352+
{
353+
auto conn = GetConnection(info);
354+
if (!conn)
355+
return info.Env().Undefined();
356+
357+
std::vector<ipc::value> response = conn->call_synchronous_helper(className, "GetDataOutput", {ipc::value(this->uid)});
358+
359+
if (!ValidateResponse(info, response))
360+
return info.Env().Undefined();
361+
362+
return Napi::Number::New(info.Env(), response[1].value_union.ui32);
363+
}

obs-studio-client/source/streaming.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class Streaming : public WorkerSignals {
4848
void SetNetwork(const Napi::CallbackInfo &info, const Napi::Value &value);
4949
Napi::Value GetSignalHandler(const Napi::CallbackInfo &info);
5050
void SetSignalHandler(const Napi::CallbackInfo &info, const Napi::Value &value);
51+
Napi::Value GetDroppedFrames(const Napi::CallbackInfo &info);
52+
Napi::Value GetTotalFrames(const Napi::CallbackInfo &info);
53+
Napi::Value GetKBitsPerSec(const Napi::CallbackInfo &info);
54+
Napi::Value GetDataOutput(const Napi::CallbackInfo &info);
5155

5256
void Start(const Napi::CallbackInfo &info);
5357
void Stop(const Napi::CallbackInfo &info);

obs-studio-client/source/video.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Napi::Value osn::Video::GetEncodedFrames(const Napi::CallbackInfo &info)
7373
if (!conn)
7474
return info.Env().Undefined();
7575

76-
std::vector<ipc::value> response = conn->call_synchronous_helper("Video", "GetTotalFrames", {ipc::value((uint64_t)(this->canvasId))});
76+
std::vector<ipc::value> response = conn->call_synchronous_helper("Video", "GetEncodedFrames", {ipc::value((uint64_t)(this->canvasId))});
7777

7878
if (!ValidateResponse(info, response))
7979
return info.Env().Undefined();

obs-studio-server/source/nodeobs_api.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include "osn-audio-track.hpp"
4242
#include "memory-manager.h"
4343

44+
//to destroy cpu usage object
45+
#include "osn-global.hpp"
46+
4447
#include <sys/types.h>
4548

4649
#ifdef __APPLE
@@ -1601,6 +1604,9 @@ void OBS_API::destroyOBS_API(void)
16011604
debug_enum_sources(" on destroyOBS_API");
16021605
os_cpu_usage_info_destroy(cpuUsageInfo);
16031606

1607+
//temp until new API migration is complete
1608+
osn::Global::StopCPUMonitoring();
1609+
16041610
#ifdef _WIN32
16051611
config_t *basicConfig = ConfigManager::getInstance().getBasic();
16061612
if (basicConfig) {

0 commit comments

Comments
 (0)