How to play sound in a Docker container on Mac OS Yosemite - audio

I'm trying to dockerize a text to speech application for sharing the code with other developers, however the issue I am having right now is the docker container cannot find the sound card on my host machine.
When I try to play a wav file in my docker container
root#3e9ef1e869ea:/# aplay Alesis-Fusion-Acoustic-Bass-C2.wav
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:722: audio open error: No such file or directory
I guess that the main problem is docker container is unable reach the sound card on my host.
So far I have
I installed alsa-utils and most of the alsa dependencies within my
docker container.
Added --group-add audio while running the
container by specifying docker run --group-add audio -t -i
self/debian /bin/bash
I am not sure if this is even possible with docker(I'm not exactly sure of how hardware resources such as sound cards are shared with containers). I'm using a debian container on a Mac OS Yosemite host.

It is definitely possible, you need to mount /dev/snd, see how Jess Frazelle launches a Spotify container, from
https://blog.jessfraz.com/post/docker-containers-on-the-desktop/
you will notice
docker run -it \
-v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
-e DISPLAY=unix$DISPLAY \ # pass the display
--device /dev/snd \ # sound
--name spotify \
jess/spotify
or for Chrome, at the end
docker run -it \
--net host \ # may as well YOLO
--cpuset-cpus 0 \ # control the cpu
--memory 512mb \ # max memory it can use
-v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
-e DISPLAY=unix$DISPLAY \ # pass the display
-v $HOME/Downloads:/root/Downloads \ # optional, but nice
-v $HOME/.config/google-chrome/:/data \ # if you want to save state
--device /dev/snd \ # so we have sound
--name chrome \
jess/chrome

Related

Build custom driver for linux

I am new to building C lib and have mostly worked with python. My goal is to take the source code from https://github.com/torvalds/linux and build a custom driver for USB/IP (https://github.com/torvalds/linux/tree/master/drivers/usb/usbip) module (some modification).
I copied only /tool/usbip/ assuming that USB and USB-IP are already present in the alpine.
I have set up a docker Image:
FROM alpine
COPY . .
RUN apk add build-base autoconf automake libtool eudev-dev libusb-dev
WORKDIR /tool/usbip/
RUN ./autogen.sh
RUN ./configure
RUN make install
I am getting the following error for make install:
Step 7/7 : RUN make install
---> Running in 48f53c225a99
Making install in libsrc
make[1]: Entering directory '/tool/usbip/libsrc'
CC libusbip_la-names.lo
In file included from names.c:23:
usbip_common.h:18:10: fatal error: linux/usb/ch9.h: No such file or directory
18 | #include <linux/usb/ch9.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:459: libusbip_la-names.lo] Error 1
make[1]: Leaving directory '/tool/usbip/libsrc'
make: *** [Makefile:500: install-recursive] Error 1
This could mean that alpine doesn't have a USB drive. How do I compile and install the driver in that docker?
Another solution can be to build the entire Linux code from the repo, but can I use alpine and add a USB-IP driver there, as I can see that alpine is very lightweight?
I see some Kconfig and Makefile, but I need guidance on building the required driver, as my task also requires modifying drivers/USB/usbip code and building the driver for usbip.
Some blog links or youtube videos on build drivers will also help, but I was not able to find any good resources online.
Updated docker file:
FROM alpine:latest
COPY . /linux
RUN apk add build-base autoconf \
automake libtool eudev-dev \
linux-headers flex bison gmp-dev \
mpc1-dev mpfr-dev
WORKDIR /linux
RUN zcat /proc/config.gz > .config
RUN make olddefconfig
RUN make modules_prepare
RUN make M=drivers/usb/usbip modules
WORKDIR /linux/tools/usb/usbip/
RUN ./autogen.sh
RUN ./configure
RUN make install
Download kernel sources and go to its root.
Copy .config for system you want to build for. E.g. if it is your running system and it provides /proc/config.gz then zcat /proc/config.gz > .config
make olddefconfig
Ensure CONFIG_USBIP and other modules are enabled as a modules:
$ grep CONFIG_USBIP .config
CONFIG_USBIP_CORE=m
CONFIG_USBIP_VHCI_HCD=m
CONFIG_USBIP_VHCI_HC_PORTS=8
CONFIG_USBIP_VHCI_NR_HCS=1
CONFIG_USBIP_HOST=m
# CONFIG_USBIP_DEBUG is not set
If not, run make nconfig (or make menuconfig), navigate to Device Drivers->USB support->USB/IP support and enable it as a module (<M>); save configuration.
make modules_prepare
make M=drivers/usb/usbip modules
Your modules are in drivers/usb/usbip/

sun4i_codec loaded but no sound card found on Cubieboard2 AllWinner A20 with fresh Archlinux installation

The problem is no sound.
Just install Archlinux on Cubieboard2, CPU is AllWinner A20.
Audio driver should be sun4i_codec loads according to this post.
Hereby are some information, please tell me what others you would me to offer. Thanks in advance.
[alarm#rAudio ~]$ aplay -l aplay: device_list:275: no soundcards
found...
[alarm#rAudio log]$ lsmod | grep sun4i_codec sun4i_codec
45056 3 snd_soc_core 208896 1 sun4i_codec snd_pcm
118784 4 sun4i_codec,snd_pcm_dmaengine,snd_soc_core
[alarm#rAudio ~]$ speaker-test -c 2
speaker-test 1.2.7
Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1334:(snd_func_refer) error evaluating name
ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5703:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM default
Playback open error: -2,No such file or directory
The system has ALSA, PipeWire and PulseAudio installed.

Chromium ARM Cross Compilation generating rpm installer

I am generating the installer (rpm) for chromium browser to run on beaglebone black after cross compiling using ninja.
root#2b5071fb9adf:~/chromium/buildhost/src# ninja -C out/arm "chrome/installer/linux:unstable_rpm"
ninja: Entering directory `out/arm'
[15/16] ACTION //chrome/installer/linux:unstable_rpm(//build/toolchain/linux:clang_arm)
FAILED: chromium-browser-unstable-89.0.4339.0-1.armhf.rpm
python ../../build/gn_run_binary.py installer/rpm/build.sh -a armhf -c unstable -d chromium -o . -t linux -f
Expected permissions on etc to be 755, but they were 777
installer/rpm/build.sh failed with exit code 1
ninja: build stopped: subcommand failed.
This done on a docker container and followed the steps as mentioned in https://unix.stackexchange.com/questions/527627/compile-chromium-browser-for-arm-2019
Any directions in resolving the above error while generating the rpm/deb would be of great help.

Compiling FFmpeg lib and add it to NDK sources on Windows8

I've seen some articles about how to compile and uses FFmpeg for Android.
These are 2 good examples - example1 and example2
Unfortunately, non off them, or others I found helped me. In those two examples a build_android.sh is created and configure the FFmpeg's configuraion file and call to make. Every time when I'm running the script I'm getting the following error:
c:\android\development\android-ndk-r9\sources\ffmpeg>sh build_android.sh
c:/android/development/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebu
ilt/windows-x86_64/arm-linux-androideabi/bin/bin/arm-linux-androideabi-gcc is un
able to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user#ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
Makefile:2: config.mak: No such file or directory
Makefile:49: /common.mak: No such file or directory
Makefile:92: /libavutil/Makefile: No such file or directory
Makefile:92: /library.mak: No such file or directory
Makefile:169: /doc/Makefile: No such file or directory
Makefile:170: /tests/Makefile: No such file or directory
make: *** No rule to make target `/tests/Makefile'. Stop.
Makefile:2: config.mak: No such file or directory
If someone encountered and solved this issue it'll be much appreciated!
After trying the suggested script I ran into a new problem that I couldn't solved, this is the output of the script:
.... Enabled components list....
In the end of the list I got the following:
Enabled indevs:
dv1394 v4l2i
fbdev
Enabled outdevs:
fbdev v4l2
License: LGPL version 2.1 or later
Creating config.mak, config.h, and doc/config.texi...
WARNING: C:/android/development/android-ndk-r9/toolchains/arm-linux-androideabi-
4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-pkg-config not found, libr
ary detection may fail.
make: *** No rule to make target libavfilter/libavfilter.so', needed by all-ye
s'. Stop.
make: *** No rule to make target install-libavfilter-shared', needed by instal
l-libs-yes'. Stop.
Can you paste what's in your build_android.sh file which you've copied inside the FFmpeg directory?
I've got the same error when one of the variables defined at the start of the script where set incorrectly. Check to see if your NDK or SYSROOT or TOOLCHAIN variables are set to a valid path!
I've tried using the following steps and it worked for me:
1) Download FFmpeg
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
2) Create a file called build_android.sh inside the FFmpeg directory
cd ffmpeg; touch build_ffmpeg_for_android.sh;
3) Add the following content to the file
#!/usr/bin/env bash
NDK=$HOME/Software/Android/android-ndk-r10/
SYSROOT=$NDK/platforms/android-19/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j4
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
4) Make the script executable
chmod +x build_ffmpeg_for_android.sh
5) Start the build of FFmpeg for Android (ARM)
(run the script with Bash, i.e. /usr/bin/bash not /usr/bin/sh)
./build_ffmpeg_for_android.sh
I was getting the same errors as #powerX and I was able to solve the issue using a different method from #dZkF9RWJT6wN8ux.
Though I am using Ubuntu 13.10, I hope you find my answer helpful. With android NDK r9 and FFMPEG 2.2 "Muybridge" release, I was finally able to accomplish the third step entitled "Build FFMPEG" from #powerX example1 link: http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/
I finally fixed this by changing the SYSROOT variable in the build_android.sh file to point to ".../android-19/arch-arm" instead of .../android-9/arch-arm".
Hope this helps.

