tsdemux: Change the pad naming scheme to include a generation ID

A simple fix for the problem of creating new pads with duplicate
names when switching program, easier than the alternative of
trying to work out which pads might persist and manage that.

See https://bugzilla.gnome.org/show_bug.cgi?id=758454
This commit is contained in:
Jan Schmidt 2015-09-23 02:51:57 +10:00 committed by Sebastian Dröge
parent a40ecc1168
commit e3f5ccb333
2 changed files with 21 additions and 8 deletions

View file

@ -246,24 +246,24 @@ struct _TSDemuxStream
GST_STATIC_CAPS ("subpicture/x-pgs; subpicture/x-dvd; subpicture/x-dvb") GST_STATIC_CAPS ("subpicture/x-pgs; subpicture/x-dvd; subpicture/x-dvb")
static GstStaticPadTemplate video_template = static GstStaticPadTemplate video_template =
GST_STATIC_PAD_TEMPLATE ("video_%04x", GST_PAD_SRC, GST_STATIC_PAD_TEMPLATE ("video_%01x_%05x", GST_PAD_SRC,
GST_PAD_SOMETIMES, GST_PAD_SOMETIMES,
VIDEO_CAPS); VIDEO_CAPS);
static GstStaticPadTemplate audio_template = static GstStaticPadTemplate audio_template =
GST_STATIC_PAD_TEMPLATE ("audio_%04x", GST_STATIC_PAD_TEMPLATE ("audio_%01x_%05x",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_SOMETIMES, GST_PAD_SOMETIMES,
AUDIO_CAPS); AUDIO_CAPS);
static GstStaticPadTemplate subpicture_template = static GstStaticPadTemplate subpicture_template =
GST_STATIC_PAD_TEMPLATE ("subpicture_%04x", GST_STATIC_PAD_TEMPLATE ("subpicture_%01x_%05x",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_SOMETIMES, GST_PAD_SOMETIMES,
SUBPICTURE_CAPS); SUBPICTURE_CAPS);
static GstStaticPadTemplate private_template = static GstStaticPadTemplate private_template =
GST_STATIC_PAD_TEMPLATE ("private_%04x", GST_STATIC_PAD_TEMPLATE ("private_%01x_%05x",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_SOMETIMES, GST_PAD_SOMETIMES,
GST_STATIC_CAPS_ANY); GST_STATIC_CAPS_ANY);
@ -418,6 +418,7 @@ gst_ts_demux_reset (MpegTSBase * base)
demux->group_id = G_MAXUINT; demux->group_id = G_MAXUINT;
demux->last_seek_offset = -1; demux->last_seek_offset = -1;
demux->program_generation = 0;
} }
static void static void
@ -1533,16 +1534,24 @@ done:
if (caps) { if (caps) {
if (is_audio) { if (is_audio) {
template = gst_static_pad_template_get (&audio_template); template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid); name =
g_strdup_printf ("audio_%01x_%04x", demux->program_generation,
bstream->pid);
} else if (is_video) { } else if (is_video) {
template = gst_static_pad_template_get (&video_template); template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid); name =
g_strdup_printf ("video_%01x_%04x", demux->program_generation,
bstream->pid);
} else if (is_private) { } else if (is_private) {
template = gst_static_pad_template_get (&private_template); template = gst_static_pad_template_get (&private_template);
name = g_strdup_printf ("private_%04x", bstream->pid); name =
g_strdup_printf ("private_%01x_%04x", demux->program_generation,
bstream->pid);
} else if (is_subpicture) { } else if (is_subpicture) {
template = gst_static_pad_template_get (&subpicture_template); template = gst_static_pad_template_get (&subpicture_template);
name = g_strdup_printf ("subpicture_%04x", bstream->pid); name =
g_strdup_printf ("subpicture_%01x_%04x", demux->program_generation,
bstream->pid);
} else } else
g_assert_not_reached (); g_assert_not_reached ();
@ -1799,6 +1808,9 @@ gst_ts_demux_program_started (MpegTSBase * base, MpegTSBaseProgram * program)
demux->program_number = program->program_number; demux->program_number = program->program_number;
demux->program = program; demux->program = program;
/* Increment the program_generation counter */
demux->program_generation = (demux->program_generation + 1) & 0xf;
/* If this is not the initial program, we need to calculate /* If this is not the initial program, we need to calculate
* a new segment */ * a new segment */
if (demux->segment_event) { if (demux->segment_event) {

View file

@ -64,6 +64,7 @@ struct _GstTSDemux
gboolean emit_statistics; gboolean emit_statistics;
/*< private >*/ /*< private >*/
gint program_generation; /* Incremented each time we switch program 0..15 */
MpegTSBaseProgram *program; /* Current program */ MpegTSBaseProgram *program; /* Current program */
MpegTSBaseProgram *previous_program; /* Previous program, to deactivate once MpegTSBaseProgram *previous_program; /* Previous program, to deactivate once
* the new program becomes active */ * the new program becomes active */