diff --git a/ecosystem/gstreamer_plugin/gst_mtl_common.c b/ecosystem/gstreamer_plugin/gst_mtl_common.c index 108f6fe5..d32b9f4d 100644 --- a/ecosystem/gstreamer_plugin/gst_mtl_common.c +++ b/ecosystem/gstreamer_plugin/gst_mtl_common.c @@ -193,7 +193,8 @@ gboolean gst_mtl_common_parse_audio_format(const char* format, enum st30_fmt* au return TRUE; } -gboolean gst_mtl_common_parse_sampling(gint sampling, enum st30_sampling* st_sampling) { +gboolean gst_mtl_common_gst_to_st_sampling(gint sampling, + enum st30_sampling* st_sampling) { if (!st_sampling) { GST_ERROR("Invalid st_sampling pointer"); return FALSE; @@ -210,6 +211,30 @@ gboolean gst_mtl_common_parse_sampling(gint sampling, enum st30_sampling* st_sam *st_sampling = ST30_SAMPLING_96K; return TRUE; default: + GST_ERROR("Unsupported sampling value"); + return FALSE; + } +} + +gboolean gst_mtl_common_st_to_gst_sampling(enum st30_sampling st_sampling, + gint* gst_sampling) { + if (!gst_sampling) { + GST_ERROR("Invalid gst_sampling pointer"); + return FALSE; + } + + switch (st_sampling) { + case ST31_SAMPLING_44K: + *gst_sampling = GST_MTL_SUPPORTED_AUDIO_SAMPLING_44_1K; + return TRUE; + case ST30_SAMPLING_48K: + *gst_sampling = GST_MTL_SUPPORTED_AUDIO_SAMPLING_48K; + return TRUE; + case ST30_SAMPLING_96K: + *gst_sampling = GST_MTL_SUPPORTED_AUDIO_SAMPLING_96K; + return TRUE; + default: + GST_ERROR("Unsupported st_sampling value"); return FALSE; } } diff --git a/ecosystem/gstreamer_plugin/gst_mtl_common.h b/ecosystem/gstreamer_plugin/gst_mtl_common.h index 715dd21a..c8233598 100644 --- a/ecosystem/gstreamer_plugin/gst_mtl_common.h +++ b/ecosystem/gstreamer_plugin/gst_mtl_common.h @@ -84,7 +84,10 @@ 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_sampling(gint sampling, enum st30_sampling* st_sampling); +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, + gint* gst_sampling); gboolean gst_mtl_common_parse_dev_arguments(struct mtl_init_params* mtl_init_params, StDevArgs* devArgs); diff --git a/ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c b/ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c index e95c2f33..f444a37f 100644 --- a/ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c +++ b/ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c @@ -208,7 +208,7 @@ static gboolean gst_mtl_st30p_rx_start(GstBaseSrc* basesrc) { ops_rx->ptime = ST30_PTIME_1MS; ops_rx->flags |= ST30P_RX_FLAG_BLOCK_GET; - if (!gst_mtl_common_parse_sampling(src->sampling, &ops_rx->sampling)) { + 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; } @@ -353,25 +353,32 @@ static void gst_mtl_st30p_rx_get_property(GObject* object, guint prop_id, GValue */ static gboolean gst_mtl_st30p_rx_negotiate(GstBaseSrc* basesrc) { - GstAudioInfo* info; Gst_Mtl_St30p_Rx* src = GST_MTL_ST30P_RX(basesrc); struct st30p_rx_ops* ops_rx = &src->ops_rx; - gint ret; + GstAudioInfo* info; + gint sampling; GstCaps* caps; + gint ret; info = gst_audio_info_new(); + if (!gst_mtl_common_st_to_gst_sampling(ops_rx->sampling, &sampling)) { + GST_ERROR("Failed to convert sampling rate"); + gst_audio_info_free(info); + return FALSE; + } + switch (ops_rx->fmt) { case ST30_FMT_PCM24: - gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S24LE, info->rate, info->channels, + gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S24LE, sampling, ops_rx->channel, NULL); break; case ST30_FMT_PCM16: - gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S16LE, info->rate, info->channels, + gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S16LE, sampling, ops_rx->channel, NULL); break; case ST30_FMT_PCM8: - gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S8, info->rate, info->channels, + gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S8, sampling, ops_rx->channel, NULL); break; default: @@ -380,9 +387,6 @@ static gboolean gst_mtl_st30p_rx_negotiate(GstBaseSrc* basesrc) { return FALSE; } - info->rate = ops_rx->sampling; - info->channels = ops_rx->channel; - caps = gst_caps_new_simple("audio/x-raw", "format", G_TYPE_STRING, gst_audio_format_to_string(info->finfo->format), "channels", G_TYPE_INT, info->channels, "rate", G_TYPE_INT, info->rate, diff --git a/ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c b/ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c index 1c098655..fc80dd28 100644 --- a/ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c +++ b/ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c @@ -128,27 +128,6 @@ static GstFlowReturn gst_mtl_st30p_tx_chain(GstPad* pad, GstObject* parent, static gboolean gst_mtl_st30p_tx_start(GstBaseSink* bsink); static gboolean gst_mtl_st30p_tx_cur_frame_flush(Gst_Mtl_St30p_Tx* sink); -static gboolean gst_mtl_st30p_tx_parse_sampling(gint sampling, - enum st30_sampling* st_sampling) { - if (!st_sampling) { - GST_ERROR("Invalid st_sampling pointer"); - return FALSE; - } - switch (sampling) { - case GST_MTL_SUPPORTED_AUDIO_SAMPLING_44_1K: - *st_sampling = ST31_SAMPLING_44K; - return TRUE; - case GST_MTL_SUPPORTED_AUDIO_SAMPLING_48K: - *st_sampling = ST30_SAMPLING_48K; - return TRUE; - case GST_MTL_SUPPORTED_AUDIO_SAMPLING_96K: - *st_sampling = ST30_SAMPLING_96K; - return TRUE; - default: - return FALSE; - } -} - static void gst_mtl_st30p_tx_class_init(Gst_Mtl_St30p_TxClass* klass) { GObjectClass* gobject_class; GstElementClass* gstelement_class; @@ -311,7 +290,7 @@ static gboolean gst_mtl_st30p_tx_session_create(Gst_Mtl_St30p_Tx* sink, GstCaps* } ops_tx.channel = info->channels; - if (!gst_mtl_st30p_tx_parse_sampling(info->rate, &ops_tx.sampling)) { + if (!gst_mtl_common_gst_to_st_sampling(info->rate, &ops_tx.sampling)) { GST_ERROR("Failed to parse sampling rate"); gst_audio_info_free(info); return FALSE; diff --git a/lib/src/st2110/pipeline/st30_pipeline_tx.c b/lib/src/st2110/pipeline/st30_pipeline_tx.c index 6188df68..760b8353 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st30_pipeline_tx.c @@ -350,6 +350,13 @@ static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx* ctx) { mt_sleep_ms(10); } } + /* Workaround: When tx_st30p_frame_done is called and subsequently framebuff->stat is + * set to ST30P_TX_FRAME_FREE, data from the framebuffer can still be in transport, + * already packetized and copied into rte_mbuf, waiting to be sent. + * TODO: add synchronization mechanism to ensure all data is sent before freeing the + * session. + */ + mt_sleep_ms(50); } struct st30_frame* st30p_tx_get_frame(st30p_tx_handle handle) {