Skip to content

Commit

Permalink
stream: device specific buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Nov 5, 2023
1 parent 76819cb commit ef95994
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/arvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ArvStream, arv_stream, G_TYPE_OBJECT,
G_ADD_PRIVATE (ArvStream)
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, arv_stream_initable_iface_init))

unsigned int
arv_stream_create_buffers (ArvStream *stream, unsigned int n_buffers,
void *user_data, GDestroyNotify user_data_destroy_func,
GError **error)
{
ArvStreamClass *stream_class;
ArvStreamPrivate *priv = arv_stream_get_instance_private (stream);
size_t payload_size;
unsigned int i;

g_return_val_if_fail (ARV_IS_STREAM (stream), 0);
g_return_val_if_fail (n_buffers > 0, 0);
g_return_val_if_fail (ARV_IS_DEVICE (priv->device), 0);

payload_size = arv_device_get_integer_feature_value (priv->device, "PayloadSize", error);
if (payload_size < 1)
return 0;

stream_class = ARV_STREAM_GET_CLASS (stream);
if (stream_class->create_buffers != NULL)
return stream_class->create_buffers (stream, n_buffers, payload_size, user_data, user_data_destroy_func);

for (i = 0; i < n_buffers; i++)
arv_stream_push_buffer (stream, arv_buffer_new_full (payload_size, NULL,
user_data, user_data_destroy_func));

return n_buffers;
}

/**
* arv_stream_push_buffer:
* @stream: a #ArvStream
Expand Down
7 changes: 7 additions & 0 deletions src/arvstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ struct _ArvStreamClass {
void (*start_thread) (ArvStream *stream);
void (*stop_thread) (ArvStream *stream);

unsigned int (*create_buffers) (ArvStream *stream, unsigned int n_buffers, size_t size,
void *user_data, GDestroyNotify user_data_destroy_func);

/* signals */
void (*new_buffer) (ArvStream *stream);
};
Expand All @@ -84,6 +87,10 @@ struct _ArvStreamClass {

typedef void (*ArvStreamCallback) (void *user_data, ArvStreamCallbackType type, ArvBuffer *buffer);

ARV_API unsigned int arv_stream_create_buffers (ArvStream *stream, unsigned int n_buffers,
void *user_data, GDestroyNotify user_data_destroy_func,
GError **error);

ARV_API void arv_stream_push_buffer (ArvStream *stream, ArvBuffer *buffer);
ARV_API ArvBuffer * arv_stream_pop_buffer (ArvStream *stream);
ARV_API ArvBuffer * arv_stream_try_pop_buffer (ArvStream *stream);
Expand Down
19 changes: 19 additions & 0 deletions src/arvuvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ typedef struct {

G_DEFINE_TYPE_WITH_CODE (ArvUvStream, arv_uv_stream, ARV_TYPE_STREAM, G_ADD_PRIVATE (ArvUvStream))

typedef struct {
void *buffer;
gboolean is_dev_mem;
void *user_data;
GDestroyNotify user_data_destroy_func;
} ArvUvStreamBufferInfos;

static void
_destroy_buffer (void *abstract_data)
{
}

static unsigned int
arv_uv_stream_create_buffers (ArvStream *stream, unsigned int n_buffers, size_t size,
void *user_data, GDestroyNotify user_data_destroy_func)
{
return 0;
}

static void
arv_uv_stream_buffer_context_wait_transfer_completed (ArvUvStreamBufferContext* ctx, gint64 timeout_ms)
{
Expand Down
14 changes: 5 additions & 9 deletions viewer/arvviewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ static void
exposure_spin_cb (GtkSpinButton *spin_button, ArvViewer *viewer)
{
double exposure = gtk_spin_button_get_value (spin_button);
double scaled_exposure = viewer->exposure_time_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
double scaled_exposure = viewer->exposure_time_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
arv_viewer_value_to_log (exposure, viewer->exposure_min, viewer->exposure_max) : exposure;

gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (viewer->auto_exposure_toggle), FALSE);
Expand All @@ -514,7 +514,7 @@ static void
gain_spin_cb (GtkSpinButton *spin_button, ArvViewer *viewer)
{
double gain = gtk_spin_button_get_value (spin_button);
double scaled_gain = viewer->gain_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
double scaled_gain = viewer->gain_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
arv_viewer_value_to_log (gain, viewer->gain_min, viewer->gain_max) : gain;

gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (viewer->auto_gain_toggle), FALSE);
Expand Down Expand Up @@ -591,7 +591,7 @@ update_exposure_cb (void *data)
double scaled_exposure;

exposure = arv_camera_get_exposure_time (viewer->camera, NULL);
scaled_exposure = viewer->exposure_time_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
scaled_exposure = viewer->exposure_time_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
arv_viewer_value_to_log (exposure, viewer->exposure_min, viewer->exposure_max) : exposure;

g_signal_handler_block (viewer->exposure_hscale, viewer->exposure_hscale_changed);
Expand Down Expand Up @@ -637,7 +637,7 @@ update_gain_cb (void *data)
double scaled_gain;

gain = arv_camera_get_gain (viewer->camera, NULL);
scaled_gain = viewer->gain_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
scaled_gain = viewer->gain_representation == ARV_GC_REPRESENTATION_LOGARITHMIC ?
arv_viewer_value_to_log (gain, viewer->gain_min, viewer->gain_max) : gain;

g_signal_handler_block (viewer->gain_hscale, viewer->gain_hscale_changed);
Expand Down Expand Up @@ -1408,8 +1408,6 @@ start_video (ArvViewer *viewer)
GstElement *videoconvert;
GstCaps *caps;
ArvPixelFormat pixel_format;
unsigned payload;
unsigned i;
gint width, height;
const char *caps_string;
char *component;
Expand Down Expand Up @@ -1452,9 +1450,7 @@ start_video (ArvViewer *viewer)
}

arv_stream_set_emit_signals (viewer->stream, TRUE);
payload = arv_camera_get_payload (viewer->camera, NULL);
for (i = 0; i < ARV_VIEWER_N_BUFFERS; i++)
arv_stream_push_buffer (viewer->stream, arv_buffer_new (payload, NULL));
arv_stream_create_buffers (viewer->stream, 10, NULL, NULL, NULL);

set_camera_widgets(viewer);
pixel_format = arv_camera_get_pixel_format (viewer->camera, NULL);
Expand Down

0 comments on commit ef95994

Please sign in to comment.