subparse: Handle GAP events before buffers

Make sure we did initial negotiation and segment pushing if we get GAP events
before buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2834>
This commit is contained in:
Edward Hervey 2021-12-14 16:14:56 +01:00 committed by Tim-Philipp Müller
parent 7d0ca03998
commit afa0549c0c

View file

@ -1599,26 +1599,10 @@ done:
} }
static GstFlowReturn 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; 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 */ /* make sure we know the format */
if (G_UNLIKELY (self->parser_type == GST_SUB_PARSE_FORMAT_UNKNOWN)) { if (G_UNLIKELY (self->parser_type == GST_SUB_PARSE_FORMAT_UNKNOWN)) {
GstCaps *preferred; 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))) { while (!self->flushing && (line = get_next_line (self))) {
guint offset = 0; guint offset = 0;
@ -1807,6 +1820,16 @@ gst_sub_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
self->need_segment = TRUE; self->need_segment = TRUE;
break; 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: case GST_EVENT_FLUSH_START:
{ {
self->flushing = TRUE; self->flushing = TRUE;