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
diff --git a/gst/audioparsers/gstflacparse.c b/gst/audioparsers/gstflacparse.c
index 69a6928..90176af 100644
--- a/gst/audioparsers/gstflacparse.c
+++ b/gst/audioparsers/gstflacparse.c
@@ -212,6 +212,8 @@
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 @@
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 @@
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;
+}