I'm trying to pass video between two GStreamer pipelines through shared memory (shmsrc & shmsink plugins). The pipelines run in different Docker containers. I have a Docker volume used as a shared space. I've checked that it's possible to manage same files from both containers.
The first pipeline:
gst-launch-1.0 -v videotestsrc ! "video/x-raw, format=BGRx, width=(int)1920, height=(int)1080, framerate=(fraction)60/1" ! queue ! shmsink socket-path=/sharedspace/shm shm-size=663552000 wait-for-connection=false
The second pipeline:
gst-launch-1.0 shmsrc socket-path=/sharedspace/shm is-live=true ! "video/x-raw, format=BGRx, width=(int)1920, height=(int)1080, framerate=(fraction)60/1" ! queue ! videoconvert ! queue ! autovideosink
At first I tried to run two similar containers with the volume attached like this:
docker run -it --rm --gpus all --net=host-v SharedSpace:/sharedspace
Then I tried running the first container like this:
docker run -it --name=MemorySharer --rm --gpus all --net=host-v SharedSpace:/sharedspace
And the second one like this:
docker run -it --name=MemoryGrabber --rm --gpus all --net=host--volumes-from MemorySharer
In both cases I'm getting the same error. The first pipeline runs normally (at least time counter increases) and it doesn't fail. The second pipeline fails immediately after start and prints:
...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
shm_open failed on /shmpipe. 214. 0 (2): No such file or directory
ERROR: from element /GstPipeline:pipeline0/GstShmSrc:shmsrc0: Failed to read from shmsrc
Additional debug info:
../subprojects/gst-plugins-bad/sys/shm/gstshmsrc.c(374): gst_shm_src_create (): /GstPipeline:pipeline0/GstShmSrc:shmsrc0:
Error reading control data: -4
ERROR: from element /GstPipeline:pipeline0/GstShmSrc:shmsrc0: Internal data stream error.
Additional debug info:
../subprojects/gstreamer/libs/gst/base/gstbasesrc.c(3127): gst_base_src_loop (): /GstPipeline:pipeline0/GstShmSrc:shmsrc0:
streaming stopped, reason error (-5)
Execution ended after 0:00:00.000345404
Setting pipeline to NULL ...
Freeing pipeline ...
Output under GDB is similar and doesn't give any backtrace. The first pipeline doesn't react for the second pipeline fail.
Also I've tried another case: running the two pipelines under the same container. Behaviour is different. The first pipeline is running. When I start the second one - video appears for one or couple frames then both pipelines fail. After this fail first pipeline fails all the time with the same error on start until restarting Docker container.
First pipeline fail:
...
New clock: GstSystemClock
0:00:11.5 / 99:99:99.
Thread 4 "videotestsrc0:s" received signal SIGBUS, Bus error.
[Switching to Thread 0x7f0b2f7fe700 (LWP 247)]
0x00007f0b5ed9f199 in ?? ()
(gdb) bt
#0 0x00007f0b5ed9f199 in ?? ()
#1 0x00007f0b5ce3ff1e in video_orc_pack_BGRA (d1=0x7f0b389d7c38 '\377' <repeats 200 times>..., s1=0x7f0b200069e0 '\377' <repeats 200 times>..., n=1920)
at subprojects/gst-plugins-base/gst-libs/gst/video/video-orc.c:4655
#2 0x00007f0b5d0dabbd in convert_hline_generic (p=<optimized out>, frame=0x7f0b2f7fd950, y=98) at ../subprojects/gst-plugins-base/gst/videotestsrc/videotestsrc.c:1289
#3 0x00007f0b5d0da81e in videotestsrc_convert_tmpline (p=p@entry=0x7f0b2f7fd850, frame=frame@entry=0x7f0b2f7fd950, j=j@entry=98) at ../subprojects/gst-plugins-base/gst/videotestsrc/videotestsrc.c:273
#4 0x00007f0b5d0db1bf in gst_video_test_src_smpte (v=0x55c04b5a2b40 [GstVideoTestSrc|videotestsrc0], pts=<optimized out>, frame=0x7f0b2f7fd950)
at ../subprojects/gst-plugins-base/gst/videotestsrc/videotestsrc.c:351
#5 0x00007f0b5d0d7d09 in gst_video_test_src_fill (psrc=0x55c04b5a2b40 [GstVideoTestSrc|videotestsrc0], buffer=0x7f0b28005480 [GstBuffer])
at ../subprojects/gst-plugins-base/gst/videotestsrc/gstvideotestsrc.c:1162
#6 0x00007f0b5cbde15f in gst_base_src_default_create (src=0x55c04b5a2b40 [GstVideoTestSrc|videotestsrc0], offset=18446744073709551615, size=4096, buffer=0x7f0b2f7fdd08)
at ../subprojects/gstreamer/libs/gst/base/gstbasesrc.c:1596
#7 0x00007f0b5cbdffa9 in gst_base_src_get_range (src=src@entry=0x55c04b5a2b40 [GstVideoTestSrc|videotestsrc0], offset=offset@entry=18446744073709551615, length=<optimized out>, buf=buf@entry=0x7f0b2f7fdde0)
at ../subprojects/gstreamer/libs/gst/base/gstbasesrc.c:2587
#8 0x00007f0b5cbe31b0 in gst_base_src_loop (pad=0x55c04b5a61c0 [GstPad|src]) at ../subprojects/gstreamer/libs/gst/base/gstbasesrc.c:2911
#9 0x00007f0b5e903a79 in gst_task_func (task=0x55c04b5ba170 [GstTask|videotestsrc0:src]) at ../subprojects/gstreamer/gst/gsttask.c:328
#10 0x00007f0b5e5762d2 in g_thread_pool_thread_proxy (data=<optimized out>) at ../subprojects/glib/glib/gthreadpool.c:308
#11 0x00007f0b5e5758dd in g_thread_proxy (data=0x55c04b4142d0) at ../subprojects/glib/glib/gthread.c:805
#12 0x00007f0b5e0896db in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#13 0x00007f0b5ddb271f in clone () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) c
Continuing.
[Thread 0x7f0b2effd700 (LWP 248) exited]
[Thread 0x7f0b2f7fe700 (LWP 247) exited]
[Thread 0x7f0b2ffff700 (LWP 246) exited]
[Thread 0x7f0b349d7700 (LWP 245) exited]
Program terminated with signal SIGBUS, Bus error.
The program no longer exists.
Second pipeline fail (no gdb backtrace available):
...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
(gst-launch-1.0:253): GStreamer-CRITICAL **: 08:54:43.731: gst_segment_to_stream_time: assertion 'segment->format == format' failed
(gst-launch-1.0:253): GStreamer-CRITICAL **: 08:54:43.929: gst_segment_to_stream_time: assertion 'segment->format == format' failed
(gst-launch-1.0:253): GStreamer-CRITICAL **: 08:54:43.995: gst_segment_to_stream_time: assertion 'segment->format == format' failed
(gst-launch-1.0:253): GStreamer-CRITICAL **: 08:54:44.023: gst_segment_to_stream_time: assertion 'segment->format == format' failed
(gst-launch-1.0:253): GStreamer-CRITICAL **: 08:54:44.089: gst_segment_to_stream_time: assertion 'segment->format == format' failed
ERROR: from element /GstPipeline:pipeline0/GstShmSrc:shmsrc0: Failed to read from shmsrc
Additional debug info:
../subprojects/gst-plugins-bad/sys/shm/gstshmsrc.c(356): gst_shm_src_create (): /GstPipeline:pipeline0/GstShmSrc:shmsrc0:
Control socket has closed
Execution ended after 0:00:19.060861019
Setting pipeline to NULL ...
ERROR: from element /GstPipeline:pipeline0/GstShmSrc:shmsrc0: Internal data stream error.
Additional debug info:
../subprojects/gstreamer/libs/gst/base/gstbasesrc.c(3127): gst_base_src_loop (): /GstPipeline:pipeline0/GstShmSrc:shmsrc0:
streaming stopped, reason error (-5)
Freeing pipeline ...
The same pipelines work without Docker. What am I doing wrong? How to fix this errors?