Hi,
I’m trying to query the capabilities of the v4l2src to detect what kind of sources are available from the currently connected camera. The approach I’m taking is:
- Create the
v4l2src
with the correctdevice
, - Set the state to
PAUSED
and wait onget_state()
to make sure that it is set correctly, - Iterate through all pads available in
v4l2src
and on each pad performquery_caps()
, and then operate on caps that were retrieved.
The minimal code example I have created is as follows:
#!/usr/bin/env python3
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
VIDEO_DEV = "/dev/video4"
Gst.init(None)
v4l2 = Gst.parse_launch(f"v4l2src device={VIDEO_DEV}")
v4l2.set_state(Gst.State.PAUSED)
v4l2.get_state(5)
for pad in v4l2.srcpads:
caps = pad.query_caps(None)
v4l2.set_state(Gst.State.NULL)
v4l2.get_state(5)
But running it in a bash loop shows that it occasionally (once in 10-20 executions) crashes. The backtrace as seen in the core dump is as follows:
#0 0x00007f75e30fe547 in gst_v4l2_object_probe_caps (v4l2object=<optimized out>, filter=<optimized out>) at ../sys/v4l2/gstv4l2object.c:4753
#1 0x00007f75e310c968 in gst_v4l2_object_get_caps (filter=0x0, v4l2object=<optimized out>) at ../sys/v4l2/gstv4l2object.c:4811
#2 gst_v4l2src_get_caps (src=<optimized out>, filter=0x0) at ../sys/v4l2/gstv4l2src.c:870
#3 0x00007f75e30ae852 in gst_base_src_default_query (src=0x563d3f6318a0, query=0x7f75d4000e60) at ../libs/gst/base/gstbasesrc.c:1354
#4 0x00007f75e33864cd in gst_pad_query (pad=0x563d3f8c2930, query=0x7f75d4000e60) at ../gst/gstpad.c:4228
#5 0x00007f75e33cf1ce in gst_pad_query_caps (pad=0x563d3f8c2930, filter=filter@entry=0x0) at ../gst/gstutils.c:3117
#6 0x00007f75e310b5e3 in gst_v4l2src_negotiate (basesrc=0x563d3f6318a0) at ../sys/v4l2/gstv4l2src.c:781
#7 0x00007f75e30a3559 in gst_base_src_negotiate_unlocked (basesrc=basesrc@entry=0x563d3f6318a0) at ../libs/gst/base/gstbasesrc.c:3449
#8 0x00007f75e30a3db0 in gst_base_src_loop (pad=0x563d3f8c2930) at ../libs/gst/base/gstbasesrc.c:2874
#9 0x00007f75e33b6ed4 in gst_task_func (task=0x563d3f8ca420) at ../gst/gsttask.c:384
#10 0x00007f75e42efe02 in g_thread_pool_thread_proxy (data=<optimized out>) at ../glib/gthreadpool.c:350
#11 0x00007f75e42eb573 in g_thread_proxy (data=0x7f75dc000b90) at ../glib/gthread.c:831
#12 0x00007f75f1eac897 in start_thread (arg=<optimized out>) at pthread_create.c:444
#13 0x00007f75f1f33a5c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
dmesg
doesn’t show anything suspicious during the crash, and I’ve tried it on two different v4l2 cameras, so I assume that it’s not related to hardware. I’m runnig up-to-date Fedora 39, with GStreamer versions gstreamer1-1.22.12-1.fc39
, python-gstreamer1-1.22.12-1.fc39
, gstreamer1-plugins-good-1.22.12-1.fc39
and kernel 6.8.10-200.fc39.x86_64
.
Is my approach wrong? Thanks in advance for help.