From e3f5ccb3333f3b22c41e59cf78e4343c99187009 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Wed, 23 Sep 2015 02:51:57 +1000 Subject: [PATCH] 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 --- gst/mpegtsdemux/tsdemux.c | 28 ++++++++++++++++++++-------- gst/mpegtsdemux/tsdemux.h | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index 8a41f90e8c..91d37763a1 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -246,24 +246,24 @@ struct _TSDemuxStream GST_STATIC_CAPS ("subpicture/x-pgs; subpicture/x-dvd; subpicture/x-dvb") 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, VIDEO_CAPS); static GstStaticPadTemplate audio_template = -GST_STATIC_PAD_TEMPLATE ("audio_%04x", +GST_STATIC_PAD_TEMPLATE ("audio_%01x_%05x", GST_PAD_SRC, GST_PAD_SOMETIMES, AUDIO_CAPS); static GstStaticPadTemplate subpicture_template = -GST_STATIC_PAD_TEMPLATE ("subpicture_%04x", +GST_STATIC_PAD_TEMPLATE ("subpicture_%01x_%05x", GST_PAD_SRC, GST_PAD_SOMETIMES, SUBPICTURE_CAPS); static GstStaticPadTemplate private_template = -GST_STATIC_PAD_TEMPLATE ("private_%04x", +GST_STATIC_PAD_TEMPLATE ("private_%01x_%05x", GST_PAD_SRC, GST_PAD_SOMETIMES, GST_STATIC_CAPS_ANY); @@ -418,6 +418,7 @@ gst_ts_demux_reset (MpegTSBase * base) demux->group_id = G_MAXUINT; demux->last_seek_offset = -1; + demux->program_generation = 0; } static void @@ -1533,16 +1534,24 @@ done: if (caps) { if (is_audio) { 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) { 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) { 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) { 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 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 = 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 * a new segment */ if (demux->segment_event) { diff --git a/gst/mpegtsdemux/tsdemux.h b/gst/mpegtsdemux/tsdemux.h index b416733d72..32cbde27ce 100644 --- a/gst/mpegtsdemux/tsdemux.h +++ b/gst/mpegtsdemux/tsdemux.h @@ -64,6 +64,7 @@ struct _GstTSDemux gboolean emit_statistics; /*< private >*/ + gint program_generation; /* Incremented each time we switch program 0..15 */ MpegTSBaseProgram *program; /* Current program */ MpegTSBaseProgram *previous_program; /* Previous program, to deactivate once * the new program becomes active */