Skip to content

Commit

Permalink
fakecamera: add a destroy notifier to set_fill_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Jan 23, 2025
1 parent 44edc40 commit 4f63bd1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
9 changes: 5 additions & 4 deletions docs/reference/aravis/porting-0.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ function, which creates interface native buffers if possible.
has a third out parameter returning the number of buffer owned by the stream
receiving thread.

#### arv_camera_create_stream and arv_device_create_stream
#### arv_camera_create_stream, arv_device_create_stream and arv_fake_camera_set_fill_pattern

[method@Aravis.Camera.create_stream] and [method@Aravis.Device.create_stream]
take an additional GDestroyNotify parameter, that will be called when the
callback closure data are not useful anymore, and can be destroyed.
[method@Aravis.Camera.create_stream], [method@Aravis.Device.create_stream] and
[method@Aravis.FakeCamera.set_fill_pattern] take an additional GDestroyNotify
parameter, that will be called when the callback closure data are not useful
anymore, and can be destroyed.
23 changes: 20 additions & 3 deletions src/arvfakecamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef struct {

ArvFakeCameraFillPattern fill_pattern_callback;
void *fill_pattern_data;
GDestroyNotify fill_pattern_destroy;
} ArvFakeCameraPrivate;

struct _ArvFakeCamera {
Expand Down Expand Up @@ -716,27 +717,35 @@ arv_fake_camera_diagonal_ramp (ArvBuffer *buffer, void *fill_pattern_data,
/**
* arv_fake_camera_set_fill_pattern:
* @camera: a #ArvFakeCamera
* @fill_pattern_callback: (scope call) (closure fill_pattern_data) : callback for image filling
* @fill_pattern_data: image filling user data
* @fill_pattern_callback: (nullable) (scope call) (closure fill_pattern_data) (destroy destroy): callback for image filling
* @fill_pattern_data: (allow-none): image filling user data
* @destroy: (nullable): destroy notifier of @fill_pattern_data
*
* Sets the fill pattern callback for custom test images.
*/

void
arv_fake_camera_set_fill_pattern (ArvFakeCamera *camera,
ArvFakeCameraFillPattern fill_pattern_callback,
void *fill_pattern_data)
void *fill_pattern_data,
GDestroyNotify destroy)
{
g_return_if_fail (ARV_IS_FAKE_CAMERA (camera));

g_mutex_lock (&camera->priv->fill_pattern_mutex);

if (camera->priv->fill_pattern_data != NULL &&
camera->priv->fill_pattern_destroy != NULL)
camera->priv->fill_pattern_destroy (camera->priv->fill_pattern_data);

if (fill_pattern_callback != NULL) {
camera->priv->fill_pattern_callback = fill_pattern_callback;
camera->priv->fill_pattern_data = fill_pattern_data;
camera->priv->fill_pattern_destroy = destroy;
} else {
camera->priv->fill_pattern_callback = arv_fake_camera_diagonal_ramp;
camera->priv->fill_pattern_data = NULL;
camera->priv->fill_pattern_destroy = NULL;
}

g_mutex_unlock (&camera->priv->fill_pattern_mutex);
Expand Down Expand Up @@ -1106,6 +1115,14 @@ arv_fake_camera_finalize (GObject *object)
{
ArvFakeCamera *fake_camera = ARV_FAKE_CAMERA (object);

g_mutex_lock (&fake_camera->priv->fill_pattern_mutex);

if (fake_camera->priv->fill_pattern_data != NULL &&
fake_camera->priv->fill_pattern_destroy != NULL)
fake_camera->priv->fill_pattern_destroy (fake_camera->priv->fill_pattern_data);

g_mutex_unlock (&fake_camera->priv->fill_pattern_mutex);

g_mutex_clear (&fake_camera->priv->fill_pattern_mutex);
g_clear_pointer (&fake_camera->priv->memory, g_free);
g_clear_pointer (&fake_camera->priv->genicam_xml, g_free);
Expand Down
3 changes: 2 additions & 1 deletion src/arvfakecamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ ARV_API guint32 arv_fake_camera_get_heartbeat_timeout (ArvFakeCamera *camera)

ARV_API void arv_fake_camera_set_fill_pattern (ArvFakeCamera *camera,
ArvFakeCameraFillPattern fill_pattern_callback,
void *fill_pattern_data);
void *fill_pattern_data,
GDestroyNotify destroy);
ARV_API void arv_fake_camera_set_trigger_frequency (ArvFakeCamera *camera, double frequency);
ARV_API gboolean arv_fake_camera_is_in_free_running_mode (ArvFakeCamera *camera);
ARV_API gboolean arv_fake_camera_is_in_software_trigger_mode (ArvFakeCamera *camera);
Expand Down
4 changes: 2 additions & 2 deletions tests/fake.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ fake_stream_test (void)
g_assert (ARV_IS_STREAM (stream));
g_assert (error == NULL);

arv_fake_camera_set_fill_pattern (fake_camera, fill_pattern_cb, &counter);
arv_fake_camera_set_fill_pattern (fake_camera, fill_pattern_cb, &counter, NULL);

payload = arv_camera_get_payload (camera, NULL);
arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL));
Expand All @@ -359,7 +359,7 @@ fake_stream_test (void)
buffer = arv_stream_pop_buffer (stream);
arv_camera_stop_acquisition (camera, NULL);

arv_fake_camera_set_fill_pattern (fake_camera, NULL, NULL);
arv_fake_camera_set_fill_pattern (fake_camera, NULL, NULL, NULL);

g_assert_cmpint (counter, ==, 1);

Expand Down

0 comments on commit 4f63bd1

Please sign in to comment.