diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c b/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c index cecedbd22a..1f88072689 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c @@ -388,6 +388,7 @@ gst_base_ts_mux_create_or_update_stream (GstBaseTsMux * mux, guint8 color_spec = 0; const gchar *stream_format = NULL; const char *interlace_mode = NULL; + gchar *pmt_name; GST_DEBUG_OBJECT (ts_pad, "%s stream with PID 0x%04x for caps %" GST_PTR_FORMAT, @@ -693,6 +694,12 @@ gst_base_ts_mux_create_or_update_stream (GstBaseTsMux * mux, goto error; } + pmt_name = g_strdup_printf ("PMT_%d", ts_pad->pid); + if (mux->prog_map && gst_structure_has_field (mux->prog_map, pmt_name)) { + gst_structure_get_int (mux->prog_map, pmt_name, &ts_pad->stream->pmt_index); + } + g_free (pmt_name); + interlace_mode = gst_structure_get_string (s, "interlace-mode"); gst_structure_get_int (s, "rate", &ts_pad->stream->audio_sampling); gst_structure_get_int (s, "channels", &ts_pad->stream->audio_channels); diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c index 299506bce8..e2b994fd4e 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmux.c @@ -611,24 +611,39 @@ tsmux_program_add_stream (TsMuxProgram * program, TsMuxStream * stream) { GPtrArray *streams; guint i; - gint array_index = -1 /* append */ ; + gint pmt_index, array_index = -1 /* append */ ; guint16 pid; g_return_if_fail (program != NULL); g_return_if_fail (stream != NULL); streams = program->streams; + pmt_index = stream->pmt_index; 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 (pmt_index >= 0) { + /* Insert into streams with known indices */ + 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; + if (s->pmt_index < 0 || pmt_index < s->pmt_index) { + array_index = i; + GST_DEBUG ("PID 0x%04x: Using known-order index %d/%u", + pid, array_index, streams->len); + break; + } + } + } else { + /* Insert after streams with known indices, sorted by PID */ + for (i = 0; i < streams->len; i++) { + TsMuxStream *s = g_ptr_array_index (streams, i); + + if (s->pmt_index < 0 && 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; + } } } diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.c b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.c index 151ad83902..04dafa0c5e 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.c @@ -117,6 +117,7 @@ tsmux_stream_new (guint16 pid, guint stream_type) stream->pes_payload_size = 0; stream->cur_pes_payload_size = 0; stream->pes_bytes_written = 0; + stream->pmt_index = -1; switch (stream_type) { case TSMUX_ST_VIDEO_MPEG1: diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.h b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.h index 6bdcde8675..3920e4076a 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.h +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/tsmux/tsmuxstream.h @@ -150,6 +150,8 @@ struct TsMuxStream { guint8 id; /* extended stream id (13818-1 Amdt 2) */ guint8 id_extended; + /* requested index in the PMT */ + gint pmt_index; gboolean is_video_stream;