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