【问题标题】:Sharing memory between GStreamer pipelines under Docker containers在 Docker 容器下的 GStreamer 管道之间共享内存
【发布时间】:2021-10-27 07:08:36
【问题描述】:

我正在尝试通过共享内存(shmsrcshmsink 插件)在两个 GStreamer 管道之间传递视频。管道在不同的 Docker 容器中运行。我有一个 Docker 卷用作共享空间。我已经检查过是否可以从两个容器中管理相同的文件。

第一个管道:

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

第二条管道:

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

起初我尝试运行两个类似的容器,并像这样附加卷:

docker run -it --rm --gpus all --net=host-v SharedSpace:/sharedspace

然后我尝试像这样运行第一个容器:

docker run -it --name=MemorySharer --rm --gpus all --net=host-v SharedSpace:/sharedspace

第二个是这样的:

docker run -it --name=MemoryGrabber --rm --gpus all --net=host--volumes-from MemorySharer

在这两种情况下,我都会遇到相同的错误。第一个管道正常运行(至少时间计数器增加)并且它不会失败。第二个管道在启动后立即失败并打印:

...
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 ...

GDB 下的输出类似,不提供任何回溯。第一个管道对第二个管道失败没有反应。

我还尝试了另一种情况:在同一个容器下运行两个管道。行为不同。第一个管道正在运行。当我开始第二个 - 视频出现一帧或几帧时,两个管道都失败了。在此失败后,第一个管道一直失败,并在启动时出现相同的错误,直到重新启动 Docker 容器。

第一个管道失败:

...
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.

第二个管道失败(没有可用的 gdb 回溯):

...
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 ...

相同的管道在没有 Docker 的情况下工作。我究竟做错了什么?如何解决此错误?

【问题讨论】:

    标签: docker gstreamer shared-memory


    【解决方案1】:

    我知道这有点晚了,但我遇到了同样的问题,不得不解决它。还不如留给别人。

    发件人:Shared Memory with Docker containers (docker version 1.4.1)

    看起来容器具有隔离的进程间通信 (IPC) 命名空间。有利于安全和隔离,不利于视频传输。您可以为容器 IPC 命名空间添加标志。 IPC settings (--ipc)

    只需添加:

    docker run ... --volume="/shmdir:/shmdir" --ipc=host ...
    

    需要提供 shm 的音量。然后使用--ipc=host,将主机IPC连接到容器,就可以连接到我这里的shmsocket /tmp/tmpsock。

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 2021-06-20
      • 2014-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多