From b6303c46b79dea2e40177c7b236980c19c8b3d1b Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 14 Dec 2021 16:14:56 +0100 Subject: [PATCH] subparse: Handle GAP events before buffers Make sure we did initial negotiation and segment pushing if we get GAP events before buffers. Part-of: --- .../gst-plugins-base/gst/subparse/gstsubparse.c | 57 +++++++++++++++------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/subprojects/gst-plugins-base/gst/subparse/gstsubparse.c b/subprojects/gst-plugins-base/gst/subparse/gstsubparse.c index eaae3cf..d123624 100644 --- a/subprojects/gst-plugins-base/gst/subparse/gstsubparse.c +++ b/subprojects/gst-plugins-base/gst/subparse/gstsubparse.c @@ -1599,26 +1599,10 @@ done: } static GstFlowReturn -handle_buffer (GstSubParse * self, GstBuffer * buf) +check_initial_events (GstSubParse * self) { - GstFlowReturn ret = GST_FLOW_OK; - gchar *line, *subtitle; gboolean need_tags = FALSE; - if (self->first_buffer) { - GstMapInfo map; - - gst_buffer_map (buf, &map, GST_MAP_READ); - self->detected_encoding = - gst_sub_parse_detect_encoding ((gchar *) map.data, map.size); - gst_buffer_unmap (buf, &map); - self->first_buffer = FALSE; - self->state.fps_n = self->fps_n; - self->state.fps_d = self->fps_d; - } - - feed_textbuf (self, buf); - /* make sure we know the format */ if (G_UNLIKELY (self->parser_type == GST_SUB_PARSE_FORMAT_UNKNOWN)) { GstCaps *preferred; @@ -1657,6 +1641,35 @@ handle_buffer (GstSubParse * self, GstBuffer * buf) } } + return GST_FLOW_OK; +} + +static GstFlowReturn +handle_buffer (GstSubParse * self, GstBuffer * buf) +{ + GstFlowReturn ret = GST_FLOW_OK; + gchar *line, *subtitle; + + GST_DEBUG_OBJECT (self, "%" GST_PTR_FORMAT, buf); + + if (self->first_buffer) { + GstMapInfo map; + + gst_buffer_map (buf, &map, GST_MAP_READ); + self->detected_encoding = + gst_sub_parse_detect_encoding ((gchar *) map.data, map.size); + gst_buffer_unmap (buf, &map); + self->first_buffer = FALSE; + self->state.fps_n = self->fps_n; + self->state.fps_d = self->fps_d; + } + + feed_textbuf (self, buf); + + ret = check_initial_events (self); + if (ret != GST_FLOW_OK) + return ret; + while (!self->flushing && (line = get_next_line (self))) { guint offset = 0; @@ -1807,6 +1820,16 @@ gst_sub_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) self->need_segment = TRUE; break; } + case GST_EVENT_GAP: + { + ret = check_initial_events (self); + if (ret == GST_FLOW_OK) { + ret = gst_pad_event_default (pad, parent, event); + } else { + gst_event_unref (event); + } + break; + } case GST_EVENT_FLUSH_START: { self->flushing = TRUE; -- 2.7.4