summaryrefslogtreecommitdiff
path: root/gst/mpegtsmux
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>2021-05-20 10:09:57 +0200
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-05-20 13:35:06 +0000
commit0312887452e25c75124f38126c2bd704d88caaa9 (patch)
treece687d316c32fc3e8c5629dcd130d13c2f420bb2 /gst/mpegtsmux
parent360a1951585a6f41e8ca02ed5dfaf085fd6a104e (diff)
downloadgstreamer-plugins-bad-0312887452e25c75124f38126c2bd704d88caaa9.tar.gz
mpegtsmux: Fixup program array indices after stream removal
Each stream stores the `program_array_index` of its position in its program's `streams` array. When we remove a stream from this array, we need to correct the `program_array_index` of all streams that were backshifted by the removal. Also extract the removal into a new function and add some more safety checks. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2266>
Diffstat (limited to 'gst/mpegtsmux')
-rw-r--r--gst/mpegtsmux/tsmux/tsmux.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c
index 566111bf8..632f9f8f4 100644
--- a/gst/mpegtsmux/tsmux/tsmux.c
+++ b/gst/mpegtsmux/tsmux/tsmux.c
@@ -757,6 +757,31 @@ tsmux_find_stream (TsMux * mux, guint16 pid)
return found;
}
+static gboolean
+tsmux_program_remove_stream (TsMuxProgram * program, TsMuxStream * stream)
+{
+ GArray *streams = program->streams;
+ TsMuxStream *s;
+ gint i;
+
+ i = stream->program_array_index;
+ g_return_val_if_fail (i >= 0, FALSE);
+
+ s = g_array_index (streams, TsMuxStream *, i);
+ g_return_val_if_fail (s == stream, FALSE);
+
+ g_array_remove_index (streams, i);
+
+ /* Correct indices of remaining streams, if any */
+ for (; i < streams->len; i++) {
+ s = g_array_index (streams, TsMuxStream *, i);
+ s->program_array_index -= 1;
+ }
+
+ return streams->len == 0;
+}
+
+
gboolean
tsmux_remove_stream (TsMux * mux, guint16 pid, TsMuxProgram * program)
{
@@ -769,20 +794,16 @@ tsmux_remove_stream (TsMux * mux, guint16 pid, TsMuxProgram * program)
TsMuxStream *stream = (TsMuxStream *) cur->data;
if (tsmux_stream_get_pid (stream) == pid) {
- if (program->streams->len == 1) {
- tsmux_program_delete (mux, program);
- ret = TRUE;
- } else {
- program->streams =
- g_array_remove_index (program->streams,
- stream->program_array_index);
- }
-
+ ret = tsmux_program_remove_stream (program, stream);
mux->streams = g_list_remove (mux->streams, stream);
tsmux_stream_free (stream);
- return ret;
+ break;
}
}
+
+ if (ret)
+ tsmux_program_delete (mux, program);
+
return ret;
}