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>
This commit is contained in:
parent
360a195158
commit
0312887452
@ -757,6 +757,31 @@ tsmux_find_stream (TsMux * mux, guint16 pid)
|
|||||||
return found;
|
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
|
gboolean
|
||||||
tsmux_remove_stream (TsMux * mux, guint16 pid, TsMuxProgram * program)
|
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;
|
TsMuxStream *stream = (TsMuxStream *) cur->data;
|
||||||
|
|
||||||
if (tsmux_stream_get_pid (stream) == pid) {
|
if (tsmux_stream_get_pid (stream) == pid) {
|
||||||
if (program->streams->len == 1) {
|
ret = tsmux_program_remove_stream (program, stream);
|
||||||
tsmux_program_delete (mux, program);
|
|
||||||
ret = TRUE;
|
|
||||||
} else {
|
|
||||||
program->streams =
|
|
||||||
g_array_remove_index (program->streams,
|
|
||||||
stream->program_array_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
mux->streams = g_list_remove (mux->streams, stream);
|
mux->streams = g_list_remove (mux->streams, stream);
|
||||||
tsmux_stream_free (stream);
|
tsmux_stream_free (stream);
|
||||||
return ret;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
tsmux_program_delete (mux, program);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user