GNOME Bugzilla – Bug 785156
v4l2src: May takes a lot of time to start with certain USB UVC cameras
Last modified: 2017-07-21 19:45:59 UTC
This has been often reported but never files as bug. I own a camera that takes about 38s to start with GStreamer and 7s with other application. Fixing this was non-trivial as we didn't want to drop support for negotiating interlace-mode and colorimetry, but it was possible. Patches coming ...
Created attachment 355992 [details] [review]
v4l2object: Validate field in S/TRY_FMT
This is in preparation from removing the slow TRY_FMT probes for
interlacing. As we won't have tried that interlace-mode already
we need to validate that the driver isn't refusing it.
Created attachment 355993 [details] [review]
v4l2object: Validate colorimetry in S/TRY_FMT
This is in preparation for removing slow TRY_FMT probes for
colorimetry. As we won't have tried that colorimetry we cannot
assume the driver will accept it.
Created attachment 355994 [details] [review]
v4l2object: Fix try/s_fmt errors
According to the spec,TRY_FMT cannot return EBUSY, though it can
return EINVAL if it was not possible to update the format to
Created attachment 355995 [details] [review]
v4l2object: Minor style fix and useful trace
Created attachment 355996 [details] [review]
v4l2object: always set the GstV4l2Error on error
Some of the error case were conditional to using try_fmt or not.
This is slightly unexpected, always set the error so the caller
Created attachment 355997 [details] [review]
v4l2object: Introduce quirk to skip slow probes
skip_try_fmt_probes quirk is set, V4L2 object will not probe for
interlace-mode and colorimetry to avoid relying on try_fmt. This quirk
will be used by v4l2src to avoid desastrous startup time with slow
When this quirk is enabled, caller will have to iterate over the
negotiated caps as it may contains unsupported formats. If the peer
didn't choose a specific interlace-mode, or colorimetry, the value
chosen by the driver is set into the caps. For this reason, when this
mode is enabled, gst_v4l2_object_set_format() will require writable
Created attachment 355998 [details] [review]
v4l2src: Speedup camera startup by skipping try_fmt
In this commit, we enabled skip_try_fmt_probes quirk in order to speed
up the start which is known to be disastrously slow with certain USB
This has the side effect that we needed to rewrite the entire
negotiation process in a way that we iterate over the possible caps
until we find one that works.
The new negotiation method consist of extracting a preferred structure
from the peer caps and using this to fixate and sort the caps. To
reflect the old behaviour, we sort all resolution strictly bigger
to the preferred one with the closes one first. The rest is appended,
keeping the same order. We then normalize the caps in case there was
some list of interlace-mode or colorimetry left. We finally iterate
over all fixed caps and try it. 99% of the time, the first or the
second one should work, whit the result of a single S_FMT being issues.
From there, it will be relatively easy to introduce new negotiation
algorithm. The current algorithm is made for optimal image quality
with a scaling sink that sets it's window resolution as preference.
This the case if for:
v4l2src ! videoconvert ! videoscale ! ximagesink
Other strategy would be needed to optimize for non-scaling sink like
ximagesink or kmssink when the driver does not scale.
With some minor fixes found during further testing.
Attachment 355992 [details] pushed as 336c8a7 - v4l2object: Validate field in S/TRY_FMT
Attachment 355993 [details] pushed as 558e9f4 - v4l2object: Validate colorimetry in S/TRY_FMT
Attachment 355994 [details] pushed as c00d4ca - v4l2object: Fix try/s_fmt errors
Attachment 355995 [details] pushed as 059ccf9 - v4l2object: Minor style fix and useful trace
Attachment 355996 [details] pushed as 7d3b262 - v4l2object: always set the GstV4l2Error on error
Attachment 355997 [details] pushed as cae0b9a - v4l2object: Introduce quirk to skip slow probes
Attachment 355998 [details] pushed as b3e089d - v4l2src: Speedup camera startup by skipping try_fmt
Was also testing with cheese, switching camera takes less then a second (depends on the camera of course), which is better then my phone.