Play .aac/.mp3/.ogg files running cog inside a container (Torizon)?

Hi there,

Using Torizon OS on imx8 Apalis modules, is it possible to play audio on cog? (.aac/.mp3/.ogg, or other file types?)
If so, what are the extrapackages, and docker file device share I should use?

Thanks in advance!

Greetings @rawmance,

To be honest I’m not completely sure. I know standalone audio can be played in a container, at least .wav files. Though I never tried other audio types like the ones you listed. These ones probably require gstreamer support for things like mp3 and such. I would need to check if the gstreamer we package in our containers even has support for this. Then there’s the question of whether this will all be compatible with Cog which is unknown at the moment.

Just so I know, what exactly is your use-case here? It sounds like you plan to create a web application of some kind that features sound? Or is it something else?

Best Regards,
Jeremias

1 Like

Hi there @jeremias.tx ,

Yes, we need to reproduce sound in a webapplication. Basicaly playing sound file.

Thanks in advance

I did some tests and here are my findings. Good news, I was able to play a standalone mp3 audio file. I used our VPU example container found here: torizon-samples/vpu/generic/vpuGeneric at bookworm-new · toradex/torizon-samples · GitHub

I ran this container by bind-mounting all of /dev and with privileged access to make sure the container had what it needed.

In this container I then downloaded an example audio file from here: Sample MP3 audio files

I was able to play the audio file with the following command:

gst-launch-1.0 playbin uri=file:///sample-15s.mp3 audio-sink="alsasink device=hw:0,0"

And it worked. I then tried to apply this to Cog. However, so far no success. Navigating to the same website and trying to play the audio samples there had no effect. It’s not clear to me where the issue lies exactly. I know in the past Cog had to do some work for i.MX GPUs to work properly. I’m wondering if work needs to be done on Cog to support i.MX audio decoding as well. This might be more of a question for the Cog folks over at: GitHub - Igalia/cog: WPE launcher and webapp container

Is this something you need immediately/urgently?

Best Regards,
Jeremias

1 Like

Do you know if it works using a Electron application? As it uses chromium, maybe it’s easier to make it work? (Using this as example Enable audio in chromium container - #2 by seasoned_geek)

Do you know if it works using a Electron application?

Not sure never tried with Electron, and I don’t think anyone here has either, at least none that have publicly shared their findings. If you do try this, please share your findings if you don’t mind.

Best Regards,
Jeremias

1 Like

I have no idea. I haven’t done anything with Toradex products in over a
year.

1 Like

Ok @jeremias.tx ,

I will :slight_smile:

Hi there @jeremias.tx ,

(How to play audio on Torizon OS using Alsa and C/C++ | Toradex Developer Center) , this guide seems to be for another version of visual studio code plugin, isn’t it? The apolloX seems a ‘little’ bit different

Hi there @jeremias.tx ,

I’ve tried to download the Dockerfile in the example you mentioned, but at the middle of the build process, the shell goes crazy :stuck_out_tongue:

Does it need some extra tweak or should it work out of the box?

Hi there @jeremias.tx ,

I’ve managed to build the image on another machine, but i had no success when running your example (without electron integration, just a bare vpugeneric image)

root@443978dac5c0:/# gst-launch-1.0 playbin uri=file:///sample-12s.mp3 audio-sink="alsasink device=hw:0,0"

(gst-plugin-scanner:17): GStreamer-CRITICAL **: 10:40:38.095: gst_element_class_add_pad_template: assertion 'GST_IS_PAD_TEMPLATE (templ)' failed

(gst-plugin-scanner:17): GStreamer-CRITICAL **: 10:40:38.098: gst_element_class_add_pad_template: assertion 'GST_IS_PAD_TEMPLATE (templ)' failed
Setting pipeline to PAUSED ...
ERROR: from element /GstAlsaSink:alsasink0: Could not open audio device for playback.
Additional debug info:
../ext/alsa/gstalsasink.c(924): gst_alsasink_open (): /GstAlsaSink:alsasink0:
Playback open error on device 'hw:0,0': No such file or directory
ERROR: pipeline doesn't want to preroll.
Failed to set pipeline to PAUSED.
Setting pipeline to NULL ...
Freeing pipeline ...

docker-compose.yml (2.0 KB)
Dockerfile (7.9 KB)

I’ve used the example you’ve pointed in the original post, and i’m using a apalis imx8 module with ixora carrierboard.
(I’ve changed the docker-compose.yml file to define MACHINE as apalis-imx8, and to point to my local dev registry)

Am i missing some step here?

Thanks in advance

I wonder if there is a need to access /proc/asound… :roll_eyes:

I’ve tried to run the guide (How to play audio on Torizon OS using Alsa and C/C++ | Toradex Developer Center), but it seems to also fail.

"Can't open audio default: No such file or directory"

(How to play audio on Torizon OS using Alsa and C/C++ | Toradex Developer Center) , this guide seems to be for another version of visual studio code plugin, isn’t it? The apolloX seems a ‘little’ bit different

This article is outdated and written for a much older version of our extension please don’t reference this word for word at the moment. I provided updated instructions on how to use this example for the current extension on this other thread here: Audio sample for torizon, vs code extension

I’ve used the example you’ve pointed in the original post, and i’m using a apalis imx8 module with ixora carrierboard.

In the gst-launch-1.0 command I used device=hw:0,0 since that is what the sound card enumerated as during my test. But this can change and the soundcard can be enumerated as a different numbered device other than 0,0. Based on your error it looks like this was the case. You can check /proc/asound/cards to see what device numer the sound card enumerated as. For apalis-imx8 the correct soundcard device is apalisimx8qmsgt. For example see on my device:

cat /proc/asound/cards
 0 [apalisimx8qmsgt]: simple-card - apalis-imx8qm-sgtl5000
                      apalis-imx8qm-sgtl5000
 1 [imxaudiohdmitx ]: imx-audio-hdmi- - imx-audio-hdmi-tx
                      imx-audio-hdmi-tx
 2 [imxspdif       ]: imx-spdif - imx-spdif
                      imx-spdif

In this case it’s still device 0, but this is not consistent across boots. One final note, you may need to set the volume on your headphones/playback device before you can hear anything. You can do that by installing alsa-utils in the container and running amixer set Headphone unmuted 50%.

For reference I just tried my example again on an Apalis i.MX8 with the Ixora carrier board and it still seems to work fine for me.

Best Regards,
Jeremias