After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 785156 - v4l2src: May takes a lot of time to start with certain USB UVC cameras
v4l2src: May takes a lot of time to start with certain USB UVC cameras
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
1.6.0
Other Linux
: Normal normal
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-07-20 02:45 UTC by Nicolas Dufresne (ndufresne)
Modified: 2017-07-21 19:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
v4l2object: Validate field in S/TRY_FMT (1.77 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
v4l2object: Validate colorimetry in S/TRY_FMT (1.89 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
v4l2object: Fix try/s_fmt errors (2.50 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
v4l2object: Minor style fix and useful trace (1.62 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
v4l2object: always set the GstV4l2Error on error (2.76 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
v4l2object: Introduce quirk to skip slow probes (4.80 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
v4l2src: Speedup camera startup by skipping try_fmt (16.67 KB, patch)
2017-07-20 02:46 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review

Description Nicolas Dufresne (ndufresne) 2017-07-20 02:45:20 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 ...
Comment 1 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:24 UTC
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.
Comment 2 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:28 UTC
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.
Comment 3 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:31 UTC
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
something supported.
Comment 4 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:35 UTC
Created attachment 355995 [details] [review]
v4l2object: Minor style fix and useful trace
Comment 5 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:39 UTC
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
can decide.
Comment 6 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:43 UTC
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
USB webcams.

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
caps.
Comment 7 Nicolas Dufresne (ndufresne) 2017-07-20 02:46:47 UTC
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
cameras.

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.
Comment 8 Nicolas Dufresne (ndufresne) 2017-07-21 19:44:30 UTC
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
Comment 9 Nicolas Dufresne (ndufresne) 2017-07-21 19:45:59 UTC
Was also testing with cheese, switching camera takes less then a second (depends on the camera of course), which is better then my phone.