From a0616bce59c27e91f5f83c4934e347e71045ca4f Mon Sep 17 00:00:00 2001 From: Emmanuel Pacaud Date: Tue, 13 May 2025 15:42:34 +0200 Subject: [PATCH 1/2] gvstream: fix underrun count Count only one underrun by frame id. --- src/arvgvstream.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/arvgvstream.c b/src/arvgvstream.c index 13296a48b..30be85927 100644 --- a/src/arvgvstream.c +++ b/src/arvgvstream.c @@ -162,6 +162,8 @@ struct _ArvGvStreamThreadData { gboolean use_packet_socket; + guint64 underrun_frame_id; + /* Statistics */ guint64 n_completed_buffers; @@ -373,10 +375,13 @@ _find_frame_data (ArvGvStreamThreadData *thread_data, buffer = arv_stream_pop_input_buffer (thread_data->stream); if (buffer == NULL) { - thread_data->n_underruns++; - + if (thread_data->underrun_frame_id != frame_id) { + thread_data->n_underruns++; + thread_data->underrun_frame_id = frame_id; + } return NULL; } + thread_data->underrun_frame_id = 0; n_packets = _compute_n_expected_packets (packet, buffer->priv->allocated_size, From afd8a4bc0bdd347e45b8b2789eb0cd91eb81cb24 Mon Sep 17 00:00:00 2001 From: Emmanuel Pacaud Date: Tue, 13 May 2025 17:54:48 +0200 Subject: [PATCH 2/2] gvstream: mark buffer status as underrun if buffer was late in input queue --- src/arvbuffer.h | 4 +++- src/arvgvstream.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/arvbuffer.h b/src/arvbuffer.h index 580cfb8fb..e7dacef1a 100644 --- a/src/arvbuffer.h +++ b/src/arvbuffer.h @@ -44,6 +44,7 @@ G_BEGIN_DECLS * @ARV_BUFFER_STATUS_FILLING: the image is currently being filled * @ARV_BUFFER_STATUS_ABORTED: the filling was aborted before completion * @ARV_BUFFER_STATUS_PAYLOAD_NOT_SUPPORTED: payload not yet supported + * @ARV_BUFFER_STATUS_UNDERRUN: buffer found late in input queue and timeout reached before all packets are received */ typedef enum { @@ -56,7 +57,8 @@ typedef enum { ARV_BUFFER_STATUS_SIZE_MISMATCH, ARV_BUFFER_STATUS_FILLING, ARV_BUFFER_STATUS_ABORTED, - ARV_BUFFER_STATUS_PAYLOAD_NOT_SUPPORTED + ARV_BUFFER_STATUS_PAYLOAD_NOT_SUPPORTED, + ARV_BUFFER_STATUS_UNDERRUN } ArvBufferStatus; /** diff --git a/src/arvgvstream.c b/src/arvgvstream.c index 30be85927..ba52b61b8 100644 --- a/src/arvgvstream.c +++ b/src/arvgvstream.c @@ -123,6 +123,7 @@ typedef struct { gboolean resend_ratio_reached; gboolean extended_ids; + gboolean underrun; } ArvGvStreamFrameData; struct _ArvGvStreamThreadData { @@ -381,7 +382,6 @@ _find_frame_data (ArvGvStreamThreadData *thread_data, } return NULL; } - thread_data->underrun_frame_id = 0; n_packets = _compute_n_expected_packets (packet, buffer->priv->allocated_size, @@ -393,11 +393,13 @@ _find_frame_data (ArvGvStreamThreadData *thread_data, thread_data->callback (thread_data->callback_data, ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE, buffer); + thread_data->underrun_frame_id = 0; return NULL; } frame = g_new0 (ArvGvStreamFrameData, 1); + frame->underrun = thread_data->underrun_frame_id == frame_id; frame->disable_resend_request = FALSE; frame->frame_id = frame_id; @@ -436,6 +438,8 @@ _find_frame_data (ArvGvStreamThreadData *thread_data, arv_histogram_fill (thread_data->histogram, 1, 0); + thread_data->underrun_frame_id = 0; + return frame; } @@ -838,7 +842,9 @@ _check_frame_completion (ArvGvStreamThreadData *thread_data, * acquisition start. */ (frame->frame_id != thread_data->last_frame_id || frame->last_valid_packet != 0) && time_us - frame->last_packet_time_us >= thread_data->frame_retention_us) { - frame->buffer->priv->status = ARV_BUFFER_STATUS_TIMEOUT; + frame->buffer->priv->status = frame->underrun ? + ARV_BUFFER_STATUS_UNDERRUN : + ARV_BUFFER_STATUS_TIMEOUT; arv_warning_stream_thread ("[GvStream::check_frame_completion] Timeout for frame %" G_GUINT64_FORMAT " at dt = %" G_GUINT64_FORMAT, frame->frame_id, time_us - frame->first_packet_time_us);