Skip to content

Commit 8afd408

Browse files
Fix: Audio formats in Gstreamer plugin (#1107)
- Interpret PCM format as big endian in Gstreamer plugin - Fix audio formats description in README. --------- Signed-off-by: Kasiewicz, Marek <[email protected]> Co-authored-by: Mateusz Grabuszyński <[email protected]>
1 parent da3e06b commit 8afd408

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

ecosystem/gstreamer_plugin/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ Audio plugins for MTL that are able to send, receive synchronous raw audio via t
273273

274274
The `mtl_st30p_tx` plugin supports the following pad capabilities:
275275

276-
- **Formats**: `S16LE`, `S24LE`, `S32LE`
276+
- **Formats**: `S8`, `S16BE`, `S24BE`
277277
- **Sample Rate Range**: 44100, 48000, 96000
278278
- **Channels Range**: 1 to 8
279279

@@ -285,7 +285,7 @@ The `mtl_st30p_tx` plugin supports the following pad capabilities:
285285
| tx-ptime | string | Packetization time for the audio stream. | `1ms`, `125us`, `250us`, `333us`, `4ms`, `80us`, `1.09ms`, `0.14ms`, `0.09ms` | `1.09ms` for 44.1kHz, `1ms` for others |
286286
| async-session-create | boolean | Improve initialization time by creating a session in a separate thread. All buffers that arrive before the session is ready will be dropped | TRUE/FALSE | FALSE |
287287

288-
#### 4.1.2. Example GStreamer Pipeline for Transmission with s16LE format
288+
#### 4.1.2. Example GStreamer Pipeline for Transmission with s16BE format
289289

290290
To run the `mtl_st30p_tx` plugin, you need to setup metadata (Here we are using pipeline capabilities).
291291
Instead of using input video we opted for build-in GStreamer audio files generator.
@@ -297,7 +297,7 @@ export VFIO_PORT_T="pci_address_of_the_device"
297297
298298
# Audio pipeline with 48kHz sample rate on port 30000
299299
gst-launch-1.0 audiotestsrc ! \
300-
audio/x-raw,format=S16LE,rate=48000,channels=2 ! \
300+
audio/x-raw,format=S16BE,rate=48000,channels=2 ! \
301301
mtl_st30p_tx tx-queues=4 rx-queues=0 udp-port=30000 payload-type=113 dev-ip="192.168.96.3" ip="239.168.75.30" dev-port=$VFIO_PORT_T \
302302
--gst-plugin-path $GSTREAMER_PLUGINS_PATH
303303
```
@@ -308,19 +308,21 @@ mtl_st30p_tx tx-queues=4 rx-queues=0 udp-port=30000 payload-type=113 dev-ip="192
308308

309309
The `mtl_st30p_rx` plugin supports the following pad capabilities:
310310

311-
- **Formats**: `S8`, `S16LE`, `S24LE`
311+
- **Formats**: `S8`, `S16BE`, `S24BE`
312312
- **Channels Range**: 1 to 2
313313
- **Sample Rate Range**: 44100, 48000, 96000
314314

315315
**Arguments**
316-
| Property Name | Type | Description | Range | Default Value |
317-
|---------------------|---------|-------------------------------------------------------|-------------------------|---------------|
318-
| rx-framebuff-num | uint | Number of framebuffers to be used for transmission. | 0 to G_MAXUINT | 3 |
319-
| rx-channel | uint | Audio channel number. | 0 to G_MAXUINT | 2 |
316+
| Property Name | Type | Description | Range | Default Value |
317+
|---------------------|---------|-------------------------------------------------------|--------------------------|---------------|
318+
| rx-framebuff-num | uint | Number of framebuffers to be used for transmission. | 0 to G_MAXUINT | 3 |
319+
| rx-channel | uint | Audio channel number. | 0 to G_MAXUINT | 2 |
320320
| rx-sampling | uint | Audio sampling rate. | [Supported Audio Sampling Rates](#232-supported-audio-sampling-rates) | 48000 |
321-
| rx-audio-format | string | Audio format type. | `S8`, `S16LE`, `S24LE` | `S16LE` |
321+
| rx-audio-format | string | Audio format type. | `PCM8`, `PCM16`, `PCM24` | `PCM16` |
322322
| rx-ptime | string | Packetization time for the audio stream. | `1ms`, `125us`, `250us`, `333us`, `4ms`, `80us`, `1.09ms`, `0.14ms`, `0.09ms` | `1.09ms` for 44.1kHz, `1ms` for others |
323323

324+
> **Note**: The `PCM` formats are interpreted as big endian.
325+
324326
#### 4.2.2. Preparing Output Path
325327

326328
In our pipelines, we will use the `$OUTPUT` variable to hold the path to the audio file.
@@ -344,7 +346,7 @@ export VFIO_PORT_R="pci_address_of_the_device"
344346
export OUTPUT="path_to_the_file_we_want_to_save"
345347
346348
# Run the receiver pipeline
347-
gst-launch-1.0 -v mtl_st30p_rx rx-queues=4 udp-port=30000 payload-type=111 dev-ip="192.168.96.2" ip="239.168.75.30" dev-port=$VFIO_PORT_R rx-audio-format=PCM24 rx-channel=2 rx-sampling=48000 ! \
349+
gst-launch-1.0 -v mtl_st30p_rx rx-queues=4 udp-port=30000 payload-type=111 dev-ip="192.168.96.2" ip="239.168.75.30" dev-port=$VFIO_PORT_R rx-audio-format=PCM16 rx-channel=2 rx-sampling=48000 ! \
348350
filesink location=$OUTPUT --gst-plugin-path $GSTREAMER_PLUGINS_PATH
349351
```
350352

ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum {
103103
static GstStaticPadTemplate gst_mtl_st30p_rx_src_pad_template =
104104
GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS,
105105
GST_STATIC_CAPS("audio/x-raw, "
106-
"format = (string) {S8, S16LE, S24LE},"
106+
"format = (string) {S8, S16BE, S24BE},"
107107
"channels = (int) [1, 2], "
108108
"rate = (int) {44100, 48000, 96000}"));
109109

@@ -362,11 +362,11 @@ static gboolean gst_mtl_st30p_rx_negotiate(GstBaseSrc* basesrc) {
362362

363363
switch (ops_rx->fmt) {
364364
case ST30_FMT_PCM24:
365-
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S24LE, sampling, ops_rx->channel,
365+
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S24BE, sampling, ops_rx->channel,
366366
NULL);
367367
break;
368368
case ST30_FMT_PCM16:
369-
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S16LE, sampling, ops_rx->channel,
369+
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S16BE, sampling, ops_rx->channel,
370370
NULL);
371371
break;
372372
case ST30_FMT_PCM8:

ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typedef struct {
109109
static GstStaticPadTemplate gst_mtl_st30p_tx_sink_pad_template =
110110
GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
111111
GST_STATIC_CAPS("audio/x-raw, "
112-
"format = (string) {S8, S16LE, S24LE},"
112+
"format = (string) {S8, S16BE, S24BE},"
113113
"channels = (int) [1, 2], "
114114
"rate = (int) {44100, 48000, 96000}"));
115115

@@ -308,19 +308,21 @@ static gboolean gst_mtl_st30p_tx_session_create(Gst_Mtl_St30p_Tx* sink, GstCaps*
308308
}
309309
ops_tx.name = "st30sink";
310310
ops_tx.fmt = ST30_FMT_PCM16;
311-
if (!info->finfo) {
312-
ops_tx.fmt = ST30_FMT_PCM24;
313-
} else {
314-
if (info->finfo->format == GST_AUDIO_FORMAT_S24LE) {
315-
ops_tx.fmt = ST30_FMT_PCM24;
316-
} else if (info->finfo->format == GST_AUDIO_FORMAT_S16LE) {
317-
ops_tx.fmt = ST30_FMT_PCM16;
318-
} else if (info->finfo->format == GST_AUDIO_FORMAT_S8) {
319-
ops_tx.fmt = ST30_FMT_PCM8;
320-
} else {
321-
gst_audio_info_free(info);
322-
GST_ERROR(" invalid format audio");
323-
return FALSE;
311+
if (info->finfo) {
312+
switch (info->finfo->format) {
313+
case GST_AUDIO_FORMAT_S24BE:
314+
ops_tx.fmt = ST30_FMT_PCM24;
315+
break;
316+
case GST_AUDIO_FORMAT_S16BE:
317+
ops_tx.fmt = ST30_FMT_PCM16;
318+
break;
319+
case GST_AUDIO_FORMAT_S8:
320+
ops_tx.fmt = ST30_FMT_PCM8;
321+
break;
322+
default:
323+
gst_audio_info_free(info);
324+
GST_ERROR(" invalid audio format");
325+
return FALSE;
324326
}
325327
}
326328
ops_tx.channel = info->channels;

include/st30_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct st_rx_audio_session_handle_impl* st30_rx_handle;
9797

9898
/**
9999
* Payload format of st2110-30/31(audio) streaming
100+
* Note: PCM format is interpreted as big endian.
100101
*/
101102
enum st30_fmt {
102103
ST30_FMT_PCM8 = 0, /**< 8 bits per channel */

0 commit comments

Comments
 (0)