From 419c62c048cd8b59b15227b47c2d1132acc2b033 Mon Sep 17 00:00:00 2001 From: Andrey Kalugin Date: Mon, 15 Jan 2024 18:55:41 +0100 Subject: [PATCH] Add 'scIsConnected()' method to API to make application connection waiting more flexible. --- src/softcam/softcam.cpp | 5 +++++ src/softcam/softcam.def | 1 + src/softcam/softcam.h | 10 ++++++++++ src/softcamcore/SenderAPI.cpp | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/src/softcam/softcam.cpp b/src/softcam/softcam.cpp index cb4f771..703e95f 100644 --- a/src/softcam/softcam.cpp +++ b/src/softcam/softcam.cpp @@ -176,3 +176,8 @@ extern "C" bool scWaitForConnection(scCamera camera, float timeout) { return softcam::sender::WaitForConnection(camera, timeout); } + +extern "C" bool scIsConnected(scCamera camera) +{ + return softcam::sender::IsConnected(camera); +} diff --git a/src/softcam/softcam.def b/src/softcam/softcam.def index 75f5657..74f533e 100644 --- a/src/softcam/softcam.def +++ b/src/softcam/softcam.def @@ -8,3 +8,4 @@ EXPORTS scDeleteCamera scSendFrame scWaitForConnection + scIsConnected diff --git a/src/softcam/softcam.h b/src/softcam/softcam.h index 8f917fc..01e9746 100644 --- a/src/softcam/softcam.h +++ b/src/softcam/softcam.h @@ -74,4 +74,14 @@ extern "C" this function returns `false`. */ bool SOFTCAM_API scWaitForConnection(scCamera camera, float timeout = 0.0f); + + /* + This function reports if an application is connected to the specified + virtual camera. + + This function returns `true` if the virtual camera has ever been + accessed by an application before this function returns. Otherwise, + this function returns `false`. + */ + bool SOFTCAM_API scIsConnected(scCamera camera); } diff --git a/src/softcamcore/SenderAPI.cpp b/src/softcamcore/SenderAPI.cpp index 8c759b7..defb4e0 100644 --- a/src/softcamcore/SenderAPI.cpp +++ b/src/softcamcore/SenderAPI.cpp @@ -111,5 +111,15 @@ bool WaitForConnection(CameraHandle camera, float timeout) return false; } +bool IsConnected(CameraHandle camera) +{ + Camera* target = static_cast(camera); + if (target && s_camera.load() == target) + { + return target->m_frame_buffer.connected(); + } + return false; +} + } //namespace sender } //namespace softcam