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/1903>
This commit is contained in:
Edward Hervey 2021-12-14 16:14:56 +01:00 committed by GStreamer Marge Bot
parent 0d617885f1
commit b6303c46b7

View file

@ -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;