Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: ptime as a parameter to st30 GST plugins #1055

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ecosystem/gstreamer_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ The `mtl_st30p_tx` plugin supports the following pad capabilities:
|---------------------|--------|-------------------------------------------------------|-------------------------|---------------|
| tx-samplerate | uint | Sample rate of the audio. | [gst_mtl_supported_audio_sampling](#232-supported-audio-sampling-rates-gst_mtl_supported_audio_sampling) | 0 |
| tx-channels | uint | Number of audio channels. | 1 to 8 | 2 |
| 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 |

#### 4.1.2. Example GStreamer Pipeline for Transmission with s16LE format

Expand Down Expand Up @@ -310,6 +311,7 @@ The `mtl_st30p_rx` plugin supports the following pad capabilities:
| rx-channel | uint | Audio channel number. | 0 to G_MAXUINT | 2 |
| rx-sampling | uint | Audio sampling rate. | [gst_mtl_supported_audio_sampling](#232-supported-audio-sampling-rates-gst_mtl_supported_audio_sampling) | 48000 |
| rx-audio-format | string | Audio format type. | `S8`, `S16LE`, `S24LE` | `S16LE` |
| 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 |

#### 4.2.2. Preparing Output Path

Expand Down
32 changes: 32 additions & 0 deletions ecosystem/gstreamer_plugin/gst_mtl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,38 @@ gboolean gst_mtl_common_parse_pixel_format(const char* format, enum st_frame_fmt
return TRUE;
}

gboolean gst_mtl_common_parse_ptime(const char* ptime_str, enum st30_ptime* ptime) {
if (!ptime_str || !ptime) {
GST_ERROR("%s, invalid input\n", __func__);
return FALSE;
}

if (strcmp(ptime_str, "1ms") == 0) {
*ptime = ST30_PTIME_1MS;
} else if (strcmp(ptime_str, "125us") == 0) {
*ptime = ST30_PTIME_125US;
} else if (strcmp(ptime_str, "250us") == 0) {
*ptime = ST30_PTIME_250US;
} else if (strcmp(ptime_str, "333us") == 0) {
*ptime = ST30_PTIME_333US;
} else if (strcmp(ptime_str, "4ms") == 0) {
*ptime = ST30_PTIME_4MS;
} else if (strcmp(ptime_str, "80us") == 0) {
*ptime = ST31_PTIME_80US;
} else if (strcmp(ptime_str, "1.09ms") == 0) {
*ptime = ST31_PTIME_1_09MS;
} else if (strcmp(ptime_str, "0.14ms") == 0) {
*ptime = ST31_PTIME_0_14MS;
} else if (strcmp(ptime_str, "0.09ms") == 0) {
*ptime = ST31_PTIME_0_09MS;
} else {
GST_ERROR("invalid packet time %s\n", ptime_str);
return FALSE;
}

return TRUE;
}

gboolean gst_mtl_common_parse_audio_format(const char* format, enum st30_fmt* audio) {
if (!audio || !format) {
GST_ERROR("%s, invalid input\n", __func__);
Expand Down
1 change: 1 addition & 0 deletions ecosystem/gstreamer_plugin/gst_mtl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ gboolean gst_mtl_common_parse_fps_code(gint fps_code, enum st_fps* fps);
gboolean gst_mtl_common_parse_pixel_format(const char* format, enum st_frame_fmt* fmt);

gboolean gst_mtl_common_parse_audio_format(const char* format, enum st30_fmt* audio);
gboolean gst_mtl_common_parse_ptime(const char* ptime_str, enum st30_ptime* ptime);
gboolean gst_mtl_common_gst_to_st_sampling(gint sampling,
enum st30_sampling* st_sampling);
gboolean gst_mtl_common_st_to_gst_sampling(enum st30_sampling st_sampling,
Expand Down
26 changes: 25 additions & 1 deletion ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum {
PROP_ST30P_RX_CHANNEL,
PROP_ST30P_RX_SAMPLING,
PROP_ST30P_RX_AUDIO_FORMAT,
PROP_ST30P_RX_PTIME,
PROP_MAX
};

Expand Down Expand Up @@ -180,6 +181,12 @@ static void gst_mtl_st30p_rx_class_init(Gst_Mtl_St30p_RxClass* klass) {
gobject_class, PROP_ST30P_RX_AUDIO_FORMAT,
g_param_spec_string("rx-audio-format", "Audio format", "Audio format type.", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property(
gobject_class, PROP_ST30P_RX_PTIME,
g_param_spec_string("rx-ptime", "Packetization time",
"Packetization time for the audio stream", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}

static gboolean gst_mtl_st30p_rx_start(GstBaseSrc* basesrc) {
Expand All @@ -205,14 +212,25 @@ static gboolean gst_mtl_st30p_rx_start(GstBaseSrc* basesrc) {
ops_rx->name = "st30src";
ops_rx->channel = src->channel;
ops_rx->port.num_port = 1;
ops_rx->ptime = ST30_PTIME_1MS;
ops_rx->flags |= ST30P_RX_FLAG_BLOCK_GET;

if (!gst_mtl_common_gst_to_st_sampling(src->sampling, &ops_rx->sampling)) {
GST_ERROR("Failed to parse ops_rx sampling %d", src->sampling);
return FALSE;
}

if (src->ptime[0] != '\0') {
if (!gst_mtl_common_parse_ptime(src->ptime, &ops_rx->ptime)) {
GST_ERROR("Failed to parse ops_rx ptime %s", src->ptime);
return FALSE;
}
} else {
if (ops_rx->sampling == ST31_SAMPLING_44K)
ops_rx->ptime = ST31_PTIME_1_09MS;
else
ops_rx->ptime = ST30_PTIME_1MS;
}

if (!gst_mtl_common_parse_audio_format(src->audio_format, &ops_rx->fmt)) {
GST_ERROR("Failed to parse ops_rx audio format %s", src->audio_format);
return FALSE;
Expand Down Expand Up @@ -312,6 +330,9 @@ static void gst_mtl_st30p_rx_set_property(GObject* object, guint prop_id,
case PROP_ST30P_RX_AUDIO_FORMAT:
strncpy(self->audio_format, g_value_get_string(value), MTL_PORT_MAX_LEN);
break;
case PROP_ST30P_RX_PTIME:
g_strlcpy(self->ptime, g_value_get_string(value), MTL_PORT_MAX_LEN);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
Expand Down Expand Up @@ -341,6 +362,9 @@ static void gst_mtl_st30p_rx_get_property(GObject* object, guint prop_id, GValue
case PROP_ST30P_RX_AUDIO_FORMAT:
g_value_set_string(value, src->audio_format);
break;
case PROP_ST30P_RX_PTIME:
g_value_set_string(value, src->ptime);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct _Gst_Mtl_St30p_Rx {
/* audio (st30p) specific arguments */
guint channel;
guint sampling;
gboolean ptime;
gchar ptime[MTL_PORT_MAX_LEN];
gchar audio_format[MTL_PORT_MAX_LEN];
};

Expand Down
25 changes: 24 additions & 1 deletion ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum {
PROP_ST30P_TX_RETRY = PROP_GENERAL_MAX,
PROP_ST30P_TX_FRAMERATE,
PROP_ST30P_TX_FRAMEBUFF_NUM,
PROP_ST30P_TX_PTIME,
PROP_MAX
};

Expand Down Expand Up @@ -157,6 +158,12 @@ static void gst_mtl_st30p_tx_class_init(Gst_Mtl_St30p_TxClass* klass) {
g_param_spec_uint("tx-framebuff-num", "Number of framebuffers",
"Number of framebuffers to be used for transmission.", 0,
G_MAXUINT, 3, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property(
gobject_class, PROP_ST30P_TX_PTIME,
g_param_spec_string("tx-ptime", "Packetization time",
"Packetization time for the audio stream", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}

static gboolean gst_mtl_st30p_tx_start(GstBaseSink* bsink) {
Expand Down Expand Up @@ -215,6 +222,9 @@ static void gst_mtl_st30p_tx_set_property(GObject* object, guint prop_id,
case PROP_ST30P_TX_FRAMEBUFF_NUM:
self->framebuffer_num = g_value_get_uint(value);
break;
case PROP_ST30P_TX_PTIME:
g_strlcpy(self->ptime, g_value_get_string(value), MTL_PORT_MAX_LEN);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
Expand All @@ -241,6 +251,9 @@ static void gst_mtl_st30p_tx_get_property(GObject* object, guint prop_id, GValue
case PROP_ST30P_TX_FRAMEBUFF_NUM:
g_value_set_uint(value, sink->framebuffer_num);
break;
case PROP_ST30P_TX_PTIME:
g_value_set_string(value, sink->ptime);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
Expand Down Expand Up @@ -296,7 +309,17 @@ static gboolean gst_mtl_st30p_tx_session_create(Gst_Mtl_St30p_Tx* sink, GstCaps*
return FALSE;
}
gst_audio_info_free(info);
ops_tx.ptime = ST30_PTIME_1MS;
if (sink->ptime[0] != '\0') {
if (!gst_mtl_common_parse_ptime(sink->ptime, &ops_tx.ptime)) {
GST_ERROR("Failed to parse ops_tx ptime %s", sink->ptime);
return FALSE;
}
} else {
if (ops_tx.sampling == ST31_SAMPLING_44K)
ops_tx.ptime = ST31_PTIME_1_09MS;
else
ops_tx.ptime = ST30_PTIME_1MS;
}

ops_tx.port.num_port = 1;

Expand Down
1 change: 1 addition & 0 deletions ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct _Gst_Mtl_St30p_Tx {
SessionPortArgs portArgs; /* imtl tx session */
guint framebuffer_num;
guint framerate;
gchar ptime[MTL_PORT_MAX_LEN];
};

G_END_DECLS
Expand Down