简体   繁体   English

如何从 Docker 容器访问 JACK 音频

[英]How to access JACK audio from a Docker container

I have a multimedia app in a Docker container.我在 Docker 容器中有一个多媒体应用程序。 I would like connect it to my JACK audio server running in the host system.我想将它连接到我在主机系统中运行的 JACK 音频服务器。 How can I do it?我该怎么做?

This is my current (and not working) docker run command:这是我当前(并且不工作)的docker run命令:

    docker run \
        --rm \
        -i -t \
        -u $(id -u):$(id -g) \
        -v $(pwd):/home/app/build \
        -v $HOME:/home/app \
        -v /media:/media \
        -v /usr/local/lib64:/usr/local/lib64 \
        -v /tmp/.X11-unix:/tmp/.X11-unix \
        -v /etc/machine-id:/etc/machine-id \
        -v /run/user/$(id -u)/pulse:/run/user/$(id -u)/pulse \
        -v $HOME/.pulse:/home/app/.pulse \
        --env DISPLAY \
        --env HOME='/home/app' \
        --privileged \
        --group-add $(getent group audio | cut -d: -f3) \
        --name "app" \
        <image name> <parameters>

From this :这个

SHared Memory Another from of IPC used is shared memory.共享内存另一个使用的 IPC 是共享内存。 The base class for all shared memory in the JACK system is JackShmMemAble. JACK 系统中所有共享内存的基类是 JackShmMemAble。 Objects that need to go to shared memory need to derive from this base class.需要进入共享内存的对象需要从这个基类派生。 The implementation of this class is again platform dependent.此类的实现再次依赖于平台。 For Linux systems the System V shared memory API's are made use of.对于 Linux 系统,使用了 System V 共享内存 API。 The shared memory is used for a variety of purposes like notifying the client RT thread of what priority it must set itself to.共享内存用于多种目的,例如通知客户端 RT 线程它必须将自身设置为什么优先级。 Template classes JackShmReadWritePtr, JackShmReadWritePtr1 and JackShmReadPtr are made use of to access shared memory.模板类 JackShmReadWritePtr、JackShmReadWritePtr1 和 JackShmReadPtr 用于访问共享内存。

So, I think you should bind mount /dev/shm to container like next, then I guess the client in container could communicate with the jack audio server in host with shared memory:所以,我认为你应该像下一个一样将 mount /dev/shm绑定到容器,然后我猜容器中的客户端可以与主机中的 jack 音频服务器通信,共享内存:

docker run \
    --rm \
    -i -t \
    -u $(id -u):$(id -g) \
    -v /dev/shm:/dev/shm \
    -v $(pwd):/home/app/build \
    -v $HOME:/home/app \
    -v /media:/media \
    -v /usr/local/lib64:/usr/local/lib64 \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /etc/machine-id:/etc/machine-id \
    -v /run/user/$(id -u)/pulse:/run/user/$(id -u)/pulse \
    -v $HOME/.pulse:/home/app/.pulse \
    --env DISPLAY \
    --env HOME='/home/app' \
    --privileged \
    --group-add $(getent group audio | cut -d: -f3) \
    --name "app" \
    <image name> <parameters>

Have you tried with docker run --ipc=host (...) ?您是否尝试过docker run --ipc=host (...)

I think documentation refers to shared memory in the context of IPC.我认为文档是指 IPC 上下文中的共享内存。 I guess --ipc=host has some security implications (since the container will have access to all IPC on the host for the running user).我猜--ipc=host有一些安全隐患(因为容器将可以访问主机上运行用户的所有 IPC)。 Also, maybe you'll need to run the process in the docker container with the same UID than the user on your host.此外,也许您需要使用与主机上的用户相同的 UID 在 docker 容器中运行该进程。

You'll want to use你会想要使用

 --device /dev/snd:/dev/snd

working with sound in docker 在 docker 中处理声音

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM