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

Fix: st30_pipeline don't close until mbuf is free #1049

Merged
merged 1 commit into from
Jan 30, 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
27 changes: 26 additions & 1 deletion ecosystem/gstreamer_plugin/gst_mtl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
5 changes: 4 additions & 1 deletion ecosystem/gstreamer_plugin/gst_mtl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 13 additions & 9 deletions ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down
23 changes: 1 addition & 22 deletions ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions lib/src/st2110/pipeline/st30_pipeline_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading