Search code examples
cgstreamergstreamer-1.0

How many total threads in a given GStreamer pipeline?


How many threads are there in this GStreamer pipeline?

gst-launch-1.0 autovideosrc ! queue ! fakesink

I want the total number and function of each thread. I searched online and in the documentation but couldn't find a clear answer.

My knowledge is that there is a main loop thread, an event thread (not sure) and two (because of queue element) buffer threads here. This gives a total of 4 threads for the mentioned pipeline.

Am I correct? Or is there some other mechanism?

Experiments:

Running the first time gives 8 threads initially.

/ # ps -T | grep "gst"
 3681 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3702 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3703 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3704 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3716 root      0:00 {queue0:src} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3717 root      0:00 {fake-auto-video} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3718 root      0:00 {gmain} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3719 root      0:00 {pool} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3729 root      0:00 grep gst

After some time it becomes 7 threads

/ # ps -T | grep "gst"
 3681 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3702 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3703 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3704 root      0:00 gst-launch-1.0 autovideosrc ! queue ! fakesink
 3716 root      0:00 {queue0:src} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3717 root      0:02 {fake-auto-video} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3718 root      0:00 {gmain} gst-launch-1.0 autovideosrc ! queue ! fakesink
 3731 root      0:00 grep gst

I did strace -p 3681 and so on and found

3681:

ppoll([{fd=3, events=POLLIN}, {fd=9, events=POLLIN}], 2, NULL, NULL, 0

3702:

ioctl(11, BINDER_WRITE_READ

3703

ioctl(11, BINDER_WRITE_READ

3704:

ioctl(11, BINDER_WRITE_READ

3716:

...
futex(0x5580a842a8, FUTEX_WAIT_PRIVATE, 11083, NULL) = 0

3717:

...
ppoll([{fd=6, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, {tv_sec=0, tv_nsec=31373754}, NULL, 8) = 0 (Timeout)
futex(0x5580a842a8, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x5580a84290, FUTEX_WAKE_PRIVATE, 1) = 1

3718:

ppoll([{fd=5, events=POLLIN}], 1, NULL, NULL, 0

What does this mean?


Solution

  • I asked this in https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel and got this reply from Nicolas Dufresne [email protected]

    It's impossible to say which video source will be picked by autovideosrc. Replace this magic thing with an explicit src, like videotestsrc, then you should have 4 thread,

    • source streaming thread
    • queue streaming thread
    • main thread (gst-launch runs a GLib main-loop, though this is optional)
    • Some thread pool.

    You may have more threads if you use an element that initialize GIO, those will stay mostly idle.

    You can track GStreamer related thread in your software with the STREAM_STATUS message. All other threads are from third party libraries, glib or you libc.

    There is no mainline code in GStreamer that would use Android ioctl BINDER, so I suppose you are using some HW specific video source and then sky is the limit on what that third party camera stack may do.