chroot into other arch's environment

Following the Linux from Scratch book I have managed to build a toolchain for an ARM on
an ARM. This is till chapter 6 of the book, and on the ARM board itself I could go on further with no problems.
My question is if I can use the prepared environment to continue building the soft from chapter 6 on my x86_64 Fedora 16 laptop?
I thought that while I have all the binaries set up I could just copy them to laptop, chroot inside and feel myself as on the ARM board, but using the command from the book gives no result:
`# chroot "$LFS" /tools/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /tools/bin/bash --login +h
chroot: failed to run command `/tools/bin/env': No such file or directory`
The binary is there, but it doesn't belong to this system:
`# ldd /tools/bin/env
not a dynamic executable`
The binary is compiled as per the book:
# readelf -l /tools/bin/env | grep interpreter
[Requesting program interpreter: /tools/lib/ld-linux.so.3]
So I wonder if there is a way, like using proper environment variables for CC LD READELF, to continue building for ARM using these tools on x86_64 host.
Thank you.
Yes, you certainly can chroot into an ARM rootfs on an x86 box.
Basically, like this:
$ sudo chroot /path/to/arm/rootfs /bin/sh
sh-4.3# ls --version 2>&1 | head
/bin/ls: unrecognized option '--version'
BusyBox v1.22.1 (2017-03-02 15:41:43 CST) multi-call binary.
Usage: ls [-1AaCxdLHRFplinsehrSXvctu] [-w WIDTH] [FILE]...
List directory contents
-1 One column output
-a Include entries which start with .
-A Like -a, but exclude . and ..
sh-4.3# ls
bin css dev home media proc sbin usr wav
boot data etc lib mnt qemu-arm sys var
My rootfs is for a small embedded device, so everything is BusyBox-based.
How is this working? Firstly, I have the binfmt-misc support running in the kernel. I didn't have to do anything; it came with Ubuntu 18. When the kernel sees an ARM binary, it hands it off to the registered interpreter /usr/bin/qemu-arm-static.
A static executable by that name is found inside my rootfs:
sh-4.3# ls /usr/bin/q*
/usr/bin/qemu-arm-static
I got it from a Ubuntu package. I installed:
$ apt-get install qemu-user-static
and then copied /usr/bin/qemu-arm-static into the usr/bin subdirectory of the rootfs tree.
That's it; now I can chroot into that rootfs without even mentioning QEMU on the chroot command line.
Nope. You can't run ARM binaries on x86, so you can't enter its chroot. No amount of environment variables will change that.
You might be able to continue the process by creating a filesystem image for the target and running it under an emulator (e.g, qemu-system-arm), but that's quite a different thing.
No you cannot, at least not using chroot. What you have in your hands is a toolchain with an ARM target for an ARM host. Binaries are directly executable only on architectures compatible with their host architecture - and x86_64 is not ARM-compatible.
That said, you might be able to use an emulated environment. qemu, for example, offers two emulation modes for ARM: qemu-system-arm that emulates a whole ARM-based system and qemu-arm that uses ARM-native libraries to provide a thinner emulation layer for running ARM Linux executables on non-ARM hosts.

Resources