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 Feb 14, 2022
1 parent 5b2d0c4 commit 1e5b935
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/arvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 @@ -58,12 +58,19 @@ 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);
};

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 @@ -114,6 +114,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)
{
Expand Down
7 changes: 2 additions & 5 deletions viewer/arvviewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,6 @@ start_video (ArvViewer *viewer)
GstElement *videoconvert;
GstCaps *caps;
ArvPixelFormat pixel_format;
unsigned payload;
unsigned i;
gint width, height;
const char *caps_string;

Expand Down Expand Up @@ -1248,9 +1246,8 @@ start_video (ArvViewer *viewer)
}

arv_stream_set_emit_signals (viewer->stream, TRUE);
payload = arv_camera_get_payload (viewer->camera, NULL);
for (i = 0; i < 10; 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 1e5b935

Please sign in to comment.