Audio format S20/U20 support in GStreamer Rust bindings?

Hi all,

I am working on an audio backend project (vhost-device-sound) using GStreamer Rust bindings.
The device protocol requires 20-bit audio formats (S20/U20) as defined in the virtio-sound specification:

/* analog formats (width / physical width) */ 
VIRTIO_SND_PCM_FMT_S20, /* 20 / 32 bits */ 
VIRTIO_SND_PCM_FMT_U20, /* 20 / 32 bits */

However, I couldn’t find a direct mapping in GStreamer (AudioFormat enum only provides S16, S24_32, S32, etc.).

My questions are:
Does GStreamer support S20/U20 natively? If not, what is the recommended approach?
Are there plans to expose S20/U20 in the Rust bindings?

Environment:

GStreamer 1.22, gstreamer-rs 0.22

Thanks in advance!

This is not supported by GStreamer right now and would have to be added first. The closest that currently exists is 24 bits in 32 bits (S24_32) and 20 bits in 24 bits (S20).

You’d have to add a new S20_32 (and U20, etc). This should be mostly a matter of copy&paste with a few minor changes compared to the existing code for S24_32. Do you want to give that a try and provide an MR? If not, please nonetheless create an issue for this in gitlab.

Once GStreamer supports this directly, support in the Rust bindings would be added on the next update.

As a workaround you’d currently have to use S24_32 and shift by 4 bits for conversion.

Thanks for the clarification. I’ll give it a try and work on a MR to add support for S20_32 and U20_32.
If I run into issues during implementation, I’ll open an issue in GitLab.

1 Like