Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'scIsConnected()' method to API to make application connection waiting more flexible. #51

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/softcam/softcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/softcam/softcam.def
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ EXPORTS
scDeleteCamera
scSendFrame
scWaitForConnection
scIsConnected
10 changes: 10 additions & 0 deletions src/softcam/softcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 10 additions & 0 deletions src/softcamcore/SenderAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,15 @@ bool WaitForConnection(CameraHandle camera, float timeout)
return false;
}

bool IsConnected(CameraHandle camera)
{
Camera* target = static_cast<Camera*>(camera);
if (target && s_camera.load() == target)
{
return target->m_frame_buffer.connected();
}
return false;
}

} //namespace sender
} //namespace softcam
1 change: 1 addition & 0 deletions src/softcamcore/SenderAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CameraHandle CreateCamera(int width, int height, float framerate = 60.0f);
void DeleteCamera(CameraHandle camera);
void SendFrame(CameraHandle camera, const void* image_bits);
bool WaitForConnection(CameraHandle camera, float timeout = 0.0f);
bool IsConnected(CameraHandle camera);

} //namespace sender
} //namespace softcam
Loading