Skip to content

Wip/gv underrun fixes#1009

Draft
EmmanuelP wants to merge 2 commits intomainfrom
wip/gv-underrun-fixes
Draft

Wip/gv underrun fixes#1009
EmmanuelP wants to merge 2 commits intomainfrom
wip/gv-underrun-fixes

Conversation

@EmmanuelP
Copy link
Contributor

An incomplete attempt to detect underrun conditions, as a fix to #849 .

The complete implementation should take resent packets into account.

@EmmanuelP EmmanuelP force-pushed the wip/gv-underrun-fixes branch from afd8a4b to 7743c7c Compare February 8, 2026 20:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit “underrun” classification to the GigE Vision streaming path so frames that time out due to late buffer availability can be distinguished from genuine network/packet-loss timeouts (related to #849).

Changes:

  • Track a per-frame underrun condition in arvgvstream and emit ARV_BUFFER_STATUS_UNDERRUN on completion-timeout for those frames.
  • De-duplicate underrun statistics counting to avoid incrementing underruns for every packet while no input buffers are available.
  • Extend ArvBufferStatus with a new ARV_BUFFER_STATUS_UNDERRUN value and document it.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/arvgvstream.c Tracks underrun state per frame and maps timeout completion to UNDERRUN when appropriate.
src/arvbuffer.h Adds new public buffer status enum value and gtk-doc entry for underruns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 165 to +167

guint64 underrun_frame_id;

Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

underrun_frame_id is indented with spaces while other members in _ArvGvStreamThreadData use tabs. Please fix indentation to match the existing formatting conventions in this struct.

Copilot uses AI. Check for mistakes.
Comment on lines 377 to +383

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;
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

underrun_frame_id is used to de-duplicate underrun counting purely by comparing the raw frame_id. For non-extended IDs the frame id wraps (16-bit), so during long buffer starvation this can undercount underruns and can also mis-tag a later wrapped frame as an underrun. Consider de-duplicating using a monotonic sequence derived from last_frame_id/frame_id_inc (or track an explicit underrun-active generation) instead of the raw frame_id alone.

Copilot uses AI. Check for mistakes.
Comment on lines 849 to 850
arv_warning_stream_thread ("[GvStream::check_frame_completion] Timeout for frame %"
G_GUINT64_FORMAT " at dt = %" G_GUINT64_FORMAT,
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When frame->underrun is true the buffer status is set to ARV_BUFFER_STATUS_UNDERRUN, but the log message still says "Timeout for frame". This is misleading for users diagnosing underruns; update the message (and/or include the chosen status) so logs match the emitted buffer status.

Suggested change
arv_warning_stream_thread ("[GvStream::check_frame_completion] Timeout for frame %"
G_GUINT64_FORMAT " at dt = %" G_GUINT64_FORMAT,
arv_warning_stream_thread ("[GvStream::check_frame_completion] %s for frame %"
G_GUINT64_FORMAT " at dt = %" G_GUINT64_FORMAT,
frame->underrun ? "Underrun" : "Timeout",

Copilot uses AI. Check for mistakes.
Comment on lines 845 to +847
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 :
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces a new externally visible status (ARV_BUFFER_STATUS_UNDERRUN) and changes the observable outcome of _check_frame_completion. There doesn’t appear to be test coverage ensuring underrun-induced frame completion is classified as UNDERRUN (and not TIMEOUT) in the GigE stream path; adding a regression test (e.g., using the fake GigE stream and deliberately starving input buffers) would help prevent regressions.

Copilot uses AI. Check for mistakes.
* @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
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ARV_BUFFER_STATUS_UNDERRUN docstring is a bit ambiguous about what condition triggers it. The implementation sets it when no input buffer was available for the frame at some point (buffer underrun) and the frame later hits the retention timeout; consider rewording to reflect that specific trigger so API users can distinguish it from network/packet-loss timeouts.

Suggested change
* @ARV_BUFFER_STATUS_UNDERRUN: buffer found late in input queue and timeout reached before all packets are received
* @ARV_BUFFER_STATUS_UNDERRUN: at some point no input buffer was available for this frame (buffer underrun), and when a buffer later became available the frame had already exceeded its retention timeout (distinct from network/packet-loss timeouts)

Copilot uses AI. Check for mistakes.
Comment on lines 125 to 127
gboolean extended_ids;
gboolean underrun;
} ArvGvStreamFrameData;
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new underrun field is indented with spaces while surrounding struct members use tabs. This makes the struct formatting inconsistent; please align indentation with the rest of the file’s style.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments