From ade531183f1b5c9e81fa770bde606be571a33248 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Tue, 2 Jul 2019 21:21:05 +0300 Subject: [PATCH] qtdemux: Provide a 30 frames lead-in for MP3 mpegaudioparse suggests MP3 needs 10 or 30 frames of lead-in (depending on mpegaudioversion, which we don't know here), thus provide at least 30 frames lead-in for such cases as a followup to commit cbfa4531ee5ef. --- gst/isomp4/qtdemux.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 79b5f06d18..8e03d6a9f1 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -5141,8 +5141,20 @@ gst_qtdemux_activate_segment (GstQTDemux * qtdemux, QtDemuxStream * stream, /* go back two frames to provide lead-in for non-raw audio decoders */ if (stream->subtype == FOURCC_soun && !stream->need_clip) { + guint32 lead_in = 2; guint32 old_index = kf_index; - kf_index = MAX (kf_index, 2) - 2; + GstStructure *s = gst_caps_get_structure (CUR_STREAM (stream)->caps, 0); + + if (gst_structure_has_name (s, "audio/mpeg")) { + gint mpegversion; + if (gst_structure_get_int (s, "mpegversion", &mpegversion) + && mpegversion == 1) { + /* mp3 could need up to 30 frames of lead-in per mpegaudioparse */ + lead_in = 30; + } + } + + kf_index = MAX (kf_index, lead_in) - lead_in; if (qtdemux_parse_samples (qtdemux, stream, kf_index)) { GST_DEBUG_OBJECT (stream->pad, "Moving backwards %u frames to ensure sufficient sound lead-in",