Skip to content

Commit 375536a

Browse files
authored
Fix: st30_pipeline don't close until mbuf is free (#1049)
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. Added sleep after last packet status is set to ST30P_TX_FRAME_FREE Pass the correct sampling rate by the st30 RX Gstreamer plugin in negotiations. Signed-off-by: Kasiewicz, Marek <[email protected]>
1 parent 6b056c8 commit 375536a

File tree

5 files changed

+51
-33
lines changed

5 files changed

+51
-33
lines changed

ecosystem/gstreamer_plugin/gst_mtl_common.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ gboolean gst_mtl_common_parse_audio_format(const char* format, enum st30_fmt* au
193193
return TRUE;
194194
}
195195

196-
gboolean gst_mtl_common_parse_sampling(gint sampling, enum st30_sampling* st_sampling) {
196+
gboolean gst_mtl_common_gst_to_st_sampling(gint sampling,
197+
enum st30_sampling* st_sampling) {
197198
if (!st_sampling) {
198199
GST_ERROR("Invalid st_sampling pointer");
199200
return FALSE;
@@ -210,6 +211,30 @@ gboolean gst_mtl_common_parse_sampling(gint sampling, enum st30_sampling* st_sam
210211
*st_sampling = ST30_SAMPLING_96K;
211212
return TRUE;
212213
default:
214+
GST_ERROR("Unsupported sampling value");
215+
return FALSE;
216+
}
217+
}
218+
219+
gboolean gst_mtl_common_st_to_gst_sampling(enum st30_sampling st_sampling,
220+
gint* gst_sampling) {
221+
if (!gst_sampling) {
222+
GST_ERROR("Invalid gst_sampling pointer");
223+
return FALSE;
224+
}
225+
226+
switch (st_sampling) {
227+
case ST31_SAMPLING_44K:
228+
*gst_sampling = GST_MTL_SUPPORTED_AUDIO_SAMPLING_44_1K;
229+
return TRUE;
230+
case ST30_SAMPLING_48K:
231+
*gst_sampling = GST_MTL_SUPPORTED_AUDIO_SAMPLING_48K;
232+
return TRUE;
233+
case ST30_SAMPLING_96K:
234+
*gst_sampling = GST_MTL_SUPPORTED_AUDIO_SAMPLING_96K;
235+
return TRUE;
236+
default:
237+
GST_ERROR("Unsupported st_sampling value");
213238
return FALSE;
214239
}
215240
}

ecosystem/gstreamer_plugin/gst_mtl_common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ gboolean gst_mtl_common_parse_fps_code(gint fps_code, enum st_fps* fps);
8484
gboolean gst_mtl_common_parse_pixel_format(const char* format, enum st_frame_fmt* fmt);
8585

8686
gboolean gst_mtl_common_parse_audio_format(const char* format, enum st30_fmt* audio);
87-
gboolean gst_mtl_common_parse_sampling(gint sampling, enum st30_sampling* st_sampling);
87+
gboolean gst_mtl_common_gst_to_st_sampling(gint sampling,
88+
enum st30_sampling* st_sampling);
89+
gboolean gst_mtl_common_st_to_gst_sampling(enum st30_sampling st_sampling,
90+
gint* gst_sampling);
8891

8992
gboolean gst_mtl_common_parse_dev_arguments(struct mtl_init_params* mtl_init_params,
9093
StDevArgs* devArgs);

ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static gboolean gst_mtl_st30p_rx_start(GstBaseSrc* basesrc) {
208208
ops_rx->ptime = ST30_PTIME_1MS;
209209
ops_rx->flags |= ST30P_RX_FLAG_BLOCK_GET;
210210

211-
if (!gst_mtl_common_parse_sampling(src->sampling, &ops_rx->sampling)) {
211+
if (!gst_mtl_common_gst_to_st_sampling(src->sampling, &ops_rx->sampling)) {
212212
GST_ERROR("Failed to parse ops_rx sampling %d", src->sampling);
213213
return FALSE;
214214
}
@@ -353,25 +353,32 @@ static void gst_mtl_st30p_rx_get_property(GObject* object, guint prop_id, GValue
353353
*/
354354

355355
static gboolean gst_mtl_st30p_rx_negotiate(GstBaseSrc* basesrc) {
356-
GstAudioInfo* info;
357356
Gst_Mtl_St30p_Rx* src = GST_MTL_ST30P_RX(basesrc);
358357
struct st30p_rx_ops* ops_rx = &src->ops_rx;
359-
gint ret;
358+
GstAudioInfo* info;
359+
gint sampling;
360360
GstCaps* caps;
361+
gint ret;
361362

362363
info = gst_audio_info_new();
363364

365+
if (!gst_mtl_common_st_to_gst_sampling(ops_rx->sampling, &sampling)) {
366+
GST_ERROR("Failed to convert sampling rate");
367+
gst_audio_info_free(info);
368+
return FALSE;
369+
}
370+
364371
switch (ops_rx->fmt) {
365372
case ST30_FMT_PCM24:
366-
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S24LE, info->rate, info->channels,
373+
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S24LE, sampling, ops_rx->channel,
367374
NULL);
368375
break;
369376
case ST30_FMT_PCM16:
370-
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S16LE, info->rate, info->channels,
377+
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S16LE, sampling, ops_rx->channel,
371378
NULL);
372379
break;
373380
case ST30_FMT_PCM8:
374-
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S8, info->rate, info->channels,
381+
gst_audio_info_set_format(info, GST_AUDIO_FORMAT_S8, sampling, ops_rx->channel,
375382
NULL);
376383
break;
377384
default:
@@ -380,9 +387,6 @@ static gboolean gst_mtl_st30p_rx_negotiate(GstBaseSrc* basesrc) {
380387
return FALSE;
381388
}
382389

383-
info->rate = ops_rx->sampling;
384-
info->channels = ops_rx->channel;
385-
386390
caps = gst_caps_new_simple("audio/x-raw", "format", G_TYPE_STRING,
387391
gst_audio_format_to_string(info->finfo->format), "channels",
388392
G_TYPE_INT, info->channels, "rate", G_TYPE_INT, info->rate,

ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,6 @@ static GstFlowReturn gst_mtl_st30p_tx_chain(GstPad* pad, GstObject* parent,
128128
static gboolean gst_mtl_st30p_tx_start(GstBaseSink* bsink);
129129
static gboolean gst_mtl_st30p_tx_cur_frame_flush(Gst_Mtl_St30p_Tx* sink);
130130

131-
static gboolean gst_mtl_st30p_tx_parse_sampling(gint sampling,
132-
enum st30_sampling* st_sampling) {
133-
if (!st_sampling) {
134-
GST_ERROR("Invalid st_sampling pointer");
135-
return FALSE;
136-
}
137-
switch (sampling) {
138-
case GST_MTL_SUPPORTED_AUDIO_SAMPLING_44_1K:
139-
*st_sampling = ST31_SAMPLING_44K;
140-
return TRUE;
141-
case GST_MTL_SUPPORTED_AUDIO_SAMPLING_48K:
142-
*st_sampling = ST30_SAMPLING_48K;
143-
return TRUE;
144-
case GST_MTL_SUPPORTED_AUDIO_SAMPLING_96K:
145-
*st_sampling = ST30_SAMPLING_96K;
146-
return TRUE;
147-
default:
148-
return FALSE;
149-
}
150-
}
151-
152131
static void gst_mtl_st30p_tx_class_init(Gst_Mtl_St30p_TxClass* klass) {
153132
GObjectClass* gobject_class;
154133
GstElementClass* gstelement_class;
@@ -311,7 +290,7 @@ static gboolean gst_mtl_st30p_tx_session_create(Gst_Mtl_St30p_Tx* sink, GstCaps*
311290
}
312291
ops_tx.channel = info->channels;
313292

314-
if (!gst_mtl_st30p_tx_parse_sampling(info->rate, &ops_tx.sampling)) {
293+
if (!gst_mtl_common_gst_to_st_sampling(info->rate, &ops_tx.sampling)) {
315294
GST_ERROR("Failed to parse sampling rate");
316295
gst_audio_info_free(info);
317296
return FALSE;

lib/src/st2110/pipeline/st30_pipeline_tx.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx* ctx) {
350350
mt_sleep_ms(10);
351351
}
352352
}
353+
/* Workaround: When tx_st30p_frame_done is called and subsequently framebuff->stat is
354+
* set to ST30P_TX_FRAME_FREE, data from the framebuffer can still be in transport,
355+
* already packetized and copied into rte_mbuf, waiting to be sent.
356+
* TODO: add synchronization mechanism to ensure all data is sent before freeing the
357+
* session.
358+
*/
359+
mt_sleep_ms(50);
353360
}
354361

355362
struct st30_frame* st30p_tx_get_frame(st30p_tx_handle handle) {

0 commit comments

Comments
 (0)