Skip to content

Commit

Permalink
uvstream: be easy on CPU use when the input queue is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Jul 28, 2023
1 parent 1b115e8 commit 603a33f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/arvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ arv_stream_pop_input_buffer (ArvStream *stream)
return g_async_queue_try_pop (priv->input_queue);
}

ArvBuffer *
arv_stream_timeout_pop_input_buffer (ArvStream *stream, guint64 timeout)
{
ArvStreamPrivate *priv = arv_stream_get_instance_private (stream);

g_return_val_if_fail (ARV_IS_STREAM (stream), NULL);

return g_async_queue_timeout_pop (priv->input_queue, timeout);
}

void
arv_stream_push_output_buffer (ArvStream *stream, ArvBuffer *buffer)
{
Expand Down
1 change: 1 addition & 0 deletions src/arvstreamprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
G_BEGIN_DECLS

ArvBuffer * arv_stream_pop_input_buffer (ArvStream *stream);
ArvBuffer * arv_stream_timeout_pop_input_buffer (ArvStream *stream, guint64 timeout);
void arv_stream_push_output_buffer (ArvStream *stream, ArvBuffer *buffer);
void arv_stream_take_init_error (ArvStream *device, GError *error);

Expand Down
5 changes: 4 additions & 1 deletion src/arvuvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#define ARV_UV_STREAM_MAXIMUM_TRANSFER_SIZE (1024*1024*1)
#define ARV_UV_STREAM_MAXIMUM_SUBMIT_TOTAL (8*1024*1024)

#define ARV_UV_STREAM_POP_INPUT_BUFFER_TIMEOUT_US 10000

enum {
ARV_UV_STREAM_PROPERTY_0,
ARV_UV_STREAM_PROPERTY_USB_MODE
Expand Down Expand Up @@ -463,7 +465,8 @@ arv_uv_stream_thread_async (void *data)
arv_uv_device_is_connected (thread_data->uv_device)) {
ArvUvStreamBufferContext* ctx;

buffer = arv_stream_pop_input_buffer (thread_data->stream);
buffer = arv_stream_timeout_pop_input_buffer (thread_data->stream,
ARV_UV_STREAM_POP_INPUT_BUFFER_TIMEOUT_US);

if( buffer == NULL ) {
thread_data->statistics.n_underruns += 1;
Expand Down

0 comments on commit 603a33f

Please sign in to comment.