-
Notifications
You must be signed in to change notification settings - Fork 7
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
Added virtual function uca_camera_grab_live
#97
Open
gabs1234
wants to merge
1
commit into
master
Choose a base branch
from
live_images
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1232,6 +1232,101 @@ uca_camera_grab (UcaCamera *camera, gpointer data, GError **error) | |
return result; | ||
} | ||
|
||
/** | ||
* uca_camera_grab_live: | ||
* @camera: A #UcaCamera object | ||
* @data: (type gulong): Pointer to suitably sized data buffer. Must not be | ||
* %NULL. | ||
* @error: Location to store a #UcaCameraError error or %NULL | ||
* | ||
* Graba single frame and store the result in @data. | ||
* | ||
* You must have called uca_camera_start_recording() before, otherwise you will | ||
* get a #UCA_CAMERA_ERROR_NOT_RECORDING error. This function does not interfere | ||
* with uca_camera_grab(). | ||
*/ | ||
gboolean | ||
uca_camera_grab_live (UcaCamera *camera, gpointer data, GError **error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
{ | ||
UcaCameraClass *klass; | ||
gboolean result = FALSE; | ||
|
||
/* FIXME: this prevents accessing two independent cameras simultanously. */ | ||
static GMutex mutex; | ||
|
||
g_return_val_if_fail (UCA_IS_CAMERA(camera), FALSE); | ||
|
||
klass = UCA_CAMERA_GET_CLASS (camera); | ||
|
||
g_return_val_if_fail (klass != NULL, FALSE); | ||
g_return_val_if_fail (klass->grab_live != NULL, FALSE); | ||
g_return_val_if_fail (data != NULL, FALSE); | ||
|
||
if (!camera->priv->buffered) { | ||
g_mutex_lock (&mutex); | ||
|
||
if (!camera->priv->is_recording && !camera->priv->is_readout) { | ||
g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, | ||
"Camera is neither recording nor in readout mode"); | ||
} | ||
else { | ||
#ifdef WITH_PYTHON_MULTITHREADING | ||
if (Py_IsInitialized ()) { | ||
PyGILState_STATE state = PyGILState_Ensure (); | ||
Py_BEGIN_ALLOW_THREADS | ||
|
||
g_mutex_lock (&access_lock); | ||
result = (*klass->grab_live) (camera, data, error); | ||
g_mutex_unlock (&access_lock); | ||
|
||
Py_END_ALLOW_THREADS | ||
PyGILState_Release (state); | ||
} | ||
else { | ||
g_mutex_lock (&access_lock); | ||
result = (*klass->grab_live) (camera, data, error); | ||
g_mutex_unlock (&access_lock); | ||
} | ||
#else | ||
g_mutex_lock (&access_lock); | ||
result = (*klass->grab_live) (camera, data, error); | ||
g_mutex_unlock (&access_lock); | ||
#endif | ||
} | ||
|
||
g_mutex_unlock (&mutex); | ||
} | ||
else { | ||
gpointer buffer; | ||
|
||
if (camera->priv->ring_buffer == NULL) | ||
return FALSE; | ||
|
||
/* | ||
* Spin-lock until we can read something. This shouldn't happen to | ||
* often, as buffering is usually used in those cases when the camera is | ||
* faster than the software. | ||
*/ | ||
while (!uca_ring_buffer_available (camera->priv->ring_buffer)) { | ||
if (camera->priv->cancelling_grab) { | ||
return FALSE; | ||
} | ||
} | ||
|
||
buffer = uca_ring_buffer_get_read_pointer (camera->priv->ring_buffer); | ||
|
||
if (buffer == NULL) { | ||
g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_END_OF_STREAM, | ||
"Ring buffer is empty"); | ||
} | ||
else { | ||
memcpy (data, buffer, uca_ring_buffer_get_block_size (camera->priv->ring_buffer)); | ||
result = TRUE; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* uca_camera_readout: | ||
* @camera: A #UcaCamera object | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make one function which is called from both, the normal
grab
andgrab_live
instead of duplicating code?