Skip to content

Commit 1954564

Browse files
Fix: GStreamer plugins wrong memory buffer size (#1167)
In the st20tx and st30tx GStreamer plugins, the memory buffer size was incorrectly taken from the GstBuffer size which includes the combined size of all GstMemory elements in the buffer, as we Allow multiple GstMemory elements in the buffer This would result in a wrong buffer parsing. Fix via taking the size from the memory map.
1 parent 763f0b6 commit 1954564

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

ecosystem/gstreamer_plugin/gst_mtl_st20p_tx.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ static gboolean gst_mtl_st20p_tx_sink_event(GstPad* pad, GstObject* parent,
457457
static GstFlowReturn gst_mtl_st20p_tx_chain(GstPad* pad, GstObject* parent,
458458
GstBuffer* buf) {
459459
Gst_Mtl_St20p_Tx* sink = GST_MTL_ST20P_TX(parent);
460-
gint buffer_size = gst_buffer_get_size(buf);
461-
gint buffer_n = gst_buffer_n_memory(buf);
460+
gint buffer_size, buffer_n = gst_buffer_n_memory(buf);
462461
struct st_frame* frame = NULL;
463462
gint frame_size = sink->frame_size;
464463
GstMemory* gst_buffer_memory;
@@ -481,18 +480,20 @@ static GstFlowReturn gst_mtl_st20p_tx_chain(GstPad* pad, GstObject* parent,
481480
return GST_FLOW_ERROR;
482481
}
483482

484-
if (buffer_size != frame_size) {
485-
GST_ERROR("Buffer size %d does not match frame size %d", buffer_size, frame_size);
486-
return GST_FLOW_ERROR;
487-
}
488-
489483
for (int i = 0; i < buffer_n; i++) {
490484
gst_buffer_memory = gst_buffer_peek_memory(buf, i);
491485

492486
if (!gst_memory_map(gst_buffer_memory, &map_info, GST_MAP_READ)) {
493487
GST_ERROR("Failed to map memory");
494488
return GST_FLOW_ERROR;
495489
}
490+
buffer_size = map_info.size;
491+
492+
if (buffer_size < frame_size) {
493+
GST_ERROR("Buffer size %d is smaller than frame size %d", buffer_size, frame_size);
494+
gst_memory_unmap(gst_buffer_memory, &map_info);
495+
return GST_FLOW_ERROR;
496+
}
496497

497498
frame = st20p_tx_get_frame(sink->tx_handle);
498499
if (!frame) {

ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,14 @@ static GstFlowReturn gst_mtl_st30p_tx_chain(GstPad* pad, GstObject* parent,
527527
}
528528

529529
for (int i = 0; i < buffer_n; i++) {
530-
bytes_to_write = gst_buffer_get_size(buf);
531530
gst_buffer_memory = gst_buffer_peek_memory(buf, i);
532531

533532
if (!gst_memory_map(gst_buffer_memory, &map_info, GST_MAP_READ)) {
534533
GST_ERROR("Failed to map memory");
535534
return GST_FLOW_ERROR;
536535
}
537536

537+
bytes_to_write = map_info.size;
538538
/* This could be done with GstAdapter */
539539
while (bytes_to_write > 0) {
540540
frame = mtl_st30p_fetch_frame(sink);
@@ -566,6 +566,7 @@ static GstFlowReturn gst_mtl_st30p_tx_chain(GstPad* pad, GstObject* parent,
566566
}
567567
gst_memory_unmap(gst_buffer_memory, &map_info);
568568
}
569+
569570
gst_buffer_unref(buf);
570571
return GST_FLOW_OK;
571572
}

0 commit comments

Comments
 (0)