From 336a97157c0aeae470c5c60492a7b69a35215cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 16 Apr 2018 21:27:47 +0300 Subject: [PATCH] flacparse: Drain the parser when a CAPS event is received After a CAPS event, in theory a new stream can start and it might start with the FLAC headers again. We can't detect FLAC headers in the middle of the stream, so we drain the parser to be able to detect either FLAC headers after the CAPS event or the continuation of the previous stream. This fixes for example gst-launch-1.0 audiotestsrc num-buffers=200 ! flacenc ! c. \ audiotestsrc num-buffers=200 freq=880 ! flacenc ! c. \ concat name=c ! rtpgstpay ! udpsink host=127.0.0.1 port=5000 gst-launch-1.0 udpsrc multicast-group=127.0.0.1 port=5000 \ caps=application/x-rtp,media=application,clock-rate=90000,encoding-name=X-GST ! \ rtpgstdepay ! flacparse ! flacdec ! audioconvert ! pulsesin --- gst/audioparsers/gstflacparse.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gst/audioparsers/gstflacparse.c b/gst/audioparsers/gstflacparse.c index 69a69280ae..90176af9ad 100644 --- a/gst/audioparsers/gstflacparse.c +++ b/gst/audioparsers/gstflacparse.c @@ -212,6 +212,8 @@ static gboolean gst_flac_parse_src_event (GstBaseParse * parse, GstEvent * event); static GstCaps *gst_flac_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter); +static gboolean gst_flac_parse_set_sink_caps (GstBaseParse * parse, + GstCaps * caps); #define gst_flac_parse_parent_class parent_class G_DEFINE_TYPE (GstFlacParse, gst_flac_parse, GST_TYPE_BASE_PARSE); @@ -246,6 +248,8 @@ gst_flac_parse_class_init (GstFlacParseClass * klass) baseparse_class->src_event = GST_DEBUG_FUNCPTR (gst_flac_parse_src_event); baseparse_class->get_sink_caps = GST_DEBUG_FUNCPTR (gst_flac_parse_get_sink_caps); + baseparse_class->set_sink_caps = + GST_DEBUG_FUNCPTR (gst_flac_parse_set_sink_caps); gst_element_class_add_static_pad_template (element_class, &src_factory); gst_element_class_add_static_pad_template (element_class, &sink_factory); @@ -1875,3 +1879,15 @@ gst_flac_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter) return res; } + +static gboolean +gst_flac_parse_set_sink_caps (GstBaseParse * parse, GstCaps * caps) +{ + /* If caps are changing, drain any pending frames we have so that afterwards + * we can potentially accept a new stream that is starting with the FLAC + * headers again. If headers appear in the middle of the stream we can't + * detect them + */ + gst_base_parse_drain (parse); + return TRUE; +}