Skip to content

linux-v4l2: Avoid stopping capture on AVERROR(EAGAIN) #12303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

JiangXsong
Copy link
Contributor

Description

When capturing video from UVC devices using H.264 at higher resolutions (e.g. 2560x1440 or higher), video capture frequently stops unexpectedly. This patch makes a minor adjustment to the decoder logic in v4l2_decode_frame() to continue capturing instead of stopping on AVERROR(EAGAIN).

Motivation and Context

Currently, the v4l2_decode_frame() function treats all negative return values from avcodec_receive_frame() as fatal errors. However, AVERROR(EAGAIN) is a common return code that simply indicates that more data is needed before a frame can be decoded. Treating this as an error causes the video capture to stop unnecessarily, especially with high-resolution formats like H.264.

This change allows the decoder to continue feeding data to the codec even after receiving AVERROR(EAGAIN), ensuring a more stable and continuous capture experience.

How Has This Been Tested?

  • Platform: Ubuntu 24.04
  • Device: UVC device (bulk mode) supporting H.264
  • Resolution: 2560x1440 @ 30fps, 3840x2160 @ 30fps and 4096x2160 @ 30fps
  • Verified that video capture continues normally without interruption
  • Monitored logs to confirm that AVERROR(EAGAIN) no longer causes capture to stop

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@WizardCM WizardCM added Bug Fix Non-breaking change which fixes an issue Linux Affects Linux labels Jun 21, 2025
@stephematician
Copy link
Contributor

Looks good! It looks like there should be a #include <libavutil/error.h> - otherwise the macro AVERROR might not be defined.

@JiangXsong
Copy link
Contributor Author

Thank you for the suggestion!
I’ve added the include explicitly in v4l2-decoder.c to ensure compatibility across different build environments.

@RytoEX RytoEX requested a review from kkartaltepe June 26, 2025 17:55
@norihiro
Copy link
Contributor

norihiro commented Jul 5, 2025

The commit message should be wrapped to 72 columns max.

Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

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

Nit: Capitalize the first word after the prefix in the commit message.

linux-v4l2: Avoid stopping capture on AVERROR(EAGAIN)

@JiangXsong JiangXsong force-pushed the linux-v4l2-bugfix branch 2 times, most recently from 2c3e434 to a40ad95 Compare July 14, 2025 02:09
@JiangXsong JiangXsong requested a review from RytoEX July 14, 2025 02:33
@RytoEX RytoEX changed the title linux-v4l2: avoid stopping capture on AVERROR(EAGAIN) linux-v4l2: Avoid stopping capture on AVERROR(EAGAIN) Jul 14, 2025
@JiangXsong JiangXsong force-pushed the linux-v4l2-bugfix branch 2 times, most recently from 91b0ebd to 2e19672 Compare July 16, 2025 06:28
Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

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

The commit message appears to contain the commit message of another commit. Please fix that.

@JiangXsong JiangXsong force-pushed the linux-v4l2-bugfix branch 3 times, most recently from be15037 to d362dc4 Compare July 17, 2025 01:44
v4l2-decoder: continue sending frame to codec
if avcodec_receive_frame() returns AVERROR(EAGAIN)
@JiangXsong JiangXsong requested a review from RytoEX July 18, 2025 01:45
Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

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

Seems fine.

@RytoEX RytoEX merged commit bd6c471 into obsproject:master Jul 18, 2025
15 checks passed
@RytoEX RytoEX added this to the OBS Studio 31.1 milestone Jul 18, 2025
@JiangXsong JiangXsong deleted the linux-v4l2-bugfix branch July 21, 2025 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue Linux Affects Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants