Repository navigation
Fix black preview when the phone refuses USB transfers (0.1.1) - #23
Merged
Merged
Conversation
On a Pixel 7 Pro short of memory the kernel refused libuvc's 96 KB isochronous transfers with ENOMEM. libuvc freed each refused transfer, and even reported success when the first one failed, so the stream lost its transfers and went black while the app still said "streaming". - New libuvc patch: transfers of 32 KB at most, refused or failed transfers are parked and queued again from the event thread, parked transfers are freed on stop, and a submit hook for tests. - usbcam.cpp: retries parked transfers, resets the video interface to alt 0 before negotiating, and resets the USB port once if the camera still refuses to start with an I/O error (seen after the app was killed mid-stream). Debug builds read debug.hardline.usbfail to fail a share of submissions on purpose. - CameraController: restarts a stream that delivers no frames for 5 s, and shows an error after 3 restarts in a minute. - Version 0.1.1 (versionCode 2), changelog and docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a Pixel 7 Pro (Android 17) with the 349c:8319 endoscope, the preview stayed black while the app said "Now streaming MJPG 640x480 25 fps".
Logging added to libuvc showed the cause. libuvc queues 100 isochronous transfers of 96 KB each, and the kernel needs one physically contiguous buffer per transfer. With the phone short of memory,
USBDEVFS_SUBMITURBfailed with errno 12 (ENOMEM) from the 2nd to 5th transfer onward. libuvc freed every refused transfer. If even the first submit failed, it still returned success. The stream lost its transfers one by one and went quiet with no error.Changes
patches/libuvc-0.0.8-transfers.patch(new):uvc_retry_parked_transfers()queues parked transfers again, at most every 20 ms.uvc_stream_stopfrees parked transfers so it cannot wait forever.uvc_submit_hooklets tests make submissions fail.usbcam.cpp:videoLockkeeps that away from stream start and stop; the event thread only usestry_lock, so stopping cannot deadlock.setprop debug.hardline.usbfail Nfails N% of submissions.CameraController: if no frame arrives for 5 s, the stream is restarted. After 3 restarts in a minute the app shows an error instead of a silent black screen.BUILDING.mdandTESTING.md.Testing
Emulator (virtual UVC camera, debug build):
Pixel 7 Pro with the real camera (release build):
Unit tests and lint pass.
🤖 Generated with Claude Code