From 22fb7b7b71bf028faddcefd5c5cd77d95cc51e2c Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Mon, 10 Jan 2022 14:16:28 +0100 Subject: [PATCH] tsmux: Deterministically order program streams by PID Part-of: --- .../gst/mpegtsmux/tsmux/tsmux.c | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c index 390f60f455..299506bce8 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c @@ -609,10 +609,30 @@ tsmux_program_get_scte35_pid (TsMuxProgram * program) void tsmux_program_add_stream (TsMuxProgram * program, TsMuxStream * stream) { + GPtrArray *streams; + guint i; + gint array_index = -1 /* append */ ; + guint16 pid; + g_return_if_fail (program != NULL); g_return_if_fail (stream != NULL); - g_ptr_array_add (program->streams, stream); + streams = program->streams; + pid = tsmux_stream_get_pid (stream); + + /* Insert sorted by PID */ + for (i = 0; i < streams->len; i++) { + TsMuxStream *s = g_ptr_array_index (streams, i); + + if (pid < tsmux_stream_get_pid (s)) { + array_index = i; + GST_DEBUG ("PID 0x%04x: Using PID-order index %d/%u", + pid, array_index, streams->len); + break; + } + } + + g_ptr_array_insert (streams, array_index, stream); program->pmt_changed = TRUE; }