diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index e001e8b312..b602ab7c14 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -1654,6 +1654,12 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset) /* Search for the first PCRs */ ret = process_pcr (base, base->first_pat_offset, &initial, 10, TRUE); + + if (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED) { + GST_WARNING ("Problem getting initial PCRs"); + goto beach; + } + mpegts_packetizer_clear (base->packetizer); /* Remove current program so we ensure looking for a PAT when scanning the * for the final PCR */ @@ -1661,11 +1667,6 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset) base->pat = NULL; mpegts_base_remove_program (base, demux->current_program_number); - if (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED) { - GST_WARNING ("Problem getting initial PCRs"); - goto beach; - } - /* Find end position */ if (G_UNLIKELY (!gst_pad_query_peer_duration (base->sinkpad, &format, &total_bytes) || format != GST_FORMAT_BYTES)) { @@ -1718,8 +1719,10 @@ beach: mpegts_packetizer_clear (base->packetizer); /* Remove current program */ - gst_structure_free (base->pat); - base->pat = NULL; + if (base->pat) { + gst_structure_free (base->pat); + base->pat = NULL; + } mpegts_base_remove_program (base, demux->current_program_number); return ret;