tsmux: Allow specifying PMT order via the prog-map

Look for an entry `PMT_<PID>` in the `prog-map`, which specifies the
relative index of the stream in the PMT.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1510>
This commit is contained in:
Jan Alexander Steffens (heftig) 2022-01-10 13:34:21 +01:00 committed by GStreamer Marge Bot
parent 22fb7b7b71
commit 2f7ec968f4
4 changed files with 34 additions and 9 deletions

View file

@ -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);

View file

@ -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;
}
}
}

View file

@ -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:

View file

@ -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